Skip to content
Permalink
Browse files
Fix indeterminate state for numeric line edits was showing "NULL"
  • Loading branch information
nyalldawson committed May 9, 2016
1 parent 8126d46 commit a65d9c522f840b6c66284bdb9e563110962d955b
Showing with 26 additions and 1 deletion.
  1. +22 −1 src/gui/editorwidgets/qgstexteditwrapper.cpp
  2. +4 −0 src/gui/editorwidgets/qgstexteditwrapper.h
@@ -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();
@@ -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( "" ) );

@@ -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 );
}

@@ -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;
@@ -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 );
};

0 comments on commit a65d9c5

Please sign in to comment.