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