Редакция 219 | Редакция 225 | К новейшей редакции | Только различия | Учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 219 | Редакция 224 | ||
---|---|---|---|
1 | 1 | ||
2 | 2 | ||
3 | /****************************************************************************
|
3 | /****************************************************************************
|
4 | **
|
4 | **
|
5 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
5 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
6 | ** All rights reserved.
|
6 | ** All rights reserved.
|
7 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
7 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
8 | **
|
8 | **
|
9 | ** This file is part of the examples of the Qt Toolkit.
|
9 | ** This file is part of the examples of the Qt Toolkit.
|
10 | **
|
10 | **
|
11 | ** $QT_BEGIN_LICENSE:LGPL$
|
11 | ** $QT_BEGIN_LICENSE:LGPL$
|
12 | ** Commercial Usage
|
12 | ** Commercial Usage
|
13 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
13 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
14 | ** accordance with the Qt Commercial License Agreement provided with the
|
14 | ** accordance with the Qt Commercial License Agreement provided with the
|
15 | ** Software or, alternatively, in accordance with the terms contained in
|
15 | ** Software or, alternatively, in accordance with the terms contained in
|
16 | ** a written agreement between you and Nokia.
|
16 | ** a written agreement between you and Nokia.
|
17 | **
|
17 | **
|
18 | ** GNU Lesser General Public License Usage
|
18 | ** GNU Lesser General Public License Usage
|
19 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
19 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
20 | ** General Public License version 2.1 as published by the Free Software
|
20 | ** General Public License version 2.1 as published by the Free Software
|
21 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
21 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
22 | ** packaging of this file. Please review the following information to
|
22 | ** packaging of this file. Please review the following information to
|
23 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
23 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
24 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
24 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
25 | **
|
25 | **
|
26 | ** In addition, as a special exception, Nokia gives you certain additional
|
26 | ** In addition, as a special exception, Nokia gives you certain additional
|
27 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
27 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
29 | **
|
29 | **
|
30 | ** GNU General Public License Usage
|
30 | ** GNU General Public License Usage
|
31 | ** Alternatively, this file may be used under the terms of the GNU
|
31 | ** Alternatively, this file may be used under the terms of the GNU
|
32 | ** General Public License version 3.0 as published by the Free Software
|
32 | ** General Public License version 3.0 as published by the Free Software
|
33 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
33 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
34 | ** packaging of this file. Please review the following information to
|
34 | ** packaging of this file. Please review the following information to
|
35 | ** ensure the GNU General Public License version 3.0 requirements will be
|
35 | ** ensure the GNU General Public License version 3.0 requirements will be
|
36 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
36 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
37 | **
|
37 | **
|
38 | ** If you have questions regarding the use of this file, please contact
|
38 | ** If you have questions regarding the use of this file, please contact
|
39 | ** Nokia at qt-info@nokia.com.
|
39 | ** Nokia at qt-info@nokia.com.
|
40 | ** $QT_END_LICENSE$
|
40 | ** $QT_END_LICENSE$
|
41 | **
|
41 | **
|
42 | ****************************************************************************/
|
42 | ****************************************************************************/
|
43 | 43 | ||
44 | /*
|
44 | /*
|
45 | delegate.cpp
|
45 | delegate.cpp
|
46 | 46 | ||
47 | A delegate that allows the user to change integer values from the model
|
47 | A delegate that allows the user to change integer values from the model
|
48 | using a spin box widget.
|
48 | using a spin box widget.
|
49 | */
|
49 | */
|
50 | 50 | ||
51 | #include <QtGui>
|
51 | #include <QtGui>
|
52 | 52 | ||
53 | #include "delegate.h"
|
53 | #include "delegate.h"
|
54 | 54 | ||
55 | 55 | ||
56 | //! [0]
|
56 | //! [0]
|
57 | SpinBoxDelegate::SpinBoxDelegate(QObject *parent) |
57 | SpinBoxDelegate::SpinBoxDelegate(QObject *parent) |
58 | : QItemDelegate(parent) |
58 | : QItemDelegate(parent) |
59 | {
|
59 | {
|
60 | }
|
60 | }
|
61 | //! [0]
|
61 | //! [0]
|
62 | 62 | ||
63 | void SpinBoxDelegate::setInctance(QString newInctance){ |
63 | void SpinBoxDelegate::setInctance(QString newInctance){ |
64 | inctance = newInctance; |
64 | inctance = newInctance; |
65 | }
|
65 | }
|
66 | 66 | ||
67 | void SpinBoxDelegate::getItems(){ |
67 | void SpinBoxDelegate::getItems(){ |
68 | QMap <QString, QString> result_map; |
68 | QMap <QString, QString> result_map; |
69 | QSqlQuery q;
|
69 | QSqlQuery q;
|
70 | QString query_str;
|
70 | QString query_str;
|
71 | bool ok; |
71 | bool ok; |
72 | 72 | ||
73 | if (SpinBoxDelegate::inctance.isEmpty()) |
73 | if (SpinBoxDelegate::inctance.isEmpty()) |
74 | {
|
74 | {
|
75 | items.clear(); |
75 | items.clear(); |
76 | return; |
76 | return; |
77 | }
|
77 | }
|
78 | 78 | ||
79 | query_str = tr("select * from `"); |
79 | query_str = tr("select * from `"); |
80 | query_str.append(inctance); |
80 | query_str.append(inctance); |
81 | query_str.append( tr("`")); |
81 | query_str.append( tr("`")); |
82 | 82 | ||
83 | q.prepare(query_str); |
83 | q.prepare(query_str); |
84 | 84 | ||
85 | 85 | ||
86 | ok = q.exec(); |
86 | ok = q.exec(); |
87 | 87 | ||
88 | 88 | ||
89 | 89 | ||
90 | 90 | ||
91 | if (!ok) { |
91 | if (!ok) { |
92 | /*
|
92 | /*
|
93 | QString error_str;
|
93 | QString error_str;
|
94 | error_str = tr("íå óäàëîñü ïîëó÷èòü ñïèñîê îáúåêòîâ èç òàáëèöû ");
|
94 | error_str = tr("íå óäàëîñü ïîëó÷èòü ñïèñîê îáúåêòîâ èç òàáëèöû ");
|
95 | error_str.append(inctance);
|
95 | error_str.append(inctance);
|
96 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
|
96 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
|
97 | this, // Ðîäèòåëüñêèé âèäæåò.
|
97 | this, // Ðîäèòåëüñêèé âèäæåò.
|
98 | QObject::tr("Database Error"), // Çàãîëîâîê.
|
98 | QObject::tr("Database Error"), // Çàãîëîâîê.
|
99 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ.
|
99 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ.
|
100 | // tr("íå óäàëîñü ïîëó÷èòü ñïèñîê îáúåêòîâ èç òàáëèöû ")); // Òåêñò ñîîáùåíèÿ.
|
100 | // tr("íå óäàëîñü ïîëó÷èòü ñïèñîê îáúåêòîâ èç òàáëèöû ")); // Òåêñò ñîîáùåíèÿ.
|
101 | 101 | ||
102 | */
|
102 | */
|
103 | items.clear(); |
103 | items.clear(); |
104 | return; |
104 | return; |
105 | }
|
105 | }
|
106 | 106 | ||
107 | 107 | ||
108 | // field_inctance = q.record().indexOf(tr("TableWhithInstance"));
|
108 | // field_inctance = q.record().indexOf(tr("TableWhithInstance"));
|
109 | items.clear(); |
109 | items.clear(); |
110 | while(q.next()){ |
110 | while(q.next()){ |
111 | 111 | ||
112 | QString ID;
|
112 | QString ID;
|
113 | QString Name;
|
113 | QString Name;
|
114 | ID = q.value(0).toString(); // îïðåäåëÿåì ID |
114 | ID = q.value(0).toString(); // îïðåäåëÿåì ID |
115 | Name = q.value(1).toString(); // îïðåäåëÿåì Name |
115 | Name = q.value(1).toString(); // îïðåäåëÿåì Name |
116 | items.insert(ID, Name); |
116 | items.insert(ID, Name); |
117 | }
|
117 | }
|
118 | 118 | ||
119 | 119 | ||
120 | // return result_map;
|
120 | // return result_map;
|
121 | }
|
121 | }
|
122 | 122 | ||
123 | 123 | ||
124 | //! [1]
|
124 | //! [1]
|
125 | QWidget *SpinBoxDelegate::createEditor(QWidget *parent, |
125 | QWidget *SpinBoxDelegate::createEditor(QWidget *parent, |
126 | const QStyleOptionViewItem &/* option */, |
126 | const QStyleOptionViewItem &/* option */, |
127 | const QModelIndex &/* index */) const |
127 | const QModelIndex &/* index */) const |
128 | {
|
128 | {
|
129 | //QSpinBox *editor = new QSpinBox(parent);
|
129 | //QSpinBox *editor = new QSpinBox(parent);
|
130 | //editor->setMinimum(0);
|
130 | //editor->setMinimum(0);
|
131 | //editor->setMaximum(100);
|
131 | //editor->setMaximum(100);
|
132 | QStringList ID_list;
|
132 | QStringList ID_list;
|
133 | QStringList Name_list;
|
133 | QStringList Name_list;
|
134 | 134 | ||
135 | // getItems();
|
135 | // getItems();
|
136 | 136 | ||
137 | 137 | ||
138 | 138 | ||
139 | 139 | ||
140 | 140 | ||
141 | ID_list = items.keys(); |
141 | ID_list = items.keys(); |
142 | Name_list = items.values(); |
142 | Name_list = items.values(); |
143 | 143 | ||
144 | QComboBox *editor = new QComboBox(parent); |
144 | QComboBox *editor = new QComboBox(parent); |
145 | 145 | ||
146 | /*
|
146 | /*
|
147 | editor->addItem("0");
|
147 | editor->addItem("0");
|
148 | editor->addItem("1");
|
148 | editor->addItem("1");
|
149 | editor->addItem("2");
|
149 | editor->addItem("2");
|
150 | editor->addItem("3");
|
150 | editor->addItem("3");
|
151 | editor->addItem("4");
|
151 | editor->addItem("4");
|
152 | editor->addItem("5");
|
152 | editor->addItem("5");
|
153 | editor->addItem("6");
|
153 | editor->addItem("6");
|
154 | editor->addItem("7");
|
154 | editor->addItem("7");
|
155 | editor->addItem("8");
|
155 | editor->addItem("8");
|
156 | editor->addItem("9");
|
156 | editor->addItem("9");
|
157 | */
|
157 | */
|
158 | 158 | ||
159 | // editor->addItem("0");
|
159 | // editor->addItem("0");
|
160 | 160 | ||
161 | editor->addItems(Name_list); |
161 | editor->addItems(Name_list); |
162 | // editor->setEditable(false);
|
162 | // editor->setEditable(false);
|
163 | return editor; |
163 | return editor; |
164 | }
|
164 | }
|
165 | //! [1]
|
165 | //! [1]
|
166 | 166 | ||
167 | //! [2]
|
167 | //! [2]
|
168 | void SpinBoxDelegate::setEditorData(QWidget *editor, |
168 | void SpinBoxDelegate::setEditorData(QWidget *editor, |
169 | const QModelIndex &index) const |
169 | const QModelIndex &index) const |
170 | {
|
170 | {
|
171 | // int value = index.model()->data(index, Qt::EditRole).toInt();
|
171 | // int value = index.model()->data(index, Qt::EditRole).toInt();
|
172 | 172 | ||
173 | // QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
173 | // QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
174 | // spinBox->setValue(value);
|
174 | // spinBox->setValue(value);
|
175 | QString value = index.model()->data(index, Qt::EditRole).toString(); |
175 | QString value = index.model()->data(index, Qt::EditRole).toString(); |
176 | 176 | ||
177 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
177 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
178 | 178 | ||
179 | QStringList ID_list;
|
179 | QStringList ID_list;
|
180 | QStringList Name_list;
|
180 | QStringList Name_list;
|
181 | int curr_index; |
181 | int curr_index; |
182 | 182 | ||
183 | ID_list = items.keys(); |
183 | ID_list = items.keys(); |
184 | Name_list = items.values(); |
184 | Name_list = items.values(); |
185 | 185 | ||
186 | curr_index = ID_list.indexOf(value); |
186 | curr_index = ID_list.indexOf(value); |
187 | if (curr_index==-1) return; |
187 | if (curr_index==-1) return; |
188 | comboBox->setCurrentIndex(curr_index); |
188 | comboBox->setCurrentIndex(curr_index); |
189 | /****************************************************
|
189 | /****************************************************
|
190 | if (value == "0") comboBox->setCurrentIndex(0);
|
190 | if (value == "0") comboBox->setCurrentIndex(0);
|
191 | if (value == "1") comboBox->setCurrentIndex(1);
|
191 | if (value == "1") comboBox->setCurrentIndex(1);
|
192 | if (value == "2") comboBox->setCurrentIndex(2);
|
192 | if (value == "2") comboBox->setCurrentIndex(2);
|
193 | if (value == "3") comboBox->setCurrentIndex(3);
|
193 | if (value == "3") comboBox->setCurrentIndex(3);
|
194 | if (value == "4") comboBox->setCurrentIndex(4);
|
194 | if (value == "4") comboBox->setCurrentIndex(4);
|
195 | if (value == "5") comboBox->setCurrentIndex(5);
|
195 | if (value == "5") comboBox->setCurrentIndex(5);
|
196 | if (value == "6") comboBox->setCurrentIndex(6);
|
196 | if (value == "6") comboBox->setCurrentIndex(6);
|
197 | if (value == "7") comboBox->setCurrentIndex(7);
|
197 | if (value == "7") comboBox->setCurrentIndex(7);
|
198 | if (value == "8") comboBox->setCurrentIndex(8);
|
198 | if (value == "8") comboBox->setCurrentIndex(8);
|
199 | if (value == "9") comboBox->setCurrentIndex(9);
|
199 | if (value == "9") comboBox->setCurrentIndex(9);
|
200 | ******************************************************/
|
200 | ******************************************************/
|
201 | comboBox->setEditable(false); |
201 | comboBox->setEditable(false); |
202 | 202 | ||
203 | 203 | ||
204 | //comboBox->setItemText(0, value);
|
204 | //comboBox->setItemText(0, value);
|
205 | 205 | ||
206 | }
|
206 | }
|
207 | //! [2]
|
207 | //! [2]
|
208 | 208 | ||
209 | //! [3]
|
209 | //! [3]
|
210 | void SpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, |
210 | void SpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, |
211 | const QModelIndex &index) const |
211 | const QModelIndex &index) const |
212 | {
|
212 | {
|
213 | // QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
213 | // QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
214 | // spinBox->interpretText();
|
214 | // spinBox->interpretText();
|
215 | // int value = spinBox->value();
|
215 | // int value = spinBox->value();
|
216 | 216 | ||
217 | // model->setData(index, value, Qt::EditRole);
|
217 | // model->setData(index, value, Qt::EditRole);
|
218 | QStringList ID_list;
|
218 | QStringList ID_list;
|
219 | QStringList Name_list;
|
219 | QStringList Name_list;
|
220 | 220 | ||
221 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
221 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
222 | int currIndex; |
222 | int currIndex; |
223 | currIndex = comboBox->currentIndex(); |
223 | currIndex = comboBox->currentIndex(); |
224 | if (currIndex==-1) return; |
224 | if (currIndex==-1) return; |
225 | // QString value = comboBox->itemText(currIndex);
|
225 | // QString value = comboBox->itemText(currIndex);
|
226 | 226 | ||
227 | ID_list = items.keys(); |
227 | ID_list = items.keys(); |
228 | Name_list = items.values(); |
228 | Name_list = items.values(); |
229 | 229 | ||
230 | QString value = ID_list.at(currIndex); |
230 | QString value = ID_list.at(currIndex); |
231 | model->setData(index, value, Qt::EditRole); |
231 | model->setData(index, value, Qt::EditRole); |
232 | }
|
232 | }
|
233 | //! [3]
|
233 | //! [3]
|
234 | 234 | ||
235 | //! [4]
|
235 | //! [4]
|
236 | void SpinBoxDelegate::updateEditorGeometry(QWidget *editor, |
236 | void SpinBoxDelegate::updateEditorGeometry(QWidget *editor, |
237 | const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
237 | const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
238 | {
|
238 | {
|
239 | editor->setGeometry(option.rect); |
239 | editor->setGeometry(option.rect); |
240 | }
|
240 | }
|
241 | 241 | ||
242 | 242 | ||
243 | 243 | ||
244 | 244 | ||
245 | 245 | ||
246 | 246 | ||
247 | 247 | ||
248 | 248 | ||
249 | 249 | ||
250 | 250 | ||
251 | 251 | ||
252 | //! [0]
|
252 | //! [0]
|
253 | FilterSpinBoxDelegate::FilterSpinBoxDelegate(QObject *parent) |
253 | FilterSpinBoxDelegate::FilterSpinBoxDelegate(QObject *parent) |
254 | : QItemDelegate(parent) |
254 | : QItemDelegate(parent) |
255 | {
|
255 | {
|
256 | }
|
256 | }
|
257 | //! [0]
|
257 | //! [0]
|
258 | 258 | ||
259 | void FilterSpinBoxDelegate::setClassID(QString newClassID){ |
259 | void FilterSpinBoxDelegate::setClassID(QString newClassID){ |
260 | class_id = newClassID; |
260 | class_id = newClassID; |
261 | }
|
261 | }
|
262 | 262 | ||
263 | void FilterSpinBoxDelegate::getItems(){ |
263 | void FilterSpinBoxDelegate::getItems(){ |
264 | QMap <QString, QString> result_map; |
264 | QMap <QString, QString> result_map; |
265 | QSqlQuery q;
|
265 | QSqlQuery q;
|
266 | QString query_str;
|
266 | QString query_str;
|
267 | bool ok; |
267 | bool ok; |
268 | 268 | ||
269 | if (FilterSpinBoxDelegate::class_id.isEmpty()) |
269 | if (FilterSpinBoxDelegate::class_id.isEmpty()) |
270 | {
|
270 | {
|
271 | items.clear(); |
271 | items.clear(); |
272 | return; |
272 | return; |
273 | }
|
273 | }
|
274 | 274 | ||
275 | query_str = tr("select * from `DescriptionOfClasses` where `ClassIdentifer` = '"); |
275 | query_str = tr("select * from `DescriptionOfClasses` where `ClassIdentifer` = '"); |
276 | query_str.append(class_id); |
276 | query_str.append(class_id); |
277 | query_str.append( tr("'")); |
277 | query_str.append( tr("'")); |
278 | 278 | ||
279 | q.prepare(query_str); |
279 | q.prepare(query_str); |
280 | 280 | ||
281 | 281 | ||
282 | ok = q.exec(); |
282 | ok = q.exec(); |
283 | 283 | ||
284 | 284 | ||
285 | 285 | ||
286 | 286 | ||
287 | if (!ok) { |
287 | if (!ok) { |
288 | /*
|
288 | /*
|
289 | QString error_str;
|
289 | QString error_str;
|
290 | error_str = tr("íå óäàëîñü ïîëó÷èòü ñïèñîê îáúåêòîâ èç òàáëèöû ");
|
290 | error_str = tr("íå óäàëîñü ïîëó÷èòü ñïèñîê îáúåêòîâ èç òàáëèöû ");
|
291 | error_str.append(inctance);
|
291 | error_str.append(inctance);
|
292 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
|
292 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
|
293 | this, // Ðîäèòåëüñêèé âèäæåò.
|
293 | this, // Ðîäèòåëüñêèé âèäæåò.
|
294 | QObject::tr("Database Error"), // Çàãîëîâîê.
|
294 | QObject::tr("Database Error"), // Çàãîëîâîê.
|
295 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ.
|
295 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ.
|
296 | // tr("íå óäàëîñü ïîëó÷èòü ñïèñîê îáúåêòîâ èç òàáëèöû ")); // Òåêñò ñîîáùåíèÿ.
|
296 | // tr("íå óäàëîñü ïîëó÷èòü ñïèñîê îáúåêòîâ èç òàáëèöû ")); // Òåêñò ñîîáùåíèÿ.
|
297 | 297 | ||
298 | */
|
298 | */
|
299 | items.clear(); |
299 | items.clear(); |
300 | return; |
300 | return; |
301 | }
|
301 | }
|
302 | 302 | ||
303 | 303 | ||
304 | // field_inctance = q.record().indexOf(tr("TableWhithInstance"));
|
304 | // field_inctance = q.record().indexOf(tr("TableWhithInstance"));
|
305 | items.clear(); |
305 | items.clear(); |
306 | while(q.next()){ |
306 | while(q.next()){ |
307 | 307 | ||
308 | QString ID;
|
308 | QString ID;
|
309 | QString Name;
|
309 | QString Name;
|
310 | ID = q.value(0).toString(); // îïðåäåëÿåì ID |
310 | ID = q.value(0).toString(); // îïðåäåëÿåì ID |
311 | Name = q.value(1).toString(); // îïðåäåëÿåì Name |
311 | Name = q.value(1).toString(); // îïðåäåëÿåì Name |
312 | items.insert(ID, Name); |
312 | items.insert(ID, Name); |
313 | }
|
313 | }
|
314 | 314 | ||
315 | 315 | ||
316 | // return result_map;
|
316 | // return result_map;
|
317 | }
|
317 | }
|
318 | 318 | ||
319 | 319 | ||
320 | //! [1]
|
320 | //! [1]
|
321 | QWidget *FilterSpinBoxDelegate::createEditor(QWidget *parent, |
321 | QWidget *FilterSpinBoxDelegate::createEditor(QWidget *parent, |
322 | const QStyleOptionViewItem &/* option */, |
322 | const QStyleOptionViewItem &/* option */, |
323 | const QModelIndex &/* index */) const |
323 | const QModelIndex &/* index */) const |
324 | {
|
324 | {
|
325 | //QSpinBox *editor = new QSpinBox(parent);
|
325 | //QSpinBox *editor = new QSpinBox(parent);
|
326 | //editor->setMinimum(0);
|
326 | //editor->setMinimum(0);
|
327 | //editor->setMaximum(100);
|
327 | //editor->setMaximum(100);
|
328 | QStringList ID_list;
|
328 | QStringList ID_list;
|
329 | QStringList Name_list;
|
329 | QStringList Name_list;
|
330 | 330 | ||
331 | // getItems();
|
331 | // getItems();
|
332 | 332 | ||
333 | 333 | ||
334 | 334 | ||
335 | 335 | ||
336 | 336 | ||
337 | ID_list = items.keys(); |
337 | ID_list = items.keys(); |
338 | Name_list = items.values(); |
338 | Name_list = items.values(); |
339 | 339 | ||
340 | QComboBox *editor = new QComboBox(parent); |
340 | QComboBox *editor = new QComboBox(parent); |
341 | 341 | ||
342 | /*
|
342 | /*
|
343 | editor->addItem("0");
|
343 | editor->addItem("0");
|
344 | editor->addItem("1");
|
344 | editor->addItem("1");
|
345 | editor->addItem("2");
|
345 | editor->addItem("2");
|
346 | editor->addItem("3");
|
346 | editor->addItem("3");
|
347 | editor->addItem("4");
|
347 | editor->addItem("4");
|
348 | editor->addItem("5");
|
348 | editor->addItem("5");
|
349 | editor->addItem("6");
|
349 | editor->addItem("6");
|
350 | editor->addItem("7");
|
350 | editor->addItem("7");
|
351 | editor->addItem("8");
|
351 | editor->addItem("8");
|
352 | editor->addItem("9");
|
352 | editor->addItem("9");
|
353 | */
|
353 | */
|
354 | 354 | ||
355 | // editor->addItem("0");
|
355 | // editor->addItem("0");
|
356 | 356 | ||
357 | editor->addItems(Name_list); |
357 | editor->addItems(Name_list); |
358 | // editor->setEditable(false);
|
358 | // editor->setEditable(false);
|
359 | return editor; |
359 | return editor; |
360 | }
|
360 | }
|
361 | //! [1]
|
361 | //! [1]
|
362 | 362 | ||
363 | //! [2]
|
363 | //! [2]
|
364 | void FilterSpinBoxDelegate::setEditorData(QWidget *editor, |
364 | void FilterSpinBoxDelegate::setEditorData(QWidget *editor, |
365 | const QModelIndex &index) const |
365 | const QModelIndex &index) const |
366 | {
|
366 | {
|
367 | // int value = index.model()->data(index, Qt::EditRole).toInt();
|
367 | // int value = index.model()->data(index, Qt::EditRole).toInt();
|
368 | 368 | ||
369 | // QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
369 | // QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
370 | // spinBox->setValue(value);
|
370 | // spinBox->setValue(value);
|
371 | QString value = index.model()->data(index, Qt::EditRole).toString(); |
371 | QString value = index.model()->data(index, Qt::EditRole).toString(); |
372 | 372 | ||
373 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
373 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
374 | 374 | ||
375 | QStringList ID_list;
|
375 | QStringList ID_list;
|
376 | QStringList Name_list;
|
376 | QStringList Name_list;
|
377 | int curr_index; |
377 | int curr_index; |
378 | 378 | ||
379 | ID_list = items.keys(); |
379 | ID_list = items.keys(); |
380 | Name_list = items.values(); |
380 | Name_list = items.values(); |
381 | 381 | ||
382 | curr_index = ID_list.indexOf(value); |
382 | curr_index = ID_list.indexOf(value); |
383 | if (curr_index==-1) return; |
383 | if (curr_index==-1) return; |
384 | comboBox->setCurrentIndex(curr_index); |
384 | comboBox->setCurrentIndex(curr_index); |
385 | /****************************************************
|
385 | /****************************************************
|
386 | if (value == "0") comboBox->setCurrentIndex(0);
|
386 | if (value == "0") comboBox->setCurrentIndex(0);
|
387 | if (value == "1") comboBox->setCurrentIndex(1);
|
387 | if (value == "1") comboBox->setCurrentIndex(1);
|
388 | if (value == "2") comboBox->setCurrentIndex(2);
|
388 | if (value == "2") comboBox->setCurrentIndex(2);
|
389 | if (value == "3") comboBox->setCurrentIndex(3);
|
389 | if (value == "3") comboBox->setCurrentIndex(3);
|
390 | if (value == "4") comboBox->setCurrentIndex(4);
|
390 | if (value == "4") comboBox->setCurrentIndex(4);
|
391 | if (value == "5") comboBox->setCurrentIndex(5);
|
391 | if (value == "5") comboBox->setCurrentIndex(5);
|
392 | if (value == "6") comboBox->setCurrentIndex(6);
|
392 | if (value == "6") comboBox->setCurrentIndex(6);
|
393 | if (value == "7") comboBox->setCurrentIndex(7);
|
393 | if (value == "7") comboBox->setCurrentIndex(7);
|
394 | if (value == "8") comboBox->setCurrentIndex(8);
|
394 | if (value == "8") comboBox->setCurrentIndex(8);
|
395 | if (value == "9") comboBox->setCurrentIndex(9);
|
395 | if (value == "9") comboBox->setCurrentIndex(9);
|
396 | ******************************************************/
|
396 | ******************************************************/
|
397 | comboBox->setEditable(false); |
397 | comboBox->setEditable(false); |
398 | 398 | ||
399 | 399 | ||
400 | //comboBox->setItemText(0, value);
|
400 | //comboBox->setItemText(0, value);
|
401 | 401 | ||
402 | }
|
402 | }
|
403 | //! [2]
|
403 | //! [2]
|
404 | 404 | ||
405 | //! [3]
|
405 | //! [3]
|
406 | void FilterSpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, |
406 | void FilterSpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, |
407 | const QModelIndex &index) const |
407 | const QModelIndex &index) const |
408 | {
|
408 | {
|
409 | // QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
409 | // QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
410 | // spinBox->interpretText();
|
410 | // spinBox->interpretText();
|
411 | // int value = spinBox->value();
|
411 | // int value = spinBox->value();
|
412 | 412 | ||
413 | // model->setData(index, value, Qt::EditRole);
|
413 | // model->setData(index, value, Qt::EditRole);
|
414 | QStringList ID_list;
|
414 | QStringList ID_list;
|
415 | QStringList Name_list;
|
415 | QStringList Name_list;
|
416 | 416 | ||
417 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
417 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
418 | int currIndex; |
418 | int currIndex; |
419 | currIndex = comboBox->currentIndex(); |
419 | currIndex = comboBox->currentIndex(); |
420 | if (currIndex==-1) return; |
420 | if (currIndex==-1) return; |
421 | // QString value = comboBox->itemText(currIndex);
|
421 | // QString value = comboBox->itemText(currIndex);
|
422 | 422 | ||
423 | ID_list = items.keys(); |
423 | ID_list = items.keys(); |
424 | Name_list = items.values(); |
424 | Name_list = items.values(); |
425 | 425 | ||
426 | // QString value = ID_list.at(currIndex);
|
426 | // QString value = ID_list.at(currIndex);
|
427 | QString value = Name_list.at(currIndex); |
427 | QString value = Name_list.at(currIndex); |
428 | model->setData(index, value, Qt::EditRole); |
428 | model->setData(index, value, Qt::EditRole); |
429 | }
|
429 | }
|
430 | //! [3]
|
430 | //! [3]
|
431 | 431 | ||
432 | //! [4]
|
432 | //! [4]
|
433 | void FilterSpinBoxDelegate::updateEditorGeometry(QWidget *editor, |
433 | void FilterSpinBoxDelegate::updateEditorGeometry(QWidget *editor, |
434 | const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
434 | const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
435 | {
|
435 | {
|
436 | editor->setGeometry(option.rect); |
436 | editor->setGeometry(option.rect); |
437 | }
|
437 | }
|
438 | 438 | ||
439 | 439 | ||
440 | 440 | ||
441 | 441 | ||
442 | 442 | ||
443 | 443 | ||
444 | 444 | ||
445 | 445 | ||
446 | 446 | ||
447 | 447 | ||
448 | //! [0]
|
448 | //! [0]
|
449 | FilterConditionDelegate::FilterConditionDelegate(QObject *parent) |
449 | FilterConditionDelegate::FilterConditionDelegate(QObject *parent) |
450 | : QItemDelegate(parent) |
450 | : QItemDelegate(parent) |
451 | {
|
451 | {
|
452 | }
|
452 | }
|
453 | //! [0]
|
453 | //! [0]
|
454 | 454 | ||
455 | void FilterConditionDelegate::setClassID(QString newClassID){ |
455 | void FilterConditionDelegate::setClassID(QString newClassID){ |
456 | class_id = newClassID; |
456 | class_id = newClassID; |
457 | }
|
457 | }
|
458 | 458 | ||
459 | 459 | ||
460 | 460 | ||
461 | //! [1]
|
461 | //! [1]
|
462 | QWidget *FilterConditionDelegate::createEditor(QWidget *parent, |
462 | QWidget *FilterConditionDelegate::createEditor(QWidget *parent, |
463 | const QStyleOptionViewItem &/* option */, |
463 | const QStyleOptionViewItem &/* option */, |
464 | const QModelIndex &/* index */) const |
464 | const QModelIndex &/* index */) const |
465 | {
|
465 | {
|
466 | QStringList Name_list;
|
466 | QStringList Name_list;
|
467 | 467 | ||
468 | Name_list = items; |
468 | Name_list = items; |
469 | 469 | ||
470 | QComboBox *editor = new QComboBox(parent); |
470 | QComboBox *editor = new QComboBox(parent); |
471 | 471 | ||
472 | /*
|
472 | /*
|
473 | editor->addItem("0");
|
473 | editor->addItem("0");
|
474 | editor->addItem("1");
|
474 | editor->addItem("1");
|
475 | editor->addItem("2");
|
475 | editor->addItem("2");
|
476 | editor->addItem("3");
|
476 | editor->addItem("3");
|
477 | editor->addItem("4");
|
477 | editor->addItem("4");
|
478 | editor->addItem("5");
|
478 | editor->addItem("5");
|
479 | editor->addItem("6");
|
479 | editor->addItem("6");
|
480 | editor->addItem("7");
|
480 | editor->addItem("7");
|
481 | editor->addItem("8");
|
481 | editor->addItem("8");
|
482 | editor->addItem("9");
|
482 | editor->addItem("9");
|
483 | */
|
483 | */
|
484 | 484 | ||
485 | // editor->addItem("0");
|
485 | // editor->addItem("0");
|
486 | 486 | ||
487 | editor->addItems(Name_list); |
487 | editor->addItems(Name_list); |
488 | // editor->setEditable(false);
|
488 | // editor->setEditable(false);
|
489 | return editor; |
489 | return editor; |
490 | }
|
490 | }
|
491 | //! [1]
|
491 | //! [1]
|
492 | 492 | ||
493 | //! [2]
|
493 | //! [2]
|
494 | void FilterConditionDelegate::setEditorData(QWidget *editor, |
494 | void FilterConditionDelegate::setEditorData(QWidget *editor, |
495 | const QModelIndex &index) const |
495 | const QModelIndex &index) const |
496 | {
|
496 | {
|
497 | // int value = index.model()->data(index, Qt::EditRole).toInt();
|
497 | // int value = index.model()->data(index, Qt::EditRole).toInt();
|
498 | 498 | ||
499 | // QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
499 | // QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
500 | // spinBox->setValue(value);
|
500 | // spinBox->setValue(value);
|
501 | QString value = index.model()->data(index, Qt::EditRole).toString(); |
501 | QString value = index.model()->data(index, Qt::EditRole).toString(); |
502 | 502 | ||
503 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
503 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
504 | 504 | ||
505 | //QStringList ID_list;
|
505 | //QStringList ID_list;
|
506 | //QStringList Name_list;
|
506 | //QStringList Name_list;
|
507 | int curr_index; |
507 | int curr_index; |
508 | 508 | ||
509 | //ID_list = items.keys();
|
509 | //ID_list = items.keys();
|
510 | //Name_list = items.values();
|
510 | //Name_list = items.values();
|
511 | 511 | ||
512 | curr_index = items.indexOf(value); |
512 | curr_index = items.indexOf(value); |
513 | if (curr_index==-1) return; |
513 | if (curr_index==-1) return; |
514 | comboBox->setCurrentIndex(curr_index); |
514 | comboBox->setCurrentIndex(curr_index); |
515 | /****************************************************
|
515 | /****************************************************
|
516 | if (value == "0") comboBox->setCurrentIndex(0);
|
516 | if (value == "0") comboBox->setCurrentIndex(0);
|
517 | if (value == "1") comboBox->setCurrentIndex(1);
|
517 | if (value == "1") comboBox->setCurrentIndex(1);
|
518 | if (value == "2") comboBox->setCurrentIndex(2);
|
518 | if (value == "2") comboBox->setCurrentIndex(2);
|
519 | if (value == "3") comboBox->setCurrentIndex(3);
|
519 | if (value == "3") comboBox->setCurrentIndex(3);
|
520 | if (value == "4") comboBox->setCurrentIndex(4);
|
520 | if (value == "4") comboBox->setCurrentIndex(4);
|
521 | if (value == "5") comboBox->setCurrentIndex(5);
|
521 | if (value == "5") comboBox->setCurrentIndex(5);
|
522 | if (value == "6") comboBox->setCurrentIndex(6);
|
522 | if (value == "6") comboBox->setCurrentIndex(6);
|
523 | if (value == "7") comboBox->setCurrentIndex(7);
|
523 | if (value == "7") comboBox->setCurrentIndex(7);
|
524 | if (value == "8") comboBox->setCurrentIndex(8);
|
524 | if (value == "8") comboBox->setCurrentIndex(8);
|
525 | if (value == "9") comboBox->setCurrentIndex(9);
|
525 | if (value == "9") comboBox->setCurrentIndex(9);
|
526 | ******************************************************/
|
526 | ******************************************************/
|
527 | comboBox->setEditable(false); |
527 | comboBox->setEditable(false); |
528 | 528 | ||
529 | 529 | ||
530 | //comboBox->setItemText(0, value);
|
530 | //comboBox->setItemText(0, value);
|
531 | 531 | ||
532 | }
|
532 | }
|
533 | //! [2]
|
533 | //! [2]
|
534 | 534 | ||
535 | //! [3]
|
535 | //! [3]
|
536 | void FilterConditionDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, |
536 | void FilterConditionDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, |
537 | const QModelIndex &index) const |
537 | const QModelIndex &index) const |
538 | {
|
538 | {
|
539 | // QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
539 | // QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
540 | // spinBox->interpretText();
|
540 | // spinBox->interpretText();
|
541 | // int value = spinBox->value();
|
541 | // int value = spinBox->value();
|
542 | 542 | ||
543 | // model->setData(index, value, Qt::EditRole);
|
543 | // model->setData(index, value, Qt::EditRole);
|
544 | QStringList ID_list;
|
544 | QStringList ID_list;
|
545 | QStringList Name_list;
|
545 | QStringList Name_list;
|
546 | 546 | ||
547 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
547 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
548 | int currIndex; |
548 | int currIndex; |
549 | currIndex = comboBox->currentIndex(); |
549 | currIndex = comboBox->currentIndex(); |
550 | if (currIndex==-1) return; |
550 | if (currIndex==-1) return; |
551 | // QString value = comboBox->itemText(currIndex);
|
551 | // QString value = comboBox->itemText(currIndex);
|
552 | 552 | ||
553 | // ID_list = items.keys();
|
553 | // ID_list = items.keys();
|
554 | // Name_list = items.values();
|
554 | // Name_list = items.values();
|
555 | 555 | ||
556 | // QString value = ID_list.at(currIndex);
|
556 | // QString value = ID_list.at(currIndex);
|
557 | QString value = items.at(currIndex); |
557 | QString value = items.at(currIndex); |
558 | model->setData(index, value, Qt::EditRole); |
558 | model->setData(index, value, Qt::EditRole); |
559 | }
|
559 | }
|
560 | //! [3]
|
560 | //! [3]
|
561 | 561 | ||
562 | //! [4]
|
562 | //! [4]
|
563 | void FilterConditionDelegate::updateEditorGeometry(QWidget *editor, |
563 | void FilterConditionDelegate::updateEditorGeometry(QWidget *editor, |
564 | const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
564 | const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
565 | {
|
565 | {
|
566 | editor->setGeometry(option.rect); |
566 | editor->setGeometry(option.rect); |
567 | }
|
567 | }
|
568 | 568 | ||
569 | 569 | ||
570 | 570 | ||
571 | 571 | ||
572 | 572 | ||
573 | 573 | ||
574 | 574 | ||
575 | 575 | ||
576 | 576 | ||
577 | 577 | ||
- | 578 | FilterValueDelegate::FilterValueDelegate(QObject *parent) |
|
- | 579 | : QItemDelegate(parent) |
|
- | 580 | {
|
|
- | 581 | }
|
|
- | 582 | //! [0]
|
|
- | 583 | ||
- | 584 | void FilterValueDelegate::setClassID(QString newClassID){ |
|
- | 585 | class_id = newClassID; |
|
- | 586 | }
|
|
- | 587 | ||
- | 588 | ||
- | 589 | ||
- | 590 | //! [1]
|
|
- | 591 | QWidget *FilterValueDelegate::createEditor(QWidget *parent, |
|
- | 592 | const QStyleOptionViewItem &/* option */, |
|
- | 593 | const QModelIndex &/* index */) const |
|
- | 594 | {
|
|
- | 595 | QStringList Name_list;
|
|
- | 596 | ||
- | 597 | Name_list = items; |
|
- | 598 | ||
- | 599 | QComboBox *editor = new QComboBox(parent); |
|
- | 600 | ||
- | 601 | /*
|
|
- | 602 | editor->addItem("0");
|
|
- | 603 | editor->addItem("1");
|
|
- | 604 | editor->addItem("2");
|
|
- | 605 | editor->addItem("3");
|
|
- | 606 | editor->addItem("4");
|
|
- | 607 | editor->addItem("5");
|
|
- | 608 | editor->addItem("6");
|
|
- | 609 | editor->addItem("7");
|
|
- | 610 | editor->addItem("8");
|
|
- | 611 | editor->addItem("9");
|
|
- | 612 | */
|
|
- | 613 | ||
- | 614 | // editor->addItem("0");
|
|
- | 615 | ||
- | 616 | // // // editor->addItems(Name_list);
|
|
- | 617 | // editor->setEditable(false);
|
|
- | 618 | return editor; |
|
- | 619 | }
|
|
- | 620 | //! [1]
|
|
- | 621 | ||
- | 622 | //! [2]
|
|
- | 623 | void FilterValueDelegate::setEditorData(QWidget *editor, |
|
- | 624 | const QModelIndex &index) const |
|
- | 625 | {
|
|
- | 626 | // int value = index.model()->data(index, Qt::EditRole).toInt();
|
|
- | 627 | ||
- | 628 | // QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
|
- | 629 | // spinBox->setValue(value);
|
|
- | 630 | ||
- | 631 | ||
- | 632 | const QAbstractItemModel * model = index.model(); |
|
- | 633 | ||
- | 634 | ||
- | 635 | QString value = index.model()->data(index, Qt::EditRole).toString(); |
|
- | 636 | QString class_id = index.model()->data(model->index(index.row(),2), Qt::EditRole).toString(); |
|
- | 637 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
|
- | 638 | ||
- | 639 | //QStringList ID_list;
|
|
- | 640 | //QStringList Name_list;
|
|
- | 641 | int curr_index; |
|
- | 642 | ||
- | 643 | //ID_list = items.keys();
|
|
- | 644 | //Name_list = items.values();
|
|
- | 645 | ||
- | 646 | curr_index = items.indexOf(value); |
|
- | 647 | if (curr_index==-1) return; |
|
- | 648 | comboBox->setCurrentIndex(curr_index); |
|
- | 649 | /****************************************************
|
|
- | 650 | if (value == "0") comboBox->setCurrentIndex(0);
|
|
- | 651 | if (value == "1") comboBox->setCurrentIndex(1);
|
|
- | 652 | if (value == "2") comboBox->setCurrentIndex(2);
|
|
- | 653 | if (value == "3") comboBox->setCurrentIndex(3);
|
|
- | 654 | if (value == "4") comboBox->setCurrentIndex(4);
|
|
- | 655 | if (value == "5") comboBox->setCurrentIndex(5);
|
|
- | 656 | if (value == "6") comboBox->setCurrentIndex(6);
|
|
- | 657 | if (value == "7") comboBox->setCurrentIndex(7);
|
|
- | 658 | if (value == "8") comboBox->setCurrentIndex(8);
|
|
- | 659 | if (value == "9") comboBox->setCurrentIndex(9);
|
|
- | 660 | ******************************************************/
|
|
- | 661 | comboBox->setEditable(false); |
|
- | 662 | ||
- | 663 | ||
- | 664 | //comboBox->setItemText(0, value);
|
|
- | 665 | ||
- | 666 | }
|
|
- | 667 | //! [2]
|
|
- | 668 | ||
- | 669 | //! [3]
|
|
- | 670 | void FilterValueDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, |
|
- | 671 | const QModelIndex &index) const |
|
- | 672 | {
|
|
- | 673 | // QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
|
- | 674 | // spinBox->interpretText();
|
|
- | 675 | // int value = spinBox->value();
|
|
- | 676 | ||
- | 677 | // model->setData(index, value, Qt::EditRole);
|
|
- | 678 | QStringList ID_list;
|
|
- | 679 | QStringList Name_list;
|
|
- | 680 | ||
- | 681 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
|
- | 682 | int currIndex; |
|
- | 683 | currIndex = comboBox->currentIndex(); |
|
- | 684 | if (currIndex==-1) return; |
|
- | 685 | // QString value = comboBox->itemText(currIndex);
|
|
- | 686 | ||
- | 687 | // ID_list = items.keys();
|
|
- | 688 | // Name_list = items.values();
|
|
- | 689 | ||
- | 690 | // QString value = ID_list.at(currIndex);
|
|
- | 691 | QString value = items.at(currIndex); |
|
- | 692 | model->setData(index, value, Qt::EditRole); |
|
- | 693 | }
|
|
- | 694 | //! [3]
|
|
- | 695 | ||
- | 696 | //! [4]
|
|
- | 697 | void FilterValueDelegate::updateEditorGeometry(QWidget *editor, |
|
- | 698 | const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
|
- | 699 | {
|
|
- | 700 | editor->setGeometry(option.rect); |
|
- | 701 | }
|
|
- | 702 | ||
- | 703 | ||
- | 704 | ||
- | 705 | ||
- | 706 | ||
- | 707 | ||
- | 708 | ||
- | 709 | ||
- | 710 | ||
- | 711 | ||
- | 712 | ||
- | 713 | ||
- | 714 | ||
- | 715 | ||
- | 716 | ||
578 | //! [4]
|
717 | //! [4]
|
579 | MyDEDelegate::MyDEDelegate( |
718 | MyDEDelegate::MyDEDelegate( |
580 | bool calpopup,
|
719 | bool calpopup,
|
581 | QObject *parent) |
720 | QObject *parent) |
582 | : QItemDelegate(parent), |
721 | : QItemDelegate(parent), |
583 | m_calpopup(calpopup) { |
722 | m_calpopup(calpopup) { |
584 | }
|
723 | }
|
585 | 724 | ||
586 | QWidget *MyDEDelegate::createEditor( |
725 | QWidget *MyDEDelegate::createEditor( |
587 | QWidget *parent,
|
726 | QWidget *parent,
|
588 | const QStyleOptionViewItem& /* option */, |
727 | const QStyleOptionViewItem& /* option */, |
589 | const QModelIndex& /* index */) const { |
728 | const QModelIndex& /* index */) const { |
590 | QDateEdit *editor = new QDateEdit(parent); |
729 | QDateEdit *editor = new QDateEdit(parent); |
591 | editor->setCalendarPopup(m_calpopup); |
730 | editor->setCalendarPopup(m_calpopup); |
592 | editor->installEventFilter(const_cast<MyDEDelegate*>(this)); |
731 | editor->installEventFilter(const_cast<MyDEDelegate*>(this)); |
593 | return editor; |
732 | return editor; |
594 | }
|
733 | }
|
595 | 734 | ||
596 | void MyDEDelegate::setEditorData( |
735 | void MyDEDelegate::setEditorData( |
597 | QWidget *editor,
|
736 | QWidget *editor,
|
598 | const QModelIndex &index) const { |
737 | const QModelIndex &index) const { |
599 | QDate value = index.model()->data( |
738 | QDate value = index.model()->data( |
600 | index, Qt::EditRole).toDate(); |
739 | index, Qt::EditRole).toDate(); |
601 | QDateEdit *de = static_cast<QDateEdit*>(editor); |
740 | QDateEdit *de = static_cast<QDateEdit*>(editor); |
602 | de->setDate(value); |
741 | de->setDate(value); |
603 | }
|
742 | }
|
604 | 743 | ||
605 | void MyDEDelegate::setModelData( |
744 | void MyDEDelegate::setModelData( |
606 | QWidget *editor,
|
745 | QWidget *editor,
|
607 | QAbstractItemModel *model,
|
746 | QAbstractItemModel *model,
|
608 | const QModelIndex& index) const { |
747 | const QModelIndex& index) const { |
609 | QDateEdit *de = static_cast<QDateEdit*>(editor); |
748 | QDateEdit *de = static_cast<QDateEdit*>(editor); |
610 | de->interpretText(); |
749 | de->interpretText(); |
611 | QDate value = de->date(); |
750 | QDate value = de->date(); |
612 | model->setData(index, value); |
751 | model->setData(index, value); |
613 | }
|
752 | }
|
614 | 753 | ||
615 | void MyDEDelegate::updateEditorGeometry( |
754 | void MyDEDelegate::updateEditorGeometry( |
616 | QWidget *editor,
|
755 | QWidget *editor,
|
617 | const QStyleOptionViewItem &option, |
756 | const QStyleOptionViewItem &option, |
618 | const QModelIndex& /* index */) const { |
757 | const QModelIndex& /* index */) const { |
619 | 758 | ||
620 | 759 | ||
621 | 760 | ||
622 | editor->setGeometry(option.rect); |
761 | editor->setGeometry(option.rect); |
623 | }
|
762 | }
|
624 | 763 | ||
625 | 764 | ||
626 | 765 | ||
627 | 766 | ||
628 | 767 | ||
629 | CPictureDelegate::CPictureDelegate( QObject * parent ) : QItemDelegate(parent) |
768 | CPictureDelegate::CPictureDelegate( QObject * parent ) : QItemDelegate(parent) |
630 | {
|
769 | {
|
631 | }
|
770 | }
|
632 | 771 | ||
633 | void CPictureDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const |
772 | void CPictureDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const |
634 | {
|
773 | {
|
635 | m_pxPicture.fill( QColor(Qt::white) ); |
774 | m_pxPicture.fill( QColor(Qt::white) ); |
636 | 775 | ||
637 | const QAbstractItemModel * model = index.model(); |
776 | const QAbstractItemModel * model = index.model(); |
638 | QString sFileName = model->data( index, Qt::DisplayRole ).toString(); |
777 | QString sFileName = model->data( index, Qt::DisplayRole ).toString(); |
639 | 778 | ||
640 | if ( !sFileName.isEmpty() ) |
779 | if ( !sFileName.isEmpty() ) |
641 | m_pxPicture.load( sFileName ); |
780 | m_pxPicture.load( sFileName ); |
642 | else { |
781 | else { |
643 | //QItemDelegate::paint(painter, option, index);
|
782 | //QItemDelegate::paint(painter, option, index);
|
644 | return; |
783 | return; |
645 | }
|
784 | }
|
646 | 785 | ||
647 | QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) ? |
786 | QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) ? |
648 | ((option.state & QStyle::State_Active) ? QPalette::Normal : QPalette::Inactive ) : |
787 | ((option.state & QStyle::State_Active) ? QPalette::Normal : QPalette::Inactive ) : |
649 | QPalette::Disabled; |
788 | QPalette::Disabled; |
650 | 789 | ||
651 | if (option.state & QStyle::State_Selected) |
790 | if (option.state & QStyle::State_Selected) |
652 | painter->fillRect(option.rect, option.palette.color(cg, QPalette::Highlight)); |
791 | painter->fillRect(option.rect, option.palette.color(cg, QPalette::Highlight)); |
653 | 792 | ||
654 | int nX = option.rect.x() + ( ( option.rect.width() - m_pxPicture.rect().width() ) / 2 ); |
793 | int nX = option.rect.x() + ( ( option.rect.width() - m_pxPicture.rect().width() ) / 2 ); |
655 | int nY = option.rect.y() + ( ( option.rect.height() - m_pxPicture.rect().height() ) / 2 ); |
794 | int nY = option.rect.y() + ( ( option.rect.height() - m_pxPicture.rect().height() ) / 2 ); |
656 | painter->drawPixmap( nX, nY, m_pxPicture ); |
795 | painter->drawPixmap( nX, nY, m_pxPicture ); |
657 | 796 | ||
658 | 797 | ||
659 | //// drawFocus(painter, option, option.rect.adjusted(0, 0, -1, -1)); // since we draw the grid ourselves
|
798 | //// drawFocus(painter, option, option.rect.adjusted(0, 0, -1, -1)); // since we draw the grid ourselves
|
660 | 799 | ||
661 | /*
|
800 | /*
|
662 | QPen pen = painter->pen();
|
801 | QPen pen = painter->pen();
|
663 | painter->setPen(option.palette.color(QPalette::Mid));
|
802 | painter->setPen(option.palette.color(QPalette::Mid));
|
664 | painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
|
803 | painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
|
665 | painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
|
804 | painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
|
666 | painter->setPen(pen);
|
805 | painter->setPen(pen);
|
667 | */
|
806 | */
|
668 | }
|
807 | }
|
669 | 808 | ||
670 | 809 | ||
671 | 810 | ||
672 | 811 | ||
673 | void TimeEditDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, |
812 | void TimeEditDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, |
674 | const QModelIndex &index) const |
813 | const QModelIndex &index) const |
675 | {
|
814 | {
|
676 | int datetime = index.model()->data(index, Qt::DisplayRole).toInt(); |
815 | int datetime = index.model()->data(index, Qt::DisplayRole).toInt(); |
677 | 816 | ||
678 | QString indexvalue = ""; |
817 | QString indexvalue = ""; |
679 | 818 | ||
680 | if (datetime > 0) |
819 | if (datetime > 0) |
681 | {
|
820 | {
|
682 | QDateTime dateTime2 = QDateTime(); |
821 | QDateTime dateTime2 = QDateTime(); |
683 | dateTime2.setTime_t(datetime); |
822 | dateTime2.setTime_t(datetime); |
684 | indexvalue = dateTime2.toString(this->timeformat); |
823 | indexvalue = dateTime2.toString(this->timeformat); |
685 | }
|
824 | }
|
686 | else
|
825 | else
|
687 | {
|
826 | {
|
688 | indexvalue = tr("Date not set"); |
827 | indexvalue = tr("Date not set"); |
689 | }
|
828 | }
|
690 | 829 | ||
691 | Q_ASSERT(index.isValid()); |
830 | Q_ASSERT(index.isValid()); |
692 | 831 | ||
693 | QStyleOptionViewItemV3 opt = setOptions(index, option); |
832 | QStyleOptionViewItemV3 opt = setOptions(index, option); |
694 | 833 | ||
695 | const QStyleOptionViewItemV2 *v2 = qstyleoption_cast<const QStyleOptionViewItemV2 *>(&option); |
834 | const QStyleOptionViewItemV2 *v2 = qstyleoption_cast<const QStyleOptionViewItemV2 *>(&option); |
696 | opt.features = v2 ? v2->features |
835 | opt.features = v2 ? v2->features |
697 | : QStyleOptionViewItemV2::ViewItemFeatures(QStyleOptionViewItemV2::None); |
836 | : QStyleOptionViewItemV2::ViewItemFeatures(QStyleOptionViewItemV2::None); |
698 | const QStyleOptionViewItemV3 *v3 = qstyleoption_cast<const QStyleOptionViewItemV3 *>(&option); |
837 | const QStyleOptionViewItemV3 *v3 = qstyleoption_cast<const QStyleOptionViewItemV3 *>(&option); |
699 | opt.locale = v3 ? v3->locale : QLocale(); |
838 | opt.locale = v3 ? v3->locale : QLocale(); |
700 | opt.widget = v3 ? v3->widget : 0; |
839 | opt.widget = v3 ? v3->widget : 0; |
701 | 840 | ||
702 | // prepare
|
841 | // prepare
|
703 | painter->save(); |
842 | painter->save(); |
704 | 843 | ||
705 | painter->setClipRect(opt.rect); |
844 | painter->setClipRect(opt.rect); |
706 | 845 | ||
707 | // get the data and the rectangles
|
846 | // get the data and the rectangles
|
708 | QVariant value;
|
847 | QVariant value;
|
709 | 848 | ||
710 | QPixmap pixmap;
|
849 | QPixmap pixmap;
|
711 | QRect decorationRect;
|
850 | QRect decorationRect;
|
712 | value = index.data(Qt::DecorationRole); |
851 | value = index.data(Qt::DecorationRole); |
713 | 852 | ||
714 | QString text;
|
853 | QString text;
|
715 | QRect displayRect;
|
854 | QRect displayRect;
|
716 | value = index.data(Qt::DisplayRole); |
855 | value = index.data(Qt::DisplayRole); |
717 | if (value.isValid()) { |
856 | if (value.isValid()) { |
718 | text = indexvalue; |
857 | text = indexvalue; |
719 | displayRect = textRectangle(painter, option.rect, opt.font, text); |
858 | displayRect = textRectangle(painter, option.rect, opt.font, text); |
720 | }
|
859 | }
|
721 | 860 | ||
722 | QRect checkRect;
|
861 | QRect checkRect;
|
723 | Qt::CheckState checkState = Qt::Unchecked; |
862 | Qt::CheckState checkState = Qt::Unchecked; |
724 | value = index.data(Qt::CheckStateRole); |
863 | value = index.data(Qt::CheckStateRole); |
725 | if (value.isValid()) { |
864 | if (value.isValid()) { |
726 | checkState = static_cast<Qt::CheckState>(value.toInt()); |
865 | checkState = static_cast<Qt::CheckState>(value.toInt()); |
727 | checkRect = check(opt, opt.rect, value); |
866 | checkRect = check(opt, opt.rect, value); |
728 | }
|
867 | }
|
729 | 868 | ||
730 | // do the layout
|
869 | // do the layout
|
731 | doLayout(opt, &checkRect, &decorationRect, &displayRect, false); |
870 | doLayout(opt, &checkRect, &decorationRect, &displayRect, false); |
732 | // draw the item
|
871 | // draw the item
|
733 | 872 | ||
734 | drawBackground(painter, opt, index); |
873 | drawBackground(painter, opt, index); |
735 | drawCheck(painter, opt, checkRect, checkState); |
874 | drawCheck(painter, opt, checkRect, checkState); |
736 | drawDecoration(painter, opt, decorationRect, pixmap); |
875 | drawDecoration(painter, opt, decorationRect, pixmap); |
737 | drawDisplay(painter, opt, displayRect, text); |
876 | drawDisplay(painter, opt, displayRect, text); |
738 | drawFocus(painter, opt, displayRect); |
877 | drawFocus(painter, opt, displayRect); |
739 | 878 | ||
740 | // done
|
879 | // done
|
741 | painter->restore(); |
880 | painter->restore(); |
742 | }
|
881 | }
|
743 | 882 | ||
744 | 883 | ||
745 | 884 | ||
746 | 885 | ||
747 | 886 | ||
748 | 887 | ||
749 | IconDelegate::IconDelegate( QObject * parent ) : QItemDelegate(parent) |
888 | IconDelegate::IconDelegate( QObject * parent ) : QItemDelegate(parent) |
750 | {
|
889 | {
|
751 | }
|
890 | }
|
752 | 891 | ||
753 | 892 | ||
754 | 893 | ||
755 | 894 | ||
756 | 895 | ||
757 | QWidget *IconDelegate::createEditor(QWidget *parent, |
896 | QWidget *IconDelegate::createEditor(QWidget *parent, |
758 | const QStyleOptionViewItem &/* option */, |
897 | const QStyleOptionViewItem &/* option */, |
759 | const QModelIndex & /* index */) const |
898 | const QModelIndex & /* index */) const |
760 | {
|
899 | {
|
761 | 900 | ||
762 | IconForm *editor = new IconForm(parent); |
901 | IconForm *editor = new IconForm(parent); |
763 | 902 | ||
764 | return editor; |
903 | return editor; |
765 | 904 | ||
766 | }
|
905 | }
|
767 | 906 | ||
768 | 907 | ||
769 | 908 | ||
770 | 909 | ||
771 | void IconDelegate::setEditorData(QWidget *editor, |
910 | void IconDelegate::setEditorData(QWidget *editor, |
772 | const QModelIndex &index) const |
911 | const QModelIndex &index) const |
773 | {
|
912 | {
|
774 | 913 | ||
775 | 914 | ||
776 | const QAbstractItemModel * model = index.model(); |
915 | const QAbstractItemModel * model = index.model(); |
777 | IconForm *icnFrm = static_cast<IconForm*>(editor); |
916 | IconForm *icnFrm = static_cast<IconForm*>(editor); |
778 | QVariant currentImage = model->data(index,0); |
917 | QVariant currentImage = model->data(index,0); |
779 | QByteArray bytes = currentImage.toByteArray(); |
918 | QByteArray bytes = currentImage.toByteArray(); |
780 | if (currentImage.isValid()) { |
919 | if (currentImage.isValid()) { |
781 | m_pxPicture.loadFromData(bytes); |
920 | m_pxPicture.loadFromData(bytes); |
782 | }
|
921 | }
|
783 | else { |
922 | else { |
784 | //QItemDelegate::paint(painter, option, index);
|
923 | //QItemDelegate::paint(painter, option, index);
|
785 | 924 | ||
786 | 925 | ||
787 | return; |
926 | return; |
788 | }
|
927 | }
|
789 | icnFrm->setPixmap(m_pxPicture); |
928 | icnFrm->setPixmap(m_pxPicture); |
790 | // tblView->setRowHeight(index.row(), icnFrm->geometry().height());
|
929 | // tblView->setRowHeight(index.row(), icnFrm->geometry().height());
|
791 | }
|
930 | }
|
792 | 931 | ||
793 | 932 | ||
794 | 933 | ||
795 | 934 | ||
796 | void IconDelegate::setModelData( |
935 | void IconDelegate::setModelData( |
797 | QWidget *editor,
|
936 | QWidget *editor,
|
798 | QAbstractItemModel *model,
|
937 | QAbstractItemModel *model,
|
799 | const QModelIndex& index) const { |
938 | const QModelIndex& index) const { |
800 | IconForm *icnFrm = static_cast<IconForm*>(editor); |
939 | IconForm *icnFrm = static_cast<IconForm*>(editor); |
801 | if (!(icnFrm->dataIsChanged())) return; |
940 | if (!(icnFrm->dataIsChanged())) return; |
802 | 941 | ||
803 | m_pxPicture = icnFrm->pixmap(); |
942 | m_pxPicture = icnFrm->pixmap(); |
804 | QImage currentImage = m_pxPicture.toImage(); |
943 | QImage currentImage = m_pxPicture.toImage(); |
805 | QByteArray bytes;
|
944 | QByteArray bytes;
|
806 | QBuffer buffer(&bytes); |
945 | QBuffer buffer(&bytes); |
807 | buffer.open(QIODevice::WriteOnly); |
946 | buffer.open(QIODevice::WriteOnly); |
808 | currentImage.save(&buffer, "PNG"); |
947 | currentImage.save(&buffer, "PNG"); |
809 | 948 | ||
810 | 949 | ||
811 | 950 | ||
812 | 951 | ||
813 | model->setData(index, QVariant (bytes), Qt::EditRole); |
952 | model->setData(index, QVariant (bytes), Qt::EditRole); |
814 | 953 | ||
815 | // int widht = m_pxPicture.width();
|
954 | // int widht = m_pxPicture.width();
|
816 | // int heigh = m_pxPicture.height();
|
955 | // int heigh = m_pxPicture.height();
|
817 | // tblView->setRowHeight(index.row(), heigh + 10);
|
956 | // tblView->setRowHeight(index.row(), heigh + 10);
|
818 | // model->submitAll();
|
957 | // model->submitAll();
|
819 | 958 | ||
820 | 959 | ||
821 | 960 | ||
822 | 961 | ||
823 | // model->setData(index, value);
|
962 | // model->setData(index, value);
|
824 | }
|
963 | }
|
825 | 964 | ||
826 | 965 | ||
827 | 966 | ||
828 | void IconDelegate::updateEditorGeometry( |
967 | void IconDelegate::updateEditorGeometry( |
829 | QWidget *editor,
|
968 | QWidget *editor,
|
830 | const QStyleOptionViewItem &option, |
969 | const QStyleOptionViewItem &option, |
831 | const QModelIndex& /* index */) const { |
970 | const QModelIndex& /* index */) const { |
832 | 971 | ||
833 | 972 | ||
834 | // QRect r(option.rect.x() + option.rect.width()/2 - 7, option.rect.y() + option.rect.height()/2 - 7, 150, 100);
|
973 | // QRect r(option.rect.x() + option.rect.width()/2 - 7, option.rect.y() + option.rect.height()/2 - 7, 150, 100);
|
835 | // editor->setGeometry(r);
|
974 | // editor->setGeometry(r);
|
836 | 975 | ||
837 | editor->setGeometry(option.rect); |
976 | editor->setGeometry(option.rect); |
838 | }
|
977 | }
|
839 | 978 | ||
840 | 979 | ||
841 | 980 | ||
842 | 981 | ||
843 | void IconDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const |
982 | void IconDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const |
844 | {
|
983 | {
|
845 | 984 | ||
846 | 985 | ||
847 | m_pxPicture.fill( QColor(Qt::white) ); |
986 | m_pxPicture.fill( QColor(Qt::white) ); |
848 | 987 | ||
849 | const QAbstractItemModel * model = index.model(); |
988 | const QAbstractItemModel * model = index.model(); |
850 | QString sFileName = model->data( index, Qt::DisplayRole ).toString(); |
989 | QString sFileName = model->data( index, Qt::DisplayRole ).toString(); |
851 | 990 | ||
852 | QVariant currentImage = model->data(index,0); |
991 | QVariant currentImage = model->data(index,0); |
853 | 992 | ||
854 | 993 | ||
855 | QByteArray bytes = currentImage.toByteArray(); |
994 | QByteArray bytes = currentImage.toByteArray(); |
856 | // QImage image;
|
995 | // QImage image;
|
857 | // image.loadFromData(bytes);
|
996 | // image.loadFromData(bytes);
|
858 | 997 | ||
859 | 998 | ||
860 | if (currentImage.isValid()) { |
999 | if (currentImage.isValid()) { |
861 | m_pxPicture.loadFromData(bytes); |
1000 | m_pxPicture.loadFromData(bytes); |
862 | 1001 | ||
863 | }
|
1002 | }
|
864 | else { |
1003 | else { |
865 | //QItemDelegate::paint(painter, option, index);
|
1004 | //QItemDelegate::paint(painter, option, index);
|
866 | return; |
1005 | return; |
867 | }
|
1006 | }
|
868 | 1007 | ||
869 | 1008 | ||
870 | 1009 | ||
871 | 1010 | ||
872 | 1011 | ||
873 | /*
|
1012 | /*
|
874 | 1013 | ||
875 | if ( !sFileName.isEmpty() )
|
1014 | if ( !sFileName.isEmpty() )
|
876 | m_pxPicture.load( sFileName );
|
1015 | m_pxPicture.load( sFileName );
|
877 | else {
|
1016 | else {
|
878 | //QItemDelegate::paint(painter, option, index);
|
1017 | //QItemDelegate::paint(painter, option, index);
|
879 | return;
|
1018 | return;
|
880 | }
|
1019 | }
|
881 | */
|
1020 | */
|
882 | 1021 | ||
883 | 1022 | ||
884 | 1023 | ||
885 | 1024 | ||
886 | 1025 | ||
887 | QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) ? |
1026 | QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) ? |
888 | ((option.state & QStyle::State_Active) ? QPalette::Normal : QPalette::Inactive ) : |
1027 | ((option.state & QStyle::State_Active) ? QPalette::Normal : QPalette::Inactive ) : |
889 | QPalette::Disabled; |
1028 | QPalette::Disabled; |
890 | 1029 | ||
891 | if (option.state & QStyle::State_Selected) |
1030 | if (option.state & QStyle::State_Selected) |
892 | 1031 | ||
893 | 1032 | ||
894 | painter->fillRect(option.rect, option.palette.color(cg, QPalette::Highlight)); |
1033 | painter->fillRect(option.rect, option.palette.color(cg, QPalette::Highlight)); |
895 | 1034 | ||
896 | 1035 | ||
897 | 1036 | ||
898 | int nX = option.rect.x() + ( ( option.rect.width() - m_pxPicture.rect().width() ) / 2 ); |
1037 | int nX = option.rect.x() + ( ( option.rect.width() - m_pxPicture.rect().width() ) / 2 ); |
899 | int nY = option.rect.y() + ( ( option.rect.height() - m_pxPicture.rect().height() ) / 2 ); |
1038 | int nY = option.rect.y() + ( ( option.rect.height() - m_pxPicture.rect().height() ) / 2 ); |
900 | // painter->setRenderHint(QPainter::Antialiasing);
|
1039 | // painter->setRenderHint(QPainter::Antialiasing);
|
901 | painter->drawPixmap( nX, nY, m_pxPicture ); |
1040 | painter->drawPixmap( nX, nY, m_pxPicture ); |
902 | 1041 | ||
903 | // drawFocus(painter, option, option.rect.adjusted(0, 0, -1, -1)); // since we draw the grid ourselves
|
1042 | // drawFocus(painter, option, option.rect.adjusted(0, 0, -1, -1)); // since we draw the grid ourselves
|
904 | 1043 | ||
905 | /*
|
1044 | /*
|
906 | QPen pen = painter->pen();
|
1045 | QPen pen = painter->pen();
|
907 | painter->setPen(option.palette.color(QPalette::Mid));
|
1046 | painter->setPen(option.palette.color(QPalette::Mid));
|
908 | painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
|
1047 | painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
|
909 | painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
|
1048 | painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
|
910 | painter->setPen(pen);
|
1049 | painter->setPen(pen);
|
911 | */
|
1050 | */
|
912 | }
|
1051 | }
|
913 | 1052 | ||
914 | 1053 | ||
915 | void IconDelegate::setTableView(QTableView* table){ |
1054 | void IconDelegate::setTableView(QTableView* table){ |
916 | tblView = table; |
1055 | tblView = table; |
917 | }
|
1056 | }
|
918 | 1057 | ||
919 | 1058 | ||
920 | 1059 | ||
921 | 1060 | ||
922 | 1061 | ||
923 | 1062 | ||
924 | 1063 | ||
925 | 1064 | ||
926 | FileDelegate::FileDelegate( QObject * parent ) : QItemDelegate(parent) |
1065 | FileDelegate::FileDelegate( QObject * parent ) : QItemDelegate(parent) |
927 | {
|
1066 | {
|
928 | }
|
1067 | }
|
929 | 1068 | ||
930 | 1069 | ||
931 | 1070 | ||
932 | 1071 | ||
933 | 1072 | ||
934 | QWidget *FileDelegate::createEditor(QWidget *parent, |
1073 | QWidget *FileDelegate::createEditor(QWidget *parent, |
935 | const QStyleOptionViewItem &/* option */, |
1074 | const QStyleOptionViewItem &/* option */, |
936 | const QModelIndex & /* index */) const |
1075 | const QModelIndex & /* index */) const |
937 | {
|
1076 | {
|
938 | 1077 | ||
939 | FileForm *editor = new FileForm(parent); |
1078 | FileForm *editor = new FileForm(parent); |
940 | 1079 | ||
941 | return editor; |
1080 | return editor; |
942 | 1081 | ||
943 | }
|
1082 | }
|
944 | 1083 | ||
945 | 1084 | ||
946 | 1085 | ||
947 | 1086 | ||
948 | void FileDelegate::setEditorData(QWidget *editor, |
1087 | void FileDelegate::setEditorData(QWidget *editor, |
949 | const QModelIndex &index) const |
1088 | const QModelIndex &index) const |
950 | {
|
1089 | {
|
951 | 1090 | ||
952 | 1091 | ||
953 | const QAbstractItemModel * model = index.model(); |
1092 | const QAbstractItemModel * model = index.model(); |
954 | FileForm *flFrm = static_cast<FileForm*>(editor); |
1093 | FileForm *flFrm = static_cast<FileForm*>(editor); |
955 | QVariant currentData = model->data(index,Qt::EditRole); |
1094 | QVariant currentData = model->data(index,Qt::EditRole); |
956 | 1095 | ||
957 | // QVariant currentData = QSqlTableModel::data(index, 0);
|
1096 | // QVariant currentData = QSqlTableModel::data(index, 0);
|
958 | QByteArray bytes = currentData.toByteArray(); |
1097 | QByteArray bytes = currentData.toByteArray(); |
959 | if (currentData.isValid()) flFrm->setData(bytes); |
1098 | if (currentData.isValid()) flFrm->setData(bytes); |
960 | else return; |
1099 | else return; |
961 | 1100 | ||
962 | }
|
1101 | }
|
963 | 1102 | ||
964 | 1103 | ||
965 | 1104 | ||
966 | 1105 | ||
967 | void FileDelegate::setModelData( |
1106 | void FileDelegate::setModelData( |
968 | QWidget *editor,
|
1107 | QWidget *editor,
|
969 | QAbstractItemModel *model,
|
1108 | QAbstractItemModel *model,
|
970 | const QModelIndex& index) const { |
1109 | const QModelIndex& index) const { |
971 | FileForm *flFrm = static_cast<FileForm*>(editor); |
1110 | FileForm *flFrm = static_cast<FileForm*>(editor); |
972 | if (!(flFrm->dataIsChanged())) return; |
1111 | if (!(flFrm->dataIsChanged())) return; |
973 | 1112 | ||
974 | m_Data = flFrm->data(); |
1113 | m_Data = flFrm->data(); |
975 | if (!m_Data.isEmpty()) { // åñëè ìàññèâ íå ïóñòîé |
1114 | if (!m_Data.isEmpty()) { // åñëè ìàññèâ íå ïóñòîé |
976 | model->setData(index, QVariant (m_Data), Qt::EditRole); |
1115 | model->setData(index, QVariant (m_Data), Qt::EditRole); |
977 | 1116 | ||
978 | }
|
1117 | }
|
979 | else { // åñëè ìàññèâ ïóñòîé (ôàéë óäàëèëè) |
1118 | else { // åñëè ìàññèâ ïóñòîé (ôàéë óäàëèëè) |
980 | QVariant val_null;
|
1119 | QVariant val_null;
|
981 | model->setData(index, val_null, Qt::EditRole); |
1120 | model->setData(index, val_null, Qt::EditRole); |
982 | 1121 | ||
983 | }
|
1122 | }
|
984 | 1123 | ||
985 | 1124 | ||
986 | 1125 | ||
987 | }
|
1126 | }
|
988 | 1127 | ||
989 | 1128 | ||
990 | 1129 | ||
991 | void FileDelegate::updateEditorGeometry( |
1130 | void FileDelegate::updateEditorGeometry( |
992 | QWidget *editor,
|
1131 | QWidget *editor,
|
993 | const QStyleOptionViewItem &option, |
1132 | const QStyleOptionViewItem &option, |
994 | const QModelIndex& /* index */) const { |
1133 | const QModelIndex& /* index */) const { |
995 | 1134 | ||
996 | 1135 | ||
997 | // QRect r(option.rect.x() + option.rect.width()/2 - 7, option.rect.y() + option.rect.height()/2 - 7, 150, 100);
|
1136 | // QRect r(option.rect.x() + option.rect.width()/2 - 7, option.rect.y() + option.rect.height()/2 - 7, 150, 100);
|
998 | // editor->setGeometry(r);
|
1137 | // editor->setGeometry(r);
|
999 | 1138 | ||
1000 | editor->setGeometry(option.rect); |
1139 | editor->setGeometry(option.rect); |
1001 | }
|
1140 | }
|
1002 | 1141 | ||
1003 | 1142 | ||
1004 | 1143 | ||
1005 | 1144 | ||
1006 | 1145 |