Skip to content

Commit

Permalink
Fix indeterminate state for numeric line edits was showing "NULL"
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 9, 2016
1 parent 8126d46 commit a65d9c5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/gui/editorwidgets/qgstexteditwrapper.cpp
Expand Up @@ -115,14 +115,16 @@ void QgsTextEditWrapper::initWidget( QWidget* editor )
QgsFilterLineEdit *fle = qobject_cast<QgsFilterLineEdit*>( mLineEdit );
if ( field().type() == QVariant::Int || field().type() == QVariant::Double || field().type() == QVariant::LongLong || field().type() == QVariant::Date )
{
mLineEdit->setPlaceholderText( defVal.toString() );
mPlaceholderText = defVal.toString();
mLineEdit->setPlaceholderText( mPlaceholderText );
}
else if ( fle )
{
fle->setNullValue( defVal.toString() );
}

connect( mLineEdit, SIGNAL( textChanged( QString ) ), this, SLOT( valueChanged( QString ) ) );
connect( mLineEdit, SIGNAL( textChanged( QString ) ), this, SLOT( textChanged( QString ) ) );

mWritablePalette = mLineEdit->palette();
mReadOnlyPalette = mLineEdit->palette();
Expand All @@ -143,7 +145,12 @@ void QgsTextEditWrapper::showIndeterminateState()
if ( mPlainTextEdit )
mPlainTextEdit->blockSignals( true );
if ( mLineEdit )
{
mLineEdit->blockSignals( true );
// for interdeminate state we need to clear the placeholder text - we want an empty line edit, not
// one showing the default value (eg "NULL")
mLineEdit->setPlaceholderText( QString() );
}

setWidgetValue( QString( "" ) );

Expand All @@ -157,6 +164,11 @@ void QgsTextEditWrapper::showIndeterminateState()

void QgsTextEditWrapper::setValue( const QVariant& val )
{
if ( mLineEdit )
{
//restore placeholder text, which may have been removed by showIndeterminateState()
mLineEdit->setPlaceholderText( mPlaceholderText );
}
setWidgetValue( val );
}

Expand All @@ -178,6 +190,15 @@ void QgsTextEditWrapper::setEnabled( bool enabled )
}
}

void QgsTextEditWrapper::textChanged( const QString& )
{
if ( mLineEdit )
{
//restore placeholder text, which may have been removed by showIndeterminateState()
mLineEdit->setPlaceholderText( mPlaceholderText );
}
}

void QgsTextEditWrapper::setWidgetValue( const QVariant& val )
{
QString v;
Expand Down
4 changes: 4 additions & 0 deletions src/gui/editorwidgets/qgstexteditwrapper.h
Expand Up @@ -53,12 +53,16 @@ class GUI_EXPORT QgsTextEditWrapper : public QgsEditorWidgetWrapper
void setValue( const QVariant& value ) override;
void setEnabled( bool enabled ) override;

private slots:
void textChanged( const QString& text );

private:
QTextEdit* mTextEdit;
QPlainTextEdit* mPlainTextEdit;
QLineEdit* mLineEdit;
QPalette mReadOnlyPalette;
QPalette mWritablePalette;
QString mPlaceholderText;

void setWidgetValue( const QVariant& value );
};
Expand Down

0 comments on commit a65d9c5

Please sign in to comment.