summaryrefslogtreecommitdiffstats
path: root/editorlib/src/editorscene.cpp
diff options
context:
space:
mode:
authorTomi Korpipää <tomi.korpipaa@theqtcompany.com>2016-05-31 14:01:05 +0300
committerTomi Korpipää <tomi.korpipaa@theqtcompany.com>2016-05-31 11:13:11 +0000
commit731ff9eb491f2f0761354d43481589780e42a74e (patch)
treee7cfe316a68cf69e2db540cadf7550b8064b04a8 /editorlib/src/editorscene.cpp
parent66f40c8c6b97d04e6c69a1137072b96b7e02c7a3 (diff)
Multiselection support in tree view
Change-Id: Ic8ff4247465be9ef8418c798922bc9517ae2b296 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Diffstat (limited to 'editorlib/src/editorscene.cpp')
-rw-r--r--editorlib/src/editorscene.cpp75
1 files changed, 43 insertions, 32 deletions
diff --git a/editorlib/src/editorscene.cpp b/editorlib/src/editorscene.cpp
index 60f0cb6..9e6f2b3 100644
--- a/editorlib/src/editorscene.cpp
+++ b/editorlib/src/editorscene.cpp
@@ -116,6 +116,7 @@ EditorScene::EditorScene(QObject *parent)
, m_duplicateCount(0)
, m_previousDuplicate(nullptr)
, m_multiSelect(false)
+ , m_previousSelectedEntity(nullptr)
{
retranslateUi();
createRootEntity();
@@ -1667,6 +1668,11 @@ void EditorScene::setSelection(Qt3DCore::QEntity *entity)
m_selectedEntityTransform = EditorUtils::entityTransform(m_selectedEntity);
}
+ if (!m_multiSelect && m_selectedEntity != m_rootEntity)
+ m_previousSelectedEntity = m_selectedEntity;
+ else
+ m_previousSelectedEntity = nullptr;
+
// Emit signal to highlight the entity from the list
emit selectionChanged(m_selectedEntity);
}
@@ -1676,7 +1682,7 @@ void EditorScene::setSelection(Qt3DCore::QEntity *entity)
// Disable scale handles for cameras
m_dragHandleScaleTransform->setEnabled(false);
m_dragHandleRotateTransform->setEnabled(!isPropertyLocked(QStringLiteral("upVector"),
- m_selectedEntity));
+ m_selectedEntity));
m_dragHandleTranslateTransform->setEnabled(
!isPropertyLocked(QStringLiteral("position"), m_selectedEntity));
m_viewCenterLocked = isPropertyLocked(QStringLiteral("viewCenter"), m_selectedEntity);
@@ -1710,9 +1716,9 @@ void EditorScene::setSelection(Qt3DCore::QEntity *entity)
m_dragHandleRotateTransform->setEnabled(false);
} else {
m_dragHandleScaleTransform->setEnabled(!isPropertyLocked(QStringLiteral("scale3D"),
- transform));
+ transform));
m_dragHandleRotateTransform->setEnabled(!isPropertyLocked(QStringLiteral("rotation"),
- transform));
+ transform));
}
}
}
@@ -1724,14 +1730,17 @@ void EditorScene::setSelection(Qt3DCore::QEntity *entity)
}
}
+QString EditorScene::previousSelectedEntityName() const {
+ if (m_previousSelectedEntity)
+ return m_previousSelectedEntity->objectName();
+ else
+ return QString();
+}
+
void EditorScene::setMultiSelection(const QStringList &multiSelection)
{
- if (m_selectedEntityNameList != multiSelection) {
+ if (m_selectedEntityNameList != multiSelection)
m_selectedEntityNameList = multiSelection;
- // TODO: Update selection box
- // TODO: Do something else?
- emit multiSelectionChanged(m_selectedEntityNameList);
- }
}
QStringList EditorScene::multiSelection()
@@ -1739,6 +1748,26 @@ QStringList EditorScene::multiSelection()
return m_selectedEntityNameList;
}
+void EditorScene::addToMultiSelection(const QString &name)
+{
+ QStringList oldList = m_selectedEntityNameList;
+ // TODO: Highlight selected entities somehow?
+ // Add previously selected one, if different than new one and other than scene root.
+ if (m_selectedEntityNameList.isEmpty() && m_pickedEntity != m_selectedEntity
+ && m_selectedEntity != m_sceneEntity) {
+ m_selectedEntityNameList.append(previousSelectedEntityName());
+ }
+ // If the new one is already in, remove it. Otherwise add it.
+ if (!m_selectedEntityNameList.contains(name))
+ m_selectedEntityNameList.append(name);
+ else
+ m_selectedEntityNameList.removeOne(name);
+
+ // Emit multiselection list if it changed
+ if (oldList != m_selectedEntityNameList)
+ emit multiSelectionChanged(m_selectedEntityNameList);
+}
+
void EditorScene::setActiveSceneCameraIndex(int index)
{
int previousIndex = m_activeSceneCameraIndex;
@@ -1824,30 +1853,12 @@ void EditorScene::endSelectionHandling()
{
if (m_dragMode == DragNone && m_pickedEntity) {
// Multiselection handling
- QStringList oldList = m_selectedEntityNameList;
- // TODO: Why does selection box disappear when selecting more than one entity?
- if (m_multiSelect) {
- // Add previously selected one, if different than new one and other than scene root.
- if (m_selectedEntityNameList.isEmpty() && m_pickedEntity != m_selectedEntity
- && m_selectedEntity != m_sceneEntity) {
- m_selectedEntityNameList.append(m_selectedEntity->objectName());
- }
- // If the new one is already in, remove it. Otherwise add it.
- if (m_pickedEntity) {
- if (!m_selectedEntityNameList.contains(m_pickedEntity->objectName()))
- m_selectedEntityNameList.append(m_pickedEntity->objectName());
- else
- m_selectedEntityNameList.removeOne(m_pickedEntity->objectName());
- }
- } else {
+ if (m_multiSelect)
+ addToMultiSelection(m_pickedEntity->objectName());
+ else
m_selectedEntityNameList.clear();
- }
-
- if (oldList != m_selectedEntityNameList) {
- // Emit multiselection list
- emit multiSelectionChanged(m_selectedEntityNameList);
- }
+ // Selection handling
if (m_multiSelect && m_selectedEntityNameList.isEmpty())
setSelection(m_sceneEntity);
else
@@ -2053,8 +2064,8 @@ bool EditorScene::handleMouseRelease(QMouseEvent *event)
{
if (event->button() == Qt::RightButton) {
if (m_dragMode == DragNone || m_ignoringInitialDrag) {
- emit mouseRightButtonReleasedWithoutDragging(m_multiSelect
- && m_selectedEntityNameList.count() > 1);
+ emit mouseRightButtonReleasedWithoutDragging(m_multiSelect
+ && m_selectedEntityNameList.count() > 1);
}
}
cancelDrag();