Skip to content
Permalink
Browse files

Add an interderminant "empty" state for QgsDateTimeEdit

  • Loading branch information
nyalldawson committed May 22, 2016
1 parent 1e77839 commit 6d868598f5e477c4dfe25a0acd80e6370e291f2b
@@ -30,6 +30,10 @@ class QgsDateTimeEdit : QDateTimeEdit
//! @note if the widget is not configured to accept NULL dates, this will have no effect
virtual void clear();

/** Resets the widget to show no value (ie, an "unknown" state).
* @note added in QGIS 2.16
*/
void setEmpty();

protected:
virtual void resizeEvent( QResizeEvent* event );
@@ -28,6 +28,7 @@ QgsDateTimeEdit::QgsDateTimeEdit( QWidget *parent )
: QDateTimeEdit( parent )
, mAllowNull( true )
, mIsNull( true )
, mIsEmpty( false )
{
mClearButton = new QToolButton( this );
mClearButton->setIcon( QgsApplication::getThemeIcon( "/mIconClear.svg" ) );
@@ -57,9 +58,9 @@ void QgsDateTimeEdit::setAllowNull( bool allowNull )
{
mAllowNull = allowNull;

mNullLabel->setVisible( mAllowNull && mIsNull );
mClearButton->setVisible( mAllowNull && !mIsNull );
lineEdit()->setVisible( !mAllowNull || !mIsNull );
mNullLabel->setVisible(( mAllowNull && mIsNull ) && !mIsEmpty );
mClearButton->setVisible( mAllowNull && ( !mIsNull || mIsEmpty ) );
lineEdit()->setVisible(( !mAllowNull || !mIsNull ) && !mIsEmpty );
}


@@ -69,6 +70,13 @@ void QgsDateTimeEdit::clear()
emit dateTimeChanged( QDateTime() );
}

void QgsDateTimeEdit::setEmpty()
{
mNullLabel->setVisible( false );
lineEdit()->setVisible( false );
mClearButton->setVisible( mAllowNull );
}

void QgsDateTimeEdit::mousePressEvent( QMouseEvent* event )
{
QRect lerect = rect().adjusted( 0, 0, -spinButtonWidth(), 0 );
@@ -80,6 +88,7 @@ void QgsDateTimeEdit::mousePressEvent( QMouseEvent* event )

void QgsDateTimeEdit::changed( const QDateTime & dateTime )
{
mIsEmpty = false;
mIsNull = dateTime.isNull();
mNullLabel->setVisible( mAllowNull && mIsNull );
mClearButton->setVisible( mAllowNull && !mIsNull );
@@ -98,6 +107,8 @@ int QgsDateTimeEdit::frameWidth() const

void QgsDateTimeEdit::setDateTime( const QDateTime& dateTime )
{
mIsEmpty = false;

// set an undefined date
if ( !dateTime.isValid() || dateTime.isNull() )
{
@@ -107,6 +118,7 @@ void QgsDateTimeEdit::setDateTime( const QDateTime& dateTime )
{
QDateTimeEdit::setDateTime( dateTime );
mIsNull = false;
changed( dateTime );
}
}

@@ -52,6 +52,10 @@ class GUI_EXPORT QgsDateTimeEdit : public QDateTimeEdit
//! @note if the widget is not configured to accept NULL dates, this will have no effect
virtual void clear() override;

/** Resets the widget to show no value (ie, an "unknown" state).
* @note added in QGIS 2.16
*/
void setEmpty();

protected:
virtual void resizeEvent( QResizeEvent* event ) override;
@@ -69,6 +73,7 @@ class GUI_EXPORT QgsDateTimeEdit : public QDateTimeEdit

bool mAllowNull;
bool mIsNull;
bool mIsEmpty;

QLineEdit* mNullLabel;
QToolButton* mClearButton;

1 comment on commit 6d86859

@3nids

This comment has been minimized.

Copy link
Member

@3nids 3nids commented on 6d86859 Dec 27, 2017

@nyalldawson I don't see the point here. mIsEmpty is always false.

does it miss mIsEmpty = true; in setEmpty()?

Please sign in to comment.
You can’t perform that action at this time.