Fix duplicate signals emitted by QgsDateTimeEdit when changed

This commit is contained in:
Nyall Dawson 2020-02-24 11:02:28 +10:00
parent 0a5ddb3cea
commit 983a3d8655
3 changed files with 15 additions and 1 deletions

View File

@ -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

View File

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

View File

@ -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