Navigation Menu

Skip to content

Commit

Permalink
editor widgets: restore handling of null values in textedit widget (f…
Browse files Browse the repository at this point in the history
…ixes #10497)
  • Loading branch information
jef-n committed Jun 9, 2014
1 parent f617be1 commit e605ad6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
12 changes: 7 additions & 5 deletions src/app/qgsfeatureaction.cpp
Expand Up @@ -161,20 +161,22 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap& defaultAttributes )
mFeature.initAttributes( fields.count() );
for ( int idx = 0; idx < fields.count(); ++idx )
{
QVariant v;

if ( defaultAttributes.contains( idx ) )
{
QgsDebugMsg( QString( "Using specified default %1 for %2" ).arg( defaultAttributes.value( idx ).toString() ).arg( idx ) );
mFeature.setAttribute( idx, defaultAttributes.value( idx ) );
v = defaultAttributes.value( idx );
}
else if ( reuseLastValues && sLastUsedValues.contains( mLayer ) && sLastUsedValues[ mLayer ].contains( idx ) )
{
QgsDebugMsg( QString( "reusing %1 for %2" ).arg( sLastUsedValues[ mLayer ][idx].toString() ).arg( idx ) );
mFeature.setAttribute( idx, sLastUsedValues[ mLayer ][idx] );
v = sLastUsedValues[ mLayer ][idx];
}
else
{
mFeature.setAttribute( idx, provider->defaultValue( idx ) );
v = provider->defaultValue( idx );
}

mFeature.setAttribute( idx, v );
}

// show the dialog to enter attribute values
Expand Down
33 changes: 19 additions & 14 deletions src/gui/editorwidgets/qgstexteditwidget.cpp
Expand Up @@ -28,8 +28,7 @@ QgsTextEditWidget::QgsTextEditWidget( QgsVectorLayer* vl, int fieldIdx, QWidget*

QVariant QgsTextEditWidget::value()
{
QSettings settings;
QVariant v;
QString v;

if ( mTextEdit && mTextEdit->document()->isModified() )
{
Expand All @@ -53,12 +52,11 @@ QVariant QgsTextEditWidget::value()
v = mLineEdit->text();
}

if ( v.toString() == settings.value( "qgis/nullValue", "NULL" ).toString() )
{
v = QVariant( field().type() );
}

return v;
if (( v.isEmpty() && ( field().type() == QVariant::Int || field().type() == QVariant::Double || field().type() == QVariant::LongLong || field().type() == QVariant::Date ) ) ||
v == QSettings().value( "qgis/nullValue", "NULL" ).toString() )
return QVariant( field().type() );
else
return QVariant( v );
}

QWidget* QgsTextEditWidget::createWidget( QWidget* parent )
Expand Down Expand Up @@ -99,8 +97,7 @@ void QgsTextEditWidget::initWidget( QWidget* editor )
QgsFilterLineEdit *fle = qobject_cast<QgsFilterLineEdit*>( mLineEdit );
if ( fle && !( field().type() == QVariant::Int || field().type() == QVariant::Double || field().type() == QVariant::LongLong || field().type() == QVariant::Date ) )
{
QSettings settings;
fle->setNullValue( settings.value( "qgis/nullValue", "NULL" ).toString() );
fle->setNullValue( QSettings().value( "qgis/nullValue", "NULL" ).toString() );
}

connect( mLineEdit, SIGNAL( textChanged( QString ) ), this, SLOT( valueChanged( QString ) ) );
Expand All @@ -109,17 +106,25 @@ void QgsTextEditWidget::initWidget( QWidget* editor )

void QgsTextEditWidget::setValue( const QVariant& value )
{
QString v;
if ( value.isNull() && !( field().type() == QVariant::Int || field().type() == QVariant::Double || field().type() == QVariant::LongLong || field().type() == QVariant::Date ) )
{
v = QSettings().value( "qgis/nullValue", "NULL" ).toString();
}
else
v = value.toString();

if ( mTextEdit )
{
if ( config( "UseHtml" ).toBool() )
mTextEdit->setHtml( value.toString() );
mTextEdit->setHtml( v );
else
mTextEdit->setPlainText( value.toString() );
mTextEdit->setPlainText( v );
}

if ( mPlainTextEdit )
mPlainTextEdit->setPlainText( value.toString() );
mPlainTextEdit->setPlainText( v );

if ( mLineEdit )
mLineEdit->setText( value.toString() );
mLineEdit->setText( v );
}

0 comments on commit e605ad6

Please sign in to comment.