Skip to content

Commit

Permalink
Merge pull request #5992 from 3nids/fix17790
Browse files Browse the repository at this point in the history
fix NULL constraint on date/time widget with allow NULL
  • Loading branch information
3nids committed Jan 5, 2018
2 parents ed2f056 + 42976df commit 333347b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
15 changes: 15 additions & 0 deletions python/gui/editorwidgets/qgsdatetimeedit.sip
Expand Up @@ -12,6 +12,13 @@ class QgsDateTimeEdit : QDateTimeEdit
{ {
%Docstring %Docstring
The QgsDateTimeEdit class is a QDateTimeEdit with the capability of setting/reading null date/times. The QgsDateTimeEdit class is a QDateTimeEdit with the capability of setting/reading null date/times.

.. warning::

You should use the signal valueChanged of this subclass
rather than QDateTimeEdit.dateTimeChanged. If you consequently connect parent's
dateTimeChanged signal and call dateTime() afterwards there is no warranty to
have a proper NULL value handling.
%End %End


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


.. versionadded:: 2.16 .. versionadded:: 2.16
%End

signals:

void valueChanged( const QDateTime &date );
%Docstring
signal emitted whenever the value changes.
@param date the new date/time value.
%End %End


protected: protected:
Expand Down
8 changes: 7 additions & 1 deletion src/gui/editorwidgets/qgsdatetimeedit.cpp
Expand Up @@ -62,7 +62,11 @@ void QgsDateTimeEdit::clear()


changed( QDateTime() ); changed( QDateTime() );


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


mClearAction->setVisible( mAllowNull && !mIsNull ); mClearAction->setVisible( mAllowNull && !mIsNull );

emit QgsDateTimeEdit::valueChanged( dateTime );
} }


void QgsDateTimeEdit::displayNull( bool updateCalendar ) void QgsDateTimeEdit::displayNull( bool updateCalendar )
Expand Down
13 changes: 13 additions & 0 deletions src/gui/editorwidgets/qgsdatetimeedit.h
Expand Up @@ -23,6 +23,11 @@
/** /**
* \ingroup gui * \ingroup gui
* \brief The QgsDateTimeEdit class is a QDateTimeEdit with the capability of setting/reading null date/times. * \brief The QgsDateTimeEdit class is a QDateTimeEdit with the capability of setting/reading null date/times.
*
* \warning You should use the signal valueChanged of this subclass
* rather than QDateTimeEdit::dateTimeChanged. If you consequently connect parent's
* dateTimeChanged signal and call dateTime() afterwards there is no warranty to
* have a proper NULL value handling.
*/ */
class GUI_EXPORT QgsDateTimeEdit : public QDateTimeEdit class GUI_EXPORT QgsDateTimeEdit : public QDateTimeEdit
{ {
Expand Down Expand Up @@ -62,6 +67,14 @@ class GUI_EXPORT QgsDateTimeEdit : public QDateTimeEdit
*/ */
void setEmpty(); void setEmpty();


signals:

/**
* signal emitted whenever the value changes.
* @param date the new date/time value.
*/
void valueChanged( const QDateTime &date );

protected: protected:
void mousePressEvent( QMouseEvent *event ) override; void mousePressEvent( QMouseEvent *event ) override;
void focusOutEvent( QFocusEvent *event ) override; void focusOutEvent( QFocusEvent *event ) override;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/editorwidgets/qgsdatetimeeditwrapper.cpp
Expand Up @@ -93,7 +93,7 @@ void QgsDateTimeEditWrapper::initWidget( QWidget *editor )


if ( mQgsDateTimeEdit ) if ( mQgsDateTimeEdit )
{ {
connect( mQgsDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this, &QgsDateTimeEditWrapper::dateTimeChanged ); connect( mQgsDateTimeEdit, &QgsDateTimeEdit::valueChanged, this, &QgsDateTimeEditWrapper::dateTimeChanged );
} }
else else
{ {
Expand Down

0 comments on commit 333347b

Please sign in to comment.