OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
regionmap.hpp
Go to the documentation of this file.
1 #ifndef CSM_WOLRD_REGIONMAP_H
2 #define CSM_WOLRD_REGIONMAP_H
3 
4 #include <map>
5 #include <string>
6 #include <vector>
7 
8 #include <QAbstractTableModel>
9 
10 #include "record.hpp"
11 #include "cell.hpp"
12 #include "cellcoordinates.hpp"
13 
14 namespace CSMWorld
15 {
16  class Data;
17 
22  {
23  Q_OBJECT
24 
25  public:
26 
27  enum Role
28  {
29  Role_Region = Qt::UserRole,
30  Role_CellId = Qt::UserRole+1
31  };
32 
33  private:
34 
36  {
37  bool mDeleted;
38  std::string mRegion;
39  std::string mName;
40 
42 
43  CellDescription (const Record<Cell>& cell);
44  };
45 
47  std::map<CellCoordinates, CellDescription> mMap;
50  std::map<std::string, unsigned int> mColours;
51 
52  CellCoordinates getIndex (const QModelIndex& index) const;
54 
55  QModelIndex getIndex (const CellCoordinates& index) const;
56 
57  CellCoordinates getIndex (const Cell& cell) const;
58 
59  void buildRegions();
60 
61  void buildMap();
62 
63  void addCell (const CellCoordinates& index, const CellDescription& description);
65  // performed)
66 
67  void addCells (int start, int end);
68 
69  void removeCell (const CellCoordinates& index);
71 
72  void addRegion (const std::string& region, unsigned int colour);
77 
78  void removeRegion (const std::string& region);
82 
83  void updateRegions (const std::vector<std::string>& regions);
85 
86  void updateSize();
87 
88  std::pair<CellCoordinates, CellCoordinates> getSize() const;
89 
90  public:
91 
92  RegionMap (Data& data);
93 
94  virtual int rowCount (const QModelIndex& parent = QModelIndex()) const;
95 
96  virtual int columnCount (const QModelIndex& parent = QModelIndex()) const;
97 
98  virtual QVariant data (const QModelIndex& index, int role = Qt::DisplayRole) const;
101 
102  virtual Qt::ItemFlags flags (const QModelIndex& index) const;
103 
104  private slots:
105 
106  void regionsAboutToBeRemoved (const QModelIndex& parent, int start, int end);
107 
108  void regionsInserted (const QModelIndex& parent, int start, int end);
109 
110  void regionsChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight);
111 
112  void cellsAboutToBeRemoved (const QModelIndex& parent, int start, int end);
113 
114  void cellsInserted (const QModelIndex& parent, int start, int end);
115 
116  void cellsChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight);
117  };
118 }
119 
120 #endif
std::string mName
Definition: regionmap.hpp:39
void removeRegion(const std::string &region)
Definition: regionmap.cpp:158
Role
Definition: regionmap.hpp:27
CellCoordinates getIndex(const QModelIndex &index) const
Translates a Qt model index into a cell index (which can contain negative components) ...
Definition: regionmap.cpp:28
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: regionmap.cpp:299
std::map< std::string, unsigned int > mColours
region ID, colour (RGBA)
Definition: regionmap.hpp:50
bool mDeleted
Definition: regionmap.hpp:37
void buildRegions()
Definition: regionmap.cpp:52
Data & mData
Definition: regionmap.hpp:46
Model for the region map.
Definition: regionmap.hpp:21
void regionsChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
Definition: regionmap.cpp:455
Definition: regionmap.hpp:29
void updateSize()
Definition: regionmap.cpp:188
void cellsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
Definition: regionmap.cpp:479
virtual Qt::ItemFlags flags(const QModelIndex &index) const
Definition: regionmap.cpp:411
void updateRegions(const std::vector< std::string > &regions)
Update cells affected by the listed regions.
Definition: regionmap.cpp:167
Definition: regionmap.hpp:30
void regionsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
Definition: regionmap.cpp:416
CellDescription()
Definition: regionmap.cpp:13
void removeCell(const CellCoordinates &index)
May be called on a cell that is not in the map (in which case the call is ignored) ...
Definition: regionmap.cpp:137
CellCoordinates mMax
exclusive
Definition: regionmap.hpp:49
void addCell(const CellCoordinates &index, const CellDescription &description)
May be called on a cell that is already in the map (in which case an update is.
Definition: regionmap.cpp:96
Definition: nestedcolumnadapter.hpp:11
RegionMap(Data &data)
Definition: regionmap.cpp:275
std::map< CellCoordinates, CellDescription > mMap
Definition: regionmap.hpp:47
void cellsInserted(const QModelIndex &parent, int start, int end)
Definition: regionmap.cpp:494
CellCoordinates mMin
inclusive
Definition: regionmap.hpp:48
Definition: data.hpp:77
void addCells(int start, int end)
Definition: regionmap.cpp:116
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition: regionmap.cpp:315
Definition: cellcoordinates.hpp:12
Wrapper for Cell record.
Definition: cell.hpp:15
void regionsInserted(const QModelIndex &parent, int start, int end)
Definition: regionmap.cpp:434
Definition: regionmap.hpp:35
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition: regionmap.cpp:307
void buildMap()
Definition: regionmap.cpp:68
void addRegion(const std::string &region, unsigned int colour)
Definition: regionmap.cpp:153
std::string mRegion
Definition: regionmap.hpp:38
void cellsChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
Definition: regionmap.cpp:499
std::pair< CellCoordinates, CellCoordinates > getSize() const
Definition: regionmap.cpp:233