Share selection functionality with instance editing mode.

coverity_scan^2
Aesylwinn 9 years ago
parent ae0d2c3b9c
commit e8e915bcde

@ -86,7 +86,7 @@ opencs_units (view/widget
opencs_units (view/render opencs_units (view/render
scenewidget worldspacewidget pagedworldspacewidget unpagedworldspacewidget scenewidget worldspacewidget pagedworldspacewidget unpagedworldspacewidget
previewwidget editmode instancemode instanceselectionmode instancemovemode previewwidget editmode instancemode instanceselectionmode instancemovemode
orbitcameramode pathgridmode orbitcameramode pathgridmode selectionmode pathgridselectionmode
) )
opencs_units_noqt (view/render opencs_units_noqt (view/render

@ -1,4 +1,3 @@
#include "instanceselectionmode.hpp" #include "instanceselectionmode.hpp"
#include <QMenu> #include <QMenu>
@ -10,84 +9,49 @@
#include "worldspacewidget.hpp" #include "worldspacewidget.hpp"
#include "object.hpp" #include "object.hpp"
bool CSVRender::InstanceSelectionMode::createContextMenu (QMenu *menu) namespace CSVRender
{ {
if (menu) InstanceSelectionMode::InstanceSelectionMode(CSVWidget::SceneToolbar* parent, WorldspaceWidget& worldspaceWidget)
: SelectionMode(parent, worldspaceWidget, Mask_Reference)
{ {
menu->addAction (mSelectAll); mSelectSame = new QAction("Extend selection to instances with same object ID", this);
menu->addAction (mDeselectAll); mDeleteSelection = new QAction("Delete selected instances", this);
menu->addAction (mSelectSame);
menu->addAction (mDeleteSelection);
}
return true; connect(mSelectSame, SIGNAL(triggered()), this, SLOT(selectSame()));
} connect(mDeleteSelection, SIGNAL(triggered()), this, SLOT(deleteSelection()));
}
CSVRender::InstanceSelectionMode::InstanceSelectionMode (CSVWidget::SceneToolbar *parent, bool InstanceSelectionMode::createContextMenu(QMenu* menu)
WorldspaceWidget& worldspaceWidget) {
: CSVWidget::SceneToolMode (parent, "Selection Mode"), mWorldspaceWidget (worldspaceWidget) if (menu)
{ {
addButton (":placeholder", "cube-centre", SelectionMode::createContextMenu(menu);
"Centred cube"
"<ul><li>Drag with primary (make instances the selection) or secondary (invert selection state) select button from the centre of the selection cube outwards</li>"
"<li>The selection cube is aligned to the word space axis</li>"
"<li>If context selection mode is enabled, a drag with primary/secondary edit not starting on an instance will have the same effect</li>"
"</ul>"
"<font color=Red>Not implemented yet</font color>");
addButton (":placeholder", "cube-corner",
"Cube corner to corner"
"<ul><li>Drag with primary (make instances the selection) or secondary (invert selection state) select button from one corner of the selection cube to the opposite corner</li>"
"<li>The selection cube is aligned to the word space axis</li>"
"<li>If context selection mode is enabled, a drag with primary/secondary edit not starting on an instance will have the same effect</li>"
"</ul>"
"<font color=Red>Not implemented yet</font color>");
addButton (":placeholder", "sphere",
"Centred sphere"
"<ul><li>Drag with primary (make instances the selection) or secondary (invert selection state) select button from the centre of the selection sphere outwards</li>"
"<li>If context selection mode is enabled, a drag with primary/secondary edit not starting on an instance will have the same effect</li>"
"</ul>"
"<font color=Red>Not implemented yet</font color>");
mSelectAll = new QAction ("Select all instances", this); menu->addAction(mSelectSame);
mDeselectAll = new QAction ("Clear selection", this); menu->addAction(mDeleteSelection);
mDeleteSelection = new QAction ("Delete selected instances", this); }
mSelectSame = new QAction ("Extend selection to instances with same object ID", this);
connect (mSelectAll, SIGNAL (triggered ()), this, SLOT (selectAll()));
connect (mDeselectAll, SIGNAL (triggered ()), this, SLOT (clearSelection()));
connect (mDeleteSelection, SIGNAL (triggered ()), this, SLOT (deleteSelection()));
connect (mSelectSame, SIGNAL (triggered ()), this, SLOT (selectSame()));
}
void CSVRender::InstanceSelectionMode::selectAll() return true;
{ }
mWorldspaceWidget.selectAll (Mask_Reference);
}
void CSVRender::InstanceSelectionMode::clearSelection() void InstanceSelectionMode::selectSame()
{ {
mWorldspaceWidget.clearSelection (Mask_Reference); getWorldspaceWidget().selectAllWithSameParentId(Mask_Reference);
} }
void CSVRender::InstanceSelectionMode::deleteSelection() void InstanceSelectionMode::deleteSelection()
{ {
std::vector<osg::ref_ptr<TagBase> > selection = std::vector<osg::ref_ptr<TagBase> > selection = getWorldspaceWidget().getSelection(Mask_Reference);
mWorldspaceWidget.getSelection (Mask_Reference);
CSMWorld::IdTable& referencesTable = CSMWorld::IdTable& referencesTable = dynamic_cast<CSMWorld::IdTable&>(
dynamic_cast<CSMWorld::IdTable&> (*mWorldspaceWidget.getDocument().getData(). *getWorldspaceWidget().getDocument().getData().getTableModel(CSMWorld::UniversalId::Type_References));
getTableModel (CSMWorld::UniversalId::Type_References));
for (std::vector<osg::ref_ptr<TagBase> >::iterator iter (selection.begin()); for (std::vector<osg::ref_ptr<TagBase> >::iterator iter = selection.begin(); iter != selection.end(); ++iter)
iter!=selection.end(); ++iter)
{ {
CSMWorld::DeleteCommand *command = new CSMWorld::DeleteCommand (referencesTable, CSMWorld::DeleteCommand* command = new CSMWorld::DeleteCommand(referencesTable,
static_cast<ObjectTag *> (iter->get())->mObject->getReferenceId()); static_cast<ObjectTag*>(iter->get())->mObject->getReferenceId());
mWorldspaceWidget.getDocument().getUndoStack().push (command); getWorldspaceWidget().getDocument().getUndoStack().push(command);
}
} }
}
void CSVRender::InstanceSelectionMode::selectSame()
{
mWorldspaceWidget.selectAllWithSameParentId (Mask_Reference);
} }

@ -1,23 +1,19 @@
#ifndef CSV_RENDER_INSTANCE_SELECTION_MODE_H #ifndef CSV_RENDER_INSTANCE_SELECTION_MODE_H
#define CSV_RENDER_INSTANCE_SELECTION_MODE_H #define CSV_RENDER_INSTANCE_SELECTION_MODE_H
#include "../widget/scenetoolmode.hpp" #include "selectionmode.hpp"
class QAction;
namespace CSVRender namespace CSVRender
{ {
class WorldspaceWidget; class InstanceSelectionMode : public SelectionMode
class InstanceSelectionMode : public CSVWidget::SceneToolMode
{ {
Q_OBJECT Q_OBJECT
WorldspaceWidget& mWorldspaceWidget; public:
QAction *mSelectAll;
QAction *mDeselectAll; InstanceSelectionMode(CSVWidget::SceneToolbar* parent, WorldspaceWidget& worldspaceWidget);
QAction *mDeleteSelection;
QAction *mSelectSame; protected:
/// Add context menu items to \a menu. /// Add context menu items to \a menu.
/// ///
@ -25,20 +21,16 @@ namespace CSVRender
/// ///
/// \return Have there been any menu items to be added (if menu is 0 and there /// \return Have there been any menu items to be added (if menu is 0 and there
/// items to be added, the function must return true anyway. /// items to be added, the function must return true anyway.
virtual bool createContextMenu (QMenu *menu); bool createContextMenu(QMenu* menu);
public: private:
InstanceSelectionMode (CSVWidget::SceneToolbar *parent, WorldspaceWidget& worldspaceWidget); QAction* mDeleteSelection;
QAction* mSelectSame;
private slots: private slots:
void selectAll();
void clearSelection();
void deleteSelection(); void deleteSelection();
void selectSame(); void selectSame();
}; };
} }

@ -10,9 +10,12 @@
#include "../../model/world/idtable.hpp" #include "../../model/world/idtable.hpp"
#include "../../model/world/idtree.hpp" #include "../../model/world/idtree.hpp"
#include "../widget/scenetoolbar.hpp"
#include "cell.hpp" #include "cell.hpp"
#include "mask.hpp" #include "mask.hpp"
#include "pathgrid.hpp" #include "pathgrid.hpp"
#include "pathgridselectionmode.hpp"
#include "worldspacewidget.hpp" #include "worldspacewidget.hpp"
namespace CSVRender namespace CSVRender
@ -22,6 +25,7 @@ namespace CSVRender
getTooltip(), parent) getTooltip(), parent)
, mDragMode(DragMode_None) , mDragMode(DragMode_None)
, mFromNode(0) , mFromNode(0)
, mSelectionMode(0)
{ {
} }
@ -39,33 +43,13 @@ namespace CSVRender
void PathgridMode::activate(CSVWidget::SceneToolbar* toolbar) void PathgridMode::activate(CSVWidget::SceneToolbar* toolbar)
{ {
mSelectAll = new QAction("Select all other nodes in cell", this); if (!mSelectionMode)
mInvertSelection = new QAction("Invert selection", this);
mClearSelection = new QAction("Clear selection", this);
mRemoveSelected = new QAction("Remove selected nodes", this);
mRemoveSelectedEdges = new QAction("Remove edges between selected nodes", this);
connect(mSelectAll, SIGNAL(triggered()), this, SLOT(selectAll()));
connect(mInvertSelection, SIGNAL(triggered()), this, SLOT(invertSelection()));
connect(mClearSelection, SIGNAL(triggered()), this, SLOT(clearSelection()));
connect(mRemoveSelected, SIGNAL(triggered()), this, SLOT(removeSelected()));
connect(mRemoveSelectedEdges, SIGNAL(triggered()), this, SLOT(removeSelectedEdges()));
EditMode::activate(toolbar);
}
bool PathgridMode::createContextMenu(QMenu* menu)
{
if (menu)
{ {
menu->addAction(mSelectAll); mSelectionMode = new PathgridSelectionMode(toolbar, getWorldspaceWidget());
menu->addAction(mInvertSelection);
menu->addAction(mClearSelection);
menu->addAction(mRemoveSelected);
menu->addAction(mRemoveSelectedEdges);
} }
return true; EditMode::activate(toolbar);
toolbar->addTool(mSelectionMode);
} }
void PathgridMode::primaryEditPressed(const WorldspaceHitResult& hitResult) void PathgridMode::primaryEditPressed(const WorldspaceHitResult& hitResult)
@ -245,54 +229,4 @@ namespace CSVRender
{ {
getWorldspaceWidget().reset(Mask_Pathgrid); getWorldspaceWidget().reset(Mask_Pathgrid);
} }
void PathgridMode::selectAll()
{
// Select rest of nodes in selected cell
getWorldspaceWidget().selectAll(Mask_Pathgrid);
}
void PathgridMode::invertSelection()
{
getWorldspaceWidget().invertSelection(Mask_Pathgrid);
}
void PathgridMode::clearSelection()
{
getWorldspaceWidget().clearSelection(Mask_Pathgrid);
}
void PathgridMode::removeSelected()
{
std::vector<osg::ref_ptr<TagBase> > selection = getWorldspaceWidget().getSelection (Mask_Pathgrid);
for (std::vector<osg::ref_ptr<TagBase> >::iterator it = selection.begin(); it != selection.end(); ++it)
{
if (PathgridTag* tag = dynamic_cast<PathgridTag*>(it->get()))
{
QUndoStack& undoStack = getWorldspaceWidget().getDocument().getUndoStack();
QString description = "Remove selected nodes";
CSMWorld::CommandMacro macro(undoStack, description);
tag->getPathgrid()->applyRemoveNodes(macro);
}
}
}
void PathgridMode::removeSelectedEdges()
{
std::vector<osg::ref_ptr<TagBase> > selection = getWorldspaceWidget().getSelection (Mask_Pathgrid);
for (std::vector<osg::ref_ptr<TagBase> >::iterator it = selection.begin(); it != selection.end(); ++it)
{
if (PathgridTag* tag = dynamic_cast<PathgridTag*>(it->get()))
{
QUndoStack& undoStack = getWorldspaceWidget().getDocument().getUndoStack();
QString description = "Remove edges between selected nodes";
CSMWorld::CommandMacro macro(undoStack, description);
tag->getPathgrid()->applyRemoveEdges(macro);
}
}
}
} }

@ -7,6 +7,8 @@
namespace CSVRender namespace CSVRender
{ {
class PathgridSelectionMode;
class PathgridMode : public EditMode class PathgridMode : public EditMode
{ {
Q_OBJECT Q_OBJECT
@ -17,8 +19,6 @@ namespace CSVRender
virtual void activate(CSVWidget::SceneToolbar* toolbar); virtual void activate(CSVWidget::SceneToolbar* toolbar);
virtual bool createContextMenu(QMenu* menu);
virtual void primaryEditPressed(const WorldspaceHitResult& hit); virtual void primaryEditPressed(const WorldspaceHitResult& hit);
virtual void secondaryEditPressed(const WorldspaceHitResult& hit); virtual void secondaryEditPressed(const WorldspaceHitResult& hit);
@ -52,21 +52,9 @@ namespace CSVRender
std::string mLastId, mEdgeId; std::string mLastId, mEdgeId;
unsigned short mFromNode; unsigned short mFromNode;
QAction* mSelectAll; PathgridSelectionMode* mSelectionMode;
QAction* mInvertSelection;
QAction* mClearSelection;
QAction* mRemoveSelected;
QAction* mRemoveSelectedEdges;
QString getTooltip(); QString getTooltip();
private slots:
void selectAll();
void invertSelection();
void clearSelection();
void removeSelected();
void removeSelectedEdges();
}; };
} }

@ -0,0 +1,71 @@
#include "pathgridselectionmode.hpp"
#include <QMenu>
#include <QAction>
#include "../../model/world/idtable.hpp"
#include "../../model/world/commands.hpp"
#include "../../model/world/commandmacro.hpp"
#include "worldspacewidget.hpp"
#include "pathgrid.hpp"
namespace CSVRender
{
PathgridSelectionMode::PathgridSelectionMode(CSVWidget::SceneToolbar* parent, WorldspaceWidget& worldspaceWidget)
: SelectionMode(parent, worldspaceWidget, Mask_Pathgrid)
{
mRemoveSelectedNodes = new QAction("Remove selected nodes", this);
mRemoveSelectedEdges = new QAction("Remove edges between selected nodes", this);
connect(mRemoveSelectedNodes, SIGNAL(triggered()), this, SLOT(removeSelectedNodes()));
connect(mRemoveSelectedEdges, SIGNAL(triggered()), this, SLOT(removeSelectedEdges()));
}
bool PathgridSelectionMode::createContextMenu(QMenu* menu)
{
if (menu)
{
SelectionMode::createContextMenu(menu);
menu->addAction(mRemoveSelectedNodes);
menu->addAction(mRemoveSelectedEdges);
}
return true;
}
void PathgridSelectionMode::removeSelectedNodes()
{
std::vector<osg::ref_ptr<TagBase> > selection = getWorldspaceWidget().getSelection (Mask_Pathgrid);
for (std::vector<osg::ref_ptr<TagBase> >::iterator it = selection.begin(); it != selection.end(); ++it)
{
if (PathgridTag* tag = dynamic_cast<PathgridTag*>(it->get()))
{
QUndoStack& undoStack = getWorldspaceWidget().getDocument().getUndoStack();
QString description = "Remove selected nodes";
CSMWorld::CommandMacro macro(undoStack, description);
tag->getPathgrid()->applyRemoveNodes(macro);
}
}
}
void PathgridSelectionMode::removeSelectedEdges()
{
std::vector<osg::ref_ptr<TagBase> > selection = getWorldspaceWidget().getSelection (Mask_Pathgrid);
for (std::vector<osg::ref_ptr<TagBase> >::iterator it = selection.begin(); it != selection.end(); ++it)
{
if (PathgridTag* tag = dynamic_cast<PathgridTag*>(it->get()))
{
QUndoStack& undoStack = getWorldspaceWidget().getDocument().getUndoStack();
QString description = "Remove edges between selected nodes";
CSMWorld::CommandMacro macro(undoStack, description);
tag->getPathgrid()->applyRemoveEdges(macro);
}
}
}
}

@ -0,0 +1,38 @@
#ifndef CSV_RENDER_PATHGRID_SELECTION_MODE_H
#define CSV_RENDER_PATHGRID_SELECTION_MODE_H
#include "selectionmode.hpp"
namespace CSVRender
{
class PathgridSelectionMode : public SelectionMode
{
Q_OBJECT
public:
PathgridSelectionMode(CSVWidget::SceneToolbar* parent, WorldspaceWidget& worldspaceWidget);
protected:
/// Add context menu items to \a menu.
///
/// \attention menu can be a 0-pointer
///
/// \return Have there been any menu items to be added (if menu is 0 and there
/// items to be added, the function must return true anyway.
bool createContextMenu(QMenu* menu);
private:
QAction* mRemoveSelectedNodes;
QAction* mRemoveSelectedEdges;
private slots:
void removeSelectedNodes();
void removeSelectedEdges();
};
}
#endif

@ -0,0 +1,77 @@
#include "selectionmode.hpp"
#include <QMenu>
#include <QAction>
#include "worldspacewidget.hpp"
namespace CSVRender
{
SelectionMode::SelectionMode(CSVWidget::SceneToolbar* parent, WorldspaceWidget& worldspaceWidget,
unsigned int interactionMask)
: SceneToolMode(parent, "Selection mode")
, mWorldspaceWidget(worldspaceWidget)
, mInteractionMask(interactionMask)
{
addButton(":placeholder", "cube-centre",
"Centred cube"
"<ul><li>Drag with primary (make instances the selection) or secondary (invert selection state) select button from the centre of the selection cube outwards</li>"
"<li>The selection cube is aligned to the word space axis</li>"
"<li>If context selection mode is enabled, a drag with primary/secondary edit not starting on an instance will have the same effect</li>"
"</ul>"
"<font color=Red>Not implemented yet</font color>");
addButton(":placeholder", "cube-corner",
"Cube corner to corner"
"<ul><li>Drag with primary (make instances the selection) or secondary (invert selection state) select button from one corner of the selection cube to the opposite corner</li>"
"<li>The selection cube is aligned to the word space axis</li>"
"<li>If context selection mode is enabled, a drag with primary/secondary edit not starting on an instance will have the same effect</li>"
"</ul>"
"<font color=Red>Not implemented yet</font color>");
addButton(":placeholder", "sphere",
"Centred sphere"
"<ul><li>Drag with primary (make instances the selection) or secondary (invert selection state) select button from the centre of the selection sphere outwards</li>"
"<li>If context selection mode is enabled, a drag with primary/secondary edit not starting on an instance will have the same effect</li>"
"</ul>"
"<font color=Red>Not implemented yet</font color>");
mSelectAll = new QAction("Select all", this);
mDeselectAll = new QAction("Clear selection", this);
mInvertSelection = new QAction("Invert selection", this);
connect(mSelectAll, SIGNAL(triggered()), this, SLOT(selectAll()));
connect(mDeselectAll, SIGNAL(triggered()), this, SLOT(clearSelection()));
connect(mInvertSelection, SIGNAL(triggered()), this, SLOT(invertSelection()));
}
WorldspaceWidget& SelectionMode::getWorldspaceWidget()
{
return mWorldspaceWidget;
}
bool SelectionMode::createContextMenu (QMenu* menu)
{
if (menu)
{
menu->addAction(mSelectAll);
menu->addAction(mDeselectAll);
menu->addAction(mInvertSelection);
}
return true;
}
void SelectionMode::selectAll()
{
getWorldspaceWidget().selectAll(mInteractionMask);
}
void SelectionMode::clearSelection()
{
getWorldspaceWidget().clearSelection(mInteractionMask);
}
void SelectionMode::invertSelection()
{
getWorldspaceWidget().invertSelection(mInteractionMask);
}
}

@ -0,0 +1,51 @@
#ifndef CSV_RENDER_SELECTION_MODE_H
#define CSV_RENDER_SELECTION_MODE_H
#include "../widget/scenetoolmode.hpp"
#include "mask.hpp"
class QAction;
namespace CSVRender
{
class WorldspaceWidget;
class SelectionMode : public CSVWidget::SceneToolMode
{
Q_OBJECT
public:
SelectionMode(CSVWidget::SceneToolbar* parent, WorldspaceWidget& worldspaceWidget,
unsigned int interactionMask);
protected:
WorldspaceWidget& getWorldspaceWidget();
/// Add context menu items to \a menu.
///
/// \attention menu can be a 0-pointer
///
/// \return Have there been any menu items to be added (if menu is 0 and there
/// items to be added, the function must return true anyway.
virtual bool createContextMenu (QMenu* menu);
private:
WorldspaceWidget& mWorldspaceWidget;
unsigned int mInteractionMask;
QAction* mSelectAll;
QAction* mDeselectAll;
QAction* mInvertSelection;
protected slots:
virtual void selectAll();
virtual void clearSelection();
virtual void invertSelection();
};
}
#endif
Loading…
Cancel
Save