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