mirror of https://github.com/OpenMW/openmw.git
basic region map; non-interactive for now and working with dummy data instead of real cell/region records
parent
de5898c953
commit
4f05f2bddf
@ -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;
|
||||
}
|
@ -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
|
@ -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)
|
||||
{
|
||||
|
||||
}
|
@ -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
|
Loading…
Reference in New Issue