Хранилища Subversion OpenInventory

Редакция

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

Редакция Автор № строки Строка
66 pingvin 1
#include "delegateforclassestable.h"
2
#include <QtGui>
3
 
4
DelegateForClassesTable::DelegateForClassesTable(QObject *parent) :
5
    QItemDelegate(parent)
6
{
7
    items.append(tr("CHAR(10)"));
67 pingvin 8
    items.append(tr("CHAR(30)"));
66 pingvin 9
    items.append(tr("INT(10)"));
77 pingvin 10
    items.append(tr("DATE"));
137 pingvin 11
    items.append(tr("BLOB"));
66 pingvin 12
}
13
QWidget *DelegateForClassesTable::createEditor(QWidget *parent,
14
    const QStyleOptionViewItem &/* option */,
15
    const QModelIndex &/* index */) const
16
{
17
    //QSpinBox *editor = new QSpinBox(parent);
18
    //editor->setMinimum(0);
19
    //editor->setMaximum(100);
20
    QComboBox *editor = new QComboBox(parent);
21
    editor->addItems(items);
22
 
23
    /*
24
    editor->addItem("0");
25
    editor->addItem("1");
26
    editor->addItem("2");
27
    editor->addItem("3");
28
    editor->addItem("4");
29
    editor->addItem("5");
30
    editor->addItem("6");
31
    editor->addItem("7");
32
    editor->addItem("8");
33
    editor->addItem("9");
34
  //  editor->addItem("0");
35
    */
36
 
37
    return editor;
38
}
39
//! [1]
40
 
41
//! [2]
42
void DelegateForClassesTable::setEditorData(QWidget *editor,
43
                                    const QModelIndex &index) const
44
{
45
   // int value = index.model()->data(index, Qt::EditRole).toInt();
46
 
47
 //   QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
48
 //   spinBox->setValue(value);
49
QString value = index.model()->data(index, Qt::EditRole).toString();
50
QComboBox *comboBox = static_cast<QComboBox*>(editor);
51
int curr_index = items.indexOf(value);
52
if (curr_index!= -1) comboBox->setCurrentIndex(curr_index);
67 pingvin 53
else {
54
 
55
}
66 pingvin 56
/*
57
if (value == "0") comboBox->setCurrentIndex(0);
58
if (value == "1") comboBox->setCurrentIndex(1);
59
if (value == "2") comboBox->setCurrentIndex(2);
60
if (value == "3") comboBox->setCurrentIndex(3);
61
if (value == "4") comboBox->setCurrentIndex(4);
62
if (value == "5") comboBox->setCurrentIndex(5);
63
if (value == "6") comboBox->setCurrentIndex(6);
64
if (value == "7") comboBox->setCurrentIndex(7);
65
if (value == "8") comboBox->setCurrentIndex(8);
66
if (value == "9") comboBox->setCurrentIndex(9);
67
*/
67 pingvin 68
comboBox->setEditable(false);
66 pingvin 69
 
70
 
71
//comboBox->setItemText(0, value);
72
 
73
}
74
//! [2]
75
 
76
//! [3]
77
void DelegateForClassesTable::setModelData(QWidget *editor, QAbstractItemModel *model,
78
                                   const QModelIndex &index) const
79
{
80
  //  QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
81
  //  spinBox->interpretText();
82
  //  int value = spinBox->value();
83
 
84
  //  model->setData(index, value, Qt::EditRole);
85
 
86
    QComboBox *comboBox = static_cast<QComboBox*>(editor);
87
    int currIndex;
88
    currIndex = comboBox->currentIndex();
89
    QString value = comboBox->itemText(currIndex);
90
    model->setData(index, value, Qt::EditRole);
91
}
92
//! [3]
93
 
94
//! [4]
95
void DelegateForClassesTable::updateEditorGeometry(QWidget *editor,
96
    const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
97
{
98
    editor->setGeometry(option.rect);
99
}
100
//! [4]
67 pingvin 101
 
102
 
103
void DelegateForClassesTable::setItems(QStringList new_items){
104
 
105
    DelegateForClassesTable::items =  new_items;
106
 
107
}