Skip to content

Commit 333347b

Browse files
authored
Merge pull request #5992 from 3nids/fix17790
fix NULL constraint on date/time widget with allow NULL
2 parents ed2f056 + 42976df commit 333347b

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

python/gui/editorwidgets/qgsdatetimeedit.sip

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ class QgsDateTimeEdit : QDateTimeEdit
1212
{
1313
%Docstring
1414
The QgsDateTimeEdit class is a QDateTimeEdit with the capability of setting/reading null date/times.
15+
16+
.. warning::
17+
18+
You should use the signal valueChanged of this subclass
19+
rather than QDateTimeEdit.dateTimeChanged. If you consequently connect parent's
20+
dateTimeChanged signal and call dateTime() afterwards there is no warranty to
21+
have a proper NULL value handling.
1522
%End
1623

1724
%TypeHeaderCode
@@ -63,6 +70,14 @@ Set the current date as NULL
6370
Resets the widget to show no value (ie, an "unknown" state).
6471

6572
.. versionadded:: 2.16
73+
%End
74+
75+
signals:
76+
77+
void valueChanged( const QDateTime &date );
78+
%Docstring
79+
signal emitted whenever the value changes.
80+
@param date the new date/time value.
6681
%End
6782

6883
protected:

src/gui/editorwidgets/qgsdatetimeedit.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ void QgsDateTimeEdit::clear()
6262

6363
changed( QDateTime() );
6464

65-
// avoid slot double activation
65+
// emit signal of QDateTime::dateTimeChanged with an invalid date
66+
// anyway, using parent's signal should be avoided
67+
// If you consequently connect parent's dateTimeChanged signal
68+
// and call dateTime() afterwards there is no warranty to
69+
// have a proper NULL value handling
6670
disconnect( this, &QDateTimeEdit::dateTimeChanged, this, &QgsDateTimeEdit::changed );
6771
emit dateTimeChanged( QDateTime() );
6872
connect( this, &QDateTimeEdit::dateTimeChanged, this, &QgsDateTimeEdit::changed );
@@ -174,6 +178,8 @@ void QgsDateTimeEdit::changed( const QDateTime &dateTime )
174178
}
175179

176180
mClearAction->setVisible( mAllowNull && !mIsNull );
181+
182+
emit QgsDateTimeEdit::valueChanged( dateTime );
177183
}
178184

179185
void QgsDateTimeEdit::displayNull( bool updateCalendar )

src/gui/editorwidgets/qgsdatetimeedit.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
/**
2424
* \ingroup gui
2525
* \brief The QgsDateTimeEdit class is a QDateTimeEdit with the capability of setting/reading null date/times.
26+
*
27+
* \warning You should use the signal valueChanged of this subclass
28+
* rather than QDateTimeEdit::dateTimeChanged. If you consequently connect parent's
29+
* dateTimeChanged signal and call dateTime() afterwards there is no warranty to
30+
* have a proper NULL value handling.
2631
*/
2732
class GUI_EXPORT QgsDateTimeEdit : public QDateTimeEdit
2833
{
@@ -62,6 +67,14 @@ class GUI_EXPORT QgsDateTimeEdit : public QDateTimeEdit
6267
*/
6368
void setEmpty();
6469

70+
signals:
71+
72+
/**
73+
* signal emitted whenever the value changes.
74+
* @param date the new date/time value.
75+
*/
76+
void valueChanged( const QDateTime &date );
77+
6578
protected:
6679
void mousePressEvent( QMouseEvent *event ) override;
6780
void focusOutEvent( QFocusEvent *event ) override;

src/gui/editorwidgets/qgsdatetimeeditwrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ void QgsDateTimeEditWrapper::initWidget( QWidget *editor )
9393

9494
if ( mQgsDateTimeEdit )
9595
{
96-
connect( mQgsDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this, &QgsDateTimeEditWrapper::dateTimeChanged );
96+
connect( mQgsDateTimeEdit, &QgsDateTimeEdit::valueChanged, this, &QgsDateTimeEditWrapper::dateTimeChanged );
9797
}
9898
else
9999
{

0 commit comments

Comments
 (0)