Subversion Repositories OpenInventory

Rev

Rev 219 | Rev 225 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 219 Rev 224
Line 573... Line 573...
573
573
574
574
575
575
576
576
577
577
-
 
578
FilterValueDelegate::FilterValueDelegate(QObject *parent)
-
 
579
    : QItemDelegate(parent)
-
 
580
{
-
 
581
}
-
 
582
//! [0]
-
 
583
-
 
584
void FilterValueDelegate::setClassID(QString newClassID){
-
 
585
    class_id = newClassID;
-
 
586
}
-
 
587
-
 
588
-
 
589
-
 
590
//! [1]
-
 
591
QWidget *FilterValueDelegate::createEditor(QWidget *parent,
-
 
592
    const QStyleOptionViewItem &/* option */,
-
 
593
    const QModelIndex &/* index */) const
-
 
594
{
-
 
595
    QStringList Name_list;
-
 
596
-
 
597
    Name_list = items;
-
 
598
-
 
599
    QComboBox *editor = new QComboBox(parent);
-
 
600
-
 
601
/*
-
 
602
    editor->addItem("0");
-
 
603
    editor->addItem("1");
-
 
604
    editor->addItem("2");
-
 
605
    editor->addItem("3");
-
 
606
    editor->addItem("4");
-
 
607
    editor->addItem("5");
-
 
608
    editor->addItem("6");
-
 
609
    editor->addItem("7");
-
 
610
    editor->addItem("8");
-
 
611
    editor->addItem("9");
-
 
612
*/
-
 
613
-
 
614
//  editor->addItem("0");
-
 
615
-
 
616
// // //    editor->addItems(Name_list);
-
 
617
//    editor->setEditable(false);
-
 
618
    return editor;
-
 
619
}
-
 
620
//! [1]
-
 
621
-
 
622
//! [2]
-
 
623
void FilterValueDelegate::setEditorData(QWidget *editor,
-
 
624
                                    const QModelIndex &index) const
-
 
625
{
-
 
626
   // int value = index.model()->data(index, Qt::EditRole).toInt();
-
 
627
-
 
628
 //   QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
-
 
629
 //   spinBox->setValue(value);
-
 
630
-
 
631
-
 
632
const QAbstractItemModel * model = index.model();
-
 
633
-
 
634
-
 
635
QString value = index.model()->data(index, Qt::EditRole).toString();
-
 
636
QString class_id = index.model()->data(model->index(index.row(),2), Qt::EditRole).toString();
-
 
637
QComboBox *comboBox = static_cast<QComboBox*>(editor);
-
 
638
-
 
639
//QStringList ID_list;
-
 
640
//QStringList Name_list;
-
 
641
int curr_index;
-
 
642
-
 
643
//ID_list = items.keys();
-
 
644
//Name_list = items.values();
-
 
645
-
 
646
curr_index = items.indexOf(value);
-
 
647
if (curr_index==-1) return;
-
 
648
comboBox->setCurrentIndex(curr_index);
-
 
649
/****************************************************
-
 
650
if (value == "0") comboBox->setCurrentIndex(0);
-
 
651
if (value == "1") comboBox->setCurrentIndex(1);
-
 
652
if (value == "2") comboBox->setCurrentIndex(2);
-
 
653
if (value == "3") comboBox->setCurrentIndex(3);
-
 
654
if (value == "4") comboBox->setCurrentIndex(4);
-
 
655
if (value == "5") comboBox->setCurrentIndex(5);
-
 
656
if (value == "6") comboBox->setCurrentIndex(6);
-
 
657
if (value == "7") comboBox->setCurrentIndex(7);
-
 
658
if (value == "8") comboBox->setCurrentIndex(8);
-
 
659
if (value == "9") comboBox->setCurrentIndex(9);
-
 
660
******************************************************/
-
 
661
comboBox->setEditable(false);
-
 
662
-
 
663
-
 
664
//comboBox->setItemText(0, value);
-
 
665
-
 
666
}
-
 
667
//! [2]
-
 
668
-
 
669
//! [3]
-
 
670
void FilterValueDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
-
 
671
                                   const QModelIndex &index) const
-
 
672
{
-
 
673
  //  QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
-
 
674
  //  spinBox->interpretText();
-
 
675
  //  int value = spinBox->value();
-
 
676
-
 
677
  //  model->setData(index, value, Qt::EditRole);
-
 
678
    QStringList ID_list;
-
 
679
    QStringList Name_list;
-
 
680
-
 
681
    QComboBox *comboBox = static_cast<QComboBox*>(editor);
-
 
682
    int currIndex;
-
 
683
    currIndex = comboBox->currentIndex();
-
 
684
    if (currIndex==-1) return;
-
 
685
  //  QString value = comboBox->itemText(currIndex);
-
 
686
-
 
687
    // ID_list = items.keys();
-
 
688
    // Name_list = items.values();
-
 
689
-
 
690
 //   QString value = ID_list.at(currIndex);
-
 
691
    QString value = items.at(currIndex);
-
 
692
    model->setData(index, value, Qt::EditRole);
-
 
693
}
-
 
694
//! [3]
-
 
695
-
 
696
//! [4]
-
 
697
void FilterValueDelegate::updateEditorGeometry(QWidget *editor,
-
 
698
    const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
-
 
699
{
-
 
700
    editor->setGeometry(option.rect);
-
 
701
}
-
 
702
-
 
703
-
 
704
-
 
705
-
 
706
-
 
707
-
 
708
-
 
709
-
 
710
-
 
711
-
 
712
-
 
713
-
 
714
-
 
715
-
 
716
578
//! [4]
717
//! [4]
579
MyDEDelegate::MyDEDelegate(
718
MyDEDelegate::MyDEDelegate(
580
                       bool calpopup,
719
                       bool calpopup,
581
                       QObject *parent)
720
                       QObject *parent)
582
               : QItemDelegate(parent),
721
               : QItemDelegate(parent),