167 lines
3.5 KiB
C++
Executable File
167 lines
3.5 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* Interface for JumpPointWidget
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*/
|
|
|
|
|
|
// Own
|
|
#include "jump_point_model.h"
|
|
#include <Map/map.h>
|
|
#include <Map/object_factory.h>
|
|
#include <Map/situation_map_utils.h>
|
|
#include <MapImpl/layer_factory_impl.h>
|
|
#include <MapImpl/coord_translation_functor_impl.h>
|
|
|
|
|
|
// Qt
|
|
#include <QBuffer>
|
|
|
|
|
|
namespace SituationMap
|
|
{
|
|
|
|
//----------------------------------------------------------------------------
|
|
// JumpPointModel
|
|
//----------------------------------------------------------------------------
|
|
|
|
JumpPointModel::JumpPointModel(QObject *parent)
|
|
: BaseClass( {tr("Name"), tr("OriginGeo"), tr("Origin"), tr("Scale"), tr("Icon")}, parent)
|
|
{
|
|
}
|
|
|
|
void JumpPointModel::setMap(Map *map)
|
|
{
|
|
m_map = map;
|
|
}
|
|
|
|
QVariant JumpPointModel::data(const QModelIndex &index, int role) const
|
|
{
|
|
if ((role != Qt::DisplayRole && role != Qt::ToolTipRole && role != Qt::EditRole) || !indexIsValid(index))
|
|
return QVariant();
|
|
|
|
const JPData &data = m_vecData.at(index.row());
|
|
|
|
if (role==Qt::ToolTipRole)
|
|
{
|
|
QString tooltip;
|
|
tooltip.append(QStringLiteral("<html>"));
|
|
|
|
const QImage &img = data.m_image;
|
|
|
|
if (! img.isNull())
|
|
{
|
|
// without a temporary file:
|
|
QByteArray baData;
|
|
QBuffer buffer(&baData);
|
|
img.save(&buffer, "PNG", 100);
|
|
tooltip.append(QStringLiteral("<center><img src='data:image/png;base64,%1'></center>").arg(QString::fromLatin1(baData.toBase64()))); // how can i center the image?
|
|
tooltip.append(QLatin1String("<br />"));
|
|
}
|
|
tooltip.append(QStringLiteral("<p>name: %1</p>").arg(data.m_name));
|
|
tooltip.append(QStringLiteral("<p>origin: %1</p>").arg(m_map->geoToMgrsString(data.m_originGeo.toPointF())));
|
|
tooltip.append(QStringLiteral("<p>scale: %1</p>").arg(data.m_mapScale));
|
|
tooltip.append(QStringLiteral("</html>"));
|
|
return tooltip;
|
|
}
|
|
|
|
switch (index.column())
|
|
{
|
|
case NAME:
|
|
return data.m_name;
|
|
case ORIGIN_GEO:
|
|
return data.m_originGeo.toPointF();
|
|
case ORIGIN_MGRS:
|
|
{
|
|
if (m_map)
|
|
return m_map->geoToMgrsString(data.m_originGeo.toPointF());
|
|
return QString();
|
|
}
|
|
case SCALE:
|
|
return data.m_mapScale;
|
|
case ICON:
|
|
return data.m_image;
|
|
}
|
|
|
|
return QVariant();
|
|
}
|
|
|
|
void JumpPointModel::addUpdateItem(const JPData &jpData)
|
|
{
|
|
int row = rowOfItem(jpData.m_name);
|
|
if (row >= 0)
|
|
setRowData(row, jpData); // UPDATE
|
|
else
|
|
insertRow(jpData); // APPEND
|
|
}
|
|
|
|
bool JumpPointModel::removeItem(const QString &name)
|
|
{
|
|
int row = rowOfItem(name);
|
|
if (row < 0)
|
|
return false;
|
|
removeRow(row);
|
|
return true;
|
|
}
|
|
|
|
bool JumpPointModel::contains(const QString &name)
|
|
{
|
|
return rowOfItem(name) >= 0;
|
|
}
|
|
|
|
int JumpPointModel::rowOfItem(const QString &name)
|
|
{
|
|
int row = -1;
|
|
for (const JPData &item : qAsConst(m_vecData))
|
|
{
|
|
++row;
|
|
if (item.m_name.compare(name) == 0)
|
|
return row;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
JPData *JumpPointModel::getItemPtr(const QModelIndex &index)
|
|
{
|
|
if (!indexIsValid(index))
|
|
return nullptr;
|
|
|
|
int row = index.row();
|
|
if (row < 0 || row > m_vecData.size())
|
|
return nullptr;
|
|
|
|
return &m_vecData[row];
|
|
}
|
|
|
|
JPData *JumpPointModel::getItemPtr(const QString &name)
|
|
{
|
|
int row = rowOfItem(name);
|
|
if (row < 0 || row > m_vecData.size())
|
|
return nullptr;
|
|
return &m_vecData[row];
|
|
|
|
}
|
|
|
|
QVector<JPData> JumpPointModel::jumpPoints()
|
|
{
|
|
return m_vecData;
|
|
}
|
|
|
|
QStringList JumpPointModel::names()
|
|
{
|
|
QStringList sl;
|
|
sl.reserve(m_vecData.size());
|
|
|
|
for (const JPData &item : qAsConst(m_vecData))
|
|
sl.append(item.m_name);
|
|
return sl;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace SituationMap
|