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