Refactor and fix DnD in Document mode #1199
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Drag-and-drop in document mode has some issues. Some also affect the user, but others are just implementation issues. This PR addresses both. See also letsfindaway#193.
User visible issues
Internal issues
UBDocumentTreeMimeData
class is weired: it contains a list of indexes as well as a list of URLs, but in the end none of them are ever used.UBDocumentTreeModel::dropMimeData()
function is never called. Instead all drop handling is already done inUBDocumentTreeView::dropEvent()
. It is ok to do so: you can either implement dropping in the view or in the model and I'm happy to do it in the view. So that functiondropMimeData()
can be removed.UBPersistenceManager::copyDocumentScene()
, which was only called from that dead code.dropEvent()
implements scene copying in another way, preferred by me. It loads the scene, determines the related media objects and copies them, saves the scene and copies the related thumbnail.UBForeignObjectsHandler
used for the other way of copying. This class was parsing the SVG and determines the referenced objects from there. So it implements another SVG parser besides theUBSvgSubsetAdaptor
and I would like to avoid having two parsers in parallel. It was never proved whether this code actually works because it was never invoked. So I'm happy to remove this class.This PR
This PR fixes issues in drag start, drag move and drop:
UBDocumentTreeMimeData
class now carries the correct set of indexes (for the first column only) and the correct mime type.dragEnter()
now sets the correct action depending on the mime type.drawMove()
also had some minor issues. We now make sure that the correct cursor is shown indicating the proper drop action (Copy or Move).dropEvent()
uses the mime type and the data contained in the mime data classes.UBDocumentTreeView::mapIndexesToSource()
is no longer needed, as the indexes in the mime data are already referring to the base model and not the proxy model.UBDocumentTreeModel::setHighLighted()
is fixed to always highlight a complete row. Also updating the UI is now correctly done by emitting adataChanged()
signal instead of updating a specific area inUBDocumentTreeView::updateIndexEnvirons()
.So finally this PR fixes some user visible issues and at the same time improves and simplifies the code structure of DnD handling in document mode.