diff options
author | Tomi Korpipää <tomi.korpipaa@qt.io> | 2016-06-09 12:19:15 +0300 |
---|---|---|
committer | Tomi Korpipää <tomi.korpipaa@qt.io> | 2016-06-09 09:22:02 +0000 |
commit | eaba4f713fa14b0981d3cf76eab6bf55295840c1 (patch) | |
tree | d7d65456ef4ac8edf62726fd6a1639b0fa809992 /editorlib | |
parent | e9038c3d77d594022634282e5a7d02a484df5aee (diff) |
Fixed deleting and duplicating multiselection
Change-Id: I24f98923b518966a7b7571eed7194ae75ddbe6cb
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Diffstat (limited to 'editorlib')
-rw-r--r-- | editorlib/qml/ComponentMenu.qml | 7 | ||||
-rw-r--r-- | editorlib/qml/EntityTree.qml | 15 | ||||
-rw-r--r-- | editorlib/src/editorsceneitemmodel.cpp | 32 | ||||
-rw-r--r-- | editorlib/src/editorsceneitemmodel.h | 1 |
4 files changed, 49 insertions, 6 deletions
diff --git a/editorlib/qml/ComponentMenu.qml b/editorlib/qml/ComponentMenu.qml index 8d4bc6c..71b8cb5 100644 --- a/editorlib/qml/ComponentMenu.qml +++ b/editorlib/qml/ComponentMenu.qml @@ -88,8 +88,9 @@ Menu { if (multiSelect) { // Handle multiselection removal editorScene.undoHandler.beginMacro(text) - for (var i = 0; i < selectionList.length; ++i) - editorScene.undoHandler.createRemoveEntityCommand(selectionList[i]) + var removeList = editorScene.sceneModel.parentList(selectionList) + for (var i = 0; i < removeList.length; ++i) + editorScene.undoHandler.createRemoveEntityCommand(removeList[i]) editorScene.undoHandler.endMacro() } else { // Doublecheck that we don't try to remove the scene root @@ -104,9 +105,9 @@ Menu { iconSource: "images/duplicate.png" onTriggered: { if (multiSelect) { - var duplicateList = selectionList // Copy list, as the original is emptied on insertEntity // Handle multiselection duplication editorScene.undoHandler.beginMacro(text) + var duplicateList = editorScene.sceneModel.parentList(selectionList) for (var i = 0; i < duplicateList.length; ++i) editorScene.undoHandler.createDuplicateEntityCommand(duplicateList[i]) editorScene.undoHandler.endMacro() diff --git a/editorlib/qml/EntityTree.qml b/editorlib/qml/EntityTree.qml index 50a7af5..640a4ac 100644 --- a/editorlib/qml/EntityTree.qml +++ b/editorlib/qml/EntityTree.qml @@ -43,9 +43,18 @@ Item { property bool multiSelectedCamera: false Keys.onDeletePressed: { - // Doublecheck that we don't try to remove the scene root - if (entityTreeView.selection.currentIndex !== editorScene.sceneModel.sceneEntityIndex()) - editorScene.undoHandler.createRemoveEntityCommand(selectedEntityName) + if (multiSelect) { + // Handle multiselection removal + editorScene.undoHandler.beginMacro("Remove selected") + var removeList = editorScene.sceneModel.parentList(selectionList) + for (var i = 0; i < removeList.length; ++i) + editorScene.undoHandler.createRemoveEntityCommand(removeList[i]) + editorScene.undoHandler.endMacro() + } else { + // Doublecheck that we don't try to remove the scene root + if (entityTreeView.selection.currentIndex !== editorScene.sceneModel.sceneEntityIndex()) + editorScene.undoHandler.createRemoveEntityCommand(selectedEntityName) + } } function focusTree() { diff --git a/editorlib/src/editorsceneitemmodel.cpp b/editorlib/src/editorsceneitemmodel.cpp index eaeda80..85cf0ef 100644 --- a/editorlib/src/editorsceneitemmodel.cpp +++ b/editorlib/src/editorsceneitemmodel.cpp @@ -493,6 +493,38 @@ QString EditorSceneItemModel::generateValidName(const QString &desiredName, return testName; } +QStringList EditorSceneItemModel::parentList(const QStringList &originalList) +{ + const int count = originalList.length(); + QVector<EditorSceneItem *> itemList(count); + QVector<bool> skipList(count); + + for (int i = 0; i < count; ++i) { + itemList[i] = editorSceneItemFromIndex(getModelIndexByName(originalList.at(i))); + skipList[i] = false; + } + + QStringList prunedList; + prunedList.reserve(count); + for (int i = 0; i < count; ++i) { + bool pruned = false; + for (int j = count - 1; j >= 0; --j) { + if (i == j || skipList.at(j)) + continue; + if (EditorUtils::isDescendant(itemList.at(j), itemList.at(i))) { + pruned = true; + // We don't need to consider discovered descendants as ancestors in future. + skipList[i] = true; + break; + } + } + if (!pruned) + prunedList.append(originalList.at(i)); + } + + return prunedList; +} + bool EditorSceneItemModel::canReparent(EditorSceneItem *newParentItem, EditorSceneItem *movedItem) { diff --git a/editorlib/src/editorsceneitemmodel.h b/editorlib/src/editorsceneitemmodel.h index 00c6b61..924e736 100644 --- a/editorlib/src/editorsceneitemmodel.h +++ b/editorlib/src/editorsceneitemmodel.h @@ -83,6 +83,7 @@ public: EditorSceneItem *getItemByName(const QString &entityName); QString generateValidName(const QString &desiredName, const Qt3DCore::QEntity *skipEntity); EditorScene *scene() { return m_scene; } + Q_INVOKABLE QStringList parentList(const QStringList &originalList); Q_INVOKABLE bool canReparent(EditorSceneItem *newParentItem, EditorSceneItem *movedItem); void reparentEntity(const QModelIndex &newParentIndex, const QModelIndex &entityIndex); Q_INVOKABLE void addExpandedItem(const QModelIndex &index); |