Skip to content

Commit

Permalink
Fix logic in detecting whether attribute form widgets have changed
Browse files Browse the repository at this point in the history
Since two null QVariants can be reported as not equal if they have
different underlying types we need to ensure that we don't flag
this situation as a changed value.
  • Loading branch information
nyalldawson committed May 24, 2016
1 parent 38e0502 commit 2fddc00
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/gui/qgsattributeform.cpp
Expand Up @@ -274,9 +274,14 @@ bool QgsAttributeForm::saveEdits()
{
QVariant dstVar = dst.at( eww->fieldIdx() );
QVariant srcVar = eww->value();

// need to check dstVar.isNull() != srcVar.isNull()
// otherwise if dstVar=NULL and scrVar=0, then dstVar = srcVar
if (( dstVar != srcVar || dstVar.isNull() != srcVar.isNull() ) && srcVar.isValid() && !mLayer->editFormConfig()->readOnly( eww->fieldIdx() ) )
// be careful- sometimes two null qvariants will be reported as not equal!! (eg different types)
bool changed = ( dstVar != srcVar && !dstVar.isNull() && !srcVar.isNull() )
|| ( dstVar.isNull() != srcVar.isNull() );
if ( changed && srcVar.isValid()
&& !mLayer->editFormConfig()->readOnly( eww->fieldIdx() ) )
{
dst[eww->fieldIdx()] = srcVar;

Expand Down

0 comments on commit 2fddc00

Please sign in to comment.