Хранилища Subversion OpenInventory

Редакция

Редакция 236 | Редакция 238 | К новейшей редакции | Содержимое файла | Сравнить с предыдущей | Последнее изменение | Открыть журнал | RSS

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