1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-27 21:24:47 +01:00

Improved grap info ordering

This commit is contained in:
Martin Tůma 2015-10-13 00:27:49 +02:00
parent 96e8415e00
commit 2df5dd0d88
7 changed files with 40 additions and 17 deletions

View File

@ -222,7 +222,7 @@ Rádka %1</translation>
<translation>Průměr</translation>
</message>
<message>
<location filename="../src/speedgraph.cpp" line="43"/>
<location filename="../src/speedgraph.cpp" line="44"/>
<source>Maximum</source>
<translation>Maximum</translation>
</message>

View File

@ -44,8 +44,8 @@ void ElevationGraph::loadData(const QVector<QPointF> &data)
addInfo(tr("Ascent"), QString::number((int)_ascent) + " " + _yUnits);
addInfo(tr("Descent"), QString::number((int)_descent) + " " + _yUnits);
addInfo(tr("Minimum"), QString::number((int)_min) + " " + _yUnits);
addInfo(tr("Maximum"), QString::number((int)_max) + " " + _yUnits);
addInfo(tr("Minimum"), QString::number((int)_min) + " " + _yUnits);
Graph::loadData(data);
}

View File

@ -5,6 +5,8 @@
class ElevationGraph : public Graph
{
Q_OBJECT
public:
ElevationGraph();

View File

@ -210,6 +210,7 @@ void Graph::clear()
if (_info->scene() == _scene)
_scene->removeItem(_info);
_info->clear();
_scene->clear();
_graphs.clear();
_colorShop.reset();

View File

@ -17,15 +17,15 @@ QRectF InfoItem::boundingRect() const
font.setPixelSize(FONT_SIZE);
font.setFamily(FONT_FAMILY);
QFontMetrics fm(font);
QMap<QString, QString>::const_iterator i;
QList<KV>::const_iterator i;
int width = 0;
if (_map.isEmpty())
if (_list.isEmpty())
return QRectF();
for (i = _map.constBegin(); i != _map.constEnd(); i++) {
width += fm.width(i.key() + ": ");
width += fm.width(i.value()) + ((i == _map.end() - 1) ? 0 : PADDING);
for (i = _list.constBegin(); i != _list.constEnd(); i++) {
width += fm.width(i->key + ": ");
width += fm.width(i->value) + ((i == _list.end() - 1) ? 0 : PADDING);
}
return QRectF(0, 0, width, fm.height());
@ -41,15 +41,15 @@ void InfoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
font.setFamily(FONT_FAMILY);
painter->setFont(font);
QFontMetrics fm(font);
QMap<QString, QString>::const_iterator i;
QList<KV>::const_iterator i;
int width = 0;
for (i = _map.constBegin(); i != _map.constEnd(); i++) {
painter->drawText(width, fm.height() - fm.descent(), i.key() + ": ");
width += fm.width(i.key() + ": ");
painter->drawText(width, fm.height() - fm.descent(), i.value());
width += fm.width(i.value()) + ((i == _map.end() - 1) ? 0 : PADDING);
if (i != _map.end() - 1) {
for (i = _list.constBegin(); i != _list.constEnd(); i++) {
painter->drawText(width, fm.height() - fm.descent(), i->key + ": ");
width += fm.width(i->key + ": ");
painter->drawText(width, fm.height() - fm.descent(), i->value);
width += fm.width(i->value) + ((i == _list.end() - 1) ? 0 : PADDING);
if (i != _list.end() - 1) {
painter->save();
painter->setPen(Qt::gray);
painter->drawLine(width - PADDING/2, fm.descent(),
@ -66,5 +66,11 @@ void InfoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
void InfoItem::insert(const QString &key, const QString &value)
{
_map.insert(key, value);
KV kv(key, value);
int i;
if ((i = _list.indexOf(kv)) < 0)
_list.append(kv);
else
_list[i] = kv;
}

View File

@ -2,7 +2,7 @@
#define INFOITEM_H
#include <QGraphicsItem>
#include <QMap>
#include <QList>
class InfoItem : public QGraphicsItem
{
@ -14,9 +14,21 @@ public:
QWidget *widget);
void insert(const QString &key, const QString &value);
void clear() {_list.clear();}
private:
QMap<QString, QString> _map;
class KV {
public:
QString key;
QString value;
KV(const QString &k, const QString &v)
{key = k; value = v;}
bool operator==(const KV &other) const
{return this->key == other.key;}
};
QList<KV> _list;
};
#endif // INFOITEM_H

View File

@ -6,6 +6,8 @@
class SpeedGraph : public Graph
{
Q_OBJECT
public:
SpeedGraph();