mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-28 17:56:37 +00:00 
			
		
		
		
	some cleanup; added handling of deleted cells (now displayed instead of ignored)
This commit is contained in:
		
							parent
							
								
									116320cc0d
								
							
						
					
					
						commit
						121978a69e
					
				
					 2 changed files with 57 additions and 33 deletions
				
			
		|  | @ -6,9 +6,11 @@ | |||
| #include "data.hpp" | ||||
| #include "universalid.hpp" | ||||
| 
 | ||||
| CSMWorld::RegionMap::CellDescription::CellDescription() : mDeleted (false) {} | ||||
| 
 | ||||
| std::pair<int, int> 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,13 +40,18 @@ void CSMWorld::RegionMap::buildMap (Data& data) | |||
|     { | ||||
|         const Record<Cell>& cell = cells.getRecord (i); | ||||
| 
 | ||||
|         if (!cell.isDeleted()) | ||||
|         { | ||||
|         const Cell& cell2 = cell.get(); | ||||
| 
 | ||||
|         if (cell2.isExterior()) | ||||
|         { | ||||
|                 std::pair<int, int> index (cell2.mData.mX, cell2.mData.mY); | ||||
|             CellDescription description; | ||||
| 
 | ||||
|             if (cell.isDeleted()) | ||||
|                 description.mDeleted = true; | ||||
|             else | ||||
|                 description.mRegion = cell2.mRegion; | ||||
| 
 | ||||
|             CellIndex index (cell2.mData.mX, cell2.mData.mY); | ||||
| 
 | ||||
|             if (mMap.empty()) | ||||
|             { | ||||
|  | @ -64,8 +71,7 @@ void CSMWorld::RegionMap::buildMap (Data& data) | |||
|                     mMax.second = index.second + 1; | ||||
|             } | ||||
| 
 | ||||
|                 mMap.insert (std::make_pair (index, cell2.mRegion)); | ||||
|             } | ||||
|             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::pair<int, int>, std::string>::const_iterator cell = | ||||
|         std::map<CellIndex, CellDescription>::const_iterator cell = | ||||
|             mMap.find (getIndex (index)); | ||||
| 
 | ||||
|         if (cell!=mMap.end()) | ||||
|         { | ||||
|             std::map<std::string, unsigned int>::const_iterator iter = mColours.find (cell->second); | ||||
|             if (cell->second.mDeleted) | ||||
|                 return QBrush (Qt::red, Qt::DiagCrossPattern); | ||||
| 
 | ||||
|             std::map<std::string, unsigned int>::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); | ||||
|  |  | |||
|  | @ -17,12 +17,26 @@ namespace CSMWorld | |||
|     { | ||||
|             Q_OBJECT | ||||
| 
 | ||||
|             std::map<std::pair<int, int>, std::string> mMap; ///< cell index, region
 | ||||
|             std::pair<int, int> mMin; ///< inclusive
 | ||||
|             std::pair<int, int> mMax; ///< exclusive
 | ||||
|         public: | ||||
| 
 | ||||
|             typedef std::pair<int, int> CellIndex; | ||||
| 
 | ||||
|         private: | ||||
| 
 | ||||
|             struct CellDescription | ||||
|             { | ||||
|                 bool mDeleted; | ||||
|                 std::string mRegion; | ||||
| 
 | ||||
|                 CellDescription(); | ||||
|             }; | ||||
| 
 | ||||
|             std::map<CellIndex, CellDescription> mMap; | ||||
|             CellIndex mMin; ///< inclusive
 | ||||
|             CellIndex mMax; ///< exclusive
 | ||||
|             std::map<std::string, unsigned int> mColours; ///< region ID, colour (RGBA)
 | ||||
| 
 | ||||
|             std::pair<int, int> 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); | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue