Skip to content

Commit

Permalink
changes to QgsDateTimeEdit to support the minimal Date supported by Q…
Browse files Browse the repository at this point in the history
…DateTimeEdit (0100-01-01)
  • Loading branch information
mj10777 committed Jul 12, 2017
1 parent ad31087 commit b7ff59c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
12 changes: 12 additions & 0 deletions python/gui/editorwidgets/qgsdatetimeedit.sip
Expand Up @@ -30,6 +30,18 @@ Determines if the widget allows setting null date/time.
:rtype: bool
%End

void setMinimumEditDateTime();
%Docstring
Set the lowest Date that can be displayed with the Qt.ISODate format
- uses QDateTimeEdit.setMinimumDateTime (since Qt 4.4)
\note
- QDate and QDateTime does not support minus years for the Qt.ISODate format
-> returns empty (toString) or invalid (fromString) values
- QDateTimeEdit.setMinimumDateTime does not support dates < '0100-01-01'
-> it is not for us to wonder why [defined in qdatetimeparser_p.h]
.. versionadded:: 3.0
%End

void setDateTime( const QDateTime &dateTime );
%Docstring
setDateTime set the date time in the widget and handles null date times.
Expand Down
1 change: 1 addition & 0 deletions src/gui/editorwidgets/qgsdatetimeedit.cpp
Expand Up @@ -52,6 +52,7 @@ QgsDateTimeEdit::QgsDateTimeEdit( QWidget *parent )

// init with current time so mIsNull is properly initialized
QDateTimeEdit::setDateTime( QDateTime::currentDateTime() );
setMinimumEditDateTime();
}

void QgsDateTimeEdit::setAllowNull( bool allowNull )
Expand Down
14 changes: 14 additions & 0 deletions src/gui/editorwidgets/qgsdatetimeedit.h
Expand Up @@ -38,6 +38,20 @@ class GUI_EXPORT QgsDateTimeEdit : public QDateTimeEdit
void setAllowNull( bool allowNull );
bool allowNull() const {return mAllowNull;}

/** Set the lowest Date that can be displayed with the Qt::ISODate format
* - uses QDateTimeEdit::setMinimumDateTime (since Qt 4.4)
* \note
* - QDate and QDateTime does not support minus years for the Qt::ISODate format
* -> returns empty (toString) or invalid (fromString) values
* - QDateTimeEdit::setMinimumDateTime does not support dates < '0100-01-01'
* -> it is not for us to wonder why [defined in qdatetimeparser_p.h]
* \since QGIS 3.0
*/
void setMinimumEditDateTime()
{
setMinimumDateTime( QDateTime::fromString( "0100-01-01", Qt::ISODate ) );
}

/**
* \brief setDateTime set the date time in the widget and handles null date times.
* \note since QDateTimeEdit::setDateTime() is not virtual, setDateTime must be called for QgsDateTimeEdit.
Expand Down

0 comments on commit b7ff59c

Please sign in to comment.