Редакция 167 | К новейшей редакции | Только различия | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 167 | Редакция 182 | ||
---|---|---|---|
1 | 1 | ||
2 | /****************************************************************************
|
2 | /****************************************************************************
|
3 | **
|
3 | **
|
4 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
4 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
5 | ** All rights reserved.
|
5 | ** All rights reserved.
|
6 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
6 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
7 | **
|
7 | **
|
8 | ** This file is part of the examples of the Qt Toolkit.
|
8 | ** This file is part of the examples of the Qt Toolkit.
|
9 | **
|
9 | **
|
10 | ** $QT_BEGIN_LICENSE:LGPL$
|
10 | ** $QT_BEGIN_LICENSE:LGPL$
|
11 | ** Commercial Usage
|
11 | ** Commercial Usage
|
12 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
12 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
13 | ** accordance with the Qt Commercial License Agreement provided with the
|
13 | ** accordance with the Qt Commercial License Agreement provided with the
|
14 | ** Software or, alternatively, in accordance with the terms contained in
|
14 | ** Software or, alternatively, in accordance with the terms contained in
|
15 | ** a written agreement between you and Nokia.
|
15 | ** a written agreement between you and Nokia.
|
16 | **
|
16 | **
|
17 | ** GNU Lesser General Public License Usage
|
17 | ** GNU Lesser General Public License Usage
|
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
19 | ** General Public License version 2.1 as published by the Free Software
|
19 | ** General Public License version 2.1 as published by the Free Software
|
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
21 | ** packaging of this file. Please review the following information to
|
21 | ** packaging of this file. Please review the following information to
|
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
24 | **
|
24 | **
|
25 | ** In addition, as a special exception, Nokia gives you certain additional
|
25 | ** In addition, as a special exception, Nokia gives you certain additional
|
26 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
26 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
28 | **
|
28 | **
|
29 | ** GNU General Public License Usage
|
29 | ** GNU General Public License Usage
|
30 | ** Alternatively, this file may be used under the terms of the GNU
|
30 | ** Alternatively, this file may be used under the terms of the GNU
|
31 | ** General Public License version 3.0 as published by the Free Software
|
31 | ** General Public License version 3.0 as published by the Free Software
|
32 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
32 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
33 | ** packaging of this file. Please review the following information to
|
33 | ** packaging of this file. Please review the following information to
|
34 | ** ensure the GNU General Public License version 3.0 requirements will be
|
34 | ** ensure the GNU General Public License version 3.0 requirements will be
|
35 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
35 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
36 | **
|
36 | **
|
37 | ** If you have questions regarding the use of this file, please contact
|
37 | ** If you have questions regarding the use of this file, please contact
|
38 | ** Nokia at qt-info@nokia.com.
|
38 | ** Nokia at qt-info@nokia.com.
|
39 | ** $QT_END_LICENSE$
|
39 | ** $QT_END_LICENSE$
|
40 | **
|
40 | **
|
41 | ****************************************************************************/
|
41 | ****************************************************************************/
|
42 | 42 | ||
43 | /*
|
43 | /*
|
44 | delegate.cpp
|
44 | delegate.cpp
|
45 | 45 | ||
46 | A delegate that allows the user to change integer values from the model
|
46 | A delegate that allows the user to change integer values from the model
|
47 | using a spin box widget.
|
47 | using a spin box widget.
|
48 | */
|
48 | */
|
49 | 49 | ||
50 | #include <QtGui>
|
50 | #include <QtGui>
|
51 | 51 | ||
52 | #include "delegate.h"
|
52 | #include "delegate.h"
|
53 | 53 | ||
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 | // SpinBoxDelegate::getItems();
|
60 | }
|
60 | }
|
61 | //! [0]
|
61 | //! [0]
|
62 | 62 | ||
63 | //! [1]
|
63 | //! [1]
|
64 | QWidget *SpinBoxDelegate::createEditor(QWidget *parent, |
64 | QWidget *SpinBoxDelegate::createEditor(QWidget *parent, |
65 | const QStyleOptionViewItem &/* option */, |
65 | const QStyleOptionViewItem &/* option */, |
66 | const QModelIndex &/* index */) const |
66 | const QModelIndex &/* index */) const |
67 | {
|
67 | {
|
68 | QStringList ID_list;
|
68 | QStringList ID_list;
|
69 | QStringList Name_list;
|
69 | QStringList Name_list;
|
70 | 70 | ||
71 | // getItems();
|
71 | // getItems();
|
72 | 72 | ||
73 | 73 | ||
74 | 74 | ||
75 | 75 | ||
76 | 76 | ||
77 | ID_list = items.keys(); |
77 | ID_list = items.keys(); |
78 | Name_list = items.values(); |
78 | Name_list = items.values(); |
79 | 79 | ||
80 | QComboBox *editor = new QComboBox(parent); |
80 | QComboBox *editor = new QComboBox(parent); |
81 | 81 | ||
82 | /*
|
82 | /*
|
83 | editor->addItem("0");
|
83 | editor->addItem("0");
|
84 | editor->addItem("1");
|
84 | editor->addItem("1");
|
85 | editor->addItem("2");
|
85 | editor->addItem("2");
|
86 | editor->addItem("3");
|
86 | editor->addItem("3");
|
87 | editor->addItem("4");
|
87 | editor->addItem("4");
|
88 | editor->addItem("5");
|
88 | editor->addItem("5");
|
89 | editor->addItem("6");
|
89 | editor->addItem("6");
|
90 | editor->addItem("7");
|
90 | editor->addItem("7");
|
91 | editor->addItem("8");
|
91 | editor->addItem("8");
|
92 | editor->addItem("9");
|
92 | editor->addItem("9");
|
93 | */
|
93 | */
|
94 | 94 | ||
95 | // editor->addItem("0");
|
95 | // editor->addItem("0");
|
96 | 96 | ||
97 | editor->addItems(Name_list); |
97 | editor->addItems(Name_list); |
98 | return editor; |
98 | return editor; |
99 | }
|
99 | }
|
100 | //! [1]
|
100 | //! [1]
|
101 | 101 | ||
102 | //! [2]
|
102 | //! [2]
|
103 | void SpinBoxDelegate::setEditorData(QWidget *editor, |
103 | void SpinBoxDelegate::setEditorData(QWidget *editor, |
104 | const QModelIndex &index) const |
104 | const QModelIndex &index) const |
105 | {
|
105 | {
|
106 | QString value = index.model()->data(index, Qt::EditRole).toString(); |
106 | QString value = index.model()->data(index, Qt::EditRole).toString(); |
107 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
107 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
108 | 108 | ||
109 | QStringList ID_list;
|
109 | QStringList ID_list;
|
110 | QStringList Name_list;
|
110 | QStringList Name_list;
|
111 | int curr_index; |
111 | int curr_index; |
112 | 112 | ||
113 | ID_list = items.keys(); |
113 | ID_list = items.keys(); |
114 | Name_list = items.values(); |
114 | Name_list = items.values(); |
115 | 115 | ||
116 | curr_index = ID_list.indexOf(value); |
116 | curr_index = ID_list.indexOf(value); |
117 | comboBox->setCurrentIndex(curr_index); |
117 | comboBox->setCurrentIndex(curr_index); |
118 | /****************************************************
|
118 | /****************************************************
|
119 | if (value == "0") comboBox->setCurrentIndex(0);
|
119 | if (value == "0") comboBox->setCurrentIndex(0);
|
120 | if (value == "1") comboBox->setCurrentIndex(1);
|
120 | if (value == "1") comboBox->setCurrentIndex(1);
|
121 | if (value == "2") comboBox->setCurrentIndex(2);
|
121 | if (value == "2") comboBox->setCurrentIndex(2);
|
122 | if (value == "3") comboBox->setCurrentIndex(3);
|
122 | if (value == "3") comboBox->setCurrentIndex(3);
|
123 | if (value == "4") comboBox->setCurrentIndex(4);
|
123 | if (value == "4") comboBox->setCurrentIndex(4);
|
124 | if (value == "5") comboBox->setCurrentIndex(5);
|
124 | if (value == "5") comboBox->setCurrentIndex(5);
|
125 | if (value == "6") comboBox->setCurrentIndex(6);
|
125 | if (value == "6") comboBox->setCurrentIndex(6);
|
126 | if (value == "7") comboBox->setCurrentIndex(7);
|
126 | if (value == "7") comboBox->setCurrentIndex(7);
|
127 | if (value == "8") comboBox->setCurrentIndex(8);
|
127 | if (value == "8") comboBox->setCurrentIndex(8);
|
128 | if (value == "9") comboBox->setCurrentIndex(9);
|
128 | if (value == "9") comboBox->setCurrentIndex(9);
|
129 | ******************************************************/
|
129 | ******************************************************/
|
130 | comboBox->setEditable(true); |
130 | comboBox->setEditable(true); |
131 | 131 | ||
132 | 132 | ||
133 | //comboBox->setItemText(0, value);
|
133 | //comboBox->setItemText(0, value);
|
134 | 134 | ||
135 | }
|
135 | }
|
136 | //! [2]
|
136 | //! [2]
|
137 | 137 | ||
138 | //! [3]
|
138 | //! [3]
|
139 | void SpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, |
139 | void SpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, |
140 | const QModelIndex &index) const |
140 | const QModelIndex &index) const |
141 | {
|
141 | {
|
142 | QStringList ID_list;
|
142 | QStringList ID_list;
|
143 | QStringList Name_list;
|
143 | QStringList Name_list;
|
144 | 144 | ||
145 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
145 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
146 | int currIndex; |
146 | int currIndex; |
147 | currIndex = comboBox->currentIndex(); |
147 | currIndex = comboBox->currentIndex(); |
148 | // QString value = comboBox->itemText(currIndex);
|
148 | // QString value = comboBox->itemText(currIndex);
|
149 | 149 | ||
150 | ID_list = items.keys(); |
150 | ID_list = items.keys(); |
151 | Name_list = items.values(); |
151 | Name_list = items.values(); |
152 | 152 | ||
153 | QString value = ID_list.at(currIndex); |
153 | QString value = ID_list.at(currIndex); |
154 | model->setData(index, value, Qt::EditRole); |
154 | model->setData(index, value, Qt::EditRole); |
155 | 155 | ||
156 | 156 | ||
157 | }
|
157 | }
|
158 | //! [3]
|
158 | //! [3]
|
159 | 159 | ||
160 | //! [4]
|
160 | //! [4]
|
161 | void SpinBoxDelegate::updateEditorGeometry(QWidget *editor, |
161 | void SpinBoxDelegate::updateEditorGeometry(QWidget *editor, |
162 | const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
162 | const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
163 | {
|
163 | {
|
164 | editor->setGeometry(option.rect); |
164 | editor->setGeometry(option.rect); |
165 | }
|
165 | }
|
166 | //! [4]
|
166 | //! [4]
|
167 | 167 | ||
168 | void SpinBoxDelegate::getItems(){ |
168 | void SpinBoxDelegate::getItems(){ |
169 | QMap <QString, QString> result_map; |
169 | QMap <QString, QString> result_map; |
170 | QSqlQuery q;
|
170 | QSqlQuery q;
|
171 | QString query_str;
|
171 | QString query_str;
|
172 | bool ok; |
172 | bool ok; |
173 | 173 | ||
174 | query_str = tr("select * from `ListOfClasses`"); |
174 | query_str = tr("select * from `ListOfClasses`"); |
175 | q.prepare(query_str); |
175 | q.prepare(query_str); |
176 | 176 | ||
177 | 177 | ||
178 | ok = q.exec(); |
178 | ok = q.exec(); |
179 | 179 | ||
180 | 180 | ||
181 | 181 | ||
182 | 182 | ||
183 | if (!ok) { |
183 | if (!ok) { |
184 | /*
|
184 | /*
|
185 | QString error_str;
|
185 | QString error_str;
|
186 | error_str = tr("íå óäàëîñü ïîëó÷èòü ñïèñîê îáúåêòîâ èç òàáëèöû ");
|
186 | error_str = tr("íå óäàëîñü ïîëó÷èòü ñïèñîê îáúåêòîâ èç òàáëèöû ");
|
187 | error_str.append(inctance);
|
187 | error_str.append(inctance);
|
188 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
|
188 | QMessageBox::critical( // Äèàëîã ñ ñîîáùåíèåì îá îøèáêå.
|
189 | this, // Ðîäèòåëüñêèé âèäæåò.
|
189 | this, // Ðîäèòåëüñêèé âèäæåò.
|
190 | QObject::tr("Database Error"), // Çàãîëîâîê.
|
190 | QObject::tr("Database Error"), // Çàãîëîâîê.
|
191 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ.
|
191 | q.lastError().text()); // Òåêñò ñîîáùåíèÿ.
|
192 | // tr("íå óäàëîñü ïîëó÷èòü ñïèñîê îáúåêòîâ èç òàáëèöû ")); // Òåêñò ñîîáùåíèÿ.
|
192 | // tr("íå óäàëîñü ïîëó÷èòü ñïèñîê îáúåêòîâ èç òàáëèöû ")); // Òåêñò ñîîáùåíèÿ.
|
193 | 193 | ||
194 | */
|
194 | */
|
195 | items.clear(); |
195 | items.clear(); |
196 | return; |
196 | return; |
197 | }
|
197 | }
|
198 | 198 | ||
199 | 199 | ||
200 | // field_inctance = q.record().indexOf(tr("TableWhithInstance"));
|
200 | // field_inctance = q.record().indexOf(tr("TableWhithInstance"));
|
201 | items.clear(); |
201 | items.clear(); |
202 | while(q.next()){ |
202 | while(q.next()){ |
203 | 203 | ||
204 | QString ID;
|
204 | QString ID;
|
205 | QString ClassName;
|
205 | QString ClassName;
|
206 | ID = q.value(0).toString(); // îïðåäåëÿåì ID |
206 | ID = q.value(0).toString(); // îïðåäåëÿåì ID |
207 | ClassName = q.value(1).toString(); // îïðåäåëÿåì Name |
207 | ClassName = q.value(1).toString(); // îïðåäåëÿåì Name |
208 | items.insert(ID, ClassName); |
208 | items.insert(ID, ClassName); |
209 | }
|
209 | }
|
210 | 210 | ||
211 | 211 | ||
212 | // return result_map;
|
212 | // return result_map;
|
213 | }
|
213 | }
|
214 | 214 | ||
215 | 215 | ||
216 | 216 | ||
217 | 217 | ||
218 | 218 | ||
219 | 219 | ||
220 | 220 | ||
221 | 221 | ||
222 | 222 | ||
223 | 223 | ||
224 | 224 | ||
225 | 225 | ||
226 | 226 | ||
227 | 227 | ||
228 | 228 | ||
229 | 229 | ||
230 | 230 | ||
231 | MyDEDelegate::MyDEDelegate( |
231 | MyDEDelegate::MyDEDelegate( |
232 | bool calpopup,
|
232 | bool calpopup,
|
233 | QObject *parent) |
233 | QObject *parent) |
234 | : QItemDelegate(parent), |
234 | : QItemDelegate(parent), |
235 | m_calpopup(calpopup) { |
235 | m_calpopup(calpopup) { |
236 | }
|
236 | }
|
237 | 237 | ||
238 | QWidget *MyDEDelegate::createEditor( |
238 | QWidget *MyDEDelegate::createEditor( |
239 | QWidget *parent,
|
239 | QWidget *parent,
|
240 | const QStyleOptionViewItem& /* option */, |
240 | const QStyleOptionViewItem& /* option */, |
241 | const QModelIndex& /* index */) const { |
241 | const QModelIndex& /* index */) const { |
242 | QDateEdit *editor = new QDateEdit(parent); |
242 | QDateEdit *editor = new QDateEdit(parent); |
243 | editor->setCalendarPopup(m_calpopup); |
243 | editor->setCalendarPopup(m_calpopup); |
244 | editor->installEventFilter(const_cast<MyDEDelegate*>(this)); |
244 | editor->installEventFilter(const_cast<MyDEDelegate*>(this)); |
245 | return editor; |
245 | return editor; |
246 | }
|
246 | }
|
247 | 247 | ||
248 | void MyDEDelegate::setEditorData( |
248 | void MyDEDelegate::setEditorData( |
249 | QWidget *editor,
|
249 | QWidget *editor,
|
250 | const QModelIndex &index) const { |
250 | const QModelIndex &index) const { |
251 | QDate value = index.model()->data( |
251 | QDate value = index.model()->data( |
252 | index, Qt::EditRole).toDate(); |
252 | index, Qt::EditRole).toDate(); |
253 | QDateEdit *de = static_cast<QDateEdit*>(editor); |
253 | QDateEdit *de = static_cast<QDateEdit*>(editor); |
254 | de->setDate(value); |
254 | de->setDate(value); |
255 | }
|
255 | }
|
256 | 256 | ||
257 | void MyDEDelegate::setModelData( |
257 | void MyDEDelegate::setModelData( |
258 | QWidget *editor,
|
258 | QWidget *editor,
|
259 | QAbstractItemModel *model,
|
259 | QAbstractItemModel *model,
|
260 | const QModelIndex& index) const { |
260 | const QModelIndex& index) const { |
261 | QDateEdit *de = static_cast<QDateEdit*>(editor); |
261 | QDateEdit *de = static_cast<QDateEdit*>(editor); |
262 | de->interpretText(); |
262 | de->interpretText(); |
263 | QDate value = de->date(); |
263 | QDate value = de->date(); |
264 | model->setData(index, value); |
264 | model->setData(index, value); |
265 | }
|
265 | }
|
266 | 266 | ||
267 | void MyDEDelegate::updateEditorGeometry( |
267 | void MyDEDelegate::updateEditorGeometry( |
268 | QWidget *editor,
|
268 | QWidget *editor,
|
269 | const QStyleOptionViewItem &option, |
269 | const QStyleOptionViewItem &option, |
270 | const QModelIndex& /* index */) const { |
270 | const QModelIndex& /* index */) const { |
271 | editor->setGeometry(option.rect); |
271 | editor->setGeometry(option.rect); |
272 | }
|
272 | }
|
273 | 273 | ||
274 | 274 | ||
275 | 275 | ||
276 | CPictureDelegate::CPictureDelegate( QObject * parent ) : QItemDelegate(parent) |
276 | CPictureDelegate::CPictureDelegate( QObject * parent ) : QItemDelegate(parent) |
277 | {
|
277 | {
|
278 | }
|
278 | }
|
279 | 279 | ||
280 | 280 | ||
281 | 281 | ||
282 | 282 | ||
283 | 283 | ||
284 | QWidget *CPictureDelegate::createEditor(QWidget *parent, |
284 | QWidget *CPictureDelegate::createEditor(QWidget *parent, |
285 | const QStyleOptionViewItem &/* option */, |
285 | const QStyleOptionViewItem &/* option */, |
286 | const QModelIndex &/* index */) const |
286 | const QModelIndex &/* index */) const |
287 | {
|
287 | {
|
288 | 288 | ||
289 | IconForm *editor = new IconForm(parent); |
289 | IconForm *editor = new IconForm(parent); |
290 | return editor; |
290 | return editor; |
291 | 291 | ||
292 | }
|
292 | }
|
293 | 293 | ||
294 | 294 | ||
295 | 295 | ||
296 | 296 | ||
297 | void CPictureDelegate::setEditorData(QWidget *editor, |
297 | void CPictureDelegate::setEditorData(QWidget *editor, |
298 | const QModelIndex &index) const |
298 | const QModelIndex &index) const |
299 | {
|
299 | {
|
300 | 300 | ||
301 | 301 | ||
302 | const QAbstractItemModel * model = index.model(); |
302 | const QAbstractItemModel * model = index.model(); |
303 | IconForm *icnFrm = static_cast<IconForm*>(editor); |
303 | IconForm *icnFrm = static_cast<IconForm*>(editor); |
304 | QVariant currentImage = model->data(index,0); |
304 | QVariant currentImage = model->data(index,0); |
305 | QByteArray bytes = currentImage.toByteArray(); |
305 | QByteArray bytes = currentImage.toByteArray(); |
306 | if (currentImage.isValid()) { |
306 | if (currentImage.isValid()) { |
307 | m_pxPicture.loadFromData(bytes); |
307 | m_pxPicture.loadFromData(bytes); |
308 | }
|
308 | }
|
309 | else { |
309 | else { |
310 | //QItemDelegate::paint(painter, option, index);
|
310 | //QItemDelegate::paint(painter, option, index);
|
311 | 311 | ||
312 | 312 | ||
313 | return; |
313 | return; |
314 | }
|
314 | }
|
315 | icnFrm->setPixmap(m_pxPicture); |
315 | icnFrm->setPixmap(m_pxPicture); |
316 | }
|
316 | }
|
317 | 317 | ||
318 | 318 | ||
319 | 319 | ||
320 | 320 | ||
321 | void CPictureDelegate::setModelData( |
321 | void CPictureDelegate::setModelData( |
322 | QWidget *editor,
|
322 | QWidget *editor,
|
323 | QAbstractItemModel *model,
|
323 | QAbstractItemModel *model,
|
324 | const QModelIndex& index) const { |
324 | const QModelIndex& index) const { |
325 | IconForm *icnFrm = static_cast<IconForm*>(editor); |
325 | IconForm *icnFrm = static_cast<IconForm*>(editor); |
326 | if (!(icnFrm->dataIsChanged())) return; |
326 | if (!(icnFrm->dataIsChanged())) return; |
327 | 327 | ||
- | 328 | if (!(icnFrm->pixmap().isNull())){ // åñëè íå óäàëèëè èêîíêó |
|
328 | m_pxPicture = icnFrm->pixmap(); |
329 | m_pxPicture = icnFrm->pixmap(); |
329 | QImage currentImage = m_pxPicture.toImage(); |
330 | QImage currentImage = m_pxPicture.toImage(); |
330 | QByteArray bytes;
|
331 | QByteArray bytes;
|
331 | QBuffer buffer(&bytes); |
332 | QBuffer buffer(&bytes); |
332 | buffer.open(QIODevice::WriteOnly); |
333 | buffer.open(QIODevice::WriteOnly); |
333 | currentImage.save(&buffer, "PNG"); |
334 | currentImage.save(&buffer, "PNG"); |
334 | 335 | ||
335 | 336 | ||
336 | 337 | ||
337 | 338 | ||
338 | model->setData(index, QVariant (bytes), Qt::EditRole); |
339 | model->setData(index, QVariant (bytes), Qt::EditRole); |
339 | 340 | ||
340 | // int widht = m_pxPicture.width();
|
341 | // int widht = m_pxPicture.width();
|
341 | // int heigh = m_pxPicture.height();
|
342 | // int heigh = m_pxPicture.height();
|
342 | // tblView->setRowHeight(index.row(), heigh + 10);
|
343 | // tblView->setRowHeight(index.row(), heigh + 10);
|
343 | // model->submitAll();
|
344 | // model->submitAll();
|
344 | 345 | }
|
|
- | 346 | else { // èêîíêó óäàëèëè |
|
- | 347 | QVariant val_null;
|
|
- | 348 | model->setData(index, val_null, Qt::EditRole); |
|
345 | 349 | }
|
|
346 | 350 | ||
347 | 351 | ||
348 | // model->setData(index, value);
|
352 | // model->setData(index, value);
|
349 | }
|
353 | }
|
350 | 354 | ||
351 | 355 | ||
352 | 356 | ||
353 | void CPictureDelegate::updateEditorGeometry( |
357 | void CPictureDelegate::updateEditorGeometry( |
354 | QWidget *editor,
|
358 | QWidget *editor,
|
355 | const QStyleOptionViewItem &option, |
359 | const QStyleOptionViewItem &option, |
356 | const QModelIndex& /* index */) const { |
360 | const QModelIndex& /* index */) const { |
357 | 361 | ||
358 | 362 | ||
359 | // QRect r(option.rect.x() + option.rect.width()/2 - 7, option.rect.y() + option.rect.height()/2 - 7, 150, 100);
|
363 | // QRect r(option.rect.x() + option.rect.width()/2 - 7, option.rect.y() + option.rect.height()/2 - 7, 150, 100);
|
360 | // editor->setGeometry(r);
|
364 | // editor->setGeometry(r);
|
361 | 365 | ||
362 | editor->setGeometry(option.rect); |
366 | editor->setGeometry(option.rect); |
363 | }
|
367 | }
|
364 | 368 | ||
365 | 369 | ||
366 | 370 | ||
367 | 371 | ||
368 | void CPictureDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const |
372 | void CPictureDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const |
369 | {
|
373 | {
|
370 | 374 | ||
371 | 375 | ||
372 | m_pxPicture.fill( QColor(Qt::white) ); |
376 | m_pxPicture.fill( QColor(Qt::white) ); |
373 | 377 | ||
374 | const QAbstractItemModel * model = index.model(); |
378 | const QAbstractItemModel * model = index.model(); |
375 | QString sFileName = model->data( index, Qt::DisplayRole ).toString(); |
379 | QString sFileName = model->data( index, Qt::DisplayRole ).toString(); |
376 | 380 | ||
377 | QVariant currentImage = model->data(index,0); |
381 | QVariant currentImage = model->data(index,0); |
378 | 382 | ||
379 | - | ||
380 | QByteArray bytes = currentImage.toByteArray(); |
383 | QByteArray bytes = currentImage.toByteArray(); |
381 | // QImage image;
|
384 | // QImage image;
|
382 | // image.loadFromData(bytes);
|
385 | // image.loadFromData(bytes);
|
383 | 386 | ||
384 | 387 | ||
385 | if (currentImage.isValid()) { |
388 | if (currentImage.isValid()) { |
386 | m_pxPicture.loadFromData(bytes); |
389 | m_pxPicture.loadFromData(bytes); |
387 | 390 | ||
388 | }
|
391 | }
|
389 | else { |
392 | else { |
- | 393 | int i; |
|
- | 394 | i++; |
|
390 | //QItemDelegate::paint(painter, option, index);
|
395 | //QItemDelegate::paint(painter, option, index);
|
391 | return; |
396 | return; |
392 | }
|
397 | }
|
393 | 398 | ||
394 | 399 | ||
395 | 400 | ||
396 | 401 | ||
397 | 402 | ||
398 | /*
|
403 | /*
|
399 | 404 | ||
400 | if ( !sFileName.isEmpty() )
|
405 | if ( !sFileName.isEmpty() )
|
401 | m_pxPicture.load( sFileName );
|
406 | m_pxPicture.load( sFileName );
|
402 | else {
|
407 | else {
|
403 | //QItemDelegate::paint(painter, option, index);
|
408 | //QItemDelegate::paint(painter, option, index);
|
404 | return;
|
409 | return;
|
405 | }
|
410 | }
|
406 | */
|
411 | */
|
407 | 412 | ||
408 | 413 | ||
409 | QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) ? |
414 | QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) ? |
410 | ((option.state & QStyle::State_Active) ? QPalette::Normal : QPalette::Inactive ) : |
415 | ((option.state & QStyle::State_Active) ? QPalette::Normal : QPalette::Inactive ) : |
411 | QPalette::Disabled; |
416 | QPalette::Disabled; |
412 | 417 | ||
413 | if (option.state & QStyle::State_Selected) |
418 | if (option.state & QStyle::State_Selected) |
414 | 419 | ||
415 | 420 | ||
416 | painter->fillRect(option.rect, option.palette.color(cg, QPalette::Highlight)); |
421 | painter->fillRect(option.rect, option.palette.color(cg, QPalette::Highlight)); |
417 | 422 | ||
418 | int nX = option.rect.x() + ( ( option.rect.width() - m_pxPicture.rect().width() ) / 2 ); |
423 | int nX = option.rect.x() + ( ( option.rect.width() - m_pxPicture.rect().width() ) / 2 ); |
419 | int nY = option.rect.y() + ( ( option.rect.height() - m_pxPicture.rect().height() ) / 2 ); |
424 | int nY = option.rect.y() + ( ( option.rect.height() - m_pxPicture.rect().height() ) / 2 ); |
420 | painter->drawPixmap( nX, nY, m_pxPicture ); |
425 | painter->drawPixmap( nX, nY, m_pxPicture ); |
421 | 426 | ||
422 | 427 | ||
423 | // drawFocus(painter, option, option.rect.adjusted(0, 0, -1, -1)); // since we draw the grid ourselves
|
428 | // drawFocus(painter, option, option.rect.adjusted(0, 0, -1, -1)); // since we draw the grid ourselves
|
424 | 429 | ||
425 | /*
|
430 | /*
|
426 | QPen pen = painter->pen();
|
431 | QPen pen = painter->pen();
|
427 | painter->setPen(option.palette.color(QPalette::Mid));
|
432 | painter->setPen(option.palette.color(QPalette::Mid));
|
428 | painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
|
433 | painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
|
429 | painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
|
434 | painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
|
430 | painter->setPen(pen);
|
435 | painter->setPen(pen);
|
431 | */
|
436 | */
|
432 | }
|
437 | }
|
433 | 438 | ||
434 | 439 | ||
435 | void CPictureDelegate::setTableView(QTableView* table){ |
440 | void CPictureDelegate::setTableView(QTableView* table){ |
436 | tblView = table; |
441 | tblView = table; |
437 | }
|
442 | }
|
438 | 443 |