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
Fixing grouping/ungrouping crash #3190
Conversation
67ec3bf
to
90ce7c6
Compare
@nyalldawson this is ready for review, could you please take a look ? The crash was basically due to unclear ownership of the "group" item, the code was deleting it on "ungroup" while it was still referenced by the UndoRedoCommand of the "group item move". My patch drops the immediate deletion replacing it with an UndoRedoCommand that adds/remove the grouping, with "Remove" command taking ownership of the group. |
Ok it's still not ready as on "delete group item" we're still removing the items contained in the group while we should not be doing that. |
Also, "undo grouping" leaves the Scene with unselectable items |
Note that the premature deletion of items still results in a crash on exit (double free, I suspect):
|
I've tested more and fixed more undo/redo issues. I'd add a few more tests (for position and undostack state) and then cleanup and merge. |
@strk great! will take a look first thing tomorrow |
Hopefully for tomorrow I'll be finished with tests and tweaks. |
More tests have been added. Travis still fails due to lack of SIP bindings update (due to the new QgsGroupUngroupItemsCommand class). No test was added to expose the possible memory leak (only theoretical so far) |
Tests for sent signals are also missing (itemAdded/itemRemoved being sent on "undo"/"redo" operations and more) -- @nyalldawson if you want to help there, I won't be on the code before ~10 hours from now |
/** Signals removal of an item (the group) */ | ||
void itemRemoved( QgsComposerItem* item ); | ||
|
||
private: |
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.
no need to include private members in sip - they aren't accessible anyway
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.
how about signals, are them needed in SIP ?
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.
Yes, signals should be included
@strk looks good to me. Honestly the whole ownership of items in composer is a mess, and desperately in need of reworking. In future I'd like to change it so items are always deleted when removed from the scene, and only the xml representation of the composition/items is stored by undo/redo commands. |
Do you have any hint about testing signals dispatch ? As I'm not sure "itemAdded"/"itemRemoved" are sent correclty on undo/redo, and hadn't seen the current testcase checking for them. |
I'll play with QSignalSpy some before merging this. |
Given that it's a c++ test you can use QSignalSpy. See TestQgsAtlasComposition::test_signals() for similar code you could copy. |
Ok QSignalSpy testing gave its first fruits already. |
Also, should grouping/ungrouping send its own signals ? |
Another thing cough bu the test: QgsComposition::ungroupItems( group ) -- emits an ItemRemoved signal for each member of the group. Seems to be WRONG to me, as there's eventually a single item removed, assuming the group is considered an item. Likewise, there is no emission on grouping, which is inconsistent with the emissions on ungrouping. |
There, I think the code is good to ready for merging now. If Travis is happy, I'd merge. Or feel free to merge it yourself Nyall, if you have more sun than I will in the next 10 hours :) |
d273938
to
0d71b3a
Compare
squash-rebased for final check |
3984ee3
to
958cdc8
Compare
Gah, travis fails for unrelated issues: PyQgsWFSProviderGUI |
Fixes qgis#11371 (crash on ungrouping after moving the group) and more undo/redo related issues. Enable pending test for the crash (now passing) and add many more undo/redo related ones (including signals testing). Includes a new QgsGroupUngroupItemsCommand class and its SIP bindings.
958cdc8
to
66c815c
Compare
Rebase-pushed as a211c98 |
Nice work @strk! |
@nyalldawson how do you feel about backporting this to 2.14 ? See #3209 |
See http://hub.qgis.org/issues/11371