mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-16 00:05:45 -04:00
Allow null string to be customised for QgsDateTimeEdit
E.g. for processing use this needs to be "Not specified"
This commit is contained in:
parent
6c94bf493d
commit
1facaf5149
@ -103,6 +103,26 @@ Set the current date as NULL.
|
||||
Resets the widget to show no value (ie, an "unknown" state).
|
||||
|
||||
.. versionadded:: 2.16
|
||||
%End
|
||||
|
||||
QString nullRepresentation() const;
|
||||
%Docstring
|
||||
Returns the widget's NULL representation, which defaults
|
||||
to :py:func:`QgsApplication.nullRepresentation()`
|
||||
|
||||
.. seealso:: :py:func:`setNullRepresentation`
|
||||
|
||||
.. versionadded:: 3.14
|
||||
%End
|
||||
|
||||
void setNullRepresentation( const QString &null );
|
||||
%Docstring
|
||||
Sets the widget's ``null`` representation, which defaults
|
||||
to :py:func:`QgsApplication.nullRepresentation()`
|
||||
|
||||
.. seealso:: :py:func:`nullRepresentation`
|
||||
|
||||
.. versionadded:: 3.14
|
||||
%End
|
||||
|
||||
signals:
|
||||
|
@ -36,6 +36,7 @@ QgsDateTimeEdit::QgsDateTimeEdit( QWidget *parent )
|
||||
|
||||
QgsDateTimeEdit::QgsDateTimeEdit( const QVariant &var, QVariant::Type parserType, QWidget *parent )
|
||||
: QDateTimeEdit( var, parserType, parent )
|
||||
, mNullRepresentation( QgsApplication::nullRepresentation() )
|
||||
{
|
||||
QIcon clearIcon = QgsApplication::getThemeIcon( "/mIconClearText.svg" );
|
||||
mClearAction = new QAction( clearIcon, tr( "clear" ), this );
|
||||
@ -151,7 +152,7 @@ void QgsDateTimeEdit::focusOutEvent( QFocusEvent *event )
|
||||
if ( mAllowNull && mIsNull && !mCurrentPressEvent )
|
||||
{
|
||||
QAbstractSpinBox::focusOutEvent( event );
|
||||
if ( lineEdit()->text() != QgsApplication::nullRepresentation() )
|
||||
if ( lineEdit()->text() != mNullRepresentation )
|
||||
{
|
||||
displayNull();
|
||||
}
|
||||
@ -191,7 +192,7 @@ void QgsDateTimeEdit::showEvent( QShowEvent *event )
|
||||
{
|
||||
QDateTimeEdit::showEvent( event );
|
||||
if ( mAllowNull && mIsNull &&
|
||||
lineEdit()->text() != QgsApplication::nullRepresentation() )
|
||||
lineEdit()->text() != mNullRepresentation )
|
||||
{
|
||||
displayNull();
|
||||
}
|
||||
@ -222,6 +223,20 @@ void QgsDateTimeEdit::changed( const QVariant &dateTime )
|
||||
emitValueChanged( dateTime );
|
||||
}
|
||||
|
||||
QString QgsDateTimeEdit::nullRepresentation() const
|
||||
{
|
||||
return mNullRepresentation;
|
||||
}
|
||||
|
||||
void QgsDateTimeEdit::setNullRepresentation( const QString &nullRepresentation )
|
||||
{
|
||||
mNullRepresentation = nullRepresentation;
|
||||
if ( mIsNull )
|
||||
{
|
||||
lineEdit()->setText( mNullRepresentation );
|
||||
}
|
||||
}
|
||||
|
||||
void QgsDateTimeEdit::displayNull( bool updateCalendar )
|
||||
{
|
||||
disconnect( this, &QDateTimeEdit::dateTimeChanged, this, &QgsDateTimeEdit::changed );
|
||||
@ -232,7 +247,7 @@ void QgsDateTimeEdit::displayNull( bool updateCalendar )
|
||||
QDateTimeEdit::setDateTime( minimumDateTime() );
|
||||
}
|
||||
lineEdit()->setCursorPosition( lineEdit()->text().length() );
|
||||
lineEdit()->setText( QgsApplication::nullRepresentation() );
|
||||
lineEdit()->setText( mNullRepresentation );
|
||||
connect( this, &QDateTimeEdit::dateTimeChanged, this, &QgsDateTimeEdit::changed );
|
||||
}
|
||||
|
||||
|
@ -97,6 +97,24 @@ class GUI_EXPORT QgsDateTimeEdit : public QDateTimeEdit
|
||||
*/
|
||||
void setEmpty();
|
||||
|
||||
/**
|
||||
* Returns the widget's NULL representation, which defaults
|
||||
* to QgsApplication::nullRepresentation().
|
||||
*
|
||||
* \see setNullRepresentation()
|
||||
* \since QGIS 3.14
|
||||
*/
|
||||
QString nullRepresentation() const;
|
||||
|
||||
/**
|
||||
* Sets the widget's \a null representation, which defaults
|
||||
* to QgsApplication::nullRepresentation().
|
||||
*
|
||||
* \see nullRepresentation()
|
||||
* \since QGIS 3.14
|
||||
*/
|
||||
void setNullRepresentation( const QString &null );
|
||||
|
||||
signals:
|
||||
|
||||
/**
|
||||
@ -141,6 +159,7 @@ class GUI_EXPORT QgsDateTimeEdit : public QDateTimeEdit
|
||||
|
||||
QString mOriginalStyleSheet = QString();
|
||||
QAction *mClearAction;
|
||||
QString mNullRepresentation;
|
||||
|
||||
//! TRUE if the widget allows null values
|
||||
bool mAllowNull = true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user