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