Rev 157 | Rev 159 | 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(); |
||
157 | pingvin | 370 | |
371 | QString class_id; // |
||
372 | QString inctance; |
||
373 | QString filtr_tmp; |
||
374 | QMap <QString, QString> pointersList; |
||
158 | pingvin | 375 | QStringList dateFieldList; // "DATE" |
376 | QStringList boolFieldList; // "BOOL" |
||
377 | QString pointer_name; // |
||
157 | pingvin | 378 | |
379 | if (item_type == tr("object") || item_type == tr("class")){ |
||
380 | |||
381 | disconnect(sql_mogel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_sql_mogel_dataChanged(QModelIndex,QModelIndex))); |
||
382 | |||
383 | static QList<int> colomns_indexes; // |
||
384 | static QList<int> date_colomns_indexes; // "DATE" |
||
158 | pingvin | 385 | static QList <int> bool_colomns_indexes; // "BOOL" |
157 | pingvin | 386 | static QList<SpinBoxDelegate *> spin_delegate_list;// |
387 | SpinBoxDelegate * spin_delegate_tmp; |
||
388 | |||
389 | // "" |
||
390 | for (i=0; i < colomns_indexes.size(); i++){ // -: |
||
391 | ui->tableView->setItemDelegateForColumn(colomns_indexes.at(i), &standart_delegate ); // |
||
392 | // ui->tableView->setItemDelegateForColumn(colomns_indexes.at(i), &picture_delegate); |
||
393 | |||
394 | } |
||
395 | colomns_indexes.clear(); // |
||
396 | |||
397 | // "" "DATE" |
||
398 | for (i=0; i < date_colomns_indexes.size(); i++){ // -: |
||
399 | ui->tableView->setItemDelegateForColumn(date_colomns_indexes.at(i), &standart_delegate ); // |
||
400 | // ui->tableView->setItemDelegateForColumn(colomns_indexes.at(i), &picture_delegate); |
||
401 | |||
402 | } |
||
403 | |||
158 | pingvin | 404 | date_colomns_indexes.clear(); |
157 | pingvin | 405 | |
158 | pingvin | 406 | // "" "BOOL" |
407 | for (i=0; i < bool_colomns_indexes.size(); i++){ // -: |
||
408 | ui->tableView->setItemDelegateForColumn(bool_colomns_indexes.at(i), &standart_delegate ); // |
||
409 | // ui->tableView->setItemDelegateForColumn(colomns_indexes.at(i), &picture_delegate); |
||
157 | pingvin | 410 | |
158 | pingvin | 411 | } |
412 | |||
413 | bool_colomns_indexes.clear(); |
||
414 | |||
415 | |||
115 | pingvin | 416 | if (item_type == tr("object")) |
417 | { |
||
157 | pingvin | 418 | QString ID; |
119 | pingvin | 419 | ui->pushButton->setEnabled(false); |
420 | ui->pushButton_2->setEnabled(false); |
||
421 | |||
115 | pingvin | 422 | class_id = parent_item->text(2); |
116 | pingvin | 423 | ID = item->text(2); |
424 | inctance = parent_item->text(3); |
||
425 | delete sql_mogel; |
||
127 | pingvin | 426 | |
427 | sql_mogel = new MyModel(); |
||
428 | |||
116 | pingvin | 429 | sql_mogel->setTable(inctance); |
119 | pingvin | 430 | // sql_mogel->setEditStrategy(QSqlTableModel::OnFieldChange); |
431 | sql_mogel->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
116 | pingvin | 432 | |
433 | filtr_tmp.append(tr("`")); |
||
434 | filtr_tmp.append(tr("ID")); |
||
435 | filtr_tmp.append(tr("`")); |
||
436 | filtr_tmp.append(tr(" = '")); |
||
437 | filtr_tmp.append(ID); |
||
438 | filtr_tmp.append(tr("'")); |
||
128 | pingvin | 439 | |
115 | pingvin | 440 | } |
441 | if (item_type == tr("class")) |
||
442 | { |
||
443 | QString parent_object_id; // |
||
125 | pingvin | 444 | |
126 | pingvin | 445 | QString parent_class_inctance; |
138 | pingvin | 446 | |
447 | |||
119 | pingvin | 448 | ui->pushButton->setEnabled(true); |
449 | ui->pushButton_2->setEnabled(true); |
||
450 | |||
115 | pingvin | 451 | parent_object_id = parent_item->text(2); |
118 | pingvin | 452 | |
453 | parentObject_id = parent_item->text(2); |
||
454 | |||
115 | pingvin | 455 | class_id = item->text(2); |
456 | inctance = item->text(3); |
||
457 | |||
126 | pingvin | 458 | pointer_name = item->text(4); |
116 | pingvin | 459 | delete sql_mogel; |
127 | pingvin | 460 | |
461 | sql_mogel = new MyModel(); |
||
462 | |||
463 | // sql_mogel = new QSqlTableModel(this); |
||
115 | pingvin | 464 | sql_mogel->setTable(inctance); |
119 | pingvin | 465 | // sql_mogel->setEditStrategy(QSqlTableModel::OnFieldChange); |
466 | sql_mogel->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
116 | pingvin | 467 | |
468 | if (!parent_object_id.isEmpty()) |
||
469 | { |
||
470 | filtr_tmp.append(tr("`")); |
||
471 | filtr_tmp.append(pointer_name); |
||
472 | filtr_tmp.append(tr("`")); |
||
473 | filtr_tmp.append(tr(" = '")); |
||
474 | filtr_tmp.append(parent_object_id); |
||
475 | filtr_tmp.append(tr("'")); |
||
126 | pingvin | 476 | |
155 | pingvin | 477 | } |
130 | pingvin | 478 | |
479 | |||
157 | pingvin | 480 | } |
130 | pingvin | 481 | |
153 | pingvin | 482 | |
130 | pingvin | 483 | |
157 | pingvin | 484 | pointersList = getPointersList(class_id); // - |
485 | dateFieldList = getDataFieldList(class_id); // c "DATE" |
||
158 | pingvin | 486 | boolFieldList = getBoolFieldList(class_id); // c "BOOL" |
157 | pingvin | 487 | QMap <int, QString> pointersToModel; |
155 | pingvin | 488 | |
156 | pingvin | 489 | |
490 | |||
157 | pingvin | 491 | for (int i=0; i < dateFieldList.count(); i++){ // "DATA" |
158 | pingvin | 492 | static MyDEDelegate dateDelegate; |
493 | // static TimeEditDelegate dateDelegate("01.10.2010"); |
||
157 | pingvin | 494 | QString dateFieldName; // |
495 | int dataFieldIndex; // |
||
496 | dateFieldName = dateFieldList.at(i); // "DATA" |
||
497 | dataFieldIndex = sql_mogel->record().indexOf(dateFieldName); // |
||
498 | date_colomns_indexes.append(dataFieldIndex);// "DATA" |
||
499 | ui->tableView->setItemDelegateForColumn(dataFieldIndex, &dateDelegate); |
||
156 | pingvin | 500 | |
157 | pingvin | 501 | } |
130 | pingvin | 502 | |
153 | pingvin | 503 | |
158 | pingvin | 504 | for (int i=0; i < boolFieldList.count(); i++){ // "BOOL" |
505 | // // // // static MyDEDelegate dateDelegate; |
||
506 | // static TimeEditDelegate dateDelegate("01.10.2010"); |
||
507 | QString boolFieldName; // |
||
508 | int boolFieldIndex; // |
||
509 | boolFieldName = boolFieldList.at(i); // "BOOL" |
||
510 | boolFieldIndex = sql_mogel->record().indexOf(boolFieldName); // |
||
511 | bool_colomns_indexes.append(boolFieldIndex);// "DATA" |
||
512 | // ui->tableView->setItemDelegateForColumn(dataFieldIndex, &dateDelegate); |
||
130 | pingvin | 513 | |
158 | pingvin | 514 | } |
130 | pingvin | 515 | |
158 | pingvin | 516 | sql_mogel->setBooleansList(bool_colomns_indexes); |
517 | |||
518 | |||
157 | pingvin | 519 | for (int i=0; i < spin_delegate_list.count(); i++){ // |
520 | delete spin_delegate_list.at(i); |
||
521 | } |
||
130 | pingvin | 522 | |
157 | pingvin | 523 | spin_delegate_list.clear(); // |
130 | pingvin | 524 | |
157 | pingvin | 525 | QStringList pointersNames; |
526 | pointersNames = pointersList.keys(); // - |
||
130 | pingvin | 527 | |
138 | pingvin | 528 | |
529 | |||
530 | |||
531 | |||
157 | pingvin | 532 | // ui->tableView->setItemDelegateForColumn(2, picture_delegate); |
138 | pingvin | 533 | |
157 | pingvin | 534 | // ui->tableView->setRowHeight(1, 100); |
138 | pingvin | 535 | |
126 | pingvin | 536 | |
128 | pingvin | 537 | |
145 | pingvin | 538 | |
129 | pingvin | 539 | |
157 | pingvin | 540 | QStringList parentInctancesList = pointersList.values(); // |
129 | pingvin | 541 | |
157 | pingvin | 542 | for (i=0; i < pointersNames.size(); i++){ // -: |
543 | QString pointerName; |
||
153 | pingvin | 544 | |
157 | pingvin | 545 | int pointerIndex; |
546 | pointerName = pointersNames.at(i); // - |
||
547 | pointerIndex = sql_mogel->record().indexOf(pointerName); // |
||
548 | colomns_indexes.append(pointerIndex); // |
||
549 | spin_delegate_tmp = new SpinBoxDelegate(); |
||
153 | pingvin | 550 | |
157 | pingvin | 551 | // // spinDelegate.setInctance(parentInctancesList.at(i)); // |
552 | // // spinDelegate.getItems(); // |
||
153 | pingvin | 553 | |
157 | pingvin | 554 | spin_delegate_tmp->setInctance(parentInctancesList.at(i)); |
555 | spin_delegate_tmp->getItems(); |
||
128 | pingvin | 556 | |
157 | pingvin | 557 | spin_delegate_list.append(spin_delegate_tmp); |
128 | pingvin | 558 | |
157 | pingvin | 559 | // // ui->tableView->setItemDelegateForColumn(pointerIndex, &spinDelegate); // |
118 | pingvin | 560 | |
157 | pingvin | 561 | ui->tableView->setItemDelegateForColumn(pointerIndex, spin_delegate_tmp); |
115 | pingvin | 562 | |
157 | pingvin | 563 | pointersToModel.insert(pointerIndex, parentInctancesList.at(i)); // |
564 | } |
||
140 | pingvin | 565 | |
157 | pingvin | 566 | sql_mogel->setPointers(pointersToModel); // |
140 | pingvin | 567 | |
157 | pingvin | 568 | pointer_index = sql_mogel->record().indexOf(pointer_name); // , , ! :-) |
140 | pingvin | 569 | |
570 | |||
571 | |||
572 | |||
157 | pingvin | 573 | sql_mogel->setFilter(filtr_tmp); |
574 | sql_mogel->select(); |
||
154 | pingvin | 575 | |
157 | pingvin | 576 | connect(sql_mogel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_sql_mogel_dataChanged(QModelIndex,QModelIndex))); |
140 | pingvin | 577 | |
157 | pingvin | 578 | ui->tableView->setModel(sql_mogel); |
140 | pingvin | 579 | |
157 | pingvin | 580 | ui->tableView->resizeColumnsToContents(); |
581 | ui->tableView->hideColumn(0); |
||
140 | pingvin | 582 | |
583 | |||
115 | pingvin | 584 | } |
585 | |||
586 | } |
||
587 | |||
588 | |||
118 | pingvin | 589 | void MainWindow::on_pushButton_clicked(){ // " " |
590 | int row = sql_mogel->rowCount(); |
||
591 | sql_mogel->insertRows(row, 1); |
||
592 | sql_mogel->setData(sql_mogel->index(row, 1), QVariant(tr(" ")), Qt::EditRole); // " " |
||
593 | if (pointer_index > 0) { |
||
594 | sql_mogel->setData(sql_mogel->index(row, pointer_index), QVariant(parentObject_id), Qt::EditRole); // " " |
||
595 | } |
||
119 | pingvin | 596 | // sql_mogel->submitAll(); |
118 | pingvin | 597 | |
598 | } |
||
119 | pingvin | 599 | |
600 | void MainWindow::on_pushButton_2_clicked(){ // " " |
||
601 | int i; |
||
602 | i++; |
||
120 | pingvin | 603 | QModelIndex model_index; |
604 | QItemSelectionModel *selectionModel = ui->tableView->selectionModel(); |
||
605 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
||
606 | QList<int> selectedRows; |
||
607 | selectedRows.clear(); |
||
608 | foreach (model_index, indexes){ // |
||
609 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) selectedRows.append(model_index.row()); // |
||
119 | pingvin | 610 | |
611 | } |
||
120 | pingvin | 612 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // |
119 | pingvin | 613 | |
614 | |||
120 | pingvin | 615 | for (int m =0; m < selectedRows.size(); ++m){ |
616 | |||
617 | // ClassEditor::removeClass(selectedRows.at(m)); |
||
618 | |||
619 | sql_mogel->removeRow(selectedRows.at(m)); |
||
620 | |||
621 | } |
||
622 | sql_mogel->submitAll(); |
||
623 | getDatabaseData(); |
||
624 | |||
625 | } |
||
626 | |||
627 | |||
119 | pingvin | 628 | void MainWindow::on_pushButton_3_clicked(){ // "" |
629 | int i; |
||
630 | i++; |
||
631 | sql_mogel->submitAll(); |
||
632 | getDatabaseData(); |
||
633 | ui->pushButton_3->setEnabled(false); |
||
634 | ui->pushButton_4->setEnabled(false); |
||
635 | sql_mogel->select(); |
||
636 | |||
637 | } |
||
638 | |||
639 | |||
640 | void MainWindow::on_pushButton_4_clicked(){ // " " |
||
641 | int i; |
||
642 | i++; |
||
643 | sql_mogel->select(); |
||
644 | ui->pushButton_3->setEnabled(false); |
||
645 | ui->pushButton_4->setEnabled(false); |
||
646 | } |
||
647 | |||
648 | |||
144 | pingvin | 649 | void MainWindow::on_pushButton_5_clicked(){// " " |
650 | |||
651 | int i; |
||
652 | i++; |
||
653 | int row = model_for_ListModelsTable->rowCount(); |
||
654 | model_for_ListModelsTable->insertRows(row, 1); |
||
655 | model_for_ListModelsTable->setData(model_for_ListModelsTable->index(row, 1), QVariant(tr(" ")), Qt::EditRole); // " " |
||
656 | // model_for_ListModelsTable->setData(sql_mogel->index(row, pointer_index), QVariant(parentObject_id), Qt::EditRole); // " " |
||
657 | |||
658 | // sql_mogel->submitAll(); |
||
659 | |||
660 | |||
661 | } |
||
662 | |||
663 | void MainWindow::on_pushButton_6_clicked(){// " " |
||
664 | |||
665 | QModelIndex model_index; |
||
666 | QItemSelectionModel *selectionModel = ui->tableView_2->selectionModel(); |
||
667 | QModelIndexList indexes = selectionModel->selectedIndexes(); |
||
668 | QList<int> selectedRows; |
||
669 | selectedRows.clear(); |
||
670 | foreach (model_index, indexes){ // |
||
671 | if (!selectedRows.contains(model_index.row()) && (model_index.column()==1)) selectedRows.append(model_index.row()); // |
||
672 | |||
673 | } |
||
674 | qSort(selectedRows.begin(),selectedRows.end(), qGreater<int>()); // |
||
675 | |||
676 | |||
677 | for (int m =0; m < selectedRows.size(); ++m){ |
||
678 | |||
679 | // ClassEditor::removeClass(selectedRows.at(m)); |
||
680 | |||
681 | model_for_ListModelsTable->removeRow(selectedRows.at(m)); |
||
682 | |||
683 | } |
||
684 | model_for_ListModelsTable->submitAll(); |
||
685 | // getDatabaseData(); |
||
686 | |||
687 | } |
||
688 | |||
689 | |||
146 | pingvin | 690 | void MainWindow::on_pushButton_7_clicked(){// "" |
691 | model_for_ListModelsTable->submitAll(); |
||
692 | ui->pushButton_7->setEnabled(false); |
||
693 | ui->pushButton_8->setEnabled(false); |
||
694 | model_is_build = false; |
||
695 | MainWindow::readModels(); |
||
696 | model_is_build = true; |
||
697 | MainWindow::getDatabaseData(); |
||
698 | } |
||
144 | pingvin | 699 | |
146 | pingvin | 700 | void MainWindow::on_pushButton_8_clicked(){// "" ( ) |
701 | model_for_ListModelsTable->select(); |
||
702 | ui->pushButton_7->setEnabled(false); |
||
703 | ui->pushButton_8->setEnabled(false); |
||
704 | } |
||
705 | |||
119 | pingvin | 706 | void MainWindow::on_sql_mogel_dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ // |
707 | int i; |
||
708 | i++; |
||
709 | ui->pushButton_3->setEnabled(true); |
||
710 | ui->pushButton_4->setEnabled(true); |
||
711 | |||
712 | } |
||
128 | pingvin | 713 | |
146 | pingvin | 714 | void MainWindow::on_model_for_ListModelsTable_dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight ){ // |
128 | pingvin | 715 | |
146 | pingvin | 716 | ui->pushButton_7->setEnabled(true); |
717 | ui->pushButton_8->setEnabled(true); |
||
718 | } |
||
719 | |||
720 | |||
128 | pingvin | 721 | // -, - |
722 | // - |
||
723 | |||
724 | QMap <QString, QString> MainWindow::getPointersList(QString class_id){ |
||
725 | QMap <QString, QString> result_map; |
||
726 | QSqlQuery q; |
||
727 | QString sql_str; |
||
728 | QString str_tmp; |
||
729 | QString field; |
||
730 | QString result; |
||
731 | int field_name, field_default_value; |
||
732 | bool ok; |
||
733 | sql_str = tr("select * " |
||
734 | " from `DescriptionOfClasses` where `DescriptionOfClasses`.`FieldType` = 'pointer' and `DescriptionOfClasses`.`ClassIdentifer` = " // - |
||
735 | ); |
||
736 | |||
737 | sql_str.append(tr("'")); |
||
738 | sql_str.append(class_id); |
||
739 | sql_str.append(tr("' ")); |
||
740 | // sql_str.append(tr(" and `DescriptionOfClasses`.`ClassIdentifer` = '")); |
||
741 | // sql_str.append(chield_class_id); |
||
742 | // sql_str.append(tr("'")); |
||
743 | q.prepare(sql_str); |
||
744 | |||
745 | ok = q.exec(); |
||
746 | if (!ok) { |
||
747 | QMessageBox::critical( // . |
||
748 | this, // . |
||
749 | QObject::tr("Database Error"), // . |
||
750 | q.lastError().text()); // . |
||
751 | return result_map; |
||
752 | } |
||
753 | field_name = q.record().indexOf(tr("FieldName")); |
||
754 | field_default_value = q.record().indexOf(tr("DefaultValue")); |
||
755 | while(q.next()){ |
||
756 | QString pointerFieldName; |
||
757 | QString parentClassID; |
||
758 | QString parentClassInctance; |
||
759 | |||
760 | pointerFieldName = q.value(field_name).toString(); |
||
761 | parentClassID = q.value(field_default_value).toString(); |
||
762 | parentClassInctance = getClassInctance(parentClassID); |
||
763 | result_map.insert(pointerFieldName, parentClassInctance); |
||
764 | |||
765 | |||
766 | } |
||
767 | |||
768 | return result_map; |
||
769 | } |
||
770 | |||
132 | pingvin | 771 | |
772 | |||
773 | |||
774 | |||
155 | pingvin | 775 | QStringList MainWindow::getDataFieldList(QString class_id){ // c "", |
776 | // - |
||
132 | pingvin | 777 | |
155 | pingvin | 778 | QStringList result_str; |
779 | QSqlQuery q; |
||
780 | QString sql_str; |
||
781 | QString str_tmp; |
||
782 | QString field; |
||
783 | QString result; |
||
784 | int field_name, field_default_value; |
||
785 | bool ok; |
||
786 | sql_str = tr("select * " |
||
787 | " from `DescriptionOfClasses` where `DescriptionOfClasses`.`FieldType` = 'DATE' and `DescriptionOfClasses`.`ClassIdentifer` = " // - |
||
788 | ); |
||
789 | |||
790 | sql_str.append(tr("'")); |
||
791 | sql_str.append(class_id); |
||
792 | sql_str.append(tr("' ")); |
||
793 | // sql_str.append(tr(" and `DescriptionOfClasses`.`ClassIdentifer` = '")); |
||
794 | // sql_str.append(chield_class_id); |
||
795 | // sql_str.append(tr("'")); |
||
796 | q.prepare(sql_str); |
||
797 | |||
798 | ok = q.exec(); |
||
799 | if (!ok) { |
||
800 | QMessageBox::critical( // . |
||
801 | this, // . |
||
802 | QObject::tr("Database Error"), // . |
||
803 | q.lastError().text()); // . |
||
804 | return result_str; |
||
805 | } |
||
806 | field_name = q.record().indexOf(tr("FieldName")); |
||
807 | // field_default_value = q.record().indexOf(tr("DefaultValue")); |
||
808 | while(q.next()){ |
||
809 | QString DataFieldName; |
||
810 | |||
811 | DataFieldName = q.value(field_name).toString(); |
||
812 | result_str.append(DataFieldName); |
||
813 | |||
814 | |||
815 | } |
||
816 | |||
817 | return result_str; |
||
818 | } |
||
819 | |||
820 | |||
821 | |||
158 | pingvin | 822 | QStringList MainWindow::getBoolFieldList(QString class_id){ // c "bool" |
155 | pingvin | 823 | |
158 | pingvin | 824 | QStringList result_str; |
825 | QSqlQuery q; |
||
826 | QString sql_str; |
||
827 | QString str_tmp; |
||
828 | QString field; |
||
829 | QString result; |
||
830 | int field_name, field_default_value; |
||
831 | bool ok; |
||
832 | sql_str = tr("select * " |
||
833 | " from `DescriptionOfClasses` where `DescriptionOfClasses`.`FieldType` = 'BOOL' and `DescriptionOfClasses`.`ClassIdentifer` = " // - |
||
834 | ); |
||
835 | |||
836 | sql_str.append(tr("'")); |
||
837 | sql_str.append(class_id); |
||
838 | sql_str.append(tr("' ")); |
||
839 | // sql_str.append(tr(" and `DescriptionOfClasses`.`ClassIdentifer` = '")); |
||
840 | // sql_str.append(chield_class_id); |
||
841 | // sql_str.append(tr("'")); |
||
842 | q.prepare(sql_str); |
||
843 | |||
844 | ok = q.exec(); |
||
845 | if (!ok) { |
||
846 | QMessageBox::critical( // . |
||
847 | this, // . |
||
848 | QObject::tr("Database Error"), // . |
||
849 | q.lastError().text()); // . |
||
850 | return result_str; |
||
851 | } |
||
852 | field_name = q.record().indexOf(tr("FieldName")); |
||
853 | // field_default_value = q.record().indexOf(tr("DefaultValue")); |
||
854 | while(q.next()){ |
||
855 | QString DataFieldName; |
||
856 | |||
857 | DataFieldName = q.value(field_name).toString(); |
||
858 | result_str.append(DataFieldName); |
||
859 | |||
860 | |||
861 | } |
||
862 | |||
863 | return result_str; |
||
864 | } |
||
865 | |||
866 | |||
867 | |||
868 | |||
869 | |||
132 | pingvin | 870 | // |
871 | |||
872 | void MainWindow::readSettings() |
||
873 | { |
||
874 | QSettings settings("Trolltech", "Application Example"); |
||
875 | baseName = settings.value("baseName", "an_db").toString(); |
||
876 | userName = settings.value("userName", "an").toString(); |
||
877 | password = settings.value("password", "393939").toString(); |
||
878 | tableName = settings.value("tableName", "inventar").toString(); |
||
879 | hostName = settings.value("hostName", "server").toString(); |
||
880 | // resize(size); |
||
881 | // move(pos);tableName |
||
882 | } |
||
883 | |||
884 | |||
885 | void MainWindow::writeSettings() |
||
886 | { |
||
887 | QSettings settings("Trolltech", "Application Example"); |
||
888 | settings.setValue("baseName", baseName); |
||
889 | settings.setValue("userName", userName); |
||
890 | settings.setValue("password", password); |
||
891 | settings.setValue("tableName", tableName); |
||
892 | settings.setValue("hostName", hostName); |
||
893 | } |
||
894 | |||
895 | |||
896 | |||
897 | void MainWindow::applySetting() |
||
898 | { |
||
899 | bool ok; |
||
900 | baseName = setFrm.lineEdit->text(); |
||
901 | userName = setFrm.lineEdit_2->text(); |
||
902 | password = setFrm.lineEdit_3->text(); |
||
903 | // tableName = setFrm->lineEdit_4->text(); |
||
904 | hostName = setFrm.lineEdit_5->text(); |
||
905 | writeSettings(); |
||
906 | |||
907 | |||
908 | ok=openDataBase(); |
||
909 | if (!ok) return; |
||
910 | // // // ui->treeWidget->clear(); // |
||
911 | |||
912 | // // // buildPreviewModel(tr(" "), tr("1")); |
||
149 | pingvin | 913 | |
914 | model_is_build = false; |
||
915 | |||
132 | pingvin | 916 | class_list_map.clear(); // |
149 | pingvin | 917 | rootItems.clear(); |
918 | models_items.clear(); |
||
151 | pingvin | 919 | |
920 | disconnect(model_for_ListModelsTable, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_model_for_ListModelsTable_dataChanged(QModelIndex,QModelIndex))); |
||
149 | pingvin | 921 | delete model_for_ListModelsTable; |
151 | pingvin | 922 | |
149 | pingvin | 923 | initListModelsTablle(); |
924 | |||
151 | pingvin | 925 | connect(model_for_ListModelsTable, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_model_for_ListModelsTable_dataChanged(QModelIndex,QModelIndex))); |
926 | |||
149 | pingvin | 927 | ui->treeWidget->clear(); |
132 | pingvin | 928 | initComboBox(); |
149 | pingvin | 929 | // model_for_ListModelsTable->select(); |
930 | MainWindow::readModels(); |
||
931 | |||
932 | |||
933 | |||
132 | pingvin | 934 | // // // getDatabaseData(); |
935 | // delete setFrm; |
||
149 | pingvin | 936 | |
937 | |||
938 | model_is_build = true; |
||
150 | pingvin | 939 | getDatabaseData(); |
132 | pingvin | 940 | setFrm.close(); |
941 | } |
||
942 | |||
943 | |||
944 | void MainWindow::getSetting() |
||
945 | { |
||
946 | // setFrm = new settingForm; |
||
947 | // // // connect(setFrm.pushButton, SIGNAL(clicked()), this, SLOT(applySetting())); |
||
948 | setFrm.lineEdit->setText(baseName); |
||
949 | setFrm.lineEdit_2->setText(userName); |
||
950 | setFrm.lineEdit_3->setText(password); |
||
951 | // setFrm->lineEdit_4->setText(tableName); |
||
952 | setFrm.lineEdit_5->setText(hostName); |
||
953 | setFrm.show(); |
||
954 | |||
955 | |||
956 | |||
957 | } |
||
144 | pingvin | 958 | |
959 | |||
960 | |||
961 | |||
962 | void MainWindow::readModels(){ |
||
963 | |||
145 | pingvin | 964 | int row = model_for_ListModelsTable->rowCount(); |
147 | pingvin | 965 | QList <QTreeWidgetItem*> modelsItemsList; |
966 | QList <int> row_list; |
||
967 | modelsItemsList = models_items.values(); |
||
968 | |||
969 | row_list = models_items.keys(); |
||
970 | |||
971 | |||
972 | |||
145 | pingvin | 973 | rootItems.clear(); |
974 | ui->treeWidget->clear(); |
||
144 | pingvin | 975 | for (int i=0; i < row; i++){ |
976 | QTreeWidgetItem * item_tmp; |
||
977 | QString modelName; |
||
147 | pingvin | 978 | |
144 | pingvin | 979 | bool enabled; |
147 | pingvin | 980 | |
981 | |||
982 | |||
983 | //models_items.values(); |
||
984 | // modelString = |
||
985 | |||
144 | pingvin | 986 | modelName = model_for_ListModelsTable->data(model_for_ListModelsTable->index(i, 1)).toString(); |
987 | enabled = model_for_ListModelsTable->data(model_for_ListModelsTable->index(i, 3)).toBool(); |
||
988 | item_tmp = new QTreeWidgetItem(ui->treeWidget); |
||
989 | item_tmp->setText(0, modelName); |
||
147 | pingvin | 990 | item_tmp->setText(4, QVariant(i).toString()); // 4 |
144 | pingvin | 991 | if (enabled) item_tmp->setCheckState(0,Qt::Checked); |
992 | else item_tmp->setCheckState(0,Qt::Unchecked); |
||
145 | pingvin | 993 | |
994 | root_items_list << item_tmp; |
||
995 | |||
144 | pingvin | 996 | rootItems.append(item_tmp); |
147 | pingvin | 997 | |
998 | models_items[i] =item_tmp ; |
||
999 | |||
1000 | |||
145 | pingvin | 1001 | modelString = model_for_ListModelsTable->data(model_for_ListModelsTable->index(i, 2)).toString(); |
1002 | if (modelString.isEmpty()) continue; |
||
147 | pingvin | 1003 | else setupModelData(modelString.split(QString("\n")), item_tmp, i); // |
144 | pingvin | 1004 | |
1005 | } |
||
149 | pingvin | 1006 | |
144 | pingvin | 1007 | } |