1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-07-01 05:19:15 +02:00

Compare commits

...

16 Commits
1.0 ... 2.0

Author SHA1 Message Date
a809c81fd6 Some more info 2015-11-30 23:21:13 +01:00
df6aaf1883 Version 2.0 2015-11-30 23:20:46 +01:00
91bf49610d Added "data sources" help item
Now using a common directory for all data/configs
2015-11-30 22:42:51 +01:00
4e543782ec Fixed POI crash on vector reallocation
Improved error reporting
2015-11-26 19:13:59 +01:00
d1bf74f43b Yet another code cleanup 2015-11-26 00:21:11 +01:00
0b4ee95591 Code cleanup 2015-11-25 23:58:46 +01:00
5bd5b88be5 Added missing network lib 2015-11-25 23:18:07 +01:00
f54ca1529a Zooming & scrolling improvements 2015-11-25 23:17:39 +01:00
0c002bc1e9 Fixed track zoom computation on Qt5 2015-11-25 00:10:11 +01:00
b0cafe69d0 Fixed MSVC & Qt5 compile issues 2015-11-24 10:05:28 +01:00
f93b54aab0 Added support for show/hide the graphs and the toolbars 2015-11-24 00:24:26 +01:00
a9b3d2595e Updated czech translation 2015-11-23 23:24:13 +01:00
81c0789319 Map sources are now readed from config file 2015-11-23 23:19:57 +01:00
c639c6deac Added initial map support part #2 2015-11-23 02:37:08 +01:00
69095ca9eb Added initial map support 2015-11-23 02:33:01 +01:00
8a4b749d6b Fixed broken rendering with QT5 2015-10-22 10:27:27 +02:00
37 changed files with 922 additions and 227 deletions

View File

@ -1,4 +1,29 @@
# GPXSee
GPX viewer and analyzer
GPX viewer and analyzer.
GPXSee Web page: http://tumic.wz.cz/gpxsee
* User-definable map sources.
* Track and elevation/speed graphs.
* Support for multiple tracks in one view.
* Support for POI files (Garmin CSV format).
* Export to PDF.
* Native GUI for Windows, Mac OS X and Linux.
## Build
### Linux/OS X
```shell
lrelease gpxsee.pro
qmake gpxsee.pro
make
```
### Windows
```shell
lrelease gpxsee.pro
qmake gpxsee.pro
nmake release
```
## Binaries
Available at Sourceforge: http://sourceforge.net/projects/gpxsee
## Homepage
GPXSee homepage: http://tumic.wz.cz/gpxsee

View File

@ -63,7 +63,7 @@ Section "GPXSee (required)" SEC_APP
; Write the uninstall keys for Windows
WriteRegStr HKCU "${REGENTRY}" "DisplayName" "GPXSee"
WriteRegStr HKCU "${REGENTRY}" "Publisher" "Martin Tuma"
WriteRegStr HKCU "${REGENTRY}" "DisplayVersion" "1.0"
WriteRegStr HKCU "${REGENTRY}" "DisplayVersion" "2.0"
WriteRegStr HKCU "${REGENTRY}" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKCU "${REGENTRY}" "NoModify" 1
WriteRegDWORD HKCU "${REGENTRY}" "NoRepair" 1
@ -84,6 +84,7 @@ Section "QT libs" SEC_QT
File "Qt5Gui.dll"
File "Qt5Widgets.dll"
File "Qt5PrintSupport.dll"
File "Qt5Network.dll"
File "libGLESv2.dll"
File /r "platforms"

View File

@ -1,6 +1,7 @@
TARGET = GPXSee
QT += core \
gui
gui \
network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
greaterThan(QT_MAJOR_VERSION, 4): QT += printsupport
HEADERS += src/config.h \
@ -23,7 +24,10 @@ HEADERS += src/config.h \
src/elevationgraph.h \
src/speedgraph.h \
src/sliderinfoitem.h \
src/filebrowser.h
src/filebrowser.h \
src/map.h \
src/maplist.h \
src/downloader.h
SOURCES += src/main.cpp \
src/gui.cpp \
src/gpx.cpp \
@ -41,7 +45,10 @@ SOURCES += src/main.cpp \
src/elevationgraph.cpp \
src/speedgraph.cpp \
src/sliderinfoitem.cpp \
src/filebrowser.cpp
src/filebrowser.cpp \
src/map.cpp \
src/maplist.cpp \
src/downloader.cpp
RESOURCES += gpxsee.qrc
TRANSLATIONS = lang/gpxsee_cs.ts
macx:ICON = icons/gpxsee.icns

View File

@ -7,6 +7,7 @@
<file>icons/flag.png</file>
<file>icons/gpxsee.png</file>
<file>icons/application-exit.png</file>
<file>icons/applications-internet.png</file>
<file>icons/view-refresh.png</file>
<file>lang/gpxsee_cs.qm</file>
</qresource>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -4,42 +4,42 @@
<context>
<name>ElevationGraph</name>
<message>
<location filename="../src/elevationgraph.cpp" line="12"/>
<location filename="../src/elevationgraph.cpp" line="13"/>
<source>Distance</source>
<translation>Vzdálenost</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="13"/>
<location filename="../src/elevationgraph.cpp" line="14"/>
<source>Elevation</source>
<translation>Výška</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="14"/>
<location filename="../src/elevationgraph.cpp" line="15"/>
<source>km</source>
<translation>km</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="15"/>
<location filename="../src/elevationgraph.cpp" line="16"/>
<source>m</source>
<translation>m</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="51"/>
<location filename="../src/elevationgraph.cpp" line="52"/>
<source>Ascent</source>
<translation>Stoupání</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="53"/>
<location filename="../src/elevationgraph.cpp" line="54"/>
<source>Descent</source>
<translation>Klesání</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="57"/>
<location filename="../src/elevationgraph.cpp" line="58"/>
<source>Minimum</source>
<translation>Minimum</translation>
</message>
<message>
<location filename="../src/elevationgraph.cpp" line="55"/>
<location filename="../src/elevationgraph.cpp" line="56"/>
<source>Maximum</source>
<translation>Maximum</translation>
</message>
@ -47,253 +47,291 @@
<context>
<name>GUI</name>
<message>
<location filename="../src/gui.cpp" line="90"/>
<location filename="../src/gui.cpp" line="135"/>
<source>About Qt</source>
<translation>O Qt</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="217"/>
<location filename="../src/gui.cpp" line="295"/>
<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="247"/>
<location filename="../src/gui.cpp" line="353"/>
<source>Open file</source>
<translation>Otevřít soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="104"/>
<location filename="../src/gui.cpp" line="149"/>
<source>Save as</source>
<translation>Uložit jako</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="293"/>
<location filename="../src/gui.cpp" line="404"/>
<source>Open POI file</source>
<translation>Otevřít POI soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="95"/>
<location filename="../src/gui.cpp" line="140"/>
<source>Open</source>
<translation>Otevřít</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="80"/>
<location filename="../src/gui.cpp" line="123"/>
<source>Quit</source>
<translation>Ukončit</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="85"/>
<location filename="../src/gui.cpp" line="233"/>
<location filename="../src/gui.cpp" line="234"/>
<location filename="../src/gui.cpp" line="130"/>
<location filename="../src/gui.cpp" line="311"/>
<location filename="../src/gui.cpp" line="312"/>
<source>Keyboard controls</source>
<translation>Ovládací klávesy</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="99"/>
<location filename="../src/gui.cpp" line="144"/>
<source>Save</source>
<translation>Uložit</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="109"/>
<location filename="../src/gui.cpp" line="154"/>
<source>Close</source>
<translation>Zavřít</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="114"/>
<location filename="../src/gui.cpp" line="159"/>
<source>Reload</source>
<translation>Znovu načíst</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="121"/>
<source>Load file</source>
<translation>Nahrát soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="124"/>
<location filename="../src/gui.cpp" line="244"/>
<source>Show</source>
<translation>Zobrazit</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="131"/>
<location filename="../src/gui.cpp" line="158"/>
<location filename="../src/gui.cpp" line="198"/>
<location filename="../src/gui.cpp" line="235"/>
<source>File</source>
<translation>Soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="145"/>
<location filename="../src/gui.cpp" line="167"/>
<location filename="../src/gui.cpp" line="128"/>
<location filename="../src/gui.cpp" line="327"/>
<location filename="../src/gui.cpp" line="328"/>
<source>Data sources</source>
<translation>Zdroje dat</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="166"/>
<source>Load POI file</source>
<translation>Nahrát POI soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="169"/>
<source>Show POIs</source>
<translation>Zobrazit POI</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="174"/>
<source>Show map</source>
<translation>Zobrazit mapu</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="184"/>
<source>Show graphs</source>
<translation>Zobrazovat grafy</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="189"/>
<source>Show toolbars</source>
<translation>Zobrazovat nástrojové lišty</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="212"/>
<source>Map</source>
<translation>Mapa</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="217"/>
<source>POI</source>
<translation>POI</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="149"/>
<location filename="../src/gui.cpp" line="221"/>
<source>Settings</source>
<translation>Nastavení</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="225"/>
<source>Help</source>
<translation>Nápověda</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="185"/>
<location filename="../src/gui.cpp" line="263"/>
<source>Elevation</source>
<translation>Výška</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="186"/>
<location filename="../src/gui.cpp" line="264"/>
<source>Speed</source>
<translation>Rychlost</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="236"/>
<location filename="../src/gui.cpp" line="314"/>
<source>Next file</source>
<translation>Následující soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="237"/>
<location filename="../src/gui.cpp" line="315"/>
<source>Previous file</source>
<translation>Předchozí soubor</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="239"/>
<location filename="../src/gui.cpp" line="317"/>
<source>Append modifier</source>
<translation>Modifikátor nahradit/přidat</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="349"/>
<location filename="../src/gui.cpp" line="331"/>
<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="342"/>
<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="395"/>
<location filename="../src/gui.cpp" line="411"/>
<source>Line: %1</source>
<translation>Řádka: %1</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="463"/>
<source>Maximum</source>
<translation>Maximum</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="351"/>
<location filename="../src/gui.cpp" line="465"/>
<source>Minimum</source>
<translation>Minimum</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="88"/>
<location filename="../src/gui.cpp" line="213"/>
<location filename="../src/gui.cpp" line="133"/>
<location filename="../src/gui.cpp" line="291"/>
<source>About GPXSee</source>
<translation>O aplikaci GPXSee</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="215"/>
<location filename="../src/gui.cpp" line="293"/>
<source>GPX viewer and analyzer</source>
<translation>Prohlížeč a analyzátor GPX</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="342"/>
<location filename="../src/gui.cpp" line="330"/>
<source>Map sources</source>
<translation>Mapové zdroje</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="335"/>
<source>The file format is one URL per line where the tile X and Y coordinates are replaced with $x and $y. The zoom level is replaced with $z. An example map file could look like:</source>
<translation>Formát souboru je jedno URL na řádku, kde souřadnice dlaždice jsou nahrazeny řetězci $x a $y. Úroveň přiblížení (zoom) je pak nahrazena řetězcem $z. Příklad:</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="341"/>
<source>POIs</source>
<translation>POI body</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="456"/>
<source>Distance</source>
<translation>Vzdálenost</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="344"/>
<location filename="../src/gui.cpp" line="458"/>
<source>Time</source>
<translation>Čas</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="345"/>
<location filename="../src/gui.cpp" line="459"/>
<source>Ascent</source>
<translation>Stoupání</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="346"/>
<location filename="../src/gui.cpp" line="348"/>
<location filename="../src/gui.cpp" line="350"/>
<location filename="../src/gui.cpp" line="352"/>
<location filename="../src/gui.cpp" line="460"/>
<location filename="../src/gui.cpp" line="462"/>
<location filename="../src/gui.cpp" line="464"/>
<location filename="../src/gui.cpp" line="466"/>
<source>m</source>
<translation>m</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="347"/>
<location filename="../src/gui.cpp" line="461"/>
<source>Descent</source>
<translation>Klesání</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="418"/>
<location filename="../src/gui.cpp" line="557"/>
<source>%1 tracks</source>
<translation>Počet tras: %1</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="343"/>
<location filename="../src/gui.cpp" line="421"/>
<location filename="../src/gui.cpp" line="457"/>
<location filename="../src/gui.cpp" line="560"/>
<source>km</source>
<translation>km</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="285"/>
<location filename="../src/gui.cpp" line="297"/>
<location filename="../src/gui.cpp" line="397"/>
<location filename="../src/gui.cpp" line="412"/>
<source>Error</source>
<translation>Chyba</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="286"/>
<location filename="../src/gui.cpp" line="392"/>
<source>Error loading GPX file:
%1</source>
<translation>Soubor GPX nelze otevřít:
%1</translation>
</message>
<message>
<location filename="../src/gui.cpp" line="298"/>
<location filename="../src/gui.cpp" line="408"/>
<source>Error loading POI file:
%1</source>
<translation>Soubor POI nelze otevřít:
%1</translation>
</message>
</context>
<context>
<name>QObject</name>
<message>
<location filename="../src/parser.cpp" line="97"/>
<source>Not a GPX file.</source>
<translation>Neplatný GPX soubor.</translation>
</message>
<message>
<location filename="../src/parser.cpp" line="106"/>
<source>%1
Line %2</source>
<translation>%1
Rádka %2</translation>
</message>
<message>
<location filename="../src/poi.cpp" line="31"/>
<source>Invalid latitude
Line %1</source>
<translation>Neplatná zeměpisná šířka
Rádka %1</translation>
</message>
<message>
<location filename="../src/poi.cpp" line="36"/>
<source>Invalid longitude
Line %1</source>
<translation>Neplatná zeměpisná délka
Rádka %1</translation>
</message>
</context>
<context>
<name>SpeedGraph</name>
<message>
<location filename="../src/speedgraph.cpp" line="11"/>
<location filename="../src/speedgraph.cpp" line="9"/>
<source>Distance</source>
<translation>Vzdálenost</translation>
</message>
<message>
<location filename="../src/speedgraph.cpp" line="12"/>
<location filename="../src/speedgraph.cpp" line="10"/>
<source>Speed</source>
<translation>Rychlost</translation>
</message>
<message>
<location filename="../src/speedgraph.cpp" line="13"/>
<location filename="../src/speedgraph.cpp" line="11"/>
<source>km</source>
<translation></translation>
</message>
<message>
<location filename="../src/speedgraph.cpp" line="14"/>
<location filename="../src/speedgraph.cpp" line="12"/>
<source>km/h</source>
<translation>km/h</translation>
</message>
<message>
<location filename="../src/speedgraph.cpp" line="37"/>
<location filename="../src/speedgraph.cpp" line="35"/>
<source>Average</source>
<translation>Průměr</translation>
</message>
<message>
<location filename="../src/speedgraph.cpp" line="39"/>
<location filename="../src/speedgraph.cpp" line="37"/>
<source>Maximum</source>
<translation>Maximum</translation>
</message>

View File

@ -3,14 +3,12 @@
#include "config.h"
#include "axisitem.h"
#include <QDebug>
#define TICK 6
#define PADDING 6
#define XTICKS 15
#define YTICKS 10
struct Label {
double min;
double max;

View File

@ -1,11 +1,11 @@
#include "colorshop.h"
#define HUE_INIT 0.1f
#define HUE_INCREMENT 0.62f
#define SATURATION 0.99f
#define VALUE 0.99f
static unsigned hsv2rgb(float h, float s, float v)
{
unsigned hi;

View File

@ -3,11 +3,18 @@
#define APP_NAME "GPXSee"
#define APP_HOMEPAGE "http://tumic.wz.cz/gpxsee"
#define APP_VERSION "1.0"
#define APP_VERSION "2.0"
#define FONT_FAMILY "Arial"
#define FONT_SIZE 12
#define THIN_SPACE QString::fromUtf8("\xE2\x80\x89")
#if defined(Q_OS_WIN32)
#define APP_DIR "GPXSee"
#else
#define APP_DIR ".gpxsee"
#endif
#define POI_DIR APP_DIR"/POI"
#define TILES_DIR APP_DIR"/tiles"
#define MAP_LIST_FILE APP_DIR"/maps.txt"
#endif /* CONFIG_H */

75
src/downloader.cpp Normal file
View File

@ -0,0 +1,75 @@
#include <QFile>
#include <QFileInfo>
#include "config.h"
#include "downloader.h"
#if defined(Q_OS_LINUX)
#define PLATFORM_STR "Linux"
#elif defined(Q_OS_WIN32)
#define PLATFORM_STR "Windows"
#elif defined(Q_OS_MAC)
#define PLATFORM_STR "OS X"
#else
#define PLATFORM_STR "Unknown"
#endif
#define USER_AGENT APP_NAME"/"APP_VERSION" ("PLATFORM_STR"; Qt "QT_VERSION_STR")"
Downloader::Downloader()
{
connect(&manager, SIGNAL(finished(QNetworkReply*)),
SLOT(downloadFinished(QNetworkReply*)));
}
void Downloader::doDownload(const Download &dl)
{
QUrl url(dl.url());
QNetworkRequest request(url);
request.setAttribute(QNetworkRequest::User, QVariant(dl.file()));
request.setRawHeader("User-Agent", USER_AGENT);
QNetworkReply *reply = manager.get(request);
currentDownloads.append(reply);
}
bool Downloader::saveToDisk(const QString &filename, QIODevice *data)
{
QFile file(filename);
if (!file.open(QIODevice::WriteOnly)) {
fprintf(stderr, "Error writing map tile: %s: %s\n",
qPrintable(filename), qPrintable(file.errorString()));
return false;
}
file.write(data->readAll());
file.close();
return true;
}
void Downloader::downloadFinished(QNetworkReply *reply)
{
QUrl url = reply->url();
if (reply->error()) {
fprintf(stderr, "Error downloading map tile: %s: %s\n",
url.toEncoded().constData(), qPrintable(reply->errorString()));
} else {
QString filename = reply->request().attribute(QNetworkRequest::User)
.toString();
saveToDisk(filename, reply);
}
currentDownloads.removeAll(reply);
reply->deleteLater();
if (currentDownloads.isEmpty())
emit finished();
}
void Downloader::get(const QList<Download> &list)
{
for (int i = 0; i < list.count(); i++)
doDownload(list.at(i));
}

52
src/downloader.h Normal file
View File

@ -0,0 +1,52 @@
#ifndef DOWNLOADER_H
#define DOWNLOADER_H
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QUrl>
#include <QList>
class Download
{
public:
Download(const QString &url, const QString &file)
{_url = url; _file = file;}
const QString& url() const {return _url;}
const QString& file() const {return _file;}
private:
QString _url;
QString _file;
};
class Downloader : public QObject
{
Q_OBJECT
public:
static Downloader& instance()
{static Downloader i; return i;}
void get(const QList<Download> &list);
signals:
void finished();
private slots:
void downloadFinished(QNetworkReply *reply);
private:
Downloader();
Downloader(Downloader const&);
void operator=(Downloader const&);
void doDownload(const Download &dl);
bool saveToDisk(const QString &filename, QIODevice *data);
QNetworkAccessManager manager;
QList<QNetworkReply *> currentDownloads;
};
#endif // DOWNLOADER_H

View File

@ -2,6 +2,7 @@
#include "config.h"
#include "elevationgraph.h"
ElevationGraph::ElevationGraph(QWidget *parent) : Graph(parent)
{
_ascent = 0;

View File

@ -2,8 +2,6 @@
#include <QDir>
#include "filebrowser.h"
#include <QDebug>
FileBrowser::FileBrowser(QObject *parent) : QObject(parent)
{

View File

@ -3,14 +3,11 @@
#include "ll.h"
#include "gpx.h"
#include <QDebug>
#define WINDOW_EF 3
#define WINDOW_SE 11
#define WINDOW_SF 11
static bool lt(const QPointF &p1, const QPointF &p2)
{
return p1.y() < p2.y();
@ -90,14 +87,17 @@ bool GPX::loadFile(const QString &fileName)
_data.clear();
_error.clear();
_errorLine = 0;
if (!file.open(QFile::ReadOnly | QFile::Text)) {
_error = qPrintable(file.errorString());
return false;
}
if (!(ret = _parser.loadFile(&file, _data)))
if (!(ret = _parser.loadFile(&file, _data))) {
_error = _parser.errorString();
_errorLine = _parser.errorLine();
}
file.close();
return ret;
@ -150,12 +150,8 @@ void GPX::speedGraph(QVector<QPointF> &graph) const
void GPX::track(QVector<QPointF> &track) const
{
QPointF p;
for (int i = 0; i < _data.size(); i++) {
ll2mercator(_data.at(i).coordinates, p);
track.append(p);
}
for (int i = 0; i < _data.size(); i++)
track.append(ll2mercator(_data.at(i).coordinates));
}
qreal GPX::distance() const

View File

@ -11,6 +11,7 @@ class GPX
public:
bool loadFile(const QString &fileName);
const QString &errorString() const {return _error;}
int errorLine() const {return _errorLine;}
void elevationGraph(QVector<QPointF> &graph) const;
void speedGraph(QVector<QPointF> &graph) const;
@ -23,6 +24,7 @@ private:
Parser _parser;
QVector<TrackPoint> _data;
QString _error;
int _errorLine;
};
#endif // GPX_H

View File

@ -9,12 +9,9 @@
#include "config.h"
#include "graph.h"
#include <QDebug>
#define MARGIN 10.0
void Scene::mousePressEvent(QGraphicsSceneMouseEvent *e)
{
if (e->button() == Qt::LeftButton)
@ -137,7 +134,9 @@ void Graph::loadData(const QVector<QPointF> &data)
}
pi = new QGraphicsPathItem(path);
pi->setPen(QPen(color));
QBrush brush(color, Qt::SolidPattern);
QPen pen(brush, 0);
pi->setPen(pen);
_scene->addItem(pi);
_graphs.append(pi);

View File

@ -10,6 +10,8 @@
#include "colorshop.h"
#define THIN_SPACE QString::fromUtf8("\xE2\x80\x89")
class SliderItem;
class SliderInfoItem;
class InfoItem;

View File

@ -7,10 +7,13 @@
#include <QPrinter>
#include <QPainter>
#include <QKeyEvent>
#include <QSignalMapper>
#include "config.h"
#include "icons.h"
#include "keys.h"
#include "gpx.h"
#include "map.h"
#include "maplist.h"
#include "elevationgraph.h"
#include "speedgraph.h"
#include "track.h"
@ -18,8 +21,6 @@
#include "filebrowser.h"
#include "gui.h"
#include <QDebug>
static QString timeSpan(qreal time)
{
@ -36,6 +37,8 @@ static QString timeSpan(qreal time)
GUI::GUI()
{
loadFiles();
createActions();
createMenus();
createToolBars();
@ -68,6 +71,46 @@ GUI::GUI()
resize(600, 800);
}
void GUI::loadFiles()
{
// Maps
_maps = MapList::load(QString("%1/"MAP_LIST_FILE).arg(QDir::homePath()));
// POI files
QDir dir(QString("%1/"POI_DIR).arg(QDir::homePath()));
QFileInfoList list = dir.entryInfoList(QStringList(), QDir::Files);
for (int i = 0; i < list.size(); ++i) {
if (!_poi.loadFile(list.at(i).absoluteFilePath()))
fprintf(stderr, "Error loading POI file: %s: %s",
qPrintable(list.at(i).absoluteFilePath()),
qPrintable(_poi.errorString()));
}
}
void GUI::createMapActions()
{
QActionGroup *ag = new QActionGroup(this);
ag->setExclusive(true);
QSignalMapper *sm = new QSignalMapper(this);
for (int i = 0; i < _maps.count(); i++) {
QAction *a = new QAction(_maps.at(i)->name(), this);
a->setCheckable(true);
a->setActionGroup(ag);
sm->setMapping(a, i);
connect(a, SIGNAL(triggered()), sm, SLOT(map()));
_mapActions.append(a);
}
connect(sm, SIGNAL(mapped(int)), this, SLOT(mapChanged(int)));
_mapActions.at(0)->setChecked(true);
_currentMap = _maps.at(0);
}
void GUI::createActions()
{
// Action Groups
@ -82,6 +125,8 @@ void GUI::createActions()
connect(_exitAction, SIGNAL(triggered()), this, SLOT(close()));
// Help & About
_dataSourcesAction = new QAction(tr("Data sources"), this);
connect(_dataSourcesAction, SIGNAL(triggered()), this, SLOT(dataSources()));
_keysAction = new QAction(tr("Keyboard controls"), this);
connect(_keysAction, SIGNAL(triggered()), this, SLOT(keys()));
_aboutAction = new QAction(QIcon(QPixmap(APP_ICON)),
@ -118,12 +163,34 @@ void GUI::createActions()
// POI actions
_openPOIAction = new QAction(QIcon(QPixmap(OPEN_FILE_ICON)),
tr("Load file"), this);
tr("Load POI file"), this);
connect(_openPOIAction, SIGNAL(triggered()), this, SLOT(openPOIFile()));
_showPOIAction = new QAction(QIcon(QPixmap(SHOW_POI_ICON)),
tr("Show"), this);
tr("Show POIs"), this);
_showPOIAction->setCheckable(true);
connect(_showPOIAction, SIGNAL(triggered()), this, SLOT(showPOI()));
connect(_showPOIAction, SIGNAL(triggered(bool)), this, SLOT(showPOI(bool)));
// Map actions
_showMapAction = new QAction(QIcon(QPixmap(SHOW_MAP_ICON)), tr("Show map"),
this);
_showMapAction->setCheckable(true);
connect(_showMapAction, SIGNAL(triggered(bool)), this, SLOT(showMap(bool)));
if (_maps.empty())
_showMapAction->setEnabled(false);
else
createMapActions();
// Settings actions
_showGraphsAction = new QAction(tr("Show graphs"), this);
_showGraphsAction->setCheckable(true);
_showGraphsAction->setChecked(true);
connect(_showGraphsAction, SIGNAL(triggered(bool)), this,
SLOT(showGraphs(bool)));
_showToolbarsAction = new QAction(tr("Show toolbars"), this);
_showToolbarsAction->setCheckable(true);
_showToolbarsAction->setChecked(true);
connect(_showToolbarsAction, SIGNAL(triggered(bool)), this,
SLOT(showToolbars(bool)));
}
void GUI::createMenus()
@ -142,11 +209,21 @@ void GUI::createMenus()
_fileMenu->addAction(_exitAction);
#endif // __APPLE__
_mapMenu = menuBar()->addMenu(tr("Map"));
_mapMenu->addActions(_mapActions);
_mapMenu->addSeparator();
_mapMenu->addAction(_showMapAction);
_poiMenu = menuBar()->addMenu(tr("POI"));
_poiMenu->addAction(_openPOIAction);
_poiMenu->addAction(_showPOIAction);
_settingsMenu = menuBar()->addMenu(tr("Settings"));
_settingsMenu->addAction(_showToolbarsAction);
_settingsMenu->addAction(_showGraphsAction);
_helpMenu = menuBar()->addMenu(tr("Help"));
_helpMenu->addAction(_dataSourcesAction);
_helpMenu->addAction(_keysAction);
_helpMenu->addSeparator();
_helpMenu->addAction(_aboutAction);
@ -164,10 +241,11 @@ void GUI::createToolBars()
_fileToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
#endif // __APPLE__
_poiToolBar = addToolBar(tr("POI"));
_poiToolBar->addAction(_showPOIAction);
_showToolBar = addToolBar(tr("Show"));
_showToolBar->addAction(_showPOIAction);
_showToolBar->addAction(_showMapAction);
#ifdef __APPLE__
_poiToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
_showToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
#endif // __APPLE__
}
@ -242,6 +320,34 @@ void GUI::keys()
msgBox.exec();
}
void GUI::dataSources()
{
QMessageBox msgBox(this);
msgBox.setWindowTitle(tr("Data sources"));
msgBox.setText(QString("<h3>") + tr("Data sources") + QString("</h3>"));
msgBox.setInformativeText(
QString("<h4>") + tr("Map sources") + QString("</h4><p>")
+ tr("Map (tiles) source URLs are read on program startup from the "
"following file:")
+ QString("</p><p><code>") + QDir::homePath()
+ QString("/"MAP_LIST_FILE"</code></p><p>")
+ tr("The file format is one URL per line where the tile X and Y "
"coordinates are replaced with $x and $y. The zoom level is "
"replaced with $z. An example map file could look like:")
+ QString("</p><p><code>http://tile.server.com/map/$z/$x/$y.png<br/>"
"http://mapserver.org/map/$z-$x-$y</code></p>")
+ QString("<h4>") + tr("POIs") + QString("</h4><p>")
+ tr("To make GPXSee load a POI file automatically on startup, add "
"the file to the following directory:")
+ QString("</p><p><code>") + QDir::homePath()
+ QString("/"POI_DIR"</code></p>")
);
msgBox.exec();
}
void GUI::openFile()
{
QStringList files = QFileDialog::getOpenFileNames(this, tr("Open file"));
@ -282,8 +388,13 @@ bool GUI::loadFile(const QString &fileName)
return true;
} else {
QMessageBox::critical(this, tr("Error"), fileName + QString("\n\n")
+ tr("Error loading GPX file:\n%1").arg(gpx.errorString()));
QString error = fileName + QString("\n\n")
+ tr("Error loading GPX file:\n%1").arg(gpx.errorString())
+ QString("\n");
if (gpx.errorLine())
error.append(tr("Line: %1").arg(gpx.errorLine()));
QMessageBox::critical(this, tr("Error"), error);
return false;
}
}
@ -294,8 +405,11 @@ void GUI::openPOIFile()
if (!fileName.isEmpty()) {
if (!_poi.loadFile(fileName)) {
QMessageBox::critical(this, tr("Error"),
tr("Error loading POI file:\n%1").arg(_poi.errorString()));
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()));
QMessageBox::critical(this, tr("Error"), error);
} else {
_showPOIAction->setChecked(true);
_track->loadPOI(_poi);
@ -394,14 +508,39 @@ void GUI::closeFile()
updateStatusBarInfo();
}
void GUI::showPOI()
void GUI::showPOI(bool checked)
{
if (_showPOIAction->isChecked())
if (checked)
_track->loadPOI(_poi);
else
_track->clearPOI();
}
void GUI::showMap(bool checked)
{
if (checked)
_track->setMap(_currentMap);
else
_track->setMap(0);
}
void GUI::showGraphs(bool checked)
{
_trackGraphs->setHidden(!checked);
}
void GUI::showToolbars(bool checked)
{
if (checked) {
addToolBar(_fileToolBar);
addToolBar(_showToolBar);
_fileToolBar->show();
_showToolBar->show();
} else {
removeToolBar(_fileToolBar);
removeToolBar(_showToolBar);
}
}
void GUI::updateStatusBarInfo()
{
@ -422,6 +561,14 @@ void GUI::updateStatusBarInfo()
_timeLabel->setText(timeSpan(_time));
}
void GUI::mapChanged(int index)
{
_currentMap = _maps.at(index);
if (_showMapAction->isChecked())
_track->setMap(_currentMap);
}
void GUI::graphChanged(int index)
{
if (_trackGraphs->widget(index) == _elevationGraph)
@ -430,7 +577,6 @@ void GUI::graphChanged(int index)
_speedGraph->setSliderPosition(_elevationGraph->sliderPosition());
}
void GUI::keyPressEvent(QKeyEvent *event)
{
QString file;

View File

@ -16,6 +16,7 @@ class FileBrowser;
class ElevationGraph;
class SpeedGraph;
class Track;
class Map;
class GUI : public QMainWindow
{
@ -29,17 +30,25 @@ public:
private slots:
void about();
void keys();
void dataSources();
void saveFile();
void saveAs();
void openFile();
void closeFile();
void reloadFile();
void openPOIFile();
void showPOI();
void showPOI(bool checked);
void showMap(bool checked);
void showGraphs(bool checked);
void showToolbars(bool checked);
void mapChanged(int);
void graphChanged(int);
private:
void loadFiles();
void createMapActions();
void createActions();
void createMenus();
void createToolBars();
@ -56,14 +65,17 @@ private:
QMenu *_fileMenu;
QMenu *_helpMenu;
QMenu *_poiMenu;
QMenu *_mapMenu;
QMenu *_settingsMenu;
QToolBar *_fileToolBar;
QToolBar *_poiToolBar;
QToolBar *_showToolBar;
QTabWidget *_trackGraphs;
QActionGroup *_fileActionGroup;
QAction *_exitAction;
QAction *_keysAction;
QAction *_dataSourcesAction;
QAction *_aboutAction;
QAction *_aboutQtAction;
QAction *_saveFileAction;
@ -73,6 +85,10 @@ private:
QAction *_reloadFileAction;
QAction *_openPOIAction;
QAction *_showPOIAction;
QAction *_showMapAction;
QAction *_showGraphsAction;
QAction *_showToolbarsAction;
QList<QAction*> _mapActions;
QLabel *_fileNameLabel;
QLabel *_distanceLabel;
@ -83,10 +99,12 @@ private:
Track *_track;
POI _poi;
QList<Map*> _maps;
FileBrowser *_browser;
QList<QString> _files;
QString _saveFileName;
Map *_currentMap;
qreal _distance;
qreal _time;

View File

@ -9,6 +9,7 @@
#define SAVE_AS_ICON ":/icons/document-save-as.png"
#define CLOSE_FILE_ICON ":/icons/dialog-close.png"
#define SHOW_POI_ICON ":/icons/flag.png"
#define SHOW_MAP_ICON ":/icons/applications-internet.png"
#define QUIT_ICON ":/icons/application-exit.png"
#define RELOAD_FILE_ICON ":/icons/view-refresh.png"

View File

@ -1,9 +1,14 @@
#include <cmath>
#include "ll.h"
// MSVC workarounds
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif // M_PI
#if defined(_MSC_VER) && (_MSC_VER < 1800)
#define log2(n) (log(n)/log(2.0))
#endif
#define WGS84_RADIUS 6378137.0
#define deg2rad(d) (((d)*M_PI)/180.0)
@ -20,8 +25,46 @@ qreal llDistance(const QPointF &p1, const QPointF &p2)
return (WGS84_RADIUS * c);
}
void ll2mercator(const QPointF &src, QPointF &dst)
QPointF ll2mercator(const QPointF &ll)
{
dst.setX(src.x());
dst.setY(rad2deg(log(tan(M_PI/4.0 + deg2rad(src.y())/2.0))));
QPointF m;
m.setX(ll.x());
m.setY(rad2deg(log(tan(M_PI/4.0 + deg2rad(ll.y())/2.0))));
return m;
}
QPoint mercator2tile(const QPointF &m, int z)
{
QPoint tile;
tile.setX((int)(floor((m.x() + 180.0) / 360.0 * pow(2.0, z))));
tile.setY((int)(floor((1.0 - (m.y() / 180.0)) / 2.0 * pow(2.0, z))));
return tile;
}
QPointF tile2mercator(const QPoint &tile, int z)
{
QPointF m;
m.setX(tile.x() / pow(2.0, z) * 360.0 - 180);
qreal n = M_PI - 2.0 * M_PI * tile.y() / pow(2.0, z);
m.setY(rad2deg(atan(0.5 * (exp(n) - exp(-n)))));
return ll2mercator(m);
}
int scale2zoom(qreal scale)
{
int zoom;
zoom = (int)log2(360.0/(scale * (qreal)TILE_SIZE));
if (zoom < ZOOM_MIN)
return ZOOM_MIN;
if (zoom > ZOOM_MAX)
return ZOOM_MAX;
return zoom;
}

View File

@ -3,7 +3,14 @@
#include <QPointF>
void ll2mercator(const QPointF &src, QPointF &dst);
#define TILE_SIZE 256
#define ZOOM_MAX 18
#define ZOOM_MIN 3
QPointF ll2mercator(const QPointF &ll);
qreal llDistance(const QPointF &p1, const QPointF &p2);
QPoint mercator2tile(const QPointF &m, int zoom);
QPointF tile2mercator(const QPoint &tile, int zoom);
int scale2zoom(qreal scale);
#endif // LL_H

52
src/map.cpp Normal file
View File

@ -0,0 +1,52 @@
#include <QFileInfo>
#include <QDir>
#include "downloader.h"
#include "ll.h"
#include "config.h"
#include "map.h"
Map::Map(const QString &name, const QString &url)
{
_name = name;
_url = url;
connect(&Downloader::instance(), SIGNAL(finished()), this,
SLOT(emitLoaded()));
QDir::home().mkpath(QString(TILES_DIR"/%1").arg(_name));
}
void Map::emitLoaded()
{
emit loaded();
}
void Map::loadTiles(QList<Tile> &list)
{
QList<Download> dl;
for (int i = 0; i < list.size(); ++i) {
Tile &t = list[i];
QString file = QString("%1/"TILES_DIR"/%2/%3-%4-%5.png")
.arg(QDir::homePath()).arg(_name).arg(t.zoom()).arg(t.xy().rx())
.arg(t.xy().ry());
QFileInfo fi(file);
if (fi.exists())
t.pixmap().load(file);
else {
t.pixmap() = QPixmap(TILE_SIZE, TILE_SIZE);
t.pixmap().fill();
QString url(_url);
url.replace("$z", QString::number(t.zoom()));
url.replace("$x", QString::number(t.xy().x()));
url.replace("$y", QString::number(t.xy().y()));
dl.append(Download(url, file));
}
}
if (!dl.empty())
Downloader::instance().get(dl);
}

46
src/map.h Normal file
View File

@ -0,0 +1,46 @@
#ifndef MAP_H
#define MAP_H
#include <QPixmap>
#include "downloader.h"
class Tile
{
public:
Tile(const QPoint &xy, int zoom)
{_xy = xy; _zoom = zoom;}
int zoom() {return _zoom;}
QPoint& xy() {return _xy;}
QPixmap& pixmap() {return _pixmap;}
private:
int _zoom;
QPoint _xy;
QPixmap _pixmap;
};
class Map : public QObject
{
Q_OBJECT
signals:
void loaded();
public:
Map(const QString &name, const QString &url);
const QString &name() {return _name;}
void loadTiles(QList<Tile> &list);
private slots:
void emitLoaded();
private:
QString _name;
QString _url;
};
#endif // MAP_H

41
src/maplist.cpp Normal file
View File

@ -0,0 +1,41 @@
#include <QFile>
#include <QFileInfo>
#include "maplist.h"
QList<Map*> MapList::load(const QString &fileName)
{
QList<Map*> mapList;
QFileInfo fi(fileName);
if (!fi.exists())
return mapList;
QFile file(fileName);
if (!file.open(QFile::ReadOnly | QFile::Text)) {
fprintf(stderr, "Error opening map list file: %s: %s\n",
qPrintable(fileName), qPrintable(file.errorString()));
return mapList;
}
int ln = 1;
while (!file.atEnd()) {
QByteArray line = file.readLine();
QList<QByteArray> list = line.split('\t');
if (list.size() != 2) {
fprintf(stderr, "Invalid map list entry on line %d\n", ln);
continue;
}
QByteArray ba1 = list[0].trimmed();
QByteArray ba2 = list[1].trimmed();
mapList.append(new Map(QString::fromUtf8(ba1.data(), ba1.size()),
QString::fromLatin1(ba2.data(), ba2.size())));
ln++;
}
return mapList;
}

14
src/maplist.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef MAPLIST_H
#define MAPLIST_H
#include <QList>
#include "map.h"
class MapList
{
public:
static QList<Map*> load(const QString &fileName);
};
#endif // MAPLIST_H

View File

@ -1,6 +1,7 @@
#include <QPainter>
#include "markeritem.h"
#define SIZE 8
MarkerItem::MarkerItem(QGraphicsItem *parent) : QGraphicsItem(parent)

View File

@ -1,7 +1,5 @@
#include "parser.h"
#include <QDebug>
void Parser::handleExtensionData(QVector<TrackPoint> &data,
QStringRef element, const QString &value)
@ -94,20 +92,12 @@ bool Parser::parse(QVector<TrackPoint> &data)
if (_reader.name() == "gpx")
gpx(data);
else
_reader.raiseError(QObject::tr("Not a GPX file."));
_reader.raiseError("Not a GPX file.");
}
return !_reader.error();
}
QString Parser::errorString() const
{
return QObject::tr("%1\nLine %2")
.arg(_reader.errorString())
.arg(_reader.lineNumber());
}
bool Parser::loadFile(QIODevice *device, QVector<TrackPoint> &data)
{
_reader.clear();

View File

@ -20,7 +20,8 @@ class Parser
{
public:
bool loadFile(QIODevice *device, QVector<TrackPoint> &data);
QString errorString() const;
QString errorString() const {return _reader.errorString();}
int errorLine() const {return _reader.lineNumber();}
private:
bool parse(QVector<TrackPoint> &data);

View File

@ -5,13 +5,16 @@
#include "poi.h"
#define BOUNDING_RECT_SIZE 0.01
bool POI::loadFile(const QString &fileName)
{
QFile file(fileName);
bool ret;
int ln = 1;
int ln = 1, cnt = _data.size();
_error.clear();
_errorLine = 0;
if (!file.open(QFile::ReadOnly | QFile::Text)) {
_error = qPrintable(file.errorString());
@ -22,69 +25,69 @@ bool POI::loadFile(const QString &fileName)
QByteArray line = file.readLine();
QList<QByteArray> list = line.split(',');
if (list.size() < 3) {
_error = QString("Parse error\nLine %1").arg(ln);
_error = "Parse error";
_errorLine = ln;
return false;
}
qreal lat = list[0].trimmed().toDouble(&ret);
if (!ret) {
_error = QObject::tr("Invalid latitude\nLine %1").arg(ln);
_error = "Invalid latitude";
_errorLine = ln;
return false;
}
qreal lon = list[1].trimmed().toDouble(&ret);
if (!ret) {
_error = QObject::tr("Invalid longitude\nLine %1").arg(ln);
_error = "Invalid longitude";
_errorLine = ln;
return false;
}
QByteArray ba = list[2].trimmed();
QPointF p;
Entry entry;
ll2mercator(QPointF(lon, lat), p);
entry.description = QString::fromUtf8(ba.data(), ba.size());
entry.coordinates = p;
entry.coordinates = ll2mercator(QPointF(lon, lat));
_data.append(entry);
ln++;
}
for (int i = 0; i < _data.size(); ++i) {
for (int i = cnt; i < _data.size(); ++i) {
qreal c[2];
c[0] = _data.at(i).coordinates.x();
c[1] = _data.at(i).coordinates.y();
_tree.Insert(c, c, &_data.at(i));
_tree.Insert(c, c, i);
}
return true;
}
static bool cb(const Entry* data, void* context)
static bool cb(size_t data, void* context)
{
QSet<const Entry*> *set = (QSet<const Entry*>*) context;
set->insert(data);
QSet<int> *set = (QSet<int>*) context;
set->insert((int)data);
return true;
}
#define RECT 0.01
QVector<Entry> POI::points(const QVector<QPointF> &path) const
{
QVector<Entry> ret;
QSet<const Entry*> set;
QSet<int> set;
qreal min[2], max[2];
for (int i = 0; i < path.count(); i++) {
min[0] = path.at(i).x() - RECT;
min[1] = path.at(i).y() - RECT;
max[0] = path.at(i).x() + RECT;
max[1] = path.at(i).y() + RECT;
min[0] = path.at(i).x() - BOUNDING_RECT_SIZE;
min[1] = path.at(i).y() - BOUNDING_RECT_SIZE;
max[0] = path.at(i).x() + BOUNDING_RECT_SIZE;
max[1] = path.at(i).y() + BOUNDING_RECT_SIZE;
_tree.Search(min, max, cb, &set);
}
QSet<const Entry *>::const_iterator i = set.constBegin();
QSet<int>::const_iterator i = set.constBegin();
while (i != set.constEnd()) {
ret.append(*(*i));
++i;
ret.append(_data.at(*i));
++i;
}
return ret;

View File

@ -28,16 +28,19 @@ class POI
public:
bool loadFile(const QString &fileName);
QString errorString() const {return _error;}
int errorLine() const {return _errorLine;}
QVector<Entry> points(const QVector<QPointF> &path) const;
void clear();
private:
typedef RTree<const Entry*, qreal, 2> POITree;
typedef RTree<size_t, qreal, 2> POITree;
POITree _tree;
QVector<Entry> _data;
QString _error;
int _errorLine;
};
#endif // POI_H

View File

@ -2,15 +2,13 @@
#include "config.h"
#include "poiitem.h"
#include <QDebug>
#define POINT_SIZE 8
POIItem::POIItem(const QString &text, QGraphicsItem *parent)
POIItem::POIItem(const Entry &entry, QGraphicsItem *parent)
: QGraphicsItem(parent)
{
_text = text;
_entry = entry;
updateBoundingRect();
}
@ -20,7 +18,7 @@ void POIItem::updateBoundingRect()
font.setPixelSize(FONT_SIZE);
font.setFamily(FONT_FAMILY);
QFontMetrics fm(font);
QRect ts = fm.tightBoundingRect(_text);
QRect ts = fm.tightBoundingRect(_entry.description);
_boundingRect = QRectF(0, 0, ts.width() + POINT_SIZE,
ts.height() + fm.descent() + POINT_SIZE);
@ -35,11 +33,11 @@ void POIItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
font.setPixelSize(FONT_SIZE);
font.setFamily(FONT_FAMILY);
QFontMetrics fm(font);
QRect ts = fm.tightBoundingRect(_text);
QRect ts = fm.tightBoundingRect(_entry.description);
painter->setFont(font);
painter->drawText(POINT_SIZE - qMax(ts.x(), 0), POINT_SIZE + ts.height(),
_text);
_entry.description);
painter->setBrush(Qt::SolidPattern);
painter->drawEllipse(0, 0, POINT_SIZE, POINT_SIZE);

View File

@ -2,11 +2,13 @@
#define POIITEM_H
#include <QGraphicsItem>
#include "poi.h"
class POIItem : public QGraphicsItem
{
public:
POIItem(const QString &text, QGraphicsItem *parent = 0);
POIItem(const Entry &entry, QGraphicsItem *parent = 0);
const Entry &entry() const {return _entry;}
QRectF boundingRect() const {return _boundingRect;}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
@ -15,7 +17,7 @@ public:
private:
void updateBoundingRect();
QString _text;
Entry _entry;
QRectF _boundingRect;
};

View File

@ -1,7 +1,6 @@
#include <QPainter>
#include "slideritem.h"
#include <QDebug>
#define SIZE 10

View File

@ -1,8 +1,6 @@
#include "config.h"
#include "speedgraph.h"
#include <QDebug>
SpeedGraph::SpeedGraph(QWidget *parent) : Graph(parent)
{

View File

@ -3,21 +3,28 @@
#include <QGraphicsScene>
#include <QPainterPath>
#include <QWheelEvent>
#include <QGraphicsEllipseItem>
#include "poiitem.h"
#include "markeritem.h"
#include "ll.h"
#include "track.h"
#include <QDebug>
#define MARGIN 10.0
#define TRACK_WIDTH 3
Track::Track(QWidget *parent)
: QGraphicsView(parent)
{
_scene = new QGraphicsScene(this);
setScene(_scene);
setResizeAnchor(QGraphicsView::AnchorViewCenter);
setCacheMode(QGraphicsView::CacheBackground);
setDragMode(QGraphicsView::ScrollHandDrag);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
_zoom = -1;
_scale = 1.0;
_map = 0;
_maxLen = 0;
}
@ -33,6 +40,7 @@ void Track::loadGPX(const GPX &gpx)
QGraphicsPathItem *pi;
MarkerItem *mi;
QColor color = _colorShop.color();
qreal prevScale = _scale;
gpx.track(track);
@ -48,39 +56,82 @@ void Track::loadGPX(const GPX &gpx)
_maxLen = qMax(path.length(), _maxLen);
for (int i = 0; i < _trackPaths.size(); i++) {
_trackPaths.at(i)->resetTransform();
_scene->removeItem(_markers.at(i));
}
pi = new QGraphicsPathItem(path);
pi->setPen(QPen(color));
_scene->addItem(pi);
_trackPaths.append(pi);
_zoom = scale2zoom(trackScale());
_scale = mapScale();
QBrush brush(color, Qt::SolidPattern);
QPen pen(brush, TRACK_WIDTH * _scale);
pi->setPen(pen);
pi->setScale(1.0/_scale);
_scene->addItem(pi);
QTransform t = transform();
mi = new MarkerItem();
mi->setPos(pi->path().pointAtPercent(0));
mi = new MarkerItem(pi);
_markers.append(mi);
mi->setPos(pi->path().pointAtPercent(0));
mi->setScale(_scale);
for (int i = 0; i < _trackPaths.size(); i++) {
_markers.at(i)->setTransform(t);
_scene->addItem(_markers.at(i));
}
if (_trackPaths.size() > 1 && prevScale != _scale)
rescale(_scale);
_scene->setSceneRect(_scene->itemsBoundingRect());
fitInView(_scene->sceneRect(), Qt::KeepAspectRatio);
}
QTransform Track::transform() const
qreal Track::trackScale() const
{
QPointF scale(_scene->itemsBoundingRect().width() / viewport()->width(),
_scene->itemsBoundingRect().height() / viewport()->height());
QTransform transform;
transform.scale(qMax(scale.x(), scale.y()), qMax(scale.x(), scale.y()));
qreal bottom, top, left, right;
return transform;
bottom = _trackPaths.at(0)->path().boundingRect().bottom();
top = _trackPaths.at(0)->path().boundingRect().top();
left = _trackPaths.at(0)->path().boundingRect().left();
right = _trackPaths.at(0)->path().boundingRect().right();
for (int i = 1; i < _trackPaths.size(); i++) {
bottom = qMax(bottom, _trackPaths.at(i)->path().boundingRect().bottom());
top = qMin(top, _trackPaths.at(i)->path().boundingRect().top());
right = qMax(right, _trackPaths.at(i)->path().boundingRect().right());
left = qMin(left, _trackPaths.at(i)->path().boundingRect().left());
}
QRectF br(QPointF(left, top), QPointF(right, bottom));
QPointF sc(br.width() / (viewport()->width() - MARGIN/2),
br.height() / (viewport()->height() - MARGIN/2));
return qMax(sc.x(), sc.y());
}
qreal Track::mapScale() const
{
return ((360.0/(qreal)(1<<_zoom))/(qreal)TILE_SIZE);
}
void Track::rescale(qreal scale)
{
for (int i = 0; i < _trackPaths.size(); i++) {
_markers.at(i)->setScale(scale);
_trackPaths.at(i)->setScale(1.0/scale);
QPen pen(_trackPaths.at(i)->pen());
pen.setWidthF(TRACK_WIDTH * scale);
_trackPaths.at(i)->setPen(pen);
}
QHash<Entry, POIItem*>::const_iterator it, jt;
for (it = _pois.constBegin(); it != _pois.constEnd(); it++) {
it.value()->setPos(QPointF(it.value()->entry().coordinates.x()
* 1.0/scale, -it.value()->entry().coordinates.y() * 1.0/scale));
it.value()->show();
}
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();
}
}
_scale = scale;
}
void Track::loadPOI(const POI &poi)
@ -94,9 +145,9 @@ void Track::loadPOI(const POI &poi)
if (_pois.contains(p.at(i)))
continue;
POIItem *pi = new POIItem(p.at(i).description);
pi->setPos(p.at(i).coordinates.x(), -p.at(i).coordinates.y());
pi->setTransform(transform());
POIItem *pi = new POIItem(p.at(i));
pi->setPos(p.at(i).coordinates.x() * 1.0/_scale,
-p.at(i).coordinates.y() * 1.0/_scale);
pi->setZValue(1);
_scene->addItem(pi);
@ -104,9 +155,6 @@ void Track::loadPOI(const POI &poi)
}
}
for (it = _pois.constBegin(); it != _pois.constEnd(); it++)
it.value()->setTransform(transform());
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()
@ -116,15 +164,48 @@ void Track::loadPOI(const POI &poi)
}
_scene->setSceneRect(_scene->itemsBoundingRect());
fitInView(_scene->sceneRect(), Qt::KeepAspectRatio);
}
void Track::setMap(Map *map)
{
_map = map;
if (_map)
connect(_map, SIGNAL(loaded()), this, SLOT(redraw()));
resetCachedContent();
}
void Track::redraw()
{
resetCachedContent();
}
void Track::wheelEvent(QWheelEvent *event)
{
float factor;
QPointF pos = mapToScene(event->pos());
qreal scale = _scale;
factor = pow(2.0, -event->delta() / 400.0);
scale(factor, factor);
_zoom = (event->delta() > 0) ?
qMin(_zoom + 1, ZOOM_MAX) : qMax(_zoom - 1, ZOOM_MIN);
rescale(mapScale());
_scene->setSceneRect(_scene->itemsBoundingRect());
centerOn(pos * scale/_scale);
resetCachedContent();
}
void Track::showMarkers(bool show)
{
for (int i = 0; i < _markers.size(); i++)
_markers.at(i)->setVisible(show);
}
void Track::setTrackLineWidth(qreal width)
{
for (int i = 0; i < _trackPaths.size(); i++) {
QPen pen(_trackPaths.at(i)->pen());
pen.setWidthF(width);
_trackPaths.at(i)->setPen(pen);
}
}
void Track::plot(QPainter *painter, const QRectF &target)
@ -143,11 +224,11 @@ void Track::plot(QPainter *painter, const QRectF &target)
adj = orig.adjusted(0, -diff/2, 0, diff/2);
}
for (int i = 0; i < _markers.size(); i++)
_markers.at(i)->setVisible(false);
showMarkers(false);
setTrackLineWidth(0);
_scene->render(painter, target, adj, Qt::KeepAspectRatioByExpanding);
for (int i = 0; i < _markers.size(); i++)
_markers.at(i)->setVisible(true);
setTrackLineWidth(TRACK_WIDTH * _scale);
showMarkers(true);
}
enum QPrinter::Orientation Track::orientation() const
@ -191,3 +272,35 @@ void Track::movePositionMarker(qreal val)
_markers.at(i)->setPos(pos);
}
}
void Track::drawBackground(QPainter *painter, const QRectF &rect)
{
if (_tracks.isEmpty() || !_map) {
painter->fillRect(rect, Qt::white);
return;
}
painter->setWorldMatrixEnabled(false);
QRectF rr(rect.topLeft() * _scale, rect.size());
QPoint tile = mercator2tile(QPointF(rr.topLeft().x(), -rr.topLeft().y()),
_zoom);
QPointF tm = tile2mercator(tile, _zoom);
QPoint tl = mapFromScene(QPointF(tm.x() / _scale, -tm.y() / _scale));
QList<Tile> tiles;
for (int i = 0; i <= rr.size().width() / TILE_SIZE + 1; i++) {
for (int j = 0; j <= rr.size().height() / TILE_SIZE + 1; j++) {
tiles.append(Tile(QPoint(tile.x() + i, tile.y() + j), _zoom));
}
}
_map->loadTiles(tiles);
for (int i = 0; i < tiles.count(); i++) {
Tile &t = tiles[i];
QPoint tp(tl.x() + (t.xy().rx() - tile.rx()) * TILE_SIZE,
tl.y() + (t.xy().ry() - tile.ry()) * TILE_SIZE);
painter->drawPixmap(tp, t.pixmap());
}
}

View File

@ -8,6 +8,7 @@
#include <QPrinter>
#include "poi.h"
#include "gpx.h"
#include "map.h"
#include "colorshop.h"
@ -23,29 +24,45 @@ public:
~Track();
void loadGPX(const GPX &gpx);
void loadPOI(const POI &poi);
void loadPOI(const POI &poi);
void clearPOI();
void clear();
void setMap(Map *map);
void plot(QPainter *painter, const QRectF &target);
enum QPrinter::Orientation orientation() const;
public slots:
void movePositionMarker(qreal val);
private slots:
void redraw();
private:
QTransform transform() const;
qreal trackScale() const;
qreal mapScale() const;
void rescale(qreal scale);
void showMarkers(bool show);
void setTrackLineWidth(qreal width);
void wheelEvent(QWheelEvent *event);
void drawBackground(QPainter *painter, const QRectF &rect);
QGraphicsScene *_scene;
QList<QVector<QPointF> > _tracks;
QList<QGraphicsPathItem*> _trackPaths;
QList<MarkerItem*> _markers;
QHash<Entry, POIItem*> _pois;
Map *_map;
ColorShop _colorShop;
qreal _maxLen;
qreal _scale;
int _zoom;
};
#endif // TRACK_H