Skip to content
Permalink
Browse files

Proper handling of NULL values for edit widgets

 * Photo widget preserves NULL value
 * Web widget preserves NULL value
 * Attribute table can distinguish between 0 and NULL (Fix #11235)
  • Loading branch information
m-kuhn committed Sep 22, 2014
1 parent 3593608 commit 6f84cdceab5cf3110ae8d2f62ed575682b9ca7c0
@@ -97,7 +97,7 @@ void QgsAttributeTableDelegate::setModelData( QWidget *editor, QAbstractItemMode

newValue = eww->value();

if ( oldValue != newValue && newValue.isValid() )
if ( oldValue != newValue && newValue.isValid() || oldValue.isNull() != newValue.isNull() )
{
vl->beginEditCommand( tr( "Attribute changed" ) );
vl->changeAttributeValue( fid, fieldIdx, newValue, oldValue );
@@ -17,7 +17,7 @@

#include <QGridLayout>
#include <QFileDialog>

#include <QSettings>

#include "qgsfilterlineedit.h"

@@ -64,7 +64,12 @@ QVariant QgsPhotoWidgetWrapper::value()
QVariant v;

if ( mLineEdit )
v = mLineEdit->text();
{
if ( mLineEdit->text() == QSettings().value( "qgis/nullValue", "NULL" ).toString() )
v = QVariant( QVariant::String );
else
v = mLineEdit->text();
}

return v;
}
@@ -123,9 +128,12 @@ void QgsPhotoWidgetWrapper::initWidget( QWidget* editor )
void QgsPhotoWidgetWrapper::setValue( const QVariant& value )
{
if ( mLineEdit )
mLineEdit->setText( value.toString() );


{
if ( value.isNull() )
mLineEdit->setText( QSettings().value( "qgis/nullValue", "NULL" ).toString() );
else
mLineEdit->setText( value.toString() );
}
}

void QgsPhotoWidgetWrapper::setEnabled( bool enabled )
@@ -20,6 +20,7 @@

#include <QGridLayout>
#include <QFileDialog>
#include <QSettings>

QgsWebViewWidgetWrapper::QgsWebViewWidgetWrapper( QgsVectorLayer* vl, int fieldIdx, QWidget* editor, QWidget* parent )
: QgsEditorWidgetWrapper( vl, fieldIdx, editor, parent )
@@ -37,7 +38,12 @@ QVariant QgsWebViewWidgetWrapper::value()
QVariant v;

if ( mLineEdit )
v = mLineEdit->text();
{
if ( mLineEdit->text() == QSettings().value( "qgis/nullValue", "NULL" ).toString() )
v = QVariant( QVariant::String );
else
v = mLineEdit->text();
}

return v;
}
@@ -108,7 +114,12 @@ void QgsWebViewWidgetWrapper::initWidget( QWidget* editor )
void QgsWebViewWidgetWrapper::setValue( const QVariant& value )
{
if ( mLineEdit )
mLineEdit->setText( value.toString() );
{
if ( value.isNull() )
mLineEdit->setText( QSettings().value( "qgis/nullValue", "NULL" ).toString() );
else
mLineEdit->setText( value.toString() );
}

loadUrl( value.toString() );
}
@@ -207,14 +207,15 @@ bool QgsAttributeForm::save()
{
if (( dst[i] == src[i] && dst[i].isNull() == src[i].isNull() ) || !dst[i].isValid() )
{
QgsDebugMsg( "equal or invalid destination" );
QgsDebugMsg( QString( "dst:'%1' (type:%2,isNull:%3,isValid:%4)" )
.arg( dst[i].toString() ).arg( dst[i].typeName() ).arg( dst[i].isNull() ).arg( dst[i].isValid() ) );
QgsDebugMsg( QString( "src:'%1' (type:%2,isNull:%3,isValid:%4)" )
.arg( src[i].toString() ).arg( src[i].typeName() ).arg( src[i].isNull() ).arg( src[i].isValid() ) );
continue;
}

QgsDebugMsg( QString( "Updating field %1" ).arg( i ) );
QgsDebugMsg( QString( "dst:'%1' (type:%2, isNull:%3, isValid:%4)" )
.arg( dst[i].toString() ).arg( dst[i].typeName() ).arg( dst[i].isNull() ).arg( dst[i].isValid() ) );
QgsDebugMsg( QString( "src:'%1' (type:%2, isNull:%3, isValid:%4)" )
.arg( src[i].toString() ).arg( src[i].typeName() ).arg( src[i].isNull() ).arg( src[i].isValid() ) );

success &= mLayer->changeAttributeValue( mFeature.id(), i, dst[i], src[i] );
n++;
}

0 comments on commit 6f84cdc

Please sign in to comment.
You can’t perform that action at this time.