diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index cec3756a3c..c7006c4d78 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -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 diff --git a/apps/opencs/model/world/data.cpp b/apps/opencs/model/world/data.cpp index 3921754425..4a38604b1a 100644 --- a/apps/opencs/model/world/data.cpp +++ b/apps/opencs/model/world/data.cpp @@ -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() diff --git a/apps/opencs/model/world/regionmap.cpp b/apps/opencs/model/world/regionmap.cpp new file mode 100644 index 0000000000..8fbed9c5a0 --- /dev/null +++ b/apps/opencs/model/world/regionmap.cpp @@ -0,0 +1,73 @@ + +#include "regionmap.hpp" + +#include + +std::pair 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::string>::const_iterator cell = + mMap.find (getIndex (index)); + + if (cell!=mMap.end()) + { + std::map::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; +} \ No newline at end of file diff --git a/apps/opencs/model/world/regionmap.hpp b/apps/opencs/model/world/regionmap.hpp new file mode 100644 index 0000000000..78792fad15 --- /dev/null +++ b/apps/opencs/model/world/regionmap.hpp @@ -0,0 +1,38 @@ +#ifndef CSM_WOLRD_REGIONMAP_H +#define CSM_WOLRD_REGIONMAP_H + +#include +#include + +#include + +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::string> mMap; ///< cell index, region + std::pair mMin; ///< inclusive + std::pair mMax; ///< exclusive + std::map mColours; ///< region ID, colour (RGBA) + + std::pair 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 diff --git a/apps/opencs/model/world/universalid.cpp b/apps/opencs/model/world/universalid.cpp index b5efe6e220..7e07a2989b 100644 --- a/apps/opencs/model/world/universalid.cpp +++ b/apps/opencs/model/world/universalid.cpp @@ -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 }; diff --git a/apps/opencs/model/world/universalid.hpp b/apps/opencs/model/world/universalid.hpp index bd6fdeb000..8ca8765e71 100644 --- a/apps/opencs/model/world/universalid.hpp +++ b/apps/opencs/model/world/universalid.hpp @@ -81,7 +81,8 @@ namespace CSMWorld Type_Static, Type_Weapon, Type_References, - Type_Reference + Type_Reference, + Type_RegionMap }; private: diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index bcc0203504..cdc161bd84 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -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); diff --git a/apps/opencs/view/doc/view.hpp b/apps/opencs/view/doc/view.hpp index b3c4ae22ab..ff81f8223d 100644 --- a/apps/opencs/view/doc/view.hpp +++ b/apps/opencs/view/doc/view.hpp @@ -151,6 +151,8 @@ namespace CSVDoc void addReferencesSubView(); + void addRegionMapSubView(); + void showUserSettings(); }; } diff --git a/apps/opencs/view/world/regionmapsubview.cpp b/apps/opencs/view/world/regionmapsubview.cpp new file mode 100644 index 0000000000..b82c1afb54 --- /dev/null +++ b/apps/opencs/view/world/regionmapsubview.cpp @@ -0,0 +1,29 @@ + +#include "regionmapsubview.hpp" + +#include +#include + +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) +{ + +} \ No newline at end of file diff --git a/apps/opencs/view/world/regionmapsubview.hpp b/apps/opencs/view/world/regionmapsubview.hpp new file mode 100644 index 0000000000..1655107af3 --- /dev/null +++ b/apps/opencs/view/world/regionmapsubview.hpp @@ -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 diff --git a/apps/opencs/view/world/subviews.cpp b/apps/opencs/view/world/subviews.cpp index cd98ed4e06..1c06ea2f60 100644 --- a/apps/opencs/view/world/subviews.cpp +++ b/apps/opencs/view/world/subviews.cpp @@ -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); + manager.add (CSMWorld::UniversalId::Type_RegionMap, new CSVDoc::SubViewFactory); + // manager.add (CSMWorld::UniversalId::Type_Global, // new CSVDoc::SubViewFactoryWithCreateFlag (true)); } \ No newline at end of file