-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update widgets with default values on attribute form #31167
Conversation
…ing to the currently changed widgets field. On init the dependencies are stored into mDefaultValueDependencies. On attribute change the default values are written into the other widgets according to the dependency map. To avoid recursions the widgets fields index is stored into mAlreadyUpdatedFields.
f6b1ab8
to
a1bb806
Compare
src/gui/qgsattributeform.cpp
Outdated
// need to check dstVar.isNull() != srcVar.isNull() | ||
// otherwise if dstVar=NULL and scrVar=0, then dstVar = srcVar | ||
// be careful- sometimes two null qvariants will be reported as not equal!! (e.g., different types) | ||
bool changed = ( dstVar != srcVar && !dstVar.isNull() && !srcVar.isNull() ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would qgsVariantEqual
take care of all that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would care for the case that when a NULL
value changes to 0, but for what is mentioned in the comment (I took it from saveEdit
because there the behavior is the same) qgsVariantEqual
does not care for the case when a null value does not change, but "two null qvariants will be reported as not equal." This would mean both are isNull
but the comparison is not true. This could be solved by changing the qgsVectorEqual
as this:
return lhs.isNull() == rhs.isNull() && lhs == rhs || ( lhs.isNull() && rhs.isNull() ) ;
But I'm not sure about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think lhs.isNull == rhs.isNull
already takes care of exactly this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the && lhs == rhs
makes it false again. When we pass two NULL
values. the compared isNull
s returns true, but are connected with the comparison that could be false (regarding to the comment).
What the lhs.isNull == rhs.isNull
does is, that it returns false in the end in case we compare 0
with NULL
what is nice...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just because of the comment or did you experience this?
In the end I think qgsVariantCompare
was implemented exactly for cases like this, so it would be a pity if it's not usable here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just because the comment. That's why I'm not sure at all. But it should be same like in saveEdits
and so I didn't want that I risk issues with this case...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's see, the check in saveEdits was introduced in 2fddc00 (by @nyalldawson)
The method qgsVariantEqual
later in 90e2c45 (by @elpaso)
@nyalldawson / @elpaso, could the above patch be merged into qgsVariantEqual
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically the question is, should we add a testcase for
QVERIFY( qgsVariantEqual( QVariant( QVariant::Int ), QVariant( QVariant::Double ) ) )
I'd say yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to all the above ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it correct that qgsVariantEqual
should return true
in case of two NULL
values from different types, but false
if one of them is invalid?
Means these test are correct:
QVERIFY( qgsVariantEqual( QVariant( QVariant::Int ), QVariant( QVariant::String ) ) );
QVERIFY( !qgsVariantEqual( QVariant( QVariant::Int ), QVariant() ) );
With that it won't have an issue anymore on the formerly failing test for the ValueRelationWidget
but what is happening here, is still a little bit weird https://github.com/qgis/QGIS/blob/master/src/gui/editorwidgets/qgsvaluerelationwidgetwrapper.cpp#L236
QVariant v( mComboBox->itemData( i ) );
if ( qgsVariantEqual( v, value ) )
{
idx = i;
break;
}
There it won't return true
anymore if value
is invalid, but still it wouldn't had returned true
before also if v
would not be recognized as NULL
if mComboBox->itemData( i )
returns 0
. So shouldn't here be set a type with e.g. toInt()
?
src/gui/qgsattributeform.cpp
Outdated
// need to check dstVar.isNull() != srcVar.isNull() | ||
// otherwise if dstVar=NULL and scrVar=0, then dstVar = srcVar | ||
// be careful- sometimes two null qvariants will be reported as not equal!! (e.g., different types) | ||
bool changed = ( dstVar != srcVar && !dstVar.isNull() && !srcVar.isNull() ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to all the above ;)
9b9e15a
to
6bbf5da
Compare
Co-Authored-By: Matthias Kuhn <matthias@opengis.ch>
Updates widget values on real time while editing the referenced fields.
![default_value_01](https://user-images.githubusercontent.com/28384354/62712413-13b3ef80-b9fb-11e9-84f9-973e17369c2b.gif)
To avoid recursion it stores the currently updated fields index in
![default_value_02](https://user-images.githubusercontent.com/28384354/62712430-17e00d00-b9fb-11e9-8619-4781614839af.gif)
mAlreadyUpdatedFields
. The widgets contains as default value the value of the previous one plus 1:To Do:
-[ ] Testfunction in
testqgsattributeform