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