mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-31 18:56:38 +00:00 
			
		
		
		
	basic region map; non-interactive for now and working with dummy data instead of real cell/region records
This commit is contained in:
		
							parent
							
								
									de5898c953
								
							
						
					
					
						commit
						4f05f2bddf
					
				
					 11 changed files with 190 additions and 3 deletions
				
			
		|  | @ -18,7 +18,7 @@ opencs_hdrs_noqt (model/doc | |||
| 
 | ||||
| 
 | ||||
| opencs_units (model/world | ||||
|     idtable idtableproxymodel | ||||
|     idtable idtableproxymodel regionmap | ||||
|     ) | ||||
| 
 | ||||
| 
 | ||||
|  | @ -57,7 +57,7 @@ opencs_hdrs_noqt (view/doc | |||
| 
 | ||||
| 
 | ||||
| opencs_units (view/world | ||||
|     table tablesubview scriptsubview util | ||||
|     table tablesubview scriptsubview util regionmapsubview | ||||
|     ) | ||||
| 
 | ||||
| opencs_units_noqt (view/world | ||||
|  |  | |||
|  | @ -11,6 +11,7 @@ | |||
| 
 | ||||
| #include "idtable.hpp" | ||||
| #include "columns.hpp" | ||||
| #include "regionmap.hpp" | ||||
| 
 | ||||
| void CSMWorld::Data::addModel (QAbstractItemModel *model, UniversalId::Type type1, | ||||
|     UniversalId::Type type2) | ||||
|  | @ -161,6 +162,8 @@ CSMWorld::Data::Data() : mRefs (mCells) | |||
|     addModel (new IdTable (&mReferenceables), UniversalId::Type_Referenceables, | ||||
|         UniversalId::Type_Referenceable); | ||||
|     addModel (new IdTable (&mRefs), UniversalId::Type_References, UniversalId::Type_Reference); | ||||
| 
 | ||||
|     addModel (new RegionMap, UniversalId::Type_RegionMap, UniversalId::Type_None); | ||||
| } | ||||
| 
 | ||||
| CSMWorld::Data::~Data() | ||||
|  |  | |||
							
								
								
									
										73
									
								
								apps/opencs/model/world/regionmap.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								apps/opencs/model/world/regionmap.cpp
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,73 @@ | |||
| 
 | ||||
| #include "regionmap.hpp" | ||||
| 
 | ||||
| #include <QBrush> | ||||
| 
 | ||||
| std::pair<int, int> CSMWorld::RegionMap::getIndex (const QModelIndex& index) const | ||||
| { | ||||
|     return std::make_pair (index.column()+mMin.first, index.row()+mMin.second); | ||||
| } | ||||
| 
 | ||||
| CSMWorld::RegionMap::RegionMap() | ||||
| { | ||||
|     // setting up some placeholder regions
 | ||||
|     mMap.insert (std::make_pair (std::make_pair (0, 0), "a")); | ||||
|     mMap.insert (std::make_pair (std::make_pair (1, 1), "b")); | ||||
|     mMap.insert (std::make_pair (std::make_pair (1, 0), "a")); | ||||
|     mMin = std::make_pair (0, 0); | ||||
|     mMax = std::make_pair (2, 2); | ||||
|     mColours.insert (std::make_pair ("a", 0xff0000ff)); | ||||
|     mColours.insert (std::make_pair ("b", 0x00ff00ff)); | ||||
| } | ||||
| 
 | ||||
| int CSMWorld::RegionMap::rowCount (const QModelIndex& parent) const | ||||
| { | ||||
|     if (parent.isValid()) | ||||
|         return 0; | ||||
| 
 | ||||
|     return mMax.second-mMin.second; | ||||
| } | ||||
| 
 | ||||
| int CSMWorld::RegionMap::columnCount (const QModelIndex& parent) const | ||||
| { | ||||
|     if (parent.isValid()) | ||||
|         return 0; | ||||
| 
 | ||||
|     return mMax.first-mMin.first; | ||||
| } | ||||
| 
 | ||||
| QVariant CSMWorld::RegionMap::data (const QModelIndex& index, int role) const | ||||
| { | ||||
|     if (role==Qt::SizeHintRole) | ||||
|         return QSize (16, 16); | ||||
| 
 | ||||
|     if (role==Qt::BackgroundRole) | ||||
|     { | ||||
|         /// \todo GUI class in non-GUI code. Needs to be addressed eventually.
 | ||||
| 
 | ||||
|         std::map<std::pair<int, int>, std::string>::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 (iter!=mColours.end()) | ||||
|                 return QBrush ( | ||||
|                     QColor (iter->second>>24, (iter->second>>16) & 255, (iter->second>>8) & 255, | ||||
|                     iter->second & 255)); | ||||
|         } | ||||
| 
 | ||||
|         return QBrush (Qt::DiagCrossPattern); | ||||
|     } | ||||
| 
 | ||||
|     return QVariant(); | ||||
| } | ||||
| 
 | ||||
| Qt::ItemFlags CSMWorld::RegionMap::flags (const QModelIndex& index) const | ||||
| { | ||||
|     if (mMap.find (getIndex (index))!=mMap.end()) | ||||
|         return Qt::ItemIsSelectable | Qt::ItemIsEnabled; | ||||
| 
 | ||||
|     return 0; | ||||
| } | ||||
							
								
								
									
										38
									
								
								apps/opencs/model/world/regionmap.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								apps/opencs/model/world/regionmap.hpp
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,38 @@ | |||
| #ifndef CSM_WOLRD_REGIONMAP_H | ||||
| #define CSM_WOLRD_REGIONMAP_H | ||||
| 
 | ||||
| #include <map> | ||||
| #include <string> | ||||
| 
 | ||||
| #include <QAbstractTableModel> | ||||
| 
 | ||||
| namespace CSMWorld | ||||
| { | ||||
|     /// \brief Model for the region map
 | ||||
|     ///
 | ||||
|     /// This class does not holds any record data (other than for the purpose of buffering).
 | ||||
|     class RegionMap : public QAbstractTableModel | ||||
|     { | ||||
|             std::map<std::pair<int, int>, std::string> mMap; ///< cell index, region
 | ||||
|             std::pair<int, int> mMin; ///< inclusive
 | ||||
|             std::pair<int, int> mMax; ///< exclusive
 | ||||
|             std::map<std::string, unsigned int> mColours; ///< region ID, colour (RGBA)
 | ||||
| 
 | ||||
|             std::pair<int, int> getIndex (const QModelIndex& index) const; | ||||
|             ///< Translates a Qt model index into a cell index (which can contain negative components)
 | ||||
| 
 | ||||
|         public: | ||||
| 
 | ||||
|             RegionMap(); | ||||
| 
 | ||||
|             virtual int rowCount (const QModelIndex& parent = QModelIndex()) const; | ||||
| 
 | ||||
|             virtual int columnCount (const QModelIndex& parent = QModelIndex()) const; | ||||
| 
 | ||||
|             virtual QVariant data (const QModelIndex& index, int role = Qt::DisplayRole) const; | ||||
| 
 | ||||
|             virtual Qt::ItemFlags flags (const QModelIndex& index) const; | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
| #endif | ||||
|  | @ -33,6 +33,8 @@ namespace | |||
|             "Referenceables" }, | ||||
|         { CSMWorld::UniversalId::Class_RecordList, CSMWorld::UniversalId::Type_References, | ||||
|             "References" }, | ||||
|         { CSMWorld::UniversalId::Class_NonRecord, CSMWorld::UniversalId::Type_RegionMap, | ||||
|             "Region Map" }, | ||||
| 
 | ||||
|         { CSMWorld::UniversalId::Class_None, CSMWorld::UniversalId::Type_None, 0 } // end marker
 | ||||
|     }; | ||||
|  |  | |||
|  | @ -81,7 +81,8 @@ namespace CSMWorld | |||
|                 Type_Static, | ||||
|                 Type_Weapon, | ||||
|                 Type_References, | ||||
|                 Type_Reference | ||||
|                 Type_Reference, | ||||
|                 Type_RegionMap | ||||
|             }; | ||||
| 
 | ||||
|         private: | ||||
|  |  | |||
|  | @ -139,6 +139,10 @@ void CSVDoc::View::setupWorldMenu() | |||
|     QAction *references = new QAction (tr ("References"), this); | ||||
|     connect (references, SIGNAL (triggered()), this, SLOT (addReferencesSubView())); | ||||
|     world->addAction (references); | ||||
| 
 | ||||
|     QAction *regionMap = new QAction (tr ("Region Map"), this); | ||||
|     connect (regionMap, SIGNAL (triggered()), this, SLOT (addRegionMapSubView())); | ||||
|     world->addAction (regionMap); | ||||
| } | ||||
| 
 | ||||
| void CSVDoc::View::setupUi() | ||||
|  | @ -363,6 +367,11 @@ void CSVDoc::View::addReferencesSubView() | |||
|     addSubView (CSMWorld::UniversalId::Type_References); | ||||
| } | ||||
| 
 | ||||
| void CSVDoc::View::addRegionMapSubView() | ||||
| { | ||||
|     addSubView (CSMWorld::UniversalId::Type_RegionMap); | ||||
| } | ||||
| 
 | ||||
| void CSVDoc::View::abortOperation (int type) | ||||
| { | ||||
|     mDocument->abortOperation (type); | ||||
|  |  | |||
|  | @ -151,6 +151,8 @@ namespace CSVDoc | |||
| 
 | ||||
|             void addReferencesSubView(); | ||||
| 
 | ||||
|             void addRegionMapSubView(); | ||||
| 
 | ||||
|             void showUserSettings(); | ||||
|     }; | ||||
| } | ||||
|  |  | |||
							
								
								
									
										29
									
								
								apps/opencs/view/world/regionmapsubview.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								apps/opencs/view/world/regionmapsubview.cpp
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,29 @@ | |||
| 
 | ||||
| #include "regionmapsubview.hpp" | ||||
| 
 | ||||
| #include <QTableView> | ||||
| #include <QHeaderView> | ||||
| 
 | ||||
| CSVWorld::RegionMapSubView::RegionMapSubView (CSMWorld::UniversalId universalId, | ||||
|     CSMDoc::Document& document) | ||||
| : CSVDoc::SubView (universalId) | ||||
| { | ||||
|     mTable = new QTableView (this); | ||||
| 
 | ||||
|     mTable->verticalHeader()->hide(); | ||||
|     mTable->horizontalHeader()->hide(); | ||||
| 
 | ||||
|     mTable->setSelectionMode (QAbstractItemView::ExtendedSelection); | ||||
| 
 | ||||
|     mTable->setModel (document.getData().getTableModel (universalId)); | ||||
| 
 | ||||
|     mTable->resizeColumnsToContents(); | ||||
|     mTable->resizeRowsToContents(); | ||||
| 
 | ||||
|     setWidget (mTable); | ||||
| } | ||||
| 
 | ||||
| void CSVWorld::RegionMapSubView::setEditLock (bool locked) | ||||
| { | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										27
									
								
								apps/opencs/view/world/regionmapsubview.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								apps/opencs/view/world/regionmapsubview.hpp
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,27 @@ | |||
| #ifndef CSV_WORLD_REGIONMAPSUBVIEW_H | ||||
| #define CSV_WORLD_REGIONMAPSUBVIEW_H | ||||
| 
 | ||||
| #include "../doc/subview.hpp" | ||||
| 
 | ||||
| class QTableView; | ||||
| 
 | ||||
| namespace CSMDoc | ||||
| { | ||||
|     class Document; | ||||
| } | ||||
| 
 | ||||
| namespace CSVWorld | ||||
| { | ||||
|     class RegionMapSubView : public CSVDoc::SubView | ||||
|     { | ||||
|             QTableView *mTable; | ||||
| 
 | ||||
|         public: | ||||
| 
 | ||||
|             RegionMapSubView (CSMWorld::UniversalId universalId, CSMDoc::Document& document); | ||||
| 
 | ||||
|             virtual void setEditLock (bool locked); | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
| #endif | ||||
|  | @ -6,6 +6,7 @@ | |||
| #include "tablesubview.hpp" | ||||
| #include "dialoguesubview.hpp" | ||||
| #include "scriptsubview.hpp" | ||||
| #include "regionmapsubview.hpp" | ||||
| 
 | ||||
| void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager) | ||||
| { | ||||
|  | @ -38,6 +39,8 @@ void CSVWorld::addSubViewFactories (CSVDoc::SubViewFactoryManager& manager) | |||
| 
 | ||||
|     manager.add (CSMWorld::UniversalId::Type_Script, new CSVDoc::SubViewFactory<ScriptSubView>); | ||||
| 
 | ||||
|     manager.add (CSMWorld::UniversalId::Type_RegionMap, new CSVDoc::SubViewFactory<RegionMapSubView>); | ||||
| 
 | ||||
| //    manager.add (CSMWorld::UniversalId::Type_Global,
 | ||||
| //        new CSVDoc::SubViewFactoryWithCreateFlag<DialogueSubView> (true));
 | ||||
| } | ||||
		Loading…
	
		Reference in a new issue