13
13
* *
14
14
***************************************************************************/
15
15
16
+ #include < QCalendarWidget>
16
17
#include < QLineEdit>
17
18
#include < QMouseEvent>
18
19
#include < QSettings>
19
20
#include < QStyle>
20
21
#include < QToolButton>
21
22
23
+
22
24
#include " qgsdatetimeedit.h"
23
25
24
26
#include " qgsapplication.h"
@@ -47,8 +49,16 @@ QgsDateTimeEdit::QgsDateTimeEdit( QWidget *parent )
47
49
48
50
connect ( this , &QDateTimeEdit::dateTimeChanged, this , &QgsDateTimeEdit::changed );
49
51
52
+ // set this by defaut to properly connect the calendar widget
53
+ setCalendarPopup ( true );
54
+ // when clearing the widget, date of the QDateTimeEdit will be set to minimum date
55
+ // hence when the calendar popups, on selection changed if it set to the minimum date,
56
+ // the page of the current date will be shown
57
+ connect ( calendarWidget (), &QCalendarWidget::selectionChanged, this , &QgsDateTimeEdit::calendarSelectionChanged );
58
+
50
59
// init with current time so mIsNull is properly initialized
51
60
QDateTimeEdit::setDateTime ( QDateTime::currentDateTime () );
61
+
52
62
setMinimumEditDateTime ();
53
63
}
54
64
@@ -64,6 +74,12 @@ void QgsDateTimeEdit::setAllowNull( bool allowNull )
64
74
65
75
void QgsDateTimeEdit::clear ()
66
76
{
77
+ if ( calendarPopup () )
78
+ {
79
+ QDateTimeEdit::blockSignals ( true );
80
+ QDateTimeEdit::setDateTime ( minimumDateTime () );
81
+ QDateTimeEdit::blockSignals ( false );
82
+ }
67
83
changed ( QDateTime () );
68
84
emit dateTimeChanged ( QDateTime () );
69
85
}
@@ -73,6 +89,7 @@ void QgsDateTimeEdit::setEmpty()
73
89
mNullLabel ->setVisible ( false );
74
90
lineEdit ()->setVisible ( false );
75
91
mClearButton ->setVisible ( mAllowNull );
92
+ mIsEmpty = true ;
76
93
}
77
94
78
95
void QgsDateTimeEdit::mousePressEvent ( QMouseEvent *event )
@@ -81,6 +98,7 @@ void QgsDateTimeEdit::mousePressEvent( QMouseEvent *event )
81
98
if ( mAllowNull && mIsNull && lerect.contains ( event->pos () ) )
82
99
return ;
83
100
101
+
84
102
QDateTimeEdit::mousePressEvent ( event );
85
103
}
86
104
@@ -93,6 +111,14 @@ void QgsDateTimeEdit::changed( const QDateTime &dateTime )
93
111
lineEdit ()->setVisible ( !mAllowNull || !mIsNull );
94
112
}
95
113
114
+ void QgsDateTimeEdit::calendarSelectionChanged ()
115
+ {
116
+ if ( mAllowNull && calendarWidget () && calendarWidget ()->selectedDate () == minimumDate () )
117
+ {
118
+ calendarWidget ()->setCurrentPage ( QDate::currentDate ().year (), QDate::currentDate ().month () );
119
+ }
120
+ }
121
+
96
122
int QgsDateTimeEdit::spinButtonWidth () const
97
123
{
98
124
return calendarPopup () ? 25 : 18 ;
0 commit comments