diff --git a/python/gui/auto_generated/editorwidgets/qgsdatetimeedit.sip.in b/python/gui/auto_generated/editorwidgets/qgsdatetimeedit.sip.in index 8e837dec0a8..7b6fc0b221c 100644 --- a/python/gui/auto_generated/editorwidgets/qgsdatetimeedit.sip.in +++ b/python/gui/auto_generated/editorwidgets/qgsdatetimeedit.sip.in @@ -149,6 +149,7 @@ Signal emitted whenever the value changes. QgsDateTimeEdit( const QVariant &var, QVariant::Type parserType, QWidget *parent ); + void displayNull( bool updateCalendar = false ); %Docstring write the null value representation to the line edit without changing the value diff --git a/src/gui/editorwidgets/qgsdatetimeedit.cpp b/src/gui/editorwidgets/qgsdatetimeedit.cpp index 59d5fdec9dc..02ef79f014d 100644 --- a/src/gui/editorwidgets/qgsdatetimeedit.cpp +++ b/src/gui/editorwidgets/qgsdatetimeedit.cpp @@ -220,7 +220,8 @@ void QgsDateTimeEdit::changed( const QVariant &dateTime ) } mClearAction->setVisible( mAllowNull && !mIsNull ); - emitValueChanged( dateTime ); + if ( !mBlockChangedSignal ) + emitValueChanged( dateTime ); } QString QgsDateTimeEdit::nullRepresentation() const @@ -309,7 +310,10 @@ void QgsDateTimeEdit::setDateTime( const QDateTime &dateTime ) // Check if it's really changed or crash, see GH #29937 else if ( dateTime != QgsDateTimeEdit::dateTime() ) { + // changed emits a signal, so don't allow it to be emitted from setDateTime + mBlockChangedSignal++; QDateTimeEdit::setDateTime( dateTime ); + mBlockChangedSignal--; changed( dateTime ); } } @@ -374,7 +378,10 @@ void QgsTimeEdit::setTime( const QTime &time ) // Check if it's really changed or crash, see GH #29937 else if ( time != QgsTimeEdit::time() ) { + // changed emits a signal, so don't allow it to be emitted from setTime + mBlockChangedSignal++; QDateTimeEdit::setTime( time ); + mBlockChangedSignal--; changed( time ); } } @@ -408,7 +415,10 @@ void QgsDateEdit::setDate( const QDate &date ) // Check if it's really changed or crash, see GH #29937 else if ( date != QgsDateEdit::date() ) { + // changed emits a signal, so don't allow it to be emitted from setDate + mBlockChangedSignal++; QDateTimeEdit::setDate( date ); + mBlockChangedSignal--; changed( date ); } } diff --git a/src/gui/editorwidgets/qgsdatetimeedit.h b/src/gui/editorwidgets/qgsdatetimeedit.h index 12eed613a16..c6816ab07a4 100644 --- a/src/gui/editorwidgets/qgsdatetimeedit.h +++ b/src/gui/editorwidgets/qgsdatetimeedit.h @@ -135,6 +135,9 @@ class GUI_EXPORT QgsDateTimeEdit : public QDateTimeEdit //! TRUE if the widget is empty bool mIsEmpty = false; + //! Block change signals if TRUE + int mBlockChangedSignal = 0; + /** * write the null value representation to the line edit without changing the value * \param updateCalendar Flag if calendar is open and minimum date needs to be set