Редакция 144 | Редакция 146 | К новейшей редакции | Содержимое файла | Сравнить с предыдущей | Последнее изменение | Открыть журнал | RSS
Редакция | Автор | № строки | Строка |
---|---|---|---|
88 | pingvin | 1 | #include "mainwindow.h" |
2 | #include "ui_mainwindow.h" |
||
3 | |||
4 | MainWindow::MainWindow(QWidget *parent) : |
||
5 | QMainWindow(parent), |
||
6 | ui(new Ui::MainWindow) |
||
7 | { |
||
8 | ui->setupUi(this); |
||
106 | pingvin | 9 | // connect( ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(on_currentIndexChanged(int))); |
118 | pingvin | 10 | model_is_build = false; |
145 | pingvin | 11 | // MainWindow::readModel(); |
89 | pingvin | 12 | |
91 | pingvin | 13 | //QString model_str; |
140 | pingvin | 14 | |
15 | |||
16 | /* |
||
91 | pingvin | 17 | MainWindow::creatModelString(); |
18 | int i; |
||
19 | i++; |
||
93 | pingvin | 20 | QFile file_tmp("./temp.txt"); |
92 | pingvin | 21 | bool ok; |
22 | ok = file_tmp.open(QIODevice::ReadWrite | QIODevice::Text); |
||
23 | QTextStream out(&file_tmp); |
||
24 | out << MainWindow::modelString; |
||
25 | file_tmp.close(); |
||
140 | pingvin | 26 | */ |
114 | pingvin | 27 | ui->treeWidget->setAlternatingRowColors(true); |
28 | ui->treeWidget_2->setAlternatingRowColors(true); |
||
132 | pingvin | 29 | |
30 | |||
31 | MainWindow::readSettings(); |
||
32 | |||
93 | pingvin | 33 | MainWindow::openDataBase(); |
136 | pingvin | 34 | |
104 | pingvin | 35 | MainWindow::initComboBox(); |
136 | pingvin | 36 | |
145 | pingvin | 37 | // MainWindow::buildPreviewModel(tr(" "), tr("11")); |
136 | pingvin | 38 | |
142 | pingvin | 39 | MainWindow::initListModelsTablle(); |
140 | pingvin | 40 | |
144 | pingvin | 41 | MainWindow::readModels(); |
42 | |||
145 | pingvin | 43 | // MainWindow::creatModelString(); |
140 | pingvin | 44 | //int i; |
45 | //i++; |
||
145 | pingvin | 46 | |
47 | /* |
||
48 | QFile file_tmp("./modelstring.txt"); |
||
140 | pingvin | 49 | bool ok; |
50 | file_tmp.remove(); |
||
51 | ok = file_tmp.open(QIODevice::ReadWrite | QIODevice::Text); |
||
52 | QTextStream out(&file_tmp); |
||
53 | out.setCodec("cp1251"); |
||
54 | out << MainWindow::modelString; |
||
55 | file_tmp.close(); |
||
145 | pingvin | 56 | */ |
140 | pingvin | 57 | |
58 | |||
59 | |||
109 | pingvin | 60 | getDatabaseData(); |
127 | pingvin | 61 | //// sql_mogel = new QSqlTableModel(); |
62 | sql_mogel = new MyModel(); |
||
63 | |||
64 | |||
118 | pingvin | 65 | model_is_build = true; |
119 | pingvin | 66 | connect(sql_mogel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_sql_mogel_dataChanged(QModelIndex,QModelIndex))); |
67 | ui->pushButton_3->setEnabled(false); |
||
68 | ui->pushButton_4->setEnabled(false); |
||
69 | |||
132 | pingvin | 70 | // setFrm.show(); |
119 | pingvin | 71 | |
132 | pingvin | 72 | connect(ui->getsettingAct, SIGNAL(triggered()), this, SLOT(getSetting())); // " " " " |
73 | connect(setFrm.pushButton, SIGNAL(clicked()), this, SLOT(applySetting())); |
||
74 | |||
138 | pingvin | 75 | picture_delegate = new CPictureDelegate(this); |
132 | pingvin | 76 | |
88 | pingvin | 77 | } |
78 | |||
79 | MainWindow::~MainWindow() |
||
80 | { |
||
117 | pingvin | 81 | delete sql_mogel; |
88 | pingvin | 82 | delete ui; |
83 | } |
||
84 | |||
85 | void MainWindow::changeEvent(QEvent *e) |
||
86 | { |
||
87 | QMainWindow::changeEvent(e); |
||
88 | switch (e->type()) { |
||
89 | case QEvent::LanguageChange: |
||
90 | ui->retranslateUi(this); |
||
91 | break; |
||
92 | default: |
||
93 | break; |
||
94 | } |
||
95 | } |
||
89 | pingvin | 96 | |
97 | |||
98 | bool MainWindow::readModel(){ |
||
99 | bool result; |
||
100 | QString model_str; |
||
140 | pingvin | 101 | QFile file("modelstring.txt"); |
141 | pingvin | 102 | // QFile file("model.txt"); |
91 | pingvin | 103 | rootItem1 = new QTreeWidgetItem(ui->treeWidget); |
89 | pingvin | 104 | rootItem1->setText(0, tr(" 1")); |
105 | // rootItem2 = new QTreeWidgetItem(rootItem1); |
||
106 | // rootItem2->setText(0, tr(" 2")); |
||
107 | rootItem1->setCheckState(0,Qt::Checked); |
||
108 | // rootItem2->setCheckState(0,Qt::Checked); |
||
109 | |||
110 | |||
111 | |||
112 | result = file.open(QIODevice::ReadOnly); |
||
113 | if (result) { |
||
90 | pingvin | 114 | model_str = QString(tr(file.readAll())); |
89 | pingvin | 115 | } |
116 | |||
91 | pingvin | 117 | setupModelData(model_str.split(QString("\n")), rootItem1); |
89 | pingvin | 118 | |
119 | |||
120 | return result; |
||
121 | |||
122 | } |
||
123 | |||
124 | |||
125 | void MainWindow::setupModelData(const QStringList &lines, QTreeWidgetItem *parent) |
||
126 | { |
||
127 | QList<QTreeWidgetItem*> parents; |
||
128 | QList<int> indentations; |
||
129 | parents << parent; |
||
130 | indentations << 0; |
||
131 | |||
132 | int number = 0; |
||
133 | |||
134 | while (number < lines.count()) { |
||
135 | int position = 0; |
||
136 | while (position < lines[number].length()) { |
||
137 | if (lines[number].mid(position, 1) != " ") |
||
138 | break; |
||
139 | position++; |
||
140 | } |
||
141 | |||
142 | QString lineData = lines[number].mid(position).trimmed(); |
||
143 | |||
144 | if (!lineData.isEmpty()) { |
||
145 | // Read the column data from the rest of the line. |
||
146 | QStringList columnStrings = lineData.split("\t", QString::SkipEmptyParts); |
||
147 | QList<QVariant> columnData; |
||
148 | for (int column = 0; column < columnStrings.count(); ++column) |
||
149 | columnData << columnStrings[column]; |
||
150 | |||
151 | if (position > indentations.last()) { |
||
152 | // The last child of the current parent is now the new parent |
||
153 | // unless the current parent has no children. |
||
154 | |||
155 | if (parents.last()->childCount() > 0) { |
||
156 | parents << parents.last()->child(parents.last()->childCount()-1); |
||
157 | indentations << position; |
||
158 | } |
||
159 | } else { |
||
160 | while (position < indentations.last() && parents.count() > 0) { |
||
161 | parents.pop_back(); |
||
162 | indentations.pop_back(); |
||
163 | } |
||
164 | } |
||
165 | |||
166 | // Append a new item to the current parent's list of children. |
||
167 | // // // parents.last()->appendChild(new QTreeWidgetItem(columnData, parents.last())); |
||
168 | QTreeWidgetItem* itm_tmp; |
||
169 | itm_tmp = new QTreeWidgetItem( parents.last()); |
||
170 | |||
171 | itm_tmp->setText(0, QString(columnData.at(0).toString())); |
||
172 | if (columnData.at(1).toString() == "true") { |
||
173 | itm_tmp->setCheckState(0,Qt::Checked); |
||
174 | } |
||
175 | else itm_tmp->setCheckState(0,Qt::Unchecked); |
||
141 | pingvin | 176 | if (columnData.count()>2) |
177 | { |
||
90 | pingvin | 178 | itm_tmp->setText(1, QString(columnData.at(2).toString())); |
179 | itm_tmp->setText(2, QVariant(number).toString()); // - |
||
180 | itm_tmp->setText(3, QVariant(indentations.size()).toString()); |
||
141 | pingvin | 181 | } |
89 | pingvin | 182 | } |
183 | |||
184 | number++; |
||
185 | } |
||
186 | } |
||
187 | |||
188 | |||
189 | /* |
||
190 | void MainWindow::openBase() |
||
191 | { |
||
192 | |||
193 | db = QSqlDatabase::addDatabase("QMYSQL"); |
||
194 | pdb = &db; |
||
195 | raportFrm.pdb = &db; |
||
196 | |||
197 | pdb->setHostName(hostName); |
||
198 | pdb->setDatabaseName(baseName); |
||
199 | pdb->setUserName(userName); |
||
200 | pdb->setPassword(password); |
||
201 | bool ok = pdb->open(); |
||
202 | if (!ok) { |
||
203 | QMessageBox::critical( // . |
||
204 | this, // . |
||
205 | QObject::tr("Database Error"), // . |
||
206 | pdb->lastError().text()); // . |
||
207 | } |
||
208 | if (ok) |
||
209 | {lineEdit-> insert(tr(" ")); |
||
210 | } |
||
211 | else {lineEdit-> insert(tr(" . : ")); |
||
212 | lineEdit-> insert(pdb->lastError().text()); |
||
213 | } |
||
214 | |||
215 | |||
216 | |||
217 | model = new QSqlTableModel(this); |
||
218 | model->setTable(tableName); |
||
219 | |||
220 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
221 | model->setSort(0, Qt::AscendingOrder); |
||
222 | |||
223 | model->select(); |
||
224 | |||
225 | |||
226 | QSqlField field(tr("age"), QVariant::Int); |
||
227 | field.setValue(QString(tr("123"))); |
||
228 | |||
229 | bool okey; |
||
230 | int index; |
||
231 | QSqlRecord record; |
||
232 | |||
233 | |||
234 | tableView->setModel(model); |
||
235 | view.setModel(model); |
||
236 | |||
237 | |||
238 | tableView->setAlternatingRowColors(true); |
||
239 | view.setAlternatingRowColors(true); |
||
240 | |||
241 | tableView->resizeColumnsToContents(); |
||
242 | |||
243 | |||
244 | view.resizeColumnsToContents(); |
||
245 | |||
246 | tableView->show(); |
||
247 | |||
248 | |||
249 | |||
250 | initTreeWidget(); |
||
251 | } |
||
252 | */ |
||
91 | pingvin | 253 | |
254 | |||
255 | void MainWindow::creatModelString(){ |
||
256 | |||
257 | MainWindow::modelString.clear(); // |
||
258 | // for (int i =0; i < rootItem1->childCount(); ++i ) |
||
259 | |||
260 | {MainWindow::addChildsString(rootItem1, 0);} |
||
145 | pingvin | 261 | // {MainWindow::addChildsString(ui->treeWidget, 0);} |
262 | /* |
||
91 | pingvin | 263 | int root_item_child_count; |
264 | int i; |
||
265 | root_item_child_count = rootItem1->childCount(); |
||
266 | i++; |
||
145 | pingvin | 267 | */ |
91 | pingvin | 268 | } |
269 | |||
270 | |||
271 | void MainWindow::addChildsString(QTreeWidgetItem *parentItem, int level){ |
||
272 | int child_count; |
||
273 | child_count = parentItem->childCount(); |
||
274 | for (int i=0; i < child_count; ++i){ |
||
275 | for (int m=0; m < level; ++m){ |
||
276 | modelString.append(tr(" ")); // - , |
||
277 | } |
||
278 | modelString.append(parentItem->child(i)->text(0)); // - |
||
279 | modelString.append(tr("\t\t\t\t")); // - |
||
280 | if (parentItem->child(i)->checkState(0) == Qt::Checked) {modelString.append(tr("true"));} // , "true", |
||
281 | else {modelString.append(tr("false"));} // - "false", |
||
282 | modelString.append(tr("\t\t\t\t")); // - |
||
283 | modelString.append(parentItem->child(i)->text(1)); // - ID |
||
284 | modelString.append(tr("\n")); // |
||
285 | if (parentItem->child(i)->childCount() > 0) { MainWindow::addChildsString(parentItem->child(i), level+1);} |
||
286 | |||
287 | } |
||
288 | int i; |
||
289 | i++; |
||
290 | } |
||
93 | pingvin | 291 | |
292 | |||
293 | bool MainWindow::openDataBase(){ |
||
294 | QString errorString; |
||
295 | sql = QSqlDatabase::addDatabase("QMYSQL"); |
||
131 | pingvin | 296 | // sql.setDatabaseName(tr("an_db")); |
297 | |||
132 | pingvin | 298 | // // // sql.setDatabaseName(tr("inventory")); |
131 | pingvin | 299 | |
132 | pingvin | 300 | sql.setDatabaseName(baseName); |
131 | pingvin | 301 | |
302 | |||
303 | |||
132 | pingvin | 304 | // // // sql.setHostName(tr("localhost")); |
93 | pingvin | 305 | |
132 | pingvin | 306 | sql.setHostName(hostName); |
307 | |||
308 | |||
309 | // // // sql.setUserName(tr("an")); |
||
310 | |||
311 | sql.setUserName(userName); |
||
312 | |||
313 | |||
314 | |||
315 | // // // sql.setPassword(tr("393939")); |
||
316 | |||
317 | |||
318 | sql.setPassword(password); |
||
319 | |||
320 | |||
321 | |||
93 | pingvin | 322 | bool ok; |
323 | ok = sql.open(); |
||
324 | |||
325 | /* |
||
326 | if (!ok) { |
||
327 | QMessageBox::critical( // . |
||
328 | this, // . |
||
329 | QObject::tr("Database Error"), // . |
||
330 | sql.lastError().text() ); // . |
||
331 | |||
332 | |||
333 | } |
||
334 | |||
335 | */ |
||
336 | if (!ok) { |
||
337 | QMessageBox::critical( // . |
||
338 | this, // . |
||
339 | QObject::tr("Database Error"), // . |
||
340 | sql.lastError().text()); // . |
||
341 | } |
||
342 | else { |
||
343 | |||
344 | QMessageBox::information( // . |
||
345 | this, // . |
||
346 | QObject::tr("Database Connect"), // . |
||
347 | QObject::tr(" .")); // . |
||
348 | |||
349 | |||
350 | |||
351 | |||
352 | |||
353 | } |
||
354 | |||
355 | return ok; |
||
356 | } |
||
94 | pingvin | 357 | |
358 | |||
97 | pingvin | 359 | bool MainWindow::buildPreviewModel(QString modelName, QString rootClassID){ |
94 | pingvin | 360 | QSqlQuery q; |
361 | QString sql_str; |
||
95 | pingvin | 362 | QString field_name_str; |
363 | QString root_class_name; |
||
364 | bool ok; |
||
94 | pingvin | 365 | int field_name; |
95 | pingvin | 366 | |
367 | //ui->treeWidget->clear(); |
||
368 | |||
369 | root_class_name = MainWindow::ClassName(rootClassID); // |
||
370 | |||
145 | pingvin | 371 | |
95 | pingvin | 372 | rootItem1 = new QTreeWidgetItem(ui->treeWidget); |
145 | pingvin | 373 | root_items_list << rootItem1; |
97 | pingvin | 374 | rootItem1->setText(0, modelName); |
375 | |||
95 | pingvin | 376 | rootItem1->setCheckState(0,Qt::Checked); |
104 | pingvin | 377 | rootItems.append(rootItem1); |
95 | pingvin | 378 | |
379 | |||
104 | pingvin | 380 | |
145 | pingvin | 381 | rootItem2 = new QTreeWidgetItem(rootItem1); |
382 | rootItem2->setText(0, root_class_name); |
||
383 | rootItem2->setText(1, rootClassID); |
||
384 | rootItem2->setCheckState(0,Qt::Checked); |
||
95 | pingvin | 385 | |
145 | pingvin | 386 | addChildsItems(rootItem2); |
95 | pingvin | 387 | |
145 | pingvin | 388 | |
389 | /* |
||
390 | |||
94 | pingvin | 391 | sql_str = tr("select * " |
95 | pingvin | 392 | " from DescriptionOfClasses where DescriptionOfClasses.DefaultValue = '" // , |
94 | pingvin | 393 | ); |
394 | sql_str.append(rootClassID); |
||
395 | |||
95 | pingvin | 396 | sql_str.append(tr("' and DescriptionOfClasses.FieldType = 'pointer' ")); |
94 | pingvin | 397 | |
95 | pingvin | 398 | q.prepare(sql_str); |
399 | |||
400 | ok = q.exec(); |
||
401 | if (!ok) { |
||
402 | QMessageBox::critical( // . |
||
403 | this, // . |
||
404 | QObject::tr("Database Error"), // . |
||
405 | q.lastError().text()); // . |
||
406 | } |
||
407 | field_name = q.record().indexOf(tr("FieldName")); |
||
408 | while(q.next()){ |
||
409 | |||
410 | field_name_str = q.value(field_name).toString(); |
||
411 | |||
412 | } |
||
413 | |||
100 | pingvin | 414 | |
415 | |||
416 | |||
145 | pingvin | 417 | */ |
418 | |||
419 | |||
94 | pingvin | 420 | } |
95 | pingvin | 421 | |
422 | |||
107 | pingvin | 423 | bool MainWindow::rebuildPreviewModel(QTreeWidgetItem* root_item, QString rootClassID){ |
424 | QSqlQuery q; |
||
425 | QString sql_str; |
||
426 | QString field_name_str; |
||
427 | QString root_class_name; |
||
428 | bool ok; |
||
429 | int field_name; |
||
95 | pingvin | 430 | |
107 | pingvin | 431 | //ui->treeWidget->clear(); |
432 | |||
433 | root_class_name = MainWindow::ClassName(rootClassID); // |
||
434 | |||
435 | |||
436 | // rootItem1 = new QTreeWidgetItem(ui->treeWidget); |
||
437 | // root_items_list << rootItem1; |
||
438 | // rootItem1->setText(0, modelName); |
||
439 | |||
440 | // rootItem1->setCheckState(0,Qt::Checked); |
||
441 | // rootItems.append(rootItem1); |
||
442 | |||
443 | // root_item->removeChild(root_item->child(0)); // |
||
145 | pingvin | 444 | if (root_item->childCount()==0){ // , |
445 | QTreeWidgetItem* item_tmp; |
||
446 | item_tmp = new QTreeWidgetItem (root_item); |
||
447 | |||
448 | } |
||
449 | |||
450 | if (root_item->childCount()==1){ // , |
||
107 | pingvin | 451 | root_item->child(0)->setText(0, root_class_name); |
452 | root_item->child(0)->setText(1, rootClassID); |
||
453 | root_item->child(0)->setCheckState(0,Qt::Checked);} |
||
454 | |||
145 | pingvin | 455 | |
456 | |||
107 | pingvin | 457 | //delete rootItem2; |
458 | |||
459 | |||
460 | // rootItem2 = new QTreeWidgetItem(rootItem1); |
||
461 | |||
462 | |||
463 | |||
464 | // rootItem2->setText(0, root_class_name); |
||
465 | // rootItem2->setText(1, rootClassID); |
||
466 | // rootItem2->setCheckState(0,Qt::Checked); |
||
467 | |||
468 | int child_count = root_item->child(0)->childCount(); |
||
469 | |||
470 | |||
145 | pingvin | 471 | for (int i=0; i < child_count; i++){ // , |
107 | pingvin | 472 | root_item->child(0)->removeChild(root_item->child(0)->child(0)); |
473 | } |
||
474 | |||
475 | child_count = root_item->child(0)->childCount(); |
||
476 | addChildsItems(root_item->child(0)); |
||
477 | /* |
||
478 | sql_str = tr("select * " |
||
479 | " from DescriptionOfClasses where DescriptionOfClasses.DefaultValue = '" // , |
||
480 | ); |
||
481 | sql_str.append(rootClassID); |
||
482 | |||
483 | sql_str.append(tr("' and DescriptionOfClasses.FieldType = 'pointer' ")); |
||
484 | |||
485 | q.prepare(sql_str); |
||
486 | |||
487 | ok = q.exec(); |
||
488 | if (!ok) { |
||
489 | QMessageBox::critical( // . |
||
490 | this, // . |
||
491 | QObject::tr("Database Error"), // . |
||
492 | q.lastError().text()); // . |
||
493 | } |
||
494 | field_name = q.record().indexOf(tr("FieldName")); |
||
495 | while(q.next()){ |
||
496 | |||
497 | field_name_str = q.value(field_name).toString(); |
||
498 | |||
499 | } |
||
500 | |||
501 | */ |
||
502 | |||
503 | |||
504 | } |
||
505 | |||
506 | |||
507 | |||
508 | |||
95 | pingvin | 509 | QString MainWindow::ClassName(QString class_id){ // ID |
510 | QSqlQuery q; |
||
511 | QString sql_str; |
||
512 | QString class_name_str; |
||
513 | bool ok; |
||
514 | int field_class_name; |
||
515 | |||
516 | sql_str = tr("select * " |
||
517 | " from ListOfClasses where ListOfClasses.ID = '" // , |
||
518 | ); |
||
519 | |||
520 | sql_str.append(class_id); |
||
521 | sql_str.append(tr("' ")); |
||
522 | |||
523 | q.prepare(sql_str); |
||
524 | |||
525 | ok = q.exec(); |
||
526 | |||
527 | |||
528 | if (!ok) { |
||
529 | QMessageBox::critical( // . |
||
530 | this, // . |
||
531 | QObject::tr("Database Error"), // . |
||
532 | q.lastError().text()); // . |
||
533 | } |
||
534 | |||
535 | field_class_name = q.record().indexOf(tr("ClassName")); |
||
536 | while(q.next()){ |
||
537 | |||
538 | class_name_str = q.value(field_class_name).toString(); |
||
539 | |||
540 | } |
||
541 | |||
542 | return class_name_str; |
||
543 | |||
544 | } |
||
98 | pingvin | 545 | |
546 | void MainWindow::addChildsItems(QTreeWidgetItem *perent_class_item){ // , |
||
100 | pingvin | 547 | QStringList chields_list; |
548 | QString parent_ID; |
||
549 | QTreeWidgetItem *Item_tmp; |
||
550 | parent_ID = perent_class_item->text(1); |
||
551 | int chields_count, i; |
||
98 | pingvin | 552 | |
100 | pingvin | 553 | chields_list = MainWindow::classChields(parent_ID); |
554 | if(chields_list.isEmpty()) return; |
||
555 | chields_count = chields_list.size(); |
||
556 | for (int l = 0; l < chields_count; ++l){ |
||
557 | QString chield_class_name, chield_id; |
||
558 | chield_id = chields_list.at(l); |
||
559 | chield_class_name = MainWindow::ClassName(chield_id); |
||
560 | Item_tmp = new QTreeWidgetItem(perent_class_item); |
||
561 | Item_tmp->setText(0, chield_class_name); |
||
562 | Item_tmp->setText(1, chield_id); |
||
563 | Item_tmp->setCheckState(0, Qt::Checked); |
||
101 | pingvin | 564 | MainWindow::addChildsItems(Item_tmp); |
98 | pingvin | 565 | } |
566 | |||
100 | pingvin | 567 | i++; |
99 | pingvin | 568 | |
100 | pingvin | 569 | } |
570 | |||
571 | |||
99 | pingvin | 572 | /******************************************************** |
573 | * "" |
||
574 | * |
||
575 | * |
||
576 | * |
||
577 | ********************************************************/ |
||
578 | |||
579 | QStringList MainWindow::classChields(QString class_id){ |
||
580 | // QMap<QString, QString> map; |
||
581 | // TClass class_tmp; |
||
582 | // QList <TClass> chields_class_list; // |
||
583 | QStringList result; |
||
584 | QSqlQuery q; |
||
585 | QString sql_str; |
||
586 | QString classIdentifer_str; // - |
||
587 | QString field_id_str; |
||
588 | bool ok; |
||
589 | int field_classIdentifer; |
||
590 | sql_str = tr("select * " |
||
591 | " from DescriptionOfClasses where DescriptionOfClasses.DefaultValue = '" // , |
||
592 | ); |
||
593 | sql_str.append(class_id); |
||
594 | |||
595 | sql_str.append(tr("' and DescriptionOfClasses.FieldType = 'pointer' ")); |
||
596 | |||
597 | q.prepare(sql_str); |
||
598 | |||
599 | ok = q.exec(); |
||
600 | if (!ok) { |
||
601 | QMessageBox::critical( // . |
||
602 | this, // . |
||
603 | QObject::tr("Database Error"), // . |
||
604 | q.lastError().text()); // . |
||
605 | } |
||
606 | field_classIdentifer = q.record().indexOf(tr("ClassIdentifer")); |
||
607 | while(q.next()){ |
||
608 | |||
609 | classIdentifer_str = q.value(field_classIdentifer).toString(); |
||
610 | result.append(classIdentifer_str); |
||
611 | } |
||
612 | |||
613 | return result; |
||
614 | |||
615 | } |
||
102 | pingvin | 616 | |
617 | |||
618 | QMap <QString, QString> MainWindow::getClassList(){ // |
||
619 | QMap <QString, QString> result_map; |
||
620 | QSqlQuery q; |
||
621 | QString sql_str; |
||
103 | pingvin | 622 | QString class_name_str, class_id_str; |
623 | |||
102 | pingvin | 624 | int field_class_id, field_class_name; |
625 | bool ok; |
||
626 | sql_str = tr("select * " |
||
627 | " from ListOfClasses " // , |
||
628 | ); |
||
629 | q.prepare(sql_str); |
||
630 | ok = q.exec(); |
||
631 | if (!ok) { |
||
632 | QMessageBox::critical( // . |
||
633 | this, // . |
||
634 | QObject::tr("Database Error"), // . |
||
635 | q.lastError().text()); // . |
||
636 | return result_map; // - |
||
637 | } |
||
638 | field_class_id = q.record().indexOf(tr("ID")); |
||
639 | field_class_name = q.record().indexOf(tr("ClassName")); |
||
640 | |||
103 | pingvin | 641 | while(q.next()){ |
102 | pingvin | 642 | |
103 | pingvin | 643 | class_name_str = q.value(field_class_name).toString(); |
644 | class_id_str = q.value(field_class_id).toString(); |
||
645 | result_map[class_id_str] = class_name_str; |
||
646 | } |
||
102 | pingvin | 647 | return result_map; |
648 | } |
||
104 | pingvin | 649 | |
650 | |||
651 | |||
652 | |||
653 | |||
654 | void MainWindow::initComboBox(){ |
||
655 | |||
106 | pingvin | 656 | |
104 | pingvin | 657 | QStringList classesNameList; |
658 | QStringList classesID_list; |
||
659 | QStringList tmp_stringList; |
||
660 | |||
661 | |||
662 | |||
663 | QString tmp_str; |
||
664 | |||
665 | class_list_map = MainWindow::getClassList(); |
||
666 | classesID_list = class_list_map.keys(); |
||
667 | classesNameList = class_list_map.values(); |
||
668 | QMapIterator<QString, QString> interator(class_list_map); |
||
669 | // ui->comboBox->addItems(classesID_list); |
||
670 | // ui->comboBox->addItems(classesNameList); |
||
671 | while (interator.hasNext()) { |
||
672 | interator.next(); |
||
673 | tmp_str = interator.value(); |
||
674 | tmp_str.append(tr(" \t(ID=")); |
||
675 | tmp_str.append(interator.key()); |
||
676 | tmp_str.append(tr(")")); |
||
677 | tmp_stringList << tmp_str; |
||
678 | |||
679 | } |
||
132 | pingvin | 680 | // int count = ui->comboBox->count(); |
681 | |||
682 | ui->comboBox->clear(); |
||
104 | pingvin | 683 | ui->comboBox->addItems(tmp_stringList); |
684 | |||
685 | |||
686 | } |
||
105 | pingvin | 687 | |
688 | |||
106 | pingvin | 689 | void MainWindow::on_comboBox_currentIndexChanged( int index ){ |
690 | QStringList classesNameList; |
||
691 | QStringList classesID_list; |
||
692 | QString ID_str; |
||
132 | pingvin | 693 | if (index == -1) return; |
694 | |||
106 | pingvin | 695 | classesID_list = class_list_map.keys(); |
696 | classesNameList = class_list_map.values(); |
||
697 | ID_str = classesID_list[index]; |
||
698 | ui->label->setText(ID_str); |
||
145 | pingvin | 699 | if (root_items_list.indexOf(ui->treeWidget->currentItem()) != -1) |
700 | { |
||
701 | model_is_build = false; // on_treeWidget_itemChanged |
||
702 | rebuildPreviewModel(ui->treeWidget->currentItem(), ID_str); |
||
703 | model_is_build = true; // |
||
704 | } |
||
705 | getDatabaseData(); |
||
107 | pingvin | 706 | |
707 | |||
105 | pingvin | 708 | } |
709 | |||
106 | pingvin | 710 | void MainWindow::on_treeWidget_itemChanged ( QTreeWidgetItem * item, int column ){ |
711 | int i; |
||
712 | i++; |
||
713 | |||
118 | pingvin | 714 | if ((column) == 0 && (model_is_build)) getDatabaseData(); |
715 | |||
106 | pingvin | 716 | } |
717 | |||
718 | |||
719 | void MainWindow::on_treeWidget_itemClicked ( QTreeWidgetItem * item, int column ){ |
||
720 | int i; |
||
721 | i++; |
||
108 | pingvin | 722 | if (root_items_list.indexOf(item) != -1) { |
723 | QStringList classesNameList; |
||
724 | QStringList classesID_list; |
||
106 | pingvin | 725 | |
108 | pingvin | 726 | int index; |
727 | classesID_list = class_list_map.keys(); |
||
728 | classesNameList = class_list_map.values(); |
||
145 | pingvin | 729 | if (item->childCount()>0) index = classesID_list.indexOf(item->child(0)->text(1)); // , |
730 | else { // |
||
731 | ui->comboBox->setEnabled(true); |
||
732 | return; |
||
733 | |||
734 | } |
||
132 | pingvin | 735 | if (index != -1) ui->comboBox->setCurrentIndex(index); |
108 | pingvin | 736 | |
737 | ui->comboBox->setEnabled(true); |
||
738 | |||
739 | |||
740 | } |
||
106 | pingvin | 741 | // if ((rootItem1) == (item) ) ui->comboBox->setEnabled(true); |
742 | else ( ui->comboBox->setEnabled(false)); |
||
743 | } |
||
110 | pingvin | 744 | |
125 | pingvin | 745 | QMap <QString, QString> MainWindow::getFieldsList(QString class_id){ // |
110 | pingvin | 746 | |
125 | pingvin | 747 | } |
142 | pingvin | 748 | |
749 | |||
750 | void MainWindow::initListModelsTablle(){ |
||
751 | model_for_ListModelsTable = new QSqlTableModel(this); |
||
752 | |||
753 | model_for_ListModelsTable->setTable(tr("ListOfModels")); |
||
754 | model_for_ListModelsTable->setEditStrategy(QSqlTableModel::OnFieldChange); |
||
755 | |||
756 | ui->tableView_2->setModel(model_for_ListModelsTable); |
||
757 | model_for_ListModelsTable->select(); |
||
758 | } |