Rev 154 | Rev 156 | 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 | |||
4 | |||
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; |
||
114 | classID = model_item->text(1); |
||
115 | inctance = getClassInctance(classID); |
||
116 | |||
117 | sql_str = tr("select * " |
||
118 | " from " // - |
||
119 | ); |
||
120 | sql_str.append(inctance); |
||
121 | q.prepare(sql_str); |
||
122 | |||
123 | ok = q.exec(); |
||
124 | if (!ok) { |
||
125 | QMessageBox::critical( // . |
||
126 | this, // . |
||
127 | QObject::tr("Database Error"), // . |
||
128 | q.lastError().text()); // . |
||
129 | return; |
||
130 | } |
||
131 | |||
132 | field_ID = q.record().indexOf(tr("ID")); |
||
133 | |||
134 | |||
135 | while(q.next()){ |
||
136 | if (q.record().count() > 1) |
||
137 | { |
||
138 | QString value_tmp; |
||
139 | QString ID_tmp; |
||
140 | QTreeWidgetItem * itm; |
||
141 | ID_tmp = q.value(field_ID).toString(); // |
||
142 | value_tmp = q.value(1).toString(); // ( ) |
||
143 | itm = new QTreeWidgetItem(parent_item); // , |
||
144 | itm->setText(0, value_tmp); |
||
145 | for (int i; i < model_item->childCount(); i++) // , |
||
146 | { |
||
147 | QTreeWidgetItem * model_item_tmp; // |
||
148 | model_item_tmp = model_item->child(i); // |
||
149 | MainWindow::showObjectChildrens(ID_tmp, itm, model_item_tmp); |
||
150 | |||
151 | } |
||
152 | } |
||
153 | |||
154 | } |
||
155 | |||
156 | |||
157 | i++; |
||
158 | } |
||
159 | |||
160 | |||
161 | |||
162 | void MainWindow::showObjectChildrens(QString object_ID, QTreeWidgetItem * object_item, QTreeWidgetItem * model_item){ // |
||
163 | |||
164 | QString classID; // |
||
165 | |||
166 | QString inctance; // , |
||
167 | QSqlQuery q; |
||
168 | QString sql_str; |
||
169 | QString str_tmp; |
||
170 | bool ok; |
||
171 | classID = model_item->text(1); |
||
172 | inctance = getClassInctance(classID); |
||
173 | |||
174 | sql_str = tr("select * " |
||
175 | " from '" // - |
||
176 | ); |
||
177 | sql_str.append(inctance); |
||
178 | sql_str.append(tr("' where ")); |
||
179 | |||
180 | |||
181 | q.prepare(sql_str); |
||
182 | |||
183 | ok = q.exec(); |
||
184 | if (!ok) { |
||
185 | QMessageBox::critical( // . |
||
186 | this, // . |
||
187 | QObject::tr("Database Error"), // . |
||
188 | q.lastError().text()); // . |
||
189 | return; |
||
190 | } |
||
191 | } |
||
192 | |||
193 | |||
112 | pingvin | 194 | void MainWindow::showObjects(QTreeWidgetItem * parent_object_item, QTreeWidgetItem * model_item, QString filtr){ |
195 | QString classID; // |
||
126 | pingvin | 196 | QString parentClassID; // |
197 | QString pointerField; // - |
||
112 | pingvin | 198 | QString inctance; // , |
199 | QString className; // |
||
200 | int field_ID; |
||
201 | bool filtr_empty; |
||
202 | bool ok; |
||
203 | QSqlQuery q; |
||
204 | QString sql_str; |
||
205 | QString str_tmp; |
||
113 | pingvin | 206 | QTreeWidgetItem * title_item; |
207 | QFont font; |
||
114 | pingvin | 208 | // font.setWeight(40); |
209 | font.setBold(true); |
||
112 | pingvin | 210 | filtr_empty = filtr.isEmpty(); |
211 | classID = model_item->text(1); |
||
126 | pingvin | 212 | |
213 | parentClassID = model_item->parent()->text(1); |
||
214 | |||
215 | pointerField = getPointerFieldName(parentClassID, classID); |
||
216 | |||
112 | pingvin | 217 | className = model_item->text(0); |
218 | inctance = getClassInctance(classID); |
||
114 | pingvin | 219 | |
118 | pingvin | 220 | if (!model_item->checkState(0)) return; |
221 | |||
113 | pingvin | 222 | title_item = new QTreeWidgetItem(parent_object_item); |
223 | title_item->setFont(0, font); |
||
224 | title_item->setText(0, className); |
||
114 | pingvin | 225 | title_item->setText(1, tr("class")); |
226 | title_item->setText(2, classID); |
||
115 | pingvin | 227 | title_item->setText(3, inctance); |
126 | pingvin | 228 | title_item->setText(4, pointerField); |
114 | pingvin | 229 | title_item->setTextColor(0, Qt::darkBlue); |
230 | |||
126 | pingvin | 231 | |
112 | pingvin | 232 | sql_str = tr("select * " |
233 | " from " // - |
||
234 | ); |
||
235 | sql_str.append(inctance); |
||
236 | if (!filtr.isEmpty()) { // |
||
237 | sql_str.append(tr(" ")); |
||
238 | sql_str.append(filtr); // |
||
239 | } |
||
240 | |||
241 | q.prepare(sql_str); |
||
242 | |||
243 | ok = q.exec(); |
||
244 | if (!ok) { |
||
118 | pingvin | 245 | QString debug_str; |
246 | debug_str.append(tr(" showObjects(): Database Error ")); |
||
247 | debug_str.append(tr(" : ")); |
||
248 | debug_str.append(inctance); |
||
249 | debug_str.append(tr(" : ")); |
||
250 | debug_str.append(filtr); |
||
251 | debug_str.append(q.lastError().text()); |
||
112 | pingvin | 252 | QMessageBox::critical( // . |
253 | this, // . |
||
118 | pingvin | 254 | QObject::tr(" showObjects(): Database Error"), // . |
255 | debug_str |
||
256 | // q.lastError().text() |
||
257 | ); // . |
||
112 | pingvin | 258 | return; |
259 | } |
||
260 | |||
261 | field_ID = q.record().indexOf(tr("ID")); |
||
114 | pingvin | 262 | |
263 | /* |
||
113 | pingvin | 264 | if (q.size() <= 0) return; |
265 | title_item = new QTreeWidgetItem(parent_object_item); |
||
266 | title_item->setFont(0, font); |
||
267 | title_item->setText(0, className); |
||
114 | pingvin | 268 | */ |
112 | pingvin | 269 | |
270 | while(q.next()){ |
||
271 | if (q.record().count() > 1) |
||
272 | { |
||
273 | QString value_tmp; |
||
274 | QString ID_tmp; |
||
275 | QTreeWidgetItem * itm; |
||
276 | ID_tmp = q.value(field_ID).toString(); // |
||
277 | value_tmp = q.value(1).toString(); // ( ) |
||
113 | pingvin | 278 | // itm = new QTreeWidgetItem(parent_object_item); // , |
279 | itm = new QTreeWidgetItem(title_item); // , |
||
112 | pingvin | 280 | itm->setText(0, value_tmp); |
114 | pingvin | 281 | itm->setText(1, tr("object")); |
282 | itm->setText(2, ID_tmp); |
||
112 | pingvin | 283 | for (int i=0; i < model_item->childCount(); i++) // , |
284 | { |
||
285 | QTreeWidgetItem * model_item_tmp; // |
||
286 | QString pointer_name; |
||
287 | QString filtr_tmp; |
||
288 | bool pointer_isEmpty; |
||
289 | model_item_tmp = model_item->child(i); // |
||
290 | pointer_name = getPointerFieldName(classID, model_item->child(i)->text(1)); |
||
115 | pingvin | 291 | itm->setText(4, pointer_name); |
126 | pingvin | 292 | |
293 | // title_item->setText(4, pointer_name); |
||
294 | |||
295 | |||
112 | pingvin | 296 | pointer_isEmpty = pointer_name.isEmpty(); |
297 | filtr_tmp = tr("where "); |
||
298 | filtr_tmp.append(tr("`")); |
||
299 | filtr_tmp.append(pointer_name); |
||
300 | filtr_tmp.append(tr("` = '")); |
||
301 | filtr_tmp.append(ID_tmp); |
||
302 | filtr_tmp.append(tr("'")); |
||
303 | showObjects(itm, model_item_tmp, filtr_tmp); |
||
304 | //MainWindow::showObjectChildrens(ID_tmp, itm, model_item_tmp); |
||
305 | |||
306 | } |
||
307 | |||
308 | |||
309 | } |
||
310 | |||
311 | } |
||
312 | |||
313 | |||
314 | |||
315 | |||
316 | for (int i; i < model_item->childCount(); i++) // , |
||
317 | { |
||
318 | |||
319 | |||
320 | } |
||
321 | |||
111 | pingvin | 322 | } |
323 | |||
115 | pingvin | 324 | |
112 | pingvin | 325 | QString MainWindow::getPointerFieldName(QString parent_class_id, QString chield_class_id){ |
326 | |||
327 | QSqlQuery q; |
||
328 | QString sql_str; |
||
329 | QString str_tmp; |
||
330 | QString field; |
||
331 | QString result; |
||
332 | int field_name; |
||
333 | bool ok; |
||
334 | sql_str = tr("select * " |
||
335 | " from `DescriptionOfClasses` where `DescriptionOfClasses`.`FieldType` = 'pointer' and `DescriptionOfClasses`.`DefaultValue` = " // - |
||
336 | ); |
||
337 | |||
338 | sql_str.append(tr("'")); |
||
339 | sql_str.append(parent_class_id); |
||
340 | sql_str.append(tr("' ")); |
||
341 | sql_str.append(tr(" and `DescriptionOfClasses`.`ClassIdentifer` = '")); |
||
342 | sql_str.append(chield_class_id); |
||
343 | sql_str.append(tr("'")); |
||
344 | q.prepare(sql_str); |
||
345 | |||
346 | ok = q.exec(); |
||
347 | if (!ok) { |
||
348 | QMessageBox::critical( // . |
||
349 | this, // . |
||
350 | QObject::tr("Database Error"), // . |
||
351 | q.lastError().text()); // . |
||
352 | return result; |
||
353 | } |
||
354 | field_name = q.record().indexOf(tr("FieldName")); |
||
355 | while(q.next()){ |
||
356 | result = q.value(field_name).toString(); |
||
357 | } |
||
358 | return result; |
||
359 | } |
||
360 | |||
115 | pingvin | 361 | |
362 | |||
363 | void MainWindow::on_treeWidget_2_itemClicked ( QTreeWidgetItem * item, int column ){ |
||
364 | QString item_type; // ( ) |
||
365 | QString parent_object_id; |
||
366 | int i; |
||
367 | QTreeWidgetItem * parent_item; |
||
368 | item_type = item->text(1); |
||
369 | parent_item = item->parent(); |
||
370 | if (item_type == tr("object")) |
||
371 | { |
||
372 | QString class_id; |
||
116 | pingvin | 373 | QString ID; |
374 | QString inctance; |
||
375 | QString filtr_tmp; |
||
119 | pingvin | 376 | |
377 | disconnect(sql_mogel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_sql_mogel_dataChanged(QModelIndex,QModelIndex))); |
||
378 | |||
379 | ui->pushButton->setEnabled(false); |
||
380 | ui->pushButton_2->setEnabled(false); |
||
381 | |||
115 | pingvin | 382 | class_id = parent_item->text(2); |
116 | pingvin | 383 | ID = item->text(2); |
384 | inctance = parent_item->text(3); |
||
385 | delete sql_mogel; |
||
127 | pingvin | 386 | |
387 | ///////sql_mogel = new QSqlTableModel(); |
||
388 | sql_mogel = new MyModel(); |
||
389 | |||
390 | // sql_mogel = new QSqlTableModel(this); |
||
116 | pingvin | 391 | sql_mogel->setTable(inctance); |
119 | pingvin | 392 | // sql_mogel->setEditStrategy(QSqlTableModel::OnFieldChange); |
393 | sql_mogel->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
116 | pingvin | 394 | |
395 | filtr_tmp.append(tr("`")); |
||
396 | filtr_tmp.append(tr("ID")); |
||
397 | filtr_tmp.append(tr("`")); |
||
398 | filtr_tmp.append(tr(" = '")); |
||
399 | filtr_tmp.append(ID); |
||
400 | filtr_tmp.append(tr("'")); |
||
401 | sql_mogel->setFilter(filtr_tmp); |
||
402 | sql_mogel->select(); |
||
128 | pingvin | 403 | |
404 | |||
116 | pingvin | 405 | ui->tableView->setModel(sql_mogel); |
118 | pingvin | 406 | ui->tableView->resizeColumnsToContents(); |
154 | pingvin | 407 | ui->tableView->hideColumn(0); |
116 | pingvin | 408 | |
119 | pingvin | 409 | connect(sql_mogel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_sql_mogel_dataChanged(QModelIndex,QModelIndex))); |
410 | |||
116 | pingvin | 411 | //sql_mogel->clear(); |
412 | //sql_mogel->select(); |
||
413 | // ui->tableView->setVisible(false); |
||
414 | // i++; |
||
115 | pingvin | 415 | } |
416 | if (item_type == tr("class")) |
||
417 | { |
||
418 | QString parent_object_id; // |
||
125 | pingvin | 419 | |
115 | pingvin | 420 | QString class_id; // |
421 | QString inctance; |
||
126 | pingvin | 422 | QString parent_class_inctance; |
115 | pingvin | 423 | QString pointer_name; |
424 | QString filtr_tmp; |
||
138 | pingvin | 425 | |
426 | |||
427 | |||
116 | pingvin | 428 | // sql_mogel->clear(); |
429 | |||
119 | pingvin | 430 | ui->pushButton->setEnabled(true); |
431 | ui->pushButton_2->setEnabled(true); |
||
432 | |||
433 | disconnect(sql_mogel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_sql_mogel_dataChanged(QModelIndex,QModelIndex))); |
||
434 | |||
115 | pingvin | 435 | parent_object_id = parent_item->text(2); |
118 | pingvin | 436 | |
437 | parentObject_id = parent_item->text(2); |
||
438 | |||
115 | pingvin | 439 | class_id = item->text(2); |
440 | inctance = item->text(3); |
||
441 | |||
126 | pingvin | 442 | // parent_class_inctance = parent_item->parent()->text(3); // |
443 | |||
444 | // pointer_name = parent_item->text(4); |
||
445 | pointer_name = item->text(4); |
||
116 | pingvin | 446 | delete sql_mogel; |
127 | pingvin | 447 | |
448 | |||
449 | ////// sql_mogel = new QSqlTableModel(); |
||
450 | |||
451 | sql_mogel = new MyModel(); |
||
452 | |||
453 | // sql_mogel = new QSqlTableModel(this); |
||
115 | pingvin | 454 | sql_mogel->setTable(inctance); |
119 | pingvin | 455 | // sql_mogel->setEditStrategy(QSqlTableModel::OnFieldChange); |
456 | sql_mogel->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
116 | pingvin | 457 | |
458 | if (!parent_object_id.isEmpty()) |
||
459 | { |
||
460 | filtr_tmp.append(tr("`")); |
||
461 | filtr_tmp.append(pointer_name); |
||
462 | filtr_tmp.append(tr("`")); |
||
463 | filtr_tmp.append(tr(" = '")); |
||
464 | filtr_tmp.append(parent_object_id); |
||
465 | filtr_tmp.append(tr("'")); |
||
466 | sql_mogel->setFilter(filtr_tmp); |
||
467 | } |
||
126 | pingvin | 468 | |
469 | /**************************************** |
||
470 | spinDelegate.setInctance(parent_class_inctance); |
||
471 | spinDelegate.getItems(); |
||
472 | ui->tableView->setItemDelegateForColumn(2, &spinDelegate); |
||
473 | ***************************************/ |
||
474 | |||
475 | |||
115 | pingvin | 476 | sql_mogel->select(); |
116 | pingvin | 477 | |
129 | pingvin | 478 | QMap <QString, QString> pointersList = getPointersList(class_id); // - |
155 | pingvin | 479 | QStringList dateFieldList = getDataFieldList(class_id); // c "DATE" |
480 | |||
128 | pingvin | 481 | QMap <int, QString> pointersToModel; |
126 | pingvin | 482 | |
155 | pingvin | 483 | //QStringList pointersNames; |
130 | pingvin | 484 | static QList<int> colomns_indexes; // |
155 | pingvin | 485 | static QList<int> date_colomns_indexes; // "DATE" |
153 | pingvin | 486 | static QList<SpinBoxDelegate *> spin_delegate_list;// |
487 | SpinBoxDelegate * spin_delegate_tmp; |
||
155 | pingvin | 488 | |
489 | |||
130 | pingvin | 490 | // "" |
491 | for (i=0; i < colomns_indexes.size(); i++){ // -: |
||
155 | pingvin | 492 | ui->tableView->setItemDelegateForColumn(colomns_indexes.at(i), &standart_delegate ); // |
493 | // ui->tableView->setItemDelegateForColumn(colomns_indexes.at(i), &picture_delegate); |
||
130 | pingvin | 494 | |
155 | pingvin | 495 | } |
496 | colomns_indexes.clear(); // |
||
130 | pingvin | 497 | |
155 | pingvin | 498 | // "" "DATE" |
499 | for (i=0; i < date_colomns_indexes.size(); i++){ // -: |
||
500 | ui->tableView->setItemDelegateForColumn(date_colomns_indexes.at(i), &standart_delegate ); // |
||
138 | pingvin | 501 | // ui->tableView->setItemDelegateForColumn(colomns_indexes.at(i), &picture_delegate); |
130 | pingvin | 502 | |
503 | } |
||
155 | pingvin | 504 | date_colomns_indexes.clear(); // "DATE" |
130 | pingvin | 505 | |
153 | pingvin | 506 | |
130 | pingvin | 507 | |
155 | pingvin | 508 | |
509 | |||
153 | pingvin | 510 | for (int i=0; i < spin_delegate_list.count(); i++){ // |
511 | delete spin_delegate_list.at(i); |
||
512 | } |
||
130 | pingvin | 513 | |
153 | pingvin | 514 | spin_delegate_list.clear(); // |
515 | |||
155 | pingvin | 516 | QStringList pointersNames; |
130 | pingvin | 517 | pointersNames = pointersList.keys(); // - |
518 | |||
519 | |||
520 | |||
521 | |||
522 | |||
140 | pingvin | 523 | // ui->tableView->setItemDelegateForColumn(2, picture_delegate); |
138 | pingvin | 524 | |
139 | pingvin | 525 | // ui->tableView->setRowHeight(1, 100); |
138 | pingvin | 526 | |
527 | |||
528 | |||
529 | |||
530 | |||
129 | pingvin | 531 | QStringList parentInctancesList = pointersList.values(); // |
126 | pingvin | 532 | |
130 | pingvin | 533 | for (i=0; i < pointersNames.size(); i++){ // -: |
128 | pingvin | 534 | QString pointerName; |
535 | |||
536 | int pointerIndex; |
||
130 | pingvin | 537 | pointerName = pointersNames.at(i); // - |
538 | pointerIndex = sql_mogel->record().indexOf(pointerName); // |
||
539 | colomns_indexes.append(pointerIndex); // |
||
153 | pingvin | 540 | spin_delegate_tmp = new SpinBoxDelegate(); |
145 | pingvin | 541 | |
153 | pingvin | 542 | // // spinDelegate.setInctance(parentInctancesList.at(i)); // |
543 | // // spinDelegate.getItems(); // |
||
129 | pingvin | 544 | |
153 | pingvin | 545 | spin_delegate_tmp->setInctance(parentInctancesList.at(i)); |
546 | spin_delegate_tmp->getItems(); |
||
129 | pingvin | 547 | |
153 | pingvin | 548 | spin_delegate_list.append(spin_delegate_tmp); |
549 | |||
550 | // // ui->tableView->setItemDelegateForColumn(pointerIndex, &spinDelegate); // |
||
551 | |||
552 | ui->tableView->setItemDelegateForColumn(pointerIndex, spin_delegate_tmp); |
||
553 | |||
130 | pingvin | 554 | pointersToModel.insert(pointerIndex, parentInctancesList.at(i)); // |
128 | pingvin | 555 | } |
556 | |||
130 | pingvin | 557 | sql_mogel->setPointers(pointersToModel); // |
128 | pingvin | 558 | |
130 | pingvin | 559 | pointer_index = sql_mogel->record().indexOf(pointer_name); // , , ! :-) |
118 | pingvin | 560 | |
115 | pingvin | 561 | ui->tableView->setModel(sql_mogel); |
562 | |||
154 | pingvin | 563 | ui->tableView->resizeColumnsToContents(); |
564 | ui->tableView->hideColumn(0); |
||
140 | pingvin | 565 | |
566 | |||
567 | |||
568 | |||
569 | |||
570 | |||
154 | pingvin | 571 | |
140 | pingvin | 572 | /**********************************************************/ |
573 | |||
574 | // for (int i; i < sql_mogel->rowCount(); i++ ) { |
||
575 | // ui->tableView->setRowHeight(i, 100); |
||
576 | // } |
||
577 | |||
578 | /**********************************************************/ |
||
579 | |||
580 | |||
581 | |||
582 | |||
583 | |||
584 | |||
119 | pingvin | 585 | connect(sql_mogel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_sql_mogel_dataChanged(QModelIndex,QModelIndex))); |
586 | |||
587 | |||
588 | // ui->tableView->setVisible(true);; |
||
115 | pingvin | 589 | i++; |
590 | } |
||
591 | |||
592 | //parent_object_id = parent_object_item->text(1); |
||
593 | |||
594 | |||
595 | |||
596 | |||
597 | |||
598 | i++; |
||
599 | |||
600 | } |
||
601 | |||
602 | |||
118 | pingvin | 603 | void MainWindow::on_pushButton_clicked(){ // " " |
604 | int row = sql_mogel->rowCount(); |
||
605 | sql_mogel->insertRows(row, 1); |
||
606 | sql_mogel->setData(sql_mogel->index(row, 1), QVariant(tr(" ")), Qt::EditRole); // " " |
||
607 | if (pointer_index > 0) { |
||
608 | sql_mogel->setData(sql_mogel->index(row, pointer_index), QVariant(parentObject_id), Qt::EditRole); // " " |
||
609 | } |
||
119 | pingvin | 610 | // sql_mogel->submitAll(); |
118 | pingvin | 611 | |
612 | } |
||
119 | pingvin | 613 | |
614 | void MainWindow::on_pushButton_2_clicked(){ // " " |
||
615 | int i; |
||
616 | i++; |
||
120 | pingvin | 617 | QModelIndex model_index; |
618 | QItemSelectionModel *selectionModel = ui->tableView->selectionModel(); |
||
619 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
||
620 | QList<int> selectedRows; |
||
621 | selectedRows.clear(); |
||
622 | foreach (model_index, indexes){ // |
||
623 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) selectedRows.append(model_index.row()); // |
||
119 | pingvin | 624 | |
625 | } |
||
120 | pingvin | 626 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // |
119 | pingvin | 627 | |
628 | |||
120 | pingvin | 629 | for (int m =0; m < selectedRows.size(); ++m){ |
630 | |||
631 | // ClassEditor::removeClass(selectedRows.at(m)); |
||
632 | |||
633 | sql_mogel->removeRow(selectedRows.at(m)); |
||
634 | |||
635 | } |
||
636 | sql_mogel->submitAll(); |
||
637 | getDatabaseData(); |
||
638 | |||
639 | } |
||
640 | |||
641 | |||
119 | pingvin | 642 | void MainWindow::on_pushButton_3_clicked(){ // "" |
643 | int i; |
||
644 | i++; |
||
645 | sql_mogel->submitAll(); |
||
646 | getDatabaseData(); |
||
647 | ui->pushButton_3->setEnabled(false); |
||
648 | ui->pushButton_4->setEnabled(false); |
||
649 | sql_mogel->select(); |
||
650 | |||
651 | } |
||
652 | |||
653 | |||
654 | void MainWindow::on_pushButton_4_clicked(){ // " " |
||
655 | int i; |
||
656 | i++; |
||
657 | sql_mogel->select(); |
||
658 | ui->pushButton_3->setEnabled(false); |
||
659 | ui->pushButton_4->setEnabled(false); |
||
660 | } |
||
661 | |||
662 | |||
144 | pingvin | 663 | void MainWindow::on_pushButton_5_clicked(){// " " |
664 | |||
665 | int i; |
||
666 | i++; |
||
667 | int row = model_for_ListModelsTable->rowCount(); |
||
668 | model_for_ListModelsTable->insertRows(row, 1); |
||
669 | model_for_ListModelsTable->setData(model_for_ListModelsTable->index(row, 1), QVariant(tr(" ")), Qt::EditRole); // " " |
||
670 | // model_for_ListModelsTable->setData(sql_mogel->index(row, pointer_index), QVariant(parentObject_id), Qt::EditRole); // " " |
||
671 | |||
672 | // sql_mogel->submitAll(); |
||
673 | |||
674 | |||
675 | } |
||
676 | |||
677 | void MainWindow::on_pushButton_6_clicked(){// " " |
||
678 | |||
679 | QModelIndex model_index; |
||
680 | QItemSelectionModel *selectionModel = ui->tableView_2->selectionModel(); |
||
681 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
||
682 | QList<int> selectedRows; |
||
683 | selectedRows.clear(); |
||
684 | foreach (model_index, indexes){ // |
||
685 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) selectedRows.append(model_index.row()); // |
||
686 | |||
687 | } |
||
688 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // |
||
689 | |||
690 | |||
691 | for (int m =0; m < selectedRows.size(); ++m){ |
||
692 | |||
693 | // ClassEditor::removeClass(selectedRows.at(m)); |
||
694 | |||
695 | model_for_ListModelsTable->removeRow(selectedRows.at(m)); |
||
696 | |||
697 | } |
||
698 | model_for_ListModelsTable->submitAll(); |
||
699 | // getDatabaseData(); |
||
700 | |||
701 | } |
||
702 | |||
703 | |||
146 | pingvin | 704 | void MainWindow::on_pushButton_7_clicked(){// "" |
705 | model_for_ListModelsTable->submitAll(); |
||
706 | ui->pushButton_7->setEnabled(false); |
||
707 | ui->pushButton_8->setEnabled(false); |
||
708 | model_is_build = false; |
||
709 | MainWindow::readModels(); |
||
710 | model_is_build = true; |
||
711 | MainWindow::getDatabaseData(); |
||
712 | } |
||
144 | pingvin | 713 | |
146 | pingvin | 714 | void MainWindow::on_pushButton_8_clicked(){// "" ( ) |
715 | model_for_ListModelsTable->select(); |
||
716 | ui->pushButton_7->setEnabled(false); |
||
717 | ui->pushButton_8->setEnabled(false); |
||
718 | } |
||
719 | |||
119 | pingvin | 720 | void MainWindow::on_sql_mogel_dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ // |
721 | int i; |
||
722 | i++; |
||
723 | ui->pushButton_3->setEnabled(true); |
||
724 | ui->pushButton_4->setEnabled(true); |
||
725 | |||
726 | |||
727 | } |
||
128 | pingvin | 728 | |
146 | pingvin | 729 | void MainWindow::on_model_for_ListModelsTable_dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ // |
128 | pingvin | 730 | |
146 | pingvin | 731 | ui->pushButton_7->setEnabled(true); |
732 | ui->pushButton_8->setEnabled(true); |
||
733 | } |
||
734 | |||
735 | |||
128 | pingvin | 736 | // -, - |
737 | // - |
||
738 | |||
739 | QMap <QString, QString> MainWindow::getPointersList(QString class_id){ |
||
740 | QMap <QString, QString> result_map; |
||
741 | QSqlQuery q; |
||
742 | QString sql_str; |
||
743 | QString str_tmp; |
||
744 | QString field; |
||
745 | QString result; |
||
746 | int field_name, field_default_value; |
||
747 | bool ok; |
||
748 | sql_str = tr("select * " |
||
749 | " from `DescriptionOfClasses` where `DescriptionOfClasses`.`FieldType` = 'pointer' and `DescriptionOfClasses`.`ClassIdentifer` = " // - |
||
750 | ); |
||
751 | |||
752 | sql_str.append(tr("'")); |
||
753 | sql_str.append(class_id); |
||
754 | sql_str.append(tr("' ")); |
||
755 | // sql_str.append(tr(" and `DescriptionOfClasses`.`ClassIdentifer` = '")); |
||
756 | // sql_str.append(chield_class_id); |
||
757 | // sql_str.append(tr("'")); |
||
758 | q.prepare(sql_str); |
||
759 | |||
760 | ok = q.exec(); |
||
761 | if (!ok) { |
||
762 | QMessageBox::critical( // . |
||
763 | this, // . |
||
764 | QObject::tr("Database Error"), // . |
||
765 | q.lastError().text()); // . |
||
766 | return result_map; |
||
767 | } |
||
768 | field_name = q.record().indexOf(tr("FieldName")); |
||
769 | field_default_value = q.record().indexOf(tr("DefaultValue")); |
||
770 | while(q.next()){ |
||
771 | QString pointerFieldName; |
||
772 | QString parentClassID; |
||
773 | QString parentClassInctance; |
||
774 | |||
775 | pointerFieldName = q.value(field_name).toString(); |
||
776 | parentClassID = q.value(field_default_value).toString(); |
||
777 | parentClassInctance = getClassInctance(parentClassID); |
||
778 | result_map.insert(pointerFieldName, parentClassInctance); |
||
779 | |||
780 | |||
781 | } |
||
782 | |||
783 | return result_map; |
||
784 | } |
||
785 | |||
132 | pingvin | 786 | |
787 | |||
788 | |||
789 | |||
155 | pingvin | 790 | QStringList MainWindow::getDataFieldList(QString class_id){ // c "", |
791 | // - |
||
132 | pingvin | 792 | |
155 | pingvin | 793 | QStringList result_str; |
794 | QSqlQuery q; |
||
795 | QString sql_str; |
||
796 | QString str_tmp; |
||
797 | QString field; |
||
798 | QString result; |
||
799 | int field_name, field_default_value; |
||
800 | bool ok; |
||
801 | sql_str = tr("select * " |
||
802 | " from `DescriptionOfClasses` where `DescriptionOfClasses`.`FieldType` = 'DATE' and `DescriptionOfClasses`.`ClassIdentifer` = " // - |
||
803 | ); |
||
804 | |||
805 | sql_str.append(tr("'")); |
||
806 | sql_str.append(class_id); |
||
807 | sql_str.append(tr("' ")); |
||
808 | // sql_str.append(tr(" and `DescriptionOfClasses`.`ClassIdentifer` = '")); |
||
809 | // sql_str.append(chield_class_id); |
||
810 | // sql_str.append(tr("'")); |
||
811 | q.prepare(sql_str); |
||
812 | |||
813 | ok = q.exec(); |
||
814 | if (!ok) { |
||
815 | QMessageBox::critical( // . |
||
816 | this, // . |
||
817 | QObject::tr("Database Error"), // . |
||
818 | q.lastError().text()); // . |
||
819 | return result_str; |
||
820 | } |
||
821 | field_name = q.record().indexOf(tr("FieldName")); |
||
822 | // field_default_value = q.record().indexOf(tr("DefaultValue")); |
||
823 | while(q.next()){ |
||
824 | QString DataFieldName; |
||
825 | |||
826 | DataFieldName = q.value(field_name).toString(); |
||
827 | result_str.append(DataFieldName); |
||
828 | |||
829 | |||
830 | } |
||
831 | |||
832 | return result_str; |
||
833 | } |
||
834 | |||
835 | |||
836 | |||
837 | |||
132 | pingvin | 838 | // |
839 | |||
840 | void MainWindow::readSettings() |
||
841 | { |
||
842 | QSettings settings("Trolltech", "Application Example"); |
||
843 | baseName = settings.value("baseName", "an_db").toString(); |
||
844 | userName = settings.value("userName", "an").toString(); |
||
845 | password = settings.value("password", "393939").toString(); |
||
846 | tableName = settings.value("tableName", "inventar").toString(); |
||
847 | hostName = settings.value("hostName", "server").toString(); |
||
848 | // resize(size); |
||
849 | // move(pos);tableName |
||
850 | } |
||
851 | |||
852 | |||
853 | void MainWindow::writeSettings() |
||
854 | { |
||
855 | QSettings settings("Trolltech", "Application Example"); |
||
856 | settings.setValue("baseName", baseName); |
||
857 | settings.setValue("userName", userName); |
||
858 | settings.setValue("password", password); |
||
859 | settings.setValue("tableName", tableName); |
||
860 | settings.setValue("hostName", hostName); |
||
861 | } |
||
862 | |||
863 | |||
864 | |||
865 | void MainWindow::applySetting() |
||
866 | { |
||
867 | bool ok; |
||
868 | baseName = setFrm.lineEdit->text(); |
||
869 | userName = setFrm.lineEdit_2->text(); |
||
870 | password = setFrm.lineEdit_3->text(); |
||
871 | // tableName = setFrm->lineEdit_4->text(); |
||
872 | hostName = setFrm.lineEdit_5->text(); |
||
873 | writeSettings(); |
||
874 | |||
875 | |||
876 | ok=openDataBase(); |
||
877 | if (!ok) return; |
||
878 | // // // ui->treeWidget->clear(); // |
||
879 | |||
880 | // // // buildPreviewModel(tr(" "), tr("1")); |
||
149 | pingvin | 881 | |
882 | model_is_build = false; |
||
883 | |||
132 | pingvin | 884 | class_list_map.clear(); // |
149 | pingvin | 885 | rootItems.clear(); |
886 | models_items.clear(); |
||
151 | pingvin | 887 | |
888 | disconnect(model_for_ListModelsTable, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_model_for_ListModelsTable_dataChanged(QModelIndex,QModelIndex))); |
||
149 | pingvin | 889 | delete model_for_ListModelsTable; |
151 | pingvin | 890 | |
149 | pingvin | 891 | initListModelsTablle(); |
892 | |||
151 | pingvin | 893 | connect(model_for_ListModelsTable, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_model_for_ListModelsTable_dataChanged(QModelIndex,QModelIndex))); |
894 | |||
149 | pingvin | 895 | ui->treeWidget->clear(); |
132 | pingvin | 896 | initComboBox(); |
149 | pingvin | 897 | // model_for_ListModelsTable->select(); |
898 | MainWindow::readModels(); |
||
899 | |||
900 | |||
901 | |||
132 | pingvin | 902 | // // // getDatabaseData(); |
903 | // delete setFrm; |
||
149 | pingvin | 904 | |
905 | |||
906 | model_is_build = true; |
||
150 | pingvin | 907 | getDatabaseData(); |
132 | pingvin | 908 | setFrm.close(); |
909 | } |
||
910 | |||
911 | |||
912 | void MainWindow::getSetting() |
||
913 | { |
||
914 | // setFrm = new settingForm; |
||
915 | // // // connect(setFrm.pushButton, SIGNAL(clicked()), this, SLOT(applySetting())); |
||
916 | setFrm.lineEdit->setText(baseName); |
||
917 | setFrm.lineEdit_2->setText(userName); |
||
918 | setFrm.lineEdit_3->setText(password); |
||
919 | // setFrm->lineEdit_4->setText(tableName); |
||
920 | setFrm.lineEdit_5->setText(hostName); |
||
921 | setFrm.show(); |
||
922 | |||
923 | |||
924 | |||
925 | } |
||
144 | pingvin | 926 | |
927 | |||
928 | |||
929 | |||
930 | void MainWindow::readModels(){ |
||
931 | |||
145 | pingvin | 932 | int row = model_for_ListModelsTable->rowCount(); |
147 | pingvin | 933 | QList <QTreeWidgetItem*> modelsItemsList; |
934 | QList <int> row_list; |
||
935 | modelsItemsList = models_items.values(); |
||
936 | |||
937 | row_list = models_items.keys(); |
||
938 | |||
939 | |||
940 | |||
145 | pingvin | 941 | rootItems.clear(); |
942 | ui->treeWidget->clear(); |
||
144 | pingvin | 943 | for (int i=0; i < row; i++){ |
944 | QTreeWidgetItem * item_tmp; |
||
945 | QString modelName; |
||
147 | pingvin | 946 | |
144 | pingvin | 947 | bool enabled; |
147 | pingvin | 948 | |
949 | |||
950 | |||
951 | //models_items.values(); |
||
952 | // modelString = |
||
953 | |||
144 | pingvin | 954 | modelName = model_for_ListModelsTable->data(model_for_ListModelsTable->index(i, 1)).toString(); |
955 | enabled = model_for_ListModelsTable->data(model_for_ListModelsTable->index(i, 3)).toBool(); |
||
956 | item_tmp = new QTreeWidgetItem(ui->treeWidget); |
||
957 | item_tmp->setText(0, modelName); |
||
147 | pingvin | 958 | item_tmp->setText(4, QVariant(i).toString()); // 4 |
144 | pingvin | 959 | if (enabled) item_tmp->setCheckState(0,Qt::Checked); |
960 | else item_tmp->setCheckState(0,Qt::Unchecked); |
||
145 | pingvin | 961 | |
962 | root_items_list << item_tmp; |
||
963 | |||
144 | pingvin | 964 | rootItems.append(item_tmp); |
147 | pingvin | 965 | |
966 | models_items[i] =item_tmp ; |
||
967 | |||
968 | |||
145 | pingvin | 969 | modelString = model_for_ListModelsTable->data(model_for_ListModelsTable->index(i, 2)).toString(); |
970 | if (modelString.isEmpty()) continue; |
||
147 | pingvin | 971 | else setupModelData(modelString.split(QString("\n")), item_tmp, i); // |
144 | pingvin | 972 | |
973 | } |
||
149 | pingvin | 974 | |
144 | pingvin | 975 | } |