Skip to content
Permalink
Browse files

editor widgets: restore handling of null values in textedit widget (f…

…ixes #10497)
  • Loading branch information
jef-n committed Jun 9, 2014
1 parent f617be1 commit e605ad6501b08cf925a9f8492276601d2ae052e8
Showing with 26 additions and 19 deletions.
  1. +7 −5 src/app/qgsfeatureaction.cpp
  2. +19 −14 src/gui/editorwidgets/qgstexteditwidget.cpp
@@ -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
@@ -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() )
{
@@ -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 )
@@ -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 ) ) );
@@ -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.
You can’t perform that action at this time.