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