Skip to content
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

Geom compatibility check release 2.18 fixes #15741 #16927 #5223

Conversation

luipir
Copy link
Contributor

@luipir luipir commented Sep 20, 2017

Description

Added geometry compatibility check in addFeature and changeGeometry of QgsVectorLayerEditBuffer. In this way the user is prompted of incompatibility errors during editing.
Also added in QgsVectorLayerProvider::convertToProviderType flat geometry in case provider does not support 3d or M => they are removed.
This patch would fix #15741 #16927
This fix has effect also on the issue #16948 during paste in case of incompatibilities.

NOTE: because now editBuffer addFeature and changeGeometry can return boolean error => also vectorLayer changeGeometry and addFeature can return error. I updated (I hope) any place where this method were used without taking into account a possible fails. Most of these code parts were not covered by test to know if the patch can introduce more regressions.

Checklist

Reviewing is a process done by project maintainers, mostly on a volunteer basis. We try to keep the overhead as small as possible and appreciate if you help us to do so by completing the following items. Feel free to ask in a comment if you have troubles with any of them.

  • Commit messages are descriptive and explain the rationale for changes
  • Commits which fix bugs include fixes #11111 in the commit message next to the description
  • Commits which add new features are tagged with [FEATURE] in the commit message
  • Commits which change the UI or existing user workflows are tagged with [needs-docs] in the commit message and containt sufficient information in the commit message to be documented
  • I have read the QGIS Coding Standards and this PR complies with them
  • This PR passes all existing unit tests (test results will be reported by travis-ci after opening this PR)
  • New unit tests have been added for core changes
  • I have run the scripts/prepare-commit.sh script before each commit

Copy link
Member

@m-kuhn m-kuhn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one, make sure that there are no changes in terms of things that would have been committed before and are no longer committed because of early exit on failure, since we are in a stable release series.

* In case of convertion a message is notified in the log
* @param geom pointer to the geometry that is adapted to provider
* @return bool true if success
* @note added in QGIS 2.18
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be QGIS 2.18.patch

@@ -148,4 +148,13 @@ class QgsVectorLayerEditBuffer : QObject
void updateAttributeMapIndex( QgsAttributeMap& attrs, int index, int offset ) const;

void updateLayerFields();

/** Apply geom modification basing on provider geometry type.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/geom/geometry/


/** Apply geom modification basing on provider geometry type.
* Geom is modified only if successful convertion is possibile.
* In case of convertion a message is notified in the log
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conversion
sent to the log

/** Apply geom modification basing on provider geometry type.
* Geom is modified only if successful convertion is possibile.
* In case of convertion a message is notified in the log
* @param geom pointer to the geometry that is adapted to provider
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/geom/geometry
"is adapted" -> "should be adapted"

* Geom is modified only if successful convertion is possibile.
* In case of convertion a message is notified in the log
* @param geom pointer to the geometry that is adapted to provider
* @return bool true if success
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can success be interpreted here? Only if the geometry has been changed or also if it already was ok before?

remoteLayer->addAttribute( field );
if ( !remoteLayer->addAttribute( field ) )
{
this->syncError = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to use this.

remoteLayer->addFeature( f, false );
if ( !remoteLayer->addFeature( f, false ) )
{
this->syncError = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this

remoteLayer->deleteFeature( fid );
if ( !remoteLayer->deleteFeature( fid ) )
{
this->syncError = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to use this.

remoteLayer->changeAttributeValue( fid, attrLookup[ values.at( i ).attr ], values.at( i ).value );
if ( !remoteLayer->changeAttributeValue( fid, attrLookup[ values.at( i ).attr ], values.at( i ).value ) )
{
this->syncError = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No more repetitions ;)

QgsGeometry* newGeom = provider->convertToProviderType( geom );
if ( !newGeom )
{
QgsMessageLog::logMessage( tr( "ERROR: geometry type is not compatible with the layer.", "not compatible geometry" ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use level instead of an "ERROR" prefix

@luipir
Copy link
Contributor Author

luipir commented Sep 21, 2017

@m-kuhn about your comment:
"Nice one, make sure that there are no changes in terms of things that would have been committed before and are no longer committed because of early exit on failure, since we are in a stable release series."
I asked to some power users to do tests (a lot of old parts are not covered by unit tests). BTW I would prefer to see this patch merged before to have more extensive test in case of regressions.
There will obviously regression regarding the workflow! now the error is raised as soon as it happened. since 2.18.13, the error is raise only at commitChanges phase with the risk to loose all editing work because of one feature incompatibility.

@m-kuhn
Copy link
Member

m-kuhn commented Sep 21, 2017

since 2.18.13, the error is raise only at commitChanges phase with the risk to loose all editing work because of one feature incompatibility.

Ah, sorry, I wasn't aware of that. This changes everything a bit.

In which scenario does this happen actually? I guess it's there for 2D->3D promotion and similar which should be easy to do, is it related to pasting multi-features on single-layers?

@gioman
Copy link
Contributor

gioman commented Sep 21, 2017

In which scenario does this happen actually?

in 2.14: you have a table that is not "multi" and you try to manually merge two features so to create a multi-geometry, a warning pop up saying that you can't and the operation is discarded.

in 2.18: you do the same, no error/warning, you continue with (a ton of) other edits and then try to save > error because of the "multi" geometry you created and you can only discard all the changes you made.

@gioman
Copy link
Contributor

gioman commented Sep 21, 2017

in 2.18: you do the same, no error/warning, you continue with (a ton of) other edits and then try to save > error because of the "multi" geometry you created and you can only discard all the changes you made.

moreover at some point in 2.18 when discarding changes there was also data loss (now this seems fixed).

@m-kuhn
Copy link
Member

m-kuhn commented Sep 21, 2017

Why could we do a warning pop up back then and now we need to send it to the message log?

* @return bool true if success.
* Success means that input geometry is changed because conversion is applied or
* geometry is untouched if geometry conversion is not necessary.
* Fail if conversion is not possible and geometry is untuched.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typos:
False if conversion is not possible and geometry is untouched.

Can you also change the "Geom" strings to "Geometry", while at it?

Thanks

@gioman
Copy link
Contributor

gioman commented Sep 21, 2017

Why could we do a warning pop up back then and now we need to send it to the message log?

good question.

@m-kuhn
Copy link
Member

m-kuhn commented Sep 21, 2017

Bit +1 to go ahead with this fast

@luipir
Copy link
Contributor Author

luipir commented Sep 21, 2017

@gioman @m-kuhn
compatibility check weas moved from qgisapp:
https://github.com/qgis/QGIS/blob/release-2_14/src/app/qgisapp.cpp#L6539
from this @mhugent commit:
8d70a51
IMHO move the check to provider is a good solution, but lack of a complete user notification.

@luipir
Copy link
Contributor Author

luipir commented Sep 21, 2017

TestQgsServer now fail afte updated a doxygen comment?

@m-kuhn
Copy link
Member

m-kuhn commented Sep 21, 2017

IIRC on the provider we have the infrastructure in place to pushError()

@luipir
Copy link
Contributor Author

luipir commented Sep 21, 2017

IIRC on the provider we have the infrastructure in place to pushError()

I'll give a look

@gioman
Copy link
Contributor

gioman commented Sep 21, 2017

@luipir I tested your branch and the patch seems to work fine to me! It certainly a much better user experience. I would suggest to merge asap for wider testing.

@m-kuhn
Copy link
Member

m-kuhn commented Sep 21, 2017

Thanks for testing @gioman
@luipir, your call, if a better UX/error reporting is possible, it would be awesome, if not, let's get this merged.

Copy link
Member

@m-kuhn m-kuhn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the improvements

@luipir
Copy link
Contributor Author

luipir commented Sep 21, 2017

@m-kuhn I'm doing some tests with pushMessages from QgsVectorDataProvider::convertToProviderType I'll give you more report tomorrows

@luipir
Copy link
Contributor Author

luipir commented Sep 22, 2017

@m-kuhn simplified error message management usign pushMessage

@luipir
Copy link
Contributor Author

luipir commented Sep 22, 2017

@m-kuhn now two test fails:
170 - PyQgsComposerPicture (Failed) <- (test passes locally)
265 - PyQgsServer (Failed) <- as usual

@luipir
Copy link
Contributor Author

luipir commented Sep 25, 2017

still PyQgsServer failing as usual? I've to ask to merge? PyQgsServer seems fail in every 2.18 build

@m-kuhn
Copy link
Member

m-kuhn commented Sep 25, 2017

@luipir can you identify since when the tests fail?

@luipir
Copy link
Contributor Author

luipir commented Sep 25, 2017

@m-kuhn If I'm not wrong, would be this merge #5225

@luipir luipir force-pushed the geom_compatibility_check_release-2_18-fix15741 branch from 76e9199 to 45f041d Compare September 26, 2017 07:33
@luipir
Copy link
Contributor Author

luipir commented Sep 26, 2017

rebased on the latest upstream fuixes that should fix failing trest on QgsServer

@luipir
Copy link
Contributor Author

luipir commented Sep 26, 2017

now a new test fail that pass locally :/
qgis_legendrenderertest

@m-kuhn
Copy link
Member

m-kuhn commented Sep 26, 2017

Haven't seen that one fail before, but this looks suspicious indeed:

Expected

Expected

Result

Result

@luipir
Copy link
Contributor Author

luipir commented Sep 26, 2017

again I'm lost :(
thi sis my successful local test that here is failing:
68: QDEBUG : TestQgsLegendRenderer::testDiagramSizeLegend() src/core/symbology-ng/qgssymbollayerv2utils.cpp: 4074: (prettyBreaks) [0ms] pretty classes: 5
68: QDEBUG : TestQgsLegendRenderer::testDiagramSizeLegend() "testName:legend_diagram_size size=52.9219x89.9 dpmm=3.77953 s=200x339"
68: QDEBUG : TestQgsLegendRenderer::testDiagramSizeLegend() src/core/qgsscalecalculator.cpp: 40: (setMapUnits) [14ms] Map units set to 2
68: QDEBUG : TestQgsLegendRenderer::testDiagramSizeLegend() QgsRenderChecker using mask image
68: /tmp/legend_diagram_size.png
68: /home/ginetto/PROGRAMMING/QGIS/QGIS-2.18/tests/testdata/control_images/legend/expected_legend_diagram_size/expected_legend_diagram_size.png
68: QDEBUG : TestQgsLegendRenderer::testDiagramSizeLegend() Expected size: 200w x 339h
68: QDEBUG : TestQgsLegendRenderer::testDiagramSizeLegend() Actual size: 200w x 339h
68: /tmp/legend_diagram_size_result_diff.png
68: QDEBUG : TestQgsLegendRenderer::testDiagramSizeLegend() 6/67800 pixels mismatched (500 allowed)
68: 6/67800
68: QDEBUG : TestQgsLegendRenderer::testDiagramSizeLegend() src/core/layertree/qgslayertreeregistrybridge.cpp: 78: (layersWillBeRemoved) [7ms] 1 layers will be removed, enabled:1
68: QDEBUG : TestQgsLegendRenderer::testDiagramSizeLegend() src/core/layertree/qgslayertreeregistrybridge.cpp: 78: (layersWillBeRemoved) [0ms] 4 layers will be removed, enabled:1
68: PASS : TestQgsLegendRenderer::testDiagramSizeLegend()

@m-kuhn
Copy link
Member

m-kuhn commented Sep 26, 2017

If you could use git blame to see who created the test we could ping him here to see if he has a hint on what's going wrong.

If it's unrelated to your changes (and only a flaky test) we can easily restart the tests, merge and leave the author of the legend tests to further investigate what could have gone wrong.

@luipir
Copy link
Contributor Author

luipir commented Sep 26, 2017

I always think it's my responsability... and I loose a lot of time for this :/... I'll look for the test author

@@ -148,4 +148,16 @@ class QgsVectorLayerEditBuffer : QObject
void updateAttributeMapIndex( QgsAttributeMap& attrs, int index, int offset ) const;

void updateLayerFields();

/** Apply geometry modification basing on provider geometry type.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you could add here a hint on what kind of modification can be expected from this method this would help a lot for a reader of the API. (I.e. some reference to Z, M, Multi, others?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added more doc to the underling call that do the work: convertToProviderType

@luipir
Copy link
Contributor Author

luipir commented Sep 26, 2017

@nyalldawson any idea why:
qgis_legendrenderertest -> TestQgsLegendRenderer::testDiagramSizeLegend fails? (blame points to you)
It works locally and my PR is involved only in case of add features or change geometries and test just works on an empty layer.

@nyalldawson
Copy link
Collaborator

@nyalldawson any idea why:
qgis_legendrenderertest -> TestQgsLegendRenderer::testDiagramSizeLegend fails? (blame points to you)
It works locally and my PR is involved only in case of add features or change geometries and test just works on an empty layer.

Sorry - no idea. I write a LOT of tests without necessarily understanding all the underlying code! ;)

@luipir
Copy link
Contributor Author

luipir commented Sep 26, 2017

now success! :/ travis magics?

@nyalldawson
Copy link
Collaborator

Odd.. I don't recall seeing that test fail intermittently. Maybe another recent change has caused this...

@m-kuhn
Copy link
Member

m-kuhn commented Sep 26, 2017

now success! :/ travis magics?

Probably more an unstable test...

@luipir
Copy link
Contributor Author

luipir commented Sep 26, 2017

me too... is the first time I'm facing this fail!

@luipir
Copy link
Contributor Author

luipir commented Sep 26, 2017

@m-kuhn merge?

@@ -391,6 +391,13 @@ class QgsVectorDataProvider : QgsDataProvider
void pushError( const QString& msg );

/** Converts the geometry to the provider type if possible / necessary
* this is the list of possibile modifications:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/possibile/possible/

* - convert to multitype if necessary
* - convert to curved type if necessary
* - convert to linear type from curved type
* - Add or Remove z/m types
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this say "values" instead of "types"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh and either always capitalize the items or never

* - convert to multitype if necessary
* - convert to curved type if necessary
* - convert to linear type from curved type
* - Add or Remove z/m types
@return the converted geometry or nullptr if no conversion was necessary or possible*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better us \returns, most code is now written this way

@luipir
Copy link
Contributor Author

luipir commented Sep 27, 2017

@m-kuhn is it safe to merge? do you need more reviewer to merge?

@m-kuhn
Copy link
Member

m-kuhn commented Sep 27, 2017

It looks good for me. I can't tell if it is safe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants