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