From 1f902ff0695d515673db07bc9e7518b2895640b9 Mon Sep 17 00:00:00 2001 From: Aesylwinn Date: Tue, 3 May 2016 16:08:12 -0400 Subject: [PATCH] Remove code duplication. --- apps/opencs/view/render/cell.cpp | 56 ++++++++++---------------------- apps/opencs/view/render/cell.hpp | 2 ++ 2 files changed, 20 insertions(+), 38 deletions(-) diff --git a/apps/opencs/view/render/cell.cpp b/apps/opencs/view/render/cell.cpp index 1bd43c23f..a87451398 100644 --- a/apps/opencs/view/render/cell.cpp +++ b/apps/opencs/view/render/cell.cpp @@ -68,6 +68,19 @@ bool CSVRender::Cell::addObjects (int start, int end) return modified; } +void CSVRender::Cell::recreatePathgrid() +{ + const CSMWorld::SubCellCollection& pathgrids = mData.getPathgrids(); + int pathgridIndex = pathgrids.searchId(mId); + if (pathgridIndex != -1) + { + mPathgridGeode->removeDrawable(mPathgridGeometry); + mPathgridGeometry = SceneUtil::PathgridGeometryFactory::get().create( + pathgrids.getRecord(pathgridIndex).get()); + mPathgridGeode->addDrawable(mPathgridGeometry); + } +} + CSVRender::Cell::Cell (CSMWorld::Data& data, osg::Group* rootNode, const std::string& id, bool deleted) : mData (data), mId (Misc::StringUtils::lowerCase (id)), mDeleted (deleted), mSubMode (0), @@ -120,14 +133,7 @@ CSVRender::Cell::Cell (CSMWorld::Data& data, osg::Group* rootNode, const std::st } } - const CSMWorld::SubCellCollection& pathgrids = mData.getPathgrids(); - int pathgridIndex = pathgrids.searchId(mId); - if (pathgridIndex != -1) - { - mPathgridGeometry = SceneUtil::PathgridGeometryFactory::get().create( - pathgrids.getRecord(pathgridIndex).get()); - mPathgridGeode->addDrawable(mPathgridGeometry); - } + recreatePathgrid(); } } @@ -280,9 +286,7 @@ bool CSVRender::Cell::referenceAdded (const QModelIndex& parent, int start, int void CSVRender::Cell::pathgridAdded(const CSMWorld::Pathgrid& pathgrid) { - mPathgridGeode->removeDrawable(mPathgridGeometry); - mPathgridGeometry = SceneUtil::PathgridGeometryFactory::get().create(pathgrid); - mPathgridGeode->addDrawable(mPathgridGeometry); + recreatePathgrid(); } void CSVRender::Cell::pathgridRemoved() @@ -292,41 +296,17 @@ void CSVRender::Cell::pathgridRemoved() void CSVRender::Cell::pathgridDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight) { - const CSMWorld::SubCellCollection& pathgrids = mData.getPathgrids(); - int pathgridIndex = pathgrids.searchId(mId); - if (pathgridIndex != -1) - { - mPathgridGeode->removeDrawable(mPathgridGeometry); - mPathgridGeometry = SceneUtil::PathgridGeometryFactory::get().create( - pathgrids.getRecord(pathgridIndex).get()); - mPathgridGeode->addDrawable(mPathgridGeometry); - } + recreatePathgrid(); } void CSVRender::Cell::pathgridRowRemoved(const QModelIndex& parent, int start, int end) { - const CSMWorld::SubCellCollection& pathgrids = mData.getPathgrids(); - int pathgridIndex = pathgrids.searchId(mId); - if (pathgridIndex != -1) - { - mPathgridGeode->removeDrawable(mPathgridGeometry); - mPathgridGeometry = SceneUtil::PathgridGeometryFactory::get().create( - pathgrids.getRecord(pathgridIndex).get()); - mPathgridGeode->addDrawable(mPathgridGeometry); - } + recreatePathgrid(); } void CSVRender::Cell::pathgridRowAdded(const QModelIndex& parent, int start, int end) { - const CSMWorld::SubCellCollection& pathgrids = mData.getPathgrids(); - int pathgridIndex = pathgrids.searchId(mId); - if (pathgridIndex != -1) - { - mPathgridGeode->removeDrawable(mPathgridGeometry); - mPathgridGeometry = SceneUtil::PathgridGeometryFactory::get().create( - pathgrids.getRecord(pathgridIndex).get()); - mPathgridGeode->addDrawable(mPathgridGeometry); - } + recreatePathgrid(); } void CSVRender::Cell::setSelection (int elementMask, Selection mode) diff --git a/apps/opencs/view/render/cell.hpp b/apps/opencs/view/render/cell.hpp index 0efb8757c..e265fc21c 100644 --- a/apps/opencs/view/render/cell.hpp +++ b/apps/opencs/view/render/cell.hpp @@ -69,6 +69,8 @@ namespace CSVRender /// \return Have any objects been added? bool addObjects (int start, int end); + void recreatePathgrid(); + public: enum Selection