mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Merge pull request #5992 from 3nids/fix17790
fix NULL constraint on date/time widget with allow NULL
This commit is contained in:
commit
333347b9a0
@ -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:
|
||||
|
@ -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 )
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user