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.

(cherry-picked from 2fddc00)
  • Loading branch information
nyalldawson committed May 25, 2016
1 parent 41a98ca commit 695883e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/gui/qgsattributeform.cpp
Expand Up @@ -176,9 +176,14 @@ bool QgsAttributeForm::save()
{
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 695883e

Please sign in to comment.