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