Хранилища Subversion OpenInventory

Редакция

Редакция 224 | Редакция 226 | К новейшей редакции | Весь файл | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS

Редакция 224 Редакция 225
Строка 585... Строка 585...
585
    class_id = newClassID;
585
    class_id = newClassID;
586
}
586
}
587
587
588
588
589
589
-
 
590
// ïîëó÷àåì èìÿ òàáëèöû - õðàíèëèùà îáúåêòîâ êëàññà
-
 
591
QString FilterValueDelegate::getClassInctanc(QString class_id){
-
 
592
-
 
593
-
 
594
-
 
595
-
 
596
    QSqlQuery q;
-
 
597
    QString sql_str;
-
 
598
    QString result;
-
 
599
    QString classInctance;
-
 
600
    int field_inctance;
-
 
601
    bool ok;
-
 
602
    sql_str = tr("select * "
-
 
603
                 " from ListOfClasses where  ListOfClasses.ID = '"       //îïðåäåëèì êëàññû, äëÿ êîòîðûõ êîðíåâîé ÿâëÿåòñÿ êîíòåéíåðîì
-
 
604
                 );
-
 
605
    sql_str.append(class_id);
-
 
606
     sql_str.append(tr("'"));
-
 
607
    q.prepare(sql_str);
-
 
608
-
 
609
    ok = q.exec();
-
 
610
-
 
611
    if (!ok) return result;
-
 
612
-
 
613
    /*
-
 
614
    if (!ok) {
-
 
615
                            QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
-
 
616
                                                                            this,                      // Ðîäèòåëüñêèé âèäæåò.
-
 
617
                                                                            QObject::tr("Database Error"),   // Çàãîëîâîê.
-
 
618
                                                                            q.lastError().text());          // Òåêñò ñîîáùåíèÿ.
-
 
619
                                                                            return result;
-
 
620
                     }
-
 
621

-
 
622
   */
-
 
623
-
 
624
-
 
625
-
 
626
-
 
627
    field_inctance = q.record().indexOf(tr("TableWhithInstance"));
-
 
628
    while(q.next()){
-
 
629
-
 
630
                  classInctance = q.value(field_inctance).toString();
-
 
631
                  result.append(classInctance);
-
 
632
                  }
-
 
633
-
 
634
  return result;
-
 
635
-
 
636
-
 
637
-
 
638
-
 
639
-
 
640
}
-
 
641
-
 
642
-
 
643
-
 
644
 QString grtFieldType(QString class_id, QString fieldName)//îïðåäåëÿåì òèï äàííûõ ïîëÿ
-
 
645
 {
-
 
646
-
 
647
 }
-
 
648
-
 
649
590
//! [1]
650
//! [1]
591
QWidget *FilterValueDelegate::createEditor(QWidget *parent,
651
QWidget *FilterValueDelegate::createEditor(QWidget *parent,
592
    const QStyleOptionViewItem &/* option */,
652
    const QStyleOptionViewItem &/* option */,
593
    const QModelIndex &/* index */) const
653
    const QModelIndex &/* index */) const
594
{
654
{
Строка 612... Строка 672...
612
*/
672
*/
613
673
614
//  editor->addItem("0");
674
//  editor->addItem("0");
615
675
616
// // //    editor->addItems(Name_list);
676
// // //    editor->addItems(Name_list);
617
//    editor->setEditable(false);
677
    editor->setEditable(true);
618
    return editor;
678
    return editor;
619
}
679
}
620
//! [1]
680
//! [1]
621
681
-
 
682
-
 
683
-
 
684
-
 
685
-
 
686
-
 
687
-
 
688
-
 
689
-
 
690
622
//! [2]
691
//! [2]
623
void FilterValueDelegate::setEditorData(QWidget *editor,
692
void FilterValueDelegate::setEditorData(QWidget *editor,
624
                                    const QModelIndex &index) const
693
                                    const QModelIndex &index) const
625
{
694
{
626
   // int value = index.model()->data(index, Qt::EditRole).toInt();
695
   // int value = index.model()->data(index, Qt::EditRole).toInt();
Строка 633... Строка 702...
633
702
634
703
635
QString value = index.model()->data(index, Qt::EditRole).toString();
704
QString value = index.model()->data(index, Qt::EditRole).toString();
636
QString class_id = index.model()->data(model->index(index.row(),2), Qt::EditRole).toString();
705
QString class_id = index.model()->data(model->index(index.row(),2), Qt::EditRole).toString();
637
QComboBox *comboBox = static_cast<QComboBox*>(editor);
706
QComboBox *comboBox = static_cast<QComboBox*>(editor);
-
 
707
QString inctance; //õðàíèëèùå îáúåêòîâ êëàññà
-
 
708
QString fieldName;//èìÿ ïîëÿ
-
 
709
QSqlQuery q;
-
 
710
QString sql_str;
-
 
711
QStringList itemsList;
-
 
712
bool ok;
-
 
713
-
 
714
-
 
715
-
 
716
fieldName = index.model()->data(model->index(index.row(),4), Qt::EditRole).toString();
-
 
717
-
 
718
-
 
719
inctance = FilterValueDelegate::getClassInctanc(class_id);
-
 
720
if (!inctance.isEmpty() && !fieldName.isEmpty()){
-
 
721
sql_str = tr("select `");
-
 
722
sql_str.append(fieldName);
-
 
723
sql_str.append(tr("` from `"));
-
 
724
sql_str.append(inctance);
-
 
725
sql_str.append(tr("`"));
-
 
726
ok = q.prepare(sql_str);
-
 
727
ok = q.exec();
-
 
728
-
 
729
while(q.next()){
-
 
730
QString tmp_str;
-
 
731
tmp_str = q.record().value(fieldName).asString();
-
 
732
itemsList.append(tmp_str);
-
 
733
FilterValueDelegate::items.append(tmp_str);
-
 
734
        }
-
 
735
if(!itemsList.isEmpty()) {
-
 
736
                            comboBox->addItems(itemsList);
-
 
737
                            items = itemsList; // ãëîáàëüãàÿ ïåðåìåííàÿ
-
 
738
                         }
-
 
739
-
 
740
}
-
 
741
-
 
742
-
 
743
-
 
744
638
745
639
//QStringList ID_list;
746
//QStringList ID_list;
640
//QStringList Name_list;
747
//QStringList Name_list;
641
int curr_index;
748
int curr_index;
642
749
643
//ID_list = items.keys();
750
//ID_list = items.keys();
644
//Name_list = items.values();
751
//Name_list = items.values();
645
752
646
curr_index = items.indexOf(value);
753
curr_index = itemsList.indexOf(value);
647
if (curr_index==-1) return;
754
if (curr_index==-1) return;
648
comboBox->setCurrentIndex(curr_index);
755
comboBox->setCurrentIndex(curr_index);
649
/****************************************************
756
/****************************************************
650
if (value == "0") comboBox->setCurrentIndex(0);
757
if (value == "0") comboBox->setCurrentIndex(0);
651
if (value == "1") comboBox->setCurrentIndex(1);
758
if (value == "1") comboBox->setCurrentIndex(1);
Строка 656... Строка 763...
656
if (value == "6") comboBox->setCurrentIndex(6);
763
if (value == "6") comboBox->setCurrentIndex(6);
657
if (value == "7") comboBox->setCurrentIndex(7);
764
if (value == "7") comboBox->setCurrentIndex(7);
658
if (value == "8") comboBox->setCurrentIndex(8);
765
if (value == "8") comboBox->setCurrentIndex(8);
659
if (value == "9") comboBox->setCurrentIndex(9);
766
if (value == "9") comboBox->setCurrentIndex(9);
660
******************************************************/
767
******************************************************/
661
comboBox->setEditable(false);
768
comboBox->setEditable(true);
662
769
663
770
664
//comboBox->setItemText(0, value);
771
//comboBox->setItemText(0, value);
665
772
666
}
773
}
Строка 673... Строка 780...
673
  //  QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
780
  //  QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
674
  //  spinBox->interpretText();
781
  //  spinBox->interpretText();
675
  //  int value = spinBox->value();
782
  //  int value = spinBox->value();
676
783
677
  //  model->setData(index, value, Qt::EditRole);
784
  //  model->setData(index, value, Qt::EditRole);
-
 
785
678
    QStringList ID_list;
786
    QStringList ID_list;
679
    QStringList Name_list;
787
    QStringList Name_list;
680
788
681
    QComboBox *comboBox = static_cast<QComboBox*>(editor);
789
    QComboBox *comboBox = static_cast<QComboBox*>(editor);
682
    int currIndex;
790
    int currIndex;
Строка 688... Строка 796...
688
    // Name_list = items.values();
796
    // Name_list = items.values();
689
797
690
 //   QString value = ID_list.at(currIndex);
798
 //   QString value = ID_list.at(currIndex);
691
    QString value = items.at(currIndex);
799
    QString value = items.at(currIndex);
692
    model->setData(index, value, Qt::EditRole);
800
    model->setData(index, value, Qt::EditRole);
-
 
801
-
 
802
693
}
803
}
-
 
804
-
 
805
-
 
806
-
 
807
-
 
808
-
 
809
-
 
810
-
 
811
694
//! [3]
812
//! [3]
695
813
696
//! [4]
814
//! [4]
697
void FilterValueDelegate::updateEditorGeometry(QWidget *editor,
815
void FilterValueDelegate::updateEditorGeometry(QWidget *editor,
698
    const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
816
    const QStyleOptionViewItem &option, const QModelIndex &/* index */) const