1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-07-14 19:04:23 +02:00

Compare commits

..

13 Commits
2.19 ... 2.20

Author SHA1 Message Date
a6b2a477a1 Version 2.20 2016-10-15 23:43:26 +02:00
0ca264b176 GUI plishing 2016-10-12 22:37:40 +02:00
be3c101c07 Fixed graph line distortion in PDF output 2016-10-12 20:38:18 +02:00
cb52ad8bc5 Better file select button 2016-10-11 03:17:30 +02:00
12d5dcc78c Improved error handling.
Code cleanup.
2016-10-11 00:19:42 +02:00
afd87c6fa2 Fixed POI loading
Better map signal handling
2016-10-09 23:58:24 +02:00
c7d68f924f POI code refactoring 2016-10-09 23:46:30 +02:00
89304c0d5c Fixed QT4 compile issue 2016-10-08 21:16:56 +02:00
c57a0f4061 Improved POI files open dialogue 2016-10-08 21:10:13 +02:00
f02ff1fa01 POI loading optimization 2016-10-08 14:53:10 +02:00
434df521fb Added missing drag&drop enable 2016-10-05 18:23:16 +02:00
9d90b97ba3 Added support for drag&drop 2016-10-04 10:16:46 +02:00
09631de5a2 Code cleanup 2016-10-02 23:26:48 +02:00
21 changed files with 488 additions and 304 deletions

View File

@ -1,5 +1,5 @@
TARGET = GPXSee
VERSION = 2.19
VERSION = 2.20
QT += core \
gui \
network

View File

@ -5,7 +5,7 @@
<name>ElevationGraph</name>
<message>
<location filename="../src/elevationgraph.cpp" line="48"/>
<location filename="../src/elevationgraph.h" line="16"/>
<location filename="../src/elevationgraph.h" line="13"/>
<source>Elevation</source>
<translation>Výška</translation>
</message>
@ -146,377 +146,392 @@
<context>
<name>GUI</name>
<message>
<location filename="../src/gui.cpp" line="513"/>
<location filename="../src/gui.cpp" line="518"/>
<source>GPXSee is distributed under the terms of the GNU General Public License version 3. For more info about GPXSee visit the project homepage at </source>
<translation>Program GPXSee je distribuován pod podmínkami licence GNU General Public License verze 3. Pro více informací navštivte stránky programu na adrese </translation>
</message>
<message>
<location filename="../src/gui.cpp" line="577"/>
<location filename="../src/gui.cpp" line="582"/>
<source>Open file</source>
<translation>Otevřít soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="658"/>
<location filename="../src/gui.cpp" line="661"/>
<source>Open POI file</source>
<translation>Otevřít POI soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="204"/>
<location filename="../src/gui.cpp" line="206"/>
<source>Open</source>
<translation>Otevřít</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="188"/>
<location filename="../src/gui.cpp" line="190"/>
<source>Quit</source>
<translation>Ukončit</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="196"/>
<location filename="../src/gui.cpp" line="529"/>
<location filename="../src/gui.cpp" line="530"/>
<location filename="../src/gui.cpp" line="198"/>
<location filename="../src/gui.cpp" line="534"/>
<location filename="../src/gui.cpp" line="535"/>
<source>Keyboard controls</source>
<translation>Ovládací klávesy</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="220"/>
<location filename="../src/gui.cpp" line="222"/>
<source>Close</source>
<translation>Zavřít</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="226"/>
<location filename="../src/gui.cpp" line="228"/>
<source>Reload</source>
<translation>Znovu načíst</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="446"/>
<location filename="../src/gui.cpp" line="449"/>
<source>Show</source>
<translation>Zobrazit</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="370"/>
<location filename="../src/gui.cpp" line="440"/>
<location filename="../src/gui.cpp" line="373"/>
<location filename="../src/gui.cpp" line="443"/>
<source>File</source>
<translation>Soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="194"/>
<location filename="../src/gui.cpp" line="552"/>
<location filename="../src/gui.cpp" line="553"/>
<location filename="../src/gui.cpp" line="196"/>
<location filename="../src/gui.cpp" line="557"/>
<location filename="../src/gui.cpp" line="558"/>
<source>Data sources</source>
<translation>Zdroje dat</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="234"/>
<location filename="../src/gui.cpp" line="236"/>
<source>Load POI file</source>
<translation>Nahrát POI soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="237"/>
<location filename="../src/gui.cpp" line="239"/>
<source>Close POI files</source>
<translation>Zavřit POI soubory</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="239"/>
<location filename="../src/gui.cpp" line="241"/>
<source>Overlap POIs</source>
<translation>Překrývat POI</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="243"/>
<location filename="../src/gui.cpp" line="245"/>
<source>Show POI labels</source>
<translation>Zobrazovat názvy POI</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="248"/>
<location filename="../src/gui.cpp" line="250"/>
<source>Show POIs</source>
<translation>Zobrazit POI</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="256"/>
<location filename="../src/gui.cpp" line="259"/>
<source>Show map</source>
<translation>Zobrazit mapu</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="262"/>
<location filename="../src/gui.cpp" line="265"/>
<source>Clear tile cache</source>
<translation>Vymazat mezipaměť dlaždic</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="271"/>
<location filename="../src/gui.cpp" line="275"/>
<location filename="../src/gui.cpp" line="539"/>
<location filename="../src/gui.cpp" line="274"/>
<location filename="../src/gui.cpp" line="278"/>
<location filename="../src/gui.cpp" line="544"/>
<source>Next map</source>
<translation>Následující mapa</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="282"/>
<location filename="../src/gui.cpp" line="285"/>
<source>Show tracks</source>
<translation>Zobrazit cesty</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="286"/>
<location filename="../src/gui.cpp" line="289"/>
<source>Show routes</source>
<translation>Zobrazit trasy</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="290"/>
<location filename="../src/gui.cpp" line="293"/>
<source>Show waypoints</source>
<translation>Zobrazit navigační body</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="294"/>
<location filename="../src/gui.cpp" line="297"/>
<source>Waypoint labels</source>
<translation>Názvy navigačních bodů</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="305"/>
<location filename="../src/gui.cpp" line="308"/>
<source>Show graphs</source>
<translation>Zobrazovat grafy</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="327"/>
<location filename="../src/gui.cpp" line="330"/>
<source>Show toolbars</source>
<translation>Zobrazovat nástrojové lišty</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="333"/>
<location filename="../src/gui.cpp" line="336"/>
<source>Metric</source>
<translation>Metrické</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="338"/>
<location filename="../src/gui.cpp" line="341"/>
<source>Imperial</source>
<translation>Imperiální</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="344"/>
<location filename="../src/gui.cpp" line="347"/>
<source>Fullscreen mode</source>
<translation>Celoobrazovkový režim</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="352"/>
<location filename="../src/gui.cpp" line="355"/>
<source>Next</source>
<translation>Následující</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="355"/>
<location filename="../src/gui.cpp" line="358"/>
<source>Previous</source>
<translation>Předchozí</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="359"/>
<location filename="../src/gui.cpp" line="362"/>
<source>Last</source>
<translation>Poslední</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="362"/>
<location filename="../src/gui.cpp" line="365"/>
<source>First</source>
<translation>První</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="384"/>
<location filename="../src/gui.cpp" line="387"/>
<source>Map</source>
<translation>Mapa</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="391"/>
<location filename="../src/gui.cpp" line="394"/>
<source>Graph</source>
<translation>Graf</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="397"/>
<location filename="../src/gui.cpp" line="400"/>
<source>POI</source>
<translation>POI</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="398"/>
<location filename="../src/gui.cpp" line="401"/>
<source>POI files</source>
<translation>POI soubory</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="409"/>
<location filename="../src/gui.cpp" line="412"/>
<source>Data</source>
<translation>Data</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="410"/>
<location filename="../src/gui.cpp" line="413"/>
<source>Display</source>
<translation>Zobrazit</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="418"/>
<location filename="../src/gui.cpp" line="421"/>
<source>Settings</source>
<translation>Nastavení</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="419"/>
<location filename="../src/gui.cpp" line="422"/>
<source>Units</source>
<translation>Jednotky</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="427"/>
<location filename="../src/gui.cpp" line="430"/>
<source>Help</source>
<translation>Nápověda</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="541"/>
<location filename="../src/gui.cpp" line="546"/>
<source>Previous map</source>
<translation>Předchozí mapa</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="746"/>
<location filename="../src/gui.cpp" line="749"/>
<location filename="../src/gui.cpp" line="663"/>
<source>GPX files (*.gpx)</source>
<translation>Soubory GPX (*.gpx)</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="663"/>
<source>CSV files (*.csv)</source>
<translation>Soubory CSV (*.csv)</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="664"/>
<source>All files (*)</source>
<translation>Všechny soubory (*)</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="752"/>
<location filename="../src/gui.cpp" line="755"/>
<source>Date</source>
<translation>Datum</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="758"/>
<location filename="../src/gui.cpp" line="764"/>
<source>Routes</source>
<translation>Trasy</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="948"/>
<location filename="../src/gui.cpp" line="946"/>
<source>No GPX files loaded</source>
<translation>Nejsou načteny žádné GPX soubory</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="952"/>
<location filename="../src/gui.cpp" line="950"/>
<source>%1 files</source>
<translation>%1 souborů</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="532"/>
<location filename="../src/gui.cpp" line="537"/>
<source>Next file</source>
<translation>Následující soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="509"/>
<location filename="../src/gui.cpp" line="514"/>
<source>Version </source>
<translation>Verze </translation>
</message>
<message>
<location filename="../src/gui.cpp" line="209"/>
<location filename="../src/gui.cpp" line="211"/>
<source>Print...</source>
<translation>Tisknout...</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="214"/>
<location filename="../src/gui.cpp" line="216"/>
<source>Export to PDF...</source>
<translation>Exportovat do PDF...</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="760"/>
<location filename="../src/gui.cpp" line="662"/>
<source>All POI files (*.gpx *.csv)</source>
<translation>Všechny POI soubory (*.gpx *.csv)</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="766"/>
<source>Waypoints</source>
<translation>Navigační body</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="533"/>
<location filename="../src/gui.cpp" line="538"/>
<source>Previous file</source>
<translation>Předchozí soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="298"/>
<location filename="../src/gui.cpp" line="301"/>
<source>Route waypoints</source>
<translation>Body tras</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="535"/>
<location filename="../src/gui.cpp" line="540"/>
<source>First file</source>
<translation>První soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="536"/>
<location filename="../src/gui.cpp" line="541"/>
<source>Last file</source>
<translation>Poslední soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="537"/>
<location filename="../src/gui.cpp" line="542"/>
<source>Append modifier</source>
<translation>Modifikátor nahradit/přidat</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="556"/>
<location filename="../src/gui.cpp" line="561"/>
<source>Map (tiles) source URLs are read on program startup from the following file:</source>
<translation>URL mapových zdrojů (dlaždic) jsou načteny při startu programu z následujícího souboru:</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="559"/>
<location filename="../src/gui.cpp" line="564"/>
<source>The file format is one map entry per line, consisting of the map name and tiles URL delimited by a TAB character. The tile X and Y coordinates are replaced with $x and $y in the URL and the zoom level is replaced with $z. An example map file could look like:</source>
<translation>Formát souboru je jeden mapový záznam na řádku, kde mapový záznam sestává ze jména mapy a URL dlaždic navzájem oddělených tabulátorem. Souřadnice dlaždice jsou v URL nahrazeny řetězci $x a $y, úroven přiblížení (zoom) pak řetězcem $z. Příklad:</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="567"/>
<location filename="../src/gui.cpp" line="572"/>
<source>To make GPXSee load a POI file automatically on startup, add the file to the following directory:</source>
<translation>POI soubory, které se mají automaticky nahrát při startu programu jsou načítány z následujícího adresáře:</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="578"/>
<location filename="../src/gui.cpp" line="583"/>
<source>GPX files (*.gpx);;All files (*)</source>
<translation>Soubory GPX (*.gpx);;Všechny soubory (*)</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="649"/>
<location filename="../src/gui.cpp" line="675"/>
<location filename="../src/gui.cpp" line="652"/>
<location filename="../src/gui.cpp" line="680"/>
<source>Line: %1</source>
<translation>Řádka: %1</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="659"/>
<source>GPX files (*.gpx);;CSV files (*.csv);;All files (*)</source>
<translation>Soubory GPX (*.gpx);;Soubory CSV (*.csv);;Všechny soubory (*)</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="756"/>
<location filename="../src/gui.cpp" line="762"/>
<source>Tracks</source>
<translation>Cesty</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="199"/>
<location filename="../src/gui.cpp" line="507"/>
<location filename="../src/gui.cpp" line="201"/>
<location filename="../src/gui.cpp" line="512"/>
<source>About GPXSee</source>
<translation>O aplikaci GPXSee</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="451"/>
<location filename="../src/gui.cpp" line="454"/>
<source>Navigation</source>
<translation>Navigace</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="555"/>
<location filename="../src/gui.cpp" line="560"/>
<source>Map sources</source>
<translation>Mapové zdroje</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="566"/>
<location filename="../src/gui.cpp" line="571"/>
<source>POIs</source>
<translation>POI body</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="313"/>
<location filename="../src/gui.cpp" line="763"/>
<location filename="../src/gui.cpp" line="316"/>
<location filename="../src/gui.cpp" line="769"/>
<source>Distance</source>
<translation>Vzdálenost</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="319"/>
<location filename="../src/gui.cpp" line="765"/>
<location filename="../src/gui.cpp" line="322"/>
<location filename="../src/gui.cpp" line="771"/>
<source>Time</source>
<translation>Čas</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="651"/>
<location filename="../src/gui.cpp" line="676"/>
<location filename="../src/gui.cpp" line="654"/>
<location filename="../src/gui.cpp" line="681"/>
<source>Error</source>
<translation>Chyba</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="646"/>
<location filename="../src/gui.cpp" line="649"/>
<source>Error loading GPX file:
%1</source>
<translation>Soubor GPX nelze otevřít:
%1</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="672"/>
<location filename="../src/gui.cpp" line="677"/>
<source>Error loading POI file:
%1</source>
<translation>Soubor POI nelze otevřít:
@ -575,7 +590,7 @@
<name>HeartRateGraph</name>
<message>
<location filename="../src/heartrategraph.cpp" line="11"/>
<location filename="../src/heartrategraph.h" line="15"/>
<location filename="../src/heartrategraph.h" line="13"/>
<source>Heart rate</source>
<translation>Tep</translation>
</message>
@ -655,7 +670,7 @@
<name>SpeedGraph</name>
<message>
<location filename="../src/speedgraph.cpp" line="12"/>
<location filename="../src/speedgraph.h" line="16"/>
<location filename="../src/speedgraph.h" line="14"/>
<source>Speed</source>
<translation>Rychlost</translation>
</message>
@ -684,7 +699,7 @@
<name>TemperatureGraph</name>
<message>
<location filename="../src/temperaturegraph.cpp" line="11"/>
<location filename="../src/temperaturegraph.h" line="15"/>
<location filename="../src/temperaturegraph.h" line="13"/>
<source>Temperature</source>
<translation>Teplota</translation>
</message>

View File

@ -4,7 +4,7 @@
; The name of the installer
Name "GPXSee"
; Program version
!define VERSION "2.19"
!define VERSION "2.20"
; The file to write
OutFile "GPXSee-${VERSION}.exe"

View File

@ -4,7 +4,7 @@
; The name of the installer
Name "GPXSee"
; Program version
!define VERSION "2.19"
!define VERSION "2.20"
; The file to write
OutFile "GPXSee-${VERSION}_x64.exe"

View File

@ -3,9 +3,6 @@
#include "graphtab.h"
class GPX;
class PathItem;
class ElevationGraph : public GraphTab
{
Q_OBJECT

View File

@ -91,6 +91,7 @@ ExportDialog::ExportDialog(QPrinter *printer, QWidget *parent)
line->setFrameShadow(QFrame::Sunken);
pageSetupLayout->addRow(line);
pageSetupLayout->addRow(tr("File:"), _fileSelect);
pageSetupLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
#else // Q_OS_MAC
pageSetupBox->setLayout(pageSetupLayout);
#endif // Q_OS_MAC

View File

@ -1,4 +1,5 @@
#include <QPushButton>
#include <QToolButton>
#include <QFileDialog>
#include <QHBoxLayout>
#include <QFileInfo>
@ -12,7 +13,13 @@ FileSelectWidget::FileSelectWidget(QWidget *parent) : QWidget(parent)
QFontMetrics fm(QApplication::font());
_edit = new QLineEdit();
_edit->setMinimumWidth(fm.boundingRect(QDir::homePath()).width());
_button = new QPushButton(tr("Browse..."));
#ifdef Q_OS_WIN32
_button = new QPushButton("...");
_button->setMaximumWidth(_button->sizeHint().width() / 2);
#else // Q_OS_WIN32
_button = new QToolButton();
_button->setText("...");
#endif // Q_OS_WIN32
connect(_button, SIGNAL(clicked()), this, SLOT(browse()));
QHBoxLayout *layout = new QHBoxLayout();
@ -20,6 +27,9 @@ FileSelectWidget::FileSelectWidget(QWidget *parent) : QWidget(parent)
layout->addWidget(_edit);
layout->addWidget(_button);
setLayout(layout);
QSizePolicy p(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
setSizePolicy(p);
}
void FileSelectWidget::browse()

View File

@ -5,6 +5,7 @@
#include <QLineEdit>
class QPushButton;
class QToolButton;
class FileSelectWidget : public QWidget
{
@ -22,7 +23,11 @@ private slots:
private:
QLineEdit *_edit;
#ifdef Q_OS_WIN32
QPushButton *_button;
#else // Q_OS_WIN32
QToolButton *_button;
#endif // Q_OS_WIN32
QString _filter;
};

View File

@ -15,6 +15,7 @@ public:
qreal s() const {return _s;}
qreal t() const {return _t;}
qreal y() const {return _y;}
qreal x(GraphType type) const {return (type == Distance) ? _s : _t;}
void setS(qreal s) {_s = s;}
void setT(qreal t) {_t = t;}

View File

@ -5,37 +5,6 @@
#define GRAPH_WIDTH 1
#define HOVER_WIDTH 2
static qreal yAtX(const QPainterPath &path, qreal x)
{
int low = 0;
int high = path.elementCount() - 1;
int mid = 0;
Q_ASSERT(high > low);
Q_ASSERT(x >= path.elementAt(low).x && x <= path.elementAt(high).x);
while (low <= high) {
mid = low + ((high - low) / 2);
const QPainterPath::Element &e = path.elementAt(mid);
if (e.x > x)
high = mid - 1;
else if (e.x < x)
low = mid + 1;
else
return e.y;
}
QLineF l;
if (path.elementAt(mid).x < x)
l = QLineF(path.elementAt(mid).x, path.elementAt(mid).y,
path.elementAt(mid+1).x, path.elementAt(mid+1).y);
else
l = QLineF(path.elementAt(mid-1).x, path.elementAt(mid-1).y,
path.elementAt(mid).x, path.elementAt(mid).y);
return l.pointAt((x - l.p1().x()) / (l.p2().x() - l.p1().x())).y();
}
static bool hasTime(const Graph &graph)
{
for (int i = 0; i < graph.count(); i++)
@ -49,20 +18,16 @@ GraphItem::GraphItem(const Graph &graph, QGraphicsItem *parent)
: QGraphicsObject(parent)
{
_id = 0;
_type = Distance;
_pen = QPen(Qt::black, GRAPH_WIDTH);
_pen.setCosmetic(true);
_distancePath.moveTo(graph.first().s(), -graph.first().y());
for (int i = 1; i < graph.size(); i++)
_distancePath.lineTo(graph.at(i).s(), -graph.at(i).y());
_type = Distance;
_graph = graph;
_sx = 1.0; _sy = 1.0;
_time = hasTime(_graph);
if (hasTime(graph)) {
_timePath.moveTo(graph.first().t(), -graph.first().y());
for (int i = 1; i < graph.size(); i++)
_timePath.lineTo(graph.at(i).t(), -graph.at(i).y());
}
updatePath();
updateBounds();
}
void GraphItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
@ -72,7 +37,7 @@ void GraphItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
Q_UNUSED(widget);
painter->setPen(_pen);
painter->drawPath((_type == Distance) ? _distancePath : _timePath);
painter->drawPath(_path);
/*
QPen p = QPen(QBrush(Qt::red), 0);
@ -84,7 +49,10 @@ void GraphItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
void GraphItem::setGraphType(GraphType type)
{
prepareGeometryChange();
_type = type;
updatePath();
updateBounds();
}
void GraphItem::setColor(const QColor &color)
@ -95,37 +63,62 @@ void GraphItem::setColor(const QColor &color)
qreal GraphItem::yAtX(qreal x)
{
return ::yAtX((_type == Distance) ? _distancePath : _timePath, x);
int low = 0;
int high = _graph.count() - 1;
int mid = 0;
Q_ASSERT(high > low);
Q_ASSERT(x >= _graph.at(low).x(_type) && x <= _graph.at(high).x(_type));
while (low <= high) {
mid = low + ((high - low) / 2);
const GraphPoint &p = _graph.at(mid);
if (p.x(_type) > x)
high = mid - 1;
else if (p.x(_type) < x)
low = mid + 1;
else
return -p.y();
}
QLineF l;
if (_graph.at(mid).x(_type) < x)
l = QLineF(_graph.at(mid).x(_type), _graph.at(mid).y(),
_graph.at(mid+1).x(_type), _graph.at(mid+1).y());
else
l = QLineF(_graph.at(mid-1).x(_type), _graph.at(mid-1).y(),
_graph.at(mid).x(_type), _graph.at(mid).y());
return -l.pointAt((x - l.p1().x()) / (l.p2().x() - l.p1().x())).y();
}
qreal GraphItem::distanceAtTime(qreal time)
{
int low = 0;
int high = _timePath.elementCount() - 1;
int high = _graph.count() - 1;
int mid = 0;
Q_ASSERT(high > low);
Q_ASSERT(time >= _timePath.elementAt(low).x
&& time <= _timePath.elementAt(high).x);
Q_ASSERT(time >= _graph.at(low).t() && time <= _graph.at(high).t());
while (low <= high) {
mid = low + ((high - low) / 2);
const QPainterPath::Element &e = _timePath.elementAt(mid);
if (e.x > time)
const GraphPoint &p = _graph.at(mid);
if (p.t() > time)
high = mid - 1;
else if (e.x < time)
else if (p.t() < time)
low = mid + 1;
else
return _distancePath.elementAt(mid).x;
return _graph.at(mid).s();
}
QLineF l;
if (_timePath.elementAt(mid).x < time)
l = QLineF(_timePath.elementAt(mid).x, _distancePath.elementAt(mid).x,
_timePath.elementAt(mid+1).x, _distancePath.elementAt(mid+1).x);
if (_graph.at(mid).t() < time)
l = QLineF(_graph.at(mid).t(), _graph.at(mid).s(), _graph.at(mid+1).t(),
_graph.at(mid+1).s());
else
l = QLineF(_timePath.elementAt(mid-1).x, _distancePath.elementAt(mid-1).x,
_timePath.elementAt(mid).x, _distancePath.elementAt(mid).x);
l = QLineF(_graph.at(mid-1).t(), _graph.at(mid-1).s(),
_graph.at(mid).t(), _graph.at(mid).s());
return l.pointAt((time - l.p1().x()) / (l.p2().x() - l.p1().x())).y();
}
@ -133,15 +126,13 @@ qreal GraphItem::distanceAtTime(qreal time)
void GraphItem::emitSliderPositionChanged(qreal pos)
{
if (_type == Time) {
if (!_timePath.isEmpty()) {
if (pos <= _timePath.elementAt(_timePath.elementCount() - 1).x)
if (_time) {
if (pos <= _graph.last().t())
emit sliderPositionChanged(distanceAtTime(pos));
else
emit sliderPositionChanged(_distancePath.elementAt(
_distancePath.elementCount() - 1).x + 1);
emit sliderPositionChanged(_graph.last().s() + 1);
} else
emit sliderPositionChanged(_distancePath.elementAt(
_distancePath.elementCount() - 1).x + 1);
emit sliderPositionChanged(_graph.last().s() + 1);
} else
emit sliderPositionChanged(pos);
}
@ -158,3 +149,47 @@ void GraphItem::selected(bool selected)
update();
}
void GraphItem::setScale(qreal sx, qreal sy)
{
if (_sx == sx && _sy == sy)
return;
prepareGeometryChange();
_sx = sx; _sy = sy;
updatePath();
}
void GraphItem::updatePath()
{
_path = QPainterPath();
if (_type == Time && !_time)
return;
_path.moveTo(_graph.first().x(_type) * _sx, -_graph.first().y() * _sy);
for (int i = 1; i < _graph.size(); i++)
_path.lineTo(_graph.at(i).x(_type) * _sx, -_graph.at(i).y() * _sy);
}
void GraphItem::updateBounds()
{
if (_type == Time && !_time) {
_bounds = QRectF();
return;
}
qreal bottom, top, left, right;
QPointF p = QPointF(_graph.first().x(_type), -_graph.first().y());
bottom = p.y(); top = p.y(); left = p.x(); right = p.x();
for (int i = 1; i < _graph.size(); i++) {
p = QPointF(_graph.at(i).x(_type), -_graph.at(i).y());
bottom = qMax(bottom, p.y()); top = qMin(top, p.y());
right = qMax(right, p.x()); left = qMin(left, p.x());
}
_bounds = QRectF(QPointF(left, top), QPointF(right, bottom));
}

View File

@ -13,11 +13,13 @@ public:
GraphItem(const Graph &graph, QGraphicsItem *parent = 0);
QRectF boundingRect() const
{return (_type == Distance) ? _distancePath.boundingRect()
: _timePath.boundingRect();}
{return _path.boundingRect();}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
const QRectF &bounds() const {return _bounds;}
void setScale(qreal sx, qreal sy);
void setGraphType(GraphType type);
int id() const {return _id;}
void setId(int id) {_id = id;}
@ -34,10 +36,19 @@ public slots:
void selected(bool selected);
private:
void updatePath();
void updateBounds();
int _id;
QPen _pen;
QPainterPath _distancePath, _timePath;
Graph _graph;
GraphType _type;
bool _time;
QPainterPath _path;
QRectF _bounds;
qreal _sx, _sy;
};
#endif // GRAPHITEM_H

View File

@ -153,7 +153,7 @@ void GraphView::setGraphType(GraphType type)
for (int i = 0; i < _graphs.count(); i++) {
_graphs.at(i)->setGraphType(type);
if (_graphs.at(i)->scene() == _scene)
_bounds |= _graphs.at(i)->boundingRect();
_bounds |= _graphs.at(i)->bounds();
}
if (type == Distance)
@ -186,7 +186,7 @@ void GraphView::loadGraph(const Graph &graph, PathItem *path, int id)
if (!_hide.contains(id)) {
_visible.append(gi);
_scene->addItem(gi);
_bounds |= gi->boundingRect();
_bounds |= gi->bounds();
setXUnits();
}
}
@ -219,7 +219,7 @@ void GraphView::showGraph(bool show, int id)
else {
addItem(gi);
_visible.append(gi);
_bounds |= gi->boundingRect();
_bounds |= gi->bounds();
}
}
}
@ -241,8 +241,7 @@ void GraphView::redraw(const QSizeF &size)
QRectF r;
QSizeF mx, my;
RangeF rx, ry;
QTransform transform;
qreal xs, ys;
qreal sx, sy;
if (_visible.isEmpty() || _bounds.isNull()) {
@ -275,20 +274,19 @@ void GraphView::redraw(const QSizeF &size)
r.adjust(0, -(_minYRange/2 - r.height()/2), 0,
_minYRange/2 - r.height()/2);
xs = (size.width() - (my.width() + mx.width())) / r.width();
ys = (size.height() - (mx.height() + my.height())
sx = (size.width() - (my.width() + mx.width())) / r.width();
sy = (size.height() - (mx.height() + my.height())
- _info->boundingRect().height()) / r.height();
transform.scale(xs, ys);
for (int i = 0; i < _visible.size(); i++)
_visible.at(i)->setTransform(transform);
_visible.at(i)->setScale(sx, sy);
QPointF p(r.left() * xs, r.top() * ys);
QSizeF s(r.width() * xs, r.height() * ys);
QPointF p(r.left() * sx, r.top() * sy);
QSizeF s(r.width() * sx, r.height() * sy);
r = QRectF(p, s);
if (r.height() < _minYRange * ys)
r.adjust(0, -(_minYRange/2 * ys - r.height()/2), 0,
(_minYRange/2) * ys - r.height()/2);
if (r.height() < _minYRange * sy)
r.adjust(0, -(_minYRange/2 * sy - r.height()/2), 0,
(_minYRange/2) * sy - r.height()/2);
_xAxis->setSize(r.width());
_yAxis->setSize(r.height());
@ -368,7 +366,7 @@ void GraphView::updateSliderInfo()
if (!_sliderInfo->isVisible())
return;
QRectF br(_visible.first()->boundingRect());
QRectF br(_visible.first()->bounds());
if (br.height() < _minYRange)
br.adjust(0, -(_minYRange/2 - br.height()/2), 0,
_minYRange/2 - br.height()/2);

View File

@ -18,6 +18,8 @@
#include <QLabel>
#include <QSettings>
#include <QLocale>
#include <QMimeData>
#include <QUrl>
#include <QPixmapCache>
#include "config.h"
#include "icons.h"
@ -92,6 +94,7 @@ GUI::GUI(QWidget *parent) : QMainWindow(parent)
_exportFileName = QString("%1/export.pdf").arg(QDir::currentPath());
_exportMargins = MarginsF(5.0, 5.0, 5.0, 5.0);
setAcceptDrops(true);
QPixmapCache::setCacheLimit(65536);
}
@ -117,13 +120,15 @@ void GUI::loadPOIs()
QDir userDir(USER_POI_DIR);
QDir globalDir(GLOBAL_POI_DIR);
_poi = new POI(this);
if (userDir.exists())
list = userDir.entryInfoList(QStringList(), QDir::Files);
else
list = globalDir.entryInfoList(QStringList(), QDir::Files);
for (int i = 0; i < list.size(); ++i)
_poi.loadFile(list.at(i).absoluteFilePath());
_poi->loadFile(list.at(i).absoluteFilePath());
}
void GUI::createMapActions()
@ -151,7 +156,7 @@ void GUI::createPOIFilesActions()
{
_poiFilesSM = new QSignalMapper(this);
for (int i = 0; i < _poi.files().count(); i++)
for (int i = 0; i < _poi->files().count(); i++)
createPOIFileAction(i);
connect(_poiFilesSM, SIGNAL(mapped(int)), this, SLOT(poiFileChecked(int)));
@ -159,7 +164,7 @@ void GUI::createPOIFilesActions()
QAction *GUI::createPOIFileAction(int index)
{
QAction *a = new QAction(QFileInfo(_poi.files().at(index)).fileName(),
QAction *a = new QAction(QFileInfo(_poi->files().at(index)).fileName(),
this);
a->setCheckable(true);
@ -248,7 +253,8 @@ void GUI::createActions()
tr("Show POIs"), this);
_showPOIAction->setCheckable(true);
_showPOIAction->setShortcut(SHOW_POI_SHORTCUT);
connect(_showPOIAction, SIGNAL(triggered(bool)), this, SLOT(showPOI(bool)));
connect(_showPOIAction, SIGNAL(triggered(bool)), _pathView,
SLOT(showPOI(bool)));
addAction(_showPOIAction);
createPOIFilesActions();
@ -461,6 +467,8 @@ void GUI::createPathView()
#ifdef Q_OS_WIN32
_pathView->setFrameShape(QFrame::NoFrame);
#endif // Q_OS_WIN32
_pathView->setPOI(_poi);
}
void GUI::createGraphTabs()
@ -620,8 +628,6 @@ bool GUI::loadFile(const QString &fileName)
_tabs.at(i)->loadGPX(gpx, paths);
updateGraphTabs();
_pathView->setHidden(false);
if (_showPOIAction->isChecked())
_pathView->loadPOI(_poi);
for (int i = 0; i < gpx.tracks().count(); i++) {
_trackDistance += gpx.tracks().at(i)->distance();
@ -656,7 +662,9 @@ bool GUI::loadFile(const QString &fileName)
void GUI::openPOIFile()
{
QStringList files = QFileDialog::getOpenFileNames(this, tr("Open POI file"),
QString(), tr("GPX files (*.gpx);;CSV files (*.csv);;All files (*)"));
QString(), tr("All POI files (*.gpx *.csv)") + ";;"
+ tr("GPX files (*.gpx)") + ";;" + tr("CSV files (*.csv)") + ";;"
+ tr("All files (*)"));
QStringList list = files;
for (QStringList::Iterator it = list.begin(); it != list.end(); it++)
@ -665,21 +673,22 @@ void GUI::openPOIFile()
bool GUI::openPOIFile(const QString &fileName)
{
if (fileName.isEmpty())
if (fileName.isEmpty() || _poi->files().contains(fileName))
return false;
if (!_poi.loadFile(fileName)) {
QString error = tr("Error loading POI file:\n%1")
.arg(_poi.errorString()) + QString("\n");
if (_poi.errorLine())
error.append(tr("Line: %1").arg(_poi.errorLine()));
if (!_poi->loadFile(fileName)) {
QString error = fileName + QString("\n\n")
+ tr("Error loading POI file:\n%1").arg(_poi->errorString())
+ QString("\n");
if (_poi->errorLine())
error.append(tr("Line: %1").arg(_poi->errorLine()));
QMessageBox::critical(this, tr("Error"), error);
return false;
} else {
_pathView->showPOI(true);
_showPOIAction->setChecked(true);
_pathView->loadPOI(_poi);
QAction *action = createPOIFileAction(_poi.files().indexOf(fileName));
QAction *action = createPOIFileAction(_poi->files().indexOf(fileName));
action->setChecked(true);
_poiFilesMenu->addAction(action);
@ -695,9 +704,7 @@ void GUI::closePOIFiles()
delete _poiFilesActions[i];
_poiFilesActions.clear();
_pathView->clearPOI();
_poi.clear();
_poi->clear();
}
void GUI::printFile()
@ -851,14 +858,6 @@ void GUI::closeAll()
updateTrackView();
}
void GUI::showPOI(bool checked)
{
if (checked)
_pathView->loadPOI(_poi);
else
_pathView->clearPOI();
}
void GUI::showMap(bool checked)
{
if (checked)
@ -1002,12 +1001,8 @@ void GUI::prevMap()
void GUI::poiFileChecked(int index)
{
_poi.enableFile(_poi.files().at(index),
_poi->enableFile(_poi->files().at(index),
_poiFilesActions.at(index)->isChecked());
_pathView->clearPOI();
if (_showPOIAction->isChecked())
_pathView->loadPOI(_poi);
}
void GUI::sliderPositionChanged(qreal pos)
@ -1173,6 +1168,28 @@ void GUI::closeEvent(QCloseEvent *event)
event->accept();
}
void GUI::dragEnterEvent(QDragEnterEvent *event)
{
if (!event->mimeData()->hasUrls())
return;
if (event->proposedAction() != Qt::CopyAction)
return;
QList<QUrl> urls = event->mimeData()->urls();
for (int i = 0; i < urls.size(); i++)
if (!urls.at(i).isLocalFile())
return;
event->acceptProposedAction();
}
void GUI::dropEvent(QDropEvent *event)
{
QList<QUrl> urls = event->mimeData()->urls();
for (int i = 0; i < urls.size(); i++)
openFile(urls.at(i).toLocalFile());
}
void GUI::writeSettings()
{
QSettings settings(APP_NAME, APP_NAME);
@ -1209,7 +1226,7 @@ void GUI::writeSettings()
for (int i = 0, j = 0; i < _poiFilesActions.count(); i++) {
if (!_poiFilesActions.at(i)->isChecked()) {
settings.setArrayIndex(j++);
settings.setValue(DISABLED_POI_FILE_SETTING, _poi.files().at(i));
settings.setValue(DISABLED_POI_FILE_SETTING, _poi->files().at(i));
}
}
settings.endArray();
@ -1287,15 +1304,17 @@ void GUI::readSettings()
_showPOILabelsAction->setChecked(true);
if (settings.value(SHOW_POI_SETTING, false).toBool() == true)
_showPOIAction->setChecked(true);
else
_pathView->showPOI(false);
for (int i = 0; i < _poiFilesActions.count(); i++)
_poiFilesActions.at(i)->setChecked(true);
int size = settings.beginReadArray(DISABLED_POI_FILE_SETTINGS_PREFIX);
for (int i = 0; i < size; i++) {
settings.setArrayIndex(i);
int index = _poi.files().indexOf(settings.value(
int index = _poi->files().indexOf(settings.value(
DISABLED_POI_FILE_SETTING).toString());
if (index >= 0) {
_poi.enableFile(_poi.files().at(index), false);
_poi->enableFile(_poi->files().at(index), false);
_poiFilesActions.at(index)->setChecked(false);
}
}

View File

@ -45,7 +45,6 @@ private slots:
void reloadFile();
void openPOIFile();
void closePOIFiles();
void showPOI(bool checked);
void showMap(bool checked);
void showGraphs(bool checked);
void showToolbars(bool checked);
@ -110,6 +109,8 @@ private:
void keyPressEvent(QKeyEvent *event);
void closeEvent(QCloseEvent *event);
void dragEnterEvent(QDragEnterEvent *event);
void dropEvent(QDropEvent *event);
QToolBar *_fileToolBar;
QToolBar *_showToolBar;
@ -166,7 +167,7 @@ private:
QTabWidget *_graphTabWidget;
QList<GraphTab*> _tabs;
POI _poi;
POI *_poi;
QList<Map*> _maps;
FileBrowser *_browser;

View File

@ -3,8 +3,6 @@
#include "graphtab.h"
class GPX;
class HeartRateGraph : public GraphTab
{
Q_OBJECT

View File

@ -26,6 +26,7 @@ PathView::PathView(QWidget *parent)
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setRenderHints(QPainter::Antialiasing);
setAcceptDrops(false);
_mapScale = new ScaleItem();
_mapScale->setZValue(2.0);
@ -33,6 +34,7 @@ PathView::PathView(QWidget *parent)
_zoom = ZOOM_MAX;
_scale = mapScale(_zoom);
_map = 0;
_poi = 0;
_units = Metric;
@ -40,6 +42,7 @@ PathView::PathView(QWidget *parent)
_showRoutes = true;
_showWaypoints = true;
_showWaypointLabels = true;
_showPOI = true;
_showPOILabels = true;
_overlapPOIs = true;
_showRouteWaypoints = true;
@ -69,6 +72,9 @@ PathItem *PathView::addTrack(const Track &track)
ti->setVisible(_showTracks);
_scene->addItem(ti);
if (_poi)
addPOI(_poi->points(ti));
return ti;
}
@ -90,6 +96,9 @@ PathItem *PathView::addRoute(const Route &route)
ri->showWaypointLabels(_showWaypointLabels);
_scene->addItem(ri);
if (_poi)
addPOI(_poi->points(ri));
return ri;
}
@ -108,6 +117,9 @@ void PathView::addWaypoints(const QList<Waypoint> &waypoints)
_waypoints.append(wi);
}
if (_poi)
addPOI(_poi->points(waypoints));
_zoom = qMin(_zoom, scale2zoom(waypointScale()));
_scale = mapScale(_zoom);
}
@ -130,6 +142,8 @@ QList<PathItem *> PathView::loadGPX(const GPX &gpx)
if ((_tracks.size() + _routes.size() > 1 && _zoom < zoom)
|| (_waypoints.size() && _zoom < zoom))
rescale(_scale);
else
updatePOIVisibility();
QRectF br = trackBoundingRect() | routeBoundingRect()
| waypointBoundingRect();
@ -257,21 +271,31 @@ qreal PathView::mapScale(int zoom) const
return ((360.0/(qreal)(1<<zoom))/(qreal)TILE_SIZE);
}
void PathView::checkPOIOverlap()
void PathView::updatePOIVisibility()
{
QHash<Waypoint, WaypointItem*>::const_iterator it, jt;
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
for (jt = _pois.constBegin(); jt != _pois.constEnd(); jt++) {
if (it != jt && it.value()->isVisible() && jt.value()->isVisible()
&& it.value()->collidesWithItem(jt.value()))
jt.value()->hide();
if (!_showPOI)
return;
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
it.value()->show();
if (!_overlapPOIs) {
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
for (jt = _pois.constBegin(); jt != _pois.constEnd(); jt++) {
if (it.value()->isVisible() && jt.value()->isVisible()
&& it != jt && it.value()->collidesWithItem(jt.value()))
jt.value()->hide();
}
}
}
}
void PathView::rescale(qreal scale)
{
_scale = scale;
for (int i = 0; i < _tracks.size(); i++)
_tracks.at(i)->setScale(1.0/scale);
@ -282,15 +306,45 @@ void PathView::rescale(qreal scale)
_waypoints.at(i)->setScale(1.0/scale);
QHash<Waypoint, WaypointItem*>::const_iterator it;
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
it.value()->setScale(1.0/scale);
it.value()->show();
updatePOIVisibility();
}
void PathView::setPOI(POI *poi)
{
if (_poi)
disconnect(_poi, SIGNAL(pointsChanged()), this, SLOT(updatePOI()));
_poi = poi;
if (_poi)
connect(_poi, SIGNAL(pointsChanged()), this, SLOT(updatePOI()));
updatePOI();
}
void PathView::updatePOI()
{
QHash<Waypoint, WaypointItem*>::const_iterator it;
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
_scene->removeItem(it.value());
delete it.value();
}
_pois.clear();
if (!_overlapPOIs)
checkPOIOverlap();
if (!_poi)
return;
_scale = scale;
for (int i = 0; i < _tracks.size(); i++)
addPOI(_poi->points(_tracks.at(i)));
for (int i = 0; i < _routes.size(); i++)
addPOI(_poi->points(_routes.at(i)));
addPOI(_poi->points(_waypoints));
updatePOIVisibility();
}
void PathView::addPOI(const QVector<Waypoint> &waypoints)
@ -305,33 +359,23 @@ void PathView::addPOI(const QVector<Waypoint> &waypoints)
pi->setScale(1.0/_scale);
pi->setZValue(1);
pi->showLabel(_showPOILabels);
pi->setVisible(_showPOI);
_scene->addItem(pi);
_pois.insert(w, pi);
}
}
void PathView::loadPOI(const POI &poi)
{
if (!_tracks.size() && !_routes.size() && !_waypoints.size())
return;
for (int i = 0; i < _tracks.size(); i++)
addPOI(poi.points(_tracks.at(i)->path()));
for (int i = 0; i < _routes.size(); i++)
addPOI(poi.points(_routes.at(i)->path()));
addPOI(poi.points(_waypoints));
if (!_overlapPOIs)
checkPOIOverlap();
}
void PathView::setMap(Map *map)
{
_map = map;
if (_map)
connect(_map, SIGNAL(loaded()), this, SLOT(redraw()),
Qt::UniqueConnection);
disconnect(_map, SIGNAL(loaded()), this, SLOT(redraw()));
_map = map;
if (_map)
connect(_map, SIGNAL(loaded()), this, SLOT(redraw()));
resetCachedContent();
}
@ -453,18 +497,6 @@ void PathView::plot(QPainter *painter, const QRectF &target)
setUpdatesEnabled(true);
}
void PathView::clearPOI()
{
QHash<Waypoint, WaypointItem*>::const_iterator it;
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
_scene->removeItem(it.value());
delete it.value();
}
_pois.clear();
}
void PathView::clear()
{
if (_mapScale->scene() == _scene)
@ -526,6 +558,17 @@ void PathView::showRouteWaypoints(bool show)
_routes.at(i)->showWaypoints(show);
}
void PathView::showPOI(bool show)
{
_showPOI = show;
QHash<Waypoint, WaypointItem*>::const_iterator it;
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
it.value()->setVisible(show);
updatePOIVisibility();
}
void PathView::showPOILabels(bool show)
{
_showPOILabels = show;
@ -534,19 +577,14 @@ void PathView::showPOILabels(bool show)
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
it.value()->showLabel(show);
setPOIOverlap(_overlapPOIs);
updatePOIVisibility();
}
void PathView::setPOIOverlap(bool overlap)
{
_overlapPOIs = overlap;
if (_overlapPOIs) {
QHash<Waypoint, WaypointItem*>::const_iterator it;
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
it.value()->show();
} else
checkPOIOverlap();
updatePOIVisibility();
}
void PathView::drawBackground(QPainter *painter, const QRectF &rect)

View File

@ -30,10 +30,7 @@ public:
QList<PathItem*> loadGPX(const GPX &gpx);
void loadPOI(const POI &poi);
void clearPOI();
void clear();
void setPOI(POI *poi);
void setMap(Map *map);
void setUnits(enum Units units);
@ -43,9 +40,12 @@ public:
int routeCount() const {return _routes.count();}
int waypointCount() const {return _waypoints.count();}
void clear();
public slots:
void redraw();
void showPOI(bool show);
void setPOIOverlap(bool overlap);
void showWaypointLabels(bool show);
void showPOILabels(bool show);
@ -54,11 +54,16 @@ public slots:
void showWaypoints(bool show);
void showRouteWaypoints(bool show);
private slots:
void updatePOI();
private:
PathItem *addTrack(const Track &track);
PathItem *addRoute(const Route &route);
void addWaypoints(const QList<Waypoint> &waypoints);
void addPOI(const QVector<Waypoint> &waypoints);
void loadPOI();
void clearPOI();
QRectF trackBoundingRect() const;
QRectF routeBoundingRect() const;
@ -70,7 +75,7 @@ private:
void rescale(qreal scale);
void rescale();
void zoom(int z, const QPointF &pos);
void checkPOIOverlap();
void updatePOIVisibility();
void wheelEvent(QWheelEvent *event);
void keyPressEvent(QKeyEvent *event);
@ -79,13 +84,14 @@ private:
void paintEvent(QPaintEvent *e);
QGraphicsScene *_scene;
ScaleItem *_mapScale;
QList<TrackItem*> _tracks;
QList<RouteItem*> _routes;
QList<WaypointItem*> _waypoints;
QHash<Waypoint, WaypointItem*> _pois;
Map *_map;
ScaleItem *_mapScale;
POI *_poi;
Palette _palette;
@ -98,6 +104,7 @@ private:
bool _showRoutes;
bool _showWaypoints;
bool _showWaypointLabels;
bool _showPOI;
bool _showPOILabels;
bool _overlapPOIs;
bool _showRouteWaypoints;

View File

@ -1,13 +1,19 @@
#include <QFile>
#include <QSet>
#include <QList>
#include <QPainterPath>
#include "pathitem.h"
#include "waypointitem.h"
#include "ll.h"
#include "gpx.h"
#include "poi.h"
POI::POI(QObject *parent) : QObject(parent)
{
_errorLine = 0;
_radius = 0.01;
}
bool POI::loadFile(const QString &fileName)
{
QString error;
@ -16,15 +22,17 @@ bool POI::loadFile(const QString &fileName)
_error.clear();
_errorLine = 0;
if (loadCSVFile(fileName))
if (loadCSVFile(fileName)) {
emit pointsChanged();
return true;
else {
} else {
error = _error;
errorLine = _errorLine;
}
if (loadGPXFile(fileName))
if (loadGPXFile(fileName)) {
emit pointsChanged();
return true;
}
fprintf(stderr, "Error loading POI file: %s:\n", qPrintable(fileName));
fprintf(stderr, "CSV: line %d: %s\n", errorLine, qPrintable(error));
@ -90,20 +98,20 @@ bool POI::loadCSVFile(const QString &fileName)
QByteArray line = file.readLine();
QList<QByteArray> list = line.split(',');
if (list.size() < 3) {
_error = "Parse error";
_error = "Parse error.";
_errorLine = ln;
return false;
}
qreal lat = list[0].trimmed().toDouble(&ret);
if (!ret) {
_error = "Invalid latitude";
_error = "Invalid latitude.";
_errorLine = ln;
return false;
}
qreal lon = list[1].trimmed().toDouble(&ret);
if (!ret) {
_error = "Invalid longitude";
_error = "Invalid longitude.";
_errorLine = ln;
return false;
}
@ -145,18 +153,19 @@ static bool cb(size_t data, void* context)
return true;
}
QVector<Waypoint> POI::points(const QPainterPath &path, qreal radius) const
QVector<Waypoint> POI::points(const PathItem *path) const
{
QVector<Waypoint> ret;
QSet<int> set;
qreal min[2], max[2];
const QPainterPath &pp = path->path();
for (int i = 0; i < path.elementCount(); i++) {
QPointF p = mercator2ll(path.elementAt(i));
min[0] = p.x() - radius;
min[1] = -p.y() - radius;
max[0] = p.x() + radius;
max[1] = -p.y() + radius;
for (int i = 0; i < pp.elementCount(); i++) {
QPointF p = mercator2ll(pp.elementAt(i));
min[0] = p.x() - _radius;
min[1] = -p.y() - _radius;
max[0] = p.x() + _radius;
max[1] = -p.y() + _radius;
_tree.Search(min, max, cb, &set);
}
@ -169,7 +178,7 @@ QVector<Waypoint> POI::points(const QPainterPath &path, qreal radius) const
return ret;
}
QVector<Waypoint> POI::points(const QList<WaypointItem*> &list, qreal radius)
QVector<Waypoint> POI::points(const QList<WaypointItem*> &list)
const
{
QVector<Waypoint> ret;
@ -178,10 +187,34 @@ QVector<Waypoint> POI::points(const QList<WaypointItem*> &list, qreal radius)
for (int i = 0; i < list.count(); i++) {
const QPointF &p = list.at(i)->waypoint().coordinates();
min[0] = p.x() - radius;
min[1] = p.y() - radius;
max[0] = p.x() + radius;
max[1] = p.y() + radius;
min[0] = p.x() - _radius;
min[1] = p.y() - _radius;
max[0] = p.x() + _radius;
max[1] = p.y() + _radius;
_tree.Search(min, max, cb, &set);
}
QSet<int>::const_iterator i = set.constBegin();
while (i != set.constEnd()) {
ret.append(_data.at(*i));
++i;
}
return ret;
}
QVector<Waypoint> POI::points(const QList<Waypoint> &list) const
{
QVector<Waypoint> ret;
QSet<int> set;
qreal min[2], max[2];
for (int i = 0; i < list.count(); i++) {
const QPointF &p = list.at(i).coordinates();
min[0] = p.x() - _radius;
min[1] = p.y() - _radius;
max[0] = p.x() + _radius;
max[1] = p.y() + _radius;
_tree.Search(min, max, cb, &set);
}
@ -216,6 +249,8 @@ void POI::enableFile(const QString &fileName, bool enable)
_tree.Insert(c, c, j);
}
}
emit pointsChanged();
}
void POI::clear()
@ -224,4 +259,13 @@ void POI::clear()
_data.clear();
_files.clear();
_indexes.clear();
emit pointsChanged();
}
void POI::setRadius(qreal radius)
{
_radius = radius;
emit pointsChanged();
}

View File

@ -8,28 +8,34 @@
#include "waypoint.h"
#include "rtree.h"
class QPainterPath;
class PathItem;
class WaypointItem;
#define POI_RADIUS 0.01
class POI
class POI : public QObject
{
Q_OBJECT
public:
POI() : _errorLine(0) {}
POI(QObject *parent = 0);
bool loadFile(const QString &fileName);
const QString &errorString() const {return _error;}
int errorLine() const {return _errorLine;}
QVector<Waypoint> points(const QPainterPath &path,
qreal radius = POI_RADIUS) const;
QVector<Waypoint> points(const QList<WaypointItem*> &list,
qreal radius = POI_RADIUS) const;
qreal radius() const {return _radius;}
void setRadius(qreal radius);
QVector<Waypoint> points(const PathItem *path) const;
QVector<Waypoint> points(const QList<WaypointItem*> &list) const;
QVector<Waypoint> points(const QList<Waypoint> &list) const;
const QStringList &files() const {return _files;}
void enableFile(const QString &fileName, bool enable);
void clear();
signals:
void pointsChanged();
private:
typedef RTree<size_t, qreal, 2> POITree;
typedef struct {
@ -46,6 +52,8 @@ private:
QStringList _files;
QList<FileIndex> _indexes;
qreal _radius;
QString _error;
int _errorLine;
};

View File

@ -4,8 +4,6 @@
#include <QList>
#include "graphtab.h"
class GPX;
class SpeedGraph : public GraphTab
{
Q_OBJECT

View File

@ -3,8 +3,6 @@
#include "graphtab.h"
class GPX;
class TemperatureGraph : public GraphTab
{
Q_OBJECT