Редакция 225 | К новейшей редакции | Содержимое файла | Сравнить с предыдущей | Последнее изменение | Открыть журнал | RSS
Редакция | Автор | № строки | Строка |
---|---|---|---|
123 | 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 | |||
44 | |||
45 | A delegate that allows the user to change integer values from the model |
||
46 | |||
47 | */ |
||
48 | |||
49 | #include <QtGui> |
||
50 | |||
51 | #include "delegate.h" |
||
52 | |||
53 | |||
54 | |||
55 | |||
56 | : QItemDelegate(parent) |
||
57 | { |
||
58 | } |
||
59 | //! [0] |
||
60 | |||
61 | void SpinBoxDelegate::setInctance(QString newInctance){ |
||
62 | |||
126 | pingvin | 63 | } |
64 | |||
65 | void SpinBoxDelegate::getItems(){ |
||
66 | |||
67 | QSqlQuery q; |
||
68 | QString query_str; |
||
69 | bool ok; |
||
70 | |||
71 | if (SpinBoxDelegate::inctance.isEmpty()) |
||
72 | |||
73 | items.clear(); |
||
74 | return; |
||
75 | } |
||
76 | |||
77 | query_str = tr("select * from `"); |
||
78 | |||
79 | query_str.append( tr("`")); |
||
80 | |||
81 | q.prepare(query_str); |
||
82 | |||
83 | |||
84 | |||
85 | |||
86 | |||
87 | |||
88 | |||
89 | |||
90 | |||
91 | QString error_str; |
||
92 | error_str = tr(" "); |
||
93 | error_str.append(inctance); |
||
94 | QMessageBox::critical( // . |
||
95 | this, // . |
||
96 | QObject::tr("Database Error"), // . |
||
97 | q.lastError().text()); // . |
||
98 | // tr(" ")); // . |
||
99 | |||
100 | */ |
||
101 | |||
102 | return; |
||
103 | } |
||
104 | |||
105 | |||
106 | |||
107 | |||
108 | while(q.next()){ |
||
129 | pingvin | 109 | |
126 | pingvin | 110 | QString ID; |
111 | |||
112 | ID = q.value(0).toString(); // ID |
||
113 | Name = q.value(1).toString(); // Name |
||
114 | items.insert(ID, Name); |
||
115 | } |
||
116 | |||
117 | |||
118 | |||
119 | |||
120 | |||
121 | |||
122 | |||
123 | |||
123 | pingvin | 124 | const QStyleOptionViewItem &/* option */, |
125 | const QModelIndex &/* index */) const |
||
126 | { |
||
127 | //QSpinBox *editor = new QSpinBox(parent); |
||
128 | //editor->setMinimum(0); |
||
129 | //editor->setMaximum(100); |
||
130 | QStringList ID_list; |
||
131 | QStringList Name_list; |
||
126 | pingvin | 132 | |
133 | // getItems(); |
||
134 | |||
135 | |||
136 | |||
137 | |||
138 | |||
139 | |||
140 | |||
141 | |||
142 | QComboBox *editor = new QComboBox(parent); |
||
143 | |||
123 | pingvin | 144 | /* |
126 | pingvin | 145 | |
146 | editor->addItem("1"); |
||
123 | pingvin | 147 | editor->addItem("2"); |
148 | editor->addItem("3"); |
||
149 | editor->addItem("4"); |
||
150 | editor->addItem("5"); |
||
151 | editor->addItem("6"); |
||
152 | editor->addItem("7"); |
||
153 | editor->addItem("8"); |
||
154 | editor->addItem("9"); |
||
155 | */ |
||
156 | |||
126 | pingvin | 157 | // editor->addItem("0"); |
123 | pingvin | 158 | |
126 | pingvin | 159 | editor->addItems(Name_list); |
160 | |||
161 | return editor; |
||
179 | pingvin | 162 | } |
123 | pingvin | 163 | //! [1] |
164 | |||
165 | //! [2] |
||
166 | |||
167 | const QModelIndex &index) const |
||
168 | { |
||
169 | // int value = index.model()->data(index, Qt::EditRole).toInt(); |
||
170 | |||
171 | // QSpinBox *spinBox = static_cast<QSpinBox*>(editor); |
||
172 | |||
173 | QString value = index.model()->data(index, Qt::EditRole).toString(); |
||
174 | |||
175 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
||
136 | pingvin | 176 | |
123 | pingvin | 177 | QStringList ID_list; |
126 | pingvin | 178 | |
179 | int curr_index; |
||
180 | |||
181 | ID_list = items.keys(); |
||
182 | |||
183 | |||
184 | curr_index = ID_list.indexOf(value); |
||
185 | |||
186 | comboBox->setCurrentIndex(curr_index); |
||
136 | pingvin | 187 | /**************************************************** |
126 | pingvin | 188 | if (value == "0") comboBox->setCurrentIndex(0); |
189 | if (value == "1") comboBox->setCurrentIndex(1); |
||
123 | pingvin | 190 | if (value == "2") comboBox->setCurrentIndex(2); |
191 | if (value == "3") comboBox->setCurrentIndex(3); |
||
192 | if (value == "4") comboBox->setCurrentIndex(4); |
||
193 | if (value == "5") comboBox->setCurrentIndex(5); |
||
194 | if (value == "6") comboBox->setCurrentIndex(6); |
||
195 | if (value == "7") comboBox->setCurrentIndex(7); |
||
196 | if (value == "8") comboBox->setCurrentIndex(8); |
||
197 | if (value == "9") comboBox->setCurrentIndex(9); |
||
198 | ******************************************************/ |
||
199 | comboBox->setEditable(false); |
||
126 | pingvin | 200 | |
179 | pingvin | 201 | |
123 | pingvin | 202 | |
203 | |||
204 | } |
||
205 | |||
206 | |||
207 | //! [3] |
||
208 | |||
209 | const QModelIndex &index) const |
||
210 | { |
||
211 | // QSpinBox *spinBox = static_cast<QSpinBox*>(editor); |
||
212 | // spinBox->interpretText(); |
||
213 | // int value = spinBox->value(); |
||
214 | |||
215 | // model->setData(index, value, Qt::EditRole); |
||
216 | |||
217 | QStringList Name_list; |
||
126 | pingvin | 218 | |
219 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
||
123 | pingvin | 220 | |
221 | currIndex = comboBox->currentIndex(); |
||
222 | if (currIndex==-1) return; |
||
223 | // QString value = comboBox->itemText(currIndex); |
||
136 | pingvin | 224 | |
126 | pingvin | 225 | ID_list = items.keys(); |
226 | |||
227 | |||
228 | QString value = ID_list.at(currIndex); |
||
229 | |||
230 | } |
||
123 | pingvin | 231 | //! [3] |
232 | |||
233 | //! [4] |
||
234 | |||
235 | const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
||
236 | { |
||
237 | editor->setGeometry(option.rect); |
||
238 | } |
||
239 | |||
240 | |||
219 | pingvin | 241 | |
242 | |||
243 | |||
244 | |||
245 | |||
246 | |||
247 | |||
248 | |||
249 | |||
250 | |||
251 | |||
252 | : QItemDelegate(parent) |
||
253 | { |
||
254 | } |
||
255 | //! [0] |
||
256 | |||
257 | void FilterSpinBoxDelegate::setClassID(QString newClassID){ |
||
258 | |||
259 | } |
||
260 | |||
261 | void FilterSpinBoxDelegate::getItems(){ |
||
262 | |||
263 | QSqlQuery q; |
||
264 | QString query_str; |
||
265 | bool ok; |
||
266 | |||
267 | if (FilterSpinBoxDelegate::class_id.isEmpty()) |
||
268 | |||
269 | items.clear(); |
||
270 | return; |
||
271 | } |
||
272 | |||
273 | query_str = tr("select * from `DescriptionOfClasses` where `ClassIdentifer` = '"); |
||
274 | |||
275 | query_str.append( tr("'")); |
||
276 | |||
277 | q.prepare(query_str); |
||
278 | |||
279 | |||
280 | |||
281 | |||
282 | |||
283 | |||
284 | |||
285 | |||
286 | |||
287 | QString error_str; |
||
288 | error_str = tr(" "); |
||
289 | error_str.append(inctance); |
||
290 | QMessageBox::critical( // . |
||
291 | this, // . |
||
292 | QObject::tr("Database Error"), // . |
||
293 | q.lastError().text()); // . |
||
294 | // tr(" ")); // . |
||
295 | |||
296 | */ |
||
297 | |||
298 | return; |
||
299 | } |
||
300 | |||
301 | |||
302 | |||
303 | |||
304 | while(q.next()){ |
||
305 | |||
306 | QString ID; |
||
307 | |||
308 | ID = q.value(0).toString(); // ID |
||
309 | Name = q.value(1).toString(); // Name |
||
310 | items.insert(ID, Name); |
||
311 | } |
||
312 | |||
313 | |||
314 | |||
315 | |||
316 | |||
317 | |||
318 | |||
319 | |||
320 | const QStyleOptionViewItem &/* option */, |
||
321 | const QModelIndex &/* index */) const |
||
322 | { |
||
323 | //QSpinBox *editor = new QSpinBox(parent); |
||
324 | //editor->setMinimum(0); |
||
325 | //editor->setMaximum(100); |
||
326 | QStringList ID_list; |
||
327 | QStringList Name_list; |
||
328 | |||
329 | // getItems(); |
||
330 | |||
331 | |||
332 | |||
333 | |||
334 | |||
335 | |||
336 | |||
337 | |||
338 | QComboBox *editor = new QComboBox(parent); |
||
339 | |||
340 | /* |
||
341 | |||
342 | editor->addItem("1"); |
||
343 | editor->addItem("2"); |
||
344 | editor->addItem("3"); |
||
345 | editor->addItem("4"); |
||
346 | editor->addItem("5"); |
||
347 | editor->addItem("6"); |
||
348 | editor->addItem("7"); |
||
349 | editor->addItem("8"); |
||
350 | editor->addItem("9"); |
||
351 | */ |
||
352 | |||
353 | // editor->addItem("0"); |
||
354 | |||
355 | editor->addItems(Name_list); |
||
356 | |||
357 | return editor; |
||
358 | } |
||
359 | //! [1] |
||
360 | |||
361 | //! [2] |
||
362 | |||
363 | const QModelIndex &index) const |
||
364 | { |
||
365 | // int value = index.model()->data(index, Qt::EditRole).toInt(); |
||
366 | |||
367 | // QSpinBox *spinBox = static_cast<QSpinBox*>(editor); |
||
368 | |||
369 | QString value = index.model()->data(index, Qt::EditRole).toString(); |
||
370 | |||
371 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
||
372 | |||
373 | QStringList ID_list; |
||
374 | |||
375 | int curr_index; |
||
376 | |||
377 | ID_list = items.keys(); |
||
378 | |||
379 | |||
380 | curr_index = ID_list.indexOf(value); |
||
381 | |||
382 | comboBox->setCurrentIndex(curr_index); |
||
383 | /**************************************************** |
||
384 | if (value == "0") comboBox->setCurrentIndex(0); |
||
385 | if (value == "1") comboBox->setCurrentIndex(1); |
||
386 | if (value == "2") comboBox->setCurrentIndex(2); |
||
387 | if (value == "3") comboBox->setCurrentIndex(3); |
||
388 | if (value == "4") comboBox->setCurrentIndex(4); |
||
389 | if (value == "5") comboBox->setCurrentIndex(5); |
||
390 | if (value == "6") comboBox->setCurrentIndex(6); |
||
391 | if (value == "7") comboBox->setCurrentIndex(7); |
||
392 | if (value == "8") comboBox->setCurrentIndex(8); |
||
393 | if (value == "9") comboBox->setCurrentIndex(9); |
||
394 | ******************************************************/ |
||
395 | comboBox->setEditable(false); |
||
396 | |||
397 | |||
398 | |||
399 | |||
400 | } |
||
401 | |||
402 | |||
403 | //! [3] |
||
404 | |||
405 | const QModelIndex &index) const |
||
406 | { |
||
407 | // QSpinBox *spinBox = static_cast<QSpinBox*>(editor); |
||
408 | // spinBox->interpretText(); |
||
409 | // int value = spinBox->value(); |
||
410 | |||
411 | // model->setData(index, value, Qt::EditRole); |
||
412 | |||
413 | QStringList Name_list; |
||
414 | |||
415 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
||
416 | |||
417 | currIndex = comboBox->currentIndex(); |
||
418 | if (currIndex==-1) return; |
||
419 | // QString value = comboBox->itemText(currIndex); |
||
420 | |||
421 | ID_list = items.keys(); |
||
422 | |||
423 | |||
424 | // QString value = ID_list.at(currIndex); |
||
425 | |||
426 | model->setData(index, value, Qt::EditRole); |
||
427 | } |
||
428 | //! [3] |
||
429 | |||
430 | //! [4] |
||
431 | |||
123 | pingvin | 432 | const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
219 | pingvin | 433 | { |
434 | editor->setGeometry(option.rect); |
||
435 | } |
||
436 | |||
437 | |||
438 | |||
439 | |||
440 | |||
441 | |||
442 | |||
443 | |||
444 | |||
445 | |||
446 | |||
447 | |||
448 | : QItemDelegate(parent) |
||
449 | { |
||
450 | } |
||
451 | //! [0] |
||
452 | |||
453 | void FilterConditionDelegate::setClassID(QString newClassID){ |
||
454 | |||
455 | } |
||
456 | |||
457 | |||
458 | |||
459 | |||
460 | |||
461 | const QStyleOptionViewItem &/* option */, |
||
462 | const QModelIndex &/* index */) const |
||
463 | { |
||
464 | QStringList Name_list; |
||
465 | |||
466 | Name_list = items; |
||
467 | |||
468 | QComboBox *editor = new QComboBox(parent); |
||
469 | |||
470 | /* |
||
471 | |||
472 | editor->addItem("1"); |
||
473 | editor->addItem("2"); |
||
474 | editor->addItem("3"); |
||
475 | editor->addItem("4"); |
||
476 | editor->addItem("5"); |
||
477 | editor->addItem("6"); |
||
478 | editor->addItem("7"); |
||
479 | editor->addItem("8"); |
||
480 | editor->addItem("9"); |
||
481 | */ |
||
482 | |||
483 | // editor->addItem("0"); |
||
484 | |||
485 | editor->addItems(Name_list); |
||
486 | |||
487 | return editor; |
||
488 | } |
||
489 | //! [1] |
||
490 | |||
491 | //! [2] |
||
492 | |||
493 | const QModelIndex &index) const |
||
494 | { |
||
495 | // int value = index.model()->data(index, Qt::EditRole).toInt(); |
||
496 | |||
497 | // QSpinBox *spinBox = static_cast<QSpinBox*>(editor); |
||
498 | |||
499 | QString value = index.model()->data(index, Qt::EditRole).toString(); |
||
500 | |||
501 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
||
502 | |||
503 | //QStringList ID_list; |
||
504 | |||
505 | int curr_index; |
||
506 | |||
507 | //ID_list = items.keys(); |
||
508 | |||
509 | |||
510 | curr_index = items.indexOf(value); |
||
511 | |||
512 | comboBox->setCurrentIndex(curr_index); |
||
513 | /**************************************************** |
||
514 | if (value == "0") comboBox->setCurrentIndex(0); |
||
515 | if (value == "1") comboBox->setCurrentIndex(1); |
||
516 | if (value == "2") comboBox->setCurrentIndex(2); |
||
517 | if (value == "3") comboBox->setCurrentIndex(3); |
||
518 | if (value == "4") comboBox->setCurrentIndex(4); |
||
519 | if (value == "5") comboBox->setCurrentIndex(5); |
||
520 | if (value == "6") comboBox->setCurrentIndex(6); |
||
521 | if (value == "7") comboBox->setCurrentIndex(7); |
||
522 | if (value == "8") comboBox->setCurrentIndex(8); |
||
523 | if (value == "9") comboBox->setCurrentIndex(9); |
||
524 | ******************************************************/ |
||
525 | comboBox->setEditable(false); |
||
526 | |||
527 | |||
528 | |||
529 | |||
530 | } |
||
531 | |||
532 | |||
533 | //! [3] |
||
534 | |||
535 | const QModelIndex &index) const |
||
536 | { |
||
537 | // QSpinBox *spinBox = static_cast<QSpinBox*>(editor); |
||
538 | // spinBox->interpretText(); |
||
539 | // int value = spinBox->value(); |
||
540 | |||
541 | // model->setData(index, value, Qt::EditRole); |
||
542 | |||
543 | QStringList Name_list; |
||
544 | |||
545 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
||
546 | |||
547 | currIndex = comboBox->currentIndex(); |
||
548 | if (currIndex==-1) return; |
||
549 | // QString value = comboBox->itemText(currIndex); |
||
550 | |||
551 | // ID_list = items.keys(); |
||
552 | |||
553 | |||
554 | // QString value = ID_list.at(currIndex); |
||
555 | |||
556 | model->setData(index, value, Qt::EditRole); |
||
557 | } |
||
558 | //! [3] |
||
559 | |||
560 | //! [4] |
||
561 | |||
562 | const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
||
563 | { |
||
564 | editor->setGeometry(option.rect); |
||
565 | } |
||
566 | |||
567 | |||
568 | |||
569 | |||
570 | |||
571 | |||
572 | |||
573 | |||
574 | |||
575 | |||
576 | |||
577 | |||
224 | pingvin | 578 | { |
579 | } |
||
580 | //! [0] |
||
581 | |||
582 | void FilterValueDelegate::setClassID(QString newClassID){ |
||
583 | |||
584 | } |
||
585 | |||
586 | |||
587 | |||
588 | |||
589 | |||
225 | pingvin | 590 | |
591 | |||
592 | |||
593 | |||
594 | |||
595 | |||
596 | QString result; |
||
597 | QString classInctance; |
||
598 | int field_inctance; |
||
599 | bool ok; |
||
600 | sql_str = tr("select * " |
||
601 | " from ListOfClasses where ListOfClasses.ID = '" // , |
||
602 | ); |
||
603 | sql_str.append(class_id); |
||
604 | sql_str.append(tr("'")); |
||
605 | q.prepare(sql_str); |
||
606 | |||
607 | ok = q.exec(); |
||
608 | |||
609 | if (!ok) return result; |
||
610 | |||
611 | /* |
||
612 | |||
613 | QMessageBox::critical( // . |
||
614 | this, // . |
||
615 | QObject::tr("Database Error"), // . |
||
616 | q.lastError().text()); // . |
||
617 | return result; |
||
618 | } |
||
619 | |||
620 | */ |
||
621 | |||
622 | |||
623 | |||
624 | |||
625 | |||
626 | |||
627 | |||
628 | classInctance = q.value(field_inctance).toString(); |
||
629 | |||
630 | } |
||
631 | |||
632 | return result; |
||
633 | |||
634 | |||
635 | |||
636 | |||
637 | |||
638 | |||
639 | |||
640 | |||
641 | |||
642 | |||
643 | |||
226 | pingvin | 644 | |
225 | pingvin | 645 | } |
646 | |||
647 | |||
648 | |||
649 | |||
226 | pingvin | 650 | |
651 | |||
652 | |||
653 | |||
654 | |||
224 | pingvin | 655 | const QStyleOptionViewItem &/* option */, |
656 | const QModelIndex &/* index */) const |
||
657 | { |
||
658 | QStringList Name_list; |
||
659 | |||
660 | Name_list = items; |
||
661 | |||
662 | QComboBox *editor = new QComboBox(parent); |
||
663 | |||
664 | /* |
||
665 | |||
666 | editor->addItem("1"); |
||
667 | editor->addItem("2"); |
||
668 | editor->addItem("3"); |
||
669 | editor->addItem("4"); |
||
670 | editor->addItem("5"); |
||
671 | editor->addItem("6"); |
||
672 | editor->addItem("7"); |
||
673 | editor->addItem("8"); |
||
674 | editor->addItem("9"); |
||
675 | */ |
||
676 | |||
677 | // editor->addItem("0"); |
||
678 | |||
679 | // // // editor->addItems(Name_list); |
||
680 | |||
681 | return editor; |
||
225 | pingvin | 682 | } |
224 | pingvin | 683 | //! [1] |
684 | |||
685 | |||
686 | |||
225 | pingvin | 687 | |
688 | |||
689 | |||
226 | pingvin | 690 | const QAbstractItemModel * model = index.model(); |
691 | |||
692 | TField field_result; |
||
225 | pingvin | 693 | |
226 | pingvin | 694 | QString sql_str; |
695 | bool ok; |
||
696 | |||
697 | |||
225 | pingvin | 698 | |
699 | |||
226 | pingvin | 700 | field_result.FieldName = index.model()->data(model->index(index.row(),4), Qt::EditRole).toString(); |
701 | field_result.ClassIdentifer = index.model()->data(model->index(index.row(),2), Qt::EditRole).toString(); |
||
702 | |||
703 | sql_str = tr("select * from `DescriptionOfClasses` where `ClassIdentifer` = '"); |
||
225 | pingvin | 704 | |
226 | pingvin | 705 | sql_str.append(tr("' and `FieldName` = '")); |
706 | sql_str.append(field_result.FieldName); |
||
707 | sql_str.append(tr("'")); |
||
708 | |||
709 | ok = q.prepare(sql_str); |
||
225 | pingvin | 710 | |
226 | pingvin | 711 | if(!ok) return field_result; |
225 | pingvin | 712 | |
226 | pingvin | 713 | ok = q.exec(); |
714 | |||
715 | if(!ok) return field_result; |
||
716 | |||
717 | int ID_index = q.record().indexOf(tr("ID")); |
||
718 | |||
719 | int FieldAlias_index = q.record().indexOf(tr("FieldAlias")); |
||
720 | |||
721 | int FieldType_index = q.record().indexOf(tr("FieldType")); |
||
722 | |||
723 | int DefaultValue_index = q.record().indexOf(tr("DefaultValue")); |
||
724 | |||
725 | int Comment_index = q.record().indexOf(tr("Comment")); |
||
726 | |||
727 | |||
728 | |||
729 | |||
730 | |||
731 | field_result.FieldAlias = q.value(FieldAlias_index).asString(); |
||
732 | field_result.FieldType = q.value(FieldType_index).asString(); |
||
733 | field_result.DefaultValue = q.value(DefaultValue_index).asString(); |
||
734 | field_result.Comment = q.value(Comment_index).asString(); |
||
735 | } |
||
736 | |||
737 | return field_result; |
||
738 | |||
739 | |||
740 | |||
741 | |||
742 | |||
743 | |||
744 | |||
745 | |||
746 | |||
747 | |||
748 | |||
224 | pingvin | 749 | const QModelIndex &index) const |
750 | { |
||
751 | // int value = index.model()->data(index, Qt::EditRole).toInt(); |
||
752 | |||
753 | // QSpinBox *spinBox = static_cast<QSpinBox*>(editor); |
||
754 | |||
755 | |||
756 | |||
757 | |||
758 | |||
759 | |||
760 | |||
761 | |||
762 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
||
763 | QString inctance; // |
||
764 | QString fieldName;// |
||
225 | pingvin | 765 | QSqlQuery q; |
766 | QString sql_str; |
||
767 | QStringList itemsList; |
||
768 | bool ok; |
||
769 | TField Field; |
||
770 | |||
226 | pingvin | 771 | Field = getField(index); |
224 | pingvin | 772 | |
226 | pingvin | 773 | |
225 | pingvin | 774 | |
775 | |||
226 | pingvin | 776 | |
777 | |||
778 | |||
779 | |||
225 | pingvin | 780 | |
781 | |||
782 | |||
783 | sql_str = tr("select `"); |
||
784 | sql_str.append(fieldName); |
||
785 | sql_str.append(tr("` from `")); |
||
786 | sql_str.append(inctance); |
||
787 | sql_str.append(tr("`")); |
||
788 | ok = q.prepare(sql_str); |
||
789 | ok = q.exec(); |
||
790 | |||
791 | while(q.next()){ |
||
792 | |||
793 | tmp_str = q.record().value(fieldName).asString(); |
||
794 | itemsList.append(tmp_str); |
||
795 | FilterValueDelegate::items.append(tmp_str); |
||
796 | } |
||
797 | if(!itemsList.isEmpty()) { |
||
798 | comboBox->addItems(itemsList); |
||
799 | items = itemsList; // |
||
800 | } |
||
801 | |||
802 | } |
||
803 | |||
804 | |||
805 | |||
806 | |||
807 | |||
808 | |||
809 | |||
224 | pingvin | 810 | int curr_index; |
811 | |||
812 | //ID_list = items.keys(); |
||
813 | |||
814 | |||
815 | curr_index = itemsList.indexOf(value); |
||
816 | |||
225 | pingvin | 817 | comboBox->setCurrentIndex(curr_index); |
224 | pingvin | 818 | /**************************************************** |
819 | if (value == "0") comboBox->setCurrentIndex(0); |
||
820 | if (value == "1") comboBox->setCurrentIndex(1); |
||
821 | if (value == "2") comboBox->setCurrentIndex(2); |
||
822 | if (value == "3") comboBox->setCurrentIndex(3); |
||
823 | if (value == "4") comboBox->setCurrentIndex(4); |
||
824 | if (value == "5") comboBox->setCurrentIndex(5); |
||
825 | if (value == "6") comboBox->setCurrentIndex(6); |
||
826 | if (value == "7") comboBox->setCurrentIndex(7); |
||
827 | if (value == "8") comboBox->setCurrentIndex(8); |
||
828 | if (value == "9") comboBox->setCurrentIndex(9); |
||
829 | ******************************************************/ |
||
830 | comboBox->setEditable(true); |
||
831 | |||
225 | pingvin | 832 | |
224 | pingvin | 833 | |
834 | |||
835 | } |
||
836 | |||
837 | |||
838 | //! [3] |
||
839 | |||
840 | const QModelIndex &index) const |
||
841 | { |
||
842 | // QSpinBox *spinBox = static_cast<QSpinBox*>(editor); |
||
843 | // spinBox->interpretText(); |
||
844 | // int value = spinBox->value(); |
||
845 | |||
846 | // model->setData(index, value, Qt::EditRole); |
||
847 | |||
848 | QStringList ID_list; |
||
225 | pingvin | 849 | |
224 | pingvin | 850 | |
851 | QComboBox *comboBox = static_cast<QComboBox*>(editor); |
||
852 | |||
853 | currIndex = comboBox->currentIndex(); |
||
854 | if (currIndex==-1) return; |
||
855 | // QString value = comboBox->itemText(currIndex); |
||
856 | |||
857 | // ID_list = items.keys(); |
||
858 | |||
859 | |||
860 | // QString value = ID_list.at(currIndex); |
||
861 | |||
862 | model->setData(index, value, Qt::EditRole); |
||
863 | |||
864 | |||
225 | pingvin | 865 | |
866 | |||
224 | pingvin | 867 | |
225 | pingvin | 868 | |
869 | |||
870 | |||
871 | |||
872 | |||
873 | |||
874 | |||
875 | |||
224 | pingvin | 876 | //! [4] |
877 | |||
219 | pingvin | 878 | const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
224 | pingvin | 879 | { |
880 | editor->setGeometry(option.rect); |
||
881 | } |
||
882 | |||
883 | |||
884 | |||
885 | |||
886 | |||
887 | |||
888 | |||
889 | |||
890 | |||
891 | |||
892 | |||
893 | |||
894 | |||
895 | |||
896 | |||
897 | |||
898 | |||
899 | bool calpopup, |
||
123 | pingvin | 900 | QObject *parent) |
901 | : QItemDelegate(parent), |
||
902 | m_calpopup(calpopup) { |
||
903 | } |
||
904 | |||
905 | QWidget *MyDEDelegate::createEditor( |
||
906 | |||
907 | const QStyleOptionViewItem& /* option */, |
||
908 | const QModelIndex& /* index */) const { |
||
909 | QDateEdit *editor = new QDateEdit(parent); |
||
910 | editor->setCalendarPopup(m_calpopup); |
||
911 | editor->installEventFilter(const_cast<MyDEDelegate*>(this)); |
||
912 | return editor; |
||
913 | } |
||
914 | |||
915 | void MyDEDelegate::setEditorData( |
||
916 | |||
917 | const QModelIndex &index) const { |
||
918 | QDate value = index.model()->data( |
||
919 | index, Qt::EditRole).toDate(); |
||
920 | QDateEdit *de = static_cast<QDateEdit*>(editor); |
||
921 | de->setDate(value); |
||
922 | } |
||
923 | |||
924 | void MyDEDelegate::setModelData( |
||
925 | |||
926 | QAbstractItemModel *model, |
||
927 | const QModelIndex& index) const { |
||
928 | QDateEdit *de = static_cast<QDateEdit*>(editor); |
||
929 | de->interpretText(); |
||
930 | QDate value = de->date(); |
||
931 | model->setData(index, value); |
||
932 | } |
||
933 | |||
934 | void MyDEDelegate::updateEditorGeometry( |
||
935 | |||
936 | const QStyleOptionViewItem &option, |
||
937 | const QModelIndex& /* index */) const { |
||
938 | |||
939 | |||
169 | pingvin | 940 | |
941 | |||
942 | |||
123 | pingvin | 943 | |
944 | |||
138 | pingvin | 945 | |
946 | |||
947 | |||
948 | |||
949 | |||
950 | } |
||
951 | |||
952 | void CPictureDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const |
||
953 | |||
954 | m_pxPicture.fill( QColor(Qt::white) ); |
||
955 | |||
956 | const QAbstractItemModel * model = index.model(); |
||
957 | |||
958 | |||
959 | if ( !sFileName.isEmpty() ) |
||
960 | |||
961 | else { |
||
962 | //QItemDelegate::paint(painter, option, index); |
||
963 | return; |
||
964 | } |
||
965 | |||
966 | QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) ? |
||
967 | |||
968 | QPalette::Disabled; |
||
969 | |||
970 | if (option.state & QStyle::State_Selected) |
||
971 | |||
972 | |||
973 | int nX = option.rect.x() + ( ( option.rect.width() - m_pxPicture.rect().width() ) / 2 ); |
||
974 | |||
975 | painter->drawPixmap( nX, nY, m_pxPicture ); |
||
976 | |||
977 | |||
978 | |||
979 | |||
980 | /* |
||
981 | |||
982 | painter->setPen(option.palette.color(QPalette::Mid)); |
||
983 | painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight()); |
||
984 | painter->drawLine(option.rect.topRight(), option.rect.bottomRight()); |
||
985 | painter->setPen(pen); |
||
986 | */ |
||
987 | } |
||
988 | |||
989 | |||
158 | pingvin | 990 | |
991 | |||
992 | |||
993 | |||
994 | { |
||
995 | int datetime = index.model()->data(index, Qt::DisplayRole).toInt(); |
||
996 | |||
997 | QString indexvalue = ""; |
||
998 | |||
999 | if (datetime > 0) |
||
1000 | |||
1001 | QDateTime dateTime2 = QDateTime(); |
||
1002 | dateTime2.setTime_t(datetime); |
||
1003 | indexvalue = dateTime2.toString(this->timeformat); |
||
1004 | } |
||
1005 | else |
||
1006 | { |
||
1007 | indexvalue = tr("Date not set"); |
||
1008 | } |
||
1009 | |||
1010 | Q_ASSERT(index.isValid()); |
||
1011 | |||
1012 | QStyleOptionViewItemV3 opt = setOptions(index, option); |
||
1013 | |||
1014 | const QStyleOptionViewItemV2 *v2 = qstyleoption_cast<const QStyleOptionViewItemV2 *>(&option); |
||
1015 | |||
1016 | : QStyleOptionViewItemV2::ViewItemFeatures(QStyleOptionViewItemV2::None); |
||
1017 | const QStyleOptionViewItemV3 *v3 = qstyleoption_cast<const QStyleOptionViewItemV3 *>(&option); |
||
1018 | opt.locale = v3 ? v3->locale : QLocale(); |
||
1019 | opt.widget = v3 ? v3->widget : 0; |
||
1020 | |||
1021 | // prepare |
||
1022 | |||
1023 | |||
1024 | painter->setClipRect(opt.rect); |
||
1025 | |||
1026 | // get the data and the rectangles |
||
1027 | |||
1028 | |||
1029 | QPixmap pixmap; |
||
1030 | |||
1031 | value = index.data(Qt::DecorationRole); |
||
1032 | |||
1033 | QString text; |
||
1034 | |||
1035 | value = index.data(Qt::DisplayRole); |
||
1036 | if (value.isValid()) { |
||
1037 | text = indexvalue; |
||
1038 | displayRect = textRectangle(painter, option.rect, opt.font, text); |
||
1039 | } |
||
1040 | |||
1041 | QRect checkRect; |
||
1042 | |||
1043 | value = index.data(Qt::CheckStateRole); |
||
1044 | if (value.isValid()) { |
||
1045 | checkState = static_cast<Qt::CheckState>(value.toInt()); |
||
1046 | checkRect = check(opt, opt.rect, value); |
||
1047 | } |
||
1048 | |||
1049 | // do the layout |
||
1050 | |||
1051 | // draw the item |
||
1052 | |||
1053 | drawBackground(painter, opt, index); |
||
1054 | |||
1055 | drawDecoration(painter, opt, decorationRect, pixmap); |
||
1056 | drawDisplay(painter, opt, displayRect, text); |
||
1057 | drawFocus(painter, opt, displayRect); |
||
1058 | |||
1059 | // done |
||
1060 | |||
1061 | } |
||
1062 | |||
1063 | |||
180 | pingvin | 1064 | |
1065 | |||
1066 | |||
1067 | |||
1068 | |||
1069 | |||
1070 | } |
||
1071 | |||
1072 | |||
1073 | |||
1074 | |||
1075 | |||
1076 | |||
1077 | |||
1078 | const QModelIndex & /* index */) const |
||
1079 | { |
||
1080 | |||
1081 | IconForm *editor = new IconForm(parent); |
||
1082 | |||
1083 | return editor; |
||
1084 | |||
1085 | } |
||
1086 | |||
1087 | |||
1088 | |||
1089 | |||
1090 | |||
1091 | |||
1092 | { |
||
1093 | |||
1094 | |||
1095 | |||
1096 | |||
1097 | QVariant currentImage = model->data(index,0); |
||
1098 | QByteArray bytes = currentImage.toByteArray(); |
||
1099 | if (currentImage.isValid()) { |
||
1100 | m_pxPicture.loadFromData(bytes); |
||
1101 | } |
||
1102 | else { |
||
1103 | //QItemDelegate::paint(painter, option, index); |
||
1104 | |||
1105 | |||
1106 | |||
1107 | |||
1108 | icnFrm->setPixmap(m_pxPicture); |
||
1109 | // tblView->setRowHeight(index.row(), icnFrm->geometry().height()); |
||
1110 | } |
||
1111 | |||
1112 | |||
1113 | |||
1114 | |||
1115 | |||
1116 | |||
1117 | QAbstractItemModel *model, |
||
1118 | const QModelIndex& index) const { |
||
1119 | IconForm *icnFrm = static_cast<IconForm*>(editor); |
||
1120 | if (!(icnFrm->dataIsChanged())) return; |
||
1121 | |||
1122 | m_pxPicture = icnFrm->pixmap(); |
||
1123 | |||
1124 | QByteArray bytes; |
||
1125 | QBuffer buffer(&bytes); |
||
1126 | buffer.open(QIODevice::WriteOnly); |
||
1127 | currentImage.save(&buffer, "PNG"); |
||
1128 | |||
1129 | |||
1130 | |||
1131 | |||
1132 | |||
1133 | |||
1134 | // int widht = m_pxPicture.width(); |
||
1135 | |||
1136 | // tblView->setRowHeight(index.row(), heigh + 10); |
||
1137 | // model->submitAll(); |
||
1138 | |||
1139 | |||
1140 | |||
1141 | |||
1142 | |||
1143 | |||
1144 | |||
1145 | |||
1146 | |||
1147 | |||
1148 | |||
1149 | const QStyleOptionViewItem &option, |
||
1150 | const QModelIndex& /* index */) const { |
||
1151 | |||
1152 | |||
1153 | |||
1154 | |||
1155 | |||
1156 | editor->setGeometry(option.rect); |
||
1157 | |||
1158 | |||
1159 | |||
1160 | |||
1161 | |||
1162 | |||
1163 | |||
1164 | |||
1165 | |||
1166 | |||
1167 | |||
1168 | const QAbstractItemModel * model = index.model(); |
||
1169 | |||
1170 | |||
1171 | QVariant currentImage = model->data(index,0); |
||
1172 | |||
1173 | |||
1174 | |||
1175 | |||
1176 | // image.loadFromData(bytes); |
||
1177 | |||
1178 | |||
1179 | |||
1180 | |||
1181 | |||
1182 | } |
||
1183 | |||
1184 | //QItemDelegate::paint(painter, option, index); |
||
1185 | return; |
||
1186 | } |
||
1187 | |||
1188 | |||
1189 | |||
1190 | |||
1191 | |||
1192 | |||
1193 | |||
1194 | if ( !sFileName.isEmpty() ) |
||
1195 | |||
1196 | else { |
||
1197 | //QItemDelegate::paint(painter, option, index); |
||
1198 | return; |
||
1199 | } |
||
1200 | */ |
||
1201 | |||
1202 | |||
1203 | |||
1204 | |||
205 | pingvin | 1205 | |
1206 | |||
1207 | |||
180 | pingvin | 1208 | QPalette::Disabled; |
1209 | |||
1210 | if (option.state & QStyle::State_Selected) |
||
1211 | |||
1212 | |||
1213 | |||
1214 | |||
1215 | |||
1216 | |||
205 | pingvin | 1217 | |
1218 | |||
180 | pingvin | 1219 | // painter->setRenderHint(QPainter::Antialiasing); |
1220 | painter->drawPixmap( nX, nY, m_pxPicture ); |
||
205 | pingvin | 1221 | |
180 | pingvin | 1222 | // drawFocus(painter, option, option.rect.adjusted(0, 0, -1, -1)); // since we draw the grid ourselves |
1223 | |||
1224 | /* |
||
1225 | |||
1226 | painter->setPen(option.palette.color(QPalette::Mid)); |
||
1227 | painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight()); |
||
1228 | painter->drawLine(option.rect.topRight(), option.rect.bottomRight()); |
||
1229 | painter->setPen(pen); |
||
1230 | */ |
||
1231 | } |
||
1232 | |||
1233 | |||
1234 | |||
1235 | |||
1236 | } |
||
1237 | |||
1238 | |||
201 | pingvin | 1239 | |
1240 | |||
1241 | |||
1242 | |||
1243 | |||
1244 | |||
1245 | |||
1246 | |||
1247 | } |
||
1248 | |||
1249 | |||
1250 | |||
1251 | |||
1252 | |||
1253 | |||
1254 | |||
1255 | const QModelIndex & /* index */) const |
||
1256 | { |
||
1257 | |||
1258 | FileForm *editor = new FileForm(parent); |
||
1259 | |||
1260 | return editor; |
||
1261 | |||
1262 | } |
||
1263 | |||
1264 | |||
1265 | |||
1266 | |||
1267 | |||
1268 | |||
1269 | { |
||
1270 | |||
1271 | |||
1272 | |||
1273 | |||
1274 | QVariant currentData = model->data(index,Qt::EditRole); |
||
1275 | |||
202 | pingvin | 1276 | // QVariant currentData = QSqlTableModel::data(index, 0); |
1277 | |||
1278 | if (currentData.isValid()) flFrm->setData(bytes); |
||
201 | pingvin | 1279 | else return; |
1280 | |||
1281 | } |
||
1282 | |||
1283 | |||
1284 | |||
1285 | |||
1286 | |||
1287 | |||
1288 | QAbstractItemModel *model, |
||
1289 | const QModelIndex& index) const { |
||
1290 | FileForm *flFrm = static_cast<FileForm*>(editor); |
||
1291 | if (!(flFrm->dataIsChanged())) return; |
||
1292 | |||
1293 | m_Data = flFrm->data(); |
||
1294 | |||
1295 | model->setData(index, QVariant (m_Data), Qt::EditRole); |
||
1296 | |||
1297 | } |
||
1298 | |||
1299 | QVariant val_null; |
||
1300 | model->setData(index, val_null, Qt::EditRole); |
||
1301 | |||
1302 | } |
||
1303 | |||
1304 | |||
1305 | |||
1306 | |||
1307 | |||
1308 | |||
1309 | |||
1310 | |||
1311 | |||
1312 | const QStyleOptionViewItem &option, |
||
1313 | const QModelIndex& /* index */) const { |
||
1314 | |||
1315 | |||
1316 | |||
1317 | |||
1318 | |||
1319 | editor->setGeometry(option.rect); |
||
1320 | |||
1321 |