Редакция 233 | Редакция 236 | К новейшей редакции | Содержимое файла | Сравнить с предыдущей | Последнее изменение | Открыть журнал | 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; |
||
132 | pingvin | 784 | if (index == -1) return; |
152 | pingvin | 785 | if (!comboBox_slot_enable) return; // , , |
147 | pingvin | 786 | int row; |
132 | pingvin | 787 | |
106 | pingvin | 788 | classesID_list = class_list_map.keys(); |
789 | classesNameList = class_list_map.values(); |
||
790 | ID_str = classesID_list[index]; |
||
791 | ui->label->setText(ID_str); |
||
145 | pingvin | 792 | if (root_items_list.indexOf(ui->treeWidget->currentItem()) != -1) |
793 | { |
||
147 | pingvin | 794 | row = QVariant(ui->treeWidget->currentItem()->text(4)).toInt(); |
145 | pingvin | 795 | model_is_build = false; // on_treeWidget_itemChanged |
147 | pingvin | 796 | rebuildPreviewModel(ui->treeWidget->currentItem(), ID_str, row); |
145 | pingvin | 797 | model_is_build = true; // |
147 | pingvin | 798 | QString mdl_str = MainWindow::creatModelString(ui->treeWidget->currentItem()); // |
799 | model_for_ListModelsTable->setData(model_for_ListModelsTable->index(row, 2), QVariant(mdl_str)); |
||
145 | pingvin | 800 | } |
801 | getDatabaseData(); |
||
107 | pingvin | 802 | |
803 | |||
105 | pingvin | 804 | } |
805 | |||
106 | pingvin | 806 | void MainWindow::on_treeWidget_itemChanged ( QTreeWidgetItem * item, int column ){ |
807 | int i; |
||
808 | i++; |
||
147 | pingvin | 809 | QTreeWidgetItem * item_tmp; |
810 | QString mdl_str; |
||
811 | QString row; // , |
||
148 | pingvin | 812 | QList <QTreeWidgetItem *> mdl_itm_list; |
147 | pingvin | 813 | QList <int> rows_list; |
106 | pingvin | 814 | |
147 | pingvin | 815 | |
816 | if ((column) == 0 && (model_is_build)) { |
||
817 | // if (!model_is_build) return; // |
||
148 | pingvin | 818 | |
819 | mdl_itm_list = models_items.values(); |
||
147 | pingvin | 820 | rows_list = models_items.keys(); |
148 | pingvin | 821 | row= item->text(4); |
147 | pingvin | 822 | |
148 | pingvin | 823 | |
824 | if ( mdl_itm_list.indexOf(item) != -1){ // ( ) |
||
825 | if (item->checkState(0)) model_for_ListModelsTable->setData(model_for_ListModelsTable->index(QVariant(row).toInt(), 3), QVariant(1)); |
||
826 | else model_for_ListModelsTable->setData(model_for_ListModelsTable->index(QVariant(row).toInt(), 3), QVariant(0)); |
||
827 | } |
||
828 | |||
829 | |||
830 | |||
831 | |||
147 | pingvin | 832 | if (!row.isEmpty()){ |
833 | |||
834 | |||
835 | int row_int; |
||
836 | row_int = QVariant(row).toInt(); |
||
837 | if (rows_list.indexOf(row_int) != -1) |
||
838 | { |
||
839 | item_tmp = models_items[row_int]; |
||
840 | mdl_str = MainWindow::creatModelString(item_tmp); |
||
841 | model_for_ListModelsTable->setData(model_for_ListModelsTable->index(row_int, 2), QVariant(mdl_str)); |
||
842 | } |
||
843 | |||
844 | |||
845 | } |
||
846 | |||
847 | |||
848 | } |
||
849 | |||
850 | /* |
||
851 | QTreeWidgetItem * item_tmp; |
||
852 | item_tmp = item; |
||
853 | while (item_tmp ){ |
||
854 | item_tmp = item_tmp->parent(); |
||
855 | } |
||
856 | */ |
||
118 | pingvin | 857 | if ((column) == 0 && (model_is_build)) getDatabaseData(); |
858 | |||
147 | pingvin | 859 | |
106 | pingvin | 860 | } |
861 | |||
862 | |||
863 | void MainWindow::on_treeWidget_itemClicked ( QTreeWidgetItem * item, int column ){ |
||
864 | int i; |
||
865 | i++; |
||
214 | pingvin | 866 | if (root_items_list.indexOf(item) != -1) { // |
108 | pingvin | 867 | QStringList classesNameList; |
868 | QStringList classesID_list; |
||
106 | pingvin | 869 | |
217 | pingvin | 870 | ui->pushButton_9->setEnabled(false); |
871 | ui->pushButton_10->setEnabled(false); |
||
872 | ui->pushButton_11->setEnabled(false); |
||
873 | ui->pushButton_12->setEnabled(false); |
||
874 | // ui->tableView->reset(); |
||
875 | // MainWindow::filtr_model->clear(); |
||
221 | pingvin | 876 | disconnect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
877 | delete filter_model; |
||
223 | pingvin | 878 | |
879 | filter_model = new QSqlTableModel(); |
||
880 | /// filter_model = new MyModel(); |
||
227 | pingvin | 881 | filter_model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
223 | pingvin | 882 | |
883 | connect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
||
108 | pingvin | 884 | int index; |
885 | classesID_list = class_list_map.keys(); |
||
886 | classesNameList = class_list_map.values(); |
||
145 | pingvin | 887 | if (item->childCount()>0) index = classesID_list.indexOf(item->child(0)->text(1)); // , |
888 | else { // |
||
233 | pingvin | 889 | index = classesID_list.count(); |
890 | comboBox_slot_enable = false; // comboBox |
||
891 | ui->comboBox->setCurrentIndex(index); |
||
145 | pingvin | 892 | ui->comboBox->setEnabled(true); |
206 | pingvin | 893 | comboBox_slot_enable = true; |
145 | pingvin | 894 | return; |
895 | |||
896 | } |
||
152 | pingvin | 897 | comboBox_slot_enable = false; // comboBox |
132 | pingvin | 898 | if (index != -1) ui->comboBox->setCurrentIndex(index); |
152 | pingvin | 899 | comboBox_slot_enable = true; |
108 | pingvin | 900 | ui->comboBox->setEnabled(true); |
901 | |||
902 | |||
903 | } |
||
106 | pingvin | 904 | // if ((rootItem1) == (item) ) ui->comboBox->setEnabled(true); |
214 | pingvin | 905 | else // |
906 | { |
||
215 | pingvin | 907 | QString class_id; |
908 | QString model_id; |
||
909 | QString filtr_str; |
||
221 | pingvin | 910 | QString inctance; |
219 | pingvin | 911 | QStringList conditionList; |
215 | pingvin | 912 | class_id = item->text(1); |
913 | model_id = item->text(6); |
||
221 | pingvin | 914 | inctance = MainWindow::getClassInctance(class_id); |
915 | |||
217 | pingvin | 916 | filtr_str = tr("`Model_ID` = "); |
215 | pingvin | 917 | filtr_str.append(model_id); |
217 | pingvin | 918 | filtr_str.append(tr(" AND `Class_ID` = ")); |
215 | pingvin | 919 | filtr_str.append(class_id); |
217 | pingvin | 920 | // filtr_str.append(tr("`")); |
215 | pingvin | 921 | |
221 | pingvin | 922 | disconnect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
923 | delete filter_model; |
||
223 | pingvin | 924 | /// filter_model = new MyModel(); |
215 | pingvin | 925 | |
221 | pingvin | 926 | filter_model = new QSqlTableModel(); |
227 | pingvin | 927 | filter_model->setEditStrategy(QSqlTableModel::OnManualSubmit); |
928 | |||
221 | pingvin | 929 | connect(filter_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(on_filter_model_dataChanged(QModelIndex,QModelIndex))); |
930 | filter_model->setTable(tr("Filters")); |
||
931 | filter_model->setFilter(filtr_str); |
||
226 | pingvin | 932 | |
933 | |||
934 | |||
221 | pingvin | 935 | filter_model->select(); |
226 | pingvin | 936 | |
937 | filter_model->sort(0,Qt::AscendingOrder); |
||
938 | |||
221 | pingvin | 939 | ui->tableView_3->setModel(filter_model); |
215 | pingvin | 940 | |
219 | pingvin | 941 | |
942 | ui->tableView_3->hideColumn(0); |
||
943 | ui->tableView_3->hideColumn(1); |
||
944 | ui->tableView_3->hideColumn(2); |
||
945 | |||
946 | |||
947 | filterSpinDelegate.setClassID(class_id); |
||
948 | filterSpinDelegate.getItems(); |
||
949 | ui->tableView_3->setItemDelegateForColumn(4, &filterSpinDelegate); |
||
950 | |||
224 | pingvin | 951 | // ui->tableView_3->setItemDelegate(); |
219 | pingvin | 952 | conditionList <<"" << "and" << "or" << "(" << "and (" << "or ("; |
953 | filterConditionDelegate.setItems(conditionList); |
||
954 | ui->tableView_3->setItemDelegateForColumn(3, &filterConditionDelegate); |
||
955 | |||
956 | conditionList.clear(); |
||
227 | pingvin | 957 | conditionList <<"" << "=" << "<" << ">" << "IS NULL" << "IS NOT NULL"; |
219 | pingvin | 958 | filterConditionDelegate_1.setItems(conditionList); |
959 | ui->tableView_3->setItemDelegateForColumn(5, &filterConditionDelegate_1); |
||
960 | |||
961 | |||
227 | pingvin | 962 | |
963 | |||
228 | pingvin | 964 | conditionList.clear(); |
965 | conditionList <<"" << ")"; |
||
966 | filterConditionDelegate_2.setItems(conditionList); |
||
967 | ui->tableView_3->setItemDelegateForColumn(7, &filterConditionDelegate_2); |
||
227 | pingvin | 968 | |
224 | pingvin | 969 | ui->tableView_3->setItemDelegateForColumn(6, &filterValueDelegate); |
219 | pingvin | 970 | |
224 | pingvin | 971 | |
972 | |||
973 | |||
217 | pingvin | 974 | ui->pushButton_9->setEnabled(true); |
975 | ui->pushButton_10->setEnabled(true); |
||
976 | |||
215 | pingvin | 977 | ui->comboBox->setEnabled(false); |
978 | |||
979 | |||
214 | pingvin | 980 | } |
106 | pingvin | 981 | } |
110 | pingvin | 982 | |
125 | pingvin | 983 | QMap <QString, QString> MainWindow::getFieldsList(QString class_id){ // |
110 | pingvin | 984 | |
125 | pingvin | 985 | } |
142 | pingvin | 986 | |
987 | |||
988 | void MainWindow::initListModelsTablle(){ |
||
149 | pingvin | 989 | model_for_ListModelsTable = new QSqlTableModel(); |
142 | pingvin | 990 | |
991 | model_for_ListModelsTable->setTable(tr("ListOfModels")); |
||
146 | pingvin | 992 | // model_for_ListModelsTable->setEditStrategy(QSqlTableModel::OnFieldChange); |
993 | model_for_ListModelsTable->setEditStrategy(QSqlTableModel::OnManualSubmit); |
||
142 | pingvin | 994 | ui->tableView_2->setModel(model_for_ListModelsTable); |
151 | pingvin | 995 | |
142 | pingvin | 996 | model_for_ListModelsTable->select(); |
151 | pingvin | 997 | |
223 | pingvin | 998 | |
151 | pingvin | 999 | ui->treeWidget->hideColumn(1); |
1000 | ui->treeWidget->hideColumn(2); |
||
1001 | ui->treeWidget->hideColumn(3); |
||
1002 | ui->treeWidget->hideColumn(4); |
||
221 | pingvin | 1003 | // ui->treeWidget->hideColumn(5); |
215 | pingvin | 1004 | ui->treeWidget->hideColumn(6); |
223 | pingvin | 1005 | |
151 | pingvin | 1006 | ui->tableView_2->hideColumn(0); |
1007 | ui->tableView_2->hideColumn(2); |
||
1008 | ui->tableView_2->hideColumn(3); |
||
1009 | ui->tableView_2->hideColumn(4); |
||
1010 | |||
1011 | ui->tableView_2->resizeColumnsToContents(); |
||
1012 | ui->tableView_2->setAlternatingRowColors(true); |
||
1013 | |||
146 | pingvin | 1014 | ui->pushButton_7->setEnabled(false); |
1015 | ui->pushButton_8->setEnabled(false); |
||
151 | pingvin | 1016 | |
1017 | |||
142 | pingvin | 1018 | } |
228 | pingvin | 1019 | |
1020 | void MainWindow::buildReport(bool advanced){ |
||
1021 | |||
1022 | // QTreeWidgetItem * hitm; |
||
1023 | |||
1024 | // hitm = ui->treeWidget_2->headerItem(); |
||
1025 | |||
1026 | // int count = root_items_list.count(); |
||
1027 | |||
1028 | //int count = ui->treeWidget_2->rootIndex(); |
||
1029 | |||
229 | pingvin | 1030 | |
233 | pingvin | 1031 | doc->clear();// |
228 | pingvin | 1032 | |
1033 | int list_count; |
||
1034 | if (rootItems.isEmpty()) return; |
||
1035 | |||
1036 | |||
1037 | |||
1038 | list_count = rootItems.count(); |
||
1039 | |||
1040 | for (int i=0; i < list_count; i++){ |
||
1041 | |||
1042 | getReport(rootItems.at(i), advanced); |
||
1043 | |||
229 | pingvin | 1044 | |
1045 | |||
228 | pingvin | 1046 | } |
233 | pingvin | 1047 | // (bool)QTextDocumentWriter("raport.odt").write(doc); |
228 | pingvin | 1048 | } |
1049 | |||
1050 | |||
1051 | void MainWindow::getReport(QTreeWidgetItem * model_item, bool advanced){ // |
||
1052 | |||
1053 | |||
1054 | // QTextDocument doc; |
||
1055 | // QTextCursor cursor(&doc); |
||
1056 | QTextCharFormat char_fmt; |
||
1057 | bool ok; |
||
1058 | |||
1059 | /************** |
||
1060 | |||
1061 | // char_fmt.setBackground(Qt::red); |
||
1062 | cursor.insertText(tr("1\n"),char_fmt); |
||
1063 | QImage img; |
||
1064 | ok = img.load("./hdd5.png"); |
||
1065 | doc.addResource(QTextDocument::ImageResource, QUrl("myimage"), img); |
||
1066 | cursor.insertImage("myimage"); |
||
1067 | cursor.insertText(tr(" \n"),char_fmt); |
||
1068 | |||
1069 | (bool)QTextDocumentWriter("test.odt").write(&doc); |
||
1070 | ***************/ |
||
1071 | |||
1072 | QString model_name; |
||
1073 | QString rootClassID; |
||
1074 | QString rootClassInctance; |
||
1075 | QFont font; |
||
233 | pingvin | 1076 | QBrush brush; |
228 | pingvin | 1077 | |
233 | pingvin | 1078 | brush.setColor(Qt::darkRed); |
1079 | char_fmt.setForeground(brush); |
||
1080 | font.setBold(true); |
||
1081 | char_fmt.setFont(font); |
||
1082 | |||
228 | pingvin | 1083 | model_name = model_item->text(0); |
1084 | if (model_item->checkState(0) == false) return; // |
||
1085 | |||
1086 | |||
229 | pingvin | 1087 | newPage(); |
1088 | /******************* |
||
1089 | QTextBlockFormat textFormat; |
||
1090 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore); |
||
1091 | cursor->setBlockFormat(textFormat); |
||
1092 | |||
1093 | cursor->insertText(tr(" ")); |
||
1094 | cursor->insertBlock(); |
||
1095 | |||
1096 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_Auto); |
||
1097 | cursor->setBlockFormat(textFormat); |
||
1098 | ********************/ |
||
1099 | |||
1100 | |||
1101 | |||
228 | pingvin | 1102 | if (!(model_item->childCount() > 0)) return; // ( ) |
1103 | |||
1104 | rootClassID = model_item->child(0)->text(1); |
||
1105 | rootClassInctance = getClassInctance(rootClassID); |
||
1106 | |||
233 | pingvin | 1107 | cursor->insertText(model_name, char_fmt); |
228 | pingvin | 1108 | cursor->insertText(tr("\n")); |
1109 | |||
1110 | if (model_item->child(0)->checkState(0)) // ( ), |
||
1111 | { |
||
1112 | ///// QTreeWidgetItem * item_tmp; |
||
1113 | ///// item_tmp = new QTreeWidgetItem(item); // , , |
||
1114 | ///// item_tmp->setText(0, model_item->child(0)->text(0)); // |
||
1115 | |||
1116 | //showClassObjects(item_tmp, model_item->child(0)); // |
||
1117 | |||
1118 | ///// showObjects(item_tmp, model_item->child(0), tr("")); |
||
1119 | printChild(model_item->child(0), tr(""), advanced, 1); |
||
230 | pingvin | 1120 | |
228 | pingvin | 1121 | } |
1122 | |||
1123 | |||
1124 | |||
1125 | |||
1126 | } |
||
1127 | |||
1128 | void MainWindow::printChild(QTreeWidgetItem * model_item, QString filtr, bool advanced, int pos){// |
||
1129 | QString classID; // |
||
1130 | QString parentClassID; // |
||
1131 | QString pointerField; // - |
||
1132 | QString inctance; // , |
||
1133 | QString className; // |
||
1134 | QString modelID; // |
||
1135 | QString add_filtr; // |
||
1136 | int field_ID; |
||
1137 | int icon_field_index; |
||
1138 | bool filtr_empty; |
||
1139 | bool ok; |
||
1140 | QSqlQuery q; |
||
1141 | QString sql_str; |
||
1142 | QString str_tmp; |
||
1143 | QTreeWidgetItem * title_item; |
||
233 | pingvin | 1144 | |
228 | pingvin | 1145 | QIcon icon; |
230 | pingvin | 1146 | QMap<QString, QString> fieldsTypesList;// , |
1147 | //QList<TField> FieldsList; // |
||
228 | pingvin | 1148 | |
229 | pingvin | 1149 | |
1150 | |||
1151 | |||
233 | pingvin | 1152 | // // // font.setBold(true); |
228 | pingvin | 1153 | filtr_empty = filtr.isEmpty(); |
1154 | |||
1155 | classID = model_item->text(1); |
||
1156 | modelID = model_item->text(6); |
||
1157 | add_filtr = MainWindow::getFiltrString(modelID, classID); |
||
1158 | |||
1159 | |||
1160 | icon = model_item->icon(0); |
||
1161 | |||
1162 | parentClassID = model_item->parent()->text(1); |
||
1163 | |||
1164 | pointerField = getPointerFieldName(parentClassID, classID); |
||
1165 | |||
1166 | className = model_item->text(0); |
||
1167 | inctance = getClassInctance(classID); |
||
1168 | |||
1169 | if (!model_item->checkState(0)) return; |
||
1170 | |||
1171 | |||
229 | pingvin | 1172 | |
1173 | |||
233 | pingvin | 1174 | QTextCharFormat charFormatItalic, charFormatBase, charFormatItalicBold, charFormatItalicOnly; |
1175 | QTextTableFormat tableFormat; |
||
1176 | |||
1177 | |||
1178 | // QPen pen; |
||
1179 | QBrush brush; |
||
1180 | QFont font; |
||
1181 | // pen.setColor(Qt::red); |
||
1182 | // charFormatItalic.setTextOutline(pen); |
||
1183 | |||
229 | pingvin | 1184 | //QFont font; |
233 | pingvin | 1185 | |
1186 | brush.setColor(Qt::blue); |
||
1187 | |||
229 | pingvin | 1188 | font.setItalic(true); |
233 | pingvin | 1189 | |
1190 | charFormatItalicOnly.setFont(font); |
||
229 | pingvin | 1191 | //charFormatItalic.setFontItalic(true); |
233 | pingvin | 1192 | |
1193 | font.setBold(true);///////////////// |
||
229 | pingvin | 1194 | charFormatItalic.setFont(font); |
233 | pingvin | 1195 | |
1196 | |||
1197 | charFormatItalic.setForeground(brush); |
||
1198 | |||
1199 | |||
1200 | |||
1201 | charFormatItalicBold.setFont(font); |
||
1202 | charFormatItalicBold.setForeground(brush); |
||
1203 | |||
1204 | |||
1205 | |||
229 | pingvin | 1206 | //charFormatItalic.setFontWeight(16); |
1207 | pos++; |
||
1208 | for(int i=0; i<pos; i++){ cursor->insertText( tr(" "));}// |
||
1209 | cursor->insertText(className, charFormatItalic); |
||
1210 | cursor->setCharFormat(charFormatBase); |
||
228 | pingvin | 1211 | cursor->insertText(tr("\n")); |
1212 | |||
229 | pingvin | 1213 | |
1214 | |||
228 | pingvin | 1215 | sql_str = tr("select * " |
1216 | " from " // - |
||
1217 | ); |
||
1218 | sql_str.append(inctance); |
||
1219 | |||
1220 | |||
1221 | if (filtr.isEmpty() && (!add_filtr.isEmpty())) // , |
||
1222 | { |
||
1223 | filtr.append(tr ("where ")); |
||
1224 | filtr.append(add_filtr); |
||
1225 | } |
||
1226 | |||
1227 | |||
1228 | if (!filtr.isEmpty()) { // |
||
1229 | sql_str.append(tr(" ")); |
||
1230 | sql_str.append(filtr); // |
||
1231 | } |
||
1232 | |||
1233 | q.prepare(sql_str); |
||
1234 | |||
1235 | ok = q.exec(); |
||
1236 | |||
1237 | if (!ok) { |
||
1238 | QString debug_str; |
||
1239 | debug_str.append(tr(" showObjects(): Database Error ")); |
||
1240 | debug_str.append(tr(" : ")); |
||
1241 | debug_str.append(inctance); |
||
1242 | debug_str.append(tr(" : ")); |
||
1243 | debug_str.append(filtr); |
||
1244 | debug_str.append(q.lastError().text()); |
||
1245 | QMessageBox::critical( // . |
||
1246 | this, // . |
||
1247 | QObject::tr(" showObjects(): Database Error"), // . |
||
1248 | debug_str |
||
1249 | // q.lastError().text() |
||
1250 | ); // . |
||
1251 | return; |
||
1252 | } |
||
1253 | |||
1254 | field_ID = q.record().indexOf(tr("ID")); |
||
1255 | |||
1256 | icon_field_index = q.record().indexOf(tr("Icon")); |
||
1257 | |||
229 | pingvin | 1258 | int k=0; |
1259 | QStringList fieldsNamesList;// |
||
230 | pingvin | 1260 | QList<TField> FieldsList; // |
231 | pingvin | 1261 | QMap<QString, TField> fieldsMap;// , - |
1262 | QMap <QString, QString> fieldsValues;// , |
||
230 | pingvin | 1263 | FieldsList = getFieldList(classID); // |
228 | pingvin | 1264 | |
1265 | |||
231 | pingvin | 1266 | |
1267 | |||
1268 | |||
230 | pingvin | 1269 | if(FieldsList.count()>0){ |
1270 | for(int i=0; i < FieldsList.count(); i++){ // ( - ) |
||
1271 | fieldsTypesList.insert(FieldsList.at(i).FieldName, FieldsList.at(i).FieldType); |
||
231 | pingvin | 1272 | fieldsMap.insert(FieldsList.at(i).FieldName, FieldsList.at(i)); |
230 | pingvin | 1273 | } |
229 | pingvin | 1274 | |
230 | pingvin | 1275 | // fieldsNamesList = fieldsTypesList.keys(); // |
1276 | } |
||
1277 | |||
1278 | // icon_field_index = fieldsNamesList.indexOf(tr("Icon"));// |
||
1279 | |||
1280 | |||
1281 | |||
229 | pingvin | 1282 | while(!q.record().fieldName(k).isEmpty()){// |
1283 | fieldsNamesList.append(q.record().fieldName(k++)); |
||
1284 | } |
||
1285 | |||
1286 | |||
230 | pingvin | 1287 | //icon_field_index = fieldsNamesList.indexOf(tr("Icon"));// |
1288 | |||
1289 | |||
228 | pingvin | 1290 | while(q.next()){ |
1291 | if (q.record().count() > 1) |
||
1292 | { |
||
1293 | QString value_tmp; |
||
1294 | QString ID_tmp; |
||
1295 | QString space; |
||
1296 | |||
1297 | // // // // QTreeWidgetItem * itm; |
||
1298 | ID_tmp = q.value(field_ID).toString(); // |
||
1299 | value_tmp = q.value(1).toString(); // ( ) |
||
1300 | // itm = new QTreeWidgetItem(parent_object_item); // , |
||
1301 | |||
1302 | |||
1303 | |||
1304 | |||
1305 | /*************************** |
||
1306 | itm = new QTreeWidgetItem(title_item); // , |
||
1307 | itm->setText(0, value_tmp); |
||
1308 | itm->setText(1, tr("object")); |
||
1309 | itm->setText(2, ID_tmp); |
||
1310 | ******************************/ |
||
1311 | |||
1312 | if (icon_field_index != -1){ // |
||
1313 | |||
1314 | QVariant data; |
||
1315 | QByteArray bytes; |
||
1316 | QPixmap pix; |
||
1317 | QIcon icn; |
||
1318 | QMap <QString, QPixmap> pixmap_map; |
||
1319 | QList <QString> id_list; |
||
1320 | QList <QPixmap> pixmap_list; |
||
1321 | pixmap_map = MainWindow::getObjectsIcon(inctance); |
||
1322 | if (!pixmap_map.isEmpty()) { |
||
1323 | id_list = pixmap_map.keys(); |
||
1324 | pixmap_list = pixmap_map.values(); |
||
1325 | } |
||
1326 | if (id_list.indexOf(ID_tmp) != -1) { |
||
1327 | pix = pixmap_list.at(id_list.indexOf(ID_tmp)); |
||
1328 | } |
||
1329 | // data = q.record().value(icon_field_index); |
||
1330 | // bytes = q.record().value(icon_field_index).toByteArray(); |
||
1331 | // if (data.isValid() && (!data.isNull())) { |
||
1332 | // if (!bytes.isEmpty()){ |
||
1333 | // pix.loadFromData(data.toByteArray()); |
||
1334 | // pix.loadFromData(bytes); |
||
1335 | |||
1336 | |||
1337 | if(!pix.isNull()) { |
||
1338 | if (pix.height() > 128) pix = pix.scaledToHeight(128); |
||
1339 | QString fname = value_tmp; |
||
1340 | fname.append(tr(".png")); |
||
1341 | |||
1342 | |||
1343 | pix.toImage().save(fname); |
||
233 | pingvin | 1344 | doc->addResource(QTextDocument::ImageResource, QUrl(fname), pix.toImage()); |
228 | pingvin | 1345 | |
1346 | // for(int i=0; i<pos; i++){ cursor->insertText( tr(" "));}// |
||
1347 | |||
1348 | |||
229 | pingvin | 1349 | for(int i=0; i<pos+1; i++){ cursor->insertText( tr(" "));}// |
228 | pingvin | 1350 | cursor->insertImage(fname); |
1351 | // cursor->insertText(tr("\n")); |
||
1352 | |||
1353 | } |
||
229 | pingvin | 1354 | else for(int i=0; i<pos+1; i++){ cursor->insertText( tr(" "));}// |
228 | pingvin | 1355 | |
1356 | |||
1357 | |||
1358 | |||
1359 | // // // icn.addPixmap(pix); |
||
1360 | // // // itm->setIcon(0, icn); |
||
1361 | // } |
||
1362 | |||
1363 | |||
1364 | } |
||
1365 | |||
229 | pingvin | 1366 | else for(int i=0; i<pos+1; i++){ cursor->insertText( tr(" "));}// |
228 | pingvin | 1367 | cursor->insertText( value_tmp); |
1368 | cursor->insertText( tr("\n")); |
||
1369 | |||
229 | pingvin | 1370 | |
1371 | |||
230 | pingvin | 1372 | // q.first(); |
229 | pingvin | 1373 | |
1374 | |||
230 | pingvin | 1375 | if(advanced && (fieldsNamesList.count()>0)){ // |
1376 | |||
1377 | QString tmp_string; |
||
229 | pingvin | 1378 | sql_str.clear(); |
1379 | |||
231 | pingvin | 1380 | // // // QTextTable *table = cursor->insertTable(fieldsNamesList.count()-2, 2);// , (ID ) |
229 | pingvin | 1381 | |
1382 | |||
230 | pingvin | 1383 | |
231 | pingvin | 1384 | /************************ |
1385 | QTextTable *table = cursor->insertTable(fieldsNamesList.count(), 2);// , (ID ) |
||
1386 | |||
1387 | ************************/ |
||
1388 | |||
1389 | |||
1390 | |||
1391 | |||
1392 | |||
1393 | |||
1394 | |||
1395 | |||
1396 | |||
1397 | |||
1398 | // cursor->insertText(tr(" ")); |
||
1399 | |||
1400 | |||
230 | pingvin | 1401 | // *cursor = table->cellAt(0,1).firstCursorPosition(); |
1402 | // cursor->insertText(tr(" 2")); |
||
1403 | // *cursor = table->cellAt(1,1).lastCursorPosition(); |
||
1404 | // cursor->insertText(tr(" 4")); |
||
1405 | |||
1406 | |||
1407 | // cursor->movePosition(QTextCursor::End); |
||
1408 | |||
1409 | |||
1410 | |||
1411 | //table->cellAt(1,1).firstCursorPosition().insertText(tr("1")); |
||
1412 | //table->cellAt(1,2).firstCursorPosition().insertText(tr("2")); |
||
1413 | //table->cellAt(2,1).firstCursorPosition().insertText(tr("3")); |
||
1414 | |||
1415 | //table->cellAt(2,2).firstCursorPosition().insertText(tr("4")); |
||
1416 | // cursor->insertText(tr("1 \t 2")); |
||
1417 | // cursor->insertText(tr("3 \t 4")); |
||
1418 | |||
231 | pingvin | 1419 | for(int i=0; i < fieldsNamesList.count(); i++) |
1420 | { |
||
230 | pingvin | 1421 | |
231 | pingvin | 1422 | |
1423 | if (fieldsNamesList.at(i)== tr("Icon") || fieldsNamesList.at(i)== tr("ID")) { tmp_string = tr(" "); |
||
1424 | continue; |
||
1425 | } |
||
1426 | |||
1427 | QString fieldType; |
||
1428 | fieldType = fieldsTypesList.value(fieldsNamesList.at(i)); // |
||
1429 | if(fieldType == tr("pointer")) // - |
||
1430 | { |
||
1431 | QSqlQuery q_tmp; |
||
1432 | QString sql_str; |
||
1433 | // QString val_str; |
||
1434 | QString parent_class_id;// , |
||
1435 | QString parent_class_inctance; // |
||
1436 | bool ok; |
||
1437 | TField field_tmp; |
||
1438 | field_tmp = fieldsMap.value(fieldsNamesList.at(i)); |
||
1439 | parent_class_id = field_tmp.DefaultValue; |
||
1440 | if (parent_class_id.isEmpty()) continue; // id |
||
1441 | else parent_class_inctance = getClassInctance(parent_class_id); |
||
1442 | if (parent_class_inctance.isEmpty()) continue; // id |
||
1443 | sql_str = tr("select * from `"); |
||
1444 | sql_str.append(parent_class_inctance); |
||
1445 | sql_str.append(tr("` where `ID` = '")); |
||
1446 | sql_str.append(q.record().value(i).asString()); |
||
1447 | sql_str.append(tr("'")); |
||
1448 | ok = q_tmp.prepare(sql_str); |
||
1449 | ok = q_tmp.exec(); |
||
1450 | |||
1451 | if (!ok) { |
||
1452 | QString debug_str; |
||
1453 | debug_str.append(tr(" showObjects(): Database Error ")); |
||
1454 | debug_str.append(tr(" : ")); |
||
1455 | debug_str.append(inctance); |
||
1456 | debug_str.append(tr(" : ")); |
||
1457 | debug_str.append(filtr); |
||
1458 | debug_str.append(q.lastError().text()); |
||
1459 | QMessageBox::critical( // . |
||
1460 | this, // . |
||
1461 | QObject::tr(" showObjects(): Database Error"), // . |
||
1462 | debug_str |
||
1463 | // q.lastError().text() |
||
1464 | ); // . |
||
1465 | return; |
||
1466 | } |
||
1467 | |||
1468 | tmp_string.clear(); |
||
1469 | while (q_tmp.next()){ |
||
1470 | tmp_string = q_tmp.record().value(1).asString(); |
||
1471 | |||
1472 | } |
||
1473 | |||
1474 | fieldsValues.insert(fieldsNamesList.at(i), tmp_string);// |
||
1475 | |||
1476 | continue;// |
||
1477 | |||
1478 | } // pointer |
||
1479 | |||
1480 | if(fieldType == tr("file")){ // - , |
||
1481 | |||
1482 | tmp_string = tr(" "); |
||
1483 | continue; |
||
1484 | |||
1485 | } |
||
1486 | |||
1487 | tmp_string = q.record().value(i).asString(); // , -, |
||
1488 | fieldsValues.insert(fieldsNamesList.at(i), tmp_string);// |
||
1489 | |||
1490 | |||
1491 | } |
||
1492 | |||
1493 | |||
1494 | |||
1495 | |||
1496 | |||
233 | pingvin | 1497 | // for(int i=0; i<pos+1; i++){ cursor->insertText( tr(" "));}// |
1498 | tableFormat.setAlignment(Qt::AlignLeft); |
||
1499 | tableFormat.setBackground(QColor("#e0e0e0")); |
||
1500 | // tableFormat.setCellPadding(2); |
||
1501 | // tableFormat.setCellSpacing(4); |
||
1502 | tableFormat.setLeftMargin(pos*7); |
||
1503 | tableFormat.setBorder(1); |
||
1504 | tableFormat.setBorderStyle( QTextFrameFormat::BorderStyle_Solid); |
||
231 | pingvin | 1505 | |
233 | pingvin | 1506 | QTextTable *table = cursor->insertTable(fieldsValues.count(), 2, tableFormat);// , (ID ) |
1507 | // table->setFormat(tableFormat); |
||
1508 | |||
1509 | |||
1510 | for(int i=0; i < fieldsValues.count(); i++){ // : ID , ( ) |
||
231 | pingvin | 1511 | QStringList keys_list = fieldsValues.keys(); |
1512 | QStringList values_list = fieldsValues.values(); |
||
1513 | *cursor = table->cellAt(i,0).firstCursorPosition();// i-, |
||
233 | pingvin | 1514 | cursor->insertText(keys_list.at(i), charFormatItalicOnly);// |
231 | pingvin | 1515 | *cursor = table->cellAt(i,1).firstCursorPosition();// i-, |
1516 | cursor->insertText(values_list.at(i));// |
||
1517 | } |
||
1518 | |||
233 | pingvin | 1519 | // table->setFormat(tableFormat); |
1520 | cursor->movePosition(QTextCursor::End);// |
||
231 | pingvin | 1521 | cursor->insertText( tr("\n")); |
1522 | |||
1523 | |||
1524 | |||
1525 | /****************************** |
||
1526 | |||
1527 | table = cursor->insertTable(fieldsNamesList.count(), 2);// , (ID ) |
||
1528 | |||
230 | pingvin | 1529 | for(int i=2; i < fieldsNamesList.count(); i++){ // : ID , ( ) |
1530 | // if (i !=icon_field_index) tmp_string = q.record().value(i).asString(); // , |
||
1531 | if (i !=icon_field_index) tmp_string = q.record().value(i).asString(); // , |
||
1532 | |||
1533 | |||
1534 | else tmp_string = tr(" "); |
||
1535 | //// if (i !=icon_field_index) { |
||
1536 | for(int i=0; i<pos+2; i++){ cursor->insertText( tr(" "));}// |
||
1537 | *cursor = table->cellAt(i-2,0).firstCursorPosition();// i-, |
||
1538 | cursor->insertText( fieldsNamesList.at(i));// |
||
1539 | *cursor = table->cellAt(i-2,1).firstCursorPosition();// i-, |
||
1540 | //cursor->insertText( tr(":\t")); |
||
1541 | |||
1542 | cursor->insertText(tmp_string);// |
||
1543 | // cursor->insertText( tr("\n")); |
||
1544 | } |
||
1545 | |||
1546 | //// } |
||
231 | pingvin | 1547 | |
1548 | |||
1549 | |||
1550 | |||
1551 | |||
1552 | |||
1553 | |||
1554 | |||
1555 | |||
1556 | |||
230 | pingvin | 1557 | cursor->movePosition(QTextCursor::End);// |
1558 | cursor->insertText( tr("\n")); |
||
231 | pingvin | 1559 | |
1560 | *********************************/ |
||
1561 | |||
229 | pingvin | 1562 | } |
1563 | |||
1564 | |||
1565 | |||
1566 | /******************************************************** |
||
1567 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore); |
||
1568 | cursor->setBlockFormat(textFormat); |
||
1569 | |||
1570 | cursor->insertText(tr(" ")); |
||
1571 | cursor->insertBlock(); |
||
1572 | |||
1573 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_Auto); |
||
1574 | cursor->setBlockFormat(textFormat); |
||
1575 | **********************************************************/ |
||
1576 | |||
1577 | |||
228 | pingvin | 1578 | // itm->setIcon(0, icon); |
1579 | |||
1580 | |||
1581 | for (int i=0; i < model_item->childCount(); i++) // , |
||
1582 | { |
||
1583 | QTreeWidgetItem * model_item_tmp; // |
||
1584 | QString pointer_name; |
||
1585 | QString filtr_tmp; |
||
1586 | bool pointer_isEmpty; |
||
1587 | model_item_tmp = model_item->child(i); // |
||
1588 | pointer_name = getPointerFieldName(classID, model_item->child(i)->text(1)); |
||
1589 | // // // // itm->setText(4, pointer_name); |
||
1590 | |||
1591 | // title_item->setText(4, pointer_name); |
||
1592 | |||
1593 | |||
1594 | pointer_isEmpty = pointer_name.isEmpty(); |
||
1595 | filtr_tmp = tr("where "); |
||
1596 | filtr_tmp.append(tr("`")); |
||
1597 | filtr_tmp.append(pointer_name); |
||
1598 | filtr_tmp.append(tr("` = '")); |
||
1599 | filtr_tmp.append(ID_tmp); |
||
1600 | filtr_tmp.append(tr("'")); |
||
229 | pingvin | 1601 | |
1602 | printChild(model_item_tmp, filtr_tmp, advanced, pos+1); |
||
1603 | |||
228 | pingvin | 1604 | // // // // showObjects(itm, model_item_tmp, filtr_tmp); |
1605 | //MainWindow::showObjectChildrens(ID_tmp, itm, model_item_tmp); |
||
1606 | |||
1607 | } |
||
233 | pingvin | 1608 | // if(pos==2) newPage(); // , |
228 | pingvin | 1609 | |
1610 | } |
||
1611 | |||
1612 | } |
||
1613 | |||
1614 | |||
1615 | |||
1616 | |||
1617 | |||
1618 | |||
1619 | |||
1620 | |||
1621 | |||
1622 | |||
1623 | } |
||
1624 | |||
1625 | |||
229 | pingvin | 1626 | void MainWindow::newPage(int page_number){ // |
1627 | |||
1628 | QTextBlockFormat textFormat; |
||
1629 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore); |
||
1630 | cursor->setBlockFormat(textFormat); |
||
1631 | |||
1632 | cursor->insertText(tr(" %1").arg(page_number)); |
||
1633 | cursor->insertBlock(); |
||
1634 | |||
1635 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_Auto); |
||
1636 | cursor->setBlockFormat(textFormat); |
||
1637 | |||
1638 | |||
1639 | } |
||
1640 | void MainWindow::newPage(){ // |
||
1641 | |||
1642 | QTextBlockFormat textFormat; |
||
1643 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysBefore); |
||
1644 | cursor->setBlockFormat(textFormat); |
||
1645 | |||
1646 | //cursor->insertText(tr(" %1").arg(page_number)); |
||
1647 | cursor->insertBlock(); |
||
1648 | |||
1649 | textFormat.setPageBreakPolicy(QTextFormat::PageBreak_Auto); |
||
1650 | cursor->setBlockFormat(textFormat); |
||
1651 | |||
1652 | |||
1653 | } |
||
230 | pingvin | 1654 | |
1655 | QList<TField> MainWindow::getFieldList(QString class_id){// |
||
1656 | |||
1657 | QSqlQuery q; |
||
1658 | QString sql_str; |
||
1659 | QList<TField> result_list; |
||
1660 | |||
1661 | int field_id, field_name, field_alias, field_type, field_default_value, field_classIdentifer, field_comment; |
||
1662 | |||
1663 | bool ok; |
||
1664 | sql_str = tr("select * " |
||
1665 | " from `DescriptionOfClasses` where `DescriptionOfClasses`.`ClassIdentifer` = " // - |
||
1666 | ); |
||
1667 | |||
1668 | sql_str.append(tr("'")); |
||
1669 | sql_str.append(class_id); |
||
1670 | sql_str.append(tr("' ")); |
||
1671 | ok = q.prepare(sql_str); |
||
1672 | |||
1673 | ok = q.exec(); |
||
1674 | if (!ok) { |
||
1675 | QMessageBox::critical( // . |
||
1676 | this, // . |
||
1677 | QObject::tr("Database Error"), // . |
||
1678 | q.lastError().text()); // . |
||
1679 | return result_list; |
||
1680 | } |
||
1681 | |||
1682 | |||
1683 | field_id = q.record().indexOf(tr("ID")); |
||
1684 | field_name = q.record().indexOf(tr("FieldName")); |
||
1685 | field_alias = q.record().indexOf(tr("FieldAlias")); |
||
1686 | field_type = q.record().indexOf(tr("FieldType")); |
||
1687 | field_default_value = q.record().indexOf(tr("DefaultValue")); |
||
1688 | field_classIdentifer = q.record().indexOf(tr("ClassIdentifer")); |
||
1689 | field_comment = q.record().indexOf(tr("Comment")); |
||
1690 | |||
1691 | while(q.next()){ |
||
1692 | |||
1693 | TField field_tmp; |
||
1694 | field_tmp.ID = q.value(field_id).toString(); |
||
1695 | field_tmp.FieldName = q.value(field_name).toString(); |
||
1696 | field_tmp.FieldAlias = q.value(field_alias).toString(); |
||
1697 | field_tmp.FieldType = q.value(field_type).toString(); |
||
1698 | field_tmp.DefaultValue = q.value(field_default_value).toString(); |
||
1699 | field_tmp.ClassIdentifer = q.value(field_classIdentifer).toString(); |
||
1700 | field_tmp.Comment = q.value(field_comment).toString(); |
||
1701 | result_list << field_tmp; |
||
1702 | |||
1703 | |||
1704 | |||
1705 | |||
1706 | // parentClassID = q.value(field_default_value).toString(); |
||
1707 | // parentClassInctance = getClassInctance(parentClassID); |
||
1708 | // result_map.insert(pointerFieldName, parentClassInctance); |
||
1709 | |||
1710 | |||
1711 | |||
1712 | } |
||
1713 | |||
1714 | return result_list; |
||
1715 | |||
1716 | } |