added delete selection item to selection mode button menu

This commit is contained in:
Marc Zinnschlag 2016-01-25 14:55:02 +01:00
parent 45e6974266
commit c1f0aa7260
11 changed files with 85 additions and 0 deletions

View file

@ -276,3 +276,16 @@ bool CSVRender::Cell::isDeleted() const
{ {
return mDeleted; return mDeleted;
} }
std::vector<osg::ref_ptr<CSVRender::TagBase> > CSVRender::Cell::getSelection (unsigned int elementMask) const
{
std::vector<osg::ref_ptr<TagBase> > result;
if (elementMask & Mask_Reference)
for (std::map<std::string, Object *>::const_iterator iter (mObjects.begin());
iter!=mObjects.end(); ++iter)
if (iter->second->getSelected())
result.push_back (iter->second->getTag());
return result;
}

View file

@ -31,6 +31,8 @@ namespace CSMWorld
namespace CSVRender namespace CSVRender
{ {
class TagBase;
class Cell class Cell
{ {
CSMWorld::Data& mData; CSMWorld::Data& mData;
@ -99,6 +101,8 @@ namespace CSVRender
CSMWorld::CellCoordinates getCoordinates() const; CSMWorld::CellCoordinates getCoordinates() const;
bool isDeleted() const; bool isDeleted() const;
std::vector<osg::ref_ptr<TagBase> > getSelection (unsigned int elementMask) const;
}; };
} }

View file

@ -4,7 +4,11 @@
#include <QMenu> #include <QMenu>
#include <QAction> #include <QAction>
#include "../../model/world/idtable.hpp"
#include "../../model/world/commands.hpp"
#include "worldspacewidget.hpp" #include "worldspacewidget.hpp"
#include "object.hpp"
bool CSVRender::InstanceSelectionMode::createContextMenu (QMenu *menu) bool CSVRender::InstanceSelectionMode::createContextMenu (QMenu *menu)
{ {
@ -12,6 +16,7 @@ bool CSVRender::InstanceSelectionMode::createContextMenu (QMenu *menu)
{ {
menu->addAction (mSelectAll); menu->addAction (mSelectAll);
menu->addAction (mDeselectAll); menu->addAction (mDeselectAll);
menu->addAction (mDeleteSelection);
} }
return true; return true;
@ -44,9 +49,11 @@ CSVRender::InstanceSelectionMode::InstanceSelectionMode (CSVWidget::SceneToolbar
mSelectAll = new QAction ("Select all Instances", this); mSelectAll = new QAction ("Select all Instances", this);
mDeselectAll = new QAction ("Clear selection", this); mDeselectAll = new QAction ("Clear selection", this);
mDeleteSelection = new QAction ("Delete selection", this);
connect (mSelectAll, SIGNAL (triggered ()), this, SLOT (selectAll())); connect (mSelectAll, SIGNAL (triggered ()), this, SLOT (selectAll()));
connect (mDeselectAll, SIGNAL (triggered ()), this, SLOT (clearSelection())); connect (mDeselectAll, SIGNAL (triggered ()), this, SLOT (clearSelection()));
connect (mDeleteSelection, SIGNAL (triggered ()), this, SLOT (deleteSelection()));
} }
void CSVRender::InstanceSelectionMode::selectAll() void CSVRender::InstanceSelectionMode::selectAll()
@ -58,3 +65,22 @@ void CSVRender::InstanceSelectionMode::clearSelection()
{ {
mWorldspaceWidget.clearSelection (Mask_Reference); mWorldspaceWidget.clearSelection (Mask_Reference);
} }
void CSVRender::InstanceSelectionMode::deleteSelection()
{
std::vector<osg::ref_ptr<TagBase> > selection =
mWorldspaceWidget.getSelection (Mask_Reference);
CSMWorld::IdTable& referencesTable =
dynamic_cast<CSMWorld::IdTable&> (*mWorldspaceWidget.getDocument().getData().
getTableModel (CSMWorld::UniversalId::Type_References));
for (std::vector<osg::ref_ptr<TagBase> >::iterator iter (selection.begin());
iter!=selection.end(); ++iter)
{
CSMWorld::DeleteCommand *command = new CSMWorld::DeleteCommand (referencesTable,
static_cast<ObjectTag *> (iter->get())->mObject->getReferenceId());
mWorldspaceWidget.getDocument().getUndoStack().push (command);
}
}

View file

@ -16,6 +16,7 @@ namespace CSVRender
WorldspaceWidget& mWorldspaceWidget; WorldspaceWidget& mWorldspaceWidget;
QAction *mSelectAll; QAction *mSelectAll;
QAction *mDeselectAll; QAction *mDeselectAll;
QAction *mDeleteSelection;
/// Add context menu items to \a menu. /// Add context menu items to \a menu.
/// ///
@ -34,6 +35,8 @@ namespace CSVRender
void selectAll(); void selectAll();
void clearSelection(); void clearSelection();
void deleteSelection();
}; };
} }

View file

@ -284,3 +284,8 @@ std::string CSVRender::Object::getReferenceableId() const
{ {
return mReferenceableId; return mReferenceableId;
} }
osg::ref_ptr<CSVRender::TagBase> CSVRender::Object::getTag() const
{
return static_cast<CSVRender::TagBase *> (mBaseNode->getUserData());
}

View file

@ -114,6 +114,8 @@ namespace CSVRender
std::string getReferenceId() const; std::string getReferenceId() const;
std::string getReferenceableId() const; std::string getReferenceableId() const;
osg::ref_ptr<TagBase> getTag() const;
}; };
} }

View file

@ -529,6 +529,23 @@ std::string CSVRender::PagedWorldspaceWidget::getCellId (const osg::Vec3f& point
return cellCoordinates.getId (mWorldspace); return cellCoordinates.getId (mWorldspace);
} }
std::vector<osg::ref_ptr<CSVRender::TagBase> > CSVRender::PagedWorldspaceWidget::getSelection (
unsigned int elementMask) const
{
std::vector<osg::ref_ptr<CSVRender::TagBase> > result;
for (std::map<CSMWorld::CellCoordinates, Cell *>::const_iterator iter = mCells.begin();
iter!=mCells.end(); ++iter)
{
std::vector<osg::ref_ptr<CSVRender::TagBase> > cellResult =
iter->second->getSelection (elementMask);
result.insert (result.end(), cellResult.begin(), cellResult.end());
}
return result;
}
CSVWidget::SceneToolToggle *CSVRender::PagedWorldspaceWidget::makeControlVisibilitySelector ( CSVWidget::SceneToolToggle *CSVRender::PagedWorldspaceWidget::makeControlVisibilitySelector (
CSVWidget::SceneToolbar *parent) CSVWidget::SceneToolbar *parent)
{ {

View file

@ -103,6 +103,9 @@ namespace CSVRender
virtual std::string getCellId (const osg::Vec3f& point) const; virtual std::string getCellId (const osg::Vec3f& point) const;
virtual std::vector<osg::ref_ptr<TagBase> > getSelection (unsigned int elementMask)
const;
protected: protected:
virtual void addVisibilitySelectorButtons (CSVWidget::SceneToolToggle2 *tool); virtual void addVisibilitySelectorButtons (CSVWidget::SceneToolToggle2 *tool);

View file

@ -119,6 +119,12 @@ std::string CSVRender::UnpagedWorldspaceWidget::getCellId (const osg::Vec3f& poi
return mCellId; return mCellId;
} }
std::vector<osg::ref_ptr<CSVRender::TagBase> > CSVRender::UnpagedWorldspaceWidget::getSelection (
unsigned int elementMask) const
{
return mCell->getSelection (elementMask);
}
void CSVRender::UnpagedWorldspaceWidget::referenceableDataChanged (const QModelIndex& topLeft, void CSVRender::UnpagedWorldspaceWidget::referenceableDataChanged (const QModelIndex& topLeft,
const QModelIndex& bottomRight) const QModelIndex& bottomRight)
{ {

View file

@ -51,6 +51,9 @@ namespace CSVRender
virtual std::string getCellId (const osg::Vec3f& point) const; virtual std::string getCellId (const osg::Vec3f& point) const;
virtual std::vector<osg::ref_ptr<TagBase> > getSelection (unsigned int elementMask)
const;
private: private:
virtual void referenceableDataChanged (const QModelIndex& topLeft, virtual void referenceableDataChanged (const QModelIndex& topLeft,

View file

@ -143,6 +143,9 @@ namespace CSVRender
virtual std::string getCellId (const osg::Vec3f& point) const = 0; virtual std::string getCellId (const osg::Vec3f& point) const = 0;
virtual std::vector<osg::ref_ptr<TagBase> > getSelection (unsigned int elementMask)
const = 0;
protected: protected:
/// Visual elements in a scene /// Visual elements in a scene