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