Редакция 237 | Редакция 241 | К новейшей редакции | Содержимое файла | Сравнить с предыдущей | Последнее изменение | Открыть журнал | 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); |
||
233 | pingvin | 19 | ui->tab_3->setLayout(ui->horizontalLayout_7); |
237 | pingvin | 20 | ui->tab_4->setLayout(ui->horizontalLayout_8); |
106 | pingvin | 21 | // connect( ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(on_currentIndexChanged(int))); |
118 | pingvin | 22 | model_is_build = false; |
145 | pingvin | 23 | // MainWindow::readModel(); |
89 | pingvin | 24 | |
91 | pingvin | 25 | //QString model_str; |
140 | pingvin | 26 | |
27 | |||
28 | /* |
||
91 | pingvin | 29 | MainWindow::creatModelString(); |
30 | int i; |
||
31 | i++; |
||
93 | pingvin | 32 | QFile file_tmp("./temp.txt"); |
92 | pingvin | 33 | bool ok; |
34 | ok = file_tmp.open(QIODevice::ReadWrite | QIODevice::Text); |
||
35 | QTextStream out(&file_tmp); |
||
36 | out << MainWindow::modelString; |
||
37 | file_tmp.close(); |
||
140 | pingvin | 38 | */ |
174 | pingvin | 39 | |
40 | |||
41 | |||
42 | |||
114 | pingvin | 43 | ui->treeWidget->setAlternatingRowColors(true); |
44 | ui->treeWidget_2->setAlternatingRowColors(true); |
||
132 | pingvin | 45 | |
177 | pingvin | 46 | ui->treeWidget->setIconSize(QSize(30,30)); |
209 | pingvin | 47 | ui->treeWidget->setColumnWidth(0, 400); |
193 | pingvin | 48 | ui->treeWidget_2->setIconSize(QSize(128,128)); |
132 | pingvin | 49 | |
50 | MainWindow::readSettings(); |
||
51 | |||
93 | pingvin | 52 | MainWindow::openDataBase(); |
136 | pingvin | 53 | |
174 | pingvin | 54 | classesIcons = MainWindow::getClassesIcons(); // |
55 | |||
104 | pingvin | 56 | MainWindow::initComboBox(); |
136 | pingvin | 57 | |
145 | pingvin | 58 | // MainWindow::buildPreviewModel(tr(" "), tr("11")); |
136 | pingvin | 59 | |
142 | pingvin | 60 | MainWindow::initListModelsTablle(); |
140 | pingvin | 61 | |
144 | pingvin | 62 | MainWindow::readModels(); |
63 | |||
145 | pingvin | 64 | // MainWindow::creatModelString(); |
140 | pingvin | 65 | //int i; |
66 | //i++; |
||
145 | pingvin | 67 | |
68 | /* |
||
69 | QFile file_tmp("./modelstring.txt"); |
||
140 | pingvin | 70 | bool ok; |
71 | file_tmp.remove(); |
||
72 | ok = file_tmp.open(QIODevice::ReadWrite | QIODevice::Text); |
||
73 | QTextStream out(&file_tmp); |
||
74 | out.setCodec("cp1251"); |
||
75 | out << MainWindow::modelString; |
||
76 | file_tmp.close(); |
||
145 | pingvin | 77 | */ |
140 | pingvin | 78 | |
79 | |||
151 | pingvin | 80 | ui->treeWidget_2->hideColumn(1); |
81 | ui->treeWidget_2->hideColumn(2); |
||
82 | ui->treeWidget_2->hideColumn(3); |
||
83 | ui->treeWidget_2->hideColumn(4); |
||
235 | pingvin | 84 | ui->treeWidget_2->hideColumn(5); |
140 | pingvin | 85 | |
151 | pingvin | 86 | |
109 | pingvin | 87 | getDatabaseData(); |
127 | pingvin | 88 | //// sql_mogel = new QSqlTableModel(); |
89 | sql_mogel = new MyModel(); |
||
90 | |||
223 | pingvin | 91 | /// filter_model = new MyModel(); |
92 | filter_model = new QSqlTableModel(); |
||
227 | pingvin | 93 | filter_model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
127 | pingvin | 94 | |
118 | pingvin | 95 | model_is_build = true; |
119 | pingvin | 96 | connect(sql_mogel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_sql_mogel_dataChanged(QModelIndex,QModelIndex))); |
146 | pingvin | 97 | connect(model_for_ListModelsTable, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_model_for_ListModelsTable_dataChanged(QModelIndex,QModelIndex))); |
221 | pingvin | 98 | connect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
238 | pingvin | 99 | connect(&wmiProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readStandartProcessOutput())); |
146 | pingvin | 100 | |
221 | pingvin | 101 | |
238 | pingvin | 102 | |
119 | pingvin | 103 | ui->pushButton_3->setEnabled(false); |
104 | ui->pushButton_4->setEnabled(false); |
||
105 | |||
217 | pingvin | 106 | |
107 | ui->pushButton_9->setEnabled(false); |
||
108 | ui->pushButton_10->setEnabled(false); |
||
109 | ui->pushButton_11->setEnabled(false); |
||
110 | ui->pushButton_12->setEnabled(false); |
||
111 | |||
132 | pingvin | 112 | // setFrm.show(); |
119 | pingvin | 113 | |
212 | pingvin | 114 | // treeForm.show(); |
115 | |||
132 | pingvin | 116 | connect(ui->getsettingAct, SIGNAL(triggered()), this, SLOT(getSetting())); // " " " " |
117 | connect(setFrm.pushButton, SIGNAL(clicked()), this, SLOT(applySetting())); |
||
118 | |||
158 | pingvin | 119 | // connect(ui->tableView_2,SIGNAL(activated(QModelIndex)),ui->tableView_2,SLOT(edit(QModelIndex))); |
132 | pingvin | 120 | |
158 | pingvin | 121 | picture_delegate = new CPictureDelegate(this); |
189 | pingvin | 122 | iconDelegate = new IconDelegate(this); |
201 | pingvin | 123 | fileDelegate = new FileDelegate(this); |
158 | pingvin | 124 | |
200 | pingvin | 125 | // fileForm.show(); |
196 | pingvin | 126 | |
233 | pingvin | 127 | doc = ui->textEdit->document(); |
128 | cursor = new QTextCursor(doc); |
||
129 | // buildReport(true); |
||
228 | pingvin | 130 | |
131 | |||
88 | pingvin | 132 | } |
133 | |||
134 | MainWindow::~MainWindow() |
||
135 | { |
||
117 | pingvin | 136 | delete sql_mogel; |
221 | pingvin | 137 | delete filter_model; |
88 | pingvin | 138 | delete ui; |
149 | pingvin | 139 | delete model_for_ListModelsTable; |
88 | pingvin | 140 | } |
141 | |||
142 | void MainWindow::changeEvent(QEvent *e) |
||
143 | { |
||
144 | QMainWindow::changeEvent(e); |
||
145 | switch (e->type()) { |
||
146 | case QEvent::LanguageChange: |
||
147 | ui->retranslateUi(this); |
||
148 | break; |
||
149 | default: |
||
150 | break; |
||
151 | } |
||
152 | } |
||
89 | pingvin | 153 | |
154 | |||
155 | bool MainWindow::readModel(){ |
||
156 | bool result; |
||
157 | QString model_str; |
||
140 | pingvin | 158 | QFile file("modelstring.txt"); |
141 | pingvin | 159 | // QFile file("model.txt"); |
91 | pingvin | 160 | rootItem1 = new QTreeWidgetItem(ui->treeWidget); |
89 | pingvin | 161 | rootItem1->setText(0, tr(" 1")); |
162 | // rootItem2 = new QTreeWidgetItem(rootItem1); |
||
163 | // rootItem2->setText(0, tr(" 2")); |
||
164 | rootItem1->setCheckState(0,Qt::Checked); |
||
165 | // rootItem2->setCheckState(0,Qt::Checked); |
||
166 | |||
167 | |||
168 | |||
169 | result = file.open(QIODevice::ReadOnly); |
||
170 | if (result) { |
||
90 | pingvin | 171 | model_str = QString(tr(file.readAll())); |
89 | pingvin | 172 | } |
173 | |||
215 | pingvin | 174 | setupModelData(model_str.split(QString("\n")), rootItem1, -1, tr("1")); |
89 | pingvin | 175 | |
176 | |||
177 | return result; |
||
178 | |||
179 | } |
||
180 | |||
181 | |||
215 | pingvin | 182 | void MainWindow::setupModelData(const QStringList &lines, QTreeWidgetItem *parent, int row, QString model_id) |
89 | pingvin | 183 | { |
184 | QList<QTreeWidgetItem*> parents; |
||
185 | QList<int> indentations; |
||
186 | parents << parent; |
||
187 | indentations << 0; |
||
188 | |||
189 | int number = 0; |
||
190 | |||
191 | while (number < lines.count()) { |
||
192 | int position = 0; |
||
193 | while (position < lines[number].length()) { |
||
194 | if (lines[number].mid(position, 1) != " ") |
||
195 | break; |
||
196 | position++; |
||
197 | } |
||
198 | |||
199 | QString lineData = lines[number].mid(position).trimmed(); |
||
200 | |||
201 | if (!lineData.isEmpty()) { |
||
202 | // Read the column data from the rest of the line. |
||
203 | QStringList columnStrings = lineData.split("\t", QString::SkipEmptyParts); |
||
204 | QList<QVariant> columnData; |
||
205 | for (int column = 0; column < columnStrings.count(); ++column) |
||
206 | columnData << columnStrings[column]; |
||
207 | |||
208 | if (position > indentations.last()) { |
||
209 | // The last child of the current parent is now the new parent |
||
210 | // unless the current parent has no children. |
||
211 | |||
212 | if (parents.last()->childCount() > 0) { |
||
213 | parents << parents.last()->child(parents.last()->childCount()-1); |
||
214 | indentations << position; |
||
215 | } |
||
216 | } else { |
||
217 | while (position < indentations.last() && parents.count() > 0) { |
||
218 | parents.pop_back(); |
||
219 | indentations.pop_back(); |
||
220 | } |
||
221 | } |
||
222 | |||
223 | // Append a new item to the current parent's list of children. |
||
224 | // // // parents.last()->appendChild(new QTreeWidgetItem(columnData, parents.last())); |
||
225 | QTreeWidgetItem* itm_tmp; |
||
226 | itm_tmp = new QTreeWidgetItem( parents.last()); |
||
215 | pingvin | 227 | // itm_tmp->setFlags(Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsEnabled); |
89 | pingvin | 228 | |
209 | pingvin | 229 | /* |
230 | QLineEdit * edit_line; |
||
231 | edit_line = new QLineEdit(this); |
||
232 | ui->treeWidget->setItemWidget(itm_tmp, 5, edit_line); |
||
233 | */ |
||
234 | //static QStandartDelegate delegate; |
||
235 | ui->treeWidget->setItemDelegateForColumn(5, &standart_delegate); |
||
236 | |||
237 | |||
89 | pingvin | 238 | itm_tmp->setText(0, QString(columnData.at(0).toString())); |
239 | if (columnData.at(1).toString() == "true") { |
||
240 | itm_tmp->setCheckState(0,Qt::Checked); |
||
241 | } |
||
242 | else itm_tmp->setCheckState(0,Qt::Unchecked); |
||
141 | pingvin | 243 | if (columnData.count()>2) |
244 | { |
||
173 | pingvin | 245 | QString class_id; |
222 | pingvin | 246 | QString filtr_str; |
174 | pingvin | 247 | QPixmap pxmp; |
248 | QIcon icon; |
||
173 | pingvin | 249 | class_id = QString(columnData.at(2).toString()); |
174 | pingvin | 250 | pxmp = MainWindow::classesIcons.value(class_id); |
251 | |||
173 | pingvin | 252 | // itm_tmp->setText(1, QString(columnData.at(2).toString())); // id |
253 | itm_tmp->setText(1, class_id); // id |
||
215 | pingvin | 254 | itm_tmp->setText(6, model_id); // id |
90 | pingvin | 255 | itm_tmp->setText(2, QVariant(number).toString()); // - |
173 | pingvin | 256 | itm_tmp->setText(3, QVariant(indentations.size()).toString()); // |
257 | itm_tmp->setText(4, QVariant(row).toString()); // |
||
222 | pingvin | 258 | filtr_str = getFiltrString(model_id,class_id); |
259 | itm_tmp->setText(5,filtr_str); |
||
174 | pingvin | 260 | |
261 | if (!pxmp.isNull()) |
||
262 | { |
||
263 | icon.addPixmap(pxmp); |
||
175 | pingvin | 264 | itm_tmp->setIcon(0, icon); |
174 | pingvin | 265 | } |
141 | pingvin | 266 | } |
89 | pingvin | 267 | } |
268 | |||
269 | number++; |
||
270 | } |
||
271 | } |
||
272 | |||
273 | |||
274 | /* |
||
275 | void MainWindow::openBase() |
||
276 | { |
||
277 | |||
278 | db = QSqlDatabase::addDatabase("QMYSQL"); |
||
279 | pdb = &db; |
||
280 | raportFrm.pdb = &db; |
||
281 | |||
282 | pdb->setHostName(hostName); |
||
283 | pdb->setDatabaseName(baseName); |
||
284 | pdb->setUserName(userName); |
||
285 | pdb->setPassword(password); |
||
286 | bool ok = pdb->open(); |
||
287 | if (!ok) { |
||
288 | QMessageBox::critical( // . |
||
289 | this, // . |
||
290 | QObject::tr("Database Error"), // . |
||
291 | pdb->lastError().text()); // . |
||
292 | } |
||
293 | if (ok) |
||
294 | {lineEdit-> insert(tr(" ")); |
||
295 | } |
||
296 | else {lineEdit-> insert(tr(" . : ")); |
||
297 | lineEdit-> insert(pdb->lastError().text()); |
||
298 | } |
||
299 | |||
300 | |||
301 | |||
302 | model = new QSqlTableModel(this); |
||
303 | model->setTable(tableName); |
||
304 | |||
305 | model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
306 | model->setSort(0, Qt::AscendingOrder); |
||
307 | |||
308 | model->select(); |
||
309 | |||
310 | |||
311 | QSqlField field(tr("age"), QVariant::Int); |
||
312 | field.setValue(QString(tr("123"))); |
||
313 | |||
314 | bool okey; |
||
315 | int index; |
||
316 | QSqlRecord record; |
||
317 | |||
318 | |||
319 | tableView->setModel(model); |
||
320 | view.setModel(model); |
||
321 | |||
322 | |||
323 | tableView->setAlternatingRowColors(true); |
||
324 | view.setAlternatingRowColors(true); |
||
325 | |||
326 | tableView->resizeColumnsToContents(); |
||
327 | |||
328 | |||
329 | view.resizeColumnsToContents(); |
||
330 | |||
331 | tableView->show(); |
||
332 | |||
333 | |||
334 | |||
335 | initTreeWidget(); |
||
336 | } |
||
337 | */ |
||
91 | pingvin | 338 | |
339 | |||
146 | pingvin | 340 | QString MainWindow::creatModelString(QTreeWidgetItem* model){ |
91 | pingvin | 341 | |
342 | MainWindow::modelString.clear(); // |
||
343 | // for (int i =0; i < rootItem1->childCount(); ++i ) |
||
344 | |||
146 | pingvin | 345 | {MainWindow::addChildsString(model, 0);} |
346 | |||
347 | return MainWindow::modelString; |
||
145 | pingvin | 348 | // {MainWindow::addChildsString(ui->treeWidget, 0);} |
349 | /* |
||
91 | pingvin | 350 | int root_item_child_count; |
351 | int i; |
||
352 | root_item_child_count = rootItem1->childCount(); |
||
353 | i++; |
||
145 | pingvin | 354 | */ |
91 | pingvin | 355 | } |
356 | |||
357 | |||
358 | void MainWindow::addChildsString(QTreeWidgetItem *parentItem, int level){ |
||
359 | int child_count; |
||
360 | child_count = parentItem->childCount(); |
||
361 | for (int i=0; i < child_count; ++i){ |
||
362 | for (int m=0; m < level; ++m){ |
||
363 | modelString.append(tr(" ")); // - , |
||
364 | } |
||
365 | modelString.append(parentItem->child(i)->text(0)); // - |
||
366 | modelString.append(tr("\t\t\t\t")); // - |
||
367 | if (parentItem->child(i)->checkState(0) == Qt::Checked) {modelString.append(tr("true"));} // , "true", |
||
368 | else {modelString.append(tr("false"));} // - "false", |
||
369 | modelString.append(tr("\t\t\t\t")); // - |
||
370 | modelString.append(parentItem->child(i)->text(1)); // - ID |
||
371 | modelString.append(tr("\n")); // |
||
372 | if (parentItem->child(i)->childCount() > 0) { MainWindow::addChildsString(parentItem->child(i), level+1);} |
||
373 | |||
374 | } |
||
375 | int i; |
||
376 | i++; |
||
377 | } |
||
93 | pingvin | 378 | |
379 | |||
380 | bool MainWindow::openDataBase(){ |
||
381 | QString errorString; |
||
382 | sql = QSqlDatabase::addDatabase("QMYSQL"); |
||
131 | pingvin | 383 | // sql.setDatabaseName(tr("an_db")); |
384 | |||
132 | pingvin | 385 | // // // sql.setDatabaseName(tr("inventory")); |
131 | pingvin | 386 | |
132 | pingvin | 387 | sql.setDatabaseName(baseName); |
131 | pingvin | 388 | |
389 | |||
390 | |||
132 | pingvin | 391 | // // // sql.setHostName(tr("localhost")); |
93 | pingvin | 392 | |
132 | pingvin | 393 | sql.setHostName(hostName); |
394 | |||
395 | |||
396 | // // // sql.setUserName(tr("an")); |
||
397 | |||
398 | sql.setUserName(userName); |
||
399 | |||
400 | |||
401 | |||
402 | // // // sql.setPassword(tr("393939")); |
||
403 | |||
404 | |||
405 | sql.setPassword(password); |
||
406 | |||
407 | |||
408 | |||
93 | pingvin | 409 | bool ok; |
410 | ok = sql.open(); |
||
411 | |||
412 | /* |
||
413 | if (!ok) { |
||
414 | QMessageBox::critical( // . |
||
415 | this, // . |
||
416 | QObject::tr("Database Error"), // . |
||
417 | sql.lastError().text() ); // . |
||
418 | |||
419 | |||
420 | } |
||
421 | |||
422 | */ |
||
423 | if (!ok) { |
||
424 | QMessageBox::critical( // . |
||
425 | this, // . |
||
426 | QObject::tr("Database Error"), // . |
||
427 | sql.lastError().text()); // . |
||
428 | } |
||
429 | else { |
||
430 | |||
431 | QMessageBox::information( // . |
||
432 | this, // . |
||
433 | QObject::tr("Database Connect"), // . |
||
434 | QObject::tr(" .")); // . |
||
435 | |||
436 | |||
437 | |||
438 | |||
439 | |||
440 | } |
||
441 | |||
442 | return ok; |
||
443 | } |
||
94 | pingvin | 444 | |
445 | |||
97 | pingvin | 446 | bool MainWindow::buildPreviewModel(QString modelName, QString rootClassID){ |
94 | pingvin | 447 | QSqlQuery q; |
448 | QString sql_str; |
||
95 | pingvin | 449 | QString field_name_str; |
450 | QString root_class_name; |
||
192 | pingvin | 451 | //bool ok; |
452 | //int field_name; |
||
95 | pingvin | 453 | |
454 | //ui->treeWidget->clear(); |
||
455 | |||
456 | root_class_name = MainWindow::ClassName(rootClassID); // |
||
457 | |||
145 | pingvin | 458 | |
95 | pingvin | 459 | rootItem1 = new QTreeWidgetItem(ui->treeWidget); |
145 | pingvin | 460 | root_items_list << rootItem1; |
97 | pingvin | 461 | rootItem1->setText(0, modelName); |
462 | |||
95 | pingvin | 463 | rootItem1->setCheckState(0,Qt::Checked); |
104 | pingvin | 464 | rootItems.append(rootItem1); |
95 | pingvin | 465 | |
466 | |||
104 | pingvin | 467 | |
145 | pingvin | 468 | rootItem2 = new QTreeWidgetItem(rootItem1); |
469 | rootItem2->setText(0, root_class_name); |
||
470 | rootItem2->setText(1, rootClassID); |
||
471 | rootItem2->setCheckState(0,Qt::Checked); |
||
95 | pingvin | 472 | |
147 | pingvin | 473 | addChildsItems(rootItem2, -1); |
95 | pingvin | 474 | |
145 | pingvin | 475 | |
476 | /* |
||
477 | |||
94 | pingvin | 478 | sql_str = tr("select * " |
95 | pingvin | 479 | " from DescriptionOfClasses where DescriptionOfClasses.DefaultValue = '" // , |
94 | pingvin | 480 | ); |
481 | sql_str.append(rootClassID); |
||
482 | |||
95 | pingvin | 483 | sql_str.append(tr("' and DescriptionOfClasses.FieldType = 'pointer' ")); |
94 | pingvin | 484 | |
95 | pingvin | 485 | q.prepare(sql_str); |
486 | |||
487 | ok = q.exec(); |
||
488 | if (!ok) { |
||
489 | QMessageBox::critical( // . |
||
490 | this, // . |
||
491 | QObject::tr("Database Error"), // . |
||
492 | q.lastError().text()); // . |
||
493 | } |
||
494 | field_name = q.record().indexOf(tr("FieldName")); |
||
495 | while(q.next()){ |
||
496 | |||
497 | field_name_str = q.value(field_name).toString(); |
||
498 | |||
499 | } |
||
500 | |||
100 | pingvin | 501 | |
502 | |||
503 | |||
145 | pingvin | 504 | */ |
505 | |||
506 | |||
94 | pingvin | 507 | } |
95 | pingvin | 508 | |
509 | |||
147 | pingvin | 510 | bool MainWindow::rebuildPreviewModel(QTreeWidgetItem* root_item, QString rootClassID, int row){ |
107 | pingvin | 511 | QSqlQuery q; |
512 | QString sql_str; |
||
513 | QString field_name_str; |
||
514 | QString root_class_name; |
||
192 | pingvin | 515 | //bool ok; |
516 | //int field_name; |
||
95 | pingvin | 517 | |
107 | pingvin | 518 | //ui->treeWidget->clear(); |
519 | |||
520 | root_class_name = MainWindow::ClassName(rootClassID); // |
||
521 | |||
522 | |||
523 | // rootItem1 = new QTreeWidgetItem(ui->treeWidget); |
||
524 | // root_items_list << rootItem1; |
||
525 | // rootItem1->setText(0, modelName); |
||
526 | |||
527 | // rootItem1->setCheckState(0,Qt::Checked); |
||
528 | // rootItems.append(rootItem1); |
||
529 | |||
530 | // root_item->removeChild(root_item->child(0)); // |
||
145 | pingvin | 531 | if (root_item->childCount()==0){ // , |
532 | QTreeWidgetItem* item_tmp; |
||
533 | item_tmp = new QTreeWidgetItem (root_item); |
||
147 | pingvin | 534 | item_tmp->setText(4, QVariant(row).toString()); |
145 | pingvin | 535 | |
536 | } |
||
537 | |||
538 | if (root_item->childCount()==1){ // , |
||
107 | pingvin | 539 | root_item->child(0)->setText(0, root_class_name); |
540 | root_item->child(0)->setText(1, rootClassID); |
||
147 | pingvin | 541 | root_item->child(0)->setCheckState(0,Qt::Checked); |
542 | root_item->setText(4, QVariant(row).toString()); |
||
107 | pingvin | 543 | |
147 | pingvin | 544 | } |
145 | pingvin | 545 | |
546 | |||
147 | pingvin | 547 | |
107 | pingvin | 548 | //delete rootItem2; |
549 | |||
550 | |||
551 | // rootItem2 = new QTreeWidgetItem(rootItem1); |
||
552 | |||
553 | |||
554 | |||
555 | // rootItem2->setText(0, root_class_name); |
||
556 | // rootItem2->setText(1, rootClassID); |
||
557 | // rootItem2->setCheckState(0,Qt::Checked); |
||
558 | |||
559 | int child_count = root_item->child(0)->childCount(); |
||
560 | |||
561 | |||
145 | pingvin | 562 | for (int i=0; i < child_count; i++){ // , |
107 | pingvin | 563 | root_item->child(0)->removeChild(root_item->child(0)->child(0)); |
564 | } |
||
565 | |||
566 | child_count = root_item->child(0)->childCount(); |
||
147 | pingvin | 567 | addChildsItems(root_item->child(0), row); |
107 | pingvin | 568 | /* |
569 | sql_str = tr("select * " |
||
570 | " from DescriptionOfClasses where DescriptionOfClasses.DefaultValue = '" // , |
||
571 | ); |
||
572 | sql_str.append(rootClassID); |
||
573 | |||
574 | sql_str.append(tr("' and DescriptionOfClasses.FieldType = 'pointer' ")); |
||
575 | |||
576 | q.prepare(sql_str); |
||
577 | |||
578 | ok = q.exec(); |
||
579 | if (!ok) { |
||
580 | QMessageBox::critical( // . |
||
581 | this, // . |
||
582 | QObject::tr("Database Error"), // . |
||
583 | q.lastError().text()); // . |
||
584 | } |
||
585 | field_name = q.record().indexOf(tr("FieldName")); |
||
586 | while(q.next()){ |
||
587 | |||
588 | field_name_str = q.value(field_name).toString(); |
||
589 | |||
590 | } |
||
591 | |||
592 | */ |
||
593 | |||
594 | |||
595 | } |
||
596 | |||
597 | |||
598 | |||
599 | |||
95 | pingvin | 600 | QString MainWindow::ClassName(QString class_id){ // ID |
601 | QSqlQuery q; |
||
602 | QString sql_str; |
||
603 | QString class_name_str; |
||
604 | bool ok; |
||
605 | int field_class_name; |
||
606 | |||
607 | sql_str = tr("select * " |
||
608 | " from ListOfClasses where ListOfClasses.ID = '" // , |
||
609 | ); |
||
610 | |||
611 | sql_str.append(class_id); |
||
612 | sql_str.append(tr("' ")); |
||
613 | |||
614 | q.prepare(sql_str); |
||
615 | |||
616 | ok = q.exec(); |
||
617 | |||
618 | |||
619 | if (!ok) { |
||
620 | QMessageBox::critical( // . |
||
621 | this, // . |
||
622 | QObject::tr("Database Error"), // . |
||
623 | q.lastError().text()); // . |
||
624 | } |
||
625 | |||
626 | field_class_name = q.record().indexOf(tr("ClassName")); |
||
627 | while(q.next()){ |
||
628 | |||
629 | class_name_str = q.value(field_class_name).toString(); |
||
630 | |||
631 | } |
||
632 | |||
633 | return class_name_str; |
||
634 | |||
635 | } |
||
98 | pingvin | 636 | |
147 | pingvin | 637 | void MainWindow::addChildsItems(QTreeWidgetItem *perent_class_item, int row){ // , |
100 | pingvin | 638 | QStringList chields_list; |
639 | QString parent_ID; |
||
640 | QTreeWidgetItem *Item_tmp; |
||
641 | parent_ID = perent_class_item->text(1); |
||
642 | int chields_count, i; |
||
98 | pingvin | 643 | |
100 | pingvin | 644 | chields_list = MainWindow::classChields(parent_ID); |
645 | if(chields_list.isEmpty()) return; |
||
646 | chields_count = chields_list.size(); |
||
647 | for (int l = 0; l < chields_count; ++l){ |
||
648 | QString chield_class_name, chield_id; |
||
649 | chield_id = chields_list.at(l); |
||
650 | chield_class_name = MainWindow::ClassName(chield_id); |
||
651 | Item_tmp = new QTreeWidgetItem(perent_class_item); |
||
652 | Item_tmp->setText(0, chield_class_name); |
||
653 | Item_tmp->setText(1, chield_id); |
||
654 | Item_tmp->setCheckState(0, Qt::Checked); |
||
147 | pingvin | 655 | Item_tmp->setText(4, QVariant(row).toString()); |
656 | MainWindow::addChildsItems(Item_tmp, row); |
||
98 | pingvin | 657 | } |
658 | |||
100 | pingvin | 659 | i++; |
99 | pingvin | 660 | |
100 | pingvin | 661 | } |
662 | |||
663 | |||
99 | pingvin | 664 | /******************************************************** |
665 | * "" |
||
666 | * |
||
667 | * |
||
668 | * |
||
669 | ********************************************************/ |
||
670 | |||
671 | QStringList MainWindow::classChields(QString class_id){ |
||
672 | // QMap<QString, QString> map; |
||
673 | // TClass class_tmp; |
||
674 | // QList <TClass> chields_class_list; // |
||
675 | QStringList result; |
||
676 | QSqlQuery q; |
||
677 | QString sql_str; |
||
678 | QString classIdentifer_str; // - |
||
679 | QString field_id_str; |
||
680 | bool ok; |
||
681 | int field_classIdentifer; |
||
682 | sql_str = tr("select * " |
||
683 | " from DescriptionOfClasses where DescriptionOfClasses.DefaultValue = '" // , |
||
684 | ); |
||
685 | sql_str.append(class_id); |
||
686 | |||
687 | sql_str.append(tr("' and DescriptionOfClasses.FieldType = 'pointer' ")); |
||
688 | |||
689 | q.prepare(sql_str); |
||
690 | |||
691 | ok = q.exec(); |
||
692 | if (!ok) { |
||
693 | QMessageBox::critical( // . |
||
694 | this, // . |
||
695 | QObject::tr("Database Error"), // . |
||
696 | q.lastError().text()); // . |
||
697 | } |
||
698 | field_classIdentifer = q.record().indexOf(tr("ClassIdentifer")); |
||
699 | while(q.next()){ |
||
700 | |||
701 | classIdentifer_str = q.value(field_classIdentifer).toString(); |
||
702 | result.append(classIdentifer_str); |
||
703 | } |
||
704 | |||
705 | return result; |
||
706 | |||
707 | } |
||
102 | pingvin | 708 | |
709 | |||
710 | QMap <QString, QString> MainWindow::getClassList(){ // |
||
711 | QMap <QString, QString> result_map; |
||
712 | QSqlQuery q; |
||
713 | QString sql_str; |
||
103 | pingvin | 714 | QString class_name_str, class_id_str; |
715 | |||
102 | pingvin | 716 | int field_class_id, field_class_name; |
717 | bool ok; |
||
718 | sql_str = tr("select * " |
||
719 | " from ListOfClasses " // , |
||
720 | ); |
||
721 | q.prepare(sql_str); |
||
722 | ok = q.exec(); |
||
723 | if (!ok) { |
||
724 | QMessageBox::critical( // . |
||
725 | this, // . |
||
726 | QObject::tr("Database Error"), // . |
||
727 | q.lastError().text()); // . |
||
728 | return result_map; // - |
||
729 | } |
||
730 | field_class_id = q.record().indexOf(tr("ID")); |
||
731 | field_class_name = q.record().indexOf(tr("ClassName")); |
||
732 | |||
103 | pingvin | 733 | while(q.next()){ |
102 | pingvin | 734 | |
103 | pingvin | 735 | class_name_str = q.value(field_class_name).toString(); |
736 | class_id_str = q.value(field_class_id).toString(); |
||
737 | result_map[class_id_str] = class_name_str; |
||
738 | } |
||
102 | pingvin | 739 | return result_map; |
740 | } |
||
104 | pingvin | 741 | |
742 | |||
743 | |||
744 | |||
745 | |||
746 | void MainWindow::initComboBox(){ |
||
747 | |||
106 | pingvin | 748 | |
104 | pingvin | 749 | QStringList classesNameList; |
750 | QStringList classesID_list; |
||
751 | QStringList tmp_stringList; |
||
752 | |||
753 | |||
754 | |||
755 | QString tmp_str; |
||
756 | |||
757 | class_list_map = MainWindow::getClassList(); |
||
758 | classesID_list = class_list_map.keys(); |
||
759 | classesNameList = class_list_map.values(); |
||
760 | QMapIterator<QString, QString> interator(class_list_map); |
||
761 | // ui->comboBox->addItems(classesID_list); |
||
762 | // ui->comboBox->addItems(classesNameList); |
||
233 | pingvin | 763 | |
104 | pingvin | 764 | while (interator.hasNext()) { |
765 | interator.next(); |
||
766 | tmp_str = interator.value(); |
||
767 | tmp_str.append(tr(" \t(ID=")); |
||
768 | tmp_str.append(interator.key()); |
||
769 | tmp_str.append(tr(")")); |
||
770 | tmp_stringList << tmp_str; |
||
771 | |||
772 | } |
||
233 | pingvin | 773 | tmp_stringList << tr(" "); |
132 | pingvin | 774 | // int count = ui->comboBox->count(); |
775 | |||
776 | ui->comboBox->clear(); |
||
104 | pingvin | 777 | ui->comboBox->addItems(tmp_stringList); |
778 | |||
779 | |||
780 | } |
||
105 | pingvin | 781 | |
782 | |||
106 | pingvin | 783 | void MainWindow::on_comboBox_currentIndexChanged( int index ){ |
784 | QStringList classesNameList; |
||
785 | QStringList classesID_list; |
||
786 | QString ID_str; |
||
236 | pingvin | 787 | if (index == -1) return;// " " |
788 | if (ui->comboBox->itemText(index) == tr(" ")) return; |
||
152 | pingvin | 789 | if (!comboBox_slot_enable) return; // , , |
147 | pingvin | 790 | int row; |
132 | pingvin | 791 | |
106 | pingvin | 792 | classesID_list = class_list_map.keys(); |
793 | classesNameList = class_list_map.values(); |
||
794 | ID_str = classesID_list[index]; |
||
795 | ui->label->setText(ID_str); |
||
145 | pingvin | 796 | if (root_items_list.indexOf(ui->treeWidget->currentItem()) != -1) |
797 | { |
||
147 | pingvin | 798 | row = QVariant(ui->treeWidget->currentItem()->text(4)).toInt(); |
145 | pingvin | 799 | model_is_build = false; // on_treeWidget_itemChanged |
147 | pingvin | 800 | rebuildPreviewModel(ui->treeWidget->currentItem(), ID_str, row); |
145 | pingvin | 801 | model_is_build = true; // |
147 | pingvin | 802 | QString mdl_str = MainWindow::creatModelString(ui->treeWidget->currentItem()); // |
803 | model_for_ListModelsTable->setData(model_for_ListModelsTable->index(row, 2), QVariant(mdl_str)); |
||
145 | pingvin | 804 | } |
805 | getDatabaseData(); |
||
107 | pingvin | 806 | |
807 | |||
105 | pingvin | 808 | } |
809 | |||
106 | pingvin | 810 | void MainWindow::on_treeWidget_itemChanged ( QTreeWidgetItem * item, int column ){ |
811 | int i; |
||
812 | i++; |
||
147 | pingvin | 813 | QTreeWidgetItem * item_tmp; |
814 | QString mdl_str; |
||
815 | QString row; // , |
||
148 | pingvin | 816 | QList <QTreeWidgetItem *> mdl_itm_list; |
147 | pingvin | 817 | QList <int> rows_list; |
106 | pingvin | 818 | |
147 | pingvin | 819 | |
820 | if ((column) == 0 && (model_is_build)) { |
||
821 | // if (!model_is_build) return; // |
||
148 | pingvin | 822 | |
823 | mdl_itm_list = models_items.values(); |
||
147 | pingvin | 824 | rows_list = models_items.keys(); |
148 | pingvin | 825 | row= item->text(4); |
147 | pingvin | 826 | |
148 | pingvin | 827 | |
828 | if ( mdl_itm_list.indexOf(item) != -1){ // ( ) |
||
829 | if (item->checkState(0)) model_for_ListModelsTable->setData(model_for_ListModelsTable->index(QVariant(row).toInt(), 3), QVariant(1)); |
||
830 | else model_for_ListModelsTable->setData(model_for_ListModelsTable->index(QVariant(row).toInt(), 3), QVariant(0)); |
||
831 | } |
||
832 | |||
833 | |||
834 | |||
835 | |||
147 | pingvin | 836 | if (!row.isEmpty()){ |
837 | |||
838 | |||
839 | int row_int; |
||
840 | row_int = QVariant(row).toInt(); |
||
841 | if (rows_list.indexOf(row_int) != -1) |
||
842 | { |
||
843 | item_tmp = models_items[row_int]; |
||
844 | mdl_str = MainWindow::creatModelString(item_tmp); |
||
845 | model_for_ListModelsTable->setData(model_for_ListModelsTable->index(row_int, 2), QVariant(mdl_str)); |
||
846 | } |
||
847 | |||
848 | |||
849 | } |
||
850 | |||
851 | |||
852 | } |
||
853 | |||
854 | /* |
||
855 | QTreeWidgetItem * item_tmp; |
||
856 | item_tmp = item; |
||
857 | while (item_tmp ){ |
||
858 | item_tmp = item_tmp->parent(); |
||
859 | } |
||
860 | */ |
||
118 | pingvin | 861 | if ((column) == 0 && (model_is_build)) getDatabaseData(); |
862 | |||
147 | pingvin | 863 | |
106 | pingvin | 864 | } |
865 | |||
866 | |||
867 | void MainWindow::on_treeWidget_itemClicked ( QTreeWidgetItem * item, int column ){ |
||
868 | int i; |
||
869 | i++; |
||
214 | pingvin | 870 | if (root_items_list.indexOf(item) != -1) { // |
108 | pingvin | 871 | QStringList classesNameList; |
872 | QStringList classesID_list; |
||
106 | pingvin | 873 | |
217 | pingvin | 874 | ui->pushButton_9->setEnabled(false); |
875 | ui->pushButton_10->setEnabled(false); |
||
876 | ui->pushButton_11->setEnabled(false); |
||
877 | ui->pushButton_12->setEnabled(false); |
||
878 | // ui->tableView->reset(); |
||
879 | // MainWindow::filtr_model->clear(); |
||
221 | pingvin | 880 | disconnect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
881 | delete filter_model; |
||
223 | pingvin | 882 | |
883 | filter_model = new QSqlTableModel(); |
||
884 | /// filter_model = new MyModel(); |
||
227 | pingvin | 885 | filter_model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
223 | pingvin | 886 | |
887 | connect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
||
108 | pingvin | 888 | int index; |
889 | classesID_list = class_list_map.keys(); |
||
890 | classesNameList = class_list_map.values(); |
||
145 | pingvin | 891 | if (item->childCount()>0) index = classesID_list.indexOf(item->child(0)->text(1)); // , |
892 | else { // |
||
233 | pingvin | 893 | index = classesID_list.count(); |
894 | comboBox_slot_enable = false; // comboBox |
||
895 | ui->comboBox->setCurrentIndex(index); |
||
145 | pingvin | 896 | ui->comboBox->setEnabled(true); |
206 | pingvin | 897 | comboBox_slot_enable = true; |
145 | pingvin | 898 | return; |
899 | |||
900 | } |
||
152 | pingvin | 901 | comboBox_slot_enable = false; // comboBox |
132 | pingvin | 902 | if (index != -1) ui->comboBox->setCurrentIndex(index); |
152 | pingvin | 903 | comboBox_slot_enable = true; |
108 | pingvin | 904 | ui->comboBox->setEnabled(true); |
905 | |||
906 | |||
907 | } |
||
106 | pingvin | 908 | // if ((rootItem1) == (item) ) ui->comboBox->setEnabled(true); |
214 | pingvin | 909 | else // |
910 | { |
||
215 | pingvin | 911 | QString class_id; |
912 | QString model_id; |
||
913 | QString filtr_str; |
||
221 | pingvin | 914 | QString inctance; |
219 | pingvin | 915 | QStringList conditionList; |
215 | pingvin | 916 | class_id = item->text(1); |
917 | model_id = item->text(6); |
||
221 | pingvin | 918 | inctance = MainWindow::getClassInctance(class_id); |
919 | |||
217 | pingvin | 920 | filtr_str = tr("`Model_ID` = "); |
215 | pingvin | 921 | filtr_str.append(model_id); |
217 | pingvin | 922 | filtr_str.append(tr(" AND `Class_ID` = ")); |
215 | pingvin | 923 | filtr_str.append(class_id); |
217 | pingvin | 924 | // filtr_str.append(tr("`")); |
215 | pingvin | 925 | |
221 | pingvin | 926 | disconnect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
927 | delete filter_model; |
||
223 | pingvin | 928 | /// filter_model = new MyModel(); |
215 | pingvin | 929 | |
221 | pingvin | 930 | filter_model = new QSqlTableModel(); |
227 | pingvin | 931 | filter_model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
932 | |||
221 | pingvin | 933 | connect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
934 | filter_model->setTable(tr("Filters")); |
||
935 | filter_model->setFilter(filtr_str); |
||
226 | pingvin | 936 | |
937 | |||
938 | |||
221 | pingvin | 939 | filter_model->select(); |
226 | pingvin | 940 | |
941 | filter_model->sort(0,Qt::AscendingOrder); |
||
942 | |||
221 | pingvin | 943 | ui->tableView_3->setModel(filter_model); |
215 | pingvin | 944 | |
219 | pingvin | 945 | |
946 | ui->tableView_3->hideColumn(0); |
||
947 | ui->tableView_3->hideColumn(1); |
||
948 | ui->tableView_3->hideColumn(2); |
||
949 | |||
950 | |||
951 | filterSpinDelegate.setClassID(class_id); |
||
952 | filterSpinDelegate.getItems(); |
||
953 | ui->tableView_3->setItemDelegateForColumn(4, &filterSpinDelegate); |
||
954 | |||
224 | pingvin | 955 | // ui->tableView_3->setItemDelegate(); |
219 | pingvin | 956 | conditionList <<"" << "and" << "or" << "(" << "and (" << "or ("; |
957 | filterConditionDelegate.setItems(conditionList); |
||
958 | ui->tableView_3->setItemDelegateForColumn(3, &filterConditionDelegate); |
||
959 | |||
960 | conditionList.clear(); |
||
227 | pingvin | 961 | conditionList <<"" << "=" << "<" << ">" << "IS NULL" << "IS NOT NULL"; |
219 | pingvin | 962 | filterConditionDelegate_1.setItems(conditionList); |
963 | ui->tableView_3->setItemDelegateForColumn(5, &filterConditionDelegate_1); |
||
964 | |||
965 | |||
227 | pingvin | 966 | |
967 | |||
228 | pingvin | 968 | conditionList.clear(); |
969 | conditionList <<"" << ")"; |
||
970 | filterConditionDelegate_2.setItems(conditionList); |
||
971 | ui->tableView_3->setItemDelegateForColumn(7, &filterConditionDelegate_2); |
||
227 | pingvin | 972 | |
224 | pingvin | 973 | ui->tableView_3->setItemDelegateForColumn(6, &filterValueDelegate); |
219 | pingvin | 974 | |
224 | pingvin | 975 | |
976 | |||
977 | |||
217 | pingvin | 978 | ui->pushButton_9->setEnabled(true); |
979 | ui->pushButton_10->setEnabled(true); |
||
980 | |||
215 | pingvin | 981 | ui->comboBox->setEnabled(false); |
982 | |||
983 | |||
214 | pingvin | 984 | } |
106 | pingvin | 985 | } |
110 | pingvin | 986 | |
125 | pingvin | 987 | QMap <QString, QString> MainWindow::getFieldsList(QString class_id){ // |
110 | pingvin | 988 | |
125 | pingvin | 989 | } |
142 | pingvin | 990 | |
991 | |||
992 | void MainWindow::initListModelsTablle(){ |
||
149 | pingvin | 993 | model_for_ListModelsTable = new QSqlTableModel(); |
142 | pingvin | 994 | |
995 | model_for_ListModelsTable->setTable(tr("ListOfModels")); |
||
146 | pingvin | 996 | // model_for_ListModelsTable->setEditStrategy(QSqlTableModel::OnFieldChange); |
997 | model_for_ListModelsTable->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
142 | pingvin | 998 | ui->tableView_2->setModel(model_for_ListModelsTable); |
151 | pingvin | 999 | |
142 | pingvin | 1000 | model_for_ListModelsTable->select(); |
151 | pingvin | 1001 | |
223 | pingvin | 1002 | |
151 | pingvin | 1003 | ui->treeWidget->hideColumn(1); |
1004 | ui->treeWidget->hideColumn(2); |
||
1005 | ui->treeWidget->hideColumn(3); |
||
1006 | ui->treeWidget->hideColumn(4); |
||
221 | pingvin | 1007 | // ui->treeWidget->hideColumn(5); |
215 | pingvin | 1008 | ui->treeWidget->hideColumn(6); |
223 | pingvin | 1009 | |
151 | pingvin | 1010 | ui->tableView_2->hideColumn(0); |
1011 | ui->tableView_2->hideColumn(2); |
||
1012 | ui->tableView_2->hideColumn(3); |
||
1013 | ui->tableView_2->hideColumn(4); |
||
1014 | |||
1015 | ui->tableView_2->resizeColumnsToContents(); |
||
1016 | ui->tableView_2->setAlternatingRowColors(true); |
||
1017 | |||
146 | pingvin | 1018 | ui->pushButton_7->setEnabled(false); |
1019 | ui->pushButton_8->setEnabled(false); |
||
151 | pingvin | 1020 | |
1021 | |||
142 | pingvin | 1022 | } |
228 | pingvin | 1023 | |
1024 | void MainWindow::buildReport(bool advanced){ |
||
1025 | |||
1026 | // QTreeWidgetItem * hitm; |
||
1027 | |||
1028 | // hitm = ui->treeWidget_2->headerItem(); |
||
1029 | |||
1030 | // int count = root_items_list.count(); |
||
1031 | |||
1032 | //int count = ui->treeWidget_2->rootIndex(); |
||
1033 | |||
229 | pingvin | 1034 | |
233 | pingvin | 1035 | doc->clear();// |
228 | pingvin | 1036 | |
1037 | int list_count; |
||
1038 | if (rootItems.isEmpty()) return; |
||
1039 | |||
1040 | |||
1041 | |||
1042 | list_count = rootItems.count(); |
||
1043 | |||
1044 | for (int i=0; i < list_count; i++){ |
||
1045 | |||
1046 | getReport(rootItems.at(i), advanced); |
||
1047 | |||
229 | pingvin | 1048 | |
1049 | |||
228 | pingvin | 1050 | } |
233 | pingvin | 1051 | // (bool)QTextDocumentWriter("raport.odt").write(doc); |
228 | pingvin | 1052 | } |
1053 | |||
1054 | |||
1055 | void MainWindow::getReport(QTreeWidgetItem * model_item, bool advanced){ // |
||
1056 | |||
1057 | |||
1058 | // QTextDocument doc; |
||
1059 | // QTextCursor cursor(&doc); |
||
1060 | QTextCharFormat char_fmt; |
||
1061 | bool ok; |
||
1062 | |||
1063 | /************** |
||
1064 | |||
1065 | // char_fmt.setBackground(Qt::red); |
||
1066 | cursor.insertText(tr("1\n"),char_fmt); |
||
1067 | QImage img; |
||
1068 | ok = img.load("./hdd5.png"); |
||
1069 | doc.addResource(QTextDocument::ImageResource, QUrl("myimage"), img); |
||
1070 | cursor.insertImage("myimage"); |
||
1071 | cursor.insertText(tr(" \n"),char_fmt); |
||
1072 | |||
1073 | (bool)QTextDocumentWriter("test.odt").write(&doc); |
||
1074 | ***************/ |
||
1075 | |||
1076 | QString model_name; |
||
1077 | QString rootClassID; |
||
1078 | QString rootClassInctance; |
||
1079 | QFont font; |
||
233 | pingvin | 1080 | QBrush brush; |
228 | pingvin | 1081 | |
233 | pingvin | 1082 | brush.setColor(Qt::darkRed); |
1083 | char_fmt.setForeground(brush); |
||
1084 | font.setBold(true); |
||
1085 | char_fmt.setFont(font); |
||
1086 | |||
228 | pingvin | 1087 | model_name = model_item->text(0); |
1088 | if (model_item->checkState(0) == false) return; // |
||
1089 | |||
1090 | |||
229 | pingvin | 1091 | newPage(); |
1092 | /******************* |
||
1093 | QTextBlockFormat textFormat; |
||
1094 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore); |
||
1095 | cursor->setBlockFormat(textFormat); |
||
1096 | |||
1097 | cursor->insertText(tr(" ")); |
||
1098 | cursor->insertBlock(); |
||
1099 | |||
1100 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_Auto); |
||
1101 | cursor->setBlockFormat(textFormat); |
||
1102 | ********************/ |
||
1103 | |||
1104 | |||
1105 | |||
228 | pingvin | 1106 | if (!(model_item->childCount() > 0)) return; // ( ) |
1107 | |||
1108 | rootClassID = model_item->child(0)->text(1); |
||
1109 | rootClassInctance = getClassInctance(rootClassID); |
||
1110 | |||
233 | pingvin | 1111 | cursor->insertText(model_name, char_fmt); |
228 | pingvin | 1112 | cursor->insertText(tr("\n")); |
1113 | |||
1114 | if (model_item->child(0)->checkState(0)) // ( ), |
||
1115 | { |
||
1116 | ///// QTreeWidgetItem * item_tmp; |
||
1117 | ///// item_tmp = new QTreeWidgetItem(item); // , , |
||
1118 | ///// item_tmp->setText(0, model_item->child(0)->text(0)); // |
||
1119 | |||
1120 | //showClassObjects(item_tmp, model_item->child(0)); // |
||
1121 | |||
1122 | ///// showObjects(item_tmp, model_item->child(0), tr("")); |
||
1123 | printChild(model_item->child(0), tr(""), advanced, 1); |
||
230 | pingvin | 1124 | |
228 | pingvin | 1125 | } |
1126 | |||
1127 | |||
1128 | |||
1129 | |||
1130 | } |
||
1131 | |||
1132 | void MainWindow::printChild(QTreeWidgetItem * model_item, QString filtr, bool advanced, int pos){// |
||
1133 | QString classID; // |
||
1134 | QString parentClassID; // |
||
1135 | QString pointerField; // - |
||
1136 | QString inctance; // , |
||
1137 | QString className; // |
||
1138 | QString modelID; // |
||
1139 | QString add_filtr; // |
||
1140 | int field_ID; |
||
1141 | int icon_field_index; |
||
1142 | bool filtr_empty; |
||
1143 | bool ok; |
||
1144 | QSqlQuery q; |
||
1145 | QString sql_str; |
||
1146 | QString str_tmp; |
||
1147 | QTreeWidgetItem * title_item; |
||
233 | pingvin | 1148 | |
228 | pingvin | 1149 | QIcon icon; |
230 | pingvin | 1150 | QMap<QString, QString> fieldsTypesList;// , |
1151 | //QList<TField> FieldsList; // |
||
228 | pingvin | 1152 | |
229 | pingvin | 1153 | |
1154 | |||
1155 | |||
233 | pingvin | 1156 | // // // font.setBold(true); |
228 | pingvin | 1157 | filtr_empty = filtr.isEmpty(); |
1158 | |||
1159 | classID = model_item->text(1); |
||
1160 | modelID = model_item->text(6); |
||
1161 | add_filtr = MainWindow::getFiltrString(modelID, classID); |
||
1162 | |||
1163 | |||
1164 | icon = model_item->icon(0); |
||
1165 | |||
1166 | parentClassID = model_item->parent()->text(1); |
||
1167 | |||
1168 | pointerField = getPointerFieldName(parentClassID, classID); |
||
1169 | |||
1170 | className = model_item->text(0); |
||
1171 | inctance = getClassInctance(classID); |
||
1172 | |||
1173 | if (!model_item->checkState(0)) return; |
||
1174 | |||
1175 | |||
229 | pingvin | 1176 | |
1177 | |||
233 | pingvin | 1178 | QTextCharFormat charFormatItalic, charFormatBase, charFormatItalicBold, charFormatItalicOnly; |
1179 | QTextTableFormat tableFormat; |
||
1180 | |||
1181 | |||
1182 | // QPen pen; |
||
1183 | QBrush brush; |
||
1184 | QFont font; |
||
1185 | // pen.setColor(Qt::red); |
||
1186 | // charFormatItalic.setTextOutline(pen); |
||
1187 | |||
229 | pingvin | 1188 | //QFont font; |
233 | pingvin | 1189 | |
1190 | brush.setColor(Qt::blue); |
||
1191 | |||
229 | pingvin | 1192 | font.setItalic(true); |
233 | pingvin | 1193 | |
1194 | charFormatItalicOnly.setFont(font); |
||
229 | pingvin | 1195 | //charFormatItalic.setFontItalic(true); |
233 | pingvin | 1196 | |
1197 | font.setBold(true);///////////////// |
||
229 | pingvin | 1198 | charFormatItalic.setFont(font); |
233 | pingvin | 1199 | |
1200 | |||
1201 | charFormatItalic.setForeground(brush); |
||
1202 | |||
1203 | |||
1204 | |||
1205 | charFormatItalicBold.setFont(font); |
||
1206 | charFormatItalicBold.setForeground(brush); |
||
1207 | |||
1208 | |||
1209 | |||
229 | pingvin | 1210 | //charFormatItalic.setFontWeight(16); |
1211 | pos++; |
||
1212 | for(int i=0; i<pos; i++){ cursor->insertText( tr(" "));}// |
||
1213 | cursor->insertText(className, charFormatItalic); |
||
1214 | cursor->setCharFormat(charFormatBase); |
||
228 | pingvin | 1215 | cursor->insertText(tr("\n")); |
1216 | |||
229 | pingvin | 1217 | |
1218 | |||
228 | pingvin | 1219 | sql_str = tr("select * " |
1220 | " from " // - |
||
1221 | ); |
||
1222 | sql_str.append(inctance); |
||
1223 | |||
1224 | |||
1225 | if (filtr.isEmpty() && (!add_filtr.isEmpty())) // , |
||
1226 | { |
||
1227 | filtr.append(tr ("where ")); |
||
1228 | filtr.append(add_filtr); |
||
1229 | } |
||
1230 | |||
1231 | |||
1232 | if (!filtr.isEmpty()) { // |
||
1233 | sql_str.append(tr(" ")); |
||
1234 | sql_str.append(filtr); // |
||
1235 | } |
||
1236 | |||
1237 | q.prepare(sql_str); |
||
1238 | |||
1239 | ok = q.exec(); |
||
1240 | |||
1241 | if (!ok) { |
||
1242 | QString debug_str; |
||
1243 | debug_str.append(tr(" showObjects(): Database Error ")); |
||
1244 | debug_str.append(tr(" : ")); |
||
1245 | debug_str.append(inctance); |
||
1246 | debug_str.append(tr(" : ")); |
||
1247 | debug_str.append(filtr); |
||
1248 | debug_str.append(q.lastError().text()); |
||
1249 | QMessageBox::critical( // . |
||
1250 | this, // . |
||
1251 | QObject::tr(" showObjects(): Database Error"), // . |
||
1252 | debug_str |
||
1253 | // q.lastError().text() |
||
1254 | ); // . |
||
1255 | return; |
||
1256 | } |
||
1257 | |||
1258 | field_ID = q.record().indexOf(tr("ID")); |
||
1259 | |||
1260 | icon_field_index = q.record().indexOf(tr("Icon")); |
||
1261 | |||
229 | pingvin | 1262 | int k=0; |
1263 | QStringList fieldsNamesList;// |
||
230 | pingvin | 1264 | QList<TField> FieldsList; // |
231 | pingvin | 1265 | QMap<QString, TField> fieldsMap;// , - |
1266 | QMap <QString, QString> fieldsValues;// , |
||
230 | pingvin | 1267 | FieldsList = getFieldList(classID); // |
228 | pingvin | 1268 | |
1269 | |||
231 | pingvin | 1270 | |
1271 | |||
1272 | |||
230 | pingvin | 1273 | if(FieldsList.count()>0){ |
1274 | for(int i=0; i < FieldsList.count(); i++){ // ( - ) |
||
1275 | fieldsTypesList.insert(FieldsList.at(i).FieldName, FieldsList.at(i).FieldType); |
||
231 | pingvin | 1276 | fieldsMap.insert(FieldsList.at(i).FieldName, FieldsList.at(i)); |
230 | pingvin | 1277 | } |
229 | pingvin | 1278 | |
230 | pingvin | 1279 | // fieldsNamesList = fieldsTypesList.keys(); // |
1280 | } |
||
1281 | |||
1282 | // icon_field_index = fieldsNamesList.indexOf(tr("Icon"));// |
||
1283 | |||
1284 | |||
1285 | |||
229 | pingvin | 1286 | while(!q.record().fieldName(k).isEmpty()){// |
1287 | fieldsNamesList.append(q.record().fieldName(k++)); |
||
1288 | } |
||
1289 | |||
1290 | |||
230 | pingvin | 1291 | //icon_field_index = fieldsNamesList.indexOf(tr("Icon"));// |
1292 | |||
1293 | |||
228 | pingvin | 1294 | while(q.next()){ |
1295 | if (q.record().count() > 1) |
||
1296 | { |
||
1297 | QString value_tmp; |
||
1298 | QString ID_tmp; |
||
1299 | QString space; |
||
1300 | |||
1301 | // // // // QTreeWidgetItem * itm; |
||
1302 | ID_tmp = q.value(field_ID).toString(); // |
||
1303 | value_tmp = q.value(1).toString(); // ( ) |
||
1304 | // itm = new QTreeWidgetItem(parent_object_item); // , |
||
1305 | |||
1306 | |||
1307 | |||
1308 | |||
1309 | /*************************** |
||
1310 | itm = new QTreeWidgetItem(title_item); // , |
||
1311 | itm->setText(0, value_tmp); |
||
1312 | itm->setText(1, tr("object")); |
||
1313 | itm->setText(2, ID_tmp); |
||
1314 | ******************************/ |
||
1315 | |||
1316 | if (icon_field_index != -1){ // |
||
1317 | |||
1318 | QVariant data; |
||
1319 | QByteArray bytes; |
||
1320 | QPixmap pix; |
||
1321 | QIcon icn; |
||
1322 | QMap <QString, QPixmap> pixmap_map; |
||
1323 | QList <QString> id_list; |
||
1324 | QList <QPixmap> pixmap_list; |
||
1325 | pixmap_map = MainWindow::getObjectsIcon(inctance); |
||
1326 | if (!pixmap_map.isEmpty()) { |
||
1327 | id_list = pixmap_map.keys(); |
||
1328 | pixmap_list = pixmap_map.values(); |
||
1329 | } |
||
1330 | if (id_list.indexOf(ID_tmp) != -1) { |
||
1331 | pix = pixmap_list.at(id_list.indexOf(ID_tmp)); |
||
1332 | } |
||
1333 | // data = q.record().value(icon_field_index); |
||
1334 | // bytes = q.record().value(icon_field_index).toByteArray(); |
||
1335 | // if (data.isValid() && (!data.isNull())) { |
||
1336 | // if (!bytes.isEmpty()){ |
||
1337 | // pix.loadFromData(data.toByteArray()); |
||
1338 | // pix.loadFromData(bytes); |
||
1339 | |||
1340 | |||
1341 | if(!pix.isNull()) { |
||
1342 | if (pix.height() > 128) pix = pix.scaledToHeight(128); |
||
1343 | QString fname = value_tmp; |
||
1344 | fname.append(tr(".png")); |
||
1345 | |||
1346 | |||
1347 | pix.toImage().save(fname); |
||
233 | pingvin | 1348 | doc->addResource(QTextDocument::ImageResource, QUrl(fname), pix.toImage()); |
228 | pingvin | 1349 | |
1350 | // for(int i=0; i<pos; i++){ cursor->insertText( tr(" "));}// |
||
1351 | |||
1352 | |||
229 | pingvin | 1353 | for(int i=0; i<pos+1; i++){ cursor->insertText( tr(" "));}// |
228 | pingvin | 1354 | cursor->insertImage(fname); |
1355 | // cursor->insertText(tr("\n")); |
||
1356 | |||
1357 | } |
||
229 | pingvin | 1358 | else for(int i=0; i<pos+1; i++){ cursor->insertText( tr(" "));}// |
228 | pingvin | 1359 | |
1360 | |||
1361 | |||
1362 | |||
1363 | // // // icn.addPixmap(pix); |
||
1364 | // // // itm->setIcon(0, icn); |
||
1365 | // } |
||
1366 | |||
1367 | |||
1368 | } |
||
1369 | |||
229 | pingvin | 1370 | else for(int i=0; i<pos+1; i++){ cursor->insertText( tr(" "));}// |
228 | pingvin | 1371 | cursor->insertText( value_tmp); |
1372 | cursor->insertText( tr("\n")); |
||
1373 | |||
229 | pingvin | 1374 | |
1375 | |||
230 | pingvin | 1376 | // q.first(); |
229 | pingvin | 1377 | |
1378 | |||
230 | pingvin | 1379 | if(advanced && (fieldsNamesList.count()>0)){ // |
1380 | |||
1381 | QString tmp_string; |
||
229 | pingvin | 1382 | sql_str.clear(); |
1383 | |||
231 | pingvin | 1384 | // // // QTextTable *table = cursor->insertTable(fieldsNamesList.count()-2, 2);// , (ID ) |
229 | pingvin | 1385 | |
1386 | |||
230 | pingvin | 1387 | |
231 | pingvin | 1388 | /************************ |
1389 | QTextTable *table = cursor->insertTable(fieldsNamesList.count(), 2);// , (ID ) |
||
1390 | |||
1391 | ************************/ |
||
1392 | |||
1393 | |||
1394 | |||
1395 | |||
1396 | |||
1397 | |||
1398 | |||
1399 | |||
1400 | |||
1401 | |||
1402 | // cursor->insertText(tr(" ")); |
||
1403 | |||
1404 | |||
230 | pingvin | 1405 | // *cursor = table->cellAt(0,1).firstCursorPosition(); |
1406 | // cursor->insertText(tr(" 2")); |
||
1407 | // *cursor = table->cellAt(1,1).lastCursorPosition(); |
||
1408 | // cursor->insertText(tr(" 4")); |
||
1409 | |||
1410 | |||
1411 | // cursor->movePosition(QTextCursor::End); |
||
1412 | |||
1413 | |||
1414 | |||
1415 | //table->cellAt(1,1).firstCursorPosition().insertText(tr("1")); |
||
1416 | //table->cellAt(1,2).firstCursorPosition().insertText(tr("2")); |
||
1417 | //table->cellAt(2,1).firstCursorPosition().insertText(tr("3")); |
||
1418 | |||
1419 | //table->cellAt(2,2).firstCursorPosition().insertText(tr("4")); |
||
1420 | // cursor->insertText(tr("1 \t 2")); |
||
1421 | // cursor->insertText(tr("3 \t 4")); |
||
1422 | |||
231 | pingvin | 1423 | for(int i=0; i < fieldsNamesList.count(); i++) |
1424 | { |
||
230 | pingvin | 1425 | |
231 | pingvin | 1426 | |
1427 | if (fieldsNamesList.at(i)== tr("Icon") || fieldsNamesList.at(i)== tr("ID")) { tmp_string = tr(" "); |
||
1428 | continue; |
||
1429 | } |
||
1430 | |||
1431 | QString fieldType; |
||
1432 | fieldType = fieldsTypesList.value(fieldsNamesList.at(i)); // |
||
1433 | if(fieldType == tr("pointer")) // - |
||
1434 | { |
||
1435 | QSqlQuery q_tmp; |
||
1436 | QString sql_str; |
||
1437 | // QString val_str; |
||
1438 | QString parent_class_id;// , |
||
1439 | QString parent_class_inctance; // |
||
1440 | bool ok; |
||
1441 | TField field_tmp; |
||
1442 | field_tmp = fieldsMap.value(fieldsNamesList.at(i)); |
||
1443 | parent_class_id = field_tmp.DefaultValue; |
||
1444 | if (parent_class_id.isEmpty()) continue; // id |
||
1445 | else parent_class_inctance = getClassInctance(parent_class_id); |
||
1446 | if (parent_class_inctance.isEmpty()) continue; // id |
||
1447 | sql_str = tr("select * from `"); |
||
1448 | sql_str.append(parent_class_inctance); |
||
1449 | sql_str.append(tr("` where `ID` = '")); |
||
1450 | sql_str.append(q.record().value(i).asString()); |
||
1451 | sql_str.append(tr("'")); |
||
1452 | ok = q_tmp.prepare(sql_str); |
||
1453 | ok = q_tmp.exec(); |
||
1454 | |||
1455 | if (!ok) { |
||
1456 | QString debug_str; |
||
1457 | debug_str.append(tr(" showObjects(): Database Error ")); |
||
1458 | debug_str.append(tr(" : ")); |
||
1459 | debug_str.append(inctance); |
||
1460 | debug_str.append(tr(" : ")); |
||
1461 | debug_str.append(filtr); |
||
1462 | debug_str.append(q.lastError().text()); |
||
1463 | QMessageBox::critical( // . |
||
1464 | this, // . |
||
1465 | QObject::tr(" showObjects(): Database Error"), // . |
||
1466 | debug_str |
||
1467 | // q.lastError().text() |
||
1468 | ); // . |
||
1469 | return; |
||
1470 | } |
||
1471 | |||
1472 | tmp_string.clear(); |
||
1473 | while (q_tmp.next()){ |
||
1474 | tmp_string = q_tmp.record().value(1).asString(); |
||
1475 | |||
1476 | } |
||
1477 | |||
1478 | fieldsValues.insert(fieldsNamesList.at(i), tmp_string);// |
||
1479 | |||
1480 | continue;// |
||
1481 | |||
1482 | } // pointer |
||
1483 | |||
1484 | if(fieldType == tr("file")){ // - , |
||
1485 | |||
1486 | tmp_string = tr(" "); |
||
1487 | continue; |
||
1488 | |||
1489 | } |
||
1490 | |||
1491 | tmp_string = q.record().value(i).asString(); // , -, |
||
1492 | fieldsValues.insert(fieldsNamesList.at(i), tmp_string);// |
||
1493 | |||
1494 | |||
1495 | } |
||
1496 | |||
1497 | |||
1498 | |||
1499 | |||
1500 | |||
233 | pingvin | 1501 | // for(int i=0; i<pos+1; i++){ cursor->insertText( tr(" "));}// |
1502 | tableFormat.setAlignment(Qt::AlignLeft); |
||
1503 | tableFormat.setBackground(QColor("#e0e0e0")); |
||
1504 | // tableFormat.setCellPadding(2); |
||
1505 | // tableFormat.setCellSpacing(4); |
||
1506 | tableFormat.setLeftMargin(pos*7); |
||
1507 | tableFormat.setBorder(1); |
||
1508 | tableFormat.setBorderStyle( QTextFrameFormat::BorderStyle_Solid); |
||
231 | pingvin | 1509 | |
233 | pingvin | 1510 | QTextTable *table = cursor->insertTable(fieldsValues.count(), 2, tableFormat);// , (ID ) |
1511 | // table->setFormat(tableFormat); |
||
1512 | |||
1513 | |||
1514 | for(int i=0; i < fieldsValues.count(); i++){ // : ID , ( ) |
||
231 | pingvin | 1515 | QStringList keys_list = fieldsValues.keys(); |
1516 | QStringList values_list = fieldsValues.values(); |
||
1517 | *cursor = table->cellAt(i,0).firstCursorPosition();// i-, |
||
233 | pingvin | 1518 | cursor->insertText(keys_list.at(i), charFormatItalicOnly);// |
231 | pingvin | 1519 | *cursor = table->cellAt(i,1).firstCursorPosition();// i-, |
1520 | cursor->insertText(values_list.at(i));// |
||
1521 | } |
||
1522 | |||
233 | pingvin | 1523 | // table->setFormat(tableFormat); |
1524 | cursor->movePosition(QTextCursor::End);// |
||
231 | pingvin | 1525 | cursor->insertText( tr("\n")); |
1526 | |||
1527 | |||
1528 | |||
1529 | /****************************** |
||
1530 | |||
1531 | table = cursor->insertTable(fieldsNamesList.count(), 2);// , (ID ) |
||
1532 | |||
230 | pingvin | 1533 | for(int i=2; i < fieldsNamesList.count(); i++){ // : ID , ( ) |
1534 | // if (i !=icon_field_index) tmp_string = q.record().value(i).asString(); // , |
||
1535 | if (i !=icon_field_index) tmp_string = q.record().value(i).asString(); // , |
||
1536 | |||
1537 | |||
1538 | else tmp_string = tr(" "); |
||
1539 | //// if (i !=icon_field_index) { |
||
1540 | for(int i=0; i<pos+2; i++){ cursor->insertText( tr(" "));}// |
||
1541 | *cursor = table->cellAt(i-2,0).firstCursorPosition();// i-, |
||
1542 | cursor->insertText( fieldsNamesList.at(i));// |
||
1543 | *cursor = table->cellAt(i-2,1).firstCursorPosition();// i-, |
||
1544 | //cursor->insertText( tr(":\t")); |
||
1545 | |||
1546 | cursor->insertText(tmp_string);// |
||
1547 | // cursor->insertText( tr("\n")); |
||
1548 | } |
||
1549 | |||
1550 | //// } |
||
231 | pingvin | 1551 | |
1552 | |||
1553 | |||
1554 | |||
1555 | |||
1556 | |||
1557 | |||
1558 | |||
1559 | |||
1560 | |||
230 | pingvin | 1561 | cursor->movePosition(QTextCursor::End);// |
1562 | cursor->insertText( tr("\n")); |
||
231 | pingvin | 1563 | |
1564 | *********************************/ |
||
1565 | |||
229 | pingvin | 1566 | } |
1567 | |||
1568 | |||
1569 | |||
1570 | /******************************************************** |
||
1571 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore); |
||
1572 | cursor->setBlockFormat(textFormat); |
||
1573 | |||
1574 | cursor->insertText(tr(" ")); |
||
1575 | cursor->insertBlock(); |
||
1576 | |||
1577 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_Auto); |
||
1578 | cursor->setBlockFormat(textFormat); |
||
1579 | **********************************************************/ |
||
1580 | |||
1581 | |||
228 | pingvin | 1582 | // itm->setIcon(0, icon); |
1583 | |||
1584 | |||
1585 | for (int i=0; i < model_item->childCount(); i++) // , |
||
1586 | { |
||
1587 | QTreeWidgetItem * model_item_tmp; // |
||
1588 | QString pointer_name; |
||
1589 | QString filtr_tmp; |
||
1590 | bool pointer_isEmpty; |
||
1591 | model_item_tmp = model_item->child(i); // |
||
1592 | pointer_name = getPointerFieldName(classID, model_item->child(i)->text(1)); |
||
1593 | // // // // itm->setText(4, pointer_name); |
||
1594 | |||
1595 | // title_item->setText(4, pointer_name); |
||
1596 | |||
1597 | |||
1598 | pointer_isEmpty = pointer_name.isEmpty(); |
||
1599 | filtr_tmp = tr("where "); |
||
1600 | filtr_tmp.append(tr("`")); |
||
1601 | filtr_tmp.append(pointer_name); |
||
1602 | filtr_tmp.append(tr("` = '")); |
||
1603 | filtr_tmp.append(ID_tmp); |
||
1604 | filtr_tmp.append(tr("'")); |
||
229 | pingvin | 1605 | |
1606 | printChild(model_item_tmp, filtr_tmp, advanced, pos+1); |
||
1607 | |||
228 | pingvin | 1608 | // // // // showObjects(itm, model_item_tmp, filtr_tmp); |
1609 | //MainWindow::showObjectChildrens(ID_tmp, itm, model_item_tmp); |
||
1610 | |||
1611 | } |
||
233 | pingvin | 1612 | // if(pos==2) newPage(); // , |
228 | pingvin | 1613 | |
1614 | } |
||
1615 | |||
1616 | } |
||
1617 | |||
1618 | |||
1619 | |||
1620 | |||
1621 | |||
1622 | |||
1623 | |||
1624 | |||
1625 | |||
1626 | |||
1627 | } |
||
1628 | |||
1629 | |||
229 | pingvin | 1630 | void MainWindow::newPage(int page_number){ // |
1631 | |||
1632 | QTextBlockFormat textFormat; |
||
1633 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore); |
||
1634 | cursor->setBlockFormat(textFormat); |
||
1635 | |||
1636 | cursor->insertText(tr(" %1").arg(page_number)); |
||
1637 | cursor->insertBlock(); |
||
1638 | |||
1639 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_Auto); |
||
1640 | cursor->setBlockFormat(textFormat); |
||
1641 | |||
1642 | |||
1643 | } |
||
1644 | void MainWindow::newPage(){ // |
||
1645 | |||
1646 | QTextBlockFormat textFormat; |
||
1647 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore); |
||
1648 | cursor->setBlockFormat(textFormat); |
||
1649 | |||
1650 | //cursor->insertText(tr(" %1").arg(page_number)); |
||
1651 | cursor->insertBlock(); |
||
1652 | |||
1653 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_Auto); |
||
1654 | cursor->setBlockFormat(textFormat); |
||
1655 | |||
1656 | |||
1657 | } |
||
230 | pingvin | 1658 | |
1659 | QList<TField> MainWindow::getFieldList(QString class_id){// |
||
1660 | |||
1661 | QSqlQuery q; |
||
1662 | QString sql_str; |
||
1663 | QList<TField> result_list; |
||
1664 | |||
1665 | int field_id, field_name, field_alias, field_type, field_default_value, field_classIdentifer, field_comment; |
||
1666 | |||
1667 | bool ok; |
||
1668 | sql_str = tr("select * " |
||
1669 | " from `DescriptionOfClasses` where `DescriptionOfClasses`.`ClassIdentifer` = " // - |
||
1670 | ); |
||
1671 | |||
1672 | sql_str.append(tr("'")); |
||
1673 | sql_str.append(class_id); |
||
1674 | sql_str.append(tr("' ")); |
||
1675 | ok = q.prepare(sql_str); |
||
1676 | |||
1677 | ok = q.exec(); |
||
1678 | if (!ok) { |
||
1679 | QMessageBox::critical( // . |
||
1680 | this, // . |
||
1681 | QObject::tr("Database Error"), // . |
||
1682 | q.lastError().text()); // . |
||
1683 | return result_list; |
||
1684 | } |
||
1685 | |||
1686 | |||
1687 | field_id = q.record().indexOf(tr("ID")); |
||
1688 | field_name = q.record().indexOf(tr("FieldName")); |
||
1689 | field_alias = q.record().indexOf(tr("FieldAlias")); |
||
1690 | field_type = q.record().indexOf(tr("FieldType")); |
||
1691 | field_default_value = q.record().indexOf(tr("DefaultValue")); |
||
1692 | field_classIdentifer = q.record().indexOf(tr("ClassIdentifer")); |
||
1693 | field_comment = q.record().indexOf(tr("Comment")); |
||
1694 | |||
1695 | while(q.next()){ |
||
1696 | |||
1697 | TField field_tmp; |
||
1698 | field_tmp.ID = q.value(field_id).toString(); |
||
1699 | field_tmp.FieldName = q.value(field_name).toString(); |
||
1700 | field_tmp.FieldAlias = q.value(field_alias).toString(); |
||
1701 | field_tmp.FieldType = q.value(field_type).toString(); |
||
1702 | field_tmp.DefaultValue = q.value(field_default_value).toString(); |
||
1703 | field_tmp.ClassIdentifer = q.value(field_classIdentifer).toString(); |
||
1704 | field_tmp.Comment = q.value(field_comment).toString(); |
||
1705 | result_list << field_tmp; |
||
1706 | |||
1707 | |||
1708 | |||
1709 | |||
1710 | // parentClassID = q.value(field_default_value).toString(); |
||
1711 | // parentClassInctance = getClassInctance(parentClassID); |
||
1712 | // result_map.insert(pointerFieldName, parentClassInctance); |
||
1713 | |||
1714 | |||
1715 | |||
1716 | } |
||
1717 | |||
1718 | return result_list; |
||
1719 | |||
1720 | } |
||
238 | pingvin | 1721 | |
1722 | |||
1723 | |||
1724 | void MainWindow::readStandartProcessOutput(){ |
||
1725 | |||
1726 | QTextDocument * wmiDoc = ui->textEdit_2->document(); |
||
1727 | QTextCursor * wmiCursor; |
||
1728 | wmiCursor = new QTextCursor(wmiDoc); |
||
1729 | |||
1730 | QByteArray arr; |
||
1731 | QStringList result, fields, values; |
||
1732 | QString str1, str2; |
||
1733 | int i; |
||
1734 | arr = wmiProcess.readAllStandardOutput(); |
||
1735 | QTextCodec *codecUTF = QTextCodec::codecForName("utf8"); |
||
1736 | QTextCodec *codec = QTextCodec::codecForName("cp1251"); |
||
1737 | QTextCodec::setCodecForTr(codecUTF); |
||
1738 | str1 = QString(tr(arr)); |
||
1739 | result = str1.split("\n", QString::SkipEmptyParts); |
||
1740 | if (result.count()>2){ |
||
1741 | |||
1742 | |||
1743 | |||
1744 | |||
1745 | QString tmp_str; |
||
1746 | QTextTable * wmi_table; |
||
1747 | int fields_count, row_count; |
||
1748 | tmp_str = result.at(1); |
||
1749 | fields = tmp_str.split("|"); |
||
1750 | fields_count = fields.count(); |
||
1751 | row_count = result.count()-1; // ( ) |
||
1752 | wmi_table = wmiCursor->insertTable(row_count, fields_count); |
||
1753 | for(int n = 0; n < fields.count(); n++) { // "" |
||
1754 | *wmiCursor = wmi_table->cellAt(0, n).firstCursorPosition(); |
||
1755 | wmiCursor->insertText(fields.at(n)); |
||
1756 | } |
||
1757 | // tmp_str = result.at(2); |
||
1758 | // values = tmp_str.split("|"); |
||
1759 | |||
1760 | |||
1761 | for (int m=2; m< result.count(); m++){ |
||
1762 | |||
1763 | tmp_str = result.at(m); |
||
1764 | values = tmp_str.split("|"); |
||
1765 | |||
1766 | for(int n = 0; n < values.count(); n++){ |
||
1767 | *wmiCursor = wmi_table->cellAt(m-1, n).firstCursorPosition(); |
||
1768 | |||
1769 | // wmiCursor->insertText(fields.at(n)); |
||
1770 | // wmiCursor->insertText(tr(": ")); |
||
1771 | wmiCursor->insertText(values.at(n)); |
||
1772 | // wmiCursor->insertText(tr("\n")); |
||
1773 | |||
1774 | } |
||
1775 | |||
1776 | |||
1777 | |||
1778 | } |
||
1779 | |||
1780 | |||
1781 | |||
1782 | } |
||
1783 | QTextCodec::setCodecForTr(codec); |
||
1784 | |||
1785 | |||
1786 | |||
1787 | |||
1788 | |||
1789 | |||
1790 | |||
1791 | |||
1792 | |||
1793 | // result = QStringList(arr); |
||
1794 | // str2 << arr; |
||
1795 | //i = result.size(); |
||
1796 | // str1 = result.at(0); |
||
1797 | i++; |
||
1798 | //lineEdit->insert(str1); |
||
1799 | |||
1800 | } |
||
1801 | |||
1802 | void MainWindow::readStandartProcessError(){ |
||
1803 | QByteArray arr; |
||
1804 | arr = wmiProcess.readAllStandardError(); |
||
1805 | |||
1806 | } |