33
33
#include < QCompleter>
34
34
#include < QHBoxLayout>
35
35
#include < QPlainTextEdit>
36
+ #include < QDial>
37
+ #include < QCalendarWidget>
38
+ #include < QDialogButtonBox>
36
39
37
40
void QgsAttributeEditor::selectFileName ( void )
38
41
{
@@ -55,6 +58,42 @@ void QgsAttributeEditor::selectFileName( void )
55
58
le->setText ( fileName );
56
59
}
57
60
61
+ void QgsAttributeEditor::selectDate ( void )
62
+ {
63
+ QPushButton *pb = qobject_cast<QPushButton *>( sender () );
64
+ if ( !pb )
65
+ return ;
66
+
67
+ QWidget *hbox = qobject_cast<QWidget *>( pb->parent () );
68
+ if ( !hbox )
69
+ return ;
70
+
71
+ QLineEdit *le = hbox->findChild <QLineEdit *>();
72
+ if ( !le )
73
+ return ;
74
+
75
+ QDialog *dlg = new QDialog ();
76
+ dlg->setWindowTitle ( tr ( " Select a date" ) );
77
+ QVBoxLayout *vl = new QVBoxLayout ( dlg );
78
+
79
+ QCalendarWidget *cw = new QCalendarWidget ( dlg );
80
+ cw->setSelectedDate ( QDate::fromString ( le->text (), Qt::ISODate ) );
81
+ vl->addWidget ( cw );
82
+
83
+ QDialogButtonBox *buttonBox = new QDialogButtonBox ( dlg );
84
+ buttonBox->addButton ( QDialogButtonBox::Ok );
85
+ buttonBox->addButton ( QDialogButtonBox::Cancel );
86
+ vl->addWidget ( buttonBox );
87
+
88
+ connect ( buttonBox, SIGNAL ( accepted () ), dlg, SLOT ( accept () ) );
89
+ connect ( buttonBox, SIGNAL ( rejected () ), dlg, SLOT ( reject () ) );
90
+
91
+ if ( dlg->exec () == QDialog::Accepted )
92
+ {
93
+ le->setText ( cw->selectedDate ().toString ( Qt::ISODate ) );
94
+ }
95
+ }
96
+
58
97
QComboBox *QgsAttributeEditor::comboBox ( QWidget *editor, QWidget *parent )
59
98
{
60
99
QComboBox *cb = NULL ;
@@ -180,6 +219,8 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
180
219
}
181
220
break ;
182
221
222
+
223
+ case QgsVectorLayer::DialRange:
183
224
case QgsVectorLayer::SliderRange:
184
225
case QgsVectorLayer::EditRange:
185
226
{
@@ -208,12 +249,20 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
208
249
}
209
250
else
210
251
{
211
- QSlider *sl = NULL ;
252
+ QAbstractSlider *sl = NULL ;
212
253
213
254
if ( editor )
214
- sl = qobject_cast<QSlider*>( editor );
255
+ {
256
+ sl = qobject_cast<QAbstractSlider*>( editor );
257
+ }
258
+ else if ( editType == QgsVectorLayer::DialRange )
259
+ {
260
+ sl = new QDial ( parent );
261
+ }
215
262
else
263
+ {
216
264
sl = new QSlider ( Qt::Horizontal, parent );
265
+ }
217
266
218
267
if ( sl )
219
268
{
@@ -335,6 +384,7 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
335
384
break ;
336
385
337
386
case QgsVectorLayer::FileName:
387
+ case QgsVectorLayer::Calendar:
338
388
{
339
389
QPushButton *pb = NULL ;
340
390
QLineEdit *le = qobject_cast<QLineEdit *>( editor );
@@ -365,18 +415,17 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
365
415
}
366
416
367
417
if ( pb )
368
- connect ( pb, SIGNAL ( clicked () ), new QgsAttributeEditor ( pb ), SLOT ( selectFileName () ) );
418
+ {
419
+ if ( editType == QgsVectorLayer::FileName )
420
+ connect ( pb, SIGNAL ( clicked () ), new QgsAttributeEditor ( pb ), SLOT ( selectFileName () ) );
421
+ if ( editType == QgsVectorLayer::Calendar )
422
+ connect ( pb, SIGNAL ( clicked () ), new QgsAttributeEditor ( pb ), SLOT ( selectDate () ) );
423
+ }
369
424
}
370
425
break ;
371
426
372
427
case QgsVectorLayer::Immutable:
373
428
return NULL ;
374
-
375
- }
376
-
377
- if ( editType == QgsVectorLayer::Immutable )
378
- {
379
- myWidget->setEnabled ( false );
380
429
}
381
430
382
431
setValue ( myWidget, vl, idx, value );
@@ -448,7 +497,7 @@ bool QgsAttributeEditor::retrieveValue( QWidget *widget, QgsVectorLayer *vl, int
448
497
text = QString::number ( sb->value () );
449
498
}
450
499
451
- QSlider *slider = qobject_cast<QSlider *>( widget );
500
+ QAbstractSlider *slider = qobject_cast<QAbstractSlider *>( widget );
452
501
if ( slider )
453
502
{
454
503
text = QString::number ( slider->value () );
@@ -467,6 +516,12 @@ bool QgsAttributeEditor::retrieveValue( QWidget *widget, QgsVectorLayer *vl, int
467
516
text = ckb->isChecked () ? states.first : states.second ;
468
517
}
469
518
519
+ QCalendarWidget *cw = qobject_cast<QCalendarWidget *>( widget );
520
+ if ( cw )
521
+ {
522
+ text = cw->selectedDate ().toString ();
523
+ }
524
+
470
525
le = widget->findChild <QLineEdit *>();
471
526
if ( le )
472
527
{
@@ -505,6 +560,20 @@ bool QgsAttributeEditor::retrieveValue( QWidget *widget, QgsVectorLayer *vl, int
505
560
}
506
561
}
507
562
break ;
563
+ case QVariant::Date:
564
+ {
565
+ QDate myDateValue = QDate::fromString ( text, Qt::ISODate );
566
+ if ( myDateValue.isValid () && !text.isEmpty () )
567
+ {
568
+ value = myDateValue;
569
+ modified = true ;
570
+ }
571
+ else if ( modified )
572
+ {
573
+ value = QVariant ( theField.type () );
574
+ }
575
+ }
576
+ break ;
508
577
default : // string
509
578
modified = true ;
510
579
value = QVariant ( text );
@@ -542,6 +611,7 @@ bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx,
542
611
}
543
612
break ;
544
613
614
+ case QgsVectorLayer::DialRange:
545
615
case QgsVectorLayer::SliderRange:
546
616
case QgsVectorLayer::EditRange:
547
617
{
@@ -556,7 +626,7 @@ bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx,
556
626
}
557
627
else
558
628
{
559
- QSlider *sl = qobject_cast<QSlider *>( editor );
629
+ QAbstractSlider *sl = qobject_cast<QAbstractSlider *>( editor );
560
630
if ( sl == NULL )
561
631
return false ;
562
632
sl->setValue ( value.toInt () );
@@ -615,6 +685,7 @@ bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx,
615
685
break ;
616
686
617
687
case QgsVectorLayer::FileName:
688
+ case QgsVectorLayer::Calendar:
618
689
{
619
690
QLineEdit *le = editor->findChild <QLineEdit *>();
620
691
if ( le == NULL )
0 commit comments