Редакция 53 | Редакция 161 | К новейшей редакции | Содержимое файла | Сравнить с предыдущей | Последнее изменение | Открыть журнал | RSS
Редакция | Автор | № строки | Строка |
---|---|---|---|
53 | pingvin | 1 | |
2 | ** |
||
3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
||
4 | ** All rights reserved. |
||
5 | ** Contact: Nokia Corporation (qt-info@nokia.com) |
||
6 | ** |
||
7 | ** This file is part of the examples of the Qt Toolkit. |
||
8 | ** |
||
9 | ** $QT_BEGIN_LICENSE:LGPL$ |
||
10 | ** Commercial Usage |
||
11 | ** Licensees holding valid Qt Commercial licenses may use this file in |
||
12 | ** accordance with the Qt Commercial License Agreement provided with the |
||
13 | ** Software or, alternatively, in accordance with the terms contained in |
||
14 | ** a written agreement between you and Nokia. |
||
15 | ** |
||
16 | ** GNU Lesser General Public License Usage |
||
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
||
18 | ** General Public License version 2.1 as published by the Free Software |
||
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the |
||
20 | ** packaging of this file. Please review the following information to |
||
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements |
||
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
||
23 | ** |
||
24 | ** In addition, as a special exception, Nokia gives you certain additional |
||
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception |
||
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
||
27 | ** |
||
28 | ** GNU General Public License Usage |
||
29 | ** Alternatively, this file may be used under the terms of the GNU |
||
30 | ** General Public License version 3.0 as published by the Free Software |
||
31 | ** Foundation and appearing in the file LICENSE.GPL included in the |
||
32 | ** packaging of this file. Please review the following information to |
||
33 | ** ensure the GNU General Public License version 3.0 requirements will be |
||
34 | ** met: http://www.gnu.org/copyleft/gpl.html. |
||
35 | ** |
||
36 | ** If you have questions regarding the use of this file, please contact |
||
37 | ** Nokia at qt-info@nokia.com. |
||
38 | ** $QT_END_LICENSE$ |
||
39 | ** |
||
40 | ****************************************************************************/ |
||
41 | |||
42 | |||
43 | delegate.cpp |
||
44 | |||
45 | |||
46 | using a spin box widget. |
||
47 | */ |
||
48 | |||
49 | |||
50 | |||
51 | |||
52 | |||
53 | |||
54 | |||
55 | SpinBoxDelegate::SpinBoxDelegate(QObject *parent) |
||
56 | : QItemDelegate(parent) |
||
57 | { |
||
58 | // SpinBoxDelegate::getItems(); |
||
134 | pingvin | 59 | } |
53 | pingvin | 60 | //! [0] |
61 | |||
62 | |||
63 | QWidget *SpinBoxDelegate::createEditor(QWidget *parent, |
||
64 | const QStyleOptionViewItem &/* option */, |
||
65 | const QModelIndex &/* index */) const |
||
66 | { |
||
67 | QStringList ID_list; |
||
134 | pingvin | 68 | QStringList Name_list; |
69 | |||
70 | |||
71 | |||
72 | |||
73 | |||
74 | |||
75 | |||
76 | |||
77 | Name_list = items.values(); |
||
78 | |||
79 | |||
53 | pingvin | 80 | |
134 | pingvin | 81 | |
82 | editor->addItem("0"); |
||
53 | pingvin | 83 | editor->addItem("1"); |
84 | editor->addItem("2"); |
||
85 | editor->addItem("3"); |
||
86 | editor->addItem("4"); |
||
87 | editor->addItem("5"); |
||
88 | editor->addItem("6"); |
||
89 | editor->addItem("7"); |
||
90 | editor->addItem("8"); |
||
91 | editor->addItem("9"); |
||
92 | */ |
||
134 | pingvin | 93 | |
53 | pingvin | 94 | |
134 | pingvin | 95 | |
96 | |||
97 | return editor; |
||
53 | pingvin | 98 | } |
99 | //! [1] |
||
100 | |||
101 | |||
102 | void SpinBoxDelegate::setEditorData(QWidget *editor, |
||
103 | const QModelIndex &index) const |
||
104 | { |
||
105 | QString value = index.model()->data(index, Qt::EditRole).toString(); |
||
134 | pingvin | 106 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
107 | |||
53 | pingvin | 108 | |
134 | pingvin | 109 | QStringList Name_list; |
110 | int curr_index; |
||
111 | |||
53 | pingvin | 112 | |
134 | pingvin | 113 | Name_list = items.values(); |
114 | |||
53 | pingvin | 115 | |
134 | pingvin | 116 | comboBox->setCurrentIndex(curr_index); |
117 | /**************************************************** |
||
118 | if (value == "0") comboBox->setCurrentIndex(0); |
||
119 | if (value == "1") comboBox->setCurrentIndex(1); |
||
120 | if (value == "2") comboBox->setCurrentIndex(2); |
||
121 | if (value == "3") comboBox->setCurrentIndex(3); |
||
122 | if (value == "4") comboBox->setCurrentIndex(4); |
||
123 | if (value == "5") comboBox->setCurrentIndex(5); |
||
124 | if (value == "6") comboBox->setCurrentIndex(6); |
||
125 | if (value == "7") comboBox->setCurrentIndex(7); |
||
126 | if (value == "8") comboBox->setCurrentIndex(8); |
||
127 | if (value == "9") comboBox->setCurrentIndex(9); |
||
128 | ******************************************************/ |
||
129 | comboBox->setEditable(true); |
||
130 | |||
131 | |||
132 | |||
53 | pingvin | 133 | |
134 | |||
135 | //! [2] |
||
136 | |||
137 | |||
138 | void SpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, |
||
139 | const QModelIndex &index) const |
||
140 | { |
||
141 | QStringList ID_list; |
||
134 | pingvin | 142 | QStringList Name_list; |
143 | |||
53 | pingvin | 144 | |
145 | int currIndex; |
||
146 | currIndex = comboBox->currentIndex(); |
||
147 | // QString value = comboBox->itemText(currIndex); |
||
134 | pingvin | 148 | |
149 | |||
150 | Name_list = items.values(); |
||
151 | |||
152 | |||
153 | model->setData(index, value, Qt::EditRole); |
||
53 | pingvin | 154 | |
134 | pingvin | 155 | |
156 | |||
53 | pingvin | 157 | //! [3] |
158 | |||
159 | |||
160 | void SpinBoxDelegate::updateEditorGeometry(QWidget *editor, |
||
161 | const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
||
162 | { |
||
163 | editor->setGeometry(option.rect); |
||
164 | } |
||
165 | //! [4] |
||
166 | |||
134 | pingvin | 167 | |
168 | QMap <QString, QString> result_map; |
||
169 | QSqlQuery q; |
||
170 | QString query_str; |
||
171 | bool ok; |
||
172 | |||
173 | |||
174 | q.prepare(query_str); |
||
175 | |||
176 | |||
177 | |||
178 | |||
179 | |||
180 | |||
181 | |||
182 | |||
183 | /* |
||
184 | QString error_str; |
||
185 | error_str = tr(" "); |
||
186 | error_str.append(inctance); |
||
187 | QMessageBox::critical( // . |
||
188 | this, // . |
||
189 | QObject::tr("Database Error"), // . |
||
190 | q.lastError().text()); // . |
||
191 | // tr(" ")); // . |
||
192 | |||
193 | |||
194 | items.clear(); |
||
195 | return; |
||
196 | } |
||
197 | |||
198 | |||
199 | |||
200 | items.clear(); |
||
201 | while(q.next()){ |
||
202 | |||
203 | |||
204 | QString ClassName; |
||
205 | ID = q.value(0).toString(); // ID |
||
206 | ClassName = q.value(1).toString(); // Name |
||
207 | items.insert(ID, ClassName); |
||
208 | } |
||
209 | |||
210 | |||
211 | |||
212 | } |
||
213 | |||
214 | |||
215 | |||
216 | |||
217 | |||
218 | |||
219 | |||
220 | |||
221 | |||
222 | |||
223 | |||
224 | |||
225 | |||
226 | |||
227 | |||
228 | |||
229 | |||
230 | |||
53 | pingvin | 231 | bool calpopup, |
232 | QObject *parent) |
||
233 | : QItemDelegate(parent), |
||
234 | m_calpopup(calpopup) { |
||
235 | } |
||
236 | |||
237 | |||
238 | QWidget *parent, |
||
239 | const QStyleOptionViewItem& /* option */, |
||
240 | const QModelIndex& /* index */) const { |
||
241 | QDateEdit *editor = new QDateEdit(parent); |
||
242 | editor->setCalendarPopup(m_calpopup); |
||
243 | editor->installEventFilter(const_cast<MyDEDelegate*>(this)); |
||
244 | return editor; |
||
245 | } |
||
246 | |||
247 | |||
248 | QWidget *editor, |
||
249 | const QModelIndex &index) const { |
||
250 | QDate value = index.model()->data( |
||
251 | index, Qt::EditRole).toDate(); |
||
252 | QDateEdit *de = static_cast<QDateEdit*>(editor); |
||
253 | de->setDate(value); |
||
254 | } |
||
255 | |||
256 | |||
257 | QWidget *editor, |
||
258 | QAbstractItemModel *model, |
||
259 | const QModelIndex& index) const { |
||
260 | QDateEdit *de = static_cast<QDateEdit*>(editor); |
||
261 | de->interpretText(); |
||
262 | QDate value = de->date(); |
||
263 | model->setData(index, value); |
||
264 | } |
||
265 | |||
266 | |||
267 | QWidget *editor, |
||
268 | const QStyleOptionViewItem &option, |
||
269 | const QModelIndex& /* index */) const { |
||
270 | editor->setGeometry(option.rect); |
||
271 | } |
||
272 |