Редакция 53 | Редакция 161 | К новейшей редакции | Весь файл | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 53 | Редакция 134 | ||
---|---|---|---|
Строка 54... | Строка 54... | ||
54 | 54 | ||
55 | //! [0]
|
55 | //! [0]
|
56 | SpinBoxDelegate::SpinBoxDelegate(QObject *parent) |
56 | SpinBoxDelegate::SpinBoxDelegate(QObject *parent) |
57 | : QItemDelegate(parent) |
57 | : QItemDelegate(parent) |
58 | {
|
58 | {
|
- | 59 | // SpinBoxDelegate::getItems();
|
|
59 | }
|
60 | }
|
60 | //! [0]
|
61 | //! [0]
|
61 | 62 | ||
62 | //! [1]
|
63 | //! [1]
|
63 | QWidget *SpinBoxDelegate::createEditor(QWidget *parent, |
64 | QWidget *SpinBoxDelegate::createEditor(QWidget *parent, |
64 | const QStyleOptionViewItem &/* option */, |
65 | const QStyleOptionViewItem &/* option */, |
65 | const QModelIndex &/* index */) const |
66 | const QModelIndex &/* index */) const |
66 | {
|
67 | {
|
- | 68 | QStringList ID_list;
|
|
67 | //QSpinBox *editor = new QSpinBox(parent);
|
69 | QStringList Name_list;
|
- | 70 | ||
- | 71 | // getItems();
|
|
- | 72 | ||
- | 73 | ||
- | 74 | ||
- | 75 | ||
- | 76 | ||
68 | //editor->setMinimum(0);
|
77 | ID_list = items.keys(); |
69 | //editor->setMaximum(100);
|
78 | Name_list = items.values(); |
- | 79 | ||
70 | QComboBox *editor = new QComboBox(parent); |
80 | QComboBox *editor = new QComboBox(parent); |
- | 81 | ||
- | 82 | /*
|
|
71 | editor->addItem("0"); |
83 | editor->addItem("0");
|
72 | editor->addItem("1"); |
84 | editor->addItem("1");
|
73 | editor->addItem("2"); |
85 | editor->addItem("2");
|
74 | editor->addItem("3"); |
86 | editor->addItem("3");
|
75 | editor->addItem("4"); |
87 | editor->addItem("4");
|
76 | editor->addItem("5"); |
88 | editor->addItem("5");
|
77 | editor->addItem("6"); |
89 | editor->addItem("6");
|
78 | editor->addItem("7"); |
90 | editor->addItem("7");
|
79 | editor->addItem("8"); |
91 | editor->addItem("8");
|
80 | editor->addItem("9"); |
92 | editor->addItem("9");
|
- | 93 | */
|
|
- | 94 | ||
81 | // editor->addItem("0");
|
95 | // editor->addItem("0");
|
82 | 96 | ||
- | 97 | editor->addItems(Name_list); |
|
83 | return editor; |
98 | return editor; |
84 | }
|
99 | }
|
85 | //! [1]
|
100 | //! [1]
|
86 | 101 | ||
87 | //! [2]
|
102 | //! [2]
|
88 | void SpinBoxDelegate::setEditorData(QWidget *editor, |
103 | void SpinBoxDelegate::setEditorData(QWidget *editor, |
89 | const QModelIndex &index) const |
104 | const QModelIndex &index) const |
90 | {
|
105 | {
|
91 | // int value = index.model()->data(index, Qt::EditRole).toInt();
|
106 | QString value = index.model()->data(index, Qt::EditRole).toString(); |
- | 107 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
|
92 | 108 | ||
- | 109 | QStringList ID_list;
|
|
93 | // QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
110 | QStringList Name_list;
|
- | 111 | int curr_index; |
|
- | 112 | ||
- | 113 | ID_list = items.keys(); |
|
94 | // spinBox->setValue(value);
|
114 | Name_list = items.values(); |
- | 115 | ||
95 | QString value = index.model()->data(index, Qt::EditRole).toString(); |
116 | curr_index = ID_list.indexOf(value); |
96 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
117 | comboBox->setCurrentIndex(curr_index); |
- | 118 | /****************************************************
|
|
97 | if (value == "0") comboBox->setCurrentIndex(0); |
119 | if (value == "0") comboBox->setCurrentIndex(0);
|
98 | if (value == "1") comboBox->setCurrentIndex(1); |
120 | if (value == "1") comboBox->setCurrentIndex(1);
|
99 | if (value == "2") comboBox->setCurrentIndex(2); |
121 | if (value == "2") comboBox->setCurrentIndex(2);
|
100 | if (value == "3") comboBox->setCurrentIndex(3); |
122 | if (value == "3") comboBox->setCurrentIndex(3);
|
101 | if (value == "4") comboBox->setCurrentIndex(4); |
123 | if (value == "4") comboBox->setCurrentIndex(4);
|
102 | if (value == "5") comboBox->setCurrentIndex(5); |
124 | if (value == "5") comboBox->setCurrentIndex(5);
|
103 | if (value == "6") comboBox->setCurrentIndex(6); |
125 | if (value == "6") comboBox->setCurrentIndex(6);
|
104 | if (value == "7") comboBox->setCurrentIndex(7); |
126 | if (value == "7") comboBox->setCurrentIndex(7);
|
105 | if (value == "8") comboBox->setCurrentIndex(8); |
127 | if (value == "8") comboBox->setCurrentIndex(8);
|
106 | if (value == "9") comboBox->setCurrentIndex(9); |
128 | if (value == "9") comboBox->setCurrentIndex(9);
|
- | 129 | ******************************************************/
|
|
107 | comboBox->setEditable(true); |
130 | comboBox->setEditable(true); |
108 | 131 | ||
109 | 132 | ||
110 | //comboBox->setItemText(0, value);
|
133 | //comboBox->setItemText(0, value);
|
111 | 134 | ||
112 | }
|
135 | }
|
Строка 114... | Строка 137... | ||
114 | 137 | ||
115 | //! [3]
|
138 | //! [3]
|
116 | void SpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, |
139 | void SpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, |
117 | const QModelIndex &index) const |
140 | const QModelIndex &index) const |
118 | {
|
141 | {
|
119 | // QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
- | |
120 | // spinBox->interpretText();
|
142 | QStringList ID_list;
|
121 | // int value = spinBox->value();
|
143 | QStringList Name_list;
|
122 | - | ||
123 | // model->setData(index, value, Qt::EditRole);
|
- | |
124 | 144 | ||
125 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
145 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
126 | int currIndex; |
146 | int currIndex; |
127 | currIndex = comboBox->currentIndex(); |
147 | currIndex = comboBox->currentIndex(); |
128 | QString value = comboBox->itemText(currIndex); |
148 | // QString value = comboBox->itemText(currIndex);
|
- | 149 | ||
- | 150 | ID_list = items.keys(); |
|
- | 151 | Name_list = items.values(); |
|
- | 152 | ||
- | 153 | QString value = ID_list.at(currIndex); |
|
129 | model->setData(index, value, Qt::EditRole); |
154 | model->setData(index, value, Qt::EditRole); |
- | 155 | ||
- | 156 | ||
130 | }
|
157 | }
|
131 | //! [3]
|
158 | //! [3]
|
132 | 159 | ||
133 | //! [4]
|
160 | //! [4]
|
134 | void SpinBoxDelegate::updateEditorGeometry(QWidget *editor, |
161 | void SpinBoxDelegate::updateEditorGeometry(QWidget *editor, |
135 | const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
162 | const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
136 | {
|
163 | {
|
137 | editor->setGeometry(option.rect); |
164 | editor->setGeometry(option.rect); |
138 | }
|
165 | }
|
139 | //! [4]
|
166 | //! [4]
|
- | 167 | ||
- | 168 | void SpinBoxDelegate::getItems(){ |
|
- | 169 | QMap <QString, QString> result_map; |
|
- | 170 | QSqlQuery q;
|
|
- | 171 | QString query_str;
|
|
- | 172 | bool ok; |
|
- | 173 | ||
- | 174 | query_str = tr("select * from `ListOfClasses`"); |
|
- | 175 | q.prepare(query_str); |
|
- | 176 | ||
- | 177 | ||
- | 178 | ok = q.exec(); |
|
- | 179 | ||
- | 180 | ||
- | 181 | ||
- | 182 | ||
- | 183 | if (!ok) { |
|
- | 184 | /*
|
|
- | 185 | QString error_str;
|
|
- | 186 | error_str = tr("íå óäàëîñü ïîëó÷èòü ñïèñîê îáúåêòîâ èç òàáëèöû ");
|
|
- | 187 | error_str.append(inctance);
|
|
- | 188 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
|
|
- | 189 | this, // Ðîäèòåëüñêèé âèäæåò.
|
|
- | 190 | QObject::tr("Database Error"), // Çàãîëîâîê.
|
|
- | 191 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ.
|
|
- | 192 | // tr("íå óäàëîñü ïîëó÷èòü ñïèñîê îáúåêòîâ èç òàáëèöû ")); // Òåêñò ñîîáùåíèÿ.
|
|
- | 193 | ||
- | 194 | */
|
|
- | 195 | items.clear(); |
|
- | 196 | return; |
|
- | 197 | }
|
|
- | 198 | ||
- | 199 | ||
- | 200 | // field_inctance = q.record().indexOf(tr("TableWhithInstance"));
|
|
- | 201 | items.clear(); |
|
- | 202 | while(q.next()){ |
|
- | 203 | ||
- | 204 | QString ID;
|
|
- | 205 | QString ClassName;
|
|
- | 206 | ID = q.value(0).toString(); // îïðåäåëÿåì ID |
|
- | 207 | ClassName = q.value(1).toString(); // îïðåäåëÿåì Name |
|
- | 208 | items.insert(ID, ClassName); |
|
- | 209 | }
|
|
- | 210 | ||
- | 211 | ||
- | 212 | // return result_map;
|
|
- | 213 | }
|
|
- | 214 | ||
- | 215 | ||
- | 216 | ||
- | 217 | ||
- | 218 | ||
- | 219 | ||
- | 220 | ||
- | 221 | ||
- | 222 | ||
- | 223 | ||
- | 224 | ||
- | 225 | ||
- | 226 | ||
- | 227 | ||
- | 228 | ||
- | 229 | ||
- | 230 | ||
140 | MyDEDelegate::MyDEDelegate( |
231 | MyDEDelegate::MyDEDelegate( |
141 | bool calpopup,
|
232 | bool calpopup,
|
142 | QObject *parent) |
233 | QObject *parent) |
143 | : QItemDelegate(parent), |
234 | : QItemDelegate(parent), |
144 | m_calpopup(calpopup) { |
235 | m_calpopup(calpopup) { |
Строка 177... | Строка 268... | ||
177 | QWidget *editor,
|
268 | QWidget *editor,
|
178 | const QStyleOptionViewItem &option, |
269 | const QStyleOptionViewItem &option, |
179 | const QModelIndex& /* index */) const { |
270 | const QModelIndex& /* index */) const { |
180 | editor->setGeometry(option.rect); |
271 | editor->setGeometry(option.rect); |
181 | }
|
272 | }
|
- | 273 | ||
- | 274 |