Rev 255 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
88 | pingvin | 1 | #include "mainwindow.h" |
2 | #include "ui_mainwindow.h" |
||
3 | |||
4 | MainWindow::MainWindow(QWidget *parent) : |
||
5 | QMainWindow(parent), |
||
6 | ui(new Ui::MainWindow) |
||
7 | { |
||
8 | ui->setupUi(this); |
||
222 | pingvin | 9 | /* |
10 | QPalette p = this->palette(); |
||
11 | p.setBrush(this->backgroundRole(), QBrush(QColor(255,255,255,128))); |
||
12 | this->setAutoFillBackground(true); |
||
13 | this->setPalette(p); |
||
14 | */ |
||
15 | |||
205 | pingvin | 16 | ui->centralWidget->setLayout(ui->verticalLayout); |
17 | ui->tab->setLayout(ui->horizontalLayout); |
||
18 | ui->tab_2->setLayout(ui->horizontalLayout_3); |
||
233 | pingvin | 19 | ui->tab_3->setLayout(ui->horizontalLayout_7); |
237 | pingvin | 20 | ui->tab_4->setLayout(ui->horizontalLayout_8); |
106 | pingvin | 21 | // connect( ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(on_currentIndexChanged(int))); |
118 | pingvin | 22 | model_is_build = false; |
145 | pingvin | 23 | // MainWindow::readModel(); |
89 | pingvin | 24 | |
91 | pingvin | 25 | //QString model_str; |
140 | pingvin | 26 | |
27 | |||
28 | /* |
||
91 | pingvin | 29 | MainWindow::creatModelString(); |
30 | int i; |
||
31 | i++; |
||
93 | pingvin | 32 | QFile file_tmp("./temp.txt"); |
92 | pingvin | 33 | bool ok; |
34 | ok = file_tmp.open(QIODevice::ReadWrite | QIODevice::Text); |
||
35 | QTextStream out(&file_tmp); |
||
36 | out << MainWindow::modelString; |
||
37 | file_tmp.close(); |
||
140 | pingvin | 38 | */ |
174 | pingvin | 39 | |
40 | |||
41 | |||
42 | |||
114 | pingvin | 43 | ui->treeWidget->setAlternatingRowColors(true); |
44 | ui->treeWidget_2->setAlternatingRowColors(true); |
||
132 | pingvin | 45 | |
177 | pingvin | 46 | ui->treeWidget->setIconSize(QSize(30,30)); |
209 | pingvin | 47 | ui->treeWidget->setColumnWidth(0, 400); |
193 | pingvin | 48 | ui->treeWidget_2->setIconSize(QSize(128,128)); |
132 | pingvin | 49 | |
50 | MainWindow::readSettings(); |
||
51 | |||
93 | pingvin | 52 | MainWindow::openDataBase(); |
136 | pingvin | 53 | |
174 | pingvin | 54 | classesIcons = MainWindow::getClassesIcons(); // |
55 | |||
104 | pingvin | 56 | MainWindow::initComboBox(); |
136 | pingvin | 57 | |
145 | pingvin | 58 | // MainWindow::buildPreviewModel(tr(" "), tr("11")); |
136 | pingvin | 59 | |
142 | pingvin | 60 | MainWindow::initListModelsTablle(); |
140 | pingvin | 61 | |
144 | pingvin | 62 | MainWindow::readModels(); |
63 | |||
250 | pingvin | 64 | initWmiTree(); |
65 | |||
66 | |||
145 | pingvin | 67 | // MainWindow::creatModelString(); |
140 | pingvin | 68 | //int i; |
69 | //i++; |
||
145 | pingvin | 70 | |
71 | /* |
||
72 | QFile file_tmp("./modelstring.txt"); |
||
140 | pingvin | 73 | bool ok; |
74 | file_tmp.remove(); |
||
75 | ok = file_tmp.open(QIODevice::ReadWrite | QIODevice::Text); |
||
76 | QTextStream out(&file_tmp); |
||
77 | out.setCodec("cp1251"); |
||
78 | out << MainWindow::modelString; |
||
79 | file_tmp.close(); |
||
145 | pingvin | 80 | */ |
140 | pingvin | 81 | |
82 | |||
151 | pingvin | 83 | ui->treeWidget_2->hideColumn(1); |
84 | ui->treeWidget_2->hideColumn(2); |
||
85 | ui->treeWidget_2->hideColumn(3); |
||
86 | ui->treeWidget_2->hideColumn(4); |
||
235 | pingvin | 87 | ui->treeWidget_2->hideColumn(5); |
140 | pingvin | 88 | |
151 | pingvin | 89 | |
109 | pingvin | 90 | getDatabaseData(); |
127 | pingvin | 91 | //// sql_mogel = new QSqlTableModel(); |
92 | sql_mogel = new MyModel(); |
||
93 | |||
223 | pingvin | 94 | /// filter_model = new MyModel(); |
95 | filter_model = new QSqlTableModel(); |
||
227 | pingvin | 96 | filter_model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
127 | pingvin | 97 | |
118 | pingvin | 98 | model_is_build = true; |
119 | pingvin | 99 | connect(sql_mogel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_sql_mogel_dataChanged(QModelIndex,QModelIndex))); |
146 | pingvin | 100 | connect(model_for_ListModelsTable, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_model_for_ListModelsTable_dataChanged(QModelIndex,QModelIndex))); |
221 | pingvin | 101 | connect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
238 | pingvin | 102 | connect(&wmiProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readStandartProcessOutput())); |
241 | pingvin | 103 | connect(&wmiProcess, SIGNAL(readyReadStandardError()), this, SLOT(readStandartProcessError())); |
146 | pingvin | 104 | |
221 | pingvin | 105 | |
119 | pingvin | 106 | ui->pushButton_3->setEnabled(false); |
107 | ui->pushButton_4->setEnabled(false); |
||
108 | |||
217 | pingvin | 109 | |
110 | ui->pushButton_9->setEnabled(false); |
||
111 | ui->pushButton_10->setEnabled(false); |
||
112 | ui->pushButton_11->setEnabled(false); |
||
113 | ui->pushButton_12->setEnabled(false); |
||
114 | |||
132 | pingvin | 115 | // setFrm.show(); |
119 | pingvin | 116 | |
212 | pingvin | 117 | // treeForm.show(); |
118 | |||
132 | pingvin | 119 | connect(ui->getsettingAct, SIGNAL(triggered()), this, SLOT(getSetting())); // " " " " |
120 | connect(setFrm.pushButton, SIGNAL(clicked()), this, SLOT(applySetting())); |
||
121 | |||
158 | pingvin | 122 | // connect(ui->tableView_2,SIGNAL(activated(QModelIndex)),ui->tableView_2,SLOT(edit(QModelIndex))); |
132 | pingvin | 123 | |
158 | pingvin | 124 | picture_delegate = new CPictureDelegate(this); |
189 | pingvin | 125 | iconDelegate = new IconDelegate(this); |
201 | pingvin | 126 | fileDelegate = new FileDelegate(this); |
158 | pingvin | 127 | |
200 | pingvin | 128 | // fileForm.show(); |
196 | pingvin | 129 | |
233 | pingvin | 130 | doc = ui->textEdit->document(); |
131 | cursor = new QTextCursor(doc); |
||
132 | // buildReport(true); |
||
228 | pingvin | 133 | |
241 | pingvin | 134 | all_reading = false; // |
242 | pingvin | 135 | // wmiThread = new WmiThread(this); |
228 | pingvin | 136 | |
88 | pingvin | 137 | } |
138 | |||
139 | MainWindow::~MainWindow() |
||
140 | { |
||
117 | pingvin | 141 | delete sql_mogel; |
221 | pingvin | 142 | delete filter_model; |
88 | pingvin | 143 | delete ui; |
149 | pingvin | 144 | delete model_for_ListModelsTable; |
88 | pingvin | 145 | } |
146 | |||
147 | void MainWindow::changeEvent(QEvent *e) |
||
148 | { |
||
149 | QMainWindow::changeEvent(e); |
||
150 | switch (e->type()) { |
||
151 | case QEvent::LanguageChange: |
||
152 | ui->retranslateUi(this); |
||
153 | break; |
||
154 | default: |
||
155 | break; |
||
156 | } |
||
157 | } |
||
89 | pingvin | 158 | |
159 | |||
160 | bool MainWindow::readModel(){ |
||
161 | bool result; |
||
162 | QString model_str; |
||
140 | pingvin | 163 | QFile file("modelstring.txt"); |
141 | pingvin | 164 | // QFile file("model.txt"); |
91 | pingvin | 165 | rootItem1 = new QTreeWidgetItem(ui->treeWidget); |
89 | pingvin | 166 | rootItem1->setText(0, tr(" 1")); |
167 | // rootItem2 = new QTreeWidgetItem(rootItem1); |
||
168 | // rootItem2->setText(0, tr(" 2")); |
||
169 | rootItem1->setCheckState(0,Qt::Checked); |
||
170 | // rootItem2->setCheckState(0,Qt::Checked); |
||
171 | |||
172 | |||
173 | |||
174 | result = file.open(QIODevice::ReadOnly); |
||
175 | if (result) { |
||
90 | pingvin | 176 | model_str = QString(tr(file.readAll())); |
89 | pingvin | 177 | } |
178 | |||
215 | pingvin | 179 | setupModelData(model_str.split(QString("\n")), rootItem1, -1, tr("1")); |
89 | pingvin | 180 | |
181 | |||
182 | return result; |
||
183 | |||
184 | } |
||
185 | |||
186 | |||
215 | pingvin | 187 | void MainWindow::setupModelData(const QStringList &lines, QTreeWidgetItem *parent, int row, QString model_id) |
89 | pingvin | 188 | { |
189 | QList<QTreeWidgetItem*> parents; |
||
190 | QList<int> indentations; |
||
191 | parents << parent; |
||
192 | indentations << 0; |
||
193 | |||
194 | int number = 0; |
||
195 | |||
196 | while (number < lines.count()) { |
||
197 | int position = 0; |
||
198 | while (position < lines[number].length()) { |
||
199 | if (lines[number].mid(position, 1) != " ") |
||
200 | break; |
||
201 | position++; |
||
202 | } |
||
203 | |||
204 | QString lineData = lines[number].mid(position).trimmed(); |
||
205 | |||
206 | if (!lineData.isEmpty()) { |
||
207 | // Read the column data from the rest of the line. |
||
208 | QStringList columnStrings = lineData.split("\t", QString::SkipEmptyParts); |
||
209 | QList<QVariant> columnData; |
||
210 | for (int column = 0; column < columnStrings.count(); ++column) |
||
211 | columnData << columnStrings[column]; |
||
212 | |||
213 | if (position > indentations.last()) { |
||
214 | // The last child of the current parent is now the new parent |
||
215 | // unless the current parent has no children. |
||
216 | |||
217 | if (parents.last()->childCount() > 0) { |
||
218 | parents << parents.last()->child(parents.last()->childCount()-1); |
||
219 | indentations << position; |
||
220 | } |
||
221 | } else { |
||
222 | while (position < indentations.last() && parents.count() > 0) { |
||
223 | parents.pop_back(); |
||
224 | indentations.pop_back(); |
||
225 | } |
||
226 | } |
||
227 | |||
228 | // Append a new item to the current parent's list of children. |
||
229 | // // // parents.last()->appendChild(new QTreeWidgetItem(columnData, parents.last())); |
||
230 | QTreeWidgetItem* itm_tmp; |
||
231 | itm_tmp = new QTreeWidgetItem( parents.last()); |
||
215 | pingvin | 232 | // itm_tmp->setFlags(Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsEnabled); |
89 | pingvin | 233 | |
209 | pingvin | 234 | /* |
235 | QLineEdit * edit_line; |
||
236 | edit_line = new QLineEdit(this); |
||
237 | ui->treeWidget->setItemWidget(itm_tmp, 5, edit_line); |
||
238 | */ |
||
239 | //static QStandartDelegate delegate; |
||
240 | ui->treeWidget->setItemDelegateForColumn(5, &standart_delegate); |
||
241 | |||
242 | |||
89 | pingvin | 243 | itm_tmp->setText(0, QString(columnData.at(0).toString())); |
244 | if (columnData.at(1).toString() == "true") { |
||
245 | itm_tmp->setCheckState(0,Qt::Checked); |
||
246 | } |
||
247 | else itm_tmp->setCheckState(0,Qt::Unchecked); |
||
141 | pingvin | 248 | if (columnData.count()>2) |
249 | { |
||
173 | pingvin | 250 | QString class_id; |
222 | pingvin | 251 | QString filtr_str; |
174 | pingvin | 252 | QPixmap pxmp; |
253 | QIcon icon; |
||
173 | pingvin | 254 | class_id = QString(columnData.at(2).toString()); |
174 | pingvin | 255 | pxmp = MainWindow::classesIcons.value(class_id); |
256 | |||
173 | pingvin | 257 | // itm_tmp->setText(1, QString(columnData.at(2).toString())); // id |
258 | itm_tmp->setText(1, class_id); // id |
||
215 | pingvin | 259 | itm_tmp->setText(6, model_id); // id |
90 | pingvin | 260 | itm_tmp->setText(2, QVariant(number).toString()); // - |
173 | pingvin | 261 | itm_tmp->setText(3, QVariant(indentations.size()).toString()); // |
262 | itm_tmp->setText(4, QVariant(row).toString()); // |
||
222 | pingvin | 263 | filtr_str = getFiltrString(model_id,class_id); |
264 | itm_tmp->setText(5,filtr_str); |
||
174 | pingvin | 265 | |
266 | if (!pxmp.isNull()) |
||
267 | { |
||
268 | icon.addPixmap(pxmp); |
||
175 | pingvin | 269 | itm_tmp->setIcon(0, icon); |
174 | pingvin | 270 | } |
141 | pingvin | 271 | } |
89 | pingvin | 272 | } |
273 | |||
274 | number++; |
||
275 | } |
||
276 | } |
||
277 | |||
278 | |||
279 | /* |
||
280 | void MainWindow::openBase() |
||
281 | { |
||
282 | |||
283 | db = QSqlDatabase::addDatabase("QMYSQL"); |
||
284 | pdb = &db; |
||
285 | raportFrm.pdb = &db; |
||
286 | |||
287 | pdb->setHostName(hostName); |
||
288 | pdb->setDatabaseName(baseName); |
||
289 | pdb->setUserName(userName); |
||
290 | pdb->setPassword(password); |
||
291 | bool ok = pdb->open(); |
||
292 | if (!ok) { |
||
293 | QMessageBox::critical( // . |
||
294 | this, // . |
||
295 | QObject::tr("Database Error"), // . |
||
296 | pdb->lastError().text()); // . |
||
297 | } |
||
298 | if (ok) |
||
299 | {lineEdit-> insert(tr(" ")); |
||
300 | } |
||
301 | else {lineEdit-> insert(tr(" . : ")); |
||
302 | lineEdit-> insert(pdb->lastError().text()); |
||
303 | } |
||
304 | |||
305 | |||
306 | |||
307 | model = new QSqlTableModel(this); |
||
308 | model->setTable(tableName); |
||
309 | |||
310 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
311 | model->setSort(0, Qt::AscendingOrder); |
||
312 | |||
313 | model->select(); |
||
314 | |||
315 | |||
316 | QSqlField field(tr("age"), QVariant::Int); |
||
317 | field.setValue(QString(tr("123"))); |
||
318 | |||
319 | bool okey; |
||
320 | int index; |
||
321 | QSqlRecord record; |
||
322 | |||
323 | |||
324 | tableView->setModel(model); |
||
325 | view.setModel(model); |
||
326 | |||
327 | |||
328 | tableView->setAlternatingRowColors(true); |
||
329 | view.setAlternatingRowColors(true); |
||
330 | |||
331 | tableView->resizeColumnsToContents(); |
||
332 | |||
333 | |||
334 | view.resizeColumnsToContents(); |
||
335 | |||
336 | tableView->show(); |
||
337 | |||
338 | |||
339 | |||
340 | initTreeWidget(); |
||
341 | } |
||
342 | */ |
||
91 | pingvin | 343 | |
344 | |||
146 | pingvin | 345 | QString MainWindow::creatModelString(QTreeWidgetItem* model){ |
91 | pingvin | 346 | |
347 | MainWindow::modelString.clear(); // |
||
348 | // for (int i =0; i < rootItem1->childCount(); ++i ) |
||
349 | |||
146 | pingvin | 350 | {MainWindow::addChildsString(model, 0);} |
351 | |||
352 | return MainWindow::modelString; |
||
145 | pingvin | 353 | // {MainWindow::addChildsString(ui->treeWidget, 0);} |
354 | /* |
||
91 | pingvin | 355 | int root_item_child_count; |
356 | int i; |
||
357 | root_item_child_count = rootItem1->childCount(); |
||
358 | i++; |
||
145 | pingvin | 359 | */ |
91 | pingvin | 360 | } |
361 | |||
362 | |||
363 | void MainWindow::addChildsString(QTreeWidgetItem *parentItem, int level){ |
||
364 | int child_count; |
||
365 | child_count = parentItem->childCount(); |
||
366 | for (int i=0; i < child_count; ++i){ |
||
367 | for (int m=0; m < level; ++m){ |
||
368 | modelString.append(tr(" ")); // - , |
||
369 | } |
||
370 | modelString.append(parentItem->child(i)->text(0)); // - |
||
371 | modelString.append(tr("\t\t\t\t")); // - |
||
372 | if (parentItem->child(i)->checkState(0) == Qt::Checked) {modelString.append(tr("true"));} // , "true", |
||
373 | else {modelString.append(tr("false"));} // - "false", |
||
374 | modelString.append(tr("\t\t\t\t")); // - |
||
375 | modelString.append(parentItem->child(i)->text(1)); // - ID |
||
376 | modelString.append(tr("\n")); // |
||
377 | if (parentItem->child(i)->childCount() > 0) { MainWindow::addChildsString(parentItem->child(i), level+1);} |
||
378 | |||
379 | } |
||
380 | int i; |
||
381 | i++; |
||
382 | } |
||
93 | pingvin | 383 | |
384 | |||
385 | bool MainWindow::openDataBase(){ |
||
386 | QString errorString; |
||
387 | sql = QSqlDatabase::addDatabase("QMYSQL"); |
||
131 | pingvin | 388 | // sql.setDatabaseName(tr("an_db")); |
389 | |||
132 | pingvin | 390 | // // // sql.setDatabaseName(tr("inventory")); |
131 | pingvin | 391 | |
132 | pingvin | 392 | sql.setDatabaseName(baseName); |
131 | pingvin | 393 | |
394 | |||
395 | |||
132 | pingvin | 396 | // // // sql.setHostName(tr("localhost")); |
93 | pingvin | 397 | |
132 | pingvin | 398 | sql.setHostName(hostName); |
399 | |||
400 | |||
401 | // // // sql.setUserName(tr("an")); |
||
402 | |||
403 | sql.setUserName(userName); |
||
404 | |||
405 | |||
406 | |||
407 | // // // sql.setPassword(tr("393939")); |
||
408 | |||
409 | |||
410 | sql.setPassword(password); |
||
411 | |||
412 | |||
413 | |||
93 | pingvin | 414 | bool ok; |
415 | ok = sql.open(); |
||
416 | |||
417 | /* |
||
418 | if (!ok) { |
||
419 | QMessageBox::critical( // . |
||
420 | this, // . |
||
421 | QObject::tr("Database Error"), // . |
||
422 | sql.lastError().text() ); // . |
||
423 | |||
424 | |||
425 | } |
||
426 | |||
427 | */ |
||
428 | if (!ok) { |
||
429 | QMessageBox::critical( // . |
||
430 | this, // . |
||
431 | QObject::tr("Database Error"), // . |
||
432 | sql.lastError().text()); // . |
||
433 | } |
||
434 | else { |
||
435 | |||
436 | QMessageBox::information( // . |
||
437 | this, // . |
||
438 | QObject::tr("Database Connect"), // . |
||
439 | QObject::tr(" .")); // . |
||
440 | |||
441 | |||
442 | |||
443 | |||
444 | |||
445 | } |
||
446 | |||
447 | return ok; |
||
448 | } |
||
94 | pingvin | 449 | |
450 | |||
97 | pingvin | 451 | bool MainWindow::buildPreviewModel(QString modelName, QString rootClassID){ |
94 | pingvin | 452 | QSqlQuery q; |
453 | QString sql_str; |
||
95 | pingvin | 454 | QString field_name_str; |
455 | QString root_class_name; |
||
192 | pingvin | 456 | //bool ok; |
457 | //int field_name; |
||
95 | pingvin | 458 | |
459 | //ui->treeWidget->clear(); |
||
460 | |||
461 | root_class_name = MainWindow::ClassName(rootClassID); // |
||
462 | |||
145 | pingvin | 463 | |
95 | pingvin | 464 | rootItem1 = new QTreeWidgetItem(ui->treeWidget); |
145 | pingvin | 465 | root_items_list << rootItem1; |
97 | pingvin | 466 | rootItem1->setText(0, modelName); |
467 | |||
95 | pingvin | 468 | rootItem1->setCheckState(0,Qt::Checked); |
104 | pingvin | 469 | rootItems.append(rootItem1); |
95 | pingvin | 470 | |
471 | |||
104 | pingvin | 472 | |
145 | pingvin | 473 | rootItem2 = new QTreeWidgetItem(rootItem1); |
474 | rootItem2->setText(0, root_class_name); |
||
475 | rootItem2->setText(1, rootClassID); |
||
476 | rootItem2->setCheckState(0,Qt::Checked); |
||
95 | pingvin | 477 | |
147 | pingvin | 478 | addChildsItems(rootItem2, -1); |
95 | pingvin | 479 | |
145 | pingvin | 480 | |
481 | /* |
||
482 | |||
94 | pingvin | 483 | sql_str = tr("select * " |
95 | pingvin | 484 | " from DescriptionOfClasses where DescriptionOfClasses.DefaultValue = '" // , |
94 | pingvin | 485 | ); |
486 | sql_str.append(rootClassID); |
||
487 | |||
95 | pingvin | 488 | sql_str.append(tr("' and DescriptionOfClasses.FieldType = 'pointer' ")); |
94 | pingvin | 489 | |
95 | pingvin | 490 | q.prepare(sql_str); |
491 | |||
492 | ok = q.exec(); |
||
493 | if (!ok) { |
||
494 | QMessageBox::critical( // . |
||
495 | this, // . |
||
496 | QObject::tr("Database Error"), // . |
||
497 | q.lastError().text()); // . |
||
498 | } |
||
499 | field_name = q.record().indexOf(tr("FieldName")); |
||
500 | while(q.next()){ |
||
501 | |||
502 | field_name_str = q.value(field_name).toString(); |
||
503 | |||
504 | } |
||
505 | |||
100 | pingvin | 506 | |
507 | |||
508 | |||
145 | pingvin | 509 | */ |
510 | |||
511 | |||
94 | pingvin | 512 | } |
95 | pingvin | 513 | |
514 | |||
147 | pingvin | 515 | bool MainWindow::rebuildPreviewModel(QTreeWidgetItem* root_item, QString rootClassID, int row){ |
107 | pingvin | 516 | QSqlQuery q; |
517 | QString sql_str; |
||
518 | QString field_name_str; |
||
519 | QString root_class_name; |
||
192 | pingvin | 520 | //bool ok; |
521 | //int field_name; |
||
95 | pingvin | 522 | |
107 | pingvin | 523 | //ui->treeWidget->clear(); |
524 | |||
525 | root_class_name = MainWindow::ClassName(rootClassID); // |
||
526 | |||
527 | |||
528 | // rootItem1 = new QTreeWidgetItem(ui->treeWidget); |
||
529 | // root_items_list << rootItem1; |
||
530 | // rootItem1->setText(0, modelName); |
||
531 | |||
532 | // rootItem1->setCheckState(0,Qt::Checked); |
||
533 | // rootItems.append(rootItem1); |
||
534 | |||
535 | // root_item->removeChild(root_item->child(0)); // |
||
145 | pingvin | 536 | if (root_item->childCount()==0){ // , |
537 | QTreeWidgetItem* item_tmp; |
||
538 | item_tmp = new QTreeWidgetItem (root_item); |
||
147 | pingvin | 539 | item_tmp->setText(4, QVariant(row).toString()); |
145 | pingvin | 540 | |
541 | } |
||
542 | |||
543 | if (root_item->childCount()==1){ // , |
||
107 | pingvin | 544 | root_item->child(0)->setText(0, root_class_name); |
545 | root_item->child(0)->setText(1, rootClassID); |
||
147 | pingvin | 546 | root_item->child(0)->setCheckState(0,Qt::Checked); |
547 | root_item->setText(4, QVariant(row).toString()); |
||
107 | pingvin | 548 | |
147 | pingvin | 549 | } |
145 | pingvin | 550 | |
551 | |||
147 | pingvin | 552 | |
107 | pingvin | 553 | //delete rootItem2; |
554 | |||
555 | |||
556 | // rootItem2 = new QTreeWidgetItem(rootItem1); |
||
557 | |||
558 | |||
559 | |||
560 | // rootItem2->setText(0, root_class_name); |
||
561 | // rootItem2->setText(1, rootClassID); |
||
562 | // rootItem2->setCheckState(0,Qt::Checked); |
||
563 | |||
564 | int child_count = root_item->child(0)->childCount(); |
||
565 | |||
566 | |||
145 | pingvin | 567 | for (int i=0; i < child_count; i++){ // , |
107 | pingvin | 568 | root_item->child(0)->removeChild(root_item->child(0)->child(0)); |
569 | } |
||
570 | |||
571 | child_count = root_item->child(0)->childCount(); |
||
147 | pingvin | 572 | addChildsItems(root_item->child(0), row); |
107 | pingvin | 573 | /* |
574 | sql_str = tr("select * " |
||
575 | " from DescriptionOfClasses where DescriptionOfClasses.DefaultValue = '" // , |
||
576 | ); |
||
577 | sql_str.append(rootClassID); |
||
578 | |||
579 | sql_str.append(tr("' and DescriptionOfClasses.FieldType = 'pointer' ")); |
||
580 | |||
581 | q.prepare(sql_str); |
||
582 | |||
583 | ok = q.exec(); |
||
584 | if (!ok) { |
||
585 | QMessageBox::critical( // . |
||
586 | this, // . |
||
587 | QObject::tr("Database Error"), // . |
||
588 | q.lastError().text()); // . |
||
589 | } |
||
590 | field_name = q.record().indexOf(tr("FieldName")); |
||
591 | while(q.next()){ |
||
592 | |||
593 | field_name_str = q.value(field_name).toString(); |
||
594 | |||
595 | } |
||
596 | |||
597 | */ |
||
598 | |||
599 | |||
600 | } |
||
601 | |||
602 | |||
603 | |||
604 | |||
95 | pingvin | 605 | QString MainWindow::ClassName(QString class_id){ // ID |
606 | QSqlQuery q; |
||
607 | QString sql_str; |
||
608 | QString class_name_str; |
||
609 | bool ok; |
||
610 | int field_class_name; |
||
611 | |||
612 | sql_str = tr("select * " |
||
613 | " from ListOfClasses where ListOfClasses.ID = '" // , |
||
614 | ); |
||
615 | |||
616 | sql_str.append(class_id); |
||
617 | sql_str.append(tr("' ")); |
||
618 | |||
619 | q.prepare(sql_str); |
||
620 | |||
621 | ok = q.exec(); |
||
622 | |||
623 | |||
624 | if (!ok) { |
||
625 | QMessageBox::critical( // . |
||
626 | this, // . |
||
627 | QObject::tr("Database Error"), // . |
||
628 | q.lastError().text()); // . |
||
629 | } |
||
630 | |||
631 | field_class_name = q.record().indexOf(tr("ClassName")); |
||
632 | while(q.next()){ |
||
633 | |||
634 | class_name_str = q.value(field_class_name).toString(); |
||
635 | |||
636 | } |
||
637 | |||
638 | return class_name_str; |
||
639 | |||
640 | } |
||
98 | pingvin | 641 | |
147 | pingvin | 642 | void MainWindow::addChildsItems(QTreeWidgetItem *perent_class_item, int row){ // , |
100 | pingvin | 643 | QStringList chields_list; |
644 | QString parent_ID; |
||
645 | QTreeWidgetItem *Item_tmp; |
||
646 | parent_ID = perent_class_item->text(1); |
||
647 | int chields_count, i; |
||
98 | pingvin | 648 | |
100 | pingvin | 649 | chields_list = MainWindow::classChields(parent_ID); |
650 | if(chields_list.isEmpty()) return; |
||
651 | chields_count = chields_list.size(); |
||
652 | for (int l = 0; l < chields_count; ++l){ |
||
653 | QString chield_class_name, chield_id; |
||
654 | chield_id = chields_list.at(l); |
||
655 | chield_class_name = MainWindow::ClassName(chield_id); |
||
656 | Item_tmp = new QTreeWidgetItem(perent_class_item); |
||
657 | Item_tmp->setText(0, chield_class_name); |
||
658 | Item_tmp->setText(1, chield_id); |
||
659 | Item_tmp->setCheckState(0, Qt::Checked); |
||
147 | pingvin | 660 | Item_tmp->setText(4, QVariant(row).toString()); |
661 | MainWindow::addChildsItems(Item_tmp, row); |
||
98 | pingvin | 662 | } |
663 | |||
100 | pingvin | 664 | i++; |
99 | pingvin | 665 | |
100 | pingvin | 666 | } |
667 | |||
668 | |||
99 | pingvin | 669 | /******************************************************** |
670 | * "" |
||
671 | * |
||
672 | * |
||
673 | * |
||
674 | ********************************************************/ |
||
675 | |||
676 | QStringList MainWindow::classChields(QString class_id){ |
||
677 | // QMap<QString, QString> map; |
||
678 | // TClass class_tmp; |
||
679 | // QList <TClass> chields_class_list; // |
||
680 | QStringList result; |
||
681 | QSqlQuery q; |
||
682 | QString sql_str; |
||
683 | QString classIdentifer_str; // - |
||
684 | QString field_id_str; |
||
685 | bool ok; |
||
686 | int field_classIdentifer; |
||
687 | sql_str = tr("select * " |
||
688 | " from DescriptionOfClasses where DescriptionOfClasses.DefaultValue = '" // , |
||
689 | ); |
||
690 | sql_str.append(class_id); |
||
691 | |||
692 | sql_str.append(tr("' and DescriptionOfClasses.FieldType = 'pointer' ")); |
||
693 | |||
694 | q.prepare(sql_str); |
||
695 | |||
696 | ok = q.exec(); |
||
697 | if (!ok) { |
||
698 | QMessageBox::critical( // . |
||
699 | this, // . |
||
700 | QObject::tr("Database Error"), // . |
||
701 | q.lastError().text()); // . |
||
702 | } |
||
703 | field_classIdentifer = q.record().indexOf(tr("ClassIdentifer")); |
||
704 | while(q.next()){ |
||
705 | |||
706 | classIdentifer_str = q.value(field_classIdentifer).toString(); |
||
707 | result.append(classIdentifer_str); |
||
708 | } |
||
709 | |||
710 | return result; |
||
711 | |||
712 | } |
||
102 | pingvin | 713 | |
714 | |||
715 | QMap <QString, QString> MainWindow::getClassList(){ // |
||
716 | QMap <QString, QString> result_map; |
||
717 | QSqlQuery q; |
||
718 | QString sql_str; |
||
103 | pingvin | 719 | QString class_name_str, class_id_str; |
720 | |||
102 | pingvin | 721 | int field_class_id, field_class_name; |
722 | bool ok; |
||
723 | sql_str = tr("select * " |
||
724 | " from ListOfClasses " // , |
||
725 | ); |
||
726 | q.prepare(sql_str); |
||
727 | ok = q.exec(); |
||
728 | if (!ok) { |
||
729 | QMessageBox::critical( // . |
||
730 | this, // . |
||
731 | QObject::tr("Database Error"), // . |
||
732 | q.lastError().text()); // . |
||
733 | return result_map; // - |
||
734 | } |
||
735 | field_class_id = q.record().indexOf(tr("ID")); |
||
736 | field_class_name = q.record().indexOf(tr("ClassName")); |
||
737 | |||
103 | pingvin | 738 | while(q.next()){ |
102 | pingvin | 739 | |
103 | pingvin | 740 | class_name_str = q.value(field_class_name).toString(); |
741 | class_id_str = q.value(field_class_id).toString(); |
||
742 | result_map[class_id_str] = class_name_str; |
||
743 | } |
||
102 | pingvin | 744 | return result_map; |
745 | } |
||
104 | pingvin | 746 | |
747 | |||
748 | |||
749 | |||
750 | |||
751 | void MainWindow::initComboBox(){ |
||
752 | |||
106 | pingvin | 753 | |
104 | pingvin | 754 | QStringList classesNameList; |
755 | QStringList classesID_list; |
||
756 | QStringList tmp_stringList; |
||
757 | |||
758 | |||
759 | |||
760 | QString tmp_str; |
||
761 | |||
762 | class_list_map = MainWindow::getClassList(); |
||
763 | classesID_list = class_list_map.keys(); |
||
764 | classesNameList = class_list_map.values(); |
||
765 | QMapIterator<QString, QString> interator(class_list_map); |
||
766 | // ui->comboBox->addItems(classesID_list); |
||
767 | // ui->comboBox->addItems(classesNameList); |
||
233 | pingvin | 768 | |
104 | pingvin | 769 | while (interator.hasNext()) { |
770 | interator.next(); |
||
771 | tmp_str = interator.value(); |
||
772 | tmp_str.append(tr(" \t(ID=")); |
||
773 | tmp_str.append(interator.key()); |
||
774 | tmp_str.append(tr(")")); |
||
775 | tmp_stringList << tmp_str; |
||
776 | |||
777 | } |
||
233 | pingvin | 778 | tmp_stringList << tr(" "); |
132 | pingvin | 779 | // int count = ui->comboBox->count(); |
780 | |||
781 | ui->comboBox->clear(); |
||
104 | pingvin | 782 | ui->comboBox->addItems(tmp_stringList); |
783 | |||
784 | |||
785 | } |
||
105 | pingvin | 786 | |
787 | |||
106 | pingvin | 788 | void MainWindow::on_comboBox_currentIndexChanged( int index ){ |
789 | QStringList classesNameList; |
||
790 | QStringList classesID_list; |
||
791 | QString ID_str; |
||
236 | pingvin | 792 | if (index == -1) return;// " " |
793 | if (ui->comboBox->itemText(index) == tr(" ")) return; |
||
152 | pingvin | 794 | if (!comboBox_slot_enable) return; // , , |
147 | pingvin | 795 | int row; |
132 | pingvin | 796 | |
106 | pingvin | 797 | classesID_list = class_list_map.keys(); |
798 | classesNameList = class_list_map.values(); |
||
799 | ID_str = classesID_list[index]; |
||
800 | ui->label->setText(ID_str); |
||
145 | pingvin | 801 | if (root_items_list.indexOf(ui->treeWidget->currentItem()) != -1) |
802 | { |
||
147 | pingvin | 803 | row = QVariant(ui->treeWidget->currentItem()->text(4)).toInt(); |
145 | pingvin | 804 | model_is_build = false; // on_treeWidget_itemChanged |
147 | pingvin | 805 | rebuildPreviewModel(ui->treeWidget->currentItem(), ID_str, row); |
145 | pingvin | 806 | model_is_build = true; // |
147 | pingvin | 807 | QString mdl_str = MainWindow::creatModelString(ui->treeWidget->currentItem()); // |
808 | model_for_ListModelsTable->setData(model_for_ListModelsTable->index(row, 2), QVariant(mdl_str)); |
||
145 | pingvin | 809 | } |
810 | getDatabaseData(); |
||
107 | pingvin | 811 | |
812 | |||
105 | pingvin | 813 | } |
814 | |||
106 | pingvin | 815 | void MainWindow::on_treeWidget_itemChanged ( QTreeWidgetItem * item, int column ){ |
816 | int i; |
||
817 | i++; |
||
147 | pingvin | 818 | QTreeWidgetItem * item_tmp; |
819 | QString mdl_str; |
||
820 | QString row; // , |
||
148 | pingvin | 821 | QList <QTreeWidgetItem *> mdl_itm_list; |
147 | pingvin | 822 | QList <int> rows_list; |
106 | pingvin | 823 | |
147 | pingvin | 824 | |
825 | if ((column) == 0 && (model_is_build)) { |
||
826 | // if (!model_is_build) return; // |
||
148 | pingvin | 827 | |
828 | mdl_itm_list = models_items.values(); |
||
147 | pingvin | 829 | rows_list = models_items.keys(); |
148 | pingvin | 830 | row= item->text(4); |
147 | pingvin | 831 | |
148 | pingvin | 832 | |
833 | if ( mdl_itm_list.indexOf(item) != -1){ // ( ) |
||
834 | if (item->checkState(0)) model_for_ListModelsTable->setData(model_for_ListModelsTable->index(QVariant(row).toInt(), 3), QVariant(1)); |
||
835 | else model_for_ListModelsTable->setData(model_for_ListModelsTable->index(QVariant(row).toInt(), 3), QVariant(0)); |
||
836 | } |
||
837 | |||
838 | |||
839 | |||
840 | |||
147 | pingvin | 841 | if (!row.isEmpty()){ |
842 | |||
843 | |||
844 | int row_int; |
||
845 | row_int = QVariant(row).toInt(); |
||
846 | if (rows_list.indexOf(row_int) != -1) |
||
847 | { |
||
848 | item_tmp = models_items[row_int]; |
||
849 | mdl_str = MainWindow::creatModelString(item_tmp); |
||
850 | model_for_ListModelsTable->setData(model_for_ListModelsTable->index(row_int, 2), QVariant(mdl_str)); |
||
851 | } |
||
852 | |||
853 | |||
854 | } |
||
855 | |||
856 | |||
857 | } |
||
858 | |||
859 | /* |
||
860 | QTreeWidgetItem * item_tmp; |
||
861 | item_tmp = item; |
||
862 | while (item_tmp ){ |
||
863 | item_tmp = item_tmp->parent(); |
||
864 | } |
||
865 | */ |
||
118 | pingvin | 866 | if ((column) == 0 && (model_is_build)) getDatabaseData(); |
867 | |||
147 | pingvin | 868 | |
106 | pingvin | 869 | } |
870 | |||
871 | |||
872 | void MainWindow::on_treeWidget_itemClicked ( QTreeWidgetItem * item, int column ){ |
||
873 | int i; |
||
874 | i++; |
||
214 | pingvin | 875 | if (root_items_list.indexOf(item) != -1) { // |
108 | pingvin | 876 | QStringList classesNameList; |
877 | QStringList classesID_list; |
||
106 | pingvin | 878 | |
217 | pingvin | 879 | ui->pushButton_9->setEnabled(false); |
880 | ui->pushButton_10->setEnabled(false); |
||
881 | ui->pushButton_11->setEnabled(false); |
||
882 | ui->pushButton_12->setEnabled(false); |
||
883 | // ui->tableView->reset(); |
||
884 | // MainWindow::filtr_model->clear(); |
||
221 | pingvin | 885 | disconnect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
886 | delete filter_model; |
||
223 | pingvin | 887 | |
888 | filter_model = new QSqlTableModel(); |
||
889 | /// filter_model = new MyModel(); |
||
227 | pingvin | 890 | filter_model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
223 | pingvin | 891 | |
892 | connect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
||
108 | pingvin | 893 | int index; |
894 | classesID_list = class_list_map.keys(); |
||
895 | classesNameList = class_list_map.values(); |
||
145 | pingvin | 896 | if (item->childCount()>0) index = classesID_list.indexOf(item->child(0)->text(1)); // , |
897 | else { // |
||
233 | pingvin | 898 | index = classesID_list.count(); |
899 | comboBox_slot_enable = false; // comboBox |
||
900 | ui->comboBox->setCurrentIndex(index); |
||
145 | pingvin | 901 | ui->comboBox->setEnabled(true); |
206 | pingvin | 902 | comboBox_slot_enable = true; |
145 | pingvin | 903 | return; |
904 | |||
905 | } |
||
152 | pingvin | 906 | comboBox_slot_enable = false; // comboBox |
132 | pingvin | 907 | if (index != -1) ui->comboBox->setCurrentIndex(index); |
152 | pingvin | 908 | comboBox_slot_enable = true; |
108 | pingvin | 909 | ui->comboBox->setEnabled(true); |
910 | |||
911 | |||
912 | } |
||
106 | pingvin | 913 | // if ((rootItem1) == (item) ) ui->comboBox->setEnabled(true); |
214 | pingvin | 914 | else // |
915 | { |
||
215 | pingvin | 916 | QString class_id; |
917 | QString model_id; |
||
918 | QString filtr_str; |
||
221 | pingvin | 919 | QString inctance; |
219 | pingvin | 920 | QStringList conditionList; |
215 | pingvin | 921 | class_id = item->text(1); |
922 | model_id = item->text(6); |
||
221 | pingvin | 923 | inctance = MainWindow::getClassInctance(class_id); |
924 | |||
217 | pingvin | 925 | filtr_str = tr("`Model_ID` = "); |
215 | pingvin | 926 | filtr_str.append(model_id); |
217 | pingvin | 927 | filtr_str.append(tr(" AND `Class_ID` = ")); |
215 | pingvin | 928 | filtr_str.append(class_id); |
217 | pingvin | 929 | // filtr_str.append(tr("`")); |
215 | pingvin | 930 | |
221 | pingvin | 931 | disconnect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
932 | delete filter_model; |
||
223 | pingvin | 933 | /// filter_model = new MyModel(); |
215 | pingvin | 934 | |
221 | pingvin | 935 | filter_model = new QSqlTableModel(); |
227 | pingvin | 936 | filter_model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
937 | |||
221 | pingvin | 938 | connect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
939 | filter_model->setTable(tr("Filters")); |
||
940 | filter_model->setFilter(filtr_str); |
||
226 | pingvin | 941 | |
942 | |||
943 | |||
221 | pingvin | 944 | filter_model->select(); |
226 | pingvin | 945 | |
946 | filter_model->sort(0,Qt::AscendingOrder); |
||
947 | |||
221 | pingvin | 948 | ui->tableView_3->setModel(filter_model); |
215 | pingvin | 949 | |
219 | pingvin | 950 | |
951 | ui->tableView_3->hideColumn(0); |
||
952 | ui->tableView_3->hideColumn(1); |
||
953 | ui->tableView_3->hideColumn(2); |
||
954 | |||
955 | |||
956 | filterSpinDelegate.setClassID(class_id); |
||
957 | filterSpinDelegate.getItems(); |
||
958 | ui->tableView_3->setItemDelegateForColumn(4, &filterSpinDelegate); |
||
959 | |||
224 | pingvin | 960 | // ui->tableView_3->setItemDelegate(); |
219 | pingvin | 961 | conditionList <<"" << "and" << "or" << "(" << "and (" << "or ("; |
962 | filterConditionDelegate.setItems(conditionList); |
||
963 | ui->tableView_3->setItemDelegateForColumn(3, &filterConditionDelegate); |
||
964 | |||
965 | conditionList.clear(); |
||
227 | pingvin | 966 | conditionList <<"" << "=" << "<" << ">" << "IS NULL" << "IS NOT NULL"; |
219 | pingvin | 967 | filterConditionDelegate_1.setItems(conditionList); |
968 | ui->tableView_3->setItemDelegateForColumn(5, &filterConditionDelegate_1); |
||
969 | |||
970 | |||
227 | pingvin | 971 | |
972 | |||
228 | pingvin | 973 | conditionList.clear(); |
974 | conditionList <<"" << ")"; |
||
975 | filterConditionDelegate_2.setItems(conditionList); |
||
976 | ui->tableView_3->setItemDelegateForColumn(7, &filterConditionDelegate_2); |
||
227 | pingvin | 977 | |
224 | pingvin | 978 | ui->tableView_3->setItemDelegateForColumn(6, &filterValueDelegate); |
219 | pingvin | 979 | |
224 | pingvin | 980 | |
981 | |||
982 | |||
217 | pingvin | 983 | ui->pushButton_9->setEnabled(true); |
984 | ui->pushButton_10->setEnabled(true); |
||
985 | |||
215 | pingvin | 986 | ui->comboBox->setEnabled(false); |
987 | |||
988 | |||
214 | pingvin | 989 | } |
106 | pingvin | 990 | } |
110 | pingvin | 991 | |
125 | pingvin | 992 | QMap <QString, QString> MainWindow::getFieldsList(QString class_id){ // |
110 | pingvin | 993 | |
125 | pingvin | 994 | } |
142 | pingvin | 995 | |
996 | |||
997 | void MainWindow::initListModelsTablle(){ |
||
149 | pingvin | 998 | model_for_ListModelsTable = new QSqlTableModel(); |
142 | pingvin | 999 | |
1000 | model_for_ListModelsTable->setTable(tr("ListOfModels")); |
||
146 | pingvin | 1001 | // model_for_ListModelsTable->setEditStrategy(QSqlTableModel::OnFieldChange); |
1002 | model_for_ListModelsTable->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
142 | pingvin | 1003 | ui->tableView_2->setModel(model_for_ListModelsTable); |
151 | pingvin | 1004 | |
142 | pingvin | 1005 | model_for_ListModelsTable->select(); |
151 | pingvin | 1006 | |
223 | pingvin | 1007 | |
151 | pingvin | 1008 | ui->treeWidget->hideColumn(1); |
1009 | ui->treeWidget->hideColumn(2); |
||
1010 | ui->treeWidget->hideColumn(3); |
||
1011 | ui->treeWidget->hideColumn(4); |
||
221 | pingvin | 1012 | // ui->treeWidget->hideColumn(5); |
215 | pingvin | 1013 | ui->treeWidget->hideColumn(6); |
223 | pingvin | 1014 | |
151 | pingvin | 1015 | ui->tableView_2->hideColumn(0); |
1016 | ui->tableView_2->hideColumn(2); |
||
1017 | ui->tableView_2->hideColumn(3); |
||
1018 | ui->tableView_2->hideColumn(4); |
||
1019 | |||
1020 | ui->tableView_2->resizeColumnsToContents(); |
||
1021 | ui->tableView_2->setAlternatingRowColors(true); |
||
1022 | |||
146 | pingvin | 1023 | ui->pushButton_7->setEnabled(false); |
1024 | ui->pushButton_8->setEnabled(false); |
||
151 | pingvin | 1025 | |
1026 | |||
142 | pingvin | 1027 | } |
228 | pingvin | 1028 | |
1029 | void MainWindow::buildReport(bool advanced){ |
||
1030 | |||
1031 | // QTreeWidgetItem * hitm; |
||
1032 | |||
1033 | // hitm = ui->treeWidget_2->headerItem(); |
||
1034 | |||
1035 | // int count = root_items_list.count(); |
||
1036 | |||
1037 | //int count = ui->treeWidget_2->rootIndex(); |
||
1038 | |||
229 | pingvin | 1039 | |
233 | pingvin | 1040 | doc->clear();// |
228 | pingvin | 1041 | |
1042 | int list_count; |
||
1043 | if (rootItems.isEmpty()) return; |
||
1044 | |||
1045 | |||
1046 | |||
1047 | list_count = rootItems.count(); |
||
1048 | |||
1049 | for (int i=0; i < list_count; i++){ |
||
1050 | |||
1051 | getReport(rootItems.at(i), advanced); |
||
1052 | |||
229 | pingvin | 1053 | |
1054 | |||
228 | pingvin | 1055 | } |
233 | pingvin | 1056 | // (bool)QTextDocumentWriter("raport.odt").write(doc); |
228 | pingvin | 1057 | } |
1058 | |||
1059 | |||
1060 | void MainWindow::getReport(QTreeWidgetItem * model_item, bool advanced){ // |
||
1061 | |||
1062 | |||
1063 | // QTextDocument doc; |
||
1064 | // QTextCursor cursor(&doc); |
||
1065 | QTextCharFormat char_fmt; |
||
1066 | bool ok; |
||
1067 | |||
1068 | /************** |
||
1069 | |||
1070 | // char_fmt.setBackground(Qt::red); |
||
1071 | cursor.insertText(tr("1\n"),char_fmt); |
||
1072 | QImage img; |
||
1073 | ok = img.load("./hdd5.png"); |
||
1074 | doc.addResource(QTextDocument::ImageResource, QUrl("myimage"), img); |
||
1075 | cursor.insertImage("myimage"); |
||
1076 | cursor.insertText(tr(" \n"),char_fmt); |
||
1077 | |||
1078 | (bool)QTextDocumentWriter("test.odt").write(&doc); |
||
1079 | ***************/ |
||
1080 | |||
1081 | QString model_name; |
||
1082 | QString rootClassID; |
||
1083 | QString rootClassInctance; |
||
1084 | QFont font; |
||
233 | pingvin | 1085 | QBrush brush; |
228 | pingvin | 1086 | |
233 | pingvin | 1087 | brush.setColor(Qt::darkRed); |
1088 | char_fmt.setForeground(brush); |
||
1089 | font.setBold(true); |
||
1090 | char_fmt.setFont(font); |
||
1091 | |||
228 | pingvin | 1092 | model_name = model_item->text(0); |
1093 | if (model_item->checkState(0) == false) return; // |
||
1094 | |||
1095 | |||
229 | pingvin | 1096 | newPage(); |
1097 | /******************* |
||
1098 | QTextBlockFormat textFormat; |
||
1099 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore); |
||
1100 | cursor->setBlockFormat(textFormat); |
||
1101 | |||
1102 | cursor->insertText(tr(" ")); |
||
1103 | cursor->insertBlock(); |
||
1104 | |||
1105 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_Auto); |
||
1106 | cursor->setBlockFormat(textFormat); |
||
1107 | ********************/ |
||
1108 | |||
1109 | |||
1110 | |||
228 | pingvin | 1111 | if (!(model_item->childCount() > 0)) return; // ( ) |
1112 | |||
1113 | rootClassID = model_item->child(0)->text(1); |
||
1114 | rootClassInctance = getClassInctance(rootClassID); |
||
1115 | |||
233 | pingvin | 1116 | cursor->insertText(model_name, char_fmt); |
228 | pingvin | 1117 | cursor->insertText(tr("\n")); |
1118 | |||
1119 | if (model_item->child(0)->checkState(0)) // ( ), |
||
1120 | { |
||
1121 | ///// QTreeWidgetItem * item_tmp; |
||
1122 | ///// item_tmp = new QTreeWidgetItem(item); // , , |
||
1123 | ///// item_tmp->setText(0, model_item->child(0)->text(0)); // |
||
1124 | |||
1125 | //showClassObjects(item_tmp, model_item->child(0)); // |
||
1126 | |||
1127 | ///// showObjects(item_tmp, model_item->child(0), tr("")); |
||
1128 | printChild(model_item->child(0), tr(""), advanced, 1); |
||
230 | pingvin | 1129 | |
228 | pingvin | 1130 | } |
1131 | |||
1132 | |||
1133 | |||
1134 | |||
1135 | } |
||
1136 | |||
1137 | void MainWindow::printChild(QTreeWidgetItem * model_item, QString filtr, bool advanced, int pos){// |
||
1138 | QString classID; // |
||
1139 | QString parentClassID; // |
||
1140 | QString pointerField; // - |
||
1141 | QString inctance; // , |
||
1142 | QString className; // |
||
1143 | QString modelID; // |
||
1144 | QString add_filtr; // |
||
1145 | int field_ID; |
||
1146 | int icon_field_index; |
||
1147 | bool filtr_empty; |
||
1148 | bool ok; |
||
1149 | QSqlQuery q; |
||
1150 | QString sql_str; |
||
1151 | QString str_tmp; |
||
1152 | QTreeWidgetItem * title_item; |
||
233 | pingvin | 1153 | |
228 | pingvin | 1154 | QIcon icon; |
230 | pingvin | 1155 | QMap<QString, QString> fieldsTypesList;// , |
1156 | //QList<TField> FieldsList; // |
||
228 | pingvin | 1157 | |
229 | pingvin | 1158 | |
1159 | |||
1160 | |||
233 | pingvin | 1161 | // // // font.setBold(true); |
228 | pingvin | 1162 | filtr_empty = filtr.isEmpty(); |
1163 | |||
1164 | classID = model_item->text(1); |
||
1165 | modelID = model_item->text(6); |
||
1166 | add_filtr = MainWindow::getFiltrString(modelID, classID); |
||
1167 | |||
1168 | |||
1169 | icon = model_item->icon(0); |
||
1170 | |||
1171 | parentClassID = model_item->parent()->text(1); |
||
1172 | |||
1173 | pointerField = getPointerFieldName(parentClassID, classID); |
||
1174 | |||
1175 | className = model_item->text(0); |
||
1176 | inctance = getClassInctance(classID); |
||
1177 | |||
1178 | if (!model_item->checkState(0)) return; |
||
1179 | |||
1180 | |||
229 | pingvin | 1181 | |
1182 | |||
233 | pingvin | 1183 | QTextCharFormat charFormatItalic, charFormatBase, charFormatItalicBold, charFormatItalicOnly; |
1184 | QTextTableFormat tableFormat; |
||
1185 | |||
1186 | |||
1187 | // QPen pen; |
||
1188 | QBrush brush; |
||
1189 | QFont font; |
||
1190 | // pen.setColor(Qt::red); |
||
1191 | // charFormatItalic.setTextOutline(pen); |
||
1192 | |||
229 | pingvin | 1193 | //QFont font; |
233 | pingvin | 1194 | |
1195 | brush.setColor(Qt::blue); |
||
1196 | |||
229 | pingvin | 1197 | font.setItalic(true); |
233 | pingvin | 1198 | |
1199 | charFormatItalicOnly.setFont(font); |
||
229 | pingvin | 1200 | //charFormatItalic.setFontItalic(true); |
233 | pingvin | 1201 | |
1202 | font.setBold(true);///////////////// |
||
229 | pingvin | 1203 | charFormatItalic.setFont(font); |
233 | pingvin | 1204 | |
1205 | |||
1206 | charFormatItalic.setForeground(brush); |
||
1207 | |||
1208 | |||
1209 | |||
1210 | charFormatItalicBold.setFont(font); |
||
1211 | charFormatItalicBold.setForeground(brush); |
||
1212 | |||
1213 | |||
1214 | |||
229 | pingvin | 1215 | //charFormatItalic.setFontWeight(16); |
1216 | pos++; |
||
1217 | for(int i=0; i<pos; i++){ cursor->insertText( tr(" "));}// |
||
1218 | cursor->insertText(className, charFormatItalic); |
||
1219 | cursor->setCharFormat(charFormatBase); |
||
228 | pingvin | 1220 | cursor->insertText(tr("\n")); |
1221 | |||
229 | pingvin | 1222 | |
1223 | |||
228 | pingvin | 1224 | sql_str = tr("select * " |
1225 | " from " // - |
||
1226 | ); |
||
1227 | sql_str.append(inctance); |
||
1228 | |||
1229 | |||
1230 | if (filtr.isEmpty() && (!add_filtr.isEmpty())) // , |
||
1231 | { |
||
1232 | filtr.append(tr ("where ")); |
||
1233 | filtr.append(add_filtr); |
||
1234 | } |
||
1235 | |||
1236 | |||
1237 | if (!filtr.isEmpty()) { // |
||
1238 | sql_str.append(tr(" ")); |
||
1239 | sql_str.append(filtr); // |
||
1240 | } |
||
1241 | |||
1242 | q.prepare(sql_str); |
||
1243 | |||
1244 | ok = q.exec(); |
||
1245 | |||
1246 | if (!ok) { |
||
1247 | QString debug_str; |
||
1248 | debug_str.append(tr(" showObjects(): Database Error ")); |
||
1249 | debug_str.append(tr(" : ")); |
||
1250 | debug_str.append(inctance); |
||
1251 | debug_str.append(tr(" : ")); |
||
1252 | debug_str.append(filtr); |
||
1253 | debug_str.append(q.lastError().text()); |
||
1254 | QMessageBox::critical( // . |
||
1255 | this, // . |
||
1256 | QObject::tr(" showObjects(): Database Error"), // . |
||
1257 | debug_str |
||
1258 | // q.lastError().text() |
||
1259 | ); // . |
||
1260 | return; |
||
1261 | } |
||
1262 | |||
1263 | field_ID = q.record().indexOf(tr("ID")); |
||
1264 | |||
1265 | icon_field_index = q.record().indexOf(tr("Icon")); |
||
1266 | |||
229 | pingvin | 1267 | int k=0; |
1268 | QStringList fieldsNamesList;// |
||
230 | pingvin | 1269 | QList<TField> FieldsList; // |
231 | pingvin | 1270 | QMap<QString, TField> fieldsMap;// , - |
1271 | QMap <QString, QString> fieldsValues;// , |
||
230 | pingvin | 1272 | FieldsList = getFieldList(classID); // |
228 | pingvin | 1273 | |
1274 | |||
231 | pingvin | 1275 | |
1276 | |||
1277 | |||
230 | pingvin | 1278 | if(FieldsList.count()>0){ |
1279 | for(int i=0; i < FieldsList.count(); i++){ // ( - ) |
||
1280 | fieldsTypesList.insert(FieldsList.at(i).FieldName, FieldsList.at(i).FieldType); |
||
231 | pingvin | 1281 | fieldsMap.insert(FieldsList.at(i).FieldName, FieldsList.at(i)); |
230 | pingvin | 1282 | } |
229 | pingvin | 1283 | |
230 | pingvin | 1284 | // fieldsNamesList = fieldsTypesList.keys(); // |
1285 | } |
||
1286 | |||
1287 | // icon_field_index = fieldsNamesList.indexOf(tr("Icon"));// |
||
1288 | |||
1289 | |||
1290 | |||
229 | pingvin | 1291 | while(!q.record().fieldName(k).isEmpty()){// |
1292 | fieldsNamesList.append(q.record().fieldName(k++)); |
||
1293 | } |
||
1294 | |||
1295 | |||
230 | pingvin | 1296 | //icon_field_index = fieldsNamesList.indexOf(tr("Icon"));// |
1297 | |||
1298 | |||
228 | pingvin | 1299 | while(q.next()){ |
1300 | if (q.record().count() > 1) |
||
1301 | { |
||
1302 | QString value_tmp; |
||
1303 | QString ID_tmp; |
||
1304 | QString space; |
||
1305 | |||
1306 | // // // // QTreeWidgetItem * itm; |
||
1307 | ID_tmp = q.value(field_ID).toString(); // |
||
1308 | value_tmp = q.value(1).toString(); // ( ) |
||
1309 | // itm = new QTreeWidgetItem(parent_object_item); // , |
||
1310 | |||
1311 | |||
1312 | |||
1313 | |||
1314 | /*************************** |
||
1315 | itm = new QTreeWidgetItem(title_item); // , |
||
1316 | itm->setText(0, value_tmp); |
||
1317 | itm->setText(1, tr("object")); |
||
1318 | itm->setText(2, ID_tmp); |
||
1319 | ******************************/ |
||
1320 | |||
1321 | if (icon_field_index != -1){ // |
||
1322 | |||
1323 | QVariant data; |
||
1324 | QByteArray bytes; |
||
1325 | QPixmap pix; |
||
1326 | QIcon icn; |
||
1327 | QMap <QString, QPixmap> pixmap_map; |
||
1328 | QList <QString> id_list; |
||
1329 | QList <QPixmap> pixmap_list; |
||
1330 | pixmap_map = MainWindow::getObjectsIcon(inctance); |
||
1331 | if (!pixmap_map.isEmpty()) { |
||
1332 | id_list = pixmap_map.keys(); |
||
1333 | pixmap_list = pixmap_map.values(); |
||
1334 | } |
||
1335 | if (id_list.indexOf(ID_tmp) != -1) { |
||
1336 | pix = pixmap_list.at(id_list.indexOf(ID_tmp)); |
||
1337 | } |
||
1338 | // data = q.record().value(icon_field_index); |
||
1339 | // bytes = q.record().value(icon_field_index).toByteArray(); |
||
1340 | // if (data.isValid() && (!data.isNull())) { |
||
1341 | // if (!bytes.isEmpty()){ |
||
1342 | // pix.loadFromData(data.toByteArray()); |
||
1343 | // pix.loadFromData(bytes); |
||
1344 | |||
1345 | |||
1346 | if(!pix.isNull()) { |
||
1347 | if (pix.height() > 128) pix = pix.scaledToHeight(128); |
||
1348 | QString fname = value_tmp; |
||
1349 | fname.append(tr(".png")); |
||
1350 | |||
1351 | |||
1352 | pix.toImage().save(fname); |
||
233 | pingvin | 1353 | doc->addResource(QTextDocument::ImageResource, QUrl(fname), pix.toImage()); |
228 | pingvin | 1354 | |
1355 | // for(int i=0; i<pos; i++){ cursor->insertText( tr(" "));}// |
||
1356 | |||
1357 | |||
229 | pingvin | 1358 | for(int i=0; i<pos+1; i++){ cursor->insertText( tr(" "));}// |
228 | pingvin | 1359 | cursor->insertImage(fname); |
1360 | // cursor->insertText(tr("\n")); |
||
1361 | |||
1362 | } |
||
229 | pingvin | 1363 | else for(int i=0; i<pos+1; i++){ cursor->insertText( tr(" "));}// |
228 | pingvin | 1364 | |
1365 | |||
1366 | |||
1367 | |||
1368 | // // // icn.addPixmap(pix); |
||
1369 | // // // itm->setIcon(0, icn); |
||
1370 | // } |
||
1371 | |||
1372 | |||
1373 | } |
||
1374 | |||
229 | pingvin | 1375 | else for(int i=0; i<pos+1; i++){ cursor->insertText( tr(" "));}// |
228 | pingvin | 1376 | cursor->insertText( value_tmp); |
1377 | cursor->insertText( tr("\n")); |
||
1378 | |||
229 | pingvin | 1379 | |
1380 | |||
230 | pingvin | 1381 | // q.first(); |
229 | pingvin | 1382 | |
1383 | |||
230 | pingvin | 1384 | if(advanced && (fieldsNamesList.count()>0)){ // |
1385 | |||
1386 | QString tmp_string; |
||
229 | pingvin | 1387 | sql_str.clear(); |
1388 | |||
231 | pingvin | 1389 | // // // QTextTable *table = cursor->insertTable(fieldsNamesList.count()-2, 2);// , (ID ) |
229 | pingvin | 1390 | |
1391 | |||
230 | pingvin | 1392 | |
231 | pingvin | 1393 | /************************ |
1394 | QTextTable *table = cursor->insertTable(fieldsNamesList.count(), 2);// , (ID ) |
||
1395 | |||
1396 | ************************/ |
||
1397 | |||
1398 | |||
1399 | |||
1400 | |||
1401 | |||
1402 | |||
1403 | |||
1404 | |||
1405 | |||
1406 | |||
1407 | // cursor->insertText(tr(" ")); |
||
1408 | |||
1409 | |||
230 | pingvin | 1410 | // *cursor = table->cellAt(0,1).firstCursorPosition(); |
1411 | // cursor->insertText(tr(" 2")); |
||
1412 | // *cursor = table->cellAt(1,1).lastCursorPosition(); |
||
1413 | // cursor->insertText(tr(" 4")); |
||
1414 | |||
1415 | |||
1416 | // cursor->movePosition(QTextCursor::End); |
||
1417 | |||
1418 | |||
1419 | |||
1420 | //table->cellAt(1,1).firstCursorPosition().insertText(tr("1")); |
||
1421 | //table->cellAt(1,2).firstCursorPosition().insertText(tr("2")); |
||
1422 | //table->cellAt(2,1).firstCursorPosition().insertText(tr("3")); |
||
1423 | |||
1424 | //table->cellAt(2,2).firstCursorPosition().insertText(tr("4")); |
||
1425 | // cursor->insertText(tr("1 \t 2")); |
||
1426 | // cursor->insertText(tr("3 \t 4")); |
||
1427 | |||
231 | pingvin | 1428 | for(int i=0; i < fieldsNamesList.count(); i++) |
1429 | { |
||
230 | pingvin | 1430 | |
231 | pingvin | 1431 | |
1432 | if (fieldsNamesList.at(i)== tr("Icon") || fieldsNamesList.at(i)== tr("ID")) { tmp_string = tr(" "); |
||
1433 | continue; |
||
1434 | } |
||
1435 | |||
1436 | QString fieldType; |
||
1437 | fieldType = fieldsTypesList.value(fieldsNamesList.at(i)); // |
||
1438 | if(fieldType == tr("pointer")) // - |
||
1439 | { |
||
1440 | QSqlQuery q_tmp; |
||
1441 | QString sql_str; |
||
1442 | // QString val_str; |
||
1443 | QString parent_class_id;// , |
||
1444 | QString parent_class_inctance; // |
||
1445 | bool ok; |
||
1446 | TField field_tmp; |
||
1447 | field_tmp = fieldsMap.value(fieldsNamesList.at(i)); |
||
1448 | parent_class_id = field_tmp.DefaultValue; |
||
1449 | if (parent_class_id.isEmpty()) continue; // id |
||
1450 | else parent_class_inctance = getClassInctance(parent_class_id); |
||
1451 | if (parent_class_inctance.isEmpty()) continue; // id |
||
1452 | sql_str = tr("select * from `"); |
||
1453 | sql_str.append(parent_class_inctance); |
||
1454 | sql_str.append(tr("` where `ID` = '")); |
||
1455 | sql_str.append(q.record().value(i).asString()); |
||
1456 | sql_str.append(tr("'")); |
||
1457 | ok = q_tmp.prepare(sql_str); |
||
1458 | ok = q_tmp.exec(); |
||
1459 | |||
1460 | if (!ok) { |
||
1461 | QString debug_str; |
||
1462 | debug_str.append(tr(" showObjects(): Database Error ")); |
||
1463 | debug_str.append(tr(" : ")); |
||
1464 | debug_str.append(inctance); |
||
1465 | debug_str.append(tr(" : ")); |
||
1466 | debug_str.append(filtr); |
||
1467 | debug_str.append(q.lastError().text()); |
||
1468 | QMessageBox::critical( // . |
||
1469 | this, // . |
||
1470 | QObject::tr(" showObjects(): Database Error"), // . |
||
1471 | debug_str |
||
1472 | // q.lastError().text() |
||
1473 | ); // . |
||
1474 | return; |
||
1475 | } |
||
1476 | |||
1477 | tmp_string.clear(); |
||
1478 | while (q_tmp.next()){ |
||
1479 | tmp_string = q_tmp.record().value(1).asString(); |
||
1480 | |||
1481 | } |
||
1482 | |||
1483 | fieldsValues.insert(fieldsNamesList.at(i), tmp_string);// |
||
1484 | |||
1485 | continue;// |
||
1486 | |||
1487 | } // pointer |
||
1488 | |||
1489 | if(fieldType == tr("file")){ // - , |
||
1490 | |||
1491 | tmp_string = tr(" "); |
||
1492 | continue; |
||
1493 | |||
1494 | } |
||
1495 | |||
1496 | tmp_string = q.record().value(i).asString(); // , -, |
||
1497 | fieldsValues.insert(fieldsNamesList.at(i), tmp_string);// |
||
1498 | |||
1499 | |||
1500 | } |
||
1501 | |||
1502 | |||
1503 | |||
1504 | |||
1505 | |||
233 | pingvin | 1506 | // for(int i=0; i<pos+1; i++){ cursor->insertText( tr(" "));}// |
1507 | tableFormat.setAlignment(Qt::AlignLeft); |
||
1508 | tableFormat.setBackground(QColor("#e0e0e0")); |
||
1509 | // tableFormat.setCellPadding(2); |
||
1510 | // tableFormat.setCellSpacing(4); |
||
1511 | tableFormat.setLeftMargin(pos*7); |
||
1512 | tableFormat.setBorder(1); |
||
1513 | tableFormat.setBorderStyle( QTextFrameFormat::BorderStyle_Solid); |
||
231 | pingvin | 1514 | |
233 | pingvin | 1515 | QTextTable *table = cursor->insertTable(fieldsValues.count(), 2, tableFormat);// , (ID ) |
1516 | // table->setFormat(tableFormat); |
||
1517 | |||
1518 | |||
1519 | for(int i=0; i < fieldsValues.count(); i++){ // : ID , ( ) |
||
231 | pingvin | 1520 | QStringList keys_list = fieldsValues.keys(); |
1521 | QStringList values_list = fieldsValues.values(); |
||
1522 | *cursor = table->cellAt(i,0).firstCursorPosition();// i-, |
||
233 | pingvin | 1523 | cursor->insertText(keys_list.at(i), charFormatItalicOnly);// |
231 | pingvin | 1524 | *cursor = table->cellAt(i,1).firstCursorPosition();// i-, |
1525 | cursor->insertText(values_list.at(i));// |
||
1526 | } |
||
1527 | |||
233 | pingvin | 1528 | // table->setFormat(tableFormat); |
1529 | cursor->movePosition(QTextCursor::End);// |
||
231 | pingvin | 1530 | cursor->insertText( tr("\n")); |
1531 | |||
1532 | |||
1533 | |||
1534 | /****************************** |
||
1535 | |||
1536 | table = cursor->insertTable(fieldsNamesList.count(), 2);// , (ID ) |
||
1537 | |||
230 | pingvin | 1538 | for(int i=2; i < fieldsNamesList.count(); i++){ // : ID , ( ) |
1539 | // if (i !=icon_field_index) tmp_string = q.record().value(i).asString(); // , |
||
1540 | if (i !=icon_field_index) tmp_string = q.record().value(i).asString(); // , |
||
1541 | |||
1542 | |||
1543 | else tmp_string = tr(" "); |
||
1544 | //// if (i !=icon_field_index) { |
||
1545 | for(int i=0; i<pos+2; i++){ cursor->insertText( tr(" "));}// |
||
1546 | *cursor = table->cellAt(i-2,0).firstCursorPosition();// i-, |
||
1547 | cursor->insertText( fieldsNamesList.at(i));// |
||
1548 | *cursor = table->cellAt(i-2,1).firstCursorPosition();// i-, |
||
1549 | //cursor->insertText( tr(":\t")); |
||
1550 | |||
1551 | cursor->insertText(tmp_string);// |
||
1552 | // cursor->insertText( tr("\n")); |
||
1553 | } |
||
1554 | |||
1555 | //// } |
||
231 | pingvin | 1556 | |
1557 | |||
1558 | |||
1559 | |||
1560 | |||
1561 | |||
1562 | |||
1563 | |||
1564 | |||
1565 | |||
230 | pingvin | 1566 | cursor->movePosition(QTextCursor::End);// |
1567 | cursor->insertText( tr("\n")); |
||
231 | pingvin | 1568 | |
1569 | *********************************/ |
||
1570 | |||
229 | pingvin | 1571 | } |
1572 | |||
1573 | |||
1574 | |||
1575 | /******************************************************** |
||
1576 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore); |
||
1577 | cursor->setBlockFormat(textFormat); |
||
1578 | |||
1579 | cursor->insertText(tr(" ")); |
||
1580 | cursor->insertBlock(); |
||
1581 | |||
1582 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_Auto); |
||
1583 | cursor->setBlockFormat(textFormat); |
||
1584 | **********************************************************/ |
||
1585 | |||
1586 | |||
228 | pingvin | 1587 | // itm->setIcon(0, icon); |
1588 | |||
1589 | |||
1590 | for (int i=0; i < model_item->childCount(); i++) // , |
||
1591 | { |
||
1592 | QTreeWidgetItem * model_item_tmp; // |
||
1593 | QString pointer_name; |
||
1594 | QString filtr_tmp; |
||
1595 | bool pointer_isEmpty; |
||
1596 | model_item_tmp = model_item->child(i); // |
||
1597 | pointer_name = getPointerFieldName(classID, model_item->child(i)->text(1)); |
||
1598 | // // // // itm->setText(4, pointer_name); |
||
1599 | |||
1600 | // title_item->setText(4, pointer_name); |
||
1601 | |||
1602 | |||
1603 | pointer_isEmpty = pointer_name.isEmpty(); |
||
1604 | filtr_tmp = tr("where "); |
||
1605 | filtr_tmp.append(tr("`")); |
||
1606 | filtr_tmp.append(pointer_name); |
||
1607 | filtr_tmp.append(tr("` = '")); |
||
1608 | filtr_tmp.append(ID_tmp); |
||
1609 | filtr_tmp.append(tr("'")); |
||
229 | pingvin | 1610 | |
1611 | printChild(model_item_tmp, filtr_tmp, advanced, pos+1); |
||
1612 | |||
228 | pingvin | 1613 | // // // // showObjects(itm, model_item_tmp, filtr_tmp); |
1614 | //MainWindow::showObjectChildrens(ID_tmp, itm, model_item_tmp); |
||
1615 | |||
1616 | } |
||
233 | pingvin | 1617 | // if(pos==2) newPage(); // , |
228 | pingvin | 1618 | |
1619 | } |
||
1620 | |||
1621 | } |
||
1622 | |||
1623 | |||
1624 | |||
1625 | |||
1626 | |||
1627 | |||
1628 | |||
1629 | |||
1630 | |||
1631 | |||
1632 | } |
||
1633 | |||
1634 | |||
229 | pingvin | 1635 | void MainWindow::newPage(int page_number){ // |
1636 | |||
1637 | QTextBlockFormat textFormat; |
||
1638 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore); |
||
1639 | cursor->setBlockFormat(textFormat); |
||
1640 | |||
1641 | cursor->insertText(tr(" %1").arg(page_number)); |
||
1642 | cursor->insertBlock(); |
||
1643 | |||
1644 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_Auto); |
||
1645 | cursor->setBlockFormat(textFormat); |
||
1646 | |||
1647 | |||
1648 | } |
||
1649 | void MainWindow::newPage(){ // |
||
1650 | |||
1651 | QTextBlockFormat textFormat; |
||
1652 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore); |
||
1653 | cursor->setBlockFormat(textFormat); |
||
1654 | |||
1655 | //cursor->insertText(tr(" %1").arg(page_number)); |
||
1656 | cursor->insertBlock(); |
||
1657 | |||
1658 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_Auto); |
||
1659 | cursor->setBlockFormat(textFormat); |
||
1660 | |||
1661 | |||
1662 | } |
||
230 | pingvin | 1663 | |
1664 | QList<TField> MainWindow::getFieldList(QString class_id){// |
||
1665 | |||
1666 | QSqlQuery q; |
||
1667 | QString sql_str; |
||
1668 | QList<TField> result_list; |
||
1669 | |||
1670 | int field_id, field_name, field_alias, field_type, field_default_value, field_classIdentifer, field_comment; |
||
1671 | |||
1672 | bool ok; |
||
1673 | sql_str = tr("select * " |
||
1674 | " from `DescriptionOfClasses` where `DescriptionOfClasses`.`ClassIdentifer` = " // - |
||
1675 | ); |
||
1676 | |||
1677 | sql_str.append(tr("'")); |
||
1678 | sql_str.append(class_id); |
||
1679 | sql_str.append(tr("' ")); |
||
1680 | ok = q.prepare(sql_str); |
||
1681 | |||
1682 | ok = q.exec(); |
||
1683 | if (!ok) { |
||
1684 | QMessageBox::critical( // . |
||
1685 | this, // . |
||
1686 | QObject::tr("Database Error"), // . |
||
1687 | q.lastError().text()); // . |
||
1688 | return result_list; |
||
1689 | } |
||
1690 | |||
1691 | |||
1692 | field_id = q.record().indexOf(tr("ID")); |
||
1693 | field_name = q.record().indexOf(tr("FieldName")); |
||
1694 | field_alias = q.record().indexOf(tr("FieldAlias")); |
||
1695 | field_type = q.record().indexOf(tr("FieldType")); |
||
1696 | field_default_value = q.record().indexOf(tr("DefaultValue")); |
||
1697 | field_classIdentifer = q.record().indexOf(tr("ClassIdentifer")); |
||
1698 | field_comment = q.record().indexOf(tr("Comment")); |
||
1699 | |||
1700 | while(q.next()){ |
||
1701 | |||
1702 | TField field_tmp; |
||
1703 | field_tmp.ID = q.value(field_id).toString(); |
||
1704 | field_tmp.FieldName = q.value(field_name).toString(); |
||
1705 | field_tmp.FieldAlias = q.value(field_alias).toString(); |
||
1706 | field_tmp.FieldType = q.value(field_type).toString(); |
||
1707 | field_tmp.DefaultValue = q.value(field_default_value).toString(); |
||
1708 | field_tmp.ClassIdentifer = q.value(field_classIdentifer).toString(); |
||
1709 | field_tmp.Comment = q.value(field_comment).toString(); |
||
1710 | result_list << field_tmp; |
||
1711 | |||
1712 | |||
1713 | |||
1714 | |||
1715 | // parentClassID = q.value(field_default_value).toString(); |
||
1716 | // parentClassInctance = getClassInctance(parentClassID); |
||
1717 | // result_map.insert(pointerFieldName, parentClassInctance); |
||
1718 | |||
1719 | |||
1720 | |||
1721 | } |
||
1722 | |||
1723 | return result_list; |
||
1724 | |||
1725 | } |
||
238 | pingvin | 1726 | |
1727 | |||
1728 | |||
1729 | void MainWindow::readStandartProcessOutput(){ |
||
1730 | |||
1731 | QTextDocument * wmiDoc = ui->textEdit_2->document(); |
||
1732 | QTextCursor * wmiCursor; |
||
1733 | wmiCursor = new QTextCursor(wmiDoc); |
||
1734 | |||
1735 | QByteArray arr; |
||
1736 | QStringList result, fields, values; |
||
1737 | QString str1, str2; |
||
1738 | int i; |
||
1739 | arr = wmiProcess.readAllStandardOutput(); |
||
1740 | QTextCodec *codecUTF = QTextCodec::codecForName("utf8"); |
||
1741 | QTextCodec *codec = QTextCodec::codecForName("cp1251"); |
||
1742 | QTextCodec::setCodecForTr(codecUTF); |
||
1743 | str1 = QString(tr(arr)); |
||
1744 | result = str1.split("\n", QString::SkipEmptyParts); |
||
1745 | if (result.count()>2){ |
||
1746 | |||
1747 | |||
1748 | |||
1749 | |||
1750 | QString tmp_str; |
||
1751 | QTextTable * wmi_table; |
||
1752 | int fields_count, row_count; |
||
1753 | tmp_str = result.at(1); |
||
1754 | fields = tmp_str.split("|"); |
||
1755 | fields_count = fields.count(); |
||
1756 | row_count = result.count()-1; // ( ) |
||
1757 | wmi_table = wmiCursor->insertTable(row_count, fields_count); |
||
1758 | for(int n = 0; n < fields.count(); n++) { // "" |
||
1759 | *wmiCursor = wmi_table->cellAt(0, n).firstCursorPosition(); |
||
1760 | wmiCursor->insertText(fields.at(n)); |
||
1761 | } |
||
1762 | // tmp_str = result.at(2); |
||
1763 | // values = tmp_str.split("|"); |
||
1764 | |||
1765 | |||
1766 | for (int m=2; m< result.count(); m++){ |
||
1767 | |||
1768 | tmp_str = result.at(m); |
||
1769 | values = tmp_str.split("|"); |
||
1770 | |||
1771 | for(int n = 0; n < values.count(); n++){ |
||
1772 | *wmiCursor = wmi_table->cellAt(m-1, n).firstCursorPosition(); |
||
1773 | |||
1774 | // wmiCursor->insertText(fields.at(n)); |
||
1775 | // wmiCursor->insertText(tr(": ")); |
||
1776 | wmiCursor->insertText(values.at(n)); |
||
1777 | // wmiCursor->insertText(tr("\n")); |
||
1778 | |||
1779 | } |
||
1780 | |||
1781 | |||
1782 | |||
1783 | } |
||
1784 | |||
1785 | |||
1786 | |||
1787 | } |
||
1788 | QTextCodec::setCodecForTr(codec); |
||
1789 | |||
1790 | |||
1791 | |||
1792 | |||
1793 | |||
1794 | |||
1795 | |||
1796 | |||
1797 | |||
1798 | // result = QStringList(arr); |
||
1799 | // str2 << arr; |
||
1800 | //i = result.size(); |
||
1801 | // str1 = result.at(0); |
||
1802 | i++; |
||
1803 | //lineEdit->insert(str1); |
||
241 | pingvin | 1804 | all_reading = true; |
238 | pingvin | 1805 | |
1806 | } |
||
1807 | |||
1808 | void MainWindow::readStandartProcessError(){ |
||
241 | pingvin | 1809 | QTextDocument * wmiDoc = ui->textEdit_2->document(); |
1810 | QTextCursor * wmiCursor; |
||
1811 | wmiCursor = new QTextCursor(wmiDoc); |
||
1812 | QString str; |
||
1813 | |||
1814 | QByteArray arr; |
||
238 | pingvin | 1815 | arr = wmiProcess.readAllStandardError(); |
241 | pingvin | 1816 | str = QString(tr(arr)); |
1817 | wmiCursor->insertText(str); |
||
1818 | wmiCursor->insertText(tr("\n")); |
||
238 | pingvin | 1819 | |
1820 | } |
||
241 | pingvin | 1821 | |
1822 | |||
1823 | |||
1824 | TWmiVideoCard MainWindow::getWmiVideoGard(QString host, QString user_name, QString password){ |
||
1825 | TWmiVideoCard result; |
||
1826 | bool ok; |
||
248 | pingvin | 1827 | QString ansver_string; |
243 | pingvin | 1828 | // wmiThread.moveToThread(&wmiThread); |
242 | pingvin | 1829 | wmiThread.setHost(host); // |
1830 | wmiThread.setUser(user_name);// |
||
1831 | wmiThread.setPassword( password); |
||
248 | pingvin | 1832 | wmiThread.setWmiString(tr("select Name, AdapterCompatibility, AdapterRAM, VideoProcessor from Win32_VideoController")); |
242 | pingvin | 1833 | wmiThread.start(QThread::NormalPriority); |
1834 | //for (;;) {if (wmiThread.isStopped()) break;} |
||
1835 | int t; |
||
1836 | t++; |
||
1837 | |||
1838 | |||
1839 | ok = wmiThread.wait(10000); |
||
241 | pingvin | 1840 | if (ok){ |
248 | pingvin | 1841 | QTextDocument * wmiDoc = ui->textEdit_2->document(); |
1842 | QTextCursor * wmiCursor; |
||
1843 | QStringList split_new_line; // |
||
1844 | QStringList fields_list; // |
||
1845 | QStringList values_list; // - |
||
1846 | wmiCursor = new QTextCursor(wmiDoc); |
||
1847 | ansver_string = wmiThread.resultString(); |
||
1848 | wmiCursor->insertText(ansver_string); |
||
1849 | split_new_line = ansver_string.split("\n", QString::SkipEmptyParts); // |
||
1850 | if(split_new_line.count()>2) { |
||
1851 | QString tmp_str; |
||
1852 | tmp_str = split_new_line.at(1); |
||
1853 | fields_list = tmp_str.split("|"); |
||
1854 | tmp_str = split_new_line.at(2); |
||
1855 | values_list = tmp_str.split("|"); |
||
1856 | int index_tmp; |
||
1857 | index_tmp = fields_list.indexOf(tr("AdapterCompatibility")); // |
||
249 | pingvin | 1858 | if ((index_tmp!=-1) && (index_tmp < values_list.count())) result.manufacturer = values_list.at(index_tmp); |
248 | pingvin | 1859 | index_tmp = fields_list.indexOf(tr("Name")); // |
249 | pingvin | 1860 | if ((index_tmp!=-1) && (index_tmp < values_list.count())) result.name = values_list.at(index_tmp); |
248 | pingvin | 1861 | index_tmp = fields_list.indexOf(tr("VideoProcessor")); // |
249 | pingvin | 1862 | if ((index_tmp!=-1) && (index_tmp < values_list.count())) result.model = values_list.at(index_tmp); |
248 | pingvin | 1863 | index_tmp = fields_list.indexOf(tr("AdapterRAM")); // |
249 | pingvin | 1864 | if ((index_tmp!=-1) && (index_tmp < values_list.count())) result.video_ram = QVariant(values_list.at(index_tmp)).asInt(); |
248 | pingvin | 1865 | return result; |
1866 | } |
||
1867 | else return result; // |
||
241 | pingvin | 1868 | int m; |
1869 | m++; |
||
1870 | } |
||
1871 | else { |
||
256 | pingvin | 1872 | |
1873 | wmiThread.terminate(); |
||
1874 | /********************* |
||
242 | pingvin | 1875 | wmiThread.stop(); |
1876 | ok = wmiThread.wait(10000); |
||
241 | pingvin | 1877 | int k; |
1878 | k++; |
||
256 | pingvin | 1879 | **********************/ |
241 | pingvin | 1880 | } |
1881 | |||
1882 | /* |
||
1883 | |||
1884 | QString program = tr("wmic"); |
||
1885 | QStringList arguments; |
||
1886 | |||
1887 | // arguments << tr(" -U %Patr10t //192.168.0.135 \"select * from Win32_ComputerSystem\""); |
||
1888 | // program.append(tr(" -U %Patr10t //192.168.0.135 \"select * from Win32_ComputerSystem\"")); |
||
1889 | program.append(tr(" -U admin --password=samba //192.168.0.101 \"select * from ")); //Win32_Product\"")); |
||
1890 | program.append(ui->comboBox_2->currentText()); |
||
1891 | program.append(tr("\"")); |
||
1892 | all_reading = false; |
||
1893 | int i; |
||
1894 | i++; |
||
1895 | wmiProcess.start(program); |
||
1896 | |||
1897 | |||
1898 | |||
1899 | while (!all_reading){}; //, |
||
1900 | |||
1901 | */ |
||
1902 | return result; |
||
1903 | |||
1904 | } |
||
251 | pingvin | 1905 | |
1906 | |||
1907 | TWmiMatherBoard MainWindow::getWmiMatherBoard(QString host, QString user_name, QString password){ |
||
1908 | TWmiMatherBoard result; |
||
1909 | bool ok; |
||
1910 | QString ansver_string; |
||
1911 | wmiThread.setHost(host); // |
||
1912 | wmiThread.setUser(user_name);// |
||
1913 | wmiThread.setPassword( password); |
||
1914 | wmiThread.setWmiString(tr("SELECT Manufacturer, Product FROM Win32_BaseBoard")); |
||
1915 | wmiThread.start(QThread::NormalPriority); |
||
1916 | ok = wmiThread.wait(10000); |
||
1917 | |||
1918 | if (ok){ |
||
1919 | QTextDocument * wmiDoc = ui->textEdit_2->document(); |
||
1920 | QTextCursor * wmiCursor; |
||
1921 | QStringList split_new_line; // |
||
1922 | QStringList fields_list; // |
||
1923 | QStringList values_list; // - |
||
1924 | wmiCursor = new QTextCursor(wmiDoc); |
||
1925 | ansver_string = wmiThread.resultString(); |
||
1926 | wmiCursor->insertText(ansver_string); |
||
1927 | split_new_line = ansver_string.split("\n", QString::SkipEmptyParts); // |
||
1928 | if(split_new_line.count()>2) { |
||
1929 | QString tmp_str; |
||
1930 | tmp_str = split_new_line.at(1); |
||
1931 | fields_list = tmp_str.split("|"); |
||
1932 | tmp_str = split_new_line.at(2); |
||
1933 | values_list = tmp_str.split("|"); |
||
1934 | int index_tmp; |
||
1935 | index_tmp = fields_list.indexOf(tr("Manufacturer")); // |
||
1936 | if ((index_tmp!=-1) && (index_tmp < values_list.count())) result.manufacturer = values_list.at(index_tmp); |
||
1937 | // index_tmp = fields_list.indexOf(tr("Name")); // |
||
1938 | // if ((index_tmp!=-1) && (index_tmp < values_list.count())) result.name = values_list.at(index_tmp); |
||
1939 | index_tmp = fields_list.indexOf(tr("Product")); // |
||
1940 | if ((index_tmp!=-1) && (index_tmp < values_list.count())) result.model = values_list.at(index_tmp); |
||
1941 | // index_tmp = fields_list.indexOf(tr("AdapterRAM")); // |
||
1942 | // if ((index_tmp!=-1) && (index_tmp < values_list.count())) result.video_ram = QVariant(values_list.at(index_tmp)).asInt(); |
||
1943 | return result; |
||
1944 | } |
||
1945 | else return result; // |
||
1946 | int m; |
||
1947 | m++; |
||
1948 | } |
||
1949 | else { |
||
256 | pingvin | 1950 | wmiThread.terminate(); |
1951 | /*********************** |
||
251 | pingvin | 1952 | wmiThread.stop(); |
1953 | ok = wmiThread.wait(10000); |
||
1954 | int k; |
||
1955 | k++; |
||
256 | pingvin | 1956 | **********************/ |
251 | pingvin | 1957 | } |
1958 | |||
1959 | |||
1960 | |||
1961 | return result; |
||
1962 | |||
1963 | } |
||
1964 | |||
1965 | |||
1966 | TWmiProcessor MainWindow::getWmiProcessor(QString host, QString user_name, QString password){ |
||
1967 | TWmiProcessor result; |
||
1968 | bool ok; |
||
1969 | QString ansver_string; |
||
1970 | wmiThread.setHost(host); // |
||
1971 | wmiThread.setUser(user_name);// |
||
1972 | wmiThread.setPassword( password); |
||
1973 | wmiThread.setWmiString(tr("SELECT Name, Manufacturer, CurrentClockSpeed, SocketDesignation FROM Win32_Processor")); |
||
1974 | wmiThread.start(QThread::NormalPriority); |
||
1975 | ok = wmiThread.wait(10000); |
||
1976 | |||
1977 | if (ok){ |
||
1978 | QTextDocument * wmiDoc = ui->textEdit_2->document(); |
||
1979 | QTextCursor * wmiCursor; |
||
1980 | QStringList split_new_line; // |
||
1981 | QStringList fields_list; // |
||
1982 | QStringList values_list; // - |
||
1983 | wmiCursor = new QTextCursor(wmiDoc); |
||
1984 | ansver_string = wmiThread.resultString(); |
||
1985 | wmiCursor->insertText(ansver_string); |
||
1986 | split_new_line = ansver_string.split("\n", QString::SkipEmptyParts); // |
||
1987 | if(split_new_line.count()>2) { |
||
1988 | QString tmp_str; |
||
1989 | tmp_str = split_new_line.at(1); |
||
1990 | fields_list = tmp_str.split("|"); |
||
1991 | tmp_str = split_new_line.at(2); |
||
1992 | values_list = tmp_str.split("|"); |
||
1993 | int index_tmp; |
||
1994 | index_tmp = fields_list.indexOf(tr("Manufacturer")); // |
||
1995 | if ((index_tmp!=-1) && (index_tmp < values_list.count())) result.manufacturer = values_list.at(index_tmp); |
||
1996 | |||
1997 | index_tmp = fields_list.indexOf(tr("Name")); // |
||
1998 | if ((index_tmp!=-1) && (index_tmp < values_list.count())) result.name = values_list.at(index_tmp); |
||
1999 | index_tmp = fields_list.indexOf(tr("SocketDesignation")); // |
||
2000 | if ((index_tmp!=-1) && (index_tmp < values_list.count())) result.socket = values_list.at(index_tmp); |
||
2001 | index_tmp = fields_list.indexOf(tr("CurrentClockSpeed")); // |
||
2002 | if ((index_tmp!=-1) && (index_tmp < values_list.count())) result.clockSpeed = QVariant(values_list.at(index_tmp)).asInt(); |
||
2003 | |||
2004 | |||
2005 | |||
2006 | |||
2007 | |||
2008 | return result; |
||
2009 | } |
||
2010 | else return result; // |
||
2011 | int m; |
||
2012 | m++; |
||
2013 | } |
||
2014 | else { |
||
256 | pingvin | 2015 | |
2016 | wmiThread.terminate(); |
||
2017 | /************************ |
||
251 | pingvin | 2018 | wmiThread.stop(); |
2019 | ok = wmiThread.wait(10000); |
||
2020 | int k; |
||
2021 | k++; |
||
256 | pingvin | 2022 | ********************/ |
251 | pingvin | 2023 | } |
2024 | |||
2025 | |||
2026 | |||
2027 | return result; |
||
2028 | |||
2029 | |||
2030 | |||
2031 | } |
||
2032 | |||
254 | pingvin | 2033 | |
2034 | QList<TWmiMemoryModul> MainWindow::getWmiRAM(QString host, QString user_name, QString password) |
||
2035 | { |
||
2036 | QList<TWmiMemoryModul> result; |
||
2037 | TWmiMemoryModul ramModul_tmp; |
||
2038 | bool ok; |
||
2039 | QString ansver_string; |
||
2040 | |||
2041 | |||
2042 | wmiThread.setHost(host); // |
||
2043 | wmiThread.setUser(user_name);// |
||
2044 | wmiThread.setPassword( password); |
||
2045 | wmiThread.setWmiString(tr("SELECT BankLabel, Capacity, Manufacturer from Win32_PhysicalMemory")); |
||
2046 | wmiThread.start(QThread::NormalPriority); |
||
2047 | ok = wmiThread.wait(10000); |
||
2048 | |||
2049 | if (ok){ |
||
2050 | QTextDocument * wmiDoc = ui->textEdit_2->document(); |
||
2051 | QTextCursor * wmiCursor; |
||
2052 | QStringList split_new_line; // |
||
2053 | QStringList fields_list; // |
||
2054 | QStringList values_list; // - |
||
2055 | wmiCursor = new QTextCursor(wmiDoc); |
||
2056 | ansver_string = wmiThread.resultString(); |
||
2057 | wmiCursor->insertText(ansver_string); |
||
2058 | split_new_line = ansver_string.split("\n", QString::SkipEmptyParts); // |
||
2059 | if(split_new_line.count()>2) { |
||
2060 | QString tmp_str; |
||
2061 | tmp_str = split_new_line.at(1); |
||
2062 | fields_list = tmp_str.split("|"); |
||
2063 | |||
2064 | for(int i=2; i< split_new_line.count(); i++) |
||
2065 | { |
||
2066 | ramModul_tmp.bankLabel = ""; |
||
2067 | ramModul_tmp.capacity=0; |
||
2068 | tmp_str = split_new_line.at(i); |
||
2069 | values_list = tmp_str.split("|"); |
||
2070 | int index_tmp; |
||
2071 | index_tmp = fields_list.indexOf(tr("BankLabel")); // |
||
2072 | if ((index_tmp!=-1) && (index_tmp < values_list.count())) ramModul_tmp.bankLabel = values_list.at(index_tmp); |
||
2073 | index_tmp = fields_list.indexOf(tr("Capacity")); // |
||
2074 | if ((index_tmp!=-1) && (index_tmp < values_list.count())) ramModul_tmp.capacity = QVariant(values_list.at(index_tmp)).asInt(); |
||
2075 | result << ramModul_tmp; |
||
2076 | |||
2077 | |||
2078 | |||
2079 | |||
2080 | }; |
||
2081 | |||
2082 | return result; |
||
2083 | } |
||
2084 | else return result; // |
||
2085 | int m; |
||
2086 | m++; |
||
2087 | } |
||
2088 | else { |
||
256 | pingvin | 2089 | wmiThread.terminate(); |
2090 | /********************* |
||
254 | pingvin | 2091 | wmiThread.stop(); |
2092 | ok = wmiThread.wait(10000); |
||
2093 | int k; |
||
2094 | k++; |
||
256 | pingvin | 2095 | ****************/ |
254 | pingvin | 2096 | } |
2097 | |||
2098 | |||
2099 | |||
2100 | return result; |
||
2101 | } |
||
2102 | |||
2103 | |||
255 | pingvin | 2104 | QList<TWmiHDD> MainWindow::getWmiHDD(QString host, QString user_name, QString password) |
2105 | { |
||
2106 | QList<TWmiHDD> result; |
||
2107 | TWmiHDD hdd_tmp; |
||
2108 | bool ok; |
||
2109 | QString ansver_string; |
||
2110 | |||
2111 | QList<ThddSerialNumber> serNum_list; |
||
2112 | serNum_list = MainWindow::getHDDSerNum(host, user_name, password); // |
||
2113 | |||
2114 | |||
2115 | |||
2116 | |||
2117 | wmiThread.setHost(host); // |
||
2118 | wmiThread.setUser(user_name);// |
||
2119 | wmiThread.setPassword( password); |
||
2120 | wmiThread.setWmiString(tr("SELECT Caption, Manufacturer, Size, DeviceID from Win32_DiskDrive")); |
||
2121 | wmiThread.start(QThread::NormalPriority); |
||
2122 | ok = wmiThread.wait(10000); |
||
2123 | |||
2124 | |||
2125 | if (ok){ |
||
2126 | QTextDocument * wmiDoc = ui->textEdit_2->document(); |
||
2127 | QTextCursor * wmiCursor; |
||
2128 | QStringList split_new_line; // |
||
2129 | QStringList fields_list; // |
||
2130 | QStringList values_list; // - |
||
2131 | wmiCursor = new QTextCursor(wmiDoc); |
||
2132 | |||
2133 | |||
2134 | ansver_string = wmiThread.resultString(); |
||
2135 | |||
2136 | |||
2137 | wmiCursor->insertText(ansver_string); |
||
2138 | split_new_line = ansver_string.split("\n", QString::SkipEmptyParts); // |
||
2139 | if(split_new_line.count()>2) { |
||
2140 | QString tmp_str; |
||
2141 | tmp_str = split_new_line.at(1); |
||
2142 | fields_list = tmp_str.split("|"); |
||
2143 | |||
2144 | for(int i=2; i< split_new_line.count(); i++) |
||
2145 | { |
||
2146 | hdd_tmp.caption = ""; |
||
2147 | hdd_tmp.deviceID=""; |
||
2148 | hdd_tmp.manufacturer=""; |
||
2149 | hdd_tmp.serialNumber=""; |
||
2150 | hdd_tmp.size=0; |
||
2151 | tmp_str = split_new_line.at(i); |
||
2152 | values_list = tmp_str.split("|"); |
||
2153 | int index_tmp; |
||
2154 | index_tmp = fields_list.indexOf(tr("Caption")); // |
||
2155 | if ((index_tmp!=-1) && (index_tmp < values_list.count())) hdd_tmp.caption = values_list.at(index_tmp); |
||
2156 | index_tmp = fields_list.indexOf(tr("Manufacturer")); // |
||
2157 | if ((index_tmp!=-1) && (index_tmp < values_list.count())) hdd_tmp.manufacturer = values_list.at(index_tmp); |
||
2158 | |||
2159 | |||
2160 | |||
2161 | |||
2162 | index_tmp = fields_list.indexOf(tr("Size")); // |
||
2163 | if ((index_tmp!=-1) && (index_tmp < values_list.count())) { |
||
2164 | |||
2165 | QString size_str; |
||
2166 | bool ok; |
||
2167 | size_str = values_list.at(index_tmp); |
||
2168 | int size_int=0; |
||
2169 | long size_lng; |
||
2170 | size_int = size_str.toInt(&ok); |
||
2171 | size_lng = size_str.toLong(&ok); |
||
2172 | hdd_tmp.size= size_lng; |
||
2173 | } |
||
2174 | |||
2175 | |||
2176 | |||
2177 | |||
2178 | index_tmp = fields_list.indexOf(tr("DeviceID")); // |
||
2179 | if ((index_tmp!=-1) && (index_tmp < values_list.count())) { |
||
2180 | hdd_tmp.deviceID = values_list.at(index_tmp); |
||
2181 | for (int k=0; k < serNum_list.count(); k++){ |
||
2182 | if ((serNum_list.at(k).deviceID == hdd_tmp.deviceID)&&(serNum_list.at(k).deviceID !="")) hdd_tmp.serialNumber = serNum_list.at(k).serialNumber; |
||
2183 | } |
||
2184 | |||
2185 | } |
||
2186 | result << hdd_tmp; |
||
2187 | |||
2188 | |||
2189 | |||
2190 | |||
2191 | }; |
||
2192 | |||
2193 | return result; |
||
2194 | } |
||
2195 | else return result; // |
||
2196 | int m; |
||
2197 | m++; |
||
2198 | } |
||
2199 | else { |
||
256 | pingvin | 2200 | wmiThread.terminate(); |
2201 | /*********************** |
||
255 | pingvin | 2202 | wmiThread.stop(); |
2203 | ok = wmiThread.wait(10000); |
||
2204 | int k; |
||
2205 | k++; |
||
256 | pingvin | 2206 | ***************************/ |
255 | pingvin | 2207 | } |
2208 | |||
2209 | |||
2210 | |||
2211 | |||
2212 | |||
2213 | |||
2214 | |||
2215 | |||
2216 | |||
2217 | return result; |
||
2218 | |||
2219 | } |
||
2220 | |||
2221 | |||
2222 | |||
2223 | QList<ThddSerialNumber> MainWindow::getHDDSerNum(QString host, QString user_name, QString password){ |
||
2224 | |||
2225 | QList<ThddSerialNumber> result; |
||
2226 | ThddSerialNumber serNum_tmp; |
||
2227 | bool ok; |
||
2228 | QString ansver_string; |
||
2229 | |||
2230 | |||
2231 | wmiThread.setHost(host); // |
||
2232 | wmiThread.setUser(user_name);// |
||
2233 | wmiThread.setPassword( password); |
||
2234 | wmiThread.setWmiString(tr("SELECT SerialNumber, Tag FROM Win32_PhysicalMedia")); |
||
2235 | wmiThread.start(QThread::NormalPriority); |
||
2236 | ok = wmiThread.wait(10000); |
||
2237 | |||
2238 | if (ok){ |
||
2239 | QTextDocument * wmiDoc = ui->textEdit_2->document(); |
||
2240 | QTextCursor * wmiCursor; |
||
2241 | QStringList split_new_line; // |
||
2242 | QStringList fields_list; // |
||
2243 | QStringList values_list; // - |
||
2244 | wmiCursor = new QTextCursor(wmiDoc); |
||
2245 | |||
2246 | |||
2247 | ansver_string = wmiThread.resultString(); |
||
2248 | |||
2249 | |||
2250 | wmiCursor->insertText(ansver_string); |
||
2251 | split_new_line = ansver_string.split("\n", QString::SkipEmptyParts); // |
||
2252 | if(split_new_line.count()>2) { |
||
2253 | QString tmp_str; |
||
2254 | tmp_str = split_new_line.at(1); |
||
2255 | fields_list = tmp_str.split("|"); |
||
2256 | |||
2257 | for(int i=2; i< split_new_line.count(); i++) |
||
2258 | { |
||
2259 | serNum_tmp.serialNumber = ""; |
||
2260 | serNum_tmp.deviceID = ""; |
||
2261 | tmp_str = split_new_line.at(i); |
||
2262 | values_list = tmp_str.split("|"); |
||
2263 | int index_tmp; |
||
2264 | index_tmp = fields_list.indexOf(tr("SerialNumber")); // |
||
2265 | if ((index_tmp!=-1) && (index_tmp < values_list.count())) serNum_tmp.serialNumber = values_list.at(index_tmp); |
||
2266 | index_tmp = fields_list.indexOf(tr("Tag")); // |
||
2267 | if ((index_tmp!=-1) && (index_tmp < values_list.count())) serNum_tmp.deviceID = values_list.at(index_tmp); |
||
2268 | |||
2269 | result << serNum_tmp; |
||
2270 | |||
2271 | }; |
||
2272 | |||
2273 | return result; |
||
2274 | } |
||
2275 | else return result; // |
||
2276 | int m; |
||
2277 | m++; |
||
2278 | } |
||
2279 | else { |
||
256 | pingvin | 2280 | wmiThread.terminate(); |
2281 | /**************************** |
||
255 | pingvin | 2282 | wmiThread.stop(); |
2283 | ok = wmiThread.wait(10000); |
||
2284 | int k; |
||
2285 | k++; |
||
256 | pingvin | 2286 | *************************/ |
255 | pingvin | 2287 | } |
2288 | |||
2289 | |||
2290 | |||
2291 | |||
2292 | |||
2293 | } |
||
256 | pingvin | 2294 | |
2295 | |||
2296 | |||
2297 | |||
2298 | |||
2299 | |||
2300 | |||
2301 | |||
2302 | QList<TWmiCDROM> MainWindow::getWmiCDROM(QString host, QString user_name, QString password) |
||
2303 | { |
||
2304 | QList<TWmiCDROM> result; |
||
2305 | TWmiCDROM cdrom_tmp; |
||
2306 | bool ok; |
||
2307 | QString ansver_string; |
||
2308 | |||
2309 | |||
2310 | wmiThread.setHost(host); // |
||
2311 | wmiThread.setUser(user_name);// |
||
2312 | wmiThread.setPassword( password); |
||
2313 | wmiThread.setWmiString(tr("select Caption, Manufacturer from Win32_CDRomDrive")); |
||
2314 | wmiThread.start(QThread::NormalPriority); |
||
2315 | ok = wmiThread.wait(10000); |
||
2316 | |||
2317 | if (ok){ |
||
2318 | QTextDocument * wmiDoc = ui->textEdit_2->document(); |
||
2319 | QTextCursor * wmiCursor; |
||
2320 | QStringList split_new_line; // |
||
2321 | QStringList fields_list; // |
||
2322 | QStringList values_list; // - |
||
2323 | wmiCursor = new QTextCursor(wmiDoc); |
||
2324 | |||
2325 | |||
2326 | ansver_string = wmiThread.resultString(); |
||
2327 | |||
2328 | |||
2329 | wmiCursor->insertText(ansver_string); |
||
2330 | split_new_line = ansver_string.split("\n", QString::SkipEmptyParts); // |
||
2331 | if(split_new_line.count()>2) { |
||
2332 | QString tmp_str; |
||
2333 | tmp_str = split_new_line.at(1); |
||
2334 | fields_list = tmp_str.split("|"); |
||
2335 | |||
2336 | for(int i=2; i< split_new_line.count(); i++) |
||
2337 | { |
||
2338 | cdrom_tmp.name = ""; |
||
2339 | cdrom_tmp.manufacturer = ""; |
||
2340 | tmp_str = split_new_line.at(i); |
||
2341 | values_list = tmp_str.split("|"); |
||
2342 | int index_tmp; |
||
2343 | index_tmp = fields_list.indexOf(tr("Caption")); // |
||
2344 | if ((index_tmp!=-1) && (index_tmp < values_list.count())) cdrom_tmp.name = values_list.at(index_tmp); |
||
2345 | index_tmp = fields_list.indexOf(tr("Manufacturer")); // |
||
2346 | if ((index_tmp!=-1) && (index_tmp < values_list.count())) cdrom_tmp.manufacturer = values_list.at(index_tmp); |
||
2347 | |||
2348 | result << cdrom_tmp; |
||
2349 | |||
2350 | }; |
||
2351 | |||
2352 | return result; |
||
2353 | } |
||
2354 | else return result; // |
||
2355 | int m; |
||
2356 | m++; |
||
2357 | } |
||
2358 | else { |
||
2359 | wmiThread.terminate(); |
||
2360 | return result; |
||
2361 | /********* |
||
2362 | wmiThread.stop(); |
||
2363 | ok = wmiThread.wait(10000); |
||
2364 | int k; |
||
2365 | k++; |
||
2366 | *******/ |
||
2367 | } |
||
2368 | |||
2369 | |||
2370 | |||
2371 | |||
2372 | |||
2373 | } |
||
2374 | |||
2375 | |||
2376 | |||
2377 | QList<TWmiNetCard> MainWindow::getWmiNetCard(QString host, QString user_name, QString password){ |
||
2378 | |||
2379 | QList<TWmiNetCard> result; |
||
2380 | TWmiNetCard netCard_tmp; |
||
2381 | bool ok; |
||
2382 | QString ansver_string; |
||
2383 | wmiThread.setHost(host); // |
||
2384 | wmiThread.setUser(user_name);// |
||
2385 | wmiThread.setPassword( password); |
||
2386 | wmiThread.setWmiString(tr("Select Description, Caption, MACAddress from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")); |
||
2387 | wmiThread.start(QThread::NormalPriority); |
||
2388 | ok = wmiThread.wait(10000); |
||
2389 | |||
2390 | |||
2391 | |||
2392 | if (ok){ |
||
2393 | QTextDocument * wmiDoc = ui->textEdit_2->document(); |
||
2394 | QTextCursor * wmiCursor; |
||
2395 | QStringList split_new_line; // |
||
2396 | QStringList fields_list; // |
||
2397 | QStringList values_list; // - |
||
2398 | wmiCursor = new QTextCursor(wmiDoc); |
||
2399 | |||
2400 | |||
2401 | ansver_string = wmiThread.resultString(); |
||
2402 | |||
2403 | |||
2404 | wmiCursor->insertText(ansver_string); |
||
2405 | split_new_line = ansver_string.split("\n", QString::SkipEmptyParts); // |
||
2406 | if(split_new_line.count()>2) { |
||
2407 | QString tmp_str; |
||
2408 | tmp_str = split_new_line.at(1); |
||
2409 | fields_list = tmp_str.split("|"); |
||
2410 | |||
2411 | for(int i=2; i< split_new_line.count(); i++) |
||
2412 | { |
||
2413 | netCard_tmp.caption = ""; |
||
2414 | netCard_tmp.MACAddress= ""; |
||
2415 | tmp_str = split_new_line.at(i); |
||
2416 | values_list = tmp_str.split("|"); |
||
2417 | int index_tmp; |
||
2418 | index_tmp = fields_list.indexOf(tr("Description")); // |
||
2419 | if ((index_tmp!=-1) && (index_tmp < values_list.count())) netCard_tmp.caption = values_list.at(index_tmp); |
||
2420 | index_tmp = fields_list.indexOf(tr("MACAddress")); // |
||
2421 | if ((index_tmp!=-1) && (index_tmp < values_list.count())) netCard_tmp.MACAddress = values_list.at(index_tmp); |
||
2422 | |||
2423 | result << netCard_tmp; |
||
2424 | |||
2425 | }; |
||
2426 | |||
2427 | return result; |
||
2428 | } |
||
2429 | else return result; // |
||
2430 | int m; |
||
2431 | m++; |
||
2432 | } |
||
2433 | else { |
||
2434 | wmiThread.terminate(); |
||
2435 | return result; |
||
2436 | /********* |
||
2437 | wmiThread.stop(); |
||
2438 | ok = wmiThread.wait(10000); |
||
2439 | int k; |
||
2440 | k++; |
||
2441 | *******/ |
||
2442 | } |
||
2443 | |||
2444 | |||
2445 | |||
2446 | |||
2447 | |||
2448 | |||
2449 | |||
2450 | |||
2451 | |||
2452 | |||
2453 | } |