From 0918a42060afd91c69f4ab8b8f2c0259d552d1ca Mon Sep 17 00:00:00 2001 From: dnk-88 Date: Tue, 16 Aug 2011 22:30:45 +0300 Subject: [PATCH] Fixed: #1302 Fixed crash program(LoadRootPrimitiveCommand and AddPrimitiveByClassCommand do not work with selection model, and edit points mode does not work with mouse panning). --HG-- branch : gsoc2011-worldeditorqt --- .../plugins/world_editor/primitives_view.cpp | 4 ++-- .../world_editor/world_editor_actions.cpp | 23 ++++++++++++------- .../world_editor/world_editor_actions.h | 8 +++++-- .../world_editor/world_editor_scene.cpp | 3 +++ .../world_editor/world_editor_window.cpp | 5 ++-- 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitives_view.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitives_view.cpp index 6620411ca..ca329b25b 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitives_view.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/world_editor/primitives_view.cpp @@ -135,7 +135,7 @@ void PrimitivesView::loadRootPrimitive() Q_FOREACH(QString fileName, fileNames) { m_lastDir = QFileInfo(fileName).absolutePath(); - m_undoStack->push(new LoadRootPrimitiveCommand(fileName, m_worldEditorScene, m_primitivesTreeModel)); + m_undoStack->push(new LoadRootPrimitiveCommand(fileName, m_worldEditorScene, m_primitivesTreeModel, this)); } if (fileNames.count() > 1) @@ -258,7 +258,7 @@ void PrimitivesView::addNewPrimitiveByClass(int value) QString className = node->primitiveClass()->DynamicChildren[value].ClassName.c_str(); m_undoStack->push(new AddPrimitiveByClassCommand(className, m_primitivesTreeModel->pathFromIndex(indexList.first()), - m_worldEditorScene, m_primitivesTreeModel)); + m_worldEditorScene, m_primitivesTreeModel, this)); } void PrimitivesView::generatePrimitives(int value) 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 eb1921596..9a70cebe6 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 @@ -189,9 +189,10 @@ void removeGraphicsItems(const QModelIndex &primIndex, PrimitivesTreeModel *mode { QGraphicsItem *item = getGraphicsItem(node); if (item != 0) + { + delete qvariant_cast(item->data(Constants::NODE_PERISTENT_INDEX)); scene->removeWorldItem(item); - - delete qvariant_cast(item->data(Constants::NODE_PERISTENT_INDEX)); + } } int count = model->rowCount(primIndex); @@ -350,11 +351,12 @@ void CreateRootPrimitiveCommand::redo() LoadRootPrimitiveCommand::LoadRootPrimitiveCommand(const QString &fileName, WorldEditorScene *scene, - PrimitivesTreeModel *model, QUndoCommand *parent) + PrimitivesTreeModel *model, QTreeView *view, QUndoCommand *parent) : QUndoCommand(parent), m_fileName(fileName), m_scene(scene), - m_model(model) + m_model(model), + m_view(view) { setText("Load primitive file"); } @@ -368,6 +370,8 @@ void LoadRootPrimitiveCommand::undo() // Disable edit points mode m_scene->setEnabledEditPoints(false); + m_view->selectionModel()->clearSelection(); + QModelIndex index = m_model->pathToIndex(m_rootPrimIndex); removeGraphicsItems(index, m_model, m_scene); @@ -409,19 +413,20 @@ void LoadRootPrimitiveCommand::redo() } AddPrimitiveByClassCommand::AddPrimitiveByClassCommand(const QString &className, const Path &parentIndex, - WorldEditorScene *scene, PrimitivesTreeModel *model, QUndoCommand *parent) + WorldEditorScene *scene, PrimitivesTreeModel *model, QTreeView *view, QUndoCommand *parent) : QUndoCommand(parent), m_className(className), m_parentIndex(parentIndex), m_scene(scene), - m_model(model) + m_model(model), + m_view(view) { setText(QString("Add %1").arg(m_className)); - QGraphicsView *view = m_scene->views().first(); + QGraphicsView *graphicsView = m_scene->views().first(); // TODO: returns incorrect position when zoom in - QRectF visibleArea = view->mapToScene(view->rect()).boundingRect(); + QRectF visibleArea = graphicsView->mapToScene(view->rect()).boundingRect(); m_delta = visibleArea.height() / 10.0; m_initPos = visibleArea.center(); } @@ -434,6 +439,8 @@ void AddPrimitiveByClassCommand::undo() { m_scene->setEnabledEditPoints(false); + m_view->selectionModel()->clearSelection(); + QModelIndex index = m_model->pathToIndex(m_newPrimIndex); PrimitiveNode *node = static_cast(index.internalPointer()); 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 8aae8b8dd..ad66d0e3d 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 @@ -25,6 +25,7 @@ // Qt includes #include #include +#include #include #include @@ -121,7 +122,8 @@ class LoadRootPrimitiveCommand: public QUndoCommand { public: LoadRootPrimitiveCommand(const QString &fileName, WorldEditorScene *scene, - PrimitivesTreeModel *model, QUndoCommand *parent = 0); + PrimitivesTreeModel *model, QTreeView *view, + QUndoCommand *parent = 0); virtual ~LoadRootPrimitiveCommand(); virtual void undo(); @@ -132,6 +134,7 @@ private: const QString m_fileName; WorldEditorScene *const m_scene; PrimitivesTreeModel *const m_model; + QTreeView *m_view; }; /** @@ -144,7 +147,7 @@ class AddPrimitiveByClassCommand: public QUndoCommand public: AddPrimitiveByClassCommand(const QString &className, const Path &parentIndex, WorldEditorScene *scene, PrimitivesTreeModel *model, - QUndoCommand *parent = 0); + QTreeView *view, QUndoCommand *parent = 0); virtual ~AddPrimitiveByClassCommand(); virtual void undo(); @@ -157,6 +160,7 @@ private: Path m_parentIndex, m_newPrimIndex; WorldEditorScene *m_scene; PrimitivesTreeModel *m_model; + QTreeView *m_view; }; /** 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 356f6589a..967f6651d 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 @@ -369,6 +369,9 @@ void WorldEditorScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) void WorldEditorScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) { + if (mouseEvent->button() == Qt::MidButton) + return; + if (m_pointsMode) { if (mouseEvent->button() == Qt::LeftButton) 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 97d99f82c..2df27d7c7 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 @@ -193,7 +193,8 @@ void WorldEditorWindow::loadWorldEditFile(const QString &fileName) m_undoStack->push(new LoadLandscapeCommand(QString(worldEditList[i].second.c_str()), m_primitivesModel, m_zoneBuilderBase)); break; case Utils::PrimitiveType: - m_undoStack->push(new LoadRootPrimitiveCommand(QString(worldEditList[i].second.c_str()), m_worldEditorScene, m_primitivesModel)); + m_undoStack->push(new LoadRootPrimitiveCommand(QString(worldEditList[i].second.c_str()), + m_worldEditorScene, m_primitivesModel, m_ui.treePrimitivesView)); break; }; } @@ -383,7 +384,7 @@ void WorldEditorWindow::readSettings() restoreGeometry(settings->value(Constants::WORLD_WINDOW_GEOMETRY).toByteArray()); // Use OpenGL graphics system instead raster graphics system - if (settings->value(Constants::WORLD_EDITOR_USE_OPENGL, true).toBool()) + if (settings->value(Constants::WORLD_EDITOR_USE_OPENGL, false).toBool()) { m_oglWidget = new QGLWidget(QGLFormat(QGL::DoubleBuffer)); m_ui.graphicsView->setViewport(m_oglWidget);