Редакция 219 | Редакция 222 | К новейшей редакции | Содержимое файла | Сравнить с предыдущей | Последнее изменение | Открыть журнал | 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); |
||
205 | pingvin | 9 | ui->centralWidget->setLayout(ui->verticalLayout); |
10 | ui->tab->setLayout(ui->horizontalLayout); |
||
11 | ui->tab_2->setLayout(ui->horizontalLayout_3); |
||
106 | pingvin | 12 | // connect( ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(on_currentIndexChanged(int))); |
118 | pingvin | 13 | model_is_build = false; |
145 | pingvin | 14 | // MainWindow::readModel(); |
89 | pingvin | 15 | |
91 | pingvin | 16 | //QString model_str; |
140 | pingvin | 17 | |
18 | |||
19 | /* |
||
91 | pingvin | 20 | MainWindow::creatModelString(); |
21 | int i; |
||
22 | i++; |
||
93 | pingvin | 23 | QFile file_tmp("./temp.txt"); |
92 | pingvin | 24 | bool ok; |
25 | ok = file_tmp.open(QIODevice::ReadWrite | QIODevice::Text); |
||
26 | QTextStream out(&file_tmp); |
||
27 | out << MainWindow::modelString; |
||
28 | file_tmp.close(); |
||
140 | pingvin | 29 | */ |
174 | pingvin | 30 | |
31 | |||
32 | |||
33 | |||
114 | pingvin | 34 | ui->treeWidget->setAlternatingRowColors(true); |
35 | ui->treeWidget_2->setAlternatingRowColors(true); |
||
132 | pingvin | 36 | |
177 | pingvin | 37 | ui->treeWidget->setIconSize(QSize(30,30)); |
209 | pingvin | 38 | ui->treeWidget->setColumnWidth(0, 400); |
193 | pingvin | 39 | ui->treeWidget_2->setIconSize(QSize(128,128)); |
132 | pingvin | 40 | |
41 | MainWindow::readSettings(); |
||
42 | |||
93 | pingvin | 43 | MainWindow::openDataBase(); |
136 | pingvin | 44 | |
174 | pingvin | 45 | classesIcons = MainWindow::getClassesIcons(); // |
46 | |||
104 | pingvin | 47 | MainWindow::initComboBox(); |
136 | pingvin | 48 | |
145 | pingvin | 49 | // MainWindow::buildPreviewModel(tr(" "), tr("11")); |
136 | pingvin | 50 | |
142 | pingvin | 51 | MainWindow::initListModelsTablle(); |
140 | pingvin | 52 | |
144 | pingvin | 53 | MainWindow::readModels(); |
54 | |||
145 | pingvin | 55 | // MainWindow::creatModelString(); |
140 | pingvin | 56 | //int i; |
57 | //i++; |
||
145 | pingvin | 58 | |
59 | /* |
||
60 | QFile file_tmp("./modelstring.txt"); |
||
140 | pingvin | 61 | bool ok; |
62 | file_tmp.remove(); |
||
63 | ok = file_tmp.open(QIODevice::ReadWrite | QIODevice::Text); |
||
64 | QTextStream out(&file_tmp); |
||
65 | out.setCodec("cp1251"); |
||
66 | out << MainWindow::modelString; |
||
67 | file_tmp.close(); |
||
145 | pingvin | 68 | */ |
140 | pingvin | 69 | |
70 | |||
151 | pingvin | 71 | ui->treeWidget_2->hideColumn(1); |
72 | ui->treeWidget_2->hideColumn(2); |
||
73 | ui->treeWidget_2->hideColumn(3); |
||
74 | ui->treeWidget_2->hideColumn(4); |
||
140 | pingvin | 75 | |
151 | pingvin | 76 | |
109 | pingvin | 77 | getDatabaseData(); |
127 | pingvin | 78 | //// sql_mogel = new QSqlTableModel(); |
79 | sql_mogel = new MyModel(); |
||
221 | pingvin | 80 | filter_model = new MyModel(); |
127 | pingvin | 81 | |
82 | |||
118 | pingvin | 83 | model_is_build = true; |
119 | pingvin | 84 | connect(sql_mogel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_sql_mogel_dataChanged(QModelIndex,QModelIndex))); |
146 | pingvin | 85 | connect(model_for_ListModelsTable, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_model_for_ListModelsTable_dataChanged(QModelIndex,QModelIndex))); |
221 | pingvin | 86 | connect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
146 | pingvin | 87 | |
221 | pingvin | 88 | |
119 | pingvin | 89 | ui->pushButton_3->setEnabled(false); |
90 | ui->pushButton_4->setEnabled(false); |
||
91 | |||
217 | pingvin | 92 | |
93 | ui->pushButton_9->setEnabled(false); |
||
94 | ui->pushButton_10->setEnabled(false); |
||
95 | ui->pushButton_11->setEnabled(false); |
||
96 | ui->pushButton_12->setEnabled(false); |
||
97 | |||
132 | pingvin | 98 | // setFrm.show(); |
119 | pingvin | 99 | |
212 | pingvin | 100 | // treeForm.show(); |
101 | |||
132 | pingvin | 102 | connect(ui->getsettingAct, SIGNAL(triggered()), this, SLOT(getSetting())); // " " " " |
103 | connect(setFrm.pushButton, SIGNAL(clicked()), this, SLOT(applySetting())); |
||
104 | |||
158 | pingvin | 105 | // connect(ui->tableView_2,SIGNAL(activated(QModelIndex)),ui->tableView_2,SLOT(edit(QModelIndex))); |
132 | pingvin | 106 | |
158 | pingvin | 107 | picture_delegate = new CPictureDelegate(this); |
189 | pingvin | 108 | iconDelegate = new IconDelegate(this); |
201 | pingvin | 109 | fileDelegate = new FileDelegate(this); |
158 | pingvin | 110 | |
200 | pingvin | 111 | // fileForm.show(); |
196 | pingvin | 112 | |
88 | pingvin | 113 | } |
114 | |||
115 | MainWindow::~MainWindow() |
||
116 | { |
||
117 | pingvin | 117 | delete sql_mogel; |
221 | pingvin | 118 | delete filter_model; |
88 | pingvin | 119 | delete ui; |
149 | pingvin | 120 | delete model_for_ListModelsTable; |
88 | pingvin | 121 | } |
122 | |||
123 | void MainWindow::changeEvent(QEvent *e) |
||
124 | { |
||
125 | QMainWindow::changeEvent(e); |
||
126 | switch (e->type()) { |
||
127 | case QEvent::LanguageChange: |
||
128 | ui->retranslateUi(this); |
||
129 | break; |
||
130 | default: |
||
131 | break; |
||
132 | } |
||
133 | } |
||
89 | pingvin | 134 | |
135 | |||
136 | bool MainWindow::readModel(){ |
||
137 | bool result; |
||
138 | QString model_str; |
||
140 | pingvin | 139 | QFile file("modelstring.txt"); |
141 | pingvin | 140 | // QFile file("model.txt"); |
91 | pingvin | 141 | rootItem1 = new QTreeWidgetItem(ui->treeWidget); |
89 | pingvin | 142 | rootItem1->setText(0, tr(" 1")); |
143 | // rootItem2 = new QTreeWidgetItem(rootItem1); |
||
144 | // rootItem2->setText(0, tr(" 2")); |
||
145 | rootItem1->setCheckState(0,Qt::Checked); |
||
146 | // rootItem2->setCheckState(0,Qt::Checked); |
||
147 | |||
148 | |||
149 | |||
150 | result = file.open(QIODevice::ReadOnly); |
||
151 | if (result) { |
||
90 | pingvin | 152 | model_str = QString(tr(file.readAll())); |
89 | pingvin | 153 | } |
154 | |||
215 | pingvin | 155 | setupModelData(model_str.split(QString("\n")), rootItem1, -1, tr("1")); |
89 | pingvin | 156 | |
157 | |||
158 | return result; |
||
159 | |||
160 | } |
||
161 | |||
162 | |||
215 | pingvin | 163 | void MainWindow::setupModelData(const QStringList &lines, QTreeWidgetItem *parent, int row, QString model_id) |
89 | pingvin | 164 | { |
165 | QList<QTreeWidgetItem*> parents; |
||
166 | QList<int> indentations; |
||
167 | parents << parent; |
||
168 | indentations << 0; |
||
169 | |||
170 | int number = 0; |
||
171 | |||
172 | while (number < lines.count()) { |
||
173 | int position = 0; |
||
174 | while (position < lines[number].length()) { |
||
175 | if (lines[number].mid(position, 1) != " ") |
||
176 | break; |
||
177 | position++; |
||
178 | } |
||
179 | |||
180 | QString lineData = lines[number].mid(position).trimmed(); |
||
181 | |||
182 | if (!lineData.isEmpty()) { |
||
183 | // Read the column data from the rest of the line. |
||
184 | QStringList columnStrings = lineData.split("\t", QString::SkipEmptyParts); |
||
185 | QList<QVariant> columnData; |
||
186 | for (int column = 0; column < columnStrings.count(); ++column) |
||
187 | columnData << columnStrings[column]; |
||
188 | |||
189 | if (position > indentations.last()) { |
||
190 | // The last child of the current parent is now the new parent |
||
191 | // unless the current parent has no children. |
||
192 | |||
193 | if (parents.last()->childCount() > 0) { |
||
194 | parents << parents.last()->child(parents.last()->childCount()-1); |
||
195 | indentations << position; |
||
196 | } |
||
197 | } else { |
||
198 | while (position < indentations.last() && parents.count() > 0) { |
||
199 | parents.pop_back(); |
||
200 | indentations.pop_back(); |
||
201 | } |
||
202 | } |
||
203 | |||
204 | // Append a new item to the current parent's list of children. |
||
205 | // // // parents.last()->appendChild(new QTreeWidgetItem(columnData, parents.last())); |
||
206 | QTreeWidgetItem* itm_tmp; |
||
207 | itm_tmp = new QTreeWidgetItem( parents.last()); |
||
215 | pingvin | 208 | // itm_tmp->setFlags(Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsEnabled); |
89 | pingvin | 209 | |
209 | pingvin | 210 | /* |
211 | QLineEdit * edit_line; |
||
212 | edit_line = new QLineEdit(this); |
||
213 | ui->treeWidget->setItemWidget(itm_tmp, 5, edit_line); |
||
214 | */ |
||
215 | //static QStandartDelegate delegate; |
||
216 | ui->treeWidget->setItemDelegateForColumn(5, &standart_delegate); |
||
217 | |||
218 | |||
89 | pingvin | 219 | itm_tmp->setText(0, QString(columnData.at(0).toString())); |
220 | if (columnData.at(1).toString() == "true") { |
||
221 | itm_tmp->setCheckState(0,Qt::Checked); |
||
222 | } |
||
223 | else itm_tmp->setCheckState(0,Qt::Unchecked); |
||
141 | pingvin | 224 | if (columnData.count()>2) |
225 | { |
||
173 | pingvin | 226 | QString class_id; |
174 | pingvin | 227 | QPixmap pxmp; |
228 | QIcon icon; |
||
173 | pingvin | 229 | class_id = QString(columnData.at(2).toString()); |
174 | pingvin | 230 | pxmp = MainWindow::classesIcons.value(class_id); |
231 | |||
173 | pingvin | 232 | // itm_tmp->setText(1, QString(columnData.at(2).toString())); // id |
233 | itm_tmp->setText(1, class_id); // id |
||
215 | pingvin | 234 | itm_tmp->setText(6, model_id); // id |
90 | pingvin | 235 | itm_tmp->setText(2, QVariant(number).toString()); // - |
173 | pingvin | 236 | itm_tmp->setText(3, QVariant(indentations.size()).toString()); // |
237 | itm_tmp->setText(4, QVariant(row).toString()); // |
||
174 | pingvin | 238 | |
215 | pingvin | 239 | |
174 | pingvin | 240 | if (!pxmp.isNull()) |
241 | { |
||
242 | icon.addPixmap(pxmp); |
||
175 | pingvin | 243 | itm_tmp->setIcon(0, icon); |
174 | pingvin | 244 | } |
141 | pingvin | 245 | } |
89 | pingvin | 246 | } |
247 | |||
248 | number++; |
||
249 | } |
||
250 | } |
||
251 | |||
252 | |||
253 | /* |
||
254 | void MainWindow::openBase() |
||
255 | { |
||
256 | |||
257 | db = QSqlDatabase::addDatabase("QMYSQL"); |
||
258 | pdb = &db; |
||
259 | raportFrm.pdb = &db; |
||
260 | |||
261 | pdb->setHostName(hostName); |
||
262 | pdb->setDatabaseName(baseName); |
||
263 | pdb->setUserName(userName); |
||
264 | pdb->setPassword(password); |
||
265 | bool ok = pdb->open(); |
||
266 | if (!ok) { |
||
267 | QMessageBox::critical( // . |
||
268 | this, // . |
||
269 | QObject::tr("Database Error"), // . |
||
270 | pdb->lastError().text()); // . |
||
271 | } |
||
272 | if (ok) |
||
273 | {lineEdit-> insert(tr(" ")); |
||
274 | } |
||
275 | else {lineEdit-> insert(tr(" . : ")); |
||
276 | lineEdit-> insert(pdb->lastError().text()); |
||
277 | } |
||
278 | |||
279 | |||
280 | |||
281 | model = new QSqlTableModel(this); |
||
282 | model->setTable(tableName); |
||
283 | |||
284 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
285 | model->setSort(0, Qt::AscendingOrder); |
||
286 | |||
287 | model->select(); |
||
288 | |||
289 | |||
290 | QSqlField field(tr("age"), QVariant::Int); |
||
291 | field.setValue(QString(tr("123"))); |
||
292 | |||
293 | bool okey; |
||
294 | int index; |
||
295 | QSqlRecord record; |
||
296 | |||
297 | |||
298 | tableView->setModel(model); |
||
299 | view.setModel(model); |
||
300 | |||
301 | |||
302 | tableView->setAlternatingRowColors(true); |
||
303 | view.setAlternatingRowColors(true); |
||
304 | |||
305 | tableView->resizeColumnsToContents(); |
||
306 | |||
307 | |||
308 | view.resizeColumnsToContents(); |
||
309 | |||
310 | tableView->show(); |
||
311 | |||
312 | |||
313 | |||
314 | initTreeWidget(); |
||
315 | } |
||
316 | */ |
||
91 | pingvin | 317 | |
318 | |||
146 | pingvin | 319 | QString MainWindow::creatModelString(QTreeWidgetItem* model){ |
91 | pingvin | 320 | |
321 | MainWindow::modelString.clear(); // |
||
322 | // for (int i =0; i < rootItem1->childCount(); ++i ) |
||
323 | |||
146 | pingvin | 324 | {MainWindow::addChildsString(model, 0);} |
325 | |||
326 | return MainWindow::modelString; |
||
145 | pingvin | 327 | // {MainWindow::addChildsString(ui->treeWidget, 0);} |
328 | /* |
||
91 | pingvin | 329 | int root_item_child_count; |
330 | int i; |
||
331 | root_item_child_count = rootItem1->childCount(); |
||
332 | i++; |
||
145 | pingvin | 333 | */ |
91 | pingvin | 334 | } |
335 | |||
336 | |||
337 | void MainWindow::addChildsString(QTreeWidgetItem *parentItem, int level){ |
||
338 | int child_count; |
||
339 | child_count = parentItem->childCount(); |
||
340 | for (int i=0; i < child_count; ++i){ |
||
341 | for (int m=0; m < level; ++m){ |
||
342 | modelString.append(tr(" ")); // - , |
||
343 | } |
||
344 | modelString.append(parentItem->child(i)->text(0)); // - |
||
345 | modelString.append(tr("\t\t\t\t")); // - |
||
346 | if (parentItem->child(i)->checkState(0) == Qt::Checked) {modelString.append(tr("true"));} // , "true", |
||
347 | else {modelString.append(tr("false"));} // - "false", |
||
348 | modelString.append(tr("\t\t\t\t")); // - |
||
349 | modelString.append(parentItem->child(i)->text(1)); // - ID |
||
350 | modelString.append(tr("\n")); // |
||
351 | if (parentItem->child(i)->childCount() > 0) { MainWindow::addChildsString(parentItem->child(i), level+1);} |
||
352 | |||
353 | } |
||
354 | int i; |
||
355 | i++; |
||
356 | } |
||
93 | pingvin | 357 | |
358 | |||
359 | bool MainWindow::openDataBase(){ |
||
360 | QString errorString; |
||
361 | sql = QSqlDatabase::addDatabase("QMYSQL"); |
||
131 | pingvin | 362 | // sql.setDatabaseName(tr("an_db")); |
363 | |||
132 | pingvin | 364 | // // // sql.setDatabaseName(tr("inventory")); |
131 | pingvin | 365 | |
132 | pingvin | 366 | sql.setDatabaseName(baseName); |
131 | pingvin | 367 | |
368 | |||
369 | |||
132 | pingvin | 370 | // // // sql.setHostName(tr("localhost")); |
93 | pingvin | 371 | |
132 | pingvin | 372 | sql.setHostName(hostName); |
373 | |||
374 | |||
375 | // // // sql.setUserName(tr("an")); |
||
376 | |||
377 | sql.setUserName(userName); |
||
378 | |||
379 | |||
380 | |||
381 | // // // sql.setPassword(tr("393939")); |
||
382 | |||
383 | |||
384 | sql.setPassword(password); |
||
385 | |||
386 | |||
387 | |||
93 | pingvin | 388 | bool ok; |
389 | ok = sql.open(); |
||
390 | |||
391 | /* |
||
392 | if (!ok) { |
||
393 | QMessageBox::critical( // . |
||
394 | this, // . |
||
395 | QObject::tr("Database Error"), // . |
||
396 | sql.lastError().text() ); // . |
||
397 | |||
398 | |||
399 | } |
||
400 | |||
401 | */ |
||
402 | if (!ok) { |
||
403 | QMessageBox::critical( // . |
||
404 | this, // . |
||
405 | QObject::tr("Database Error"), // . |
||
406 | sql.lastError().text()); // . |
||
407 | } |
||
408 | else { |
||
409 | |||
410 | QMessageBox::information( // . |
||
411 | this, // . |
||
412 | QObject::tr("Database Connect"), // . |
||
413 | QObject::tr(" .")); // . |
||
414 | |||
415 | |||
416 | |||
417 | |||
418 | |||
419 | } |
||
420 | |||
421 | return ok; |
||
422 | } |
||
94 | pingvin | 423 | |
424 | |||
97 | pingvin | 425 | bool MainWindow::buildPreviewModel(QString modelName, QString rootClassID){ |
94 | pingvin | 426 | QSqlQuery q; |
427 | QString sql_str; |
||
95 | pingvin | 428 | QString field_name_str; |
429 | QString root_class_name; |
||
192 | pingvin | 430 | //bool ok; |
431 | //int field_name; |
||
95 | pingvin | 432 | |
433 | //ui->treeWidget->clear(); |
||
434 | |||
435 | root_class_name = MainWindow::ClassName(rootClassID); // |
||
436 | |||
145 | pingvin | 437 | |
95 | pingvin | 438 | rootItem1 = new QTreeWidgetItem(ui->treeWidget); |
145 | pingvin | 439 | root_items_list << rootItem1; |
97 | pingvin | 440 | rootItem1->setText(0, modelName); |
441 | |||
95 | pingvin | 442 | rootItem1->setCheckState(0,Qt::Checked); |
104 | pingvin | 443 | rootItems.append(rootItem1); |
95 | pingvin | 444 | |
445 | |||
104 | pingvin | 446 | |
145 | pingvin | 447 | rootItem2 = new QTreeWidgetItem(rootItem1); |
448 | rootItem2->setText(0, root_class_name); |
||
449 | rootItem2->setText(1, rootClassID); |
||
450 | rootItem2->setCheckState(0,Qt::Checked); |
||
95 | pingvin | 451 | |
147 | pingvin | 452 | addChildsItems(rootItem2, -1); |
95 | pingvin | 453 | |
145 | pingvin | 454 | |
455 | /* |
||
456 | |||
94 | pingvin | 457 | sql_str = tr("select * " |
95 | pingvin | 458 | " from DescriptionOfClasses where DescriptionOfClasses.DefaultValue = '" // , |
94 | pingvin | 459 | ); |
460 | sql_str.append(rootClassID); |
||
461 | |||
95 | pingvin | 462 | sql_str.append(tr("' and DescriptionOfClasses.FieldType = 'pointer' ")); |
94 | pingvin | 463 | |
95 | pingvin | 464 | q.prepare(sql_str); |
465 | |||
466 | ok = q.exec(); |
||
467 | if (!ok) { |
||
468 | QMessageBox::critical( // . |
||
469 | this, // . |
||
470 | QObject::tr("Database Error"), // . |
||
471 | q.lastError().text()); // . |
||
472 | } |
||
473 | field_name = q.record().indexOf(tr("FieldName")); |
||
474 | while(q.next()){ |
||
475 | |||
476 | field_name_str = q.value(field_name).toString(); |
||
477 | |||
478 | } |
||
479 | |||
100 | pingvin | 480 | |
481 | |||
482 | |||
145 | pingvin | 483 | */ |
484 | |||
485 | |||
94 | pingvin | 486 | } |
95 | pingvin | 487 | |
488 | |||
147 | pingvin | 489 | bool MainWindow::rebuildPreviewModel(QTreeWidgetItem* root_item, QString rootClassID, int row){ |
107 | pingvin | 490 | QSqlQuery q; |
491 | QString sql_str; |
||
492 | QString field_name_str; |
||
493 | QString root_class_name; |
||
192 | pingvin | 494 | //bool ok; |
495 | //int field_name; |
||
95 | pingvin | 496 | |
107 | pingvin | 497 | //ui->treeWidget->clear(); |
498 | |||
499 | root_class_name = MainWindow::ClassName(rootClassID); // |
||
500 | |||
501 | |||
502 | // rootItem1 = new QTreeWidgetItem(ui->treeWidget); |
||
503 | // root_items_list << rootItem1; |
||
504 | // rootItem1->setText(0, modelName); |
||
505 | |||
506 | // rootItem1->setCheckState(0,Qt::Checked); |
||
507 | // rootItems.append(rootItem1); |
||
508 | |||
509 | // root_item->removeChild(root_item->child(0)); // |
||
145 | pingvin | 510 | if (root_item->childCount()==0){ // , |
511 | QTreeWidgetItem* item_tmp; |
||
512 | item_tmp = new QTreeWidgetItem (root_item); |
||
147 | pingvin | 513 | item_tmp->setText(4, QVariant(row).toString()); |
145 | pingvin | 514 | |
515 | } |
||
516 | |||
517 | if (root_item->childCount()==1){ // , |
||
107 | pingvin | 518 | root_item->child(0)->setText(0, root_class_name); |
519 | root_item->child(0)->setText(1, rootClassID); |
||
147 | pingvin | 520 | root_item->child(0)->setCheckState(0,Qt::Checked); |
521 | root_item->setText(4, QVariant(row).toString()); |
||
107 | pingvin | 522 | |
147 | pingvin | 523 | } |
145 | pingvin | 524 | |
525 | |||
147 | pingvin | 526 | |
107 | pingvin | 527 | //delete rootItem2; |
528 | |||
529 | |||
530 | // rootItem2 = new QTreeWidgetItem(rootItem1); |
||
531 | |||
532 | |||
533 | |||
534 | // rootItem2->setText(0, root_class_name); |
||
535 | // rootItem2->setText(1, rootClassID); |
||
536 | // rootItem2->setCheckState(0,Qt::Checked); |
||
537 | |||
538 | int child_count = root_item->child(0)->childCount(); |
||
539 | |||
540 | |||
145 | pingvin | 541 | for (int i=0; i < child_count; i++){ // , |
107 | pingvin | 542 | root_item->child(0)->removeChild(root_item->child(0)->child(0)); |
543 | } |
||
544 | |||
545 | child_count = root_item->child(0)->childCount(); |
||
147 | pingvin | 546 | addChildsItems(root_item->child(0), row); |
107 | pingvin | 547 | /* |
548 | sql_str = tr("select * " |
||
549 | " from DescriptionOfClasses where DescriptionOfClasses.DefaultValue = '" // , |
||
550 | ); |
||
551 | sql_str.append(rootClassID); |
||
552 | |||
553 | sql_str.append(tr("' and DescriptionOfClasses.FieldType = 'pointer' ")); |
||
554 | |||
555 | q.prepare(sql_str); |
||
556 | |||
557 | ok = q.exec(); |
||
558 | if (!ok) { |
||
559 | QMessageBox::critical( // . |
||
560 | this, // . |
||
561 | QObject::tr("Database Error"), // . |
||
562 | q.lastError().text()); // . |
||
563 | } |
||
564 | field_name = q.record().indexOf(tr("FieldName")); |
||
565 | while(q.next()){ |
||
566 | |||
567 | field_name_str = q.value(field_name).toString(); |
||
568 | |||
569 | } |
||
570 | |||
571 | */ |
||
572 | |||
573 | |||
574 | } |
||
575 | |||
576 | |||
577 | |||
578 | |||
95 | pingvin | 579 | QString MainWindow::ClassName(QString class_id){ // ID |
580 | QSqlQuery q; |
||
581 | QString sql_str; |
||
582 | QString class_name_str; |
||
583 | bool ok; |
||
584 | int field_class_name; |
||
585 | |||
586 | sql_str = tr("select * " |
||
587 | " from ListOfClasses where ListOfClasses.ID = '" // , |
||
588 | ); |
||
589 | |||
590 | sql_str.append(class_id); |
||
591 | sql_str.append(tr("' ")); |
||
592 | |||
593 | q.prepare(sql_str); |
||
594 | |||
595 | ok = q.exec(); |
||
596 | |||
597 | |||
598 | if (!ok) { |
||
599 | QMessageBox::critical( // . |
||
600 | this, // . |
||
601 | QObject::tr("Database Error"), // . |
||
602 | q.lastError().text()); // . |
||
603 | } |
||
604 | |||
605 | field_class_name = q.record().indexOf(tr("ClassName")); |
||
606 | while(q.next()){ |
||
607 | |||
608 | class_name_str = q.value(field_class_name).toString(); |
||
609 | |||
610 | } |
||
611 | |||
612 | return class_name_str; |
||
613 | |||
614 | } |
||
98 | pingvin | 615 | |
147 | pingvin | 616 | void MainWindow::addChildsItems(QTreeWidgetItem *perent_class_item, int row){ // , |
100 | pingvin | 617 | QStringList chields_list; |
618 | QString parent_ID; |
||
619 | QTreeWidgetItem *Item_tmp; |
||
620 | parent_ID = perent_class_item->text(1); |
||
621 | int chields_count, i; |
||
98 | pingvin | 622 | |
100 | pingvin | 623 | chields_list = MainWindow::classChields(parent_ID); |
624 | if(chields_list.isEmpty()) return; |
||
625 | chields_count = chields_list.size(); |
||
626 | for (int l = 0; l < chields_count; ++l){ |
||
627 | QString chield_class_name, chield_id; |
||
628 | chield_id = chields_list.at(l); |
||
629 | chield_class_name = MainWindow::ClassName(chield_id); |
||
630 | Item_tmp = new QTreeWidgetItem(perent_class_item); |
||
631 | Item_tmp->setText(0, chield_class_name); |
||
632 | Item_tmp->setText(1, chield_id); |
||
633 | Item_tmp->setCheckState(0, Qt::Checked); |
||
147 | pingvin | 634 | Item_tmp->setText(4, QVariant(row).toString()); |
635 | MainWindow::addChildsItems(Item_tmp, row); |
||
98 | pingvin | 636 | } |
637 | |||
100 | pingvin | 638 | i++; |
99 | pingvin | 639 | |
100 | pingvin | 640 | } |
641 | |||
642 | |||
99 | pingvin | 643 | /******************************************************** |
644 | * "" |
||
645 | * |
||
646 | * |
||
647 | * |
||
648 | ********************************************************/ |
||
649 | |||
650 | QStringList MainWindow::classChields(QString class_id){ |
||
651 | // QMap<QString, QString> map; |
||
652 | // TClass class_tmp; |
||
653 | // QList <TClass> chields_class_list; // |
||
654 | QStringList result; |
||
655 | QSqlQuery q; |
||
656 | QString sql_str; |
||
657 | QString classIdentifer_str; // - |
||
658 | QString field_id_str; |
||
659 | bool ok; |
||
660 | int field_classIdentifer; |
||
661 | sql_str = tr("select * " |
||
662 | " from DescriptionOfClasses where DescriptionOfClasses.DefaultValue = '" // , |
||
663 | ); |
||
664 | sql_str.append(class_id); |
||
665 | |||
666 | sql_str.append(tr("' and DescriptionOfClasses.FieldType = 'pointer' ")); |
||
667 | |||
668 | q.prepare(sql_str); |
||
669 | |||
670 | ok = q.exec(); |
||
671 | if (!ok) { |
||
672 | QMessageBox::critical( // . |
||
673 | this, // . |
||
674 | QObject::tr("Database Error"), // . |
||
675 | q.lastError().text()); // . |
||
676 | } |
||
677 | field_classIdentifer = q.record().indexOf(tr("ClassIdentifer")); |
||
678 | while(q.next()){ |
||
679 | |||
680 | classIdentifer_str = q.value(field_classIdentifer).toString(); |
||
681 | result.append(classIdentifer_str); |
||
682 | } |
||
683 | |||
684 | return result; |
||
685 | |||
686 | } |
||
102 | pingvin | 687 | |
688 | |||
689 | QMap <QString, QString> MainWindow::getClassList(){ // |
||
690 | QMap <QString, QString> result_map; |
||
691 | QSqlQuery q; |
||
692 | QString sql_str; |
||
103 | pingvin | 693 | QString class_name_str, class_id_str; |
694 | |||
102 | pingvin | 695 | int field_class_id, field_class_name; |
696 | bool ok; |
||
697 | sql_str = tr("select * " |
||
698 | " from ListOfClasses " // , |
||
699 | ); |
||
700 | q.prepare(sql_str); |
||
701 | ok = q.exec(); |
||
702 | if (!ok) { |
||
703 | QMessageBox::critical( // . |
||
704 | this, // . |
||
705 | QObject::tr("Database Error"), // . |
||
706 | q.lastError().text()); // . |
||
707 | return result_map; // - |
||
708 | } |
||
709 | field_class_id = q.record().indexOf(tr("ID")); |
||
710 | field_class_name = q.record().indexOf(tr("ClassName")); |
||
711 | |||
103 | pingvin | 712 | while(q.next()){ |
102 | pingvin | 713 | |
103 | pingvin | 714 | class_name_str = q.value(field_class_name).toString(); |
715 | class_id_str = q.value(field_class_id).toString(); |
||
716 | result_map[class_id_str] = class_name_str; |
||
717 | } |
||
102 | pingvin | 718 | return result_map; |
719 | } |
||
104 | pingvin | 720 | |
721 | |||
722 | |||
723 | |||
724 | |||
725 | void MainWindow::initComboBox(){ |
||
726 | |||
106 | pingvin | 727 | |
104 | pingvin | 728 | QStringList classesNameList; |
729 | QStringList classesID_list; |
||
730 | QStringList tmp_stringList; |
||
731 | |||
732 | |||
733 | |||
734 | QString tmp_str; |
||
735 | |||
736 | class_list_map = MainWindow::getClassList(); |
||
737 | classesID_list = class_list_map.keys(); |
||
738 | classesNameList = class_list_map.values(); |
||
739 | QMapIterator<QString, QString> interator(class_list_map); |
||
740 | // ui->comboBox->addItems(classesID_list); |
||
741 | // ui->comboBox->addItems(classesNameList); |
||
742 | while (interator.hasNext()) { |
||
743 | interator.next(); |
||
744 | tmp_str = interator.value(); |
||
745 | tmp_str.append(tr(" \t(ID=")); |
||
746 | tmp_str.append(interator.key()); |
||
747 | tmp_str.append(tr(")")); |
||
748 | tmp_stringList << tmp_str; |
||
749 | |||
750 | } |
||
132 | pingvin | 751 | // int count = ui->comboBox->count(); |
752 | |||
753 | ui->comboBox->clear(); |
||
104 | pingvin | 754 | ui->comboBox->addItems(tmp_stringList); |
755 | |||
756 | |||
757 | } |
||
105 | pingvin | 758 | |
759 | |||
106 | pingvin | 760 | void MainWindow::on_comboBox_currentIndexChanged( int index ){ |
761 | QStringList classesNameList; |
||
762 | QStringList classesID_list; |
||
763 | QString ID_str; |
||
132 | pingvin | 764 | if (index == -1) return; |
152 | pingvin | 765 | if (!comboBox_slot_enable) return; // , , |
147 | pingvin | 766 | int row; |
132 | pingvin | 767 | |
106 | pingvin | 768 | classesID_list = class_list_map.keys(); |
769 | classesNameList = class_list_map.values(); |
||
770 | ID_str = classesID_list[index]; |
||
771 | ui->label->setText(ID_str); |
||
145 | pingvin | 772 | if (root_items_list.indexOf(ui->treeWidget->currentItem()) != -1) |
773 | { |
||
147 | pingvin | 774 | row = QVariant(ui->treeWidget->currentItem()->text(4)).toInt(); |
145 | pingvin | 775 | model_is_build = false; // on_treeWidget_itemChanged |
147 | pingvin | 776 | rebuildPreviewModel(ui->treeWidget->currentItem(), ID_str, row); |
145 | pingvin | 777 | model_is_build = true; // |
147 | pingvin | 778 | QString mdl_str = MainWindow::creatModelString(ui->treeWidget->currentItem()); // |
779 | model_for_ListModelsTable->setData(model_for_ListModelsTable->index(row, 2), QVariant(mdl_str)); |
||
145 | pingvin | 780 | } |
781 | getDatabaseData(); |
||
107 | pingvin | 782 | |
783 | |||
105 | pingvin | 784 | } |
785 | |||
106 | pingvin | 786 | void MainWindow::on_treeWidget_itemChanged ( QTreeWidgetItem * item, int column ){ |
787 | int i; |
||
788 | i++; |
||
147 | pingvin | 789 | QTreeWidgetItem * item_tmp; |
790 | QString mdl_str; |
||
791 | QString row; // , |
||
148 | pingvin | 792 | QList <QTreeWidgetItem *> mdl_itm_list; |
147 | pingvin | 793 | QList <int> rows_list; |
106 | pingvin | 794 | |
147 | pingvin | 795 | |
796 | if ((column) == 0 && (model_is_build)) { |
||
797 | // if (!model_is_build) return; // |
||
148 | pingvin | 798 | |
799 | mdl_itm_list = models_items.values(); |
||
147 | pingvin | 800 | rows_list = models_items.keys(); |
148 | pingvin | 801 | row= item->text(4); |
147 | pingvin | 802 | |
148 | pingvin | 803 | |
804 | if ( mdl_itm_list.indexOf(item) != -1){ // ( ) |
||
805 | if (item->checkState(0)) model_for_ListModelsTable->setData(model_for_ListModelsTable->index(QVariant(row).toInt(), 3), QVariant(1)); |
||
806 | else model_for_ListModelsTable->setData(model_for_ListModelsTable->index(QVariant(row).toInt(), 3), QVariant(0)); |
||
807 | } |
||
808 | |||
809 | |||
810 | |||
811 | |||
147 | pingvin | 812 | if (!row.isEmpty()){ |
813 | |||
814 | |||
815 | int row_int; |
||
816 | row_int = QVariant(row).toInt(); |
||
817 | if (rows_list.indexOf(row_int) != -1) |
||
818 | { |
||
819 | item_tmp = models_items[row_int]; |
||
820 | mdl_str = MainWindow::creatModelString(item_tmp); |
||
821 | model_for_ListModelsTable->setData(model_for_ListModelsTable->index(row_int, 2), QVariant(mdl_str)); |
||
822 | } |
||
823 | |||
824 | |||
825 | } |
||
826 | |||
827 | |||
828 | } |
||
829 | |||
830 | /* |
||
831 | QTreeWidgetItem * item_tmp; |
||
832 | item_tmp = item; |
||
833 | while (item_tmp ){ |
||
834 | item_tmp = item_tmp->parent(); |
||
835 | } |
||
836 | */ |
||
118 | pingvin | 837 | if ((column) == 0 && (model_is_build)) getDatabaseData(); |
838 | |||
147 | pingvin | 839 | |
106 | pingvin | 840 | } |
841 | |||
842 | |||
843 | void MainWindow::on_treeWidget_itemClicked ( QTreeWidgetItem * item, int column ){ |
||
844 | int i; |
||
845 | i++; |
||
214 | pingvin | 846 | if (root_items_list.indexOf(item) != -1) { // |
108 | pingvin | 847 | QStringList classesNameList; |
848 | QStringList classesID_list; |
||
106 | pingvin | 849 | |
217 | pingvin | 850 | ui->pushButton_9->setEnabled(false); |
851 | ui->pushButton_10->setEnabled(false); |
||
852 | ui->pushButton_11->setEnabled(false); |
||
853 | ui->pushButton_12->setEnabled(false); |
||
854 | // ui->tableView->reset(); |
||
855 | // MainWindow::filtr_model->clear(); |
||
221 | pingvin | 856 | disconnect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
857 | delete filter_model; |
||
858 | filter_model = new QSqlTableModel(); |
||
859 | connect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
||
108 | pingvin | 860 | int index; |
861 | classesID_list = class_list_map.keys(); |
||
862 | classesNameList = class_list_map.values(); |
||
145 | pingvin | 863 | if (item->childCount()>0) index = classesID_list.indexOf(item->child(0)->text(1)); // , |
864 | else { // |
||
865 | ui->comboBox->setEnabled(true); |
||
206 | pingvin | 866 | comboBox_slot_enable = true; |
145 | pingvin | 867 | return; |
868 | |||
869 | } |
||
152 | pingvin | 870 | comboBox_slot_enable = false; // comboBox |
132 | pingvin | 871 | if (index != -1) ui->comboBox->setCurrentIndex(index); |
152 | pingvin | 872 | comboBox_slot_enable = true; |
108 | pingvin | 873 | ui->comboBox->setEnabled(true); |
874 | |||
875 | |||
876 | } |
||
106 | pingvin | 877 | // if ((rootItem1) == (item) ) ui->comboBox->setEnabled(true); |
214 | pingvin | 878 | else // |
879 | { |
||
215 | pingvin | 880 | QString class_id; |
881 | QString model_id; |
||
882 | QString filtr_str; |
||
221 | pingvin | 883 | QString inctance; |
219 | pingvin | 884 | QStringList conditionList; |
215 | pingvin | 885 | class_id = item->text(1); |
886 | model_id = item->text(6); |
||
221 | pingvin | 887 | inctance = MainWindow::getClassInctance(class_id); |
888 | |||
217 | pingvin | 889 | filtr_str = tr("`Model_ID` = "); |
215 | pingvin | 890 | filtr_str.append(model_id); |
217 | pingvin | 891 | filtr_str.append(tr(" AND `Class_ID` = ")); |
215 | pingvin | 892 | filtr_str.append(class_id); |
217 | pingvin | 893 | // filtr_str.append(tr("`")); |
215 | pingvin | 894 | |
221 | pingvin | 895 | disconnect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
896 | delete filter_model; |
||
219 | pingvin | 897 | // filtr_model = new MyModel(); |
215 | pingvin | 898 | |
221 | pingvin | 899 | filter_model = new QSqlTableModel(); |
900 | connect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
||
901 | filter_model->setTable(tr("Filters")); |
||
902 | filter_model->setFilter(filtr_str); |
||
903 | filter_model->select(); |
||
904 | ui->tableView_3->setModel(filter_model); |
||
215 | pingvin | 905 | |
219 | pingvin | 906 | |
907 | ui->tableView_3->hideColumn(0); |
||
908 | ui->tableView_3->hideColumn(1); |
||
909 | ui->tableView_3->hideColumn(2); |
||
910 | |||
911 | |||
912 | filterSpinDelegate.setClassID(class_id); |
||
913 | filterSpinDelegate.getItems(); |
||
914 | ui->tableView_3->setItemDelegateForColumn(4, &filterSpinDelegate); |
||
915 | |||
916 | |||
917 | conditionList <<"" << "and" << "or" << "(" << "and (" << "or ("; |
||
918 | filterConditionDelegate.setItems(conditionList); |
||
919 | ui->tableView_3->setItemDelegateForColumn(3, &filterConditionDelegate); |
||
920 | |||
921 | conditionList.clear(); |
||
922 | conditionList <<"" << "=" << "<" << ">" ; |
||
923 | filterConditionDelegate_1.setItems(conditionList); |
||
924 | ui->tableView_3->setItemDelegateForColumn(5, &filterConditionDelegate_1); |
||
925 | |||
926 | |||
927 | |||
217 | pingvin | 928 | ui->pushButton_9->setEnabled(true); |
929 | ui->pushButton_10->setEnabled(true); |
||
930 | |||
215 | pingvin | 931 | ui->comboBox->setEnabled(false); |
932 | |||
933 | |||
214 | pingvin | 934 | } |
106 | pingvin | 935 | } |
110 | pingvin | 936 | |
125 | pingvin | 937 | QMap <QString, QString> MainWindow::getFieldsList(QString class_id){ // |
110 | pingvin | 938 | |
125 | pingvin | 939 | } |
142 | pingvin | 940 | |
941 | |||
942 | void MainWindow::initListModelsTablle(){ |
||
149 | pingvin | 943 | model_for_ListModelsTable = new QSqlTableModel(); |
142 | pingvin | 944 | |
945 | model_for_ListModelsTable->setTable(tr("ListOfModels")); |
||
146 | pingvin | 946 | // model_for_ListModelsTable->setEditStrategy(QSqlTableModel::OnFieldChange); |
947 | model_for_ListModelsTable->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
142 | pingvin | 948 | ui->tableView_2->setModel(model_for_ListModelsTable); |
151 | pingvin | 949 | |
142 | pingvin | 950 | model_for_ListModelsTable->select(); |
151 | pingvin | 951 | |
215 | pingvin | 952 | |
151 | pingvin | 953 | ui->treeWidget->hideColumn(1); |
954 | ui->treeWidget->hideColumn(2); |
||
955 | ui->treeWidget->hideColumn(3); |
||
956 | ui->treeWidget->hideColumn(4); |
||
221 | pingvin | 957 | // ui->treeWidget->hideColumn(5); |
215 | pingvin | 958 | ui->treeWidget->hideColumn(6); |
151 | pingvin | 959 | |
960 | ui->tableView_2->hideColumn(0); |
||
961 | ui->tableView_2->hideColumn(2); |
||
962 | ui->tableView_2->hideColumn(3); |
||
963 | ui->tableView_2->hideColumn(4); |
||
964 | |||
965 | ui->tableView_2->resizeColumnsToContents(); |
||
966 | ui->tableView_2->setAlternatingRowColors(true); |
||
967 | |||
146 | pingvin | 968 | ui->pushButton_7->setEnabled(false); |
969 | ui->pushButton_8->setEnabled(false); |
||
151 | pingvin | 970 | |
971 | |||
142 | pingvin | 972 | } |