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