Rev 221 | Rev 223 | Go to most recent revision | 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; // |
||
206 | int field_ID; |
||
192 | pingvin | 207 | int icon_field_index; |
112 | pingvin | 208 | bool filtr_empty; |
209 | bool ok; |
||
210 | QSqlQuery q; |
||
211 | QString sql_str; |
||
212 | QString str_tmp; |
||
113 | pingvin | 213 | QTreeWidgetItem * title_item; |
214 | QFont font; |
||
178 | pingvin | 215 | QIcon icon; |
114 | pingvin | 216 | // font.setWeight(40); |
217 | font.setBold(true); |
||
112 | pingvin | 218 | filtr_empty = filtr.isEmpty(); |
219 | classID = model_item->text(1); |
||
126 | pingvin | 220 | |
178 | pingvin | 221 | icon = model_item->icon(0); |
222 | |||
126 | pingvin | 223 | parentClassID = model_item->parent()->text(1); |
224 | |||
225 | pointerField = getPointerFieldName(parentClassID, classID); |
||
226 | |||
112 | pingvin | 227 | className = model_item->text(0); |
228 | inctance = getClassInctance(classID); |
||
114 | pingvin | 229 | |
118 | pingvin | 230 | if (!model_item->checkState(0)) return; |
231 | |||
113 | pingvin | 232 | title_item = new QTreeWidgetItem(parent_object_item); |
233 | title_item->setFont(0, font); |
||
234 | title_item->setText(0, className); |
||
114 | pingvin | 235 | title_item->setText(1, tr("class")); |
236 | title_item->setText(2, classID); |
||
115 | pingvin | 237 | title_item->setText(3, inctance); |
126 | pingvin | 238 | title_item->setText(4, pointerField); |
114 | pingvin | 239 | title_item->setTextColor(0, Qt::darkBlue); |
240 | |||
179 | pingvin | 241 | title_item->setIcon(0, icon); |
126 | pingvin | 242 | |
178 | pingvin | 243 | |
112 | pingvin | 244 | sql_str = tr("select * " |
245 | " from " // - |
||
246 | ); |
||
247 | sql_str.append(inctance); |
||
248 | if (!filtr.isEmpty()) { // |
||
249 | sql_str.append(tr(" ")); |
||
250 | sql_str.append(filtr); // |
||
251 | } |
||
252 | |||
253 | q.prepare(sql_str); |
||
254 | |||
255 | ok = q.exec(); |
||
256 | if (!ok) { |
||
118 | pingvin | 257 | QString debug_str; |
258 | debug_str.append(tr(" showObjects(): Database Error ")); |
||
259 | debug_str.append(tr(" : ")); |
||
260 | debug_str.append(inctance); |
||
261 | debug_str.append(tr(" : ")); |
||
262 | debug_str.append(filtr); |
||
263 | debug_str.append(q.lastError().text()); |
||
112 | pingvin | 264 | QMessageBox::critical( // . |
265 | this, // . |
||
118 | pingvin | 266 | QObject::tr(" showObjects(): Database Error"), // . |
267 | debug_str |
||
268 | // q.lastError().text() |
||
269 | ); // . |
||
112 | pingvin | 270 | return; |
271 | } |
||
272 | |||
273 | field_ID = q.record().indexOf(tr("ID")); |
||
114 | pingvin | 274 | |
192 | pingvin | 275 | icon_field_index = q.record().indexOf(tr("Icon")); |
114 | pingvin | 276 | /* |
113 | pingvin | 277 | if (q.size() <= 0) return; |
278 | title_item = new QTreeWidgetItem(parent_object_item); |
||
279 | title_item->setFont(0, font); |
||
280 | title_item->setText(0, className); |
||
114 | pingvin | 281 | */ |
112 | pingvin | 282 | |
283 | while(q.next()){ |
||
284 | if (q.record().count() > 1) |
||
285 | { |
||
286 | QString value_tmp; |
||
287 | QString ID_tmp; |
||
288 | QTreeWidgetItem * itm; |
||
289 | ID_tmp = q.value(field_ID).toString(); // |
||
290 | value_tmp = q.value(1).toString(); // ( ) |
||
113 | pingvin | 291 | // itm = new QTreeWidgetItem(parent_object_item); // , |
292 | itm = new QTreeWidgetItem(title_item); // , |
||
112 | pingvin | 293 | itm->setText(0, value_tmp); |
114 | pingvin | 294 | itm->setText(1, tr("object")); |
295 | itm->setText(2, ID_tmp); |
||
178 | pingvin | 296 | |
192 | pingvin | 297 | |
298 | if (icon_field_index != -1){ // |
||
299 | QVariant data; |
||
195 | pingvin | 300 | QByteArray bytes; |
192 | pingvin | 301 | QPixmap pix; |
302 | QIcon icn; |
||
195 | pingvin | 303 | QMap <QString, QPixmap> pixmap_map; |
304 | QList <QString> id_list; |
||
305 | QList <QPixmap> pixmap_list; |
||
306 | pixmap_map = MainWindow::getObjectsIcon(inctance); |
||
307 | if (!pixmap_map.isEmpty()) { |
||
308 | id_list = pixmap_map.keys(); |
||
309 | pixmap_list = pixmap_map.values(); |
||
310 | } |
||
311 | if (id_list.indexOf(ID_tmp) != -1) { |
||
312 | pix = pixmap_list.at(id_list.indexOf(ID_tmp)); |
||
313 | } |
||
314 | // data = q.record().value(icon_field_index); |
||
315 | // bytes = q.record().value(icon_field_index).toByteArray(); |
||
316 | // if (data.isValid() && (!data.isNull())) { |
||
317 | // if (!bytes.isEmpty()){ |
||
318 | // pix.loadFromData(data.toByteArray()); |
||
319 | // pix.loadFromData(bytes); |
||
193 | pingvin | 320 | if (pix.height() > 128) pix = pix.scaledToHeight(128); |
192 | pingvin | 321 | icn.addPixmap(pix); |
322 | itm->setIcon(0, icn); |
||
195 | pingvin | 323 | // } |
192 | pingvin | 324 | |
325 | |||
326 | |||
327 | } |
||
328 | |||
329 | |||
330 | |||
179 | pingvin | 331 | // itm->setIcon(0, icon); |
178 | pingvin | 332 | |
333 | |||
112 | pingvin | 334 | for (int i=0; i < model_item->childCount(); i++) // , |
335 | { |
||
336 | QTreeWidgetItem * model_item_tmp; // |
||
337 | QString pointer_name; |
||
338 | QString filtr_tmp; |
||
339 | bool pointer_isEmpty; |
||
340 | model_item_tmp = model_item->child(i); // |
||
341 | pointer_name = getPointerFieldName(classID, model_item->child(i)->text(1)); |
||
115 | pingvin | 342 | itm->setText(4, pointer_name); |
126 | pingvin | 343 | |
344 | // title_item->setText(4, pointer_name); |
||
345 | |||
346 | |||
112 | pingvin | 347 | pointer_isEmpty = pointer_name.isEmpty(); |
348 | filtr_tmp = tr("where "); |
||
349 | filtr_tmp.append(tr("`")); |
||
350 | filtr_tmp.append(pointer_name); |
||
351 | filtr_tmp.append(tr("` = '")); |
||
352 | filtr_tmp.append(ID_tmp); |
||
353 | filtr_tmp.append(tr("'")); |
||
354 | showObjects(itm, model_item_tmp, filtr_tmp); |
||
355 | //MainWindow::showObjectChildrens(ID_tmp, itm, model_item_tmp); |
||
356 | |||
357 | } |
||
358 | |||
359 | |||
360 | } |
||
361 | |||
362 | } |
||
363 | |||
364 | |||
365 | |||
366 | |||
367 | for (int i; i < model_item->childCount(); i++) // , |
||
368 | { |
||
369 | |||
370 | |||
371 | } |
||
372 | |||
111 | pingvin | 373 | } |
374 | |||
115 | pingvin | 375 | |
112 | pingvin | 376 | QString MainWindow::getPointerFieldName(QString parent_class_id, QString chield_class_id){ |
377 | |||
378 | QSqlQuery q; |
||
379 | QString sql_str; |
||
380 | QString str_tmp; |
||
381 | QString field; |
||
382 | QString result; |
||
383 | int field_name; |
||
384 | bool ok; |
||
385 | sql_str = tr("select * " |
||
386 | " from `DescriptionOfClasses` where `DescriptionOfClasses`.`FieldType` = 'pointer' and `DescriptionOfClasses`.`DefaultValue` = " // - |
||
387 | ); |
||
388 | |||
389 | sql_str.append(tr("'")); |
||
390 | sql_str.append(parent_class_id); |
||
391 | sql_str.append(tr("' ")); |
||
392 | sql_str.append(tr(" and `DescriptionOfClasses`.`ClassIdentifer` = '")); |
||
393 | sql_str.append(chield_class_id); |
||
394 | sql_str.append(tr("'")); |
||
395 | q.prepare(sql_str); |
||
396 | |||
397 | ok = q.exec(); |
||
398 | if (!ok) { |
||
399 | QMessageBox::critical( // . |
||
400 | this, // . |
||
401 | QObject::tr("Database Error"), // . |
||
402 | q.lastError().text()); // . |
||
403 | return result; |
||
404 | } |
||
405 | field_name = q.record().indexOf(tr("FieldName")); |
||
406 | while(q.next()){ |
||
407 | result = q.value(field_name).toString(); |
||
408 | } |
||
409 | return result; |
||
410 | } |
||
411 | |||
115 | pingvin | 412 | |
413 | |||
414 | void MainWindow::on_treeWidget_2_itemClicked ( QTreeWidgetItem * item, int column ){ |
||
415 | QString item_type; // ( ) |
||
416 | QString parent_object_id; |
||
417 | int i; |
||
418 | QTreeWidgetItem * parent_item; |
||
419 | item_type = item->text(1); |
||
420 | parent_item = item->parent(); |
||
157 | pingvin | 421 | |
422 | QString class_id; // |
||
423 | QString inctance; |
||
424 | QString filtr_tmp; |
||
425 | QMap <QString, QString> pointersList; |
||
158 | pingvin | 426 | QStringList dateFieldList; // "DATE" |
427 | QStringList boolFieldList; // "BOOL" |
||
200 | pingvin | 428 | QStringList fileFieldList; // , |
158 | pingvin | 429 | QString pointer_name; // |
157 | pingvin | 430 | |
431 | if (item_type == tr("object") || item_type == tr("class")){ |
||
432 | |||
433 | disconnect(sql_mogel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_sql_mogel_dataChanged(QModelIndex,QModelIndex))); |
||
434 | |||
435 | static QList<int> colomns_indexes; // |
||
436 | static QList<int> date_colomns_indexes; // "DATE" |
||
158 | pingvin | 437 | static QList <int> bool_colomns_indexes; // "BOOL" |
200 | pingvin | 438 | static QList <int> file_colomns_indexes; // , |
439 | |||
157 | pingvin | 440 | static QList<SpinBoxDelegate *> spin_delegate_list;// |
188 | pingvin | 441 | static int icon_index = -1; // |
442 | |||
443 | |||
157 | pingvin | 444 | SpinBoxDelegate * spin_delegate_tmp; |
445 | |||
446 | // "" |
||
188 | pingvin | 447 | |
448 | if (icon_index != -1) { |
||
449 | ui->tableView->setItemDelegateForColumn(icon_index, &standart_delegate); // |
||
450 | icon_index = -1; |
||
451 | } |
||
452 | |||
157 | pingvin | 453 | for (i=0; i < colomns_indexes.size(); i++){ // -: |
454 | ui->tableView->setItemDelegateForColumn(colomns_indexes.at(i), &standart_delegate ); // |
||
455 | // ui->tableView->setItemDelegateForColumn(colomns_indexes.at(i), &picture_delegate); |
||
456 | |||
457 | } |
||
200 | pingvin | 458 | colomns_indexes.clear(); // |
157 | pingvin | 459 | |
200 | pingvin | 460 | |
461 | // "" |
||
462 | |||
463 | for (i=0; i < file_colomns_indexes.size(); i++){ // -: |
||
464 | ui->tableView->setItemDelegateForColumn(file_colomns_indexes.at(i), &standart_delegate ); // |
||
465 | } |
||
466 | file_colomns_indexes.clear(); |
||
467 | |||
468 | |||
157 | pingvin | 469 | // "" "DATE" |
470 | for (i=0; i < date_colomns_indexes.size(); i++){ // -: |
||
471 | ui->tableView->setItemDelegateForColumn(date_colomns_indexes.at(i), &standart_delegate ); // |
||
472 | // ui->tableView->setItemDelegateForColumn(colomns_indexes.at(i), &picture_delegate); |
||
473 | |||
474 | } |
||
475 | |||
158 | pingvin | 476 | date_colomns_indexes.clear(); |
157 | pingvin | 477 | |
158 | pingvin | 478 | // "" "BOOL" |
479 | for (i=0; i < bool_colomns_indexes.size(); i++){ // -: |
||
480 | ui->tableView->setItemDelegateForColumn(bool_colomns_indexes.at(i), &standart_delegate ); // |
||
481 | // ui->tableView->setItemDelegateForColumn(colomns_indexes.at(i), &picture_delegate); |
||
157 | pingvin | 482 | |
158 | pingvin | 483 | } |
484 | |||
485 | bool_colomns_indexes.clear(); |
||
159 | pingvin | 486 | boolFieldsIndexes_global.clear(); |
158 | pingvin | 487 | |
115 | pingvin | 488 | if (item_type == tr("object")) |
489 | { |
||
157 | pingvin | 490 | QString ID; |
119 | pingvin | 491 | ui->pushButton->setEnabled(false); |
492 | ui->pushButton_2->setEnabled(false); |
||
493 | |||
115 | pingvin | 494 | class_id = parent_item->text(2); |
116 | pingvin | 495 | ID = item->text(2); |
496 | inctance = parent_item->text(3); |
||
497 | delete sql_mogel; |
||
127 | pingvin | 498 | |
499 | sql_mogel = new MyModel(); |
||
500 | |||
116 | pingvin | 501 | sql_mogel->setTable(inctance); |
119 | pingvin | 502 | // sql_mogel->setEditStrategy(QSqlTableModel::OnFieldChange); |
503 | sql_mogel->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
116 | pingvin | 504 | |
505 | filtr_tmp.append(tr("`")); |
||
506 | filtr_tmp.append(tr("ID")); |
||
507 | filtr_tmp.append(tr("`")); |
||
508 | filtr_tmp.append(tr(" = '")); |
||
509 | filtr_tmp.append(ID); |
||
510 | filtr_tmp.append(tr("'")); |
||
128 | pingvin | 511 | |
115 | pingvin | 512 | } |
513 | if (item_type == tr("class")) |
||
514 | { |
||
515 | QString parent_object_id; // |
||
125 | pingvin | 516 | |
126 | pingvin | 517 | QString parent_class_inctance; |
138 | pingvin | 518 | |
519 | |||
119 | pingvin | 520 | ui->pushButton->setEnabled(true); |
521 | ui->pushButton_2->setEnabled(true); |
||
522 | |||
115 | pingvin | 523 | parent_object_id = parent_item->text(2); |
118 | pingvin | 524 | |
525 | parentObject_id = parent_item->text(2); |
||
526 | |||
115 | pingvin | 527 | class_id = item->text(2); |
528 | inctance = item->text(3); |
||
529 | |||
126 | pingvin | 530 | pointer_name = item->text(4); |
116 | pingvin | 531 | delete sql_mogel; |
127 | pingvin | 532 | |
533 | sql_mogel = new MyModel(); |
||
534 | |||
535 | // sql_mogel = new QSqlTableModel(this); |
||
115 | pingvin | 536 | sql_mogel->setTable(inctance); |
119 | pingvin | 537 | // sql_mogel->setEditStrategy(QSqlTableModel::OnFieldChange); |
538 | sql_mogel->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
116 | pingvin | 539 | |
540 | if (!parent_object_id.isEmpty()) |
||
541 | { |
||
542 | filtr_tmp.append(tr("`")); |
||
543 | filtr_tmp.append(pointer_name); |
||
544 | filtr_tmp.append(tr("`")); |
||
545 | filtr_tmp.append(tr(" = '")); |
||
546 | filtr_tmp.append(parent_object_id); |
||
547 | filtr_tmp.append(tr("'")); |
||
126 | pingvin | 548 | |
155 | pingvin | 549 | } |
130 | pingvin | 550 | |
551 | |||
157 | pingvin | 552 | } |
130 | pingvin | 553 | |
153 | pingvin | 554 | |
130 | pingvin | 555 | |
157 | pingvin | 556 | pointersList = getPointersList(class_id); // - |
557 | dateFieldList = getDataFieldList(class_id); // c "DATE" |
||
158 | pingvin | 558 | boolFieldList = getBoolFieldList(class_id); // c "BOOL" |
200 | pingvin | 559 | fileFieldList = getFileFieldList(class_id); // , |
560 | |||
189 | pingvin | 561 | icon_index = getIconFieldIndex(inctance); // |
562 | if (icon_index != -1) ui->tableView->setItemDelegateForColumn(icon_index, iconDelegate); |
||
563 | sql_mogel->setIconIndex(icon_index); |
||
564 | |||
157 | pingvin | 565 | QMap <int, QString> pointersToModel; |
155 | pingvin | 566 | |
156 | pingvin | 567 | |
568 | |||
201 | pingvin | 569 | |
202 | pingvin | 570 | QMap <int, QString> filesFieldsToModel; |
201 | pingvin | 571 | for (int i=0; i < fileFieldList.count(); i++){ // , |
572 | // static FileDelegate flDelegate; |
||
573 | // static TimeEditDelegate dateDelegate("01.10.2010"); |
||
574 | QString fileFieldName; // |
||
575 | int fileFieldIndex; // |
||
576 | fileFieldName = fileFieldList.at(i); // , |
||
577 | fileFieldIndex = sql_mogel->record().indexOf(fileFieldName); // |
||
202 | pingvin | 578 | filesFieldsToModel.insert(fileFieldIndex, fileFieldName); |
579 | file_colomns_indexes.append(fileFieldIndex);// "file" |
||
201 | pingvin | 580 | ui->tableView->setItemDelegateForColumn(fileFieldIndex, fileDelegate); |
581 | |||
582 | } |
||
202 | pingvin | 583 | sql_mogel->setFilesFields(filesFieldsToModel);// , |
201 | pingvin | 584 | |
585 | |||
586 | |||
587 | |||
157 | pingvin | 588 | for (int i=0; i < dateFieldList.count(); i++){ // "DATA" |
158 | pingvin | 589 | static MyDEDelegate dateDelegate; |
590 | // static TimeEditDelegate dateDelegate("01.10.2010"); |
||
157 | pingvin | 591 | QString dateFieldName; // |
592 | int dataFieldIndex; // |
||
593 | dateFieldName = dateFieldList.at(i); // "DATA" |
||
594 | dataFieldIndex = sql_mogel->record().indexOf(dateFieldName); // |
||
595 | date_colomns_indexes.append(dataFieldIndex);// "DATA" |
||
596 | ui->tableView->setItemDelegateForColumn(dataFieldIndex, &dateDelegate); |
||
156 | pingvin | 597 | |
157 | pingvin | 598 | } |
130 | pingvin | 599 | |
153 | pingvin | 600 | |
158 | pingvin | 601 | for (int i=0; i < boolFieldList.count(); i++){ // "BOOL" |
602 | // // // // static MyDEDelegate dateDelegate; |
||
603 | // static TimeEditDelegate dateDelegate("01.10.2010"); |
||
604 | QString boolFieldName; // |
||
605 | int boolFieldIndex; // |
||
606 | boolFieldName = boolFieldList.at(i); // "BOOL" |
||
607 | boolFieldIndex = sql_mogel->record().indexOf(boolFieldName); // |
||
608 | bool_colomns_indexes.append(boolFieldIndex);// "DATA" |
||
609 | // ui->tableView->setItemDelegateForColumn(dataFieldIndex, &dateDelegate); |
||
130 | pingvin | 610 | |
158 | pingvin | 611 | } |
130 | pingvin | 612 | |
158 | pingvin | 613 | sql_mogel->setBooleansList(bool_colomns_indexes); |
159 | pingvin | 614 | boolFieldsIndexes_global = bool_colomns_indexes; |
158 | pingvin | 615 | |
157 | pingvin | 616 | for (int i=0; i < spin_delegate_list.count(); i++){ // |
617 | delete spin_delegate_list.at(i); |
||
618 | } |
||
130 | pingvin | 619 | |
157 | pingvin | 620 | spin_delegate_list.clear(); // |
130 | pingvin | 621 | |
157 | pingvin | 622 | QStringList pointersNames; |
623 | pointersNames = pointersList.keys(); // - |
||
130 | pingvin | 624 | |
138 | pingvin | 625 | |
626 | |||
627 | |||
628 | |||
179 | pingvin | 629 | // ui->tableView->setItemDelegateForColumn(2, picture_delegate); |
138 | pingvin | 630 | |
157 | pingvin | 631 | // ui->tableView->setRowHeight(1, 100); |
138 | pingvin | 632 | |
126 | pingvin | 633 | |
128 | pingvin | 634 | |
145 | pingvin | 635 | |
129 | pingvin | 636 | |
157 | pingvin | 637 | QStringList parentInctancesList = pointersList.values(); // |
129 | pingvin | 638 | |
157 | pingvin | 639 | for (i=0; i < pointersNames.size(); i++){ // -: |
640 | QString pointerName; |
||
153 | pingvin | 641 | |
157 | pingvin | 642 | int pointerIndex; |
643 | pointerName = pointersNames.at(i); // - |
||
644 | pointerIndex = sql_mogel->record().indexOf(pointerName); // |
||
645 | colomns_indexes.append(pointerIndex); // |
||
646 | spin_delegate_tmp = new SpinBoxDelegate(); |
||
153 | pingvin | 647 | |
157 | pingvin | 648 | // // spinDelegate.setInctance(parentInctancesList.at(i)); // |
649 | // // spinDelegate.getItems(); // |
||
153 | pingvin | 650 | |
157 | pingvin | 651 | spin_delegate_tmp->setInctance(parentInctancesList.at(i)); |
652 | spin_delegate_tmp->getItems(); |
||
128 | pingvin | 653 | |
157 | pingvin | 654 | spin_delegate_list.append(spin_delegate_tmp); |
128 | pingvin | 655 | |
157 | pingvin | 656 | // // ui->tableView->setItemDelegateForColumn(pointerIndex, &spinDelegate); // |
118 | pingvin | 657 | |
157 | pingvin | 658 | ui->tableView->setItemDelegateForColumn(pointerIndex, spin_delegate_tmp); |
115 | pingvin | 659 | |
157 | pingvin | 660 | pointersToModel.insert(pointerIndex, parentInctancesList.at(i)); // |
661 | } |
||
140 | pingvin | 662 | |
201 | pingvin | 663 | sql_mogel->setPointers(pointersToModel); // |
140 | pingvin | 664 | |
157 | pingvin | 665 | pointer_index = sql_mogel->record().indexOf(pointer_name); // , , ! :-) |
140 | pingvin | 666 | |
667 | |||
668 | |||
669 | |||
157 | pingvin | 670 | sql_mogel->setFilter(filtr_tmp); |
162 | pingvin | 671 | sql_mogel->setSort(1, Qt::AscendingOrder); |
157 | pingvin | 672 | sql_mogel->select(); |
154 | pingvin | 673 | |
162 | pingvin | 674 | |
675 | |||
157 | pingvin | 676 | connect(sql_mogel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_sql_mogel_dataChanged(QModelIndex,QModelIndex))); |
140 | pingvin | 677 | |
157 | pingvin | 678 | ui->tableView->setModel(sql_mogel); |
189 | pingvin | 679 | ui->tableView->hideColumn(0); |
157 | pingvin | 680 | ui->tableView->resizeColumnsToContents(); |
189 | pingvin | 681 | ui->tableView->resizeRowsToContents(); |
140 | pingvin | 682 | |
683 | |||
189 | pingvin | 684 | |
685 | |||
686 | |||
115 | pingvin | 687 | } |
688 | |||
689 | } |
||
690 | |||
691 | |||
118 | pingvin | 692 | void MainWindow::on_pushButton_clicked(){ // " " |
693 | int row = sql_mogel->rowCount(); |
||
694 | sql_mogel->insertRows(row, 1); |
||
695 | sql_mogel->setData(sql_mogel->index(row, 1), QVariant(tr(" ")), Qt::EditRole); // " " |
||
696 | if (pointer_index > 0) { |
||
697 | sql_mogel->setData(sql_mogel->index(row, pointer_index), QVariant(parentObject_id), Qt::EditRole); // " " |
||
698 | } |
||
119 | pingvin | 699 | // sql_mogel->submitAll(); |
118 | pingvin | 700 | |
701 | } |
||
119 | pingvin | 702 | |
703 | void MainWindow::on_pushButton_2_clicked(){ // " " |
||
704 | int i; |
||
705 | i++; |
||
120 | pingvin | 706 | QModelIndex model_index; |
707 | QItemSelectionModel *selectionModel = ui->tableView->selectionModel(); |
||
708 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
||
709 | QList<int> selectedRows; |
||
710 | selectedRows.clear(); |
||
711 | foreach (model_index, indexes){ // |
||
712 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) selectedRows.append(model_index.row()); // |
||
119 | pingvin | 713 | |
714 | } |
||
120 | pingvin | 715 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // |
119 | pingvin | 716 | |
717 | |||
120 | pingvin | 718 | for (int m =0; m < selectedRows.size(); ++m){ |
719 | |||
720 | // ClassEditor::removeClass(selectedRows.at(m)); |
||
721 | |||
722 | sql_mogel->removeRow(selectedRows.at(m)); |
||
723 | |||
724 | } |
||
725 | sql_mogel->submitAll(); |
||
726 | getDatabaseData(); |
||
727 | |||
728 | } |
||
729 | |||
730 | |||
119 | pingvin | 731 | void MainWindow::on_pushButton_3_clicked(){ // "" |
732 | int i; |
||
733 | i++; |
||
734 | sql_mogel->submitAll(); |
||
735 | getDatabaseData(); |
||
736 | ui->pushButton_3->setEnabled(false); |
||
737 | ui->pushButton_4->setEnabled(false); |
||
738 | sql_mogel->select(); |
||
739 | |||
740 | } |
||
741 | |||
742 | |||
743 | void MainWindow::on_pushButton_4_clicked(){ // " " |
||
744 | int i; |
||
745 | i++; |
||
746 | sql_mogel->select(); |
||
747 | ui->pushButton_3->setEnabled(false); |
||
748 | ui->pushButton_4->setEnabled(false); |
||
190 | pingvin | 749 | ui->tableView_2->resizeRowsToContents(); |
750 | ui->tableView_2->resizeColumnsToContents(); |
||
119 | pingvin | 751 | } |
752 | |||
753 | |||
144 | pingvin | 754 | void MainWindow::on_pushButton_5_clicked(){// " " |
755 | |||
756 | int i; |
||
757 | i++; |
||
758 | int row = model_for_ListModelsTable->rowCount(); |
||
759 | model_for_ListModelsTable->insertRows(row, 1); |
||
760 | model_for_ListModelsTable->setData(model_for_ListModelsTable->index(row, 1), QVariant(tr(" ")), Qt::EditRole); // " " |
||
761 | // model_for_ListModelsTable->setData(sql_mogel->index(row, pointer_index), QVariant(parentObject_id), Qt::EditRole); // " " |
||
762 | |||
763 | // sql_mogel->submitAll(); |
||
764 | |||
765 | |||
766 | } |
||
767 | |||
768 | void MainWindow::on_pushButton_6_clicked(){// " " |
||
769 | |||
770 | QModelIndex model_index; |
||
771 | QItemSelectionModel *selectionModel = ui->tableView_2->selectionModel(); |
||
772 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
||
773 | QList<int> selectedRows; |
||
774 | selectedRows.clear(); |
||
775 | foreach (model_index, indexes){ // |
||
776 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) selectedRows.append(model_index.row()); // |
||
777 | |||
778 | } |
||
779 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // |
||
780 | |||
781 | |||
782 | for (int m =0; m < selectedRows.size(); ++m){ |
||
783 | |||
784 | // ClassEditor::removeClass(selectedRows.at(m)); |
||
785 | |||
786 | model_for_ListModelsTable->removeRow(selectedRows.at(m)); |
||
787 | |||
788 | } |
||
789 | model_for_ListModelsTable->submitAll(); |
||
790 | // getDatabaseData(); |
||
791 | |||
792 | } |
||
793 | |||
794 | |||
146 | pingvin | 795 | void MainWindow::on_pushButton_7_clicked(){// "" |
796 | model_for_ListModelsTable->submitAll(); |
||
797 | ui->pushButton_7->setEnabled(false); |
||
798 | ui->pushButton_8->setEnabled(false); |
||
799 | model_is_build = false; |
||
800 | MainWindow::readModels(); |
||
801 | model_is_build = true; |
||
802 | MainWindow::getDatabaseData(); |
||
803 | } |
||
144 | pingvin | 804 | |
146 | pingvin | 805 | void MainWindow::on_pushButton_8_clicked(){// "" ( ) |
806 | model_for_ListModelsTable->select(); |
||
807 | ui->pushButton_7->setEnabled(false); |
||
808 | ui->pushButton_8->setEnabled(false); |
||
190 | pingvin | 809 | |
146 | pingvin | 810 | } |
811 | |||
215 | pingvin | 812 | |
813 | void MainWindow::on_pushButton_9_clicked()// " " ( ) |
||
814 | { |
||
815 | QString class_id; |
||
816 | QString model_id; |
||
817 | class_id = ui->treeWidget->currentItem()->text(1); |
||
818 | model_id = ui->treeWidget->currentItem()->text(6); |
||
221 | pingvin | 819 | int row = filter_model->rowCount(); |
820 | filter_model->insertRows(row, 1); |
||
821 | filter_model->setData(filter_model->index(row, 1), QVariant(model_id), Qt::EditRole); // "Model ID" |
||
822 | filter_model->setData(filter_model->index(row, 2), QVariant(class_id), Qt::EditRole); // "Class ID" |
||
217 | pingvin | 823 | ui->pushButton_11->setEnabled(true); |
824 | ui->pushButton_12->setEnabled(true); |
||
215 | pingvin | 825 | |
826 | } |
||
827 | |||
217 | pingvin | 828 | void MainWindow::on_pushButton_10_clicked()// " " ( ) |
829 | { |
||
221 | pingvin | 830 | QModelIndex model_index; |
831 | QItemSelectionModel *selectionModel = ui->tableView_3->selectionModel(); |
||
832 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
||
833 | QList<int> selectedRows; |
||
834 | selectedRows.clear(); |
||
835 | foreach (model_index, indexes){ // |
||
836 | if (!selectedRows.contains(model_index.row()) /*&& (model_index.column()==1)*/) selectedRows.append(model_index.row()); // |
||
217 | pingvin | 837 | |
221 | pingvin | 838 | } |
839 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // |
||
840 | |||
841 | |||
842 | for (int m =0; m < selectedRows.size(); ++m){ |
||
843 | |||
844 | // ClassEditor::removeClass(selectedRows.at(m)); |
||
845 | |||
846 | filter_model->removeRow(selectedRows.at(m)); |
||
847 | |||
848 | } |
||
849 | filter_model->submitAll(); |
||
850 | // getDatabaseData(); |
||
222 | pingvin | 851 | model_is_build = false; |
852 | MainWindow::readModels(); |
||
853 | model_is_build = true; |
||
854 | MainWindow::getDatabaseData(); |
||
221 | pingvin | 855 | |
217 | pingvin | 856 | } |
857 | |||
858 | void MainWindow::on_pushButton_11_clicked()// "" ( ) |
||
859 | { |
||
221 | pingvin | 860 | filter_model->submitAll(); |
861 | ui->pushButton_11->setEnabled(false); |
||
862 | ui->pushButton_12->setEnabled(false); |
||
222 | pingvin | 863 | |
864 | model_is_build = false; |
||
865 | MainWindow::readModels(); |
||
866 | model_is_build = true; |
||
867 | MainWindow::getDatabaseData(); |
||
217 | pingvin | 868 | } |
869 | |||
870 | void MainWindow::on_pushButton_12_clicked()// " " ( ) |
||
871 | { |
||
221 | pingvin | 872 | filter_model->select(); |
873 | ui->pushButton_11->setEnabled(false); |
||
874 | ui->pushButton_12->setEnabled(false); |
||
217 | pingvin | 875 | } |
876 | |||
877 | |||
119 | pingvin | 878 | void MainWindow::on_sql_mogel_dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ // |
879 | int i; |
||
880 | i++; |
||
189 | pingvin | 881 | |
882 | if (sql_mogel->iconIndex() !=-1) { |
||
883 | ui->tableView->resizeColumnsToContents(); |
||
884 | ui->tableView->resizeRowsToContents(); |
||
885 | } |
||
886 | |||
160 | pingvin | 887 | if ((topLeft == bottomRight) && (boolFieldsIndexes_global.indexOf(topLeft.column()) != -1)) |
888 | { |
||
889 | ui->pushButton_3->setEnabled(false); |
||
890 | ui->pushButton_4->setEnabled(false); |
||
891 | return; |
||
892 | } |
||
893 | |||
894 | |||
119 | pingvin | 895 | ui->pushButton_3->setEnabled(true); |
896 | ui->pushButton_4->setEnabled(true); |
||
897 | |||
898 | } |
||
128 | pingvin | 899 | |
146 | pingvin | 900 | void MainWindow::on_model_for_ListModelsTable_dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ // |
128 | pingvin | 901 | |
146 | pingvin | 902 | ui->pushButton_7->setEnabled(true); |
903 | ui->pushButton_8->setEnabled(true); |
||
904 | } |
||
905 | |||
906 | |||
221 | pingvin | 907 | |
908 | |||
909 | void MainWindow::on_filter_model_dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ) // |
||
910 | |||
911 | { |
||
912 | ui->pushButton_11->setEnabled(true); |
||
913 | ui->pushButton_12->setEnabled(true); |
||
914 | } |
||
915 | |||
916 | |||
917 | |||
918 | |||
919 | |||
128 | pingvin | 920 | // -, - |
921 | // - |
||
922 | |||
923 | QMap <QString, QString> MainWindow::getPointersList(QString class_id){ |
||
924 | QMap <QString, QString> result_map; |
||
925 | QSqlQuery q; |
||
926 | QString sql_str; |
||
927 | QString str_tmp; |
||
928 | QString field; |
||
929 | QString result; |
||
930 | int field_name, field_default_value; |
||
931 | bool ok; |
||
932 | sql_str = tr("select * " |
||
933 | " from `DescriptionOfClasses` where `DescriptionOfClasses`.`FieldType` = 'pointer' and `DescriptionOfClasses`.`ClassIdentifer` = " // - |
||
934 | ); |
||
935 | |||
936 | sql_str.append(tr("'")); |
||
937 | sql_str.append(class_id); |
||
938 | sql_str.append(tr("' ")); |
||
939 | // sql_str.append(tr(" and `DescriptionOfClasses`.`ClassIdentifer` = '")); |
||
940 | // sql_str.append(chield_class_id); |
||
941 | // sql_str.append(tr("'")); |
||
942 | q.prepare(sql_str); |
||
943 | |||
944 | ok = q.exec(); |
||
945 | if (!ok) { |
||
946 | QMessageBox::critical( // . |
||
947 | this, // . |
||
948 | QObject::tr("Database Error"), // . |
||
949 | q.lastError().text()); // . |
||
950 | return result_map; |
||
951 | } |
||
952 | field_name = q.record().indexOf(tr("FieldName")); |
||
953 | field_default_value = q.record().indexOf(tr("DefaultValue")); |
||
954 | while(q.next()){ |
||
955 | QString pointerFieldName; |
||
956 | QString parentClassID; |
||
957 | QString parentClassInctance; |
||
958 | |||
959 | pointerFieldName = q.value(field_name).toString(); |
||
960 | parentClassID = q.value(field_default_value).toString(); |
||
961 | parentClassInctance = getClassInctance(parentClassID); |
||
962 | result_map.insert(pointerFieldName, parentClassInctance); |
||
963 | |||
964 | |||
965 | } |
||
966 | |||
967 | return result_map; |
||
968 | } |
||
969 | |||
132 | pingvin | 970 | |
971 | |||
972 | |||
973 | |||
155 | pingvin | 974 | QStringList MainWindow::getDataFieldList(QString class_id){ // c "", |
975 | // - |
||
132 | pingvin | 976 | |
155 | pingvin | 977 | QStringList result_str; |
978 | QSqlQuery q; |
||
979 | QString sql_str; |
||
980 | QString str_tmp; |
||
981 | QString field; |
||
982 | QString result; |
||
983 | int field_name, field_default_value; |
||
984 | bool ok; |
||
985 | sql_str = tr("select * " |
||
986 | " from `DescriptionOfClasses` where `DescriptionOfClasses`.`FieldType` = 'DATE' and `DescriptionOfClasses`.`ClassIdentifer` = " // - |
||
987 | ); |
||
988 | |||
989 | sql_str.append(tr("'")); |
||
990 | sql_str.append(class_id); |
||
991 | sql_str.append(tr("' ")); |
||
992 | // sql_str.append(tr(" and `DescriptionOfClasses`.`ClassIdentifer` = '")); |
||
993 | // sql_str.append(chield_class_id); |
||
994 | // sql_str.append(tr("'")); |
||
995 | q.prepare(sql_str); |
||
996 | |||
997 | ok = q.exec(); |
||
998 | if (!ok) { |
||
999 | QMessageBox::critical( // . |
||
1000 | this, // . |
||
1001 | QObject::tr("Database Error"), // . |
||
1002 | q.lastError().text()); // . |
||
1003 | return result_str; |
||
1004 | } |
||
1005 | field_name = q.record().indexOf(tr("FieldName")); |
||
1006 | // field_default_value = q.record().indexOf(tr("DefaultValue")); |
||
1007 | while(q.next()){ |
||
1008 | QString DataFieldName; |
||
1009 | |||
1010 | DataFieldName = q.value(field_name).toString(); |
||
1011 | result_str.append(DataFieldName); |
||
1012 | |||
1013 | |||
1014 | } |
||
1015 | |||
1016 | return result_str; |
||
1017 | } |
||
1018 | |||
1019 | |||
1020 | |||
188 | pingvin | 1021 | int MainWindow::getIconFieldIndex(QString inctance){ // |
1022 | |||
1023 | QSqlQuery q; |
||
1024 | bool ok; |
||
1025 | int icon_field; |
||
1026 | QString sql_str; |
||
1027 | sql_str = tr("select * from `"); // - |
||
1028 | sql_str.append(inctance); |
||
1029 | sql_str.append(tr("`")); |
||
1030 | q.prepare(sql_str); |
||
1031 | |||
1032 | ok = q.exec(); |
||
1033 | if (!ok) { |
||
1034 | QMessageBox::critical( // . |
||
1035 | this, // . |
||
1036 | QObject::tr("Database Error"), // . |
||
1037 | q.lastError().text()); // . |
||
189 | pingvin | 1038 | |
1039 | return -1; |
||
188 | pingvin | 1040 | } |
1041 | |||
1042 | icon_field = q.record().indexOf(tr("Icon")); |
||
189 | pingvin | 1043 | return icon_field; |
188 | pingvin | 1044 | |
1045 | |||
1046 | } |
||
1047 | |||
1048 | |||
200 | pingvin | 1049 | QStringList MainWindow::getFileFieldList(QString class_id){ // , |
1050 | QStringList result_str; |
||
1051 | QSqlQuery q; |
||
1052 | QString sql_str; |
||
1053 | bool ok; |
||
1054 | int field_name, field_default_value; |
||
1055 | sql_str = tr("select * " |
||
1056 | " from `DescriptionOfClasses` where `DescriptionOfClasses`.`Comment` = 'file' and `DescriptionOfClasses`.`ClassIdentifer` = " // - |
||
1057 | ); |
||
1058 | sql_str.append(tr("'")); |
||
1059 | sql_str.append(class_id); |
||
1060 | sql_str.append(tr("' ")); |
||
1061 | q.prepare(sql_str); |
||
1062 | |||
1063 | ok = q.exec(); |
||
1064 | if (!ok) { |
||
1065 | QMessageBox::critical( // . |
||
1066 | this, // . |
||
1067 | QObject::tr("Database Error"), // . |
||
1068 | q.lastError().text()); // . |
||
1069 | return result_str; |
||
1070 | } |
||
1071 | |||
1072 | field_name = q.record().indexOf(tr("FieldName")); |
||
1073 | // field_default_value = q.record().indexOf(tr("DefaultValue")); |
||
1074 | while(q.next()){ |
||
1075 | QString FileFieldName; |
||
1076 | |||
1077 | FileFieldName = q.value(field_name).toString(); |
||
1078 | result_str.append(FileFieldName); |
||
1079 | |||
1080 | |||
1081 | } |
||
1082 | |||
1083 | return result_str; |
||
1084 | |||
1085 | } |
||
1086 | |||
1087 | |||
1088 | |||
158 | pingvin | 1089 | QStringList MainWindow::getBoolFieldList(QString class_id){ // c "bool" |
155 | pingvin | 1090 | |
158 | pingvin | 1091 | QStringList result_str; |
1092 | QSqlQuery q; |
||
1093 | QString sql_str; |
||
1094 | QString str_tmp; |
||
1095 | QString field; |
||
1096 | QString result; |
||
1097 | int field_name, field_default_value; |
||
1098 | bool ok; |
||
1099 | sql_str = tr("select * " |
||
1100 | " from `DescriptionOfClasses` where `DescriptionOfClasses`.`FieldType` = 'BOOL' and `DescriptionOfClasses`.`ClassIdentifer` = " // - |
||
1101 | ); |
||
1102 | |||
1103 | sql_str.append(tr("'")); |
||
1104 | sql_str.append(class_id); |
||
1105 | sql_str.append(tr("' ")); |
||
1106 | // sql_str.append(tr(" and `DescriptionOfClasses`.`ClassIdentifer` = '")); |
||
1107 | // sql_str.append(chield_class_id); |
||
1108 | // sql_str.append(tr("'")); |
||
1109 | q.prepare(sql_str); |
||
1110 | |||
1111 | ok = q.exec(); |
||
1112 | if (!ok) { |
||
1113 | QMessageBox::critical( // . |
||
1114 | this, // . |
||
1115 | QObject::tr("Database Error"), // . |
||
1116 | q.lastError().text()); // . |
||
1117 | return result_str; |
||
1118 | } |
||
1119 | field_name = q.record().indexOf(tr("FieldName")); |
||
1120 | // field_default_value = q.record().indexOf(tr("DefaultValue")); |
||
1121 | while(q.next()){ |
||
1122 | QString DataFieldName; |
||
1123 | |||
1124 | DataFieldName = q.value(field_name).toString(); |
||
1125 | result_str.append(DataFieldName); |
||
1126 | |||
1127 | |||
1128 | } |
||
1129 | |||
1130 | return result_str; |
||
1131 | } |
||
1132 | |||
1133 | |||
1134 | |||
1135 | |||
1136 | |||
132 | pingvin | 1137 | // |
1138 | |||
1139 | void MainWindow::readSettings() |
||
1140 | { |
||
1141 | QSettings settings("Trolltech", "Application Example"); |
||
1142 | baseName = settings.value("baseName", "an_db").toString(); |
||
1143 | userName = settings.value("userName", "an").toString(); |
||
1144 | password = settings.value("password", "393939").toString(); |
||
1145 | tableName = settings.value("tableName", "inventar").toString(); |
||
1146 | hostName = settings.value("hostName", "server").toString(); |
||
1147 | // resize(size); |
||
1148 | // move(pos);tableName |
||
1149 | } |
||
1150 | |||
1151 | |||
1152 | void MainWindow::writeSettings() |
||
1153 | { |
||
1154 | QSettings settings("Trolltech", "Application Example"); |
||
1155 | settings.setValue("baseName", baseName); |
||
1156 | settings.setValue("userName", userName); |
||
1157 | settings.setValue("password", password); |
||
1158 | settings.setValue("tableName", tableName); |
||
1159 | settings.setValue("hostName", hostName); |
||
1160 | } |
||
1161 | |||
1162 | |||
1163 | |||
1164 | void MainWindow::applySetting() |
||
1165 | { |
||
1166 | bool ok; |
||
1167 | baseName = setFrm.lineEdit->text(); |
||
1168 | userName = setFrm.lineEdit_2->text(); |
||
1169 | password = setFrm.lineEdit_3->text(); |
||
1170 | // tableName = setFrm->lineEdit_4->text(); |
||
1171 | hostName = setFrm.lineEdit_5->text(); |
||
1172 | writeSettings(); |
||
1173 | |||
1174 | |||
1175 | ok=openDataBase(); |
||
1176 | if (!ok) return; |
||
1177 | // // // ui->treeWidget->clear(); // |
||
1178 | |||
1179 | // // // buildPreviewModel(tr(" "), tr("1")); |
||
149 | pingvin | 1180 | |
1181 | model_is_build = false; |
||
1182 | |||
132 | pingvin | 1183 | class_list_map.clear(); // |
149 | pingvin | 1184 | rootItems.clear(); |
1185 | models_items.clear(); |
||
151 | pingvin | 1186 | |
1187 | disconnect(model_for_ListModelsTable, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_model_for_ListModelsTable_dataChanged(QModelIndex,QModelIndex))); |
||
149 | pingvin | 1188 | delete model_for_ListModelsTable; |
151 | pingvin | 1189 | |
149 | pingvin | 1190 | initListModelsTablle(); |
1191 | |||
151 | pingvin | 1192 | connect(model_for_ListModelsTable, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_model_for_ListModelsTable_dataChanged(QModelIndex,QModelIndex))); |
1193 | |||
149 | pingvin | 1194 | ui->treeWidget->clear(); |
132 | pingvin | 1195 | initComboBox(); |
149 | pingvin | 1196 | // model_for_ListModelsTable->select(); |
1197 | MainWindow::readModels(); |
||
1198 | |||
1199 | |||
1200 | |||
132 | pingvin | 1201 | // // // getDatabaseData(); |
1202 | // delete setFrm; |
||
149 | pingvin | 1203 | |
1204 | |||
1205 | model_is_build = true; |
||
150 | pingvin | 1206 | getDatabaseData(); |
132 | pingvin | 1207 | setFrm.close(); |
1208 | } |
||
1209 | |||
1210 | |||
1211 | void MainWindow::getSetting() |
||
1212 | { |
||
1213 | // setFrm = new settingForm; |
||
1214 | // // // connect(setFrm.pushButton, SIGNAL(clicked()), this, SLOT(applySetting())); |
||
1215 | setFrm.lineEdit->setText(baseName); |
||
1216 | setFrm.lineEdit_2->setText(userName); |
||
1217 | setFrm.lineEdit_3->setText(password); |
||
1218 | // setFrm->lineEdit_4->setText(tableName); |
||
1219 | setFrm.lineEdit_5->setText(hostName); |
||
1220 | setFrm.show(); |
||
1221 | |||
1222 | |||
1223 | |||
1224 | } |
||
144 | pingvin | 1225 | |
1226 | |||
1227 | |||
1228 | |||
1229 | void MainWindow::readModels(){ |
||
1230 | |||
145 | pingvin | 1231 | int row = model_for_ListModelsTable->rowCount(); |
147 | pingvin | 1232 | QList <QTreeWidgetItem*> modelsItemsList; |
1233 | QList <int> row_list; |
||
1234 | modelsItemsList = models_items.values(); |
||
1235 | |||
1236 | row_list = models_items.keys(); |
||
1237 | |||
1238 | |||
1239 | |||
145 | pingvin | 1240 | rootItems.clear(); |
222 | pingvin | 1241 | root_items_list.clear(); |
145 | pingvin | 1242 | ui->treeWidget->clear(); |
144 | pingvin | 1243 | for (int i=0; i < row; i++){ |
1244 | QTreeWidgetItem * item_tmp; |
||
1245 | QString modelName; |
||
213 | pingvin | 1246 | QString model_id; |
147 | pingvin | 1247 | |
144 | pingvin | 1248 | bool enabled; |
147 | pingvin | 1249 | |
1250 | |||
1251 | |||
1252 | //models_items.values(); |
||
1253 | // modelString = |
||
1254 | |||
144 | pingvin | 1255 | modelName = model_for_ListModelsTable->data(model_for_ListModelsTable->index(i, 1)).toString(); |
213 | pingvin | 1256 | model_id = model_for_ListModelsTable->data(model_for_ListModelsTable->index(i, 0)).toString(); |
1257 | |||
144 | pingvin | 1258 | enabled = model_for_ListModelsTable->data(model_for_ListModelsTable->index(i, 3)).toBool(); |
1259 | item_tmp = new QTreeWidgetItem(ui->treeWidget); |
||
1260 | item_tmp->setText(0, modelName); |
||
147 | pingvin | 1261 | item_tmp->setText(4, QVariant(i).toString()); // 4 |
213 | pingvin | 1262 | item_tmp->setText(6, model_id); |
144 | pingvin | 1263 | if (enabled) item_tmp->setCheckState(0,Qt::Checked); |
1264 | else item_tmp->setCheckState(0,Qt::Unchecked); |
||
145 | pingvin | 1265 | |
1266 | root_items_list << item_tmp; |
||
1267 | |||
144 | pingvin | 1268 | rootItems.append(item_tmp); |
147 | pingvin | 1269 | |
1270 | models_items[i] =item_tmp ; |
||
1271 | |||
1272 | |||
145 | pingvin | 1273 | modelString = model_for_ListModelsTable->data(model_for_ListModelsTable->index(i, 2)).toString(); |
1274 | if (modelString.isEmpty()) continue; |
||
215 | pingvin | 1275 | else setupModelData(modelString.split(QString("\n")), item_tmp, i, model_id); // |
144 | pingvin | 1276 | |
1277 | } |
||
149 | pingvin | 1278 | |
144 | pingvin | 1279 | } |
174 | pingvin | 1280 | |
1281 | |||
1282 | |||
1283 | |||
1284 | QMap <QString, QPixmap> MainWindow::getClassesIcons(){ // |
||
1285 | // ID , - |
||
1286 | |||
1287 | QMap <QString, QPixmap> result_map; |
||
1288 | QSqlQuery q; |
||
1289 | QString sql_str; |
||
1290 | QString str_tmp; |
||
1291 | QString field; |
||
1292 | QString result; |
||
1293 | int field_id, field_icon; |
||
1294 | bool ok; |
||
1295 | sql_str = tr("select * " |
||
1296 | " from `ListOfClasses` " // - |
||
1297 | ); |
||
1298 | |||
1299 | q.prepare(sql_str); |
||
1300 | |||
1301 | ok = q.exec(); |
||
1302 | if (!ok) { |
||
1303 | QMessageBox::critical( // . |
||
1304 | this, // . |
||
1305 | QObject::tr("Database Error"), // . |
||
1306 | q.lastError().text()); // . |
||
1307 | return result_map; |
||
1308 | } |
||
1309 | field_id = q.record().indexOf(tr("ID")); |
||
1310 | field_icon = q.record().indexOf(tr("Icon")); |
||
1311 | while(q.next()){ |
||
1312 | QString classID; |
||
1313 | QByteArray loadimage = q.value(field_icon).toByteArray(); |
||
1314 | classID = q.value(field_id).toString(); |
||
1315 | if( !loadimage.isEmpty() ) |
||
1316 | { |
||
1317 | QPixmap pixmap; |
||
1318 | pixmap.loadFromData(loadimage); |
||
1319 | result_map.insert(classID, pixmap); |
||
1320 | |||
1321 | } |
||
1322 | else continue; |
||
1323 | |||
1324 | |||
1325 | |||
1326 | } |
||
1327 | |||
1328 | return result_map; |
||
1329 | |||
1330 | |||
1331 | } |
||
195 | pingvin | 1332 | |
1333 | |||
1334 | |||
1335 | |||
1336 | QMap <QString, QPixmap> MainWindow::getObjectsIcon(QString inctance){ // |
||
1337 | // ID , - |
||
1338 | QMap <QString, QPixmap> result_map; |
||
1339 | QSqlQuery q; |
||
1340 | QString sql_str; |
||
1341 | QString str_tmp; |
||
1342 | int field_id, field_icon; |
||
1343 | bool ok; |
||
1344 | sql_str = tr("select `ID`, `Icon` " |
||
1345 | " from `" // - |
||
1346 | ); |
||
1347 | sql_str.append(inctance); |
||
1348 | sql_str.append(tr("`")); |
||
1349 | |||
1350 | q.prepare(sql_str); |
||
1351 | |||
1352 | ok = q.exec(); |
||
1353 | if (!ok) { |
||
1354 | QMessageBox::critical( // . |
||
1355 | this, // . |
||
1356 | QObject::tr("Database Error"), // . |
||
1357 | q.lastError().text()); // . |
||
1358 | return result_map; |
||
1359 | } |
||
1360 | |||
1361 | field_id = q.record().indexOf(tr("ID")); |
||
1362 | field_icon = q.record().indexOf(tr("Icon")); |
||
1363 | |||
1364 | while(q.next()){ |
||
1365 | QString objectID; |
||
1366 | QByteArray loadimage = q.value(field_icon).toByteArray(); |
||
1367 | objectID = q.value(field_id).toString(); |
||
1368 | if( !loadimage.isEmpty() ) |
||
1369 | { |
||
1370 | QPixmap pixmap; |
||
1371 | pixmap.loadFromData(loadimage); |
||
1372 | result_map.insert(objectID, pixmap); |
||
1373 | |||
1374 | } |
||
1375 | else continue; |
||
1376 | |||
1377 | |||
1378 | |||
1379 | } |
||
1380 | return result_map; |
||
1381 | } |
||
222 | pingvin | 1382 | |
1383 | |||
1384 | |||
1385 | |||
1386 | QString MainWindow::getFiltrString(QString model_id, QString class_id){ // - |
||
1387 | |||
1388 | QSqlQuery q; |
||
1389 | QString sql_str; |
||
1390 | QString result_str; |
||
1391 | sql_str = tr("select * from `Filters` where `Filters`.`Model_ID` = '"); |
||
1392 | sql_str.append(model_id); |
||
1393 | sql_str.append(tr("' and `Filters`.`Class_ID` = '")); |
||
1394 | sql_str.append(class_id); |
||
1395 | sql_str.append(tr("' order by `Filters`.`ID`")); |
||
1396 | bool ok; |
||
1397 | ok = q.prepare(sql_str); |
||
1398 | ok = q.exec(); |
||
1399 | |||
1400 | if (!ok) { |
||
1401 | QMessageBox::critical( // . |
||
1402 | this, // . |
||
1403 | QObject::tr("Database Error"), // . |
||
1404 | q.lastError().text()); // . |
||
1405 | return result_str; |
||
1406 | } |
||
1407 | result_str.clear(); |
||
1408 | while(q.next()){ |
||
1409 | QString Condition, FieldName, ConditionalSymbol, ValueForComparison, PostCondition; |
||
1410 | Condition = q.record().value(3).toString(); |
||
1411 | FieldName = q.record().value(4).toString(); |
||
1412 | ConditionalSymbol = q.record().value(5).toString(); |
||
1413 | ValueForComparison = q.record().value(6).toString(); |
||
1414 | PostCondition = q.record().value(7).toString(); |
||
1415 | |||
1416 | |||
1417 | result_str.append(Condition); |
||
1418 | result_str.append(tr(" ")); |
||
1419 | result_str.append(FieldName); |
||
1420 | result_str.append(tr(" ")); |
||
1421 | result_str.append(ConditionalSymbol); |
||
1422 | result_str.append(tr(" ")); |
||
1423 | result_str.append(ValueForComparison); |
||
1424 | result_str.append(tr(" ")); |
||
1425 | result_str.append(PostCondition); |
||
1426 | |||
1427 | |||
1428 | } |
||
1429 | |||
1430 | |||
1431 | return result_str; |
||
1432 | |||
1433 | } |
||
1434 | |||
1435 |