mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-18 00:06:00 -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).
|
Resets the widget to show no value (ie, an "unknown" state).
|
||||||
|
|
||||||
.. versionadded:: 2.16
|
.. 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
|
%End
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
@ -36,6 +36,7 @@ QgsDateTimeEdit::QgsDateTimeEdit( QWidget *parent )
|
|||||||
|
|
||||||
QgsDateTimeEdit::QgsDateTimeEdit( const QVariant &var, QVariant::Type parserType, QWidget *parent )
|
QgsDateTimeEdit::QgsDateTimeEdit( const QVariant &var, QVariant::Type parserType, QWidget *parent )
|
||||||
: QDateTimeEdit( var, parserType, parent )
|
: QDateTimeEdit( var, parserType, parent )
|
||||||
|
, mNullRepresentation( QgsApplication::nullRepresentation() )
|
||||||
{
|
{
|
||||||
QIcon clearIcon = QgsApplication::getThemeIcon( "/mIconClearText.svg" );
|
QIcon clearIcon = QgsApplication::getThemeIcon( "/mIconClearText.svg" );
|
||||||
mClearAction = new QAction( clearIcon, tr( "clear" ), this );
|
mClearAction = new QAction( clearIcon, tr( "clear" ), this );
|
||||||
@ -151,7 +152,7 @@ void QgsDateTimeEdit::focusOutEvent( QFocusEvent *event )
|
|||||||
if ( mAllowNull && mIsNull && !mCurrentPressEvent )
|
if ( mAllowNull && mIsNull && !mCurrentPressEvent )
|
||||||
{
|
{
|
||||||
QAbstractSpinBox::focusOutEvent( event );
|
QAbstractSpinBox::focusOutEvent( event );
|
||||||
if ( lineEdit()->text() != QgsApplication::nullRepresentation() )
|
if ( lineEdit()->text() != mNullRepresentation )
|
||||||
{
|
{
|
||||||
displayNull();
|
displayNull();
|
||||||
}
|
}
|
||||||
@ -191,7 +192,7 @@ void QgsDateTimeEdit::showEvent( QShowEvent *event )
|
|||||||
{
|
{
|
||||||
QDateTimeEdit::showEvent( event );
|
QDateTimeEdit::showEvent( event );
|
||||||
if ( mAllowNull && mIsNull &&
|
if ( mAllowNull && mIsNull &&
|
||||||
lineEdit()->text() != QgsApplication::nullRepresentation() )
|
lineEdit()->text() != mNullRepresentation )
|
||||||
{
|
{
|
||||||
displayNull();
|
displayNull();
|
||||||
}
|
}
|
||||||
@ -222,6 +223,20 @@ void QgsDateTimeEdit::changed( const QVariant &dateTime )
|
|||||||
emitValueChanged( 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 )
|
void QgsDateTimeEdit::displayNull( bool updateCalendar )
|
||||||
{
|
{
|
||||||
disconnect( this, &QDateTimeEdit::dateTimeChanged, this, &QgsDateTimeEdit::changed );
|
disconnect( this, &QDateTimeEdit::dateTimeChanged, this, &QgsDateTimeEdit::changed );
|
||||||
@ -232,7 +247,7 @@ void QgsDateTimeEdit::displayNull( bool updateCalendar )
|
|||||||
QDateTimeEdit::setDateTime( minimumDateTime() );
|
QDateTimeEdit::setDateTime( minimumDateTime() );
|
||||||
}
|
}
|
||||||
lineEdit()->setCursorPosition( lineEdit()->text().length() );
|
lineEdit()->setCursorPosition( lineEdit()->text().length() );
|
||||||
lineEdit()->setText( QgsApplication::nullRepresentation() );
|
lineEdit()->setText( mNullRepresentation );
|
||||||
connect( this, &QDateTimeEdit::dateTimeChanged, this, &QgsDateTimeEdit::changed );
|
connect( this, &QDateTimeEdit::dateTimeChanged, this, &QgsDateTimeEdit::changed );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,6 +97,24 @@ class GUI_EXPORT QgsDateTimeEdit : public QDateTimeEdit
|
|||||||
*/
|
*/
|
||||||
void setEmpty();
|
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:
|
signals:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -141,6 +159,7 @@ class GUI_EXPORT QgsDateTimeEdit : public QDateTimeEdit
|
|||||||
|
|
||||||
QString mOriginalStyleSheet = QString();
|
QString mOriginalStyleSheet = QString();
|
||||||
QAction *mClearAction;
|
QAction *mClearAction;
|
||||||
|
QString mNullRepresentation;
|
||||||
|
|
||||||
//! TRUE if the widget allows null values
|
//! TRUE if the widget allows null values
|
||||||
bool mAllowNull = true;
|
bool mAllowNull = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user