From 2df5dd0d888d16856d5df7b6648af7926a767e63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Tue, 13 Oct 2015 00:27:49 +0200 Subject: [PATCH] Improved grap info ordering --- lang/gpxsee_cs.ts | 2 +- src/elevationgraph.cpp | 2 +- src/elevationgraph.h | 2 ++ src/graph.cpp | 1 + src/infoitem.cpp | 32 +++++++++++++++++++------------- src/infoitem.h | 16 ++++++++++++++-- src/speedgraph.h | 2 ++ 7 files changed, 40 insertions(+), 17 deletions(-) diff --git a/lang/gpxsee_cs.ts b/lang/gpxsee_cs.ts index 2b287c20..573a38fb 100644 --- a/lang/gpxsee_cs.ts +++ b/lang/gpxsee_cs.ts @@ -222,7 +222,7 @@ Rádka %1 Průměr - + Maximum Maximum diff --git a/src/elevationgraph.cpp b/src/elevationgraph.cpp index 173f4cfd..ea1e0af3 100644 --- a/src/elevationgraph.cpp +++ b/src/elevationgraph.cpp @@ -44,8 +44,8 @@ void ElevationGraph::loadData(const QVector &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); } diff --git a/src/elevationgraph.h b/src/elevationgraph.h index 74a37767..d080eefe 100644 --- a/src/elevationgraph.h +++ b/src/elevationgraph.h @@ -5,6 +5,8 @@ class ElevationGraph : public Graph { + Q_OBJECT + public: ElevationGraph(); diff --git a/src/graph.cpp b/src/graph.cpp index 5bb04498..3a01f276 100644 --- a/src/graph.cpp +++ b/src/graph.cpp @@ -210,6 +210,7 @@ void Graph::clear() if (_info->scene() == _scene) _scene->removeItem(_info); + _info->clear(); _scene->clear(); _graphs.clear(); _colorShop.reset(); diff --git a/src/infoitem.cpp b/src/infoitem.cpp index 7bdd2f14..1d8a8349 100644 --- a/src/infoitem.cpp +++ b/src/infoitem.cpp @@ -17,15 +17,15 @@ QRectF InfoItem::boundingRect() const font.setPixelSize(FONT_SIZE); font.setFamily(FONT_FAMILY); QFontMetrics fm(font); - QMap::const_iterator i; + QList::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::const_iterator i; + QList::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; } diff --git a/src/infoitem.h b/src/infoitem.h index bfc87eef..40ff851d 100644 --- a/src/infoitem.h +++ b/src/infoitem.h @@ -2,7 +2,7 @@ #define INFOITEM_H #include -#include +#include 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 _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 _list; }; #endif // INFOITEM_H diff --git a/src/speedgraph.h b/src/speedgraph.h index b89d8fa6..39fe93d2 100644 --- a/src/speedgraph.h +++ b/src/speedgraph.h @@ -6,6 +6,8 @@ class SpeedGraph : public Graph { + Q_OBJECT + public: SpeedGraph();