Skip to content

Commit

Permalink
fix NULL constraint on date/time widget with allow NULL
Browse files Browse the repository at this point in the history
the issue was that widget wrapper was using parent QDateTimeEdit::dateTimeChanged signal. It was connected both internally to QgsDateTimeEdit::changed and in the form to detect changes. When QgsAttributeForm was recreating the updated feature it was calling QgsDateTimeEdit::value() before changed() could update the value (i.e. setting mIsNull to false).

fix #17790
  • Loading branch information
3nids committed Jan 5, 2018
1 parent df95536 commit d8cc285
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
3 changes: 3 additions & 0 deletions python/gui/editorwidgets/qgsdatetimeedit.sip
Expand Up @@ -65,6 +65,9 @@ Resets the widget to show no value (ie, an "unknown" state).
.. versionadded:: 2.16
%End

signals:
void dateTimeChanged( const QDateTime &date );

protected:
virtual void mousePressEvent( QMouseEvent *event );

Expand Down
7 changes: 2 additions & 5 deletions src/gui/editorwidgets/qgsdatetimeedit.cpp
Expand Up @@ -61,11 +61,6 @@ void QgsDateTimeEdit::clear()
displayNull();

changed( QDateTime() );

// avoid slot double activation
disconnect( this, &QDateTimeEdit::dateTimeChanged, this, &QgsDateTimeEdit::changed );
emit dateTimeChanged( QDateTime() );
connect( this, &QDateTimeEdit::dateTimeChanged, this, &QgsDateTimeEdit::changed );
}
}

Expand Down Expand Up @@ -174,6 +169,8 @@ void QgsDateTimeEdit::changed( const QDateTime &dateTime )
}

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

emit QgsDateTimeEdit::dateTimeChanged( dateTime );
}

void QgsDateTimeEdit::displayNull( bool updateCalendar )
Expand Down
3 changes: 3 additions & 0 deletions src/gui/editorwidgets/qgsdatetimeedit.h
Expand Up @@ -62,6 +62,9 @@ class GUI_EXPORT QgsDateTimeEdit : public QDateTimeEdit
*/
void setEmpty();

signals:
void dateTimeChanged( const QDateTime &date );

protected:
void mousePressEvent( QMouseEvent *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 )
{
connect( mQgsDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this, &QgsDateTimeEditWrapper::dateTimeChanged );
connect( mQgsDateTimeEdit, &QgsDateTimeEdit::dateTimeChanged, this, &QgsDateTimeEditWrapper::dateTimeChanged );
}
else
{
Expand Down

0 comments on commit d8cc285

Please sign in to comment.