From 121978a69e23ebf4d5d58513970d5a608a1de62e Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 9 Jul 2013 14:20:28 +0200 Subject: [PATCH] some cleanup; added handling of deleted cells (now displayed instead of ignored) --- apps/opencs/model/world/regionmap.cpp | 68 +++++++++++++++------------ apps/opencs/model/world/regionmap.hpp | 22 +++++++-- 2 files changed, 57 insertions(+), 33 deletions(-) diff --git a/apps/opencs/model/world/regionmap.cpp b/apps/opencs/model/world/regionmap.cpp index 6dd3148d52..b45c45a542 100644 --- a/apps/opencs/model/world/regionmap.cpp +++ b/apps/opencs/model/world/regionmap.cpp @@ -6,9 +6,11 @@ #include "data.hpp" #include "universalid.hpp" +CSMWorld::RegionMap::CellDescription::CellDescription() : mDeleted (false) {} + std::pair CSMWorld::RegionMap::getIndex (const QModelIndex& index) const { - return std::make_pair (index.column()+mMin.first, index.row()+mMin.second); + return CellIndex (index.column()+mMin.first, index.row()+mMin.second); } void CSMWorld::RegionMap::buildRegions (Data& data) @@ -38,34 +40,38 @@ void CSMWorld::RegionMap::buildMap (Data& data) { const Record& cell = cells.getRecord (i); - if (!cell.isDeleted()) + const Cell& cell2 = cell.get(); + + if (cell2.isExterior()) { - const Cell& cell2 = cell.get(); + CellDescription description; - if (cell2.isExterior()) + if (cell.isDeleted()) + description.mDeleted = true; + else + description.mRegion = cell2.mRegion; + + CellIndex index (cell2.mData.mX, cell2.mData.mY); + + if (mMap.empty()) { - std::pair index (cell2.mData.mX, cell2.mData.mY); - - if (mMap.empty()) - { - mMin = index; - mMax = std::make_pair (mMin.first+1, mMin.second+1); - } - else - { - if (index.first=mMax.first) - mMax.first = index.first + 1; - - if (index.second=mMax.second) - mMax.second = index.second + 1; - } - - mMap.insert (std::make_pair (index, cell2.mRegion)); + mMin = index; + mMax = std::make_pair (mMin.first+1, mMin.second+1); } + else + { + if (index.first=mMax.first) + mMax.first = index.first + 1; + + if (index.second=mMax.second) + mMax.second = index.second + 1; + } + + mMap.insert (std::make_pair (index, description)); } } } @@ -119,22 +125,26 @@ QVariant CSMWorld::RegionMap::data (const QModelIndex& index, int role) const { /// \todo GUI class in non-GUI code. Needs to be addressed eventually. - std::map, std::string>::const_iterator cell = + std::map::const_iterator cell = mMap.find (getIndex (index)); if (cell!=mMap.end()) { - std::map::const_iterator iter = mColours.find (cell->second); + if (cell->second.mDeleted) + return QBrush (Qt::red, Qt::DiagCrossPattern); + + std::map::const_iterator iter = + mColours.find (cell->second.mRegion); if (iter!=mColours.end()) return QBrush ( QColor (iter->second>>24, (iter->second>>16) & 255, (iter->second>>8) & 255, iter->second & 255)); - if (cell->second.empty()) + if (cell->second.mRegion.empty()) return QBrush (Qt::Dense6Pattern); // no region - return QBrush (Qt::red, Qt::Dense6Pattern); + return QBrush (Qt::red, Qt::Dense6Pattern); // invalid region } return QBrush (Qt::DiagCrossPattern); diff --git a/apps/opencs/model/world/regionmap.hpp b/apps/opencs/model/world/regionmap.hpp index a61875c78e..c5f70b4908 100644 --- a/apps/opencs/model/world/regionmap.hpp +++ b/apps/opencs/model/world/regionmap.hpp @@ -17,12 +17,26 @@ namespace CSMWorld { Q_OBJECT - std::map, std::string> mMap; ///< cell index, region - std::pair mMin; ///< inclusive - std::pair mMax; ///< exclusive + public: + + typedef std::pair CellIndex; + + private: + + struct CellDescription + { + bool mDeleted; + std::string mRegion; + + CellDescription(); + }; + + std::map mMap; + CellIndex mMin; ///< inclusive + CellIndex mMax; ///< exclusive std::map mColours; ///< region ID, colour (RGBA) - std::pair getIndex (const QModelIndex& index) const; + CellIndex getIndex (const QModelIndex& index) const; ///< Translates a Qt model index into a cell index (which can contain negative components) void buildRegions (Data& data);