Хранилища Subversion OpenInventory

Редакция

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