Rev 256 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
111 | pingvin | 1 | #include "mainwindow.h" |
2 | #include "ui_mainwindow.h" |
||
3 | |||
208 | pingvin | 4 | // |
111 | pingvin | 5 | |
6 | void MainWindow::getDatabaseData(){ |
||
7 | int list_count; |
||
150 | pingvin | 8 | ui->treeWidget_2->clear(); |
111 | pingvin | 9 | if (rootItems.isEmpty()) return; |
10 | |||
145 | pingvin | 11 | |
150 | pingvin | 12 | |
111 | pingvin | 13 | list_count = rootItems.count(); |
14 | |||
15 | for (int i=0; i < list_count; i++){ |
||
16 | |||
17 | buildTree(rootItems.at(i)); |
||
18 | |||
19 | } |
||
20 | |||
21 | } |
||
22 | |||
23 | void MainWindow::buildTree(QTreeWidgetItem * model_item){ |
||
112 | pingvin | 24 | |
25 | |||
26 | |||
27 | |||
111 | pingvin | 28 | QString model_name; |
29 | QString rootClassID; |
||
30 | QString rootClassInctance; |
||
113 | pingvin | 31 | QFont font; |
111 | pingvin | 32 | |
33 | QTreeWidgetItem * item; |
||
34 | model_name = model_item->text(0); |
||
35 | if (model_item->checkState(0) == false) return; |
||
113 | pingvin | 36 | |
145 | pingvin | 37 | //ui->treeWidget_2->clear(); |
114 | pingvin | 38 | //font.setWeight(20); |
113 | pingvin | 39 | font.setItalic(true); |
111 | pingvin | 40 | item = new QTreeWidgetItem (ui->treeWidget_2); |
113 | pingvin | 41 | item->setFont(0, font); |
111 | pingvin | 42 | item->setText(0, model_name); |
114 | pingvin | 43 | item->setTextColor(0, Qt::darkGreen); |
145 | pingvin | 44 | root_items_list << item; // |
45 | |||
144 | pingvin | 46 | if (!(model_item->childCount() > 0)) return; |
113 | pingvin | 47 | |
111 | pingvin | 48 | rootClassID = model_item->child(0)->text(1); |
49 | rootClassInctance = getClassInctance(rootClassID); |
||
144 | pingvin | 50 | |
51 | |||
111 | pingvin | 52 | if (model_item->child(0)->checkState(0)) // ( ), |
53 | { |
||
113 | pingvin | 54 | ///// QTreeWidgetItem * item_tmp; |
55 | ///// item_tmp = new QTreeWidgetItem(item); // , , |
||
56 | ///// item_tmp->setText(0, model_item->child(0)->text(0)); // |
||
111 | pingvin | 57 | |
112 | pingvin | 58 | //showClassObjects(item_tmp, model_item->child(0)); // |
59 | |||
113 | pingvin | 60 | ///// showObjects(item_tmp, model_item->child(0), tr("")); |
61 | showObjects(item, model_item->child(0), tr("")); |
||
111 | pingvin | 62 | } |
112 | pingvin | 63 | |
64 | |||
65 | /*****************************************************/ |
||
66 | |||
67 | |||
111 | pingvin | 68 | } |
69 | |||
70 | |||
71 | // - |
||
72 | QString MainWindow::getClassInctance(QString class_id){ |
||
73 | QSqlQuery q; |
||
74 | QString sql_str; |
||
75 | QString result; |
||
76 | QString classInctance; |
||
77 | int field_inctance; |
||
78 | bool ok; |
||
79 | sql_str = tr("select * " |
||
80 | " from ListOfClasses where ListOfClasses.ID = '" // , |
||
81 | ); |
||
82 | sql_str.append(class_id); |
||
83 | sql_str.append(tr("'")); |
||
84 | q.prepare(sql_str); |
||
85 | |||
86 | ok = q.exec(); |
||
87 | if (!ok) { |
||
88 | QMessageBox::critical( // . |
||
89 | this, // . |
||
90 | QObject::tr("Database Error"), // . |
||
91 | q.lastError().text()); // . |
||
92 | return result; |
||
93 | } |
||
94 | field_inctance = q.record().indexOf(tr("TableWhithInstance")); |
||
95 | while(q.next()){ |
||
96 | |||
97 | classInctance = q.value(field_inctance).toString(); |
||
98 | result.append(classInctance); |
||
99 | } |
||
100 | |||
101 | return result; |
||
102 | |||
103 | } |
||
104 | |||
105 | void MainWindow::showClassObjects(QTreeWidgetItem * parent_item, QTreeWidgetItem * model_item){ |
||
106 | QString classID; // |
||
107 | QString inctance; // , |
||
108 | QSqlQuery q; |
||
109 | QString sql_str; |
||
110 | QString str_tmp; |
||
111 | bool ok; |
||
112 | int field_ID; |
||
113 | int i; |
||
178 | pingvin | 114 | QIcon icon; |
111 | pingvin | 115 | classID = model_item->text(1); |
116 | inctance = getClassInctance(classID); |
||
178 | pingvin | 117 | icon = model_item->icon(0); |
111 | pingvin | 118 | sql_str = tr("select * " |
119 | " from " // - |
||
120 | ); |
||
121 | sql_str.append(inctance); |
||
122 | q.prepare(sql_str); |
||
123 | |||
124 | ok = q.exec(); |
||
125 | if (!ok) { |
||
126 | QMessageBox::critical( // . |
||
127 | this, // . |
||
128 | QObject::tr("Database Error"), // . |
||
129 | q.lastError().text()); // . |
||
130 | return; |
||
131 | } |
||
132 | |||
133 | field_ID = q.record().indexOf(tr("ID")); |
||
134 | |||
135 | |||
136 | while(q.next()){ |
||
137 | if (q.record().count() > 1) |
||
138 | { |
||
139 | QString value_tmp; |
||
140 | QString ID_tmp; |
||
141 | QTreeWidgetItem * itm; |
||
142 | ID_tmp = q.value(field_ID).toString(); // |
||
143 | value_tmp = q.value(1).toString(); // ( ) |
||
144 | itm = new QTreeWidgetItem(parent_item); // , |
||
145 | itm->setText(0, value_tmp); |
||
178 | pingvin | 146 | |
147 | itm->setIcon(0, icon); |
||
148 | |||
111 | pingvin | 149 | for (int i; i < model_item->childCount(); i++) // , |
150 | { |
||
151 | QTreeWidgetItem * model_item_tmp; // |
||
152 | model_item_tmp = model_item->child(i); // |
||
153 | MainWindow::showObjectChildrens(ID_tmp, itm, model_item_tmp); |
||
154 | |||
155 | } |
||
156 | } |
||
157 | |||
158 | } |
||
159 | |||
160 | |||
161 | i++; |
||
162 | } |
||
163 | |||
164 | |||
165 | |||
166 | void MainWindow::showObjectChildrens(QString object_ID, QTreeWidgetItem * object_item, QTreeWidgetItem * model_item){ // |
||
167 | |||
168 | QString classID; // |
||
169 | |||
170 | QString inctance; // , |
||
171 | QSqlQuery q; |
||
172 | QString sql_str; |
||
173 | QString str_tmp; |
||
174 | bool ok; |
||
175 | classID = model_item->text(1); |
||
176 | inctance = getClassInctance(classID); |
||
177 | |||
178 | sql_str = tr("select * " |
||
179 | " from '" // - |
||
180 | ); |
||
181 | sql_str.append(inctance); |
||
182 | sql_str.append(tr("' where ")); |
||
183 | |||
184 | |||
185 | q.prepare(sql_str); |
||
186 | |||
187 | ok = q.exec(); |
||
188 | if (!ok) { |
||
189 | QMessageBox::critical( // . |
||
190 | this, // . |
||
191 | QObject::tr("Database Error"), // . |
||
192 | q.lastError().text()); // . |
||
193 | return; |
||
194 | } |
||
195 | } |
||
196 | |||
197 | |||
178 | pingvin | 198 | |
199 | // |
||
112 | pingvin | 200 | void MainWindow::showObjects(QTreeWidgetItem * parent_object_item, QTreeWidgetItem * model_item, QString filtr){ |
201 | QString classID; // |
||
126 | pingvin | 202 | QString parentClassID; // |
203 | QString pointerField; // - |
||
112 | pingvin | 204 | QString inctance; // , |
205 | QString className; // |
||
223 | pingvin | 206 | QString modelID; // |
207 | QString add_filtr; // |
||
112 | pingvin | 208 | int field_ID; |
192 | pingvin | 209 | int icon_field_index; |
112 | pingvin | 210 | bool filtr_empty; |
211 | bool ok; |
||
212 | QSqlQuery q; |
||
213 | QString sql_str; |
||
214 | QString str_tmp; |
||
113 | pingvin | 215 | QTreeWidgetItem * title_item; |
216 | QFont font; |
||
178 | pingvin | 217 | QIcon icon; |
114 | pingvin | 218 | // font.setWeight(40); |
219 | font.setBold(true); |
||
112 | pingvin | 220 | filtr_empty = filtr.isEmpty(); |
223 | pingvin | 221 | |
112 | pingvin | 222 | classID = model_item->text(1); |
223 | pingvin | 223 | modelID = model_item->text(6); |
224 | add_filtr = MainWindow::getFiltrString(modelID, classID); |
||
126 | pingvin | 225 | |
223 | pingvin | 226 | |
178 | pingvin | 227 | icon = model_item->icon(0); |
228 | |||
126 | pingvin | 229 | parentClassID = model_item->parent()->text(1); |
230 | |||
231 | pointerField = getPointerFieldName(parentClassID, classID); |
||
232 | |||
112 | pingvin | 233 | className = model_item->text(0); |
234 | inctance = getClassInctance(classID); |
||
114 | pingvin | 235 | |
118 | pingvin | 236 | if (!model_item->checkState(0)) return; |
237 | |||
113 | pingvin | 238 | title_item = new QTreeWidgetItem(parent_object_item); |
239 | title_item->setFont(0, font); |
||
240 | title_item->setText(0, className); |
||
114 | pingvin | 241 | title_item->setText(1, tr("class")); |
242 | title_item->setText(2, classID); |
||
115 | pingvin | 243 | title_item->setText(3, inctance); |
126 | pingvin | 244 | title_item->setText(4, pointerField); |
223 | pingvin | 245 | title_item->setText(5, add_filtr); // |
114 | pingvin | 246 | title_item->setTextColor(0, Qt::darkBlue); |
247 | |||
179 | pingvin | 248 | title_item->setIcon(0, icon); |
126 | pingvin | 249 | |
178 | pingvin | 250 | |
112 | pingvin | 251 | sql_str = tr("select * " |
252 | " from " // - |
||
253 | ); |
||
254 | sql_str.append(inctance); |
||
223 | pingvin | 255 | |
256 | |||
257 | if (filtr.isEmpty() && (!add_filtr.isEmpty())) // , |
||
258 | { |
||
259 | filtr.append(tr ("where ")); |
||
260 | filtr.append(add_filtr); |
||
261 | } |
||
262 | |||
263 | |||
112 | pingvin | 264 | if (!filtr.isEmpty()) { // |
265 | sql_str.append(tr(" ")); |
||
266 | sql_str.append(filtr); // |
||
267 | } |
||
268 | |||
269 | q.prepare(sql_str); |
||
270 | |||
271 | ok = q.exec(); |
||
272 | if (!ok) { |
||
118 | pingvin | 273 | QString debug_str; |
274 | debug_str.append(tr(" showObjects(): Database Error ")); |
||
275 | debug_str.append(tr(" : ")); |
||
276 | debug_str.append(inctance); |
||
277 | debug_str.append(tr(" : ")); |
||
278 | debug_str.append(filtr); |
||
279 | debug_str.append(q.lastError().text()); |
||
112 | pingvin | 280 | QMessageBox::critical( // . |
281 | this, // . |
||
118 | pingvin | 282 | QObject::tr(" showObjects(): Database Error"), // . |
283 | debug_str |
||
284 | // q.lastError().text() |
||
285 | ); // . |
||
112 | pingvin | 286 | return; |
287 | } |
||
288 | |||
289 | field_ID = q.record().indexOf(tr("ID")); |
||
114 | pingvin | 290 | |
192 | pingvin | 291 | icon_field_index = q.record().indexOf(tr("Icon")); |
114 | pingvin | 292 | /* |
113 | pingvin | 293 | if (q.size() <= 0) return; |
294 | title_item = new QTreeWidgetItem(parent_object_item); |
||
295 | title_item->setFont(0, font); |
||
296 | title_item->setText(0, className); |
||
114 | pingvin | 297 | */ |
112 | pingvin | 298 | |
299 | while(q.next()){ |
||
300 | if (q.record().count() > 1) |
||
301 | { |
||
302 | QString value_tmp; |
||
303 | QString ID_tmp; |
||
304 | QTreeWidgetItem * itm; |
||
305 | ID_tmp = q.value(field_ID).toString(); // |
||
306 | value_tmp = q.value(1).toString(); // ( ) |
||
113 | pingvin | 307 | // itm = new QTreeWidgetItem(parent_object_item); // , |
308 | itm = new QTreeWidgetItem(title_item); // , |
||
112 | pingvin | 309 | itm->setText(0, value_tmp); |
114 | pingvin | 310 | itm->setText(1, tr("object")); |
311 | itm->setText(2, ID_tmp); |
||
178 | pingvin | 312 | |
192 | pingvin | 313 | |
314 | if (icon_field_index != -1){ // |
||
315 | QVariant data; |
||
195 | pingvin | 316 | QByteArray bytes; |
192 | pingvin | 317 | QPixmap pix; |
318 | QIcon icn; |
||
195 | pingvin | 319 | QMap <QString, QPixmap> pixmap_map; |
320 | QList <QString> id_list; |
||
321 | QList <QPixmap> pixmap_list; |
||
322 | pixmap_map = MainWindow::getObjectsIcon(inctance); |
||
323 | if (!pixmap_map.isEmpty()) { |
||
324 | id_list = pixmap_map.keys(); |
||
325 | pixmap_list = pixmap_map.values(); |
||
326 | } |
||
327 | if (id_list.indexOf(ID_tmp) != -1) { |
||
328 | pix = pixmap_list.at(id_list.indexOf(ID_tmp)); |
||
329 | } |
||
330 | // data = q.record().value(icon_field_index); |
||
331 | // bytes = q.record().value(icon_field_index).toByteArray(); |
||
332 | // if (data.isValid() && (!data.isNull())) { |
||
333 | // if (!bytes.isEmpty()){ |
||
334 | // pix.loadFromData(data.toByteArray()); |
||
335 | // pix.loadFromData(bytes); |
||
193 | pingvin | 336 | if (pix.height() > 128) pix = pix.scaledToHeight(128); |
192 | pingvin | 337 | icn.addPixmap(pix); |
338 | itm->setIcon(0, icn); |
||
195 | pingvin | 339 | // } |
192 | pingvin | 340 | |
341 | |||
342 | |||
343 | } |
||
344 | |||
345 | |||
346 | |||
179 | pingvin | 347 | // itm->setIcon(0, icon); |
178 | pingvin | 348 | |
349 | |||
112 | pingvin | 350 | for (int i=0; i < model_item->childCount(); i++) // , |
351 | { |
||
352 | QTreeWidgetItem * model_item_tmp; // |
||
353 | QString pointer_name; |
||
354 | QString filtr_tmp; |
||
355 | bool pointer_isEmpty; |
||
356 | model_item_tmp = model_item->child(i); // |
||
357 | pointer_name = getPointerFieldName(classID, model_item->child(i)->text(1)); |
||
115 | pingvin | 358 | itm->setText(4, pointer_name); |
126 | pingvin | 359 | |
360 | // title_item->setText(4, pointer_name); |
||
361 | |||
362 | |||
112 | pingvin | 363 | pointer_isEmpty = pointer_name.isEmpty(); |
364 | filtr_tmp = tr("where "); |
||
365 | filtr_tmp.append(tr("`")); |
||
366 | filtr_tmp.append(pointer_name); |
||
367 | filtr_tmp.append(tr("` = '")); |
||
368 | filtr_tmp.append(ID_tmp); |
||
369 | filtr_tmp.append(tr("'")); |
||
370 | showObjects(itm, model_item_tmp, filtr_tmp); |
||
371 | //MainWindow::showObjectChildrens(ID_tmp, itm, model_item_tmp); |
||
372 | |||
373 | } |
||
374 | |||
375 | |||
376 | } |
||
377 | |||
378 | } |
||
379 | |||
380 | |||
381 | |||
382 | |||
383 | for (int i; i < model_item->childCount(); i++) // , |
||
384 | { |
||
385 | |||
386 | |||
387 | } |
||
388 | |||
111 | pingvin | 389 | } |
390 | |||
115 | pingvin | 391 | |
112 | pingvin | 392 | QString MainWindow::getPointerFieldName(QString parent_class_id, QString chield_class_id){ |
393 | |||
394 | QSqlQuery q; |
||
395 | QString sql_str; |
||
396 | QString str_tmp; |
||
397 | QString field; |
||
398 | QString result; |
||
399 | int field_name; |
||
400 | bool ok; |
||
401 | sql_str = tr("select * " |
||
402 | " from `DescriptionOfClasses` where `DescriptionOfClasses`.`FieldType` = 'pointer' and `DescriptionOfClasses`.`DefaultValue` = " // - |
||
403 | ); |
||
404 | |||
405 | sql_str.append(tr("'")); |
||
406 | sql_str.append(parent_class_id); |
||
407 | sql_str.append(tr("' ")); |
||
408 | sql_str.append(tr(" and `DescriptionOfClasses`.`ClassIdentifer` = '")); |
||
409 | sql_str.append(chield_class_id); |
||
410 | sql_str.append(tr("'")); |
||
411 | q.prepare(sql_str); |
||
412 | |||
413 | ok = q.exec(); |
||
414 | if (!ok) { |
||
415 | QMessageBox::critical( // . |
||
416 | this, // . |
||
417 | QObject::tr("Database Error"), // . |
||
418 | q.lastError().text()); // . |
||
419 | return result; |
||
420 | } |
||
421 | field_name = q.record().indexOf(tr("FieldName")); |
||
422 | while(q.next()){ |
||
423 | result = q.value(field_name).toString(); |
||
424 | } |
||
425 | return result; |
||
426 | } |
||
427 | |||
115 | pingvin | 428 | |
429 | |||
430 | void MainWindow::on_treeWidget_2_itemClicked ( QTreeWidgetItem * item, int column ){ |
||
431 | QString item_type; // ( ) |
||
432 | QString parent_object_id; |
||
433 | int i; |
||
434 | QTreeWidgetItem * parent_item; |
||
435 | item_type = item->text(1); |
||
436 | parent_item = item->parent(); |
||
157 | pingvin | 437 | |
438 | QString class_id; // |
||
439 | QString inctance; |
||
440 | QString filtr_tmp; |
||
441 | QMap <QString, QString> pointersList; |
||
158 | pingvin | 442 | QStringList dateFieldList; // "DATE" |
443 | QStringList boolFieldList; // "BOOL" |
||
200 | pingvin | 444 | QStringList fileFieldList; // , |
158 | pingvin | 445 | QString pointer_name; // |
157 | pingvin | 446 | |
447 | if (item_type == tr("object") || item_type == tr("class")){ |
||
448 | |||
449 | disconnect(sql_mogel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_sql_mogel_dataChanged(QModelIndex,QModelIndex))); |
||
450 | |||
451 | static QList<int> colomns_indexes; // |
||
452 | static QList<int> date_colomns_indexes; // "DATE" |
||
158 | pingvin | 453 | static QList <int> bool_colomns_indexes; // "BOOL" |
200 | pingvin | 454 | static QList <int> file_colomns_indexes; // , |
455 | |||
157 | pingvin | 456 | static QList<SpinBoxDelegate *> spin_delegate_list;// |
188 | pingvin | 457 | static int icon_index = -1; // |
458 | |||
459 | |||
157 | pingvin | 460 | SpinBoxDelegate * spin_delegate_tmp; |
461 | |||
462 | // "" |
||
188 | pingvin | 463 | |
464 | if (icon_index != -1) { |
||
465 | ui->tableView->setItemDelegateForColumn(icon_index, &standart_delegate); // |
||
466 | icon_index = -1; |
||
467 | } |
||
468 | |||
157 | pingvin | 469 | for (i=0; i < colomns_indexes.size(); i++){ // -: |
470 | ui->tableView->setItemDelegateForColumn(colomns_indexes.at(i), &standart_delegate ); // |
||
471 | // ui->tableView->setItemDelegateForColumn(colomns_indexes.at(i), &picture_delegate); |
||
472 | |||
473 | } |
||
200 | pingvin | 474 | colomns_indexes.clear(); // |
157 | pingvin | 475 | |
200 | pingvin | 476 | |
477 | // "" |
||
478 | |||
479 | for (i=0; i < file_colomns_indexes.size(); i++){ // -: |
||
480 | ui->tableView->setItemDelegateForColumn(file_colomns_indexes.at(i), &standart_delegate ); // |
||
481 | } |
||
482 | file_colomns_indexes.clear(); |
||
483 | |||
484 | |||
157 | pingvin | 485 | // "" "DATE" |
486 | for (i=0; i < date_colomns_indexes.size(); i++){ // -: |
||
487 | ui->tableView->setItemDelegateForColumn(date_colomns_indexes.at(i), &standart_delegate ); // |
||
488 | // ui->tableView->setItemDelegateForColumn(colomns_indexes.at(i), &picture_delegate); |
||
489 | |||
490 | } |
||
491 | |||
158 | pingvin | 492 | date_colomns_indexes.clear(); |
157 | pingvin | 493 | |
158 | pingvin | 494 | // "" "BOOL" |
495 | for (i=0; i < bool_colomns_indexes.size(); i++){ // -: |
||
496 | ui->tableView->setItemDelegateForColumn(bool_colomns_indexes.at(i), &standart_delegate ); // |
||
497 | // ui->tableView->setItemDelegateForColumn(colomns_indexes.at(i), &picture_delegate); |
||
157 | pingvin | 498 | |
158 | pingvin | 499 | } |
500 | |||
501 | bool_colomns_indexes.clear(); |
||
159 | pingvin | 502 | boolFieldsIndexes_global.clear(); |
158 | pingvin | 503 | |
115 | pingvin | 504 | if (item_type == tr("object")) |
505 | { |
||
157 | pingvin | 506 | QString ID; |
119 | pingvin | 507 | ui->pushButton->setEnabled(false); |
508 | ui->pushButton_2->setEnabled(false); |
||
509 | |||
115 | pingvin | 510 | class_id = parent_item->text(2); |
116 | pingvin | 511 | ID = item->text(2); |
512 | inctance = parent_item->text(3); |
||
513 | delete sql_mogel; |
||
127 | pingvin | 514 | |
515 | sql_mogel = new MyModel(); |
||
516 | |||
116 | pingvin | 517 | sql_mogel->setTable(inctance); |
119 | pingvin | 518 | // sql_mogel->setEditStrategy(QSqlTableModel::OnFieldChange); |
519 | sql_mogel->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
116 | pingvin | 520 | |
521 | filtr_tmp.append(tr("`")); |
||
522 | filtr_tmp.append(tr("ID")); |
||
523 | filtr_tmp.append(tr("`")); |
||
524 | filtr_tmp.append(tr(" = '")); |
||
525 | filtr_tmp.append(ID); |
||
526 | filtr_tmp.append(tr("'")); |
||
128 | pingvin | 527 | |
115 | pingvin | 528 | } |
529 | if (item_type == tr("class")) |
||
530 | { |
||
531 | QString parent_object_id; // |
||
125 | pingvin | 532 | |
126 | pingvin | 533 | QString parent_class_inctance; |
223 | pingvin | 534 | QString class_filter; |
138 | pingvin | 535 | |
536 | |||
119 | pingvin | 537 | ui->pushButton->setEnabled(true); |
538 | ui->pushButton_2->setEnabled(true); |
||
539 | |||
115 | pingvin | 540 | parent_object_id = parent_item->text(2); |
118 | pingvin | 541 | |
542 | parentObject_id = parent_item->text(2); |
||
543 | |||
115 | pingvin | 544 | class_id = item->text(2); |
545 | inctance = item->text(3); |
||
223 | pingvin | 546 | class_filter = item->text(5); |
115 | pingvin | 547 | |
126 | pingvin | 548 | pointer_name = item->text(4); |
116 | pingvin | 549 | delete sql_mogel; |
127 | pingvin | 550 | |
551 | sql_mogel = new MyModel(); |
||
552 | |||
553 | // sql_mogel = new QSqlTableModel(this); |
||
115 | pingvin | 554 | sql_mogel->setTable(inctance); |
119 | pingvin | 555 | // sql_mogel->setEditStrategy(QSqlTableModel::OnFieldChange); |
556 | sql_mogel->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
116 | pingvin | 557 | |
558 | if (!parent_object_id.isEmpty()) |
||
559 | { |
||
560 | filtr_tmp.append(tr("`")); |
||
561 | filtr_tmp.append(pointer_name); |
||
562 | filtr_tmp.append(tr("`")); |
||
563 | filtr_tmp.append(tr(" = '")); |
||
564 | filtr_tmp.append(parent_object_id); |
||
565 | filtr_tmp.append(tr("'")); |
||
126 | pingvin | 566 | |
223 | pingvin | 567 | |
568 | if (!class_filter.isEmpty()) // |
||
569 | { |
||
570 | filtr_tmp.append(tr(" and ")); |
||
571 | filtr_tmp.append(class_filter); // ( ) |
||
572 | |||
573 | } |
||
574 | |||
575 | |||
576 | |||
577 | |||
155 | pingvin | 578 | } |
224 | pingvin | 579 | else if(!class_filter.isEmpty()) // , |
223 | pingvin | 580 | { |
581 | filtr_tmp.append(class_filter); // ( ) |
||
582 | } |
||
130 | pingvin | 583 | |
157 | pingvin | 584 | } |
130 | pingvin | 585 | |
153 | pingvin | 586 | |
130 | pingvin | 587 | |
157 | pingvin | 588 | pointersList = getPointersList(class_id); // - |
589 | dateFieldList = getDataFieldList(class_id); // c "DATE" |
||
158 | pingvin | 590 | boolFieldList = getBoolFieldList(class_id); // c "BOOL" |
200 | pingvin | 591 | fileFieldList = getFileFieldList(class_id); // , |
592 | |||
189 | pingvin | 593 | icon_index = getIconFieldIndex(inctance); // |
594 | if (icon_index != -1) ui->tableView->setItemDelegateForColumn(icon_index, iconDelegate); |
||
595 | sql_mogel->setIconIndex(icon_index); |
||
596 | |||
157 | pingvin | 597 | QMap <int, QString> pointersToModel; |
155 | pingvin | 598 | |
156 | pingvin | 599 | |
600 | |||
201 | pingvin | 601 | |
202 | pingvin | 602 | QMap <int, QString> filesFieldsToModel; |
201 | pingvin | 603 | for (int i=0; i < fileFieldList.count(); i++){ // , |
604 | // static FileDelegate flDelegate; |
||
605 | // static TimeEditDelegate dateDelegate("01.10.2010"); |
||
606 | QString fileFieldName; // |
||
607 | int fileFieldIndex; // |
||
608 | fileFieldName = fileFieldList.at(i); // , |
||
609 | fileFieldIndex = sql_mogel->record().indexOf(fileFieldName); // |
||
202 | pingvin | 610 | filesFieldsToModel.insert(fileFieldIndex, fileFieldName); |
611 | file_colomns_indexes.append(fileFieldIndex);// "file" |
||
201 | pingvin | 612 | ui->tableView->setItemDelegateForColumn(fileFieldIndex, fileDelegate); |
613 | |||
614 | } |
||
202 | pingvin | 615 | sql_mogel->setFilesFields(filesFieldsToModel);// , |
201 | pingvin | 616 | |
617 | |||
618 | |||
619 | |||
157 | pingvin | 620 | for (int i=0; i < dateFieldList.count(); i++){ // "DATA" |
158 | pingvin | 621 | static MyDEDelegate dateDelegate; |
622 | // static TimeEditDelegate dateDelegate("01.10.2010"); |
||
157 | pingvin | 623 | QString dateFieldName; // |
624 | int dataFieldIndex; // |
||
625 | dateFieldName = dateFieldList.at(i); // "DATA" |
||
626 | dataFieldIndex = sql_mogel->record().indexOf(dateFieldName); // |
||
627 | date_colomns_indexes.append(dataFieldIndex);// "DATA" |
||
628 | ui->tableView->setItemDelegateForColumn(dataFieldIndex, &dateDelegate); |
||
156 | pingvin | 629 | |
157 | pingvin | 630 | } |
130 | pingvin | 631 | |
153 | pingvin | 632 | |
158 | pingvin | 633 | for (int i=0; i < boolFieldList.count(); i++){ // "BOOL" |
634 | // // // // static MyDEDelegate dateDelegate; |
||
635 | // static TimeEditDelegate dateDelegate("01.10.2010"); |
||
636 | QString boolFieldName; // |
||
637 | int boolFieldIndex; // |
||
638 | boolFieldName = boolFieldList.at(i); // "BOOL" |
||
639 | boolFieldIndex = sql_mogel->record().indexOf(boolFieldName); // |
||
640 | bool_colomns_indexes.append(boolFieldIndex);// "DATA" |
||
641 | // ui->tableView->setItemDelegateForColumn(dataFieldIndex, &dateDelegate); |
||
130 | pingvin | 642 | |
158 | pingvin | 643 | } |
130 | pingvin | 644 | |
158 | pingvin | 645 | sql_mogel->setBooleansList(bool_colomns_indexes); |
159 | pingvin | 646 | boolFieldsIndexes_global = bool_colomns_indexes; |
158 | pingvin | 647 | |
157 | pingvin | 648 | for (int i=0; i < spin_delegate_list.count(); i++){ // |
649 | delete spin_delegate_list.at(i); |
||
650 | } |
||
130 | pingvin | 651 | |
157 | pingvin | 652 | spin_delegate_list.clear(); // |
130 | pingvin | 653 | |
157 | pingvin | 654 | QStringList pointersNames; |
655 | pointersNames = pointersList.keys(); // - |
||
130 | pingvin | 656 | |
138 | pingvin | 657 | |
658 | |||
659 | |||
660 | |||
179 | pingvin | 661 | // ui->tableView->setItemDelegateForColumn(2, picture_delegate); |
138 | pingvin | 662 | |
157 | pingvin | 663 | // ui->tableView->setRowHeight(1, 100); |
138 | pingvin | 664 | |
126 | pingvin | 665 | |
128 | pingvin | 666 | |
145 | pingvin | 667 | |
129 | pingvin | 668 | |
157 | pingvin | 669 | QStringList parentInctancesList = pointersList.values(); // |
129 | pingvin | 670 | |
157 | pingvin | 671 | for (i=0; i < pointersNames.size(); i++){ // -: |
672 | QString pointerName; |
||
153 | pingvin | 673 | |
157 | pingvin | 674 | int pointerIndex; |
675 | pointerName = pointersNames.at(i); // - |
||
676 | pointerIndex = sql_mogel->record().indexOf(pointerName); // |
||
677 | colomns_indexes.append(pointerIndex); // |
||
678 | spin_delegate_tmp = new SpinBoxDelegate(); |
||
153 | pingvin | 679 | |
157 | pingvin | 680 | // // spinDelegate.setInctance(parentInctancesList.at(i)); // |
681 | // // spinDelegate.getItems(); // |
||
153 | pingvin | 682 | |
157 | pingvin | 683 | spin_delegate_tmp->setInctance(parentInctancesList.at(i)); |
684 | spin_delegate_tmp->getItems(); |
||
128 | pingvin | 685 | |
157 | pingvin | 686 | spin_delegate_list.append(spin_delegate_tmp); |
128 | pingvin | 687 | |
157 | pingvin | 688 | // // ui->tableView->setItemDelegateForColumn(pointerIndex, &spinDelegate); // |
118 | pingvin | 689 | |
157 | pingvin | 690 | ui->tableView->setItemDelegateForColumn(pointerIndex, spin_delegate_tmp); |
115 | pingvin | 691 | |
157 | pingvin | 692 | pointersToModel.insert(pointerIndex, parentInctancesList.at(i)); // |
693 | } |
||
140 | pingvin | 694 | |
201 | pingvin | 695 | sql_mogel->setPointers(pointersToModel); // |
140 | pingvin | 696 | |
157 | pingvin | 697 | pointer_index = sql_mogel->record().indexOf(pointer_name); // , , ! :-) |
140 | pingvin | 698 | |
699 | |||
700 | |||
701 | |||
157 | pingvin | 702 | sql_mogel->setFilter(filtr_tmp); |
162 | pingvin | 703 | sql_mogel->setSort(1, Qt::AscendingOrder); |
157 | pingvin | 704 | sql_mogel->select(); |
154 | pingvin | 705 | |
162 | pingvin | 706 | |
707 | |||
157 | pingvin | 708 | connect(sql_mogel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_sql_mogel_dataChanged(QModelIndex,QModelIndex))); |
140 | pingvin | 709 | |
157 | pingvin | 710 | ui->tableView->setModel(sql_mogel); |
189 | pingvin | 711 | ui->tableView->hideColumn(0); |
157 | pingvin | 712 | ui->tableView->resizeColumnsToContents(); |
189 | pingvin | 713 | ui->tableView->resizeRowsToContents(); |
140 | pingvin | 714 | |
715 | |||
189 | pingvin | 716 | |
717 | |||
718 | |||
115 | pingvin | 719 | } |
720 | |||
721 | } |
||
722 | |||
723 | |||
118 | pingvin | 724 | void MainWindow::on_pushButton_clicked(){ // " " |
725 | int row = sql_mogel->rowCount(); |
||
726 | sql_mogel->insertRows(row, 1); |
||
727 | sql_mogel->setData(sql_mogel->index(row, 1), QVariant(tr(" ")), Qt::EditRole); // " " |
||
728 | if (pointer_index > 0) { |
||
729 | sql_mogel->setData(sql_mogel->index(row, pointer_index), QVariant(parentObject_id), Qt::EditRole); // " " |
||
730 | } |
||
119 | pingvin | 731 | // sql_mogel->submitAll(); |
118 | pingvin | 732 | |
733 | } |
||
119 | pingvin | 734 | |
735 | void MainWindow::on_pushButton_2_clicked(){ // " " |
||
736 | int i; |
||
737 | i++; |
||
120 | pingvin | 738 | QModelIndex model_index; |
739 | QItemSelectionModel *selectionModel = ui->tableView->selectionModel(); |
||
740 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
||
741 | QList<int> selectedRows; |
||
742 | selectedRows.clear(); |
||
743 | foreach (model_index, indexes){ // |
||
744 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) selectedRows.append(model_index.row()); // |
||
119 | pingvin | 745 | |
746 | } |
||
120 | pingvin | 747 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // |
119 | pingvin | 748 | |
749 | |||
120 | pingvin | 750 | for (int m =0; m < selectedRows.size(); ++m){ |
751 | |||
752 | // ClassEditor::removeClass(selectedRows.at(m)); |
||
753 | |||
754 | sql_mogel->removeRow(selectedRows.at(m)); |
||
755 | |||
756 | } |
||
757 | sql_mogel->submitAll(); |
||
758 | getDatabaseData(); |
||
759 | |||
760 | } |
||
761 | |||
762 | |||
119 | pingvin | 763 | void MainWindow::on_pushButton_3_clicked(){ // "" |
764 | int i; |
||
765 | i++; |
||
766 | sql_mogel->submitAll(); |
||
767 | getDatabaseData(); |
||
768 | ui->pushButton_3->setEnabled(false); |
||
769 | ui->pushButton_4->setEnabled(false); |
||
770 | sql_mogel->select(); |
||
771 | |||
772 | } |
||
773 | |||
774 | |||
775 | void MainWindow::on_pushButton_4_clicked(){ // " " |
||
776 | int i; |
||
777 | i++; |
||
778 | sql_mogel->select(); |
||
779 | ui->pushButton_3->setEnabled(false); |
||
780 | ui->pushButton_4->setEnabled(false); |
||
190 | pingvin | 781 | ui->tableView_2->resizeRowsToContents(); |
782 | ui->tableView_2->resizeColumnsToContents(); |
||
119 | pingvin | 783 | } |
784 | |||
785 | |||
144 | pingvin | 786 | void MainWindow::on_pushButton_5_clicked(){// " " |
787 | |||
788 | int i; |
||
789 | i++; |
||
790 | int row = model_for_ListModelsTable->rowCount(); |
||
791 | model_for_ListModelsTable->insertRows(row, 1); |
||
792 | model_for_ListModelsTable->setData(model_for_ListModelsTable->index(row, 1), QVariant(tr(" ")), Qt::EditRole); // " " |
||
793 | // model_for_ListModelsTable->setData(sql_mogel->index(row, pointer_index), QVariant(parentObject_id), Qt::EditRole); // " " |
||
794 | |||
795 | // sql_mogel->submitAll(); |
||
796 | |||
797 | |||
798 | } |
||
799 | |||
800 | void MainWindow::on_pushButton_6_clicked(){// " " |
||
801 | |||
802 | QModelIndex model_index; |
||
803 | QItemSelectionModel *selectionModel = ui->tableView_2->selectionModel(); |
||
804 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
||
805 | QList<int> selectedRows; |
||
806 | selectedRows.clear(); |
||
807 | foreach (model_index, indexes){ // |
||
808 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) selectedRows.append(model_index.row()); // |
||
809 | |||
810 | } |
||
811 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // |
||
812 | |||
813 | |||
814 | for (int m =0; m < selectedRows.size(); ++m){ |
||
815 | |||
816 | // ClassEditor::removeClass(selectedRows.at(m)); |
||
817 | |||
818 | model_for_ListModelsTable->removeRow(selectedRows.at(m)); |
||
819 | |||
820 | } |
||
821 | model_for_ListModelsTable->submitAll(); |
||
233 | pingvin | 822 | ui->pushButton_7->setEnabled(true); |
144 | pingvin | 823 | // getDatabaseData(); |
824 | |||
825 | } |
||
826 | |||
827 | |||
146 | pingvin | 828 | void MainWindow::on_pushButton_7_clicked(){// "" |
829 | model_for_ListModelsTable->submitAll(); |
||
830 | ui->pushButton_7->setEnabled(false); |
||
831 | ui->pushButton_8->setEnabled(false); |
||
832 | model_is_build = false; |
||
833 | MainWindow::readModels(); |
||
834 | model_is_build = true; |
||
835 | MainWindow::getDatabaseData(); |
||
836 | } |
||
144 | pingvin | 837 | |
146 | pingvin | 838 | void MainWindow::on_pushButton_8_clicked(){// "" ( ) |
839 | model_for_ListModelsTable->select(); |
||
840 | ui->pushButton_7->setEnabled(false); |
||
841 | ui->pushButton_8->setEnabled(false); |
||
190 | pingvin | 842 | |
146 | pingvin | 843 | } |
844 | |||
215 | pingvin | 845 | |
846 | void MainWindow::on_pushButton_9_clicked()// " " ( ) |
||
847 | { |
||
848 | QString class_id; |
||
849 | QString model_id; |
||
227 | pingvin | 850 | |
851 | |||
215 | pingvin | 852 | class_id = ui->treeWidget->currentItem()->text(1); |
853 | model_id = ui->treeWidget->currentItem()->text(6); |
||
221 | pingvin | 854 | int row = filter_model->rowCount(); |
855 | filter_model->insertRows(row, 1); |
||
856 | filter_model->setData(filter_model->index(row, 1), QVariant(model_id), Qt::EditRole); // "Model ID" |
||
857 | filter_model->setData(filter_model->index(row, 2), QVariant(class_id), Qt::EditRole); // "Class ID" |
||
217 | pingvin | 858 | ui->pushButton_11->setEnabled(true); |
859 | ui->pushButton_12->setEnabled(true); |
||
215 | pingvin | 860 | |
227 | pingvin | 861 | |
215 | pingvin | 862 | } |
863 | |||
217 | pingvin | 864 | void MainWindow::on_pushButton_10_clicked()// " " ( ) |
865 | { |
||
221 | pingvin | 866 | QModelIndex model_index; |
867 | QItemSelectionModel *selectionModel = ui->tableView_3->selectionModel(); |
||
868 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
||
869 | QList<int> selectedRows; |
||
870 | selectedRows.clear(); |
||
871 | foreach (model_index, indexes){ // |
||
872 | if (!selectedRows.contains(model_index.row()) /*&& (model_index.column()==1)*/) selectedRows.append(model_index.row()); // |
||
217 | pingvin | 873 | |
221 | pingvin | 874 | } |
875 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // |
||
876 | |||
877 | |||
878 | for (int m =0; m < selectedRows.size(); ++m){ |
||
879 | |||
880 | // ClassEditor::removeClass(selectedRows.at(m)); |
||
881 | |||
882 | filter_model->removeRow(selectedRows.at(m)); |
||
883 | |||
884 | } |
||
885 | filter_model->submitAll(); |
||
226 | pingvin | 886 | |
887 | filter_model->sort(0,Qt::AscendingOrder); |
||
221 | pingvin | 888 | // getDatabaseData(); |
222 | pingvin | 889 | model_is_build = false; |
890 | MainWindow::readModels(); |
||
891 | model_is_build = true; |
||
892 | MainWindow::getDatabaseData(); |
||
221 | pingvin | 893 | |
227 | pingvin | 894 | disconnect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
895 | delete filter_model; |
||
896 | |||
897 | filter_model = new QSqlTableModel(); |
||
898 | filter_model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
899 | /// filter_model = new MyModel(); |
||
900 | |||
901 | connect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
||
902 | |||
903 | |||
904 | |||
905 | |||
217 | pingvin | 906 | } |
907 | |||
908 | void MainWindow::on_pushButton_11_clicked()// "" ( ) |
||
909 | { |
||
221 | pingvin | 910 | filter_model->submitAll(); |
226 | pingvin | 911 | filter_model->sort(0,Qt::AscendingOrder); |
221 | pingvin | 912 | ui->pushButton_11->setEnabled(false); |
913 | ui->pushButton_12->setEnabled(false); |
||
222 | pingvin | 914 | |
915 | model_is_build = false; |
||
916 | MainWindow::readModels(); |
||
917 | model_is_build = true; |
||
918 | MainWindow::getDatabaseData(); |
||
227 | pingvin | 919 | disconnect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
920 | delete filter_model; |
||
921 | |||
922 | filter_model = new QSqlTableModel(); |
||
923 | filter_model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
924 | /// filter_model = new MyModel(); |
||
925 | |||
926 | connect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
||
927 | |||
928 | |||
929 | |||
217 | pingvin | 930 | } |
931 | |||
932 | void MainWindow::on_pushButton_12_clicked()// " " ( ) |
||
933 | { |
||
223 | pingvin | 934 | ui->tableView_3->setModel(filter_model); |
221 | pingvin | 935 | filter_model->select(); |
223 | pingvin | 936 | |
221 | pingvin | 937 | ui->pushButton_11->setEnabled(false); |
938 | ui->pushButton_12->setEnabled(false); |
||
217 | pingvin | 939 | } |
940 | |||
233 | pingvin | 941 | void MainWindow::on_pushButton_13_clicked()// " " ( ) |
942 | { |
||
943 | buildReport(false); |
||
217 | pingvin | 944 | |
233 | pingvin | 945 | } |
946 | |||
947 | void MainWindow::on_pushButton_14_clicked()// " " ( ) |
||
948 | { |
||
949 | buildReport(true); |
||
950 | |||
951 | } |
||
952 | |||
953 | void MainWindow::on_pushButton_15_clicked()// "" ( ) |
||
954 | { |
||
955 | QPrinter printer; |
||
956 | QPrintDialog *dlg = new QPrintDialog(&printer, this); |
||
957 | if (dlg->exec() !=QDialog::Accepted) return; |
||
958 | doc->print(&printer); |
||
959 | |||
960 | } |
||
961 | |||
962 | |||
963 | void MainWindow::on_pushButton_16_clicked()// " PDF" ( ) |
||
964 | { |
||
965 | QString fileName = QFileDialog::getSaveFileName(this, "Export PDF", "", "PDF Files (*.pdf)"); |
||
966 | if(!fileName.isEmpty()){ |
||
967 | if (QFileInfo(fileName).suffix().isEmpty()) |
||
968 | fileName.append(".pdf"); |
||
969 | QPrinter printer(QPrinter::HighResolution); |
||
970 | printer.setOutputFormat(QPrinter::PdfFormat); |
||
971 | printer.setOutputFileName(fileName); |
||
972 | doc->print(&printer); |
||
973 | } |
||
974 | |||
975 | } |
||
976 | |||
977 | void MainWindow::on_pushButton_17_clicked()// " OpenOffice" ( ) |
||
978 | |||
979 | { |
||
980 | QString fileName = QFileDialog::getSaveFileName(this, "Export ODT", "", "OpenOffice document (*.odt)"); |
||
981 | |||
982 | if(!fileName.isEmpty()){ |
||
983 | if (QFileInfo(fileName).suffix().isEmpty()) |
||
984 | fileName.append(".odt"); |
||
985 | (bool)QTextDocumentWriter(fileName).write(doc); |
||
986 | |||
987 | } |
||
988 | |||
989 | |||
990 | } |
||
991 | |||
992 | |||
238 | pingvin | 993 | void MainWindow::on_pushButton_18_clicked()// wmi |
994 | |||
995 | { |
||
241 | pingvin | 996 | /* |
997 | |||
238 | pingvin | 998 | // QString program = tr(" wmic -U %Patr10t //192.168.0.135 \"select * from Win32_ComputerSystem\""); |
999 | QString program = tr("wmic"); |
||
1000 | QStringList arguments; |
||
1001 | |||
1002 | // arguments << tr(" -U %Patr10t //192.168.0.135 \"select * from Win32_ComputerSystem\""); |
||
1003 | // program.append(tr(" -U %Patr10t //192.168.0.135 \"select * from Win32_ComputerSystem\"")); |
||
241 | pingvin | 1004 | program.append(tr(" -U admin --password=samba //192.168.0.101 \"select * from ")); //Win32_Product\"")); |
238 | pingvin | 1005 | program.append(ui->comboBox_2->currentText()); |
1006 | program.append(tr("\"")); |
||
1007 | |||
1008 | int i; |
||
1009 | i++; |
||
1010 | wmiProcess.start(program); |
||
241 | pingvin | 1011 | */ |
238 | pingvin | 1012 | |
248 | pingvin | 1013 | TWmiVideoCard vCard; |
1014 | |||
249 | pingvin | 1015 | |
1016 | |||
1017 | vCard = MainWindow::getWmiVideoGard("192.168.0.11", tr(""), "!s-Leg01@Z"); |
||
248 | pingvin | 1018 | int i; |
1019 | i++; |
||
1020 | |||
250 | pingvin | 1021 | |
1022 | |||
238 | pingvin | 1023 | } |
1024 | |||
1025 | |||
119 | pingvin | 1026 | void MainWindow::on_sql_mogel_dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ // |
1027 | int i; |
||
1028 | i++; |
||
189 | pingvin | 1029 | |
1030 | if (sql_mogel->iconIndex() !=-1) { |
||
1031 | ui->tableView->resizeColumnsToContents(); |
||
1032 | ui->tableView->resizeRowsToContents(); |
||
1033 | } |
||
1034 | |||
160 | pingvin | 1035 | if ((topLeft == bottomRight) && (boolFieldsIndexes_global.indexOf(topLeft.column()) != -1)) |
1036 | { |
||
1037 | ui->pushButton_3->setEnabled(false); |
||
1038 | ui->pushButton_4->setEnabled(false); |
||
1039 | return; |
||
1040 | } |
||
1041 | |||
1042 | |||
119 | pingvin | 1043 | ui->pushButton_3->setEnabled(true); |
1044 | ui->pushButton_4->setEnabled(true); |
||
1045 | |||
1046 | } |
||
128 | pingvin | 1047 | |
146 | pingvin | 1048 | void MainWindow::on_model_for_ListModelsTable_dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ // |
128 | pingvin | 1049 | |
146 | pingvin | 1050 | ui->pushButton_7->setEnabled(true); |
1051 | ui->pushButton_8->setEnabled(true); |
||
1052 | } |
||
1053 | |||
1054 | |||
221 | pingvin | 1055 | |
1056 | |||
1057 | void MainWindow::on_filter_model_dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ) // |
||
1058 | |||
1059 | { |
||
1060 | ui->pushButton_11->setEnabled(true); |
||
1061 | ui->pushButton_12->setEnabled(true); |
||
1062 | } |
||
1063 | |||
1064 | |||
1065 | |||
1066 | |||
1067 | |||
128 | pingvin | 1068 | // -, - |
1069 | // - |
||
1070 | |||
1071 | QMap <QString, QString> MainWindow::getPointersList(QString class_id){ |
||
1072 | QMap <QString, QString> result_map; |
||
1073 | QSqlQuery q; |
||
1074 | QString sql_str; |
||
1075 | QString str_tmp; |
||
1076 | QString field; |
||
1077 | QString result; |
||
1078 | int field_name, field_default_value; |
||
1079 | bool ok; |
||
1080 | sql_str = tr("select * " |
||
1081 | " from `DescriptionOfClasses` where `DescriptionOfClasses`.`FieldType` = 'pointer' and `DescriptionOfClasses`.`ClassIdentifer` = " // - |
||
1082 | ); |
||
1083 | |||
1084 | sql_str.append(tr("'")); |
||
1085 | sql_str.append(class_id); |
||
1086 | sql_str.append(tr("' ")); |
||
1087 | // sql_str.append(tr(" and `DescriptionOfClasses`.`ClassIdentifer` = '")); |
||
1088 | // sql_str.append(chield_class_id); |
||
1089 | // sql_str.append(tr("'")); |
||
1090 | q.prepare(sql_str); |
||
1091 | |||
1092 | ok = q.exec(); |
||
1093 | if (!ok) { |
||
1094 | QMessageBox::critical( // . |
||
1095 | this, // . |
||
1096 | QObject::tr("Database Error"), // . |
||
1097 | q.lastError().text()); // . |
||
1098 | return result_map; |
||
1099 | } |
||
1100 | field_name = q.record().indexOf(tr("FieldName")); |
||
1101 | field_default_value = q.record().indexOf(tr("DefaultValue")); |
||
1102 | while(q.next()){ |
||
1103 | QString pointerFieldName; |
||
1104 | QString parentClassID; |
||
1105 | QString parentClassInctance; |
||
1106 | |||
1107 | pointerFieldName = q.value(field_name).toString(); |
||
1108 | parentClassID = q.value(field_default_value).toString(); |
||
1109 | parentClassInctance = getClassInctance(parentClassID); |
||
1110 | result_map.insert(pointerFieldName, parentClassInctance); |
||
1111 | |||
1112 | |||
1113 | } |
||
1114 | |||
1115 | return result_map; |
||
1116 | } |
||
1117 | |||
132 | pingvin | 1118 | |
1119 | |||
1120 | |||
1121 | |||
155 | pingvin | 1122 | QStringList MainWindow::getDataFieldList(QString class_id){ // c "", |
1123 | // - |
||
132 | pingvin | 1124 | |
155 | pingvin | 1125 | QStringList result_str; |
1126 | QSqlQuery q; |
||
1127 | QString sql_str; |
||
1128 | QString str_tmp; |
||
1129 | QString field; |
||
1130 | QString result; |
||
1131 | int field_name, field_default_value; |
||
1132 | bool ok; |
||
1133 | sql_str = tr("select * " |
||
1134 | " from `DescriptionOfClasses` where `DescriptionOfClasses`.`FieldType` = 'DATE' and `DescriptionOfClasses`.`ClassIdentifer` = " // - |
||
1135 | ); |
||
1136 | |||
1137 | sql_str.append(tr("'")); |
||
1138 | sql_str.append(class_id); |
||
1139 | sql_str.append(tr("' ")); |
||
1140 | // sql_str.append(tr(" and `DescriptionOfClasses`.`ClassIdentifer` = '")); |
||
1141 | // sql_str.append(chield_class_id); |
||
1142 | // sql_str.append(tr("'")); |
||
1143 | q.prepare(sql_str); |
||
1144 | |||
1145 | ok = q.exec(); |
||
1146 | if (!ok) { |
||
1147 | QMessageBox::critical( // . |
||
1148 | this, // . |
||
1149 | QObject::tr("Database Error"), // . |
||
1150 | q.lastError().text()); // . |
||
1151 | return result_str; |
||
1152 | } |
||
1153 | field_name = q.record().indexOf(tr("FieldName")); |
||
1154 | // field_default_value = q.record().indexOf(tr("DefaultValue")); |
||
1155 | while(q.next()){ |
||
1156 | QString DataFieldName; |
||
1157 | |||
1158 | DataFieldName = q.value(field_name).toString(); |
||
1159 | result_str.append(DataFieldName); |
||
1160 | |||
1161 | |||
1162 | } |
||
1163 | |||
1164 | return result_str; |
||
1165 | } |
||
1166 | |||
1167 | |||
1168 | |||
188 | pingvin | 1169 | int MainWindow::getIconFieldIndex(QString inctance){ // |
1170 | |||
1171 | QSqlQuery q; |
||
1172 | bool ok; |
||
1173 | int icon_field; |
||
1174 | QString sql_str; |
||
1175 | sql_str = tr("select * from `"); // - |
||
1176 | sql_str.append(inctance); |
||
1177 | sql_str.append(tr("`")); |
||
1178 | q.prepare(sql_str); |
||
1179 | |||
1180 | ok = q.exec(); |
||
1181 | if (!ok) { |
||
1182 | QMessageBox::critical( // . |
||
1183 | this, // . |
||
1184 | QObject::tr("Database Error"), // . |
||
1185 | q.lastError().text()); // . |
||
189 | pingvin | 1186 | |
1187 | return -1; |
||
188 | pingvin | 1188 | } |
1189 | |||
1190 | icon_field = q.record().indexOf(tr("Icon")); |
||
189 | pingvin | 1191 | return icon_field; |
188 | pingvin | 1192 | |
1193 | |||
1194 | } |
||
1195 | |||
1196 | |||
200 | pingvin | 1197 | QStringList MainWindow::getFileFieldList(QString class_id){ // , |
1198 | QStringList result_str; |
||
1199 | QSqlQuery q; |
||
1200 | QString sql_str; |
||
1201 | bool ok; |
||
1202 | int field_name, field_default_value; |
||
1203 | sql_str = tr("select * " |
||
1204 | " from `DescriptionOfClasses` where `DescriptionOfClasses`.`Comment` = 'file' and `DescriptionOfClasses`.`ClassIdentifer` = " // - |
||
1205 | ); |
||
1206 | sql_str.append(tr("'")); |
||
1207 | sql_str.append(class_id); |
||
1208 | sql_str.append(tr("' ")); |
||
1209 | q.prepare(sql_str); |
||
1210 | |||
1211 | ok = q.exec(); |
||
1212 | if (!ok) { |
||
1213 | QMessageBox::critical( // . |
||
1214 | this, // . |
||
1215 | QObject::tr("Database Error"), // . |
||
1216 | q.lastError().text()); // . |
||
1217 | return result_str; |
||
1218 | } |
||
1219 | |||
1220 | field_name = q.record().indexOf(tr("FieldName")); |
||
1221 | // field_default_value = q.record().indexOf(tr("DefaultValue")); |
||
1222 | while(q.next()){ |
||
1223 | QString FileFieldName; |
||
1224 | |||
1225 | FileFieldName = q.value(field_name).toString(); |
||
1226 | result_str.append(FileFieldName); |
||
1227 | |||
1228 | |||
1229 | } |
||
1230 | |||
1231 | return result_str; |
||
1232 | |||
1233 | } |
||
1234 | |||
1235 | |||
1236 | |||
158 | pingvin | 1237 | QStringList MainWindow::getBoolFieldList(QString class_id){ // c "bool" |
155 | pingvin | 1238 | |
158 | pingvin | 1239 | QStringList result_str; |
1240 | QSqlQuery q; |
||
1241 | QString sql_str; |
||
1242 | QString str_tmp; |
||
1243 | QString field; |
||
1244 | QString result; |
||
1245 | int field_name, field_default_value; |
||
1246 | bool ok; |
||
1247 | sql_str = tr("select * " |
||
1248 | " from `DescriptionOfClasses` where `DescriptionOfClasses`.`FieldType` = 'BOOL' and `DescriptionOfClasses`.`ClassIdentifer` = " // - |
||
1249 | ); |
||
1250 | |||
1251 | sql_str.append(tr("'")); |
||
1252 | sql_str.append(class_id); |
||
1253 | sql_str.append(tr("' ")); |
||
1254 | // sql_str.append(tr(" and `DescriptionOfClasses`.`ClassIdentifer` = '")); |
||
1255 | // sql_str.append(chield_class_id); |
||
1256 | // sql_str.append(tr("'")); |
||
1257 | q.prepare(sql_str); |
||
1258 | |||
1259 | ok = q.exec(); |
||
1260 | if (!ok) { |
||
1261 | QMessageBox::critical( // . |
||
1262 | this, // . |
||
1263 | QObject::tr("Database Error"), // . |
||
1264 | q.lastError().text()); // . |
||
1265 | return result_str; |
||
1266 | } |
||
1267 | field_name = q.record().indexOf(tr("FieldName")); |
||
1268 | // field_default_value = q.record().indexOf(tr("DefaultValue")); |
||
1269 | while(q.next()){ |
||
1270 | QString DataFieldName; |
||
1271 | |||
1272 | DataFieldName = q.value(field_name).toString(); |
||
1273 | result_str.append(DataFieldName); |
||
1274 | |||
1275 | |||
1276 | } |
||
1277 | |||
1278 | return result_str; |
||
1279 | } |
||
1280 | |||
1281 | |||
1282 | |||
1283 | |||
1284 | |||
132 | pingvin | 1285 | // |
1286 | |||
1287 | void MainWindow::readSettings() |
||
1288 | { |
||
1289 | QSettings settings("Trolltech", "Application Example"); |
||
1290 | baseName = settings.value("baseName", "an_db").toString(); |
||
1291 | userName = settings.value("userName", "an").toString(); |
||
1292 | password = settings.value("password", "393939").toString(); |
||
1293 | tableName = settings.value("tableName", "inventar").toString(); |
||
1294 | hostName = settings.value("hostName", "server").toString(); |
||
1295 | // resize(size); |
||
1296 | // move(pos);tableName |
||
1297 | } |
||
1298 | |||
1299 | |||
1300 | void MainWindow::writeSettings() |
||
1301 | { |
||
1302 | QSettings settings("Trolltech", "Application Example"); |
||
1303 | settings.setValue("baseName", baseName); |
||
1304 | settings.setValue("userName", userName); |
||
1305 | settings.setValue("password", password); |
||
1306 | settings.setValue("tableName", tableName); |
||
1307 | settings.setValue("hostName", hostName); |
||
1308 | } |
||
1309 | |||
1310 | |||
1311 | |||
1312 | void MainWindow::applySetting() |
||
1313 | { |
||
1314 | bool ok; |
||
1315 | baseName = setFrm.lineEdit->text(); |
||
1316 | userName = setFrm.lineEdit_2->text(); |
||
1317 | password = setFrm.lineEdit_3->text(); |
||
1318 | // tableName = setFrm->lineEdit_4->text(); |
||
1319 | hostName = setFrm.lineEdit_5->text(); |
||
1320 | writeSettings(); |
||
1321 | |||
1322 | |||
1323 | ok=openDataBase(); |
||
1324 | if (!ok) return; |
||
1325 | // // // ui->treeWidget->clear(); // |
||
1326 | |||
1327 | // // // buildPreviewModel(tr(" "), tr("1")); |
||
149 | pingvin | 1328 | |
1329 | model_is_build = false; |
||
1330 | |||
132 | pingvin | 1331 | class_list_map.clear(); // |
149 | pingvin | 1332 | rootItems.clear(); |
1333 | models_items.clear(); |
||
151 | pingvin | 1334 | |
1335 | disconnect(model_for_ListModelsTable, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_model_for_ListModelsTable_dataChanged(QModelIndex,QModelIndex))); |
||
149 | pingvin | 1336 | delete model_for_ListModelsTable; |
151 | pingvin | 1337 | |
149 | pingvin | 1338 | initListModelsTablle(); |
1339 | |||
151 | pingvin | 1340 | connect(model_for_ListModelsTable, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_model_for_ListModelsTable_dataChanged(QModelIndex,QModelIndex))); |
1341 | |||
149 | pingvin | 1342 | ui->treeWidget->clear(); |
132 | pingvin | 1343 | initComboBox(); |
149 | pingvin | 1344 | // model_for_ListModelsTable->select(); |
1345 | MainWindow::readModels(); |
||
1346 | |||
1347 | |||
1348 | |||
132 | pingvin | 1349 | // // // getDatabaseData(); |
1350 | // delete setFrm; |
||
149 | pingvin | 1351 | |
1352 | |||
1353 | model_is_build = true; |
||
150 | pingvin | 1354 | getDatabaseData(); |
132 | pingvin | 1355 | setFrm.close(); |
1356 | } |
||
1357 | |||
1358 | |||
1359 | void MainWindow::getSetting() |
||
1360 | { |
||
1361 | // setFrm = new settingForm; |
||
1362 | // // // connect(setFrm.pushButton, SIGNAL(clicked()), this, SLOT(applySetting())); |
||
1363 | setFrm.lineEdit->setText(baseName); |
||
1364 | setFrm.lineEdit_2->setText(userName); |
||
1365 | setFrm.lineEdit_3->setText(password); |
||
1366 | // setFrm->lineEdit_4->setText(tableName); |
||
1367 | setFrm.lineEdit_5->setText(hostName); |
||
1368 | setFrm.show(); |
||
1369 | |||
1370 | |||
1371 | |||
1372 | } |
||
144 | pingvin | 1373 | |
1374 | |||
1375 | |||
1376 | |||
1377 | void MainWindow::readModels(){ |
||
1378 | |||
145 | pingvin | 1379 | int row = model_for_ListModelsTable->rowCount(); |
147 | pingvin | 1380 | QList <QTreeWidgetItem*> modelsItemsList; |
1381 | QList <int> row_list; |
||
1382 | modelsItemsList = models_items.values(); |
||
1383 | |||
1384 | row_list = models_items.keys(); |
||
1385 | |||
1386 | |||
1387 | |||
145 | pingvin | 1388 | rootItems.clear(); |
222 | pingvin | 1389 | root_items_list.clear(); |
145 | pingvin | 1390 | ui->treeWidget->clear(); |
144 | pingvin | 1391 | for (int i=0; i < row; i++){ |
1392 | QTreeWidgetItem * item_tmp; |
||
1393 | QString modelName; |
||
213 | pingvin | 1394 | QString model_id; |
147 | pingvin | 1395 | |
144 | pingvin | 1396 | bool enabled; |
147 | pingvin | 1397 | |
1398 | |||
1399 | |||
1400 | //models_items.values(); |
||
1401 | // modelString = |
||
1402 | |||
144 | pingvin | 1403 | modelName = model_for_ListModelsTable->data(model_for_ListModelsTable->index(i, 1)).toString(); |
213 | pingvin | 1404 | model_id = model_for_ListModelsTable->data(model_for_ListModelsTable->index(i, 0)).toString(); |
1405 | |||
144 | pingvin | 1406 | enabled = model_for_ListModelsTable->data(model_for_ListModelsTable->index(i, 3)).toBool(); |
1407 | item_tmp = new QTreeWidgetItem(ui->treeWidget); |
||
1408 | item_tmp->setText(0, modelName); |
||
147 | pingvin | 1409 | item_tmp->setText(4, QVariant(i).toString()); // 4 |
213 | pingvin | 1410 | item_tmp->setText(6, model_id); |
144 | pingvin | 1411 | if (enabled) item_tmp->setCheckState(0,Qt::Checked); |
1412 | else item_tmp->setCheckState(0,Qt::Unchecked); |
||
145 | pingvin | 1413 | |
1414 | root_items_list << item_tmp; |
||
1415 | |||
144 | pingvin | 1416 | rootItems.append(item_tmp); |
147 | pingvin | 1417 | |
1418 | models_items[i] =item_tmp ; |
||
1419 | |||
1420 | |||
145 | pingvin | 1421 | modelString = model_for_ListModelsTable->data(model_for_ListModelsTable->index(i, 2)).toString(); |
1422 | if (modelString.isEmpty()) continue; |
||
215 | pingvin | 1423 | else setupModelData(modelString.split(QString("\n")), item_tmp, i, model_id); // |
144 | pingvin | 1424 | |
1425 | } |
||
149 | pingvin | 1426 | |
144 | pingvin | 1427 | } |
174 | pingvin | 1428 | |
1429 | |||
1430 | |||
1431 | |||
1432 | QMap <QString, QPixmap> MainWindow::getClassesIcons(){ // |
||
1433 | // ID , - |
||
1434 | |||
1435 | QMap <QString, QPixmap> result_map; |
||
1436 | QSqlQuery q; |
||
1437 | QString sql_str; |
||
1438 | QString str_tmp; |
||
1439 | QString field; |
||
1440 | QString result; |
||
1441 | int field_id, field_icon; |
||
1442 | bool ok; |
||
1443 | sql_str = tr("select * " |
||
1444 | " from `ListOfClasses` " // - |
||
1445 | ); |
||
1446 | |||
1447 | q.prepare(sql_str); |
||
1448 | |||
1449 | ok = q.exec(); |
||
1450 | if (!ok) { |
||
1451 | QMessageBox::critical( // . |
||
1452 | this, // . |
||
1453 | QObject::tr("Database Error"), // . |
||
1454 | q.lastError().text()); // . |
||
1455 | return result_map; |
||
1456 | } |
||
1457 | field_id = q.record().indexOf(tr("ID")); |
||
1458 | field_icon = q.record().indexOf(tr("Icon")); |
||
1459 | while(q.next()){ |
||
1460 | QString classID; |
||
1461 | QByteArray loadimage = q.value(field_icon).toByteArray(); |
||
1462 | classID = q.value(field_id).toString(); |
||
1463 | if( !loadimage.isEmpty() ) |
||
1464 | { |
||
1465 | QPixmap pixmap; |
||
1466 | pixmap.loadFromData(loadimage); |
||
1467 | result_map.insert(classID, pixmap); |
||
1468 | |||
1469 | } |
||
1470 | else continue; |
||
1471 | |||
1472 | |||
1473 | |||
1474 | } |
||
1475 | |||
1476 | return result_map; |
||
1477 | |||
1478 | |||
1479 | } |
||
195 | pingvin | 1480 | |
1481 | |||
1482 | |||
1483 | |||
1484 | QMap <QString, QPixmap> MainWindow::getObjectsIcon(QString inctance){ // |
||
1485 | // ID , - |
||
1486 | QMap <QString, QPixmap> result_map; |
||
1487 | QSqlQuery q; |
||
1488 | QString sql_str; |
||
1489 | QString str_tmp; |
||
1490 | int field_id, field_icon; |
||
1491 | bool ok; |
||
1492 | sql_str = tr("select `ID`, `Icon` " |
||
1493 | " from `" // - |
||
1494 | ); |
||
1495 | sql_str.append(inctance); |
||
1496 | sql_str.append(tr("`")); |
||
1497 | |||
1498 | q.prepare(sql_str); |
||
1499 | |||
1500 | ok = q.exec(); |
||
1501 | if (!ok) { |
||
1502 | QMessageBox::critical( // . |
||
1503 | this, // . |
||
1504 | QObject::tr("Database Error"), // . |
||
1505 | q.lastError().text()); // . |
||
1506 | return result_map; |
||
1507 | } |
||
1508 | |||
1509 | field_id = q.record().indexOf(tr("ID")); |
||
1510 | field_icon = q.record().indexOf(tr("Icon")); |
||
1511 | |||
1512 | while(q.next()){ |
||
1513 | QString objectID; |
||
1514 | QByteArray loadimage = q.value(field_icon).toByteArray(); |
||
1515 | objectID = q.value(field_id).toString(); |
||
1516 | if( !loadimage.isEmpty() ) |
||
1517 | { |
||
1518 | QPixmap pixmap; |
||
1519 | pixmap.loadFromData(loadimage); |
||
1520 | result_map.insert(objectID, pixmap); |
||
1521 | |||
1522 | } |
||
1523 | else continue; |
||
1524 | |||
1525 | |||
1526 | |||
1527 | } |
||
1528 | return result_map; |
||
1529 | } |
||
222 | pingvin | 1530 | |
1531 | |||
1532 | |||
1533 | |||
1534 | QString MainWindow::getFiltrString(QString model_id, QString class_id){ // - |
||
1535 | |||
1536 | QSqlQuery q; |
||
1537 | QString sql_str; |
||
1538 | QString result_str; |
||
1539 | sql_str = tr("select * from `Filters` where `Filters`.`Model_ID` = '"); |
||
1540 | sql_str.append(model_id); |
||
1541 | sql_str.append(tr("' and `Filters`.`Class_ID` = '")); |
||
1542 | sql_str.append(class_id); |
||
1543 | sql_str.append(tr("' order by `Filters`.`ID`")); |
||
1544 | bool ok; |
||
1545 | ok = q.prepare(sql_str); |
||
1546 | ok = q.exec(); |
||
1547 | |||
1548 | if (!ok) { |
||
1549 | QMessageBox::critical( // . |
||
1550 | this, // . |
||
1551 | QObject::tr("Database Error"), // . |
||
1552 | q.lastError().text()); // . |
||
1553 | return result_str; |
||
1554 | } |
||
1555 | result_str.clear(); |
||
1556 | while(q.next()){ |
||
1557 | QString Condition, FieldName, ConditionalSymbol, ValueForComparison, PostCondition; |
||
1558 | Condition = q.record().value(3).toString(); |
||
1559 | FieldName = q.record().value(4).toString(); |
||
1560 | ConditionalSymbol = q.record().value(5).toString(); |
||
1561 | ValueForComparison = q.record().value(6).toString(); |
||
1562 | PostCondition = q.record().value(7).toString(); |
||
1563 | |||
1564 | |||
1565 | result_str.append(Condition); |
||
223 | pingvin | 1566 | result_str.append(tr(" `")); |
222 | pingvin | 1567 | result_str.append(FieldName); |
223 | pingvin | 1568 | result_str.append(tr("`")); |
222 | pingvin | 1569 | result_str.append(ConditionalSymbol); |
227 | pingvin | 1570 | |
1571 | if (!ValueForComparison.isEmpty()) { |
||
1572 | result_str.append(tr("'")); |
||
1573 | result_str.append(ValueForComparison); |
||
1574 | result_str.append(tr("' ")); |
||
1575 | } |
||
222 | pingvin | 1576 | result_str.append(PostCondition); |
1577 | |||
1578 | |||
1579 | } |
||
1580 | |||
1581 | |||
1582 | return result_str; |
||
1583 | |||
1584 | } |
||
1585 | |||
1586 | |||
250 | pingvin | 1587 | void MainWindow::initWmiTree() { |
1588 | |||
1589 | QSqlQuery q; |
||
1590 | QString sqlStr; |
||
1591 | QString classID; |
||
1592 | QString inctance; |
||
1593 | int field_id; |
||
1594 | bool ok; |
||
1595 | int field_ip, field_user_name, field_password; |
||
1596 | |||
1597 | |||
1598 | sqlStr = tr("select * from `ListOfClasses` where `ListOfClasses`.`ClassName` = 'WmiHost'"); |
||
1599 | ok = q.prepare(sqlStr); |
||
1600 | ok = q.exec(); |
||
1601 | if (!ok){ |
||
1602 | QMessageBox::critical( // . |
||
1603 | this, // . |
||
1604 | QObject::tr("Database Error"), // . |
||
1605 | q.lastError().text()); // . |
||
1606 | return; |
||
1607 | } |
||
1608 | |||
1609 | field_id = q.record().indexOf(tr("ID")); |
||
1610 | if (field_id == -1) return; |
||
1611 | else while (q.next()){ |
||
1612 | classID = q.value(field_id).asString(); |
||
1613 | |||
1614 | } |
||
1615 | |||
1616 | inctance = MainWindow::getClassInctance(classID); |
||
1617 | if(inctance.isEmpty()) return; |
||
1618 | sqlStr = tr("select * from `"); |
||
1619 | sqlStr.append(inctance); |
||
1620 | sqlStr.append(tr("`")); |
||
1621 | ok = q.prepare(sqlStr); |
||
1622 | ok = q.exec(); |
||
1623 | if (!ok){ |
||
1624 | QMessageBox::critical( // . |
||
1625 | this, // . |
||
1626 | QObject::tr("Database Error"), // . |
||
1627 | q.lastError().text()); // . |
||
1628 | return; |
||
1629 | } |
||
1630 | |||
1631 | |||
1632 | |||
1633 | field_id = q.record().indexOf(tr("ID")); |
||
1634 | field_ip = q.record().indexOf(tr("IP")); |
||
1635 | field_user_name = q.record().indexOf(tr("")); |
||
1636 | field_password = q.record().indexOf(tr("")); |
||
1637 | |||
1638 | while (q.next()){ |
||
1639 | QString ID_str, IP_str, user_name_str, password_str; |
||
1640 | QTreeWidgetItem * itm_tmp; |
||
1641 | IP_str = q.value(field_ip).asString(); |
||
1642 | user_name_str = q.value(field_user_name).asString(); |
||
1643 | password_str = q.value(field_password).asString(); |
||
1644 | |||
1645 | itm_tmp = new QTreeWidgetItem(ui->treeWidget_3); |
||
1646 | itm_tmp->setText(0, IP_str); |
||
1647 | itm_tmp->setCheckState(0, Qt::Checked ); |
||
1648 | |||
1649 | |||
1650 | |||
1651 | |||
1652 | |||
1653 | TWmiVideoCard vCard; |
||
251 | pingvin | 1654 | TWmiMatherBoard mBoard; |
1655 | TWmiProcessor processor; |
||
254 | pingvin | 1656 | QList<TWmiMemoryModul> memory_moduls; |
255 | pingvin | 1657 | QList<TWmiHDD> hdd_list; |
256 | pingvin | 1658 | QList<TWmiCDROM> cdrom_list; |
1659 | QList<TWmiNetCard> netcadr_list; |
||
257 | pingvin | 1660 | QList<TWmiSoundCard> soundcard_list; |
250 | pingvin | 1661 | vCard = MainWindow::getWmiVideoGard(IP_str, user_name_str, password_str); |
1662 | |||
1663 | if (!vCard.name.isEmpty()) { |
||
1664 | QTreeWidgetItem * itm_video; |
||
1665 | QTreeWidgetItem * itm_video_ram; |
||
1666 | QTreeWidgetItem * itm_video_model; |
||
1667 | QTreeWidgetItem * itm_video_manufacturer; |
||
1668 | QString tmp_str; |
||
1669 | tmp_str = tr(": "); |
||
1670 | tmp_str.append(vCard.name); |
||
255 | pingvin | 1671 | tmp_str.append(tr(" ")); |
1672 | tmp_str.append(QVariant(vCard.video_ram/1024/1024).asString()); |
||
1673 | tmp_str.append(tr(" ")); |
||
250 | pingvin | 1674 | itm_video = new QTreeWidgetItem(itm_tmp); |
1675 | itm_video->setText(0, tmp_str); |
||
1676 | |||
1677 | tmp_str = tr(": "); |
||
1678 | tmp_str.append(vCard.manufacturer); |
||
1679 | |||
1680 | itm_video_manufacturer = new QTreeWidgetItem(itm_video); |
||
1681 | itm_video_manufacturer->setText(0, tmp_str); |
||
1682 | |||
1683 | itm_video_ram = new QTreeWidgetItem(itm_video); |
||
1684 | |||
1685 | tmp_str = tr(": "); |
||
1686 | tmp_str.append(vCard.model); |
||
1687 | itm_video_model = new QTreeWidgetItem(itm_video); |
||
1688 | itm_video_model->setText(0, tmp_str); |
||
1689 | |||
1690 | |||
1691 | |||
1692 | tmp_str = tr(" (): "); |
||
1693 | tmp_str.append(QVariant(vCard.video_ram /1048576).asString()); |
||
1694 | |||
1695 | itm_video_ram->setText(0, tmp_str); |
||
1696 | |||
1697 | |||
1698 | |||
1699 | } |
||
1700 | |||
1701 | |||
251 | pingvin | 1702 | mBoard = MainWindow::getWmiMatherBoard(IP_str, user_name_str, password_str); |
1703 | if (!mBoard.manufacturer.isEmpty()) { |
||
1704 | QTreeWidgetItem * itm_maherBoard; |
||
1705 | QTreeWidgetItem * itm_maherBoard_model; |
||
1706 | QTreeWidgetItem * itm_maherBoard_manufacturer; |
||
1707 | QString tmp_str; |
||
1708 | tmp_str = tr(" : "); |
||
1709 | tmp_str.append(mBoard.manufacturer); |
||
1710 | tmp_str.append( tr(" ")); |
||
1711 | tmp_str.append(mBoard.model); |
||
1712 | itm_maherBoard = new QTreeWidgetItem(itm_tmp); |
||
1713 | itm_maherBoard->setText(0, tmp_str); |
||
250 | pingvin | 1714 | |
251 | pingvin | 1715 | tmp_str = tr(": "); |
1716 | tmp_str.append(mBoard.manufacturer); |
||
1717 | |||
1718 | itm_maherBoard_manufacturer = new QTreeWidgetItem(itm_maherBoard); |
||
1719 | itm_maherBoard_manufacturer->setText(0, tmp_str); |
||
1720 | |||
1721 | itm_maherBoard_model = new QTreeWidgetItem(itm_maherBoard); |
||
1722 | |||
1723 | tmp_str = tr(": "); |
||
1724 | tmp_str.append(mBoard.model); |
||
1725 | |||
1726 | itm_maherBoard_model->setText(0, tmp_str); |
||
1727 | |||
1728 | |||
1729 | } |
||
1730 | |||
1731 | processor = MainWindow::getWmiProcessor(IP_str, user_name_str, password_str); |
||
1732 | if (!processor.manufacturer.isEmpty()){ |
||
1733 | |||
1734 | QTreeWidgetItem * itm_processor; |
||
1735 | QTreeWidgetItem * itm_processor_manufacturer; |
||
1736 | QTreeWidgetItem * itm_processor_clockSpeed; |
||
1737 | QTreeWidgetItem * itm_processor_socket; |
||
1738 | |||
1739 | |||
1740 | QString tmp_str; |
||
1741 | tmp_str = tr(": "); |
||
1742 | tmp_str.append(processor.name); |
||
1743 | |||
1744 | itm_processor = new QTreeWidgetItem(itm_tmp); |
||
1745 | itm_processor->setText(0, tmp_str); |
||
1746 | |||
1747 | tmp_str = tr(": "); |
||
1748 | tmp_str.append(processor.manufacturer); |
||
1749 | itm_processor_manufacturer = new QTreeWidgetItem(itm_processor); |
||
1750 | itm_processor_manufacturer->setText(0, tmp_str); |
||
1751 | |||
1752 | tmp_str = tr(": "); |
||
1753 | tmp_str.append(QVariant(processor.clockSpeed).asString()); |
||
1754 | tmp_str.append(tr(" ")); |
||
1755 | itm_processor_clockSpeed = new QTreeWidgetItem(itm_processor); |
||
1756 | itm_processor_clockSpeed->setText(0, tmp_str); |
||
1757 | |||
1758 | |||
1759 | tmp_str = tr(": "); |
||
1760 | tmp_str.append(processor.socket); |
||
1761 | itm_processor_socket = new QTreeWidgetItem(itm_processor); |
||
1762 | itm_processor_socket->setText(0, tmp_str); |
||
1763 | |||
1764 | } |
||
1765 | |||
1766 | |||
254 | pingvin | 1767 | memory_moduls = MainWindow::getWmiRAM(IP_str, user_name_str, password_str); |
1768 | |||
1769 | if (!memory_moduls.isEmpty()){ |
||
255 | pingvin | 1770 | QTreeWidgetItem * itm_ram; |
1771 | int sum_cap=0; |
||
1772 | itm_ram = new QTreeWidgetItem(itm_tmp); |
||
1773 | |||
1774 | |||
254 | pingvin | 1775 | for (int i = 0; i < memory_moduls.count(); i++){ |
1776 | |||
1777 | QTreeWidgetItem * itm_ram_modul; |
||
1778 | QTreeWidgetItem * itm_modul_bank; |
||
1779 | QTreeWidgetItem * itm_modul_cap; // |
||
1780 | |||
1781 | QString tmp_str; |
||
1782 | tmp_str = tr(" : "); |
||
255 | pingvin | 1783 | sum_cap = sum_cap + memory_moduls.at(i).capacity/1024/1024; |
254 | pingvin | 1784 | tmp_str.append(QVariant(memory_moduls.at(i).capacity/1024/1024).asString()); |
255 | pingvin | 1785 | |
254 | pingvin | 1786 | tmp_str.append(tr(" ")); |
255 | pingvin | 1787 | itm_ram_modul = new QTreeWidgetItem(itm_ram); |
254 | pingvin | 1788 | itm_ram_modul->setText(0, tmp_str); |
1789 | |||
1790 | |||
1791 | } |
||
255 | pingvin | 1792 | QString cap_str; |
1793 | cap_str = tr(" : "); |
||
1794 | cap_str.append(QVariant(sum_cap).asString()); |
||
1795 | cap_str.append(tr(" ")); |
||
1796 | itm_ram->setText(0, cap_str); |
||
254 | pingvin | 1797 | |
255 | pingvin | 1798 | } |
254 | pingvin | 1799 | |
1800 | |||
255 | pingvin | 1801 | hdd_list = MainWindow::getWmiHDD(IP_str, user_name_str, password_str); |
1802 | |||
1803 | |||
1804 | if (!hdd_list.isEmpty()){ |
||
1805 | QTreeWidgetItem * itm_hdd_list; |
||
1806 | int sum_cap = 0; |
||
1807 | itm_hdd_list = new QTreeWidgetItem(itm_tmp); |
||
1808 | |||
1809 | |||
1810 | for (int i = 0; i < hdd_list.count(); i++){ |
||
1811 | |||
1812 | QTreeWidgetItem * itm_hdd; |
||
1813 | QTreeWidgetItem * itm_hdd_man; |
||
1814 | QTreeWidgetItem * itm_hdd_cap; |
||
1815 | QTreeWidgetItem * itm_hdd_serNum; |
||
1816 | QTreeWidgetItem * itm_hdd_size; // |
||
1817 | long size_lng; |
||
1818 | QString tmp_str; |
||
1819 | tmp_str = tr("Ƹ : "); |
||
1820 | sum_cap = sum_cap + hdd_list.at(i).size/1000/1000; |
||
1821 | |||
1822 | tmp_str.append(hdd_list.at(i).caption); |
||
1823 | tmp_str.append(tr(" ")); |
||
1824 | size_lng = hdd_list.at(i).size; |
||
1825 | size_lng = size_lng/1000/1000; |
||
1826 | |||
1827 | tmp_str.append(QVariant(int(size_lng)).asString()); |
||
1828 | tmp_str.append(tr(" s/n: ")); |
||
1829 | |||
1830 | tmp_str.append(hdd_list.at(i).serialNumber); |
||
1831 | |||
1832 | itm_hdd = new QTreeWidgetItem(itm_hdd_list); |
||
1833 | itm_hdd->setText(0, tmp_str); |
||
1834 | |||
1835 | |||
1836 | tmp_str = tr(": "); |
||
1837 | tmp_str.append((hdd_list.at(i).caption)); |
||
1838 | |||
1839 | itm_hdd_cap = new QTreeWidgetItem(itm_hdd); |
||
1840 | itm_hdd_cap->setText(0, tmp_str); |
||
1841 | |||
1842 | tmp_str = tr(": "); |
||
1843 | tmp_str.append((hdd_list.at(i).manufacturer)); |
||
1844 | |||
1845 | itm_hdd_man = new QTreeWidgetItem(itm_hdd); |
||
1846 | itm_hdd_man->setText(0, tmp_str); |
||
1847 | |||
1848 | tmp_str = tr(" : "); |
||
1849 | tmp_str.append(QVariant(int(size_lng)).asString()); |
||
1850 | tmp_str.append(tr(" ")); |
||
1851 | |||
1852 | itm_hdd_size = new QTreeWidgetItem(itm_hdd); |
||
1853 | itm_hdd_size->setText(0, tmp_str); |
||
1854 | |||
1855 | tmp_str = tr(" : "); |
||
1856 | tmp_str.append((hdd_list.at(i).serialNumber)); |
||
1857 | itm_hdd_serNum = itm_hdd_size = new QTreeWidgetItem(itm_hdd); |
||
1858 | itm_hdd_serNum->setText(0, tmp_str); |
||
1859 | |||
1860 | |||
1861 | } |
||
1862 | QString cap_str; |
||
1863 | cap_str = tr(" : "); |
||
1864 | cap_str.append(QVariant(sum_cap).asString()); |
||
1865 | cap_str.append(tr(" ")); |
||
1866 | itm_hdd_list->setText(0, cap_str); |
||
1867 | |||
254 | pingvin | 1868 | } |
1869 | |||
256 | pingvin | 1870 | |
1871 | cdrom_list = MainWindow::getWmiCDROM(IP_str, user_name_str, password_str); |
||
1872 | |||
1873 | |||
1874 | if (!cdrom_list.isEmpty()){ |
||
1875 | QTreeWidgetItem * itm_cdrom_list; |
||
1876 | |||
1877 | itm_cdrom_list = new QTreeWidgetItem(itm_tmp); |
||
1878 | itm_cdrom_list->setText(0, tr("CD/DVD :")); |
||
1879 | |||
1880 | |||
1881 | for (int i = 0; i < cdrom_list.count(); i++){ |
||
1882 | |||
1883 | QTreeWidgetItem * itm_cdrom; |
||
1884 | QTreeWidgetItem * itm_cdrom_man; |
||
1885 | QTreeWidgetItem * itm_cdrom_cap; |
||
1886 | QString tmp_str; |
||
1887 | tmp_str = tr(": "); |
||
1888 | tmp_str.append(cdrom_list.at(i).name); |
||
1889 | |||
1890 | itm_cdrom = new QTreeWidgetItem(itm_cdrom_list); |
||
1891 | itm_cdrom->setText(0, tmp_str); |
||
1892 | |||
1893 | tmp_str = tr(": "); |
||
1894 | tmp_str.append(cdrom_list.at(i).name); |
||
1895 | |||
1896 | |||
1897 | itm_cdrom_cap = new QTreeWidgetItem( itm_cdrom); |
||
1898 | itm_cdrom_cap->setText(0, tmp_str); |
||
1899 | |||
1900 | |||
1901 | tmp_str = tr(": "); |
||
1902 | tmp_str.append(cdrom_list.at(i).manufacturer); |
||
1903 | itm_cdrom_man = new QTreeWidgetItem( itm_cdrom); |
||
1904 | itm_cdrom_man->setText(0, tmp_str); |
||
1905 | |||
1906 | ui->treeWidget_3->expandItem( itm_cdrom_list); |
||
1907 | |||
1908 | } |
||
1909 | |||
1910 | |||
1911 | |||
1912 | } |
||
1913 | |||
1914 | |||
1915 | netcadr_list = MainWindow::getWmiNetCard(IP_str, user_name_str, password_str); |
||
1916 | |||
1917 | |||
1918 | if (!netcadr_list.isEmpty()){ |
||
1919 | QTreeWidgetItem * itm_netCard_list; |
||
1920 | |||
1921 | itm_netCard_list = new QTreeWidgetItem(itm_tmp); |
||
1922 | itm_netCard_list->setText(0, tr(" :")); |
||
1923 | |||
1924 | |||
1925 | for (int i = 0; i < cdrom_list.count(); i++){ |
||
1926 | |||
1927 | QTreeWidgetItem * itm_net_card; |
||
1928 | QTreeWidgetItem * itm_net_card_mac; |
||
1929 | QTreeWidgetItem * itm_net_card_cap; |
||
1930 | QString tmp_str; |
||
1931 | tmp_str = tr(" : "); |
||
1932 | tmp_str.append(netcadr_list.at(i).caption); |
||
1933 | |||
1934 | itm_net_card = new QTreeWidgetItem(itm_netCard_list); |
||
1935 | itm_net_card->setText(0, tmp_str); |
||
1936 | |||
1937 | |||
1938 | tmp_str = tr(": "); |
||
1939 | tmp_str.append(netcadr_list.at(i).caption); |
||
1940 | |||
1941 | |||
1942 | itm_net_card_cap = new QTreeWidgetItem(itm_net_card); |
||
1943 | itm_net_card_cap->setText(0, tmp_str); |
||
1944 | |||
1945 | |||
1946 | tmp_str = tr("MAC : "); |
||
1947 | tmp_str.append(netcadr_list.at(i).MACAddress); |
||
1948 | itm_net_card_mac = new QTreeWidgetItem(itm_net_card); |
||
1949 | itm_net_card_mac->setText(0, tmp_str); |
||
1950 | |||
1951 | ui->treeWidget_3->expandItem( itm_netCard_list); |
||
1952 | |||
1953 | } |
||
1954 | |||
257 | pingvin | 1955 | } |
256 | pingvin | 1956 | |
257 | pingvin | 1957 | soundcard_list = MainWindow::getWmiSoundCard(IP_str, user_name_str, password_str); |
256 | pingvin | 1958 | |
257 | pingvin | 1959 | if (!soundcard_list.isEmpty()){ |
1960 | QTreeWidgetItem * itm_soundCard_list; |
||
256 | pingvin | 1961 | |
257 | pingvin | 1962 | itm_soundCard_list = new QTreeWidgetItem(itm_tmp); |
1963 | itm_soundCard_list->setText(0, tr(" :")); |
||
256 | pingvin | 1964 | |
1965 | |||
257 | pingvin | 1966 | for (int i = 0; i < cdrom_list.count(); i++){ |
256 | pingvin | 1967 | |
257 | pingvin | 1968 | QTreeWidgetItem * itm_sound_card; |
1969 | //QTreeWidgetItem * itm_net_card_mac; |
||
1970 | //QTreeWidgetItem * itm_sou_card_cap; |
||
1971 | QString tmp_str; |
||
1972 | tmp_str = tr(" : "); |
||
1973 | tmp_str.append(soundcard_list.at(i).caption); |
||
256 | pingvin | 1974 | |
257 | pingvin | 1975 | itm_sound_card = new QTreeWidgetItem(itm_soundCard_list); |
1976 | itm_sound_card->setText(0, tmp_str); |
||
256 | pingvin | 1977 | |
257 | pingvin | 1978 | |
1979 | |||
1980 | |||
1981 | ui->treeWidget_3->expandItem( itm_soundCard_list); |
||
1982 | |||
1983 | } |
||
1984 | |||
1985 | |||
1986 | |||
1987 | |||
1988 | |||
1989 | |||
1990 | |||
1991 | } |
||
1992 | |||
255 | pingvin | 1993 | ui->treeWidget_3->expandItem(itm_tmp); |
1994 | // itm_tmp->setChildIndicatorPolicy(QTreeWidget:: |
||
250 | pingvin | 1995 | int i; |
1996 | i++; |
||
1997 | |||
1998 | |||
257 | pingvin | 1999 | } //while |
250 | pingvin | 2000 | |
2001 | |||
2002 | |||
2003 | } |
||
254 | pingvin | 2004 | |
2005 | |||
2006 | |||
2007 | |||
2008 |