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