Merge pull request #5992 from 3nids/fix17790

fix NULL constraint on date/time widget with allow NULL
This commit is contained in:
Denis Rouzaud 2018-01-05 07:49:30 -04:00 committed by GitHub
commit 333347b9a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 2 deletions

View File

@ -12,6 +12,13 @@ class QgsDateTimeEdit : QDateTimeEdit
{
%Docstring
The QgsDateTimeEdit class is a QDateTimeEdit with the capability of setting/reading null date/times.
.. 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.
%End
%TypeHeaderCode
@ -63,6 +70,14 @@ Set the current date as NULL
Resets the widget to show no value (ie, an "unknown" state).
.. versionadded:: 2.16
%End
signals:
void valueChanged( const QDateTime &date );
%Docstring
signal emitted whenever the value changes.
@param date the new date/time value.
%End
protected:

View File

@ -62,7 +62,11 @@ void QgsDateTimeEdit::clear()
changed( QDateTime() );
// avoid slot double activation
// 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 );
@ -174,6 +178,8 @@ void QgsDateTimeEdit::changed( const QDateTime &dateTime )
}
mClearAction->setVisible( mAllowNull && !mIsNull );
emit QgsDateTimeEdit::valueChanged( dateTime );
}
void QgsDateTimeEdit::displayNull( bool updateCalendar )

View File

@ -23,6 +23,11 @@
/**
* \ingroup gui
* \brief The QgsDateTimeEdit class is a QDateTimeEdit with the capability of setting/reading null date/times.
*
* \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.
*/
class GUI_EXPORT QgsDateTimeEdit : public QDateTimeEdit
{
@ -62,6 +67,14 @@ class GUI_EXPORT QgsDateTimeEdit : public QDateTimeEdit
*/
void setEmpty();
signals:
/**
* signal emitted whenever the value changes.
* @param date the new date/time value.
*/
void valueChanged( const QDateTime &date );
protected:
void mousePressEvent( QMouseEvent *event ) override;
void focusOutEvent( QFocusEvent *event ) override;

View File

@ -93,7 +93,7 @@ void QgsDateTimeEditWrapper::initWidget( QWidget *editor )
if ( mQgsDateTimeEdit )
{
connect( mQgsDateTimeEdit, &QDateTimeEdit::dateTimeChanged, this, &QgsDateTimeEditWrapper::dateTimeChanged );
connect( mQgsDateTimeEdit, &QgsDateTimeEdit::valueChanged, this, &QgsDateTimeEditWrapper::dateTimeChanged );
}
else
{