From ab239ee13a8510601b0122b77519716d9b44f20c Mon Sep 17 00:00:00 2001 From: dnk-88 Date: Tue, 16 Aug 2011 21:18:10 +0300 Subject: [PATCH] Changed: #1302 When selecting graphics items in scene will be selected the appropriate primitives in the primitives dialog. --- .../plugins/world_editor/primitives_model.cpp | 2 +- .../world_editor/world_editor_actions.cpp | 8 +++++ .../world_editor/world_editor_actions.h | 4 +++ .../world_editor/world_editor_scene.cpp | 5 +++ .../plugins/world_editor/world_editor_scene.h | 2 +- .../world_editor/world_editor_window.cpp | 33 +++++++++++++++++++ .../world_editor/world_editor_window.h | 1 + 7 files changed, 53 insertions(+), 2 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitives_model.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitives_model.cpp index 9e689066a..690e7db08 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitives_model.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitives_model.cpp @@ -155,7 +155,7 @@ Path PrimitivesTreeModel::pathFromNode(Node *node) Path path; while(iter != 0) { - path.prepend(PathItem(iter->row(), 1)); + path.prepend(PathItem(iter->row(), 0)); iter = iter->parent(); } return path; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_actions.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_actions.cpp index 2e538748c..eb1921596 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_actions.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_actions.cpp @@ -167,6 +167,11 @@ void addNewGraphicsItems(const QModelIndex &primIndex, PrimitivesTreeModel *mode QVariant graphicsData; graphicsData.setValue(item); node->setData(Constants::GRAPHICS_DATA_QT4_2D, graphicsData); + + QVariant persistenVariant; + QPersistentModelIndex *persistentIndex = new QPersistentModelIndex(primIndex); + persistenVariant.setValue(persistentIndex); + item->setData(Constants::NODE_PERISTENT_INDEX, persistenVariant); } int count = model->rowCount(primIndex); @@ -185,6 +190,8 @@ void removeGraphicsItems(const QModelIndex &primIndex, PrimitivesTreeModel *mode QGraphicsItem *item = getGraphicsItem(node); if (item != 0) scene->removeWorldItem(item); + + delete qvariant_cast(item->data(Constants::NODE_PERISTENT_INDEX)); } int count = model->rowCount(primIndex); @@ -358,6 +365,7 @@ LoadRootPrimitiveCommand::~LoadRootPrimitiveCommand() void LoadRootPrimitiveCommand::undo() { + // Disable edit points mode m_scene->setEnabledEditPoints(false); QModelIndex index = m_model->pathToIndex(m_rootPrimIndex); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_actions.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_actions.h index 1c77a4ba5..8aae8b8dd 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_actions.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_actions.h @@ -26,6 +26,7 @@ #include #include #include +#include namespace LandscapeEditor { @@ -283,4 +284,7 @@ private: } /* namespace WorldEditor */ +// Enable the use of QVariant with this class. +Q_DECLARE_METATYPE(QPersistentModelIndex *) + #endif // WORLD_EDITOR_ACTIONS_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene.cpp index 749392631..356f6589a 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene.cpp @@ -459,6 +459,9 @@ void WorldEditorScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) m_selectedItems.push_back(item); } + + Q_EMIT updateSelectedItems(m_selectedItems); + updateSelectedWorldItems(true); m_selectionArea = QRectF(); update(); @@ -556,6 +559,8 @@ void WorldEditorScene::updatePickSelection(const QPointF &point) m_selectedItems.push_back(worldItemsItems.at(m_lastPickedPrimitive)); updateSelectedWorldItems(true); } + + Q_EMIT updateSelectedItems(m_selectedItems); } void WorldEditorScene::updatePickSelectionPoints(const QPointF &point) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene.h index adf491889..c9da223a7 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_scene.h @@ -68,7 +68,7 @@ public: bool isEnabledEditPoints() const; Q_SIGNALS: - void selectionUpdated(const QList &selected, const QList &deselected); + void updateSelectedItems(const QList &selected); public Q_SLOTS: void setEnabledEditPoints(bool enabled); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_window.cpp index 009ede2e1..97d99f82c 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_window.cpp @@ -39,6 +39,7 @@ #include #include #include +#include namespace WorldEditor { @@ -108,6 +109,9 @@ WorldEditorWindow::WorldEditorWindow(QWidget *parent) connect(m_ui.treePrimitivesView->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(updateSelection(QItemSelection, QItemSelection))); + connect(m_worldEditorScene, SIGNAL(updateSelectedItems(QList)), + this, SLOT(selectedItemsInScene(QList))); + m_statusBarTimer = new QTimer(this); connect(m_statusBarTimer, SIGNAL(timeout()), this, SLOT(updateStatusBar())); @@ -295,6 +299,35 @@ void WorldEditorWindow::updateSelection(const QItemSelection &selected, const QI m_worldEditorScene->updateSelection(itemSelected, itemDeselected); } +void WorldEditorWindow::selectedItemsInScene(const QList &selected) +{ + QItemSelectionModel *selectionModel = m_ui.treePrimitivesView->selectionModel(); + disconnect(m_ui.treePrimitivesView->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), + this, SLOT(updateSelection(QItemSelection, QItemSelection))); + + selectionModel->clear(); + QItemSelection itemSelection; + Q_FOREACH(QGraphicsItem *item, selected) + { + QPersistentModelIndex *index = qvariant_cast(item->data(Constants::NODE_PERISTENT_INDEX)); + if (index->isValid()) + { + QModelIndex modelIndex = index->operator const QModelIndex &(); + QItemSelection mergeItemSelection(modelIndex, modelIndex); + itemSelection.merge(mergeItemSelection, QItemSelectionModel::Select); + } + QApplication::processEvents(); + } + + selectionModel->select(itemSelection, QItemSelectionModel::Select); + + // TODO: update property editor + // ... + + connect(m_ui.treePrimitivesView->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), + this, SLOT(updateSelection(QItemSelection, QItemSelection))); +} + void WorldEditorWindow::showEvent(QShowEvent *showEvent) { QMainWindow::showEvent(showEvent); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_window.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_window.h index 5844489f6..d6e3dd593 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_window.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/world_editor_window.h @@ -61,6 +61,7 @@ private Q_SLOTS: void updateStatusBar(); void updateSelection(const QItemSelection &selected, const QItemSelection &deselected); + void selectedItemsInScene(const QList &selected); protected: virtual void showEvent(QShowEvent *showEvent);