Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 6f84cdc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/gui/attributetable/qgsattributetabledelegate.cpp
Expand Up @@ -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 );
Expand Down
18 changes: 13 additions & 5 deletions src/gui/editorwidgets/qgsphotowidgetwrapper.cpp
Expand Up @@ -17,7 +17,7 @@

#include <QGridLayout>
#include <QFileDialog>

#include <QSettings>

#include "qgsfilterlineedit.h"

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 )
Expand Down
15 changes: 13 additions & 2 deletions src/gui/editorwidgets/qgswebviewwidgetwrapper.cpp
Expand Up @@ -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 )
Expand All @@ -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;
}
Expand Down Expand Up @@ -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() );
}
Expand Down
11 changes: 6 additions & 5 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -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++;
}
Expand Down

0 comments on commit 6f84cdc

Please sign in to comment.