Skip to content

Commit

Permalink
do not override QDateTimeEdit::dateTimeChanged
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Jan 5, 2018
1 parent 2528639 commit 42976df
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
9 changes: 4 additions & 5 deletions python/gui/editorwidgets/qgsdatetimeedit.sip
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class QgsDateTimeEdit : QDateTimeEdit

.. warning::

You should use the signal dateTimeChanged of this subclass QgsDateTimeEdit
rather than parent's one (QDateTimeEdit). If you consequently connect parent's
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
Expand Down Expand Up @@ -74,10 +74,9 @@ Resets the widget to show no value (ie, an "unknown" state).

signals:

void dateTimeChanged( const QDateTime &date );
void valueChanged( const QDateTime &date );
%Docstring
reimplements QDateTimeEdit.dateTimeChanged signal
to properly handles NULL values.
signal emitted whenever the value changes.
@param date the new date/time value.
%End

Expand Down
11 changes: 10 additions & 1 deletion src/gui/editorwidgets/qgsdatetimeedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ void QgsDateTimeEdit::clear()
displayNull();

changed( QDateTime() );

// 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 );
emit dateTimeChanged( QDateTime() );
connect( this, &QDateTimeEdit::dateTimeChanged, this, &QgsDateTimeEdit::changed );
}
}

Expand Down Expand Up @@ -170,7 +179,7 @@ void QgsDateTimeEdit::changed( const QDateTime &dateTime )

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

emit QgsDateTimeEdit::dateTimeChanged( dateTime );
emit QgsDateTimeEdit::valueChanged( dateTime );
}

void QgsDateTimeEdit::displayNull( bool updateCalendar )
Expand Down
9 changes: 4 additions & 5 deletions src/gui/editorwidgets/qgsdatetimeedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
* \ingroup gui
* \brief The QgsDateTimeEdit class is a QDateTimeEdit with the capability of setting/reading null date/times.
*
* \warning You should use the signal dateTimeChanged of this subclass QgsDateTimeEdit
* rather than parent's one (QDateTimeEdit). If you consequently connect parent's
* \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.
*/
Expand Down Expand Up @@ -70,11 +70,10 @@ class GUI_EXPORT QgsDateTimeEdit : public QDateTimeEdit
signals:

/**
* reimplements QDateTimeEdit::dateTimeChanged signal
* to properly handles NULL values.
* signal emitted whenever the value changes.
* @param date the new date/time value.
*/
void dateTimeChanged( const QDateTime &date );
void valueChanged( const QDateTime &date );

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

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

0 comments on commit 42976df

Please sign in to comment.