mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 07:53:53 +00:00
added region map tooltips
This commit is contained in:
parent
c808bf2b23
commit
c26a6f884f
2 changed files with 59 additions and 12 deletions
|
@ -12,6 +12,19 @@
|
|||
|
||||
CSMWorld::RegionMap::CellDescription::CellDescription() : mDeleted (false) {}
|
||||
|
||||
CSMWorld::RegionMap::CellDescription::CellDescription (const Record<Cell>& cell)
|
||||
{
|
||||
const Cell& cell2 = cell.get();
|
||||
|
||||
if (!cell2.isExterior())
|
||||
throw std::logic_error ("Interior cell in region map");
|
||||
|
||||
mDeleted = cell.isDeleted();
|
||||
|
||||
mRegion = cell2.mRegion;
|
||||
mName = cell2.mName;
|
||||
}
|
||||
|
||||
CSMWorld::RegionMap::CellIndex CSMWorld::RegionMap::getIndex (const QModelIndex& index) const
|
||||
{
|
||||
return CellIndex (index.column()+mMin.first, index.row()+mMin.second);
|
||||
|
@ -53,12 +66,7 @@ void CSMWorld::RegionMap::buildMap()
|
|||
|
||||
if (cell2.isExterior())
|
||||
{
|
||||
CellDescription description;
|
||||
|
||||
if (cell.isDeleted())
|
||||
description.mDeleted = true;
|
||||
else
|
||||
description.mRegion = cell2.mRegion;
|
||||
CellDescription description (cell);
|
||||
|
||||
CellIndex index (cell2.mData.mX, cell2.mData.mY);
|
||||
|
||||
|
@ -106,12 +114,7 @@ void CSMWorld::RegionMap::addCells (int start, int end)
|
|||
{
|
||||
CellIndex index (cell2.mData.mX, cell2.mData.mY);
|
||||
|
||||
CellDescription description;
|
||||
|
||||
if (cell.isDeleted())
|
||||
description.mDeleted = true;
|
||||
else
|
||||
description.mRegion = cell2.mRegion;
|
||||
CellDescription description (cell);
|
||||
|
||||
addCell (index, description);
|
||||
}
|
||||
|
@ -363,6 +366,44 @@ QVariant CSMWorld::RegionMap::data (const QModelIndex& index, int role) const
|
|||
return QBrush (Qt::DiagCrossPattern);
|
||||
}
|
||||
|
||||
if (role==Qt::ToolTipRole)
|
||||
{
|
||||
CellIndex cellIndex = getIndex (index);
|
||||
|
||||
std::ostringstream stream;
|
||||
|
||||
stream << cellIndex.first << ", " << cellIndex.second;
|
||||
|
||||
std::map<CellIndex, CellDescription>::const_iterator cell =
|
||||
mMap.find (cellIndex);
|
||||
|
||||
if (cell!=mMap.end())
|
||||
{
|
||||
if (!cell->second.mName.empty())
|
||||
stream << " " << cell->second.mName;
|
||||
|
||||
if (cell->second.mDeleted)
|
||||
stream << " (deleted)";
|
||||
|
||||
if (!cell->second.mRegion.empty())
|
||||
{
|
||||
stream << "<br>";
|
||||
|
||||
std::map<std::string, unsigned int>::const_iterator iter =
|
||||
mColours.find (Misc::StringUtils::lowerCase (cell->second.mRegion));
|
||||
|
||||
if (iter!=mColours.end())
|
||||
stream << cell->second.mRegion;
|
||||
else
|
||||
stream << "<font color=red>" << cell->second.mRegion << "</font>";
|
||||
}
|
||||
}
|
||||
else
|
||||
stream << " (no cell)";
|
||||
|
||||
return QString::fromUtf8 (stream.str().c_str());
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
|
||||
#include <QAbstractTableModel>
|
||||
|
||||
#include "record.hpp"
|
||||
#include "cell.hpp"
|
||||
|
||||
namespace CSMWorld
|
||||
{
|
||||
class Data;
|
||||
|
@ -28,8 +31,11 @@ namespace CSMWorld
|
|||
{
|
||||
bool mDeleted;
|
||||
std::string mRegion;
|
||||
std::string mName;
|
||||
|
||||
CellDescription();
|
||||
|
||||
CellDescription (const Record<Cell>& cell);
|
||||
};
|
||||
|
||||
Data& mData;
|
||||
|
|
Loading…
Reference in a new issue