1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-20 17:53:53 +00:00
openmw/apps/opencs/view/render/pathgridselectionmode.cpp
2022-10-09 16:44:18 +02:00

69 lines
2.4 KiB
C++

#include "pathgridselectionmode.hpp"
#include <QAction>
#include <QMenu>
#include "../../model/world/commandmacro.hpp"
#include "pathgrid.hpp"
#include "worldspacewidget.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, &QAction::triggered, this, &PathgridSelectionMode::removeSelectedNodes);
connect(mRemoveSelectedEdges, &QAction::triggered, this, &PathgridSelectionMode::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);
}
}
}
}