OpenMW
|
00001 #ifndef CSM_WOLRD_REGIONMAP_H 00002 #define CSM_WOLRD_REGIONMAP_H 00003 00004 #include <map> 00005 #include <string> 00006 #include <vector> 00007 00008 #include <QAbstractTableModel> 00009 00010 #include "record.hpp" 00011 #include "cell.hpp" 00012 00013 namespace CSMWorld 00014 { 00015 class Data; 00016 00020 class RegionMap : public QAbstractTableModel 00021 { 00022 Q_OBJECT 00023 00024 public: 00025 00026 typedef std::pair<int, int> CellIndex; 00027 00028 private: 00029 00030 struct CellDescription 00031 { 00032 bool mDeleted; 00033 std::string mRegion; 00034 std::string mName; 00035 00036 CellDescription(); 00037 00038 CellDescription (const Record<Cell>& cell); 00039 }; 00040 00041 Data& mData; 00042 std::map<CellIndex, CellDescription> mMap; 00043 CellIndex mMin; 00044 CellIndex mMax; 00045 std::map<std::string, unsigned int> mColours; 00046 00047 CellIndex getIndex (const QModelIndex& index) const; 00049 00050 QModelIndex getIndex (const CellIndex& index) const; 00051 00052 void buildRegions(); 00053 00054 void buildMap(); 00055 00056 void addCell (const CellIndex& index, const CellDescription& description); 00058 // performed) 00059 00060 void addCells (int start, int end); 00061 00062 void removeCell (const CellIndex& index); 00064 00065 void addRegion (const std::string& region, unsigned int colour); 00070 00071 void removeRegion (const std::string& region); 00075 00076 void updateRegions (const std::vector<std::string>& regions); 00078 00079 void updateSize(); 00080 00081 std::pair<CellIndex, CellIndex> getSize() const; 00082 00083 public: 00084 00085 RegionMap (Data& data); 00086 00087 virtual int rowCount (const QModelIndex& parent = QModelIndex()) const; 00088 00089 virtual int columnCount (const QModelIndex& parent = QModelIndex()) const; 00090 00091 virtual QVariant data (const QModelIndex& index, int role = Qt::DisplayRole) const; 00092 00093 virtual Qt::ItemFlags flags (const QModelIndex& index) const; 00094 00095 private slots: 00096 00097 void regionsAboutToBeRemoved (const QModelIndex& parent, int start, int end); 00098 00099 void regionsInserted (const QModelIndex& parent, int start, int end); 00100 00101 void regionsChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight); 00102 00103 void cellsAboutToBeRemoved (const QModelIndex& parent, int start, int end); 00104 00105 void cellsInserted (const QModelIndex& parent, int start, int end); 00106 00107 void cellsChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight); 00108 }; 00109 } 00110 00111 #endif