Merge branch 'openmw-cs-regionmap-improvements' into 'master'

OpenMW CS: Minor region map fixes and improvements

See merge request OpenMW/openmw!3959
fix-osga-rotate-wildly
psi29a 10 months ago
commit 7dcd127295

@ -1,7 +1,9 @@
#include "regionmap.hpp"
#include <QApplication>
#include <QBrush>
#include <QModelIndex>
#include <QPalette>
#include <QSize>
#include <QVariant>
@ -21,20 +23,38 @@
#include "data.hpp"
#include "universalid.hpp"
namespace CSMWorld
{
float getLandHeight(const CSMWorld::Cell& cell, CSMWorld::Data& data)
{
const IdCollection<Land>& lands = data.getLand();
int landIndex = lands.searchId(cell.mId);
if (landIndex == -1)
return 0.0f;
// If any part of land is above water, returns > 0 - otherwise returns < 0
const Land& land = lands.getRecord(landIndex).get();
if (land.getLandData())
return land.getLandData()->mMaxHeight - cell.mWater;
return 0.0f;
}
}
CSMWorld::RegionMap::CellDescription::CellDescription()
: mDeleted(false)
{
}
CSMWorld::RegionMap::CellDescription::CellDescription(const Record<Cell>& cell)
CSMWorld::RegionMap::CellDescription::CellDescription(const Record<Cell>& cell, float landHeight)
{
const Cell& cell2 = cell.get();
if (!cell2.isExterior())
throw std::logic_error("Interior cell in region map");
mMaxLandHeight = landHeight;
mDeleted = cell.isDeleted();
mRegion = cell2.mRegion;
mName = cell2.mName;
}
@ -92,7 +112,7 @@ void CSMWorld::RegionMap::buildMap()
if (cell2.isExterior())
{
CellDescription description(cell);
CellDescription description(cell, getLandHeight(cell2, mData));
CellCoordinates index = getIndex(cell2);
@ -140,7 +160,7 @@ void CSMWorld::RegionMap::addCells(int start, int end)
{
CellCoordinates index = getIndex(cell2);
CellDescription description(cell);
CellDescription description(cell, getLandHeight(cell.get(), mData));
addCell(index, description);
}
@ -335,10 +355,11 @@ QVariant CSMWorld::RegionMap::data(const QModelIndex& index, int role) const
auto iter = mColours.find(cell->second.mRegion);
if (iter != mColours.end())
return QBrush(QColor(iter->second & 0xff, (iter->second >> 8) & 0xff, (iter->second >> 16) & 0xff));
return QBrush(QColor(iter->second & 0xff, (iter->second >> 8) & 0xff, (iter->second >> 16) & 0xff),
cell->second.mMaxLandHeight > 0 ? Qt::SolidPattern : Qt::CrossPattern);
if (cell->second.mRegion.empty())
return QBrush(Qt::Dense6Pattern); // no region
if (cell->second.mRegion.empty()) // no region
return QBrush(cell->second.mMaxLandHeight > 0 ? Qt::Dense3Pattern : Qt::Dense6Pattern);
return QBrush(Qt::red, Qt::Dense6Pattern); // invalid region
}

@ -40,13 +40,14 @@ namespace CSMWorld
private:
struct CellDescription
{
float mMaxLandHeight;
bool mDeleted;
ESM::RefId mRegion;
std::string mName;
CellDescription();
CellDescription(const Record<Cell>& cell);
CellDescription(const Record<Cell>& cell, float landHeight);
};
Data& mData;

@ -224,6 +224,10 @@ CSVWorld::RegionMap::RegionMap(const CSMWorld::UniversalId& universalId, CSMDoc:
addAction(mViewInTableAction);
setAcceptDrops(true);
// Make columns square incase QSizeHint doesnt apply
for (int column = 0; column < this->model()->columnCount(); ++column)
this->setColumnWidth(column, this->rowHeight(0));
}
void CSVWorld::RegionMap::selectAll()
@ -358,12 +362,23 @@ std::vector<CSMWorld::UniversalId> CSVWorld::RegionMap::getDraggedRecords() cons
return ids;
}
void CSVWorld::RegionMap::dragMoveEvent(QDragMoveEvent* event)
{
const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*>(event->mimeData());
if (mime != nullptr && (mime->holdsType(CSMWorld::UniversalId::Type_Region)))
{
event->accept();
return;
}
event->ignore();
}
void CSVWorld::RegionMap::dropEvent(QDropEvent* event)
{
QModelIndex index = indexAt(event->pos());
bool exists = QTableView::model()->data(index, Qt::BackgroundRole) != QBrush(Qt::DiagCrossPattern);
if (!index.isValid() || !exists)
{
return;

@ -59,6 +59,8 @@ namespace CSVWorld
void mouseMoveEvent(QMouseEvent* event) override;
void dragMoveEvent(QDragMoveEvent* event) override;
void dropEvent(QDropEvent* event) override;
public:

Loading…
Cancel
Save