-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Changed `TreeModel` constructor to accept `ResourceModelMap` so the tree model is capable of adding new resources to the map when doing a drag copy operation. * Changed `MainWindow::CreateResource` to allocate a new `TreeNode` directly instead of through the root. I did this originally anticipating that `TreeModel::addNode` would be used by the drag and drop code, but ultimately it wasn't. * Changed TreeModel::addNode to append the allocated child and undid the change in #47 we merged a few days ago. * Created the helper `ResourceModelMap::CreateResourceName` which gives a unique name for a new resource of the given type. This was created by extracting the logic from `MainWindow::CreateResource` so that it could also be used by a drag copy operation. Again, I will reiterate from my previous comments on #42 that this can later be made more efficient by just caching the last number (maybe max id) used to create a new resource of that type. * Changed the `dragDropMode` of the main window's tree view to `DragDrop` instead of `InternalMove` because we want to support copying the resources to the same target. Without this change the copy operation (done by holding CTRL during the drag) becomes just a move operation when the source and target are the same view. * Changed `TreeModel::flags` to indicate `Qt::ItemIsDropEnabled` where appropriate (e.g, folders & the root) and `Qt::ItemIsDragEnabled` where appropriate (e.g, every valid/visible node). * Changed `TreeModel::parent` to return an invalid model index, which means the root, when the parent node found in the `parents` map is null. This is actually an error condition and should hypothetically only occur if a logic mistake is made somewhere else, but I ran into it while doing this drag and drop and hence made the change. * Added `TreeModel::supportedDropActions` to indicate that we support `MoveAction` and not just `CopyAction` (the default implementation of `QAbstractItemModel`). * Added the private inline helper `TreeNode::treeNodeMime` so I didn't have to repeat the literal string multiple times, which decreases the potential for mistakes and typos and turns them into a compile-time error instead. * Added `TreeModel::mimeTypes` to return the mime types supported by the tree model, for now it's just the "RadialGM/TreeNode" custom mime that is currently pointer based. * Added `TreeModel::mimeData` to serialize tree nodes for drag and drop operations. - It cannot do any IPC transferring of the data because it is purely pointer based for now. - I guard against drag operations originating outside the process by writing the application process id to the data stream and checking it later during the drop processing. - This can later be changed to just serialize the proto into bytes, but that requires some extra work I didn't want to do yet. For example, it will need to do some file transferring as well for certain resources like the sound file of a sound resource. I am not too sure how interested people would be in this proposed feature yet. - I sort the indices from lowest to highest row number so that I can make certain assumptions when processing a drop operation. For example, one of the things I like to assume is that other nodes removed from the same parent have effectively decreased the index of the current row we are removing. This also allows me to create new names for the nodes during a drag copy operation in a consecutive order. * Added `TreeModel::dropMimeData` so the tree model can accept drop operations. - `ExtractSubrange` is used to remove the node from its parent's `child` repeated pointer field. I used this because it seemed to work but also the documentation says it releases ownership without destroying the item, which is what was intended. - `MoveAction` is the trickier one because it requires adjusting the insert and remove rows based on what rows we are dragging. This is even more complicated considering the fact that I chose to allow non-contiguous selections in the tree. - `CopyAction` is handled by doing a copy of the proto, not removing the previous nodes, and inserting the new nodes with a unique name based on their type. Later this will need to duplicate files on disk for certain resources, like the sound data file for a sound. - The insertion of the moved or copied nodes is done by appending it at the end of the new parent's `child` field. I then swap it into place since `RepeatedPtrField` has no built-in way of inserting items anywhere other than the end.
- Loading branch information
1 parent
cd8ff62
commit c099a98
Showing
6 changed files
with
162 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters