OpenCS: use a separate enum for the toggle buttons

coverity_scan
scrawl 9 years ago
parent 3089aeccc4
commit ad2145b463

@ -94,7 +94,7 @@ opencs_units_noqt (view/render
)
opencs_hdrs_noqt (view/render
elements
mask
)

@ -11,7 +11,7 @@
#include "../../model/world/refcollection.hpp"
#include "../../model/world/cellcoordinates.hpp"
#include "elements.hpp"
#include "mask.hpp"
#include "terrainstorage.hpp"
bool CSVRender::Cell::removeObject (const std::string& id)
@ -80,7 +80,7 @@ CSVRender::Cell::Cell (CSMWorld::Data& data, osg::Group* rootNode, const std::st
if (esmLand.getLandData (ESM::Land::DATA_VHGT))
{
mTerrain.reset(new Terrain::TerrainGrid(mCellNode, data.getResourceSystem().get(), NULL, new TerrainStorage(mData), Element_Terrain<<1));
mTerrain.reset(new Terrain::TerrainGrid(mCellNode, data.getResourceSystem().get(), NULL, new TerrainStorage(mData), Mask_Terrain));
mTerrain->loadCell(esmLand.mX,
esmLand.mY);
}
@ -230,7 +230,7 @@ bool CSVRender::Cell::referenceAdded (const QModelIndex& parent, int start, int
void CSVRender::Cell::setSelection (int elementMask, Selection mode)
{
if (elementMask & Element_Reference)
if (elementMask & Mask_Reference)
{
for (std::map<std::string, Object *>::const_iterator iter (mObjects.begin());
iter!=mObjects.end(); ++iter)

@ -7,10 +7,10 @@
#include <osg/Geometry>
#include <osg/PrimitiveSet>
#include "elements.hpp"
#include "mask.hpp"
CSVRender::CellArrowTag::CellArrowTag (CellArrow *arrow)
: TagBase (Element_CellArrow), mArrow (arrow)
: TagBase (Mask_CellArrow), mArrow (arrow)
{}
CSVRender::CellArrow *CSVRender::CellArrowTag::getCellArrow() const
@ -165,8 +165,7 @@ CSVRender::CellArrow::CellArrow (osg::Group *cellNode, Direction direction,
mParentNode->addChild (mBaseNode);
// 0x1 reserved for separating cull and update visitors
mBaseNode->setNodeMask (Element_CellArrow<<1);
mBaseNode->setNodeMask (Mask_CellArrow);
adjustTransform();
buildShape();

@ -1,23 +0,0 @@
#ifndef CSV_RENDER_ELEMENTS_H
#define CSV_RENDER_ELEMENTS_H
namespace CSVRender
{
/// Visual elements in a scene
enum Elements
{
// elements that are part of the actual scene
Element_Reference = 0x1,
Element_Pathgrid = 0x2,
Element_Water = 0x4,
Element_Fog = 0x8,
Element_Terrain = 0x10,
// control elements
Element_CellMarker = 0x10000,
Element_CellArrow = 0x20000,
Element_CellBorder = 0x40000
};
}
#endif

@ -3,12 +3,12 @@
#include "../../model/prefs/state.hpp"
#include "elements.hpp"
#include "mask.hpp"
#include "object.hpp"
#include "worldspacewidget.hpp"
CSVRender::InstanceMode::InstanceMode (WorldspaceWidget *worldspaceWidget, QWidget *parent)
: EditMode (worldspaceWidget, QIcon (":placeholder"), Element_Reference, "Instance editing",
: EditMode (worldspaceWidget, QIcon (":placeholder"), Mask_Reference, "Instance editing",
parent)
{
@ -28,7 +28,7 @@ void CSVRender::InstanceMode::secondaryEditPressed (osg::ref_ptr<TagBase> tag)
void CSVRender::InstanceMode::primarySelectPressed (osg::ref_ptr<TagBase> tag)
{
getWorldspaceWidget().clearSelection (Element_Reference);
getWorldspaceWidget().clearSelection (Mask_Reference);
if (tag)
{

@ -0,0 +1,27 @@
#ifndef CSV_RENDER_ELEMENTS_H
#define CSV_RENDER_ELEMENTS_H
namespace CSVRender
{
/// @note Enumeration values can be changed freely, as long as they do not collide.
enum Mask
{
// internal use within NifLoader, do not change
Mask_UpdateVisitor = 0x1,
// elements that are part of the actual scene
Mask_Reference = 0x2,
Mask_Pathgrid = 0x4,
Mask_Water = 0x8,
Mask_Fog = 0x10,
Mask_Terrain = 0x20,
// control elements
Mask_CellMarker = 0x10000,
Mask_CellArrow = 0x20000,
Mask_CellBorder = 0x40000
};
}
#endif

@ -19,7 +19,7 @@
#include <components/resource/scenemanager.hpp>
#include <components/sceneutil/clone.hpp>
#include "elements.hpp"
#include "mask.hpp"
namespace
{
@ -39,7 +39,7 @@ namespace
CSVRender::ObjectTag::ObjectTag (Object* object)
: TagBase (Element_Reference), mObject (object)
: TagBase (Mask_Reference), mObject (object)
{}
QString CSVRender::ObjectTag::getToolTip (bool hideBasics) const
@ -138,8 +138,7 @@ CSVRender::Object::Object (CSMWorld::Data& data, osg::Group* parentNode,
parentNode->addChild(mBaseNode);
// 0x1 reserved for separating cull and update visitors
mBaseNode->setNodeMask(Element_Reference<<1);
mBaseNode->setNodeMask(Mask_Reference);
if (referenceable)
{

@ -18,7 +18,7 @@
#include "../widget/scenetooltoggle2.hpp"
#include "editmode.hpp"
#include "elements.hpp"
#include "mask.hpp"
bool CSVRender::PagedWorldspaceWidget::adjustCells()
{
@ -126,8 +126,8 @@ void CSVRender::PagedWorldspaceWidget::addVisibilitySelectorButtons (
CSVWidget::SceneToolToggle2 *tool)
{
WorldspaceWidget::addVisibilitySelectorButtons (tool);
tool->addButton (Element_Terrain, "Terrain");
tool->addButton (Element_Fog, "Fog", "", true);
tool->addButton (CSVWidget::SceneToolToggle2::Button_Terrain, Mask_Terrain, "Terrain");
tool->addButton (CSVWidget::SceneToolToggle2::Button_Fog, Mask_Fog, "Fog", "", true);
}
void CSVRender::PagedWorldspaceWidget::addEditModeSelectorButtons (
@ -137,22 +137,22 @@ void CSVRender::PagedWorldspaceWidget::addEditModeSelectorButtons (
/// \todo replace EditMode with suitable subclasses
tool->addButton (
new EditMode (this, QIcon (":placeholder"), Element_Reference, "Terrain shape editing"),
new EditMode (this, QIcon (":placeholder"), Mask_Reference, "Terrain shape editing"),
"terrain-shape");
tool->addButton (
new EditMode (this, QIcon (":placeholder"), Element_Reference, "Terrain texture editing"),
new EditMode (this, QIcon (":placeholder"), Mask_Reference, "Terrain texture editing"),
"terrain-texture");
tool->addButton (
new EditMode (this, QIcon (":placeholder"), Element_Reference, "Terrain vertex paint editing"),
new EditMode (this, QIcon (":placeholder"), Mask_Reference, "Terrain vertex paint editing"),
"terrain-vertex");
tool->addButton (
new EditMode (this, QIcon (":placeholder"), Element_Reference, "Terrain movement"),
new EditMode (this, QIcon (":placeholder"), Mask_Reference, "Terrain movement"),
"terrain-move");
}
void CSVRender::PagedWorldspaceWidget::handleMouseClick (osg::ref_ptr<TagBase> tag, const std::string& button, bool shift)
{
if (tag && tag->getElement()==Element_CellArrow)
if (tag && tag->getMask()==Mask_CellArrow)
{
if (button=="p-edit" || button=="s-edit")
{
@ -492,7 +492,7 @@ CSVRender::WorldspaceWidget::dropRequirments CSVRender::PagedWorldspaceWidget::g
unsigned int CSVRender::PagedWorldspaceWidget::getVisibilityMask() const
{
return WorldspaceWidget::getVisibilityMask() | mControlElements->getSelection();
return WorldspaceWidget::getVisibilityMask() | mControlElements->getSelectionMask();
}
void CSVRender::PagedWorldspaceWidget::clearSelection (int elementMask)
@ -510,12 +510,12 @@ CSVWidget::SceneToolToggle *CSVRender::PagedWorldspaceWidget::makeControlVisibil
mControlElements = new CSVWidget::SceneToolToggle (parent,
"Controls & Guides Visibility", ":placeholder");
mControlElements->addButton (":placeholder", Element_CellMarker, ":placeholder",
mControlElements->addButton (":placeholder", Mask_CellMarker, ":placeholder",
"Cell marker");
mControlElements->addButton (":placeholder", Element_CellArrow, ":placeholder", "Cell arrows");
mControlElements->addButton (":placeholder", Element_CellBorder, ":placeholder", "Cell border");
mControlElements->addButton (":placeholder", Mask_CellArrow, ":placeholder", "Cell arrows");
mControlElements->addButton (":placeholder", Mask_CellBorder, ":placeholder", "Cell border");
mControlElements->setSelection (0xffffffff);
mControlElements->setSelectionMask (0xffffffff);
connect (mControlElements, SIGNAL (selectionChanged()),
this, SLOT (elementSelectionChanged()));

@ -18,6 +18,7 @@
#include "../widget/scenetoolmode.hpp"
#include "lighting.hpp"
#include "mask.hpp"
namespace CSVRender
{
@ -73,7 +74,7 @@ RenderWidget::RenderWidget(QWidget *parent, Qt::WindowFlags f)
// Press S to reveal profiling stats
mView->addEventHandler(new osgViewer::StatsHandler);
mView->getCamera()->setCullMask(~(0x1));
mView->getCamera()->setCullMask(~(Mask_UpdateVisitor));
viewer.addView(mView);
viewer.setDone(false);
@ -92,8 +93,7 @@ void RenderWidget::flagAsModified()
void RenderWidget::setVisibilityMask(int mask)
{
// 0x1 reserved for separating cull and update visitors
mView->getCamera()->setCullMask(mask<<1);
mView->getCamera()->setCullMask(mask);
}
bool RenderWidget::eventFilter(QObject* obj, QEvent* event)

@ -1,11 +1,11 @@
#include "tagbase.hpp"
CSVRender::TagBase::TagBase (Elements element) : mElement (element) {}
CSVRender::TagBase::TagBase (Mask mask) : mMask (mask) {}
CSVRender::Elements CSVRender::TagBase::getElement() const
CSVRender::Mask CSVRender::TagBase::getMask() const
{
return mElement;
return mMask;
}
QString CSVRender::TagBase::getToolTip (bool hideBasics) const

@ -5,19 +5,19 @@
#include <QString>
#include "elements.hpp"
#include "mask.hpp"
namespace CSVRender
{
class TagBase : public osg::Referenced
{
Elements mElement;
Mask mMask;
public:
TagBase (Elements element);
TagBase (Mask mask);
Elements getElement() const;
Mask getMask() const;
virtual QString getToolTip (bool hideBasics) const;

@ -17,7 +17,7 @@
#include "../widget/scenetooltoggle.hpp"
#include "../widget/scenetooltoggle2.hpp"
#include "elements.hpp"
#include "mask.hpp"
void CSVRender::UnpagedWorldspaceWidget::update()
{
@ -166,8 +166,8 @@ void CSVRender::UnpagedWorldspaceWidget::addVisibilitySelectorButtons (
CSVWidget::SceneToolToggle2 *tool)
{
WorldspaceWidget::addVisibilitySelectorButtons (tool);
tool->addButton (Element_Terrain, "Terrain", "", true);
tool->addButton (Element_Fog, "Fog");
tool->addButton (CSVWidget::SceneToolToggle2::Button_Terrain, Mask_Terrain, "Terrain", "", true);
tool->addButton (CSVWidget::SceneToolToggle2::Button_Fog, Mask_Fog, "Fog");
}
std::string CSVRender::UnpagedWorldspaceWidget::getStartupInstruction()

@ -27,7 +27,7 @@
#include "../widget/scenetoolrun.hpp"
#include "object.hpp"
#include "elements.hpp"
#include "mask.hpp"
#include "editmode.hpp"
#include "instancemode.hpp"
@ -160,7 +160,7 @@ CSVWidget::SceneToolToggle2 *CSVRender::WorldspaceWidget::makeSceneVisibilitySel
addVisibilitySelectorButtons (mSceneElements);
mSceneElements->setSelection (0xffffffff);
mSceneElements->setSelectionMask (0xffffffff);
connect (mSceneElements, SIGNAL (selectionChanged()),
this, SLOT (elementSelectionChanged()));
@ -275,12 +275,12 @@ bool CSVRender::WorldspaceWidget::handleDrop (const std::vector<CSMWorld::Univer
unsigned int CSVRender::WorldspaceWidget::getVisibilityMask() const
{
return mSceneElements->getSelection();
return mSceneElements->getSelectionMask();
}
void CSVRender::WorldspaceWidget::setInteractionMask (unsigned int mask)
{
mInteractionMask = mask | Element_CellMarker | Element_CellArrow;
mInteractionMask = mask | Mask_CellMarker | Mask_CellArrow;
}
unsigned int CSVRender::WorldspaceWidget::getInteractionMask() const
@ -296,9 +296,9 @@ void CSVRender::WorldspaceWidget::setEditLock (bool locked)
void CSVRender::WorldspaceWidget::addVisibilitySelectorButtons (
CSVWidget::SceneToolToggle2 *tool)
{
tool->addButton (Element_Reference, "Instances");
tool->addButton (Element_Water, "Water");
tool->addButton (Element_Pathgrid, "Pathgrid");
tool->addButton (CSVWidget::SceneToolToggle2::Button_Reference, Mask_Reference, "Instances");
tool->addButton (CSVWidget::SceneToolToggle2::Button_Water, Mask_Water, "Water");
tool->addButton (CSVWidget::SceneToolToggle2::Button_Pathgrid, Mask_Pathgrid, "Pathgrid");
}
void CSVRender::WorldspaceWidget::addEditModeSelectorButtons (CSVWidget::SceneToolMode *tool)
@ -306,7 +306,7 @@ void CSVRender::WorldspaceWidget::addEditModeSelectorButtons (CSVWidget::SceneTo
/// \todo replace EditMode with suitable subclasses
tool->addButton (new InstanceMode (this, tool), "object");
tool->addButton (
new EditMode (this, QIcon (":placeholder"), Element_Pathgrid, "Pathgrid editing"),
new EditMode (this, QIcon (":placeholder"), Mask_Pathgrid, "Pathgrid editing"),
"pathgrid");
}
@ -404,7 +404,7 @@ osg::ref_ptr<CSVRender::TagBase> CSVRender::WorldspaceWidget::mousePick (const Q
intersector->setIntersectionLimit(osgUtil::LineSegmentIntersector::NO_LIMIT);
osgUtil::IntersectionVisitor visitor(intersector);
visitor.setTraversalMask(getInteractionMask() << 1);
visitor.setTraversalMask(getInteractionMask());
mView->getCamera()->accept(visitor);

@ -11,7 +11,7 @@
#include "../../model/world/tablemimedata.hpp"
#include "scenewidget.hpp"
#include "elements.hpp"
#include "mask.hpp"
namespace CSMPrefs
{

@ -40,7 +40,7 @@ void CSVWidget::SceneToolToggle::adjustToolTip()
void CSVWidget::SceneToolToggle::adjustIcon()
{
unsigned int selection = getSelection();
unsigned int selection = getSelectionMask();
if (!selection)
setIcon (QIcon (QString::fromUtf8 (mEmptyIcon.c_str())));
else
@ -135,7 +135,7 @@ void CSVWidget::SceneToolToggle::showPanel (const QPoint& position)
mFirst->setFocus (Qt::OtherFocusReason);
}
void CSVWidget::SceneToolToggle::addButton (const std::string& icon, unsigned int id,
void CSVWidget::SceneToolToggle::addButton (const std::string& icon, unsigned int mask,
const std::string& smallIcon, const QString& name, const QString& tooltip)
{
if (mButtons.size()>=9)
@ -151,7 +151,7 @@ void CSVWidget::SceneToolToggle::addButton (const std::string& icon, unsigned in
mLayout->addWidget (button);
ButtonDesc desc;
desc.mId = id;
desc.mMask = mask;
desc.mSmallIcon = smallIcon;
desc.mName = name;
desc.mIndex = mButtons.size();
@ -164,23 +164,23 @@ void CSVWidget::SceneToolToggle::addButton (const std::string& icon, unsigned in
mFirst = button;
}
unsigned int CSVWidget::SceneToolToggle::getSelection() const
unsigned int CSVWidget::SceneToolToggle::getSelectionMask() const
{
unsigned int selection = 0;
for (std::map<PushButton *, ButtonDesc>::const_iterator iter (mButtons.begin());
iter!=mButtons.end(); ++iter)
if (iter->first->isChecked())
selection |= iter->second.mId;
selection |= iter->second.mMask;
return selection;
}
void CSVWidget::SceneToolToggle::setSelection (unsigned int selection)
void CSVWidget::SceneToolToggle::setSelectionMask (unsigned int selection)
{
for (std::map<PushButton *, ButtonDesc>::iterator iter (mButtons.begin());
iter!=mButtons.end(); ++iter)
iter->first->setChecked (selection & iter->second.mId);
iter->first->setChecked (selection & iter->second.mMask);
adjustToolTip();
adjustIcon();

@ -20,7 +20,7 @@ namespace CSVWidget
struct ButtonDesc
{
unsigned int mId;
unsigned int mMask;
std::string mSmallIcon;
QString mName;
int mIndex;
@ -54,13 +54,13 @@ namespace CSVWidget
/// \note The layout algorithm can not handle more than 9 buttons. To prevent this An
/// attempt to add more will result in an exception being thrown.
/// The small icons will be sized at (x-4)/3 (where x is the main icon size).
void addButton (const std::string& icon, unsigned int id,
void addButton (const std::string& icon, unsigned int mask,
const std::string& smallIcon, const QString& name, const QString& tooltip = "");
unsigned int getSelection() const;
unsigned int getSelectionMask() const;
/// \param or'ed button IDs. IDs that do not exist will be ignored.
void setSelection (unsigned int selection);
/// \param or'ed button masks. buttons that do not exist will be ignored.
void setSelectionMask (unsigned int selection);
signals:

@ -41,8 +41,15 @@ void CSVWidget::SceneToolToggle2::adjustToolTip()
void CSVWidget::SceneToolToggle2::adjustIcon()
{
unsigned int buttonIds = 0;
for (std::map<PushButton *, ButtonDesc>::const_iterator iter (mButtons.begin());
iter!=mButtons.end(); ++iter)
if (iter->first->isChecked())
buttonIds |= iter->second.mButtonId;
std::ostringstream stream;
stream << mCompositeIcon << getSelection();
stream << mCompositeIcon << buttonIds;
setIcon (QIcon (QString::fromUtf8 (stream.str().c_str())));
}
@ -70,11 +77,11 @@ void CSVWidget::SceneToolToggle2::showPanel (const QPoint& position)
mFirst->setFocus (Qt::OtherFocusReason);
}
void CSVWidget::SceneToolToggle2::addButton (unsigned int id,
void CSVWidget::SceneToolToggle2::addButton (ButtonId id, unsigned int mask,
const QString& name, const QString& tooltip, bool disabled)
{
std::ostringstream stream;
stream << mSingleIcon << id;
stream << mSingleIcon << static_cast<unsigned int>(id);
PushButton *button = new PushButton (QIcon (QPixmap (stream.str().c_str())),
PushButton::Type_Toggle, tooltip.isEmpty() ? name: tooltip, mPanel);
@ -89,7 +96,8 @@ void CSVWidget::SceneToolToggle2::addButton (unsigned int id,
mLayout->addWidget (button);
ButtonDesc desc;
desc.mId = id;
desc.mButtonId = id;
desc.mMask = mask;
desc.mName = name;
desc.mIndex = mButtons.size();
@ -101,23 +109,23 @@ void CSVWidget::SceneToolToggle2::addButton (unsigned int id,
mFirst = button;
}
unsigned int CSVWidget::SceneToolToggle2::getSelection() const
unsigned int CSVWidget::SceneToolToggle2::getSelectionMask() const
{
unsigned int selection = 0;
for (std::map<PushButton *, ButtonDesc>::const_iterator iter (mButtons.begin());
iter!=mButtons.end(); ++iter)
if (iter->first->isChecked())
selection |= iter->second.mId;
selection |= iter->second.mMask;
return selection;
}
void CSVWidget::SceneToolToggle2::setSelection (unsigned int selection)
void CSVWidget::SceneToolToggle2::setSelectionMask (unsigned int selection)
{
for (std::map<PushButton *, ButtonDesc>::iterator iter (mButtons.begin());
iter!=mButtons.end(); ++iter)
iter->first->setChecked (selection & iter->second.mId);
iter->first->setChecked (selection & iter->second.mMask);
adjustToolTip();
adjustIcon();

@ -22,7 +22,8 @@ namespace CSVWidget
struct ButtonDesc
{
unsigned int mId;
unsigned int mButtonId;
unsigned int mMask;
QString mName;
int mIndex;
};
@ -53,15 +54,25 @@ namespace CSVWidget
virtual void showPanel (const QPoint& position);
/// Visual elements in a scene
/// @note do not change the enumeration values, they are used in pre-existing button file names!
enum ButtonId
{
Button_Reference = 0x1,
Button_Pathgrid = 0x2,
Button_Water = 0x4,
Button_Fog = 0x8,
Button_Terrain = 0x10
};
/// \attention After the last button has been added, setSelection must be called at
/// least once to finalise the layout.
void addButton (unsigned int id,
void addButton (ButtonId buttonId, unsigned int mask,
const QString& name, const QString& tooltip = "", bool disabled = false);
unsigned int getSelection() const;
unsigned int getSelectionMask() const;
/// \param or'ed button IDs. IDs that do not exist will be ignored.
void setSelection (unsigned int selection);
/// \param or'ed button masks. buttons that do not exist will be ignored.
void setSelectionMask (unsigned int selection);
signals:

Loading…
Cancel
Save