Skip to content
Permalink
Browse files

fix NULL constraint on date/time widget with allow NULL

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 d8cc285fd2805a0bd43c6ef5e2c9ab9ed8086a3c
@@ -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 );

@@ -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 );
}
}

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

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

emit QgsDateTimeEdit::dateTimeChanged( dateTime );
}

void QgsDateTimeEdit::displayNull( bool updateCalendar )
@@ -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;
@@ -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
{

0 comments on commit d8cc285

Please sign in to comment.
You can’t perform that action at this time.