Subversion Repositories OpenInventory

Rev

Rev 144 | Rev 146 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 144 Rev 145
Line 6... Line 6...
6
    ui(new Ui::MainWindow)
6
    ui(new Ui::MainWindow)
7
{
7
{
8
    ui->setupUi(this);
8
    ui->setupUi(this);
9
   // connect( ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(on_currentIndexChanged(int)));
9
   // connect( ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(on_currentIndexChanged(int)));
10
    model_is_build = false;
10
    model_is_build = false;
11
   MainWindow::readModel();
11
   // MainWindow::readModel();
12
12
13
   //QString model_str;
13
   //QString model_str;
14
14
15
15
16
   /*
16
   /*
Line 32... Line 32...
32
32
33
    MainWindow::openDataBase();
33
    MainWindow::openDataBase();
34
34
35
    MainWindow::initComboBox();
35
    MainWindow::initComboBox();
36
36
37
    MainWindow::buildPreviewModel(tr("Ìîÿ ìîäåëü"), tr("7"));
37
//    MainWindow::buildPreviewModel(tr("Ìîÿ ìîäåëü"), tr("11"));
38
38
39
    MainWindow::initListModelsTablle();
39
    MainWindow::initListModelsTablle();
40
40
41
    MainWindow::readModels();
41
    MainWindow::readModels();
42
42
43
    MainWindow::creatModelString();
43
 //   MainWindow::creatModelString();
44
    //int i;
44
    //int i;
45
    //i++;
45
    //i++;
-
 
46
-
 
47
    /*
46
     QFile file_tmp("./modelstring.txt");
48
    QFile file_tmp("./modelstring.txt");
47
     bool ok;
49
     bool ok;
48
     file_tmp.remove();
50
     file_tmp.remove();
49
     ok = file_tmp.open(QIODevice::ReadWrite | QIODevice::Text);
51
     ok = file_tmp.open(QIODevice::ReadWrite | QIODevice::Text);
50
     QTextStream out(&file_tmp);
52
     QTextStream out(&file_tmp);
51
     out.setCodec("cp1251");
53
     out.setCodec("cp1251");
52
     out << MainWindow::modelString;
54
     out << MainWindow::modelString;
53
     file_tmp.close();
55
     file_tmp.close();
54
56
    */
55
57
56
58
57
59
58
    getDatabaseData();
60
    getDatabaseData();
59
    //// sql_mogel = new QSqlTableModel();
61
    //// sql_mogel = new QSqlTableModel();
Line 254... Line 256...
254
256
255
    MainWindow::modelString.clear(); // î÷èùàåì ñòðîêó ìîäåëè
257
    MainWindow::modelString.clear(); // î÷èùàåì ñòðîêó ìîäåëè
256
 //   for (int i =0; i < rootItem1->childCount(); ++i )
258
 //   for (int i =0; i < rootItem1->childCount(); ++i )
257
259
258
    {MainWindow::addChildsString(rootItem1, 0);}
260
    {MainWindow::addChildsString(rootItem1, 0);}
-
 
261
// {MainWindow::addChildsString(ui->treeWidget, 0);}
259
262
 /*
260
    int root_item_child_count;
263
    int root_item_child_count;
261
    int i;
264
    int i;
262
    root_item_child_count = rootItem1->childCount();
265
    root_item_child_count = rootItem1->childCount();
263
    i++;
266
    i++;
264
267
*/
265
}
268
}
266
269
267
270
268
void MainWindow::addChildsString(QTreeWidgetItem *parentItem, int level){
271
void MainWindow::addChildsString(QTreeWidgetItem *parentItem, int level){
269
    int child_count;
272
    int child_count;
Line 363... Line 366...
363
366
364
//ui->treeWidget->clear();
367
//ui->treeWidget->clear();
365
368
366
root_class_name = MainWindow::ClassName(rootClassID); // îïðåäåëÿåì èìÿ êëàññà
369
root_class_name = MainWindow::ClassName(rootClassID); // îïðåäåëÿåì èìÿ êëàññà
367
370
-
 
371
368
rootItem1 = new  QTreeWidgetItem(ui->treeWidget);
372
rootItem1 = new  QTreeWidgetItem(ui->treeWidget);
369
root_items_list << rootItem1;
373
 root_items_list << rootItem1;
370
 rootItem1->setText(0, modelName);
374
 rootItem1->setText(0, modelName);
371
375
372
 rootItem1->setCheckState(0,Qt::Checked);
376
 rootItem1->setCheckState(0,Qt::Checked);
373
 rootItems.append(rootItem1);
377
 rootItems.append(rootItem1);
374
378
375
379
376
380
377
rootItem2 = new  QTreeWidgetItem(rootItem1);
381
 rootItem2 = new  QTreeWidgetItem(rootItem1);
378
rootItem2->setText(0, root_class_name);
382
 rootItem2->setText(0, root_class_name);
379
rootItem2->setText(1, rootClassID);
383
 rootItem2->setText(1, rootClassID);
380
rootItem2->setCheckState(0,Qt::Checked);
384
 rootItem2->setCheckState(0,Qt::Checked);
381
385
382
addChildsItems(rootItem2);
386
 addChildsItems(rootItem2);
-
 
387
-
 
388
-
 
389
/*
383
390

384
sql_str = tr("select * "
391
sql_str = tr("select * "
385
             " from DescriptionOfClasses where  DescriptionOfClasses.DefaultValue = '"       //îïðåäåëèì êëàññû, äëÿ êîòîðûõ êîðíåâîé ÿâëÿåòñÿ êîíòåéíåðîì
392
             " from DescriptionOfClasses where  DescriptionOfClasses.DefaultValue = '"       //îïðåäåëèì êëàññû, äëÿ êîòîðûõ êîðíåâîé ÿâëÿåòñÿ êîíòåéíåðîì
386
             );
393
             );
387
sql_str.append(rootClassID);
394
sql_str.append(rootClassID);
Line 405... Line 412...
405
                }
412
                }
406
413

407
414

408
415

409
416

-
 
417
*/
-
 
418
-
 
419
410
}
420
}
411
421
412
422
413
bool MainWindow::rebuildPreviewModel(QTreeWidgetItem* root_item, QString rootClassID){
423
bool MainWindow::rebuildPreviewModel(QTreeWidgetItem* root_item, QString rootClassID){
414
QSqlQuery q;
424
QSqlQuery q;
Line 429... Line 439...
429
439
430
// rootItem1->setCheckState(0,Qt::Checked);
440
// rootItem1->setCheckState(0,Qt::Checked);
431
// rootItems.append(rootItem1);
441
// rootItems.append(rootItem1);
432
442
433
// root_item->removeChild(root_item->child(0)); // î÷èùàåì ñïèñîê äî÷åðíèõ êëàññîâ
443
// root_item->removeChild(root_item->child(0)); // î÷èùàåì ñïèñîê äî÷åðíèõ êëàññîâ
434
if (root_item->childCount()==1){
444
if (root_item->childCount()==0){ // íåò êîðíåâîãî êëàññà, ñîçäàäèì åãî
-
 
445
    QTreeWidgetItem* item_tmp;
-
 
446
    item_tmp = new QTreeWidgetItem (root_item);
-
 
447
-
 
448
}
-
 
449
-
 
450
if (root_item->childCount()==1){ // êîðíåâîé êëàññ åñòü è îí ïóñòîé, î÷èùàòü åãî íå íàäî
435
root_item->child(0)->setText(0, root_class_name);
451
root_item->child(0)->setText(0, root_class_name);
436
root_item->child(0)->setText(1, rootClassID);
452
root_item->child(0)->setText(1, rootClassID);
437
root_item->child(0)->setCheckState(0,Qt::Checked);}
453
root_item->child(0)->setCheckState(0,Qt::Checked);}
438
454
-
 
455
-
 
456
439
//delete rootItem2;
457
//delete rootItem2;
440
458
441
459
442
// rootItem2 = new  QTreeWidgetItem(rootItem1);
460
// rootItem2 = new  QTreeWidgetItem(rootItem1);
443
461
Line 448... Line 466...
448
// rootItem2->setCheckState(0,Qt::Checked);
466
// rootItem2->setCheckState(0,Qt::Checked);
449
467
450
int child_count = root_item->child(0)->childCount();
468
int child_count = root_item->child(0)->childCount();
451
469
452
470
453
-
 
454
for (int i=0; i < child_count; i++){
471
for (int i=0; i < child_count; i++){ // åñëè êîðíåâîé êëàññ åñòü è íå ïóñòîé, î÷èùàåì åãî
455
    root_item->child(0)->removeChild(root_item->child(0)->child(0));
472
    root_item->child(0)->removeChild(root_item->child(0)->child(0));
456
}
473
}
457
474
458
child_count = root_item->child(0)->childCount();
475
child_count = root_item->child(0)->childCount();
459
addChildsItems(root_item->child(0));
476
addChildsItems(root_item->child(0));
Line 677... Line 694...
677
694
678
classesID_list = class_list_map.keys();
695
classesID_list = class_list_map.keys();
679
classesNameList = class_list_map.values();
696
classesNameList = class_list_map.values();
680
ID_str =  classesID_list[index];
697
ID_str =  classesID_list[index];
681
ui->label->setText(ID_str);
698
ui->label->setText(ID_str);
682
if (root_items_list.indexOf(ui->treeWidget->currentItem()) != -1) rebuildPreviewModel(ui->treeWidget->currentItem(), ID_str);
699
if (root_items_list.indexOf(ui->treeWidget->currentItem()) != -1)
-
 
700
{
-
 
701
    model_is_build = false; // ÷òîáû íå âûçûâàëîñü ñîáûòèå on_treeWidget_itemChanged
-
 
702
    rebuildPreviewModel(ui->treeWidget->currentItem(), ID_str);
-
 
703
    model_is_build = true; // òåïåðü ïóñòü âûçûâàåòñÿ
-
 
704
}
683
getDatabaseData();
705
    getDatabaseData();
684
706
685
707
686
}
708
}
687
709
688
void MainWindow::on_treeWidget_itemChanged ( QTreeWidgetItem * item, int column ){
710
void MainWindow::on_treeWidget_itemChanged ( QTreeWidgetItem * item, int column ){
Line 702... Line 724...
702
        QStringList classesID_list;
724
        QStringList classesID_list;
703
725
704
        int index;
726
        int index;
705
        classesID_list = class_list_map.keys();
727
        classesID_list = class_list_map.keys();
706
        classesNameList = class_list_map.values();
728
        classesNameList = class_list_map.values();
707
        index = classesID_list.indexOf(item->child(0)->text(1));
729
        if (item->childCount()>0) index = classesID_list.indexOf(item->child(0)->text(1)); // åñëè ìîäåëü íå ïóñòàÿ, óçíàåì êîðíåâîé êëàññ
-
 
730
        else { // åñëè ïóñòàÿ
-
 
731
        ui->comboBox->setEnabled(true);
-
 
732
        return;
-
 
733
-
 
734
        }
708
        if (index != -1) ui->comboBox->setCurrentIndex(index);
735
        if (index != -1) ui->comboBox->setCurrentIndex(index);
709
736
710
        ui->comboBox->setEnabled(true);
737
        ui->comboBox->setEnabled(true);
711
738
712
739