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

Added support for Qt6

Removed support for Qt4 and Qt5 < 5.12
This commit is contained in:
Martin Tůma 2020-12-22 22:09:09 +01:00
parent b5972c8328
commit 97bea8c56c
81 changed files with 773 additions and 989 deletions

View File

@ -1,21 +1,21 @@
version: 7.38.{build} version: 8.0.{build}
configuration: configuration:
- Release - Release
image: image:
- Visual Studio 2017 - Visual Studio 2019
environment: environment:
NSISDIR: C:\Program Files (x86)\NSIS NSISDIR: C:\Program Files (x86)\NSIS
matrix: matrix:
- QTDIR: C:\Qt\5.13\msvc2017 - QTDIR: C:\Qt\5.15\msvc2019
NSI: gpxsee.nsi NSI: gpxsee.nsi
VCVARS: vcvars32.bat VCVARS: vcvars32.bat
OPENSSLDIR: C:\OpenSSL-v111-Win32\bin OPENSSLDIR: C:\OpenSSL-v111-Win32\bin
LIBCRYPTO: libssl-1_1.dll LIBCRYPTO: libssl-1_1.dll
LIBSSL: libcrypto-1_1.dll LIBSSL: libcrypto-1_1.dll
- QTDIR: C:\Qt\5.13\msvc2017_64 - QTDIR: C:\Qt\5.15\msvc2019_64
NSI: gpxsee64.nsi NSI: gpxsee64.nsi
VCVARS: vcvars64.bat VCVARS: vcvars64.bat
OPENSSLDIR: C:\OpenSSL-v111-Win64\bin OPENSSLDIR: C:\OpenSSL-v111-Win64\bin
@ -26,7 +26,7 @@ install:
- cmd: >- - cmd: >-
set PATH=%QTDIR%\bin;%NSISDIR%;%PATH% set PATH=%QTDIR%\bin;%NSISDIR%;%PATH%
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\"%VCVARS% call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\"%VCVARS%
build_script: build_script:
- cmd: >- - cmd: >-

View File

@ -4,13 +4,15 @@ os:
- linux - linux
- osx - osx
dist: focal
before_install: before_install:
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get -qq update; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get -qq update; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi
install: install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install qt; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install qt; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install libqt4-dev libqt4-opengl-dev; fi - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install qtbase5-dev libqt5opengl5-dev qttools5-dev-tools; fi
script: script:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then PATH=/usr/local/opt/qt/bin/:${PATH}; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then PATH=/usr/local/opt/qt/bin/:${PATH}; fi

View File

@ -18,8 +18,8 @@ GPXSee is a Qt-based GPS log file viewer and analyzer that supports all common G
## Build ## Build
Build requirements: Build requirements:
* Qt 4.8 or QT 5.x (Qt >= 5.10.1 recommended for all features) * Qt5 >= 5.12 or Qt 6.x
* C++03 or newer compiler (tested: msvc2015, gcc >= 4.8, clang/Apple LLVM version 8.1.0) * C++11 or newer compiler (tested: msvc2017, gcc 7.5.0, clang/Apple LLVM version 10.0.0)
Build steps: Build steps:
```shell ```shell

View File

@ -3,19 +3,16 @@ unix:!macx {
} else { } else {
TARGET = GPXSee TARGET = GPXSee
} }
VERSION = 7.38 VERSION = 8.0
QT += core \ QT += core \
gui \ gui \
network \ network \
sql \ sql \
concurrent concurrent \
greaterThan(QT_MAJOR_VERSION, 4) { widgets \
QT += widgets printsupport
QT += printsupport greaterThan(QT_MAJOR_VERSION, 5) {QT += openglwidgets}
}
lessThan(QT_MAJOR_VERSION, 5) {QT += opengl}
equals(QT_MAJOR_VERSION, 5) : lessThan(QT_MINOR_VERSION, 4) {QT += opengl}
INCLUDEPATH += ./src INCLUDEPATH += ./src
HEADERS += src/common/config.h \ HEADERS += src/common/config.h \
@ -27,10 +24,10 @@ HEADERS += src/common/config.h \
src/GUI/planeitem.h \ src/GUI/planeitem.h \
src/GUI/popup.h \ src/GUI/popup.h \
src/common/garmin.h \ src/common/garmin.h \
src/common/staticassert.h \
src/common/coordinates.h \ src/common/coordinates.h \
src/common/range.h \ src/common/range.h \
src/common/rectc.h \ src/common/rectc.h \
src/common/textcodec.h \
src/common/wgs84.h \ src/common/wgs84.h \
src/common/util.h \ src/common/util.h \
src/common/rtree.h \ src/common/rtree.h \
@ -58,7 +55,6 @@ HEADERS += src/common/config.h \
src/GUI/heartrategraph.h \ src/GUI/heartrategraph.h \
src/GUI/trackinfo.h \ src/GUI/trackinfo.h \
src/GUI/fileselectwidget.h \ src/GUI/fileselectwidget.h \
src/GUI/margins.h \
src/GUI/temperaturegraph.h \ src/GUI/temperaturegraph.h \
src/GUI/graphtab.h \ src/GUI/graphtab.h \
src/GUI/trackitem.h \ src/GUI/trackitem.h \
@ -74,7 +70,6 @@ HEADERS += src/common/config.h \
src/GUI/optionsdialog.h \ src/GUI/optionsdialog.h \
src/GUI/colorbox.h \ src/GUI/colorbox.h \
src/GUI/stylecombobox.h \ src/GUI/stylecombobox.h \
src/GUI/opengl.h \
src/GUI/timetype.h \ src/GUI/timetype.h \
src/GUI/percentslider.h \ src/GUI/percentslider.h \
src/GUI/elevationgraphitem.h \ src/GUI/elevationgraphitem.h \
@ -86,7 +81,6 @@ HEADERS += src/common/config.h \
src/GUI/gearratiographitem.h \ src/GUI/gearratiographitem.h \
src/GUI/oddspinbox.h \ src/GUI/oddspinbox.h \
src/GUI/settings.h \ src/GUI/settings.h \
src/GUI/cpuarch.h \
src/GUI/searchpointer.h \ src/GUI/searchpointer.h \
src/GUI/mapview.h \ src/GUI/mapview.h \
src/GUI/font.h \ src/GUI/font.h \
@ -208,7 +202,10 @@ HEADERS += src/common/config.h \
src/data/address.h \ src/data/address.h \
src/data/smlparser.h \ src/data/smlparser.h \
src/GUI/pdfexportdialog.h \ src/GUI/pdfexportdialog.h \
src/GUI/pngexportdialog.h src/GUI/pngexportdialog.h \
src/data/geojsonparser.h \
src/GUI/timezoneinfo.h
SOURCES += src/main.cpp \ SOURCES += src/main.cpp \
src/GUI/axislabelitem.cpp \ src/GUI/axislabelitem.cpp \
src/GUI/mapitem.cpp \ src/GUI/mapitem.cpp \
@ -217,6 +214,7 @@ SOURCES += src/main.cpp \
src/common/coordinates.cpp \ src/common/coordinates.cpp \
src/common/rectc.cpp \ src/common/rectc.cpp \
src/common/range.cpp \ src/common/range.cpp \
src/common/textcodec.cpp \
src/common/util.cpp \ src/common/util.cpp \
src/common/greatcircle.cpp \ src/common/greatcircle.cpp \
src/common/programpaths.cpp \ src/common/programpaths.cpp \
@ -362,19 +360,11 @@ SOURCES += src/main.cpp \
src/data/gpiparser.cpp \ src/data/gpiparser.cpp \
src/data/smlparser.cpp \ src/data/smlparser.cpp \
src/GUI/pdfexportdialog.cpp \ src/GUI/pdfexportdialog.cpp \
src/GUI/pngexportdialog.cpp src/GUI/pngexportdialog.cpp \
src/data/geojsonparser.cpp
greaterThan(QT_MAJOR_VERSION, 4) {
HEADERS += src/data/geojsonparser.h
SOURCES += src/data/geojsonparser.cpp
}
equals(QT_MAJOR_VERSION, 5):greaterThan(QT_MINOR_VERSION, 4) {
HEADERS += src/GUI/timezoneinfo.h
}
DEFINES += APP_VERSION=\\\"$$VERSION\\\" \ DEFINES += APP_VERSION=\\\"$$VERSION\\\" \
QT_NO_DEPRECATED_WARNINGS QT_NO_DEPRECATED_WARNINGS
DEFINES *= QT_USE_QSTRINGBUILDER
RESOURCES += gpxsee.qrc RESOURCES += gpxsee.qrc
TRANSLATIONS = lang/gpxsee_en.ts \ TRANSLATIONS = lang/gpxsee_en.ts \

View File

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

View File

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

View File

@ -6,6 +6,7 @@
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QLibraryInfo> #include <QLibraryInfo>
#include <QSettings> #include <QSettings>
#include <QSurfaceFormat>
#include "common/programpaths.h" #include "common/programpaths.h"
#include "common/config.h" #include "common/config.h"
#include "map/downloader.h" #include "map/downloader.h"
@ -13,7 +14,6 @@
#include "map/gcs.h" #include "map/gcs.h"
#include "map/pcs.h" #include "map/pcs.h"
#include "data/dem.h" #include "data/dem.h"
#include "opengl.h"
#include "gui.h" #include "gui.h"
#include "settings.h" #include "settings.h"
#include "mapaction.h" #include "mapaction.h"
@ -52,17 +52,18 @@ App::App(int &argc, char **argv) : QApplication(argc, argv)
"QThreadStorage: Thread X exited after QThreadStorage Y destroyed" */ "QThreadStorage: Thread X exited after QThreadStorage Y destroyed" */
Downloader::setNetworkManager(new QNetworkAccessManager(this)); Downloader::setNetworkManager(new QNetworkAccessManager(this));
DEM::setDir(ProgramPaths::demDir()); DEM::setDir(ProgramPaths::demDir());
OPENGL_SET_FORMAT(4, 8); QSurfaceFormat fmt;
fmt.setStencilBufferSize(8);
fmt.setSamples(4);
QSurfaceFormat::setDefaultFormat(fmt);
loadDatums(); loadDatums();
loadPCSs(); loadPCSs();
QSettings settings(qApp->applicationName(), qApp->applicationName()); QSettings settings(qApp->applicationName(), qApp->applicationName());
settings.beginGroup(OPTIONS_SETTINGS_GROUP); settings.beginGroup(OPTIONS_SETTINGS_GROUP);
#ifdef ENABLE_HTTP2
Downloader::enableHTTP2(settings.value(ENABLE_HTTP2_SETTING, Downloader::enableHTTP2(settings.value(ENABLE_HTTP2_SETTING,
ENABLE_HTTP2_DEFAULT).toBool()); ENABLE_HTTP2_DEFAULT).toBool());
#endif // ENABLE_HTTP2
Downloader::setTimeout(settings.value(CONNECTION_TIMEOUT_SETTING, Downloader::setTimeout(settings.value(CONNECTION_TIMEOUT_SETTING,
CONNECTION_TIMEOUT_DEFAULT).toInt()); CONNECTION_TIMEOUT_DEFAULT).toInt());
settings.endGroup(); settings.endGroup();

View File

@ -55,7 +55,8 @@ void ColorBox::mousePressEvent(QMouseEvent *event)
if (event->button() != Qt::LeftButton) if (event->button() != Qt::LeftButton)
return; return;
QColorDialog::ColorDialogOptions options = _alpha QColorDialog::ColorDialogOptions options = _alpha
? QColorDialog::ShowAlphaChannel : (QColorDialog::ColorDialogOptions)0; ? QColorDialog::ColorDialogOptions(QColorDialog::ShowAlphaChannel)
: QColorDialog::ColorDialogOptions();
QColor color = QColorDialog::getColor(_color, this, QString(), options); QColor color = QColorDialog::getColor(_color, this, QString(), options);
if (color.isValid()) { if (color.isValid()) {
_color = color; _color = color;

View File

@ -1,42 +0,0 @@
#ifndef CPUARCH_H
#define CPUARCH_H
#include <QtGlobal>
#if QT_VERSION < QT_VERSION_CHECK(5, 4, 0)
#if defined(__arm64__)
#define CPU_ARCH_STR "arm64"
#elif defined(__arm__) || defined(__TARGET_ARCH_ARM) || defined(_M_ARM)
#define CPU_ARCH_STR "arm"
#elif defined(__x86_64) || defined(__x86_64__) || defined(__amd64) \
|| defined(_M_X64)
#define CPU_ARCH_STR "x86_64"
#elif defined(__i386) || defined(__i386__) || defined(_M_IX86)
#define CPU_ARCH_STR "i386"
#elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
#define CPU_ARCH_STR "ia64"
#elif defined(_MIPS_ARCH_MIPS64) || defined(__mips64)
#define CPU_ARCH_STR "mips64"
#elif defined(__mips) || defined(__mips__) || defined(_M_MRX000)
#define CPU_ARCH_STR "mips"
#elif defined(__ppc64__) || defined(__powerpc64__) || defined(__64BIT__)
#define CPU_ARCH_STR "power64"
#elif defined(__ppc__) || defined(__ppc) || defined(__powerpc__) \
|| defined(_ARCH_COM) || defined(_ARCH_PWR) || defined(_ARCH_PPC) \
|| defined(_M_MPPC) || defined(_M_PPC)
#define CPU_ARCH_STR "power"
#else
#define CPU_ARCH_STR "unknown"
#endif
#define CPU_ARCH QString(CPU_ARCH_STR)
#else // QT_VERSION < 5.4
#include <QSysInfo>
#define CPU_ARCH QSysInfo::buildCpuArchitecture()
#endif // QT_VERSION < 5.4
#endif // CPUARCH_H

View File

@ -24,7 +24,7 @@ FileSelectWidget::FileSelectWidget(QWidget *parent) : QWidget(parent)
connect(_button, SIGNAL(clicked()), this, SLOT(browse())); connect(_button, SIGNAL(clicked()), this, SLOT(browse()));
QHBoxLayout *layout = new QHBoxLayout(); QHBoxLayout *layout = new QHBoxLayout();
layout->setMargin(0); layout->setContentsMargins(QMargins());
layout->addWidget(_edit); layout->addWidget(_edit);
layout->addWidget(_button); layout->addWidget(_button);
setLayout(layout); setLayout(layout);

View File

@ -6,8 +6,8 @@
#include <QGraphicsSimpleTextItem> #include <QGraphicsSimpleTextItem>
#include <QPalette> #include <QPalette>
#include <QLocale> #include <QLocale>
#include <QOpenGLWidget>
#include "data/graph.h" #include "data/graph.h"
#include "opengl.h"
#include "axisitem.h" #include "axisitem.h"
#include "axislabelitem.h" #include "axislabelitem.h"
#include "slideritem.h" #include "slideritem.h"
@ -351,23 +351,31 @@ void GraphView::wheelEvent(QWheelEvent *e)
{ {
static int deg = 0; static int deg = 0;
deg += e->delta() / 8; deg += e->angleDelta().y() / 8;
if (qAbs(deg) < 15) if (qAbs(deg) < 15)
return; return;
deg = 0; deg = 0;
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
QPointF pos = mapToScene(e->pos()); QPointF pos = mapToScene(e->pos());
#else // QT 5.15
QPointF pos = mapToScene(e->position().toPoint());
#endif // QT 5.15
QRectF gr(_grid->boundingRect()); QRectF gr(_grid->boundingRect());
QPointF r(pos.x() / gr.width(), pos.y() / gr.height()); QPointF r(pos.x() / gr.width(), pos.y() / gr.height());
_zoom = (e->delta() > 0) ? _zoom * 1.25 : qMax(_zoom / 1.25, 1.0); _zoom = (e->angleDelta().y() > 0) ? _zoom * 1.25 : qMax(_zoom / 1.25, 1.0);
redraw(); redraw();
QRectF ngr(_grid->boundingRect()); QRectF ngr(_grid->boundingRect());
QPointF npos(mapFromScene(QPointF(r.x() * ngr.width(), QPointF npos(mapFromScene(QPointF(r.x() * ngr.width(),
r.y() * ngr.height()))); r.y() * ngr.height())));
QScrollBar *sb = horizontalScrollBar(); QScrollBar *sb = horizontalScrollBar();
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
sb->setSliderPosition(sb->sliderPosition() + npos.x() - e->pos().x()); sb->setSliderPosition(sb->sliderPosition() + npos.x() - e->pos().x());
#else // QT 5.15
sb->setSliderPosition(sb->sliderPosition() + npos.x() - e->position().x());
#endif // QT 5.15
QGraphicsView::wheelEvent(e); QGraphicsView::wheelEvent(e);
} }
@ -456,8 +464,8 @@ void GraphView::updateSliderInfo()
'f', _precision) + UNIT_SPACE + _yUnits); 'f', _precision) + UNIT_SPACE + _yUnits);
if (cardinal && cardinal->secondaryGraph()) { if (cardinal && cardinal->secondaryGraph()) {
qreal delta = y - cardinal->secondaryGraph()->yAtX(_sliderPos); qreal delta = y - cardinal->secondaryGraph()->yAtX(_sliderPos);
yText += " " + QChar(0x0394) + l.toString(-delta * _yScale + _yOffset, yText += QString(" ") + QChar(0x0394) + l.toString(-delta * _yScale
'f', _precision) + UNIT_SPACE + _yUnits; + _yOffset, 'f', _precision) + UNIT_SPACE + _yUnits;
} }
_sliderInfo->setText(xText, yText); _sliderInfo->setText(xText, yText);
} }
@ -537,7 +545,7 @@ void GraphView::setGraphWidth(int width)
void GraphView::useOpenGL(bool use) void GraphView::useOpenGL(bool use)
{ {
if (use) if (use)
setViewport(new OPENGL_WIDGET); setViewport(new QOpenGLWidget);
else else
setViewport(new QWidget); setViewport(new QWidget);
} }

View File

@ -1,4 +1,3 @@
#include "common/config.h"
#include <QApplication> #include <QApplication>
#include <QSplitter> #include <QSplitter>
#include <QVBoxLayout> #include <QVBoxLayout>
@ -23,10 +22,8 @@
#include <QMimeData> #include <QMimeData>
#include <QUrl> #include <QUrl>
#include <QPixmapCache> #include <QPixmapCache>
#ifdef ENABLE_HIDPI
#include <QWindow> #include <QWindow>
#include <QScreen> #include <QScreen>
#endif // ENABLE_HIDPI
#include <QStyle> #include <QStyle>
#include "common/programpaths.h" #include "common/programpaths.h"
#include "data/data.h" #include "data/data.h"
@ -47,7 +44,6 @@
#include "mapview.h" #include "mapview.h"
#include "trackinfo.h" #include "trackinfo.h"
#include "filebrowser.h" #include "filebrowser.h"
#include "cpuarch.h"
#include "graphtab.h" #include "graphtab.h"
#include "graphitem.h" #include "graphitem.h"
#include "pathitem.h" #include "pathitem.h"
@ -174,8 +170,13 @@ void GUI::mapInitialized()
void GUI::createPOIFilesActions() void GUI::createPOIFilesActions()
{ {
_poiFilesSignalMapper = new QSignalMapper(this); _poiFilesSignalMapper = new QSignalMapper(this);
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
connect(_poiFilesSignalMapper, SIGNAL(mapped(int)), this, connect(_poiFilesSignalMapper, SIGNAL(mapped(int)), this,
SLOT(poiFileChecked(int))); SLOT(poiFileChecked(int)));
#else // QT 5.15
connect(_poiFilesSignalMapper, SIGNAL(mappedInt(int)), this,
SLOT(poiFileChecked(int)));
#endif // QT 5.15
for (int i = 0; i < _poi->files().count(); i++) for (int i = 0; i < _poi->files().count(); i++)
createPOIFileAction(_poi->files().at(i)); createPOIFileAction(_poi->files().at(i));
@ -691,8 +692,8 @@ void GUI::about()
msgBox.setWindowTitle(tr("About GPXSee")); msgBox.setWindowTitle(tr("About GPXSee"));
msgBox.setText("<h2>" + QString(APP_NAME) + "</h2><p><p>" + tr("Version %1") msgBox.setText("<h2>" + QString(APP_NAME) + "</h2><p><p>" + tr("Version %1")
.arg(QString(APP_VERSION) + " (" + CPU_ARCH + ", Qt " + QT_VERSION_STR .arg(QString(APP_VERSION) + " (" + QSysInfo::buildCpuArchitecture()
+ ")") + "</p>"); + ", Qt " + QT_VERSION_STR + ")") + "</p>");
msgBox.setInformativeText("<table width=\"300\"><tr><td>" msgBox.setInformativeText("<table width=\"300\"><tr><td>"
+ tr("GPXSee is distributed under the terms of the GNU General Public " + tr("GPXSee is distributed under the terms of the GNU General Public "
"License version 3. For more info about GPXSee visit the project " "License version 3. For more info about GPXSee visit the project "
@ -835,12 +836,7 @@ void GUI::loadData(const Data &data)
_trackDistance += track.distance(); _trackDistance += track.distance();
_time += track.time(); _time += track.time();
_movingTime += track.movingTime(); _movingTime += track.movingTime();
#ifdef ENABLE_TIMEZONES const QDateTime date = track.date().toTimeZone(_options.timeZone.zone());
const QDateTime date = track.date().toTimeZone(
_options.timeZone.zone());
#else // ENABLE_TIMEZONES
const QDateTime &date = track.date();
#endif // ENABLE_TIMEZONES
if (_dateRange.first.isNull() || _dateRange.first > date) if (_dateRange.first.isNull() || _dateRange.first > date)
_dateRange.first = date; _dateRange.first = date;
if (_dateRange.second.isNull() || _dateRange.second < date) if (_dateRange.second.isNull() || _dateRange.second < date)
@ -1014,23 +1010,18 @@ void GUI::openOptions()
if (options.connectionTimeout != _options.connectionTimeout) if (options.connectionTimeout != _options.connectionTimeout)
Downloader::setTimeout(options.connectionTimeout); Downloader::setTimeout(options.connectionTimeout);
#ifdef ENABLE_HTTP2
if (options.enableHTTP2 != _options.enableHTTP2) if (options.enableHTTP2 != _options.enableHTTP2)
Downloader::enableHTTP2(options.enableHTTP2); Downloader::enableHTTP2(options.enableHTTP2);
#endif // ENABLE_HTTP2
#ifdef ENABLE_HIDPI
if (options.hidpiMap != _options.hidpiMap) if (options.hidpiMap != _options.hidpiMap)
_mapView->setDevicePixelRatio(devicePixelRatioF(), _mapView->setDevicePixelRatio(devicePixelRatioF(),
options.hidpiMap ? devicePixelRatioF() : 1.0); options.hidpiMap ? devicePixelRatioF() : 1.0);
#endif // ENABLE_HIDPI
#ifdef ENABLE_TIMEZONES
if (options.timeZone != _options.timeZone) { if (options.timeZone != _options.timeZone) {
_mapView->setTimeZone(options.timeZone.zone()); _mapView->setTimeZone(options.timeZone.zone());
_dateRange.first = _dateRange.first.toTimeZone(options.timeZone.zone()); _dateRange.first = _dateRange.first.toTimeZone(options.timeZone.zone());
_dateRange.second = _dateRange.second.toTimeZone(options.timeZone.zone()); _dateRange.second = _dateRange.second.toTimeZone(options.timeZone.zone());
} }
#endif // ENABLE_TIMEZONES
if (reload) if (reload)
reloadFiles(); reloadFiles();
@ -1058,12 +1049,9 @@ void GUI::exportPDFFile()
printer.setCreator(QString(APP_NAME) + QString(" ") printer.setCreator(QString(APP_NAME) + QString(" ")
+ QString(APP_VERSION)); + QString(APP_VERSION));
printer.setResolution(_pdfExport.resolution); printer.setResolution(_pdfExport.resolution);
printer.setOrientation(_pdfExport.orientation); printer.setPageLayout(QPageLayout(QPageSize(_pdfExport.paperSize),
_pdfExport.orientation, _pdfExport.margins, QPageLayout::Millimeter));
printer.setOutputFileName(_pdfExport.fileName); printer.setOutputFileName(_pdfExport.fileName);
printer.setPaperSize(_pdfExport.paperSize);
printer.setPageMargins(_pdfExport.margins.left(), _pdfExport.margins.top(),
_pdfExport.margins.right(), _pdfExport.margins.bottom(),
QPrinter::Millimeter);
plot(&printer); plot(&printer);
} }
@ -2127,21 +2115,17 @@ void GUI::writeSettings()
if (_options.showSecondarySpeed != SHOW_SECONDARY_SPEED_DEFAULT) if (_options.showSecondarySpeed != SHOW_SECONDARY_SPEED_DEFAULT)
settings.setValue(SHOW_SECONDARY_SPEED_SETTING, settings.setValue(SHOW_SECONDARY_SPEED_SETTING,
_options.showSecondarySpeed); _options.showSecondarySpeed);
#ifdef ENABLE_TIMEZONES
if (_options.timeZone != TimeZoneInfo()) if (_options.timeZone != TimeZoneInfo())
settings.setValue(TIME_ZONE_SETTING, QVariant::fromValue( settings.setValue(TIME_ZONE_SETTING, QVariant::fromValue(
_options.timeZone)); _options.timeZone));
#endif // ENABLE_TIMEZONES
if (_options.useSegments != USE_SEGMENTS_DEFAULT) if (_options.useSegments != USE_SEGMENTS_DEFAULT)
settings.setValue(USE_SEGMENTS_SETTING, _options.useSegments); settings.setValue(USE_SEGMENTS_SETTING, _options.useSegments);
if (_options.poiRadius != POI_RADIUS_DEFAULT) if (_options.poiRadius != POI_RADIUS_DEFAULT)
settings.setValue(POI_RADIUS_SETTING, _options.poiRadius); settings.setValue(POI_RADIUS_SETTING, _options.poiRadius);
if (_options.useOpenGL != USE_OPENGL_DEFAULT) if (_options.useOpenGL != USE_OPENGL_DEFAULT)
settings.setValue(USE_OPENGL_SETTING, _options.useOpenGL); settings.setValue(USE_OPENGL_SETTING, _options.useOpenGL);
#ifdef ENABLE_HTTP2
if (_options.enableHTTP2 != ENABLE_HTTP2_DEFAULT) if (_options.enableHTTP2 != ENABLE_HTTP2_DEFAULT)
settings.setValue(ENABLE_HTTP2_SETTING, _options.enableHTTP2); settings.setValue(ENABLE_HTTP2_SETTING, _options.enableHTTP2);
#endif // ENABLE_HTTP2
if (_options.pixmapCache != PIXMAP_CACHE_DEFAULT) if (_options.pixmapCache != PIXMAP_CACHE_DEFAULT)
settings.setValue(PIXMAP_CACHE_SETTING, _options.pixmapCache); settings.setValue(PIXMAP_CACHE_SETTING, _options.pixmapCache);
if (_options.connectionTimeout != CONNECTION_TIMEOUT_DEFAULT) if (_options.connectionTimeout != CONNECTION_TIMEOUT_DEFAULT)
@ -2167,10 +2151,8 @@ void GUI::writeSettings()
settings.setValue(SLIDER_COLOR_SETTING, _options.sliderColor); settings.setValue(SLIDER_COLOR_SETTING, _options.sliderColor);
if (_options.projection != PROJECTION_DEFAULT) if (_options.projection != PROJECTION_DEFAULT)
settings.setValue(PROJECTION_SETTING, _options.projection); settings.setValue(PROJECTION_SETTING, _options.projection);
#ifdef ENABLE_HIDPI
if (_options.hidpiMap != HIDPI_MAP_DEFAULT) if (_options.hidpiMap != HIDPI_MAP_DEFAULT)
settings.setValue(HIDPI_MAP_SETTING, _options.hidpiMap); settings.setValue(HIDPI_MAP_SETTING, _options.hidpiMap);
#endif // ENABLE_HIDPI
settings.endGroup(); settings.endGroup();
} }
@ -2326,11 +2308,11 @@ void GUI::readSettings()
settings.endGroup(); settings.endGroup();
settings.beginGroup(PDF_EXPORT_SETTINGS_GROUP); settings.beginGroup(PDF_EXPORT_SETTINGS_GROUP);
_pdfExport.orientation = (QPrinter::Orientation) settings.value( _pdfExport.orientation = (QPageLayout::Orientation) settings.value(
PAPER_ORIENTATION_SETTING, PAPER_ORIENTATION_DEFAULT).toInt(); PAPER_ORIENTATION_SETTING, PAPER_ORIENTATION_DEFAULT).toInt();
_pdfExport.resolution = settings.value(RESOLUTION_SETTING, _pdfExport.resolution = settings.value(RESOLUTION_SETTING,
RESOLUTION_DEFAULT).toInt(); RESOLUTION_DEFAULT).toInt();
_pdfExport.paperSize = (QPrinter::PaperSize) settings.value( _pdfExport.paperSize = (QPageSize::PageSizeId) settings.value(
PAPER_SIZE_SETTING, PAPER_SIZE_DEFAULT).toInt(); PAPER_SIZE_SETTING, PAPER_SIZE_DEFAULT).toInt();
qreal ml = settings.value(PDF_MARGIN_LEFT_SETTING, PDF_MARGIN_LEFT_DEFAULT) qreal ml = settings.value(PDF_MARGIN_LEFT_SETTING, PDF_MARGIN_LEFT_DEFAULT)
.toReal(); .toReal();
@ -2340,7 +2322,7 @@ void GUI::readSettings()
PDF_MARGIN_RIGHT_DEFAULT).toReal(); PDF_MARGIN_RIGHT_DEFAULT).toReal();
qreal mb = settings.value(PDF_MARGIN_BOTTOM_SETTING, qreal mb = settings.value(PDF_MARGIN_BOTTOM_SETTING,
PDF_MARGIN_BOTTOM_DEFAULT).toReal(); PDF_MARGIN_BOTTOM_DEFAULT).toReal();
_pdfExport.margins = MarginsF(ml, mt, mr, mb); _pdfExport.margins = QMarginsF(ml, mt, mr, mb);
_pdfExport.fileName = settings.value(PDF_FILENAME_SETTING, _pdfExport.fileName = settings.value(PDF_FILENAME_SETTING,
PDF_FILENAME_DEFAULT).toString(); PDF_FILENAME_DEFAULT).toString();
settings.endGroup(); settings.endGroup();
@ -2425,9 +2407,7 @@ void GUI::readSettings()
_options.showSecondarySpeed = settings.value( _options.showSecondarySpeed = settings.value(
SHOW_SECONDARY_SPEED_SETTING, SHOW_SECONDARY_SPEED_SETTING,
SHOW_SECONDARY_SPEED_DEFAULT).toBool(); SHOW_SECONDARY_SPEED_DEFAULT).toBool();
#ifdef ENABLE_TIMEZONES
_options.timeZone = settings.value(TIME_ZONE_SETTING).value<TimeZoneInfo>(); _options.timeZone = settings.value(TIME_ZONE_SETTING).value<TimeZoneInfo>();
#endif // ENABLE_TIMEZONES
_options.useSegments = settings.value(USE_SEGMENTS_SETTING, _options.useSegments = settings.value(USE_SEGMENTS_SETTING,
USE_SEGMENTS_DEFAULT).toBool(); USE_SEGMENTS_DEFAULT).toBool();
_options.automaticPause = settings.value(AUTOMATIC_PAUSE_SETTING, _options.automaticPause = settings.value(AUTOMATIC_PAUSE_SETTING,
@ -2438,10 +2418,8 @@ void GUI::readSettings()
.toInt(); .toInt();
_options.useOpenGL = settings.value(USE_OPENGL_SETTING, USE_OPENGL_DEFAULT) _options.useOpenGL = settings.value(USE_OPENGL_SETTING, USE_OPENGL_DEFAULT)
.toBool(); .toBool();
#ifdef ENABLE_HTTP2
_options.enableHTTP2 = settings.value(ENABLE_HTTP2_SETTING, _options.enableHTTP2 = settings.value(ENABLE_HTTP2_SETTING,
ENABLE_HTTP2_DEFAULT).toBool(); ENABLE_HTTP2_DEFAULT).toBool();
#endif // ENABLE_HTTP2
_options.pixmapCache = settings.value(PIXMAP_CACHE_SETTING, _options.pixmapCache = settings.value(PIXMAP_CACHE_SETTING,
PIXMAP_CACHE_DEFAULT).toInt(); PIXMAP_CACHE_DEFAULT).toInt();
_options.connectionTimeout = settings.value(CONNECTION_TIMEOUT_SETTING, _options.connectionTimeout = settings.value(CONNECTION_TIMEOUT_SETTING,
@ -2466,10 +2444,8 @@ void GUI::readSettings()
SLIDER_COLOR_DEFAULT).value<QColor>(); SLIDER_COLOR_DEFAULT).value<QColor>();
_options.projection = settings.value(PROJECTION_SETTING, PROJECTION_DEFAULT) _options.projection = settings.value(PROJECTION_SETTING, PROJECTION_DEFAULT)
.toInt(); .toInt();
#ifdef ENABLE_HIDPI
_options.hidpiMap = settings.value(HIDPI_MAP_SETTING, HIDPI_MAP_SETTING) _options.hidpiMap = settings.value(HIDPI_MAP_SETTING, HIDPI_MAP_SETTING)
.toBool(); .toBool();
#endif // ENABLE_HIDPI
_mapView->setPalette(_options.palette); _mapView->setPalette(_options.palette);
_mapView->setMapOpacity(_options.mapOpacity); _mapView->setMapOpacity(_options.mapOpacity);
@ -2489,14 +2465,10 @@ void GUI::readSettings()
_mapView->setMarkerColor(_options.sliderColor); _mapView->setMarkerColor(_options.sliderColor);
if (_options.useOpenGL) if (_options.useOpenGL)
_mapView->useOpenGL(true); _mapView->useOpenGL(true);
#ifdef ENABLE_HIDPI
_mapView->setDevicePixelRatio(devicePixelRatioF(), _mapView->setDevicePixelRatio(devicePixelRatioF(),
_options.hidpiMap ? devicePixelRatioF() : 1.0); _options.hidpiMap ? devicePixelRatioF() : 1.0);
#endif // ENABLE_HIDPI
_mapView->setProjection(_options.projection); _mapView->setProjection(_options.projection);
#ifdef ENABLE_TIMEZONES
_mapView->setTimeZone(_options.timeZone.zone()); _mapView->setTimeZone(_options.timeZone.zone());
#endif // ENABLE_TIMEZONES
for (int i = 0; i < _tabs.count(); i++) { for (int i = 0; i < _tabs.count(); i++) {
_tabs.at(i)->setPalette(_options.palette); _tabs.at(i)->setPalette(_options.palette);
@ -2587,20 +2559,17 @@ void GUI::show()
{ {
QMainWindow::show(); QMainWindow::show();
#ifdef ENABLE_HIDPI
QWindow *w = windowHandle(); QWindow *w = windowHandle();
connect(w->screen(), SIGNAL(logicalDotsPerInchChanged(qreal)), this, connect(w->screen(), SIGNAL(logicalDotsPerInchChanged(qreal)), this,
SLOT(logicalDotsPerInchChanged(qreal))); SLOT(logicalDotsPerInchChanged(qreal)));
connect(w, SIGNAL(screenChanged(QScreen*)), this, connect(w, SIGNAL(screenChanged(QScreen*)), this,
SLOT(screenChanged(QScreen*))); SLOT(screenChanged(QScreen*)));
#endif // ENABLE_HIDPI
_mapView->fitContentToSize(); _mapView->fitContentToSize();
} }
void GUI::screenChanged(QScreen *screen) void GUI::screenChanged(QScreen *screen)
{ {
#ifdef ENABLE_HIDPI
_mapView->setDevicePixelRatio(devicePixelRatioF(), _mapView->setDevicePixelRatio(devicePixelRatioF(),
_options.hidpiMap ? devicePixelRatioF() : 1.0); _options.hidpiMap ? devicePixelRatioF() : 1.0);
@ -2608,17 +2577,12 @@ void GUI::screenChanged(QScreen *screen)
SLOT(logicalDotsPerInchChanged(qreal))); SLOT(logicalDotsPerInchChanged(qreal)));
connect(screen, SIGNAL(logicalDotsPerInchChanged(qreal)), this, connect(screen, SIGNAL(logicalDotsPerInchChanged(qreal)), this,
SLOT(logicalDotsPerInchChanged(qreal))); SLOT(logicalDotsPerInchChanged(qreal)));
#else // ENABLE_HIDPI
Q_UNUSED(screen);
#endif // ENABLE_HIDPI
} }
void GUI::logicalDotsPerInchChanged(qreal dpi) void GUI::logicalDotsPerInchChanged(qreal dpi)
{ {
Q_UNUSED(dpi) Q_UNUSED(dpi)
#ifdef ENABLE_HIDPI
_mapView->setDevicePixelRatio(devicePixelRatioF(), _mapView->setDevicePixelRatio(devicePixelRatioF(),
_options.hidpiMap ? devicePixelRatioF() : 1.0); _options.hidpiMap ? devicePixelRatioF() : 1.0);
#endif // ENBLE_HIDPI
} }

View File

@ -18,9 +18,9 @@ void InfoItem::updateBoundingRect()
for (QList<KV<QString, QString> >::const_iterator i = _list.constBegin(); for (QList<KV<QString, QString> >::const_iterator i = _list.constBegin();
i != _list.constEnd(); i++) { i != _list.constEnd(); i++) {
width += fm.width(i->key() + ": "); width += fm.boundingRect(i->key() + ": ").width();
width += fm.width(i->value()) + ((i == _list.constEnd() - 1) width += fm.boundingRect(i->value()).width()
? 0 : PADDING); + ((i == _list.constEnd() - 1) ? 0 : PADDING);
} }
_boundingRect = QRectF(0, 0, width, _list.isEmpty() ? 0 : fm.height()); _boundingRect = QRectF(0, 0, width, _list.isEmpty() ? 0 : fm.height());
@ -40,10 +40,10 @@ void InfoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
for (QList<KV<QString, QString> >::const_iterator i = _list.constBegin(); for (QList<KV<QString, QString> >::const_iterator i = _list.constBegin();
i != _list.constEnd(); i++) { i != _list.constEnd(); i++) {
painter->drawText(width, fm.height() - fm.descent(), i->key() + ": "); painter->drawText(width, fm.height() - fm.descent(), i->key() + ": ");
width += fm.width(i->key() + ": "); width += fm.boundingRect(i->key() + ": ").width();
painter->drawText(width, fm.height() - fm.descent(), i->value()); painter->drawText(width, fm.height() - fm.descent(), i->value());
width += fm.width(i->value()) + ((i == _list.constEnd() - 1) width += fm.boundingRect(i->value()).width()
? 0 : PADDING); + ((i == _list.constEnd() - 1) ? 0 : PADDING);
if (i != _list.constEnd() - 1) { if (i != _list.constEnd() - 1) {
painter->save(); painter->save();
painter->setPen(Qt::gray); painter->setPen(Qt::gray);

View File

@ -4,11 +4,11 @@
#include <QApplication> #include <QApplication>
#include <QScrollBar> #include <QScrollBar>
#include <QClipboard> #include <QClipboard>
#include <QOpenGLWidget>
#include "data/poi.h" #include "data/poi.h"
#include "data/data.h" #include "data/data.h"
#include "map/map.h" #include "map/map.h"
#include "map/pcs.h" #include "map/pcs.h"
#include "opengl.h"
#include "trackitem.h" #include "trackitem.h"
#include "routeitem.h" #include "routeitem.h"
#include "waypointitem.h" #include "waypointitem.h"
@ -101,10 +101,8 @@ MapView::MapView(Map *map, POI *poi, QWidget *parent)
_poiSize = 8; _poiSize = 8;
_poiColor = Qt::black; _poiColor = Qt::black;
#ifdef ENABLE_HIDPI
_deviceRatio = 1.0; _deviceRatio = 1.0;
_mapRatio = 1.0; _mapRatio = 1.0;
#endif // ENABLE_HIDPI
_opengl = false; _opengl = false;
_plot = false; _plot = false;
_digitalZoom = 0; _digitalZoom = 0;
@ -372,9 +370,7 @@ void MapView::setMap(Map *map)
_map = map; _map = map;
_map->load(); _map->load();
_map->setProjection(_projection); _map->setProjection(_projection);
#ifdef ENABLE_HIDPI
_map->setDevicePixelRatio(_deviceRatio, _mapRatio); _map->setDevicePixelRatio(_deviceRatio, _mapRatio);
#endif // ENABLE_HIDPI
connect(_map, SIGNAL(tilesLoaded()), this, SLOT(reloadMap())); connect(_map, SIGNAL(tilesLoaded()), this, SLOT(reloadMap()));
digitalZoom(0); digitalZoom(0);
@ -480,12 +476,8 @@ void MapView::setCoordinatesFormat(CoordinatesFormat format)
void MapView::setTimeZone(const QTimeZone &zone) void MapView::setTimeZone(const QTimeZone &zone)
{ {
#ifdef ENABLE_TIMEZONES
WaypointItem::setTimeZone(zone); WaypointItem::setTimeZone(zone);
PathItem::setTimeZone(zone); PathItem::setTimeZone(zone);
#else // ENABLE_TIMEZONES
Q_UNUSED(zone);
#endif // ENABLE_TIMEZONES
} }
void MapView::clearMapCache() void MapView::clearMapCache()
@ -550,12 +542,16 @@ void MapView::wheelEvent(QWheelEvent *event)
{ {
static int deg = 0; static int deg = 0;
deg += event->delta() / 8; deg += event->angleDelta().y() / 8;
if (qAbs(deg) < 15) if (qAbs(deg) < 15)
return; return;
deg = 0; deg = 0;
zoom((event->delta() > 0) ? 1 : -1, event->pos()); #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
zoom((event->angleDelta().y() > 0) ? 1 : -1, event->pos());
#else // QT 5.15
zoom((event->angleDelta().y() > 0) ? 1 : -1, event->position().toPoint());
#endif // QT 5.15
} }
void MapView::mouseDoubleClickEvent(QMouseEvent *event) void MapView::mouseDoubleClickEvent(QMouseEvent *event)
@ -626,9 +622,7 @@ void MapView::plot(QPainter *painter, const QRectF &target, qreal scale,
// Enter plot mode // Enter plot mode
setUpdatesEnabled(false); setUpdatesEnabled(false);
_plot = true; _plot = true;
#ifdef ENABLE_HIDPI
_map->setDevicePixelRatio(_deviceRatio, 1.0); _map->setDevicePixelRatio(_deviceRatio, 1.0);
#endif // ENABLE_HIDPI
// Compute sizes & ratios // Compute sizes & ratios
orig = viewport()->rect(); orig = viewport()->rect();
@ -695,9 +689,7 @@ void MapView::plot(QPainter *painter, const QRectF &target, qreal scale,
_mapScale->setPos(origPos); _mapScale->setPos(origPos);
// Exit plot mode // Exit plot mode
#ifdef ENABLE_HIDPI
_map->setDevicePixelRatio(_deviceRatio, _mapRatio); _map->setDevicePixelRatio(_deviceRatio, _mapRatio);
#endif // ENABLE_HIDPI
_plot = false; _plot = false;
setUpdatesEnabled(true); setUpdatesEnabled(true);
} }
@ -1019,7 +1011,7 @@ void MapView::useOpenGL(bool use)
_opengl = use; _opengl = use;
if (use) if (use)
setViewport(new OPENGL_WIDGET); setViewport(new QOpenGLWidget);
else else
setViewport(new QWidget); setViewport(new QWidget);
} }
@ -1046,7 +1038,6 @@ void MapView::reloadMap()
void MapView::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio) void MapView::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
{ {
#ifdef ENABLE_HIDPI
if (_deviceRatio == deviceRatio && _mapRatio == mapRatio) if (_deviceRatio == deviceRatio && _mapRatio == mapRatio)
return; return;
@ -1079,10 +1070,6 @@ void MapView::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
centerOn(nc); centerOn(nc);
reloadMap(); reloadMap();
#else // ENABLE_HIDPI
Q_UNUSED(deviceRatio);
Q_UNUSED(mapRatio);
#endif // ENABLE_HIDPI
} }
void MapView::setProjection(int id) void MapView::setProjection(int id)

View File

@ -171,10 +171,8 @@ private:
bool _plot; bool _plot;
QCursor _cursor; QCursor _cursor;
#ifdef ENABLE_HIDPI
qreal _deviceRatio; qreal _deviceRatio;
qreal _mapRatio; qreal _mapRatio;
#endif // ENABLE_HIDPI
bool _opengl; bool _opengl;
}; };

View File

@ -1,44 +0,0 @@
#ifndef MARGINS_H
#define MARGINS_H
#include <QtGlobal>
#include <QDebug>
class MarginsF
{
public:
MarginsF() {_left = 0; _top = 0; _right = 0; _bottom = 0;}
MarginsF(qreal left, qreal top, qreal right, qreal bottom)
{_left = left, _top = top; _right = right; _bottom = bottom;}
qreal left() const {return _left;}
qreal top() const {return _top;}
qreal right() const {return _right;}
qreal bottom() const {return _bottom;}
private:
qreal _left, _top, _right, _bottom;
};
inline MarginsF operator*(const MarginsF &margins, qreal factor)
{
return MarginsF(margins.left() * factor, margins.top() * factor,
margins.right() * factor, margins.bottom() * factor);
}
inline MarginsF operator/(const MarginsF &margins, qreal factor)
{
return MarginsF(margins.left() / factor, margins.top() / factor,
margins.right() / factor, margins.bottom() / factor);
}
#ifndef QT_NO_DEBUG
inline QDebug operator<<(QDebug dbg, const MarginsF &margins)
{
dbg.nospace() << "MarginsF(" << margins.left() << ", " << margins.top()
<< ", " << margins.right() << margins.bottom() << ")";
return dbg.space();
}
#endif // QT_NO_DEBUG
#endif // MARGINS_H

View File

@ -75,7 +75,7 @@ MarginsFWidget::MarginsFWidget(QWidget *parent) : QWidget(parent)
setLayout(layout); setLayout(layout);
} }
void MarginsFWidget::setValue(const MarginsF &value) void MarginsFWidget::setValue(const QMarginsF &value)
{ {
_top->setValue(value.top()); _top->setValue(value.top());
_bottom->setValue(value.bottom()); _bottom->setValue(value.bottom());
@ -104,8 +104,8 @@ void MarginsFWidget::setSingleStep(qreal step)
_right->setSingleStep(step); _right->setSingleStep(step);
} }
MarginsF MarginsFWidget::value() const QMarginsF MarginsFWidget::value() const
{ {
return MarginsF(_left->value(), _top->value(), _right->value(), return QMarginsF(_left->value(), _top->value(), _right->value(),
_bottom->value()); _bottom->value());
} }

View File

@ -3,7 +3,6 @@
#include <QWidget> #include <QWidget>
#include <QMargins> #include <QMargins>
#include "margins.h"
class QSpinBox; class QSpinBox;
class QDoubleSpinBox; class QDoubleSpinBox;
@ -33,8 +32,8 @@ class MarginsFWidget : public QWidget
public: public:
MarginsFWidget(QWidget *parent = 0); MarginsFWidget(QWidget *parent = 0);
MarginsF value() const; QMarginsF value() const;
void setValue(const MarginsF &value); void setValue(const QMarginsF &value);
void setUnits(const QString &units); void setUnits(const QString &units);
void setSingleStep(qreal step); void setSingleStep(qreal step);

View File

@ -1,28 +0,0 @@
#include <QtGlobal>
#if QT_VERSION < QT_VERSION_CHECK(5, 4, 0)
#include <QGLWidget>
#include <QGLFormat>
#else
#include <QOpenGLWidget>
#include <QSurfaceFormat>
#endif
#if QT_VERSION < QT_VERSION_CHECK(5, 4, 0)
#define OPENGL_WIDGET QGLWidget
#else
#define OPENGL_WIDGET QOpenGLWidget
#endif
#if QT_VERSION < QT_VERSION_CHECK(5, 4, 0)
#define OPENGL_SET_FORMAT(samples, stencilBuffer) \
{QGLFormat fmt; \
fmt.setStencilBufferSize(stencilBuffer); \
fmt.setSamples(samples); \
QGLFormat::setDefaultFormat(fmt);}
#else
#define OPENGL_SET_FORMAT(samples, stencilBuffer) \
{QSurfaceFormat fmt; \
fmt.setStencilBufferSize(stencilBuffer); \
fmt.setSamples(samples); \
QSurfaceFormat::setDefaultFormat(fmt);}
#endif

View File

@ -49,7 +49,7 @@ QWidget *OptionsDialog::createMapPage()
_projection = new LimitedComboBox(200); _projection = new LimitedComboBox(200);
QList<KV<int, QString> > projections(GCS::list() + PCS::list()); QList<KV<int, QString> > projections(GCS::list() + PCS::list());
qSort(projections); std::sort(projections.begin(), projections.end());
for (int i = 0; i < projections.size(); i++) { for (int i = 0; i < projections.size(); i++) {
QString text = QString::number(projections.at(i).key()) + " - " QString text = QString::number(projections.at(i).key()) + " - "
@ -58,7 +58,6 @@ QWidget *OptionsDialog::createMapPage()
} }
_projection->setCurrentIndex(_projection->findData(_options.projection)); _projection->setCurrentIndex(_projection->findData(_options.projection));
#ifdef ENABLE_HIDPI
_hidpi = new QRadioButton(tr("High-resolution")); _hidpi = new QRadioButton(tr("High-resolution"));
_lodpi = new QRadioButton(tr("Standard")); _lodpi = new QRadioButton(tr("Standard"));
if (_options.hidpiMap) if (_options.hidpiMap)
@ -75,7 +74,6 @@ QWidget *OptionsDialog::createMapPage()
llo->setWordWrap(true); llo->setWordWrap(true);
lhi->setFont(f); lhi->setFont(f);
llo->setFont(f); llo->setFont(f);
#endif // ENABLE_HIDPI
QFormLayout *vectorLayout = new QFormLayout(); QFormLayout *vectorLayout = new QFormLayout();
vectorLayout->addRow(tr("Projection:"), _projection); vectorLayout->addRow(tr("Projection:"), _projection);
@ -86,7 +84,6 @@ QWidget *OptionsDialog::createMapPage()
vectorMapsTabLayout->addStretch(); vectorMapsTabLayout->addStretch();
vectorMapsTab->setLayout(vectorMapsTabLayout); vectorMapsTab->setLayout(vectorMapsTabLayout);
#ifdef ENABLE_HIDPI
QVBoxLayout *hidpiTabLayout = new QVBoxLayout(); QVBoxLayout *hidpiTabLayout = new QVBoxLayout();
hidpiTabLayout->addWidget(_lodpi); hidpiTabLayout->addWidget(_lodpi);
hidpiTabLayout->addWidget(llo); hidpiTabLayout->addWidget(llo);
@ -97,13 +94,10 @@ QWidget *OptionsDialog::createMapPage()
QWidget *hidpiTab = new QWidget(); QWidget *hidpiTab = new QWidget();
hidpiTab->setLayout(hidpiTabLayout); hidpiTab->setLayout(hidpiTabLayout);
#endif // ENABLE_HIDPI
QTabWidget *mapPage = new QTabWidget(); QTabWidget *mapPage = new QTabWidget();
mapPage->addTab(vectorMapsTab, tr("Vector maps")); mapPage->addTab(vectorMapsTab, tr("Vector maps"));
#ifdef ENABLE_HIDPI
mapPage->addTab(hidpiTab, tr("HiDPI display mode")); mapPage->addTab(hidpiTab, tr("HiDPI display mode"));
#endif // ENABLE_HIDPI
return mapPage; return mapPage;
} }
@ -416,7 +410,6 @@ QWidget *OptionsDialog::createDataPage()
_showSecondaryElevation = new QCheckBox(tr("Show secondary elevation")); _showSecondaryElevation = new QCheckBox(tr("Show secondary elevation"));
_showSecondaryElevation->setChecked(_options.showSecondaryElevation); _showSecondaryElevation->setChecked(_options.showSecondaryElevation);
#ifdef ENABLE_TIMEZONES
_utcZone = new QRadioButton(tr("UTC")); _utcZone = new QRadioButton(tr("UTC"));
_systemZone = new QRadioButton(tr("System")); _systemZone = new QRadioButton(tr("System"));
_customZone = new QRadioButton(tr("Custom")); _customZone = new QRadioButton(tr("Custom"));
@ -437,7 +430,6 @@ QWidget *OptionsDialog::createDataPage()
QHBoxLayout *customZoneLayout = new QHBoxLayout(); QHBoxLayout *customZoneLayout = new QHBoxLayout();
customZoneLayout->addSpacing(20); customZoneLayout->addSpacing(20);
customZoneLayout->addWidget(_timeZone); customZoneLayout->addWidget(_timeZone);
#endif // ENABLE_TIMEZONES
_useSegments = new QCheckBox(tr("Use segments")); _useSegments = new QCheckBox(tr("Use segments"));
_useSegments->setChecked(_options.useSegments); _useSegments->setChecked(_options.useSegments);
@ -462,7 +454,6 @@ QWidget *OptionsDialog::createDataPage()
elevationOptions->addWidget(_dataDEMElevation); elevationOptions->addWidget(_dataDEMElevation);
elevationOptions->addWidget(_showSecondaryElevation); elevationOptions->addWidget(_showSecondaryElevation);
#ifdef ENABLE_TIMEZONES
QButtonGroup *timeZoneGroup = new QButtonGroup(this); QButtonGroup *timeZoneGroup = new QButtonGroup(this);
timeZoneGroup->addButton(_utcZone); timeZoneGroup->addButton(_utcZone);
timeZoneGroup->addButton(_systemZone); timeZoneGroup->addButton(_systemZone);
@ -472,15 +463,12 @@ QWidget *OptionsDialog::createDataPage()
zoneOptions->addWidget(_systemZone); zoneOptions->addWidget(_systemZone);
zoneOptions->addWidget(_customZone); zoneOptions->addWidget(_customZone);
zoneOptions->addItem(customZoneLayout); zoneOptions->addItem(customZoneLayout);
#endif // ENABLE_TIMEZONES
QFormLayout *formLayout = new QFormLayout(); QFormLayout *formLayout = new QFormLayout();
formLayout->addRow(tr("Speed:"), speedOptions); formLayout->addRow(tr("Speed:"), speedOptions);
formLayout->addRow(tr("Elevation:"), elevationOptions); formLayout->addRow(tr("Elevation:"), elevationOptions);
#ifdef ENABLE_TIMEZONES
formLayout->addRow(tr("Time zone:"), zoneOptions); formLayout->addRow(tr("Time zone:"), zoneOptions);
#endif // ENABLE_TIMEZONES
QFormLayout *segmentsLayout = new QFormLayout(); QFormLayout *segmentsLayout = new QFormLayout();
segmentsLayout->addWidget(_useSegments); segmentsLayout->addWidget(_useSegments);
@ -492,9 +480,7 @@ QWidget *OptionsDialog::createDataPage()
#else // Q_OS_MAC #else // Q_OS_MAC
QFormLayout *speedLayout = new QFormLayout(); QFormLayout *speedLayout = new QFormLayout();
QFormLayout *elevationLayout = new QFormLayout(); QFormLayout *elevationLayout = new QFormLayout();
#ifdef ENABLE_TIMEZONES
QFormLayout *timeZoneLayout = new QFormLayout(); QFormLayout *timeZoneLayout = new QFormLayout();
#endif // ENABLE_TIMEZONES
QFormLayout *segmentsLayout = new QFormLayout(); QFormLayout *segmentsLayout = new QFormLayout();
speedLayout->addWidget(_computedSpeed); speedLayout->addWidget(_computedSpeed);
@ -511,7 +497,6 @@ QWidget *OptionsDialog::createDataPage()
QGroupBox *elevationBox = new QGroupBox(tr("Elevation")); QGroupBox *elevationBox = new QGroupBox(tr("Elevation"));
elevationBox->setLayout(elevationLayout); elevationBox->setLayout(elevationLayout);
#ifdef ENABLE_TIMEZONES
timeZoneLayout->addWidget(_utcZone); timeZoneLayout->addWidget(_utcZone);
timeZoneLayout->addWidget(_systemZone); timeZoneLayout->addWidget(_systemZone);
timeZoneLayout->addWidget(_customZone); timeZoneLayout->addWidget(_customZone);
@ -519,15 +504,12 @@ QWidget *OptionsDialog::createDataPage()
QGroupBox *timeZoneBox = new QGroupBox(tr("Time zone")); QGroupBox *timeZoneBox = new QGroupBox(tr("Time zone"));
timeZoneBox->setLayout(timeZoneLayout); timeZoneBox->setLayout(timeZoneLayout);
#endif // ENABLE_TIMEZONES
segmentsLayout->addWidget(_useSegments); segmentsLayout->addWidget(_useSegments);
sourceTabLayout->addWidget(speedBox); sourceTabLayout->addWidget(speedBox);
sourceTabLayout->addWidget(elevationBox); sourceTabLayout->addWidget(elevationBox);
#ifdef ENABLE_TIMEZONES
sourceTabLayout->addWidget(timeZoneBox); sourceTabLayout->addWidget(timeZoneBox);
#endif // ENABLE_TIMEZONES
sourceTabLayout->addLayout(segmentsLayout); sourceTabLayout->addLayout(segmentsLayout);
#endif // Q_OS_MAC #endif // Q_OS_MAC
sourceTabLayout->addStretch(); sourceTabLayout->addStretch();
@ -648,10 +630,8 @@ QWidget *OptionsDialog::createSystemPage()
{ {
_useOpenGL = new QCheckBox(tr("Use OpenGL")); _useOpenGL = new QCheckBox(tr("Use OpenGL"));
_useOpenGL->setChecked(_options.useOpenGL); _useOpenGL->setChecked(_options.useOpenGL);
#ifdef ENABLE_HTTP2
_enableHTTP2 = new QCheckBox(tr("Enable HTTP/2")); _enableHTTP2 = new QCheckBox(tr("Enable HTTP/2"));
_enableHTTP2->setChecked(_options.enableHTTP2); _enableHTTP2->setChecked(_options.enableHTTP2);
#endif // ENABLE_HTTP2
_pixmapCache = new QSpinBox(); _pixmapCache = new QSpinBox();
_pixmapCache->setMinimum(16); _pixmapCache->setMinimum(16);
@ -670,9 +650,7 @@ QWidget *OptionsDialog::createSystemPage()
formLayout->addRow(tr("Connection timeout:"), _connectionTimeout); formLayout->addRow(tr("Connection timeout:"), _connectionTimeout);
QFormLayout *checkboxLayout = new QFormLayout(); QFormLayout *checkboxLayout = new QFormLayout();
#ifdef ENABLE_HTTP2
checkboxLayout->addWidget(_enableHTTP2); checkboxLayout->addWidget(_enableHTTP2);
#endif // ENABLE_HTTP2
checkboxLayout->addWidget(_useOpenGL); checkboxLayout->addWidget(_useOpenGL);
QWidget *systemTab = new QWidget(); QWidget *systemTab = new QWidget();
@ -766,9 +744,7 @@ void OptionsDialog::accept()
_options.projection = _projection->itemData(_projection->currentIndex()) _options.projection = _projection->itemData(_projection->currentIndex())
.toInt(); .toInt();
#ifdef ENABLE_HIDPI
_options.hidpiMap = _hidpi->isChecked(); _options.hidpiMap = _hidpi->isChecked();
#endif // ENABLE_HIDPI
_options.elevationFilter = _elevationFilter->value(); _options.elevationFilter = _elevationFilter->value();
_options.speedFilter = _speedFilter->value(); _options.speedFilter = _speedFilter->value();
@ -787,13 +763,11 @@ void OptionsDialog::accept()
_options.dataUseDEM = _dataDEMElevation->isChecked(); _options.dataUseDEM = _dataDEMElevation->isChecked();
_options.showSecondaryElevation = _showSecondaryElevation->isChecked(); _options.showSecondaryElevation = _showSecondaryElevation->isChecked();
_options.showSecondarySpeed = _showSecondarySpeed->isChecked(); _options.showSecondarySpeed = _showSecondarySpeed->isChecked();
#ifdef ENABLE_TIMEZONES
_options.timeZone.setType(_utcZone->isChecked() _options.timeZone.setType(_utcZone->isChecked()
? TimeZoneInfo::UTC : _systemZone->isChecked() ? TimeZoneInfo::UTC : _systemZone->isChecked()
? TimeZoneInfo::System : TimeZoneInfo::Custom); ? TimeZoneInfo::System : TimeZoneInfo::Custom);
_options.timeZone.setCustomZone(QTimeZone(_timeZone->currentText() _options.timeZone.setCustomZone(QTimeZone(_timeZone->currentText()
.toLatin1())); .toLatin1()));
#endif // ENABLE_TIMEZONES
_options.useSegments = _useSegments->isChecked(); _options.useSegments = _useSegments->isChecked();
qreal poiRadius = (_units == Imperial) qreal poiRadius = (_units == Imperial)
@ -803,9 +777,7 @@ void OptionsDialog::accept()
_options.poiRadius = poiRadius; _options.poiRadius = poiRadius;
_options.useOpenGL = _useOpenGL->isChecked(); _options.useOpenGL = _useOpenGL->isChecked();
#ifdef ENABLE_HTTP2
_options.enableHTTP2 = _enableHTTP2->isChecked(); _options.enableHTTP2 = _enableHTTP2->isChecked();
#endif // ENABLE_HTTP2
_options.pixmapCache = _pixmapCache->value(); _options.pixmapCache = _pixmapCache->value();
_options.connectionTimeout = _connectionTimeout->value(); _options.connectionTimeout = _connectionTimeout->value();

View File

@ -2,12 +2,9 @@
#define OPTIONSDIALOG_H #define OPTIONSDIALOG_H
#include <QDialog> #include <QDialog>
#include "common/config.h"
#include "palette.h" #include "palette.h"
#include "units.h" #include "units.h"
#ifdef ENABLE_TIMEZONES
#include "timezoneinfo.h" #include "timezoneinfo.h"
#endif // ENABLE_TIMEZONES
class ColorBox; class ColorBox;
class StyleComboBox; class StyleComboBox;
@ -43,9 +40,7 @@ struct Options {
QColor backgroundColor; QColor backgroundColor;
// Map // Map
int projection; int projection;
#ifdef ENABLE_HIDPI
bool hidpiMap; bool hidpiMap;
#endif // ENABLE_HIDPI
// Data // Data
int elevationFilter; int elevationFilter;
int speedFilter; int speedFilter;
@ -60,17 +55,13 @@ struct Options {
bool dataUseDEM; bool dataUseDEM;
bool showSecondaryElevation; bool showSecondaryElevation;
bool showSecondarySpeed; bool showSecondarySpeed;
#ifdef ENABLE_TIMEZONES
TimeZoneInfo timeZone; TimeZoneInfo timeZone;
#endif // ENABLE_TIMEZONES
bool useSegments; bool useSegments;
// POI // POI
int poiRadius; int poiRadius;
// System // System
bool useOpenGL; bool useOpenGL;
#ifdef ENABLE_HTTP2
bool enableHTTP2; bool enableHTTP2;
#endif // ENABLE_HTTP2
int pixmapCache; int pixmapCache;
int connectionTimeout; int connectionTimeout;
// Print/Export // Print/Export
@ -130,10 +121,8 @@ private:
QCheckBox *_graphAA; QCheckBox *_graphAA;
// Map // Map
LimitedComboBox *_projection; LimitedComboBox *_projection;
#ifdef ENABLE_HIDPI
QRadioButton *_hidpi; QRadioButton *_hidpi;
QRadioButton *_lodpi; QRadioButton *_lodpi;
#endif // ENABLE_HIDPI
// Data // Data
OddSpinBox *_elevationFilter; OddSpinBox *_elevationFilter;
OddSpinBox *_speedFilter; OddSpinBox *_speedFilter;
@ -151,12 +140,10 @@ private:
QRadioButton *_dataDEMElevation; QRadioButton *_dataDEMElevation;
QCheckBox *_showSecondaryElevation; QCheckBox *_showSecondaryElevation;
QCheckBox *_showSecondarySpeed; QCheckBox *_showSecondarySpeed;
#ifdef ENABLE_TIMEZONES
QRadioButton *_utcZone; QRadioButton *_utcZone;
QRadioButton *_systemZone; QRadioButton *_systemZone;
QRadioButton *_customZone; QRadioButton *_customZone;
QComboBox *_timeZone; QComboBox *_timeZone;
#endif // ENABLE_TIMEZONES
QCheckBox *_useSegments; QCheckBox *_useSegments;
// POI // POI
QDoubleSpinBox *_poiRadius; QDoubleSpinBox *_poiRadius;
@ -164,9 +151,7 @@ private:
QSpinBox *_pixmapCache; QSpinBox *_pixmapCache;
QSpinBox *_connectionTimeout; QSpinBox *_connectionTimeout;
QCheckBox *_useOpenGL; QCheckBox *_useOpenGL;
#ifdef ENABLE_HTTP2
QCheckBox *_enableHTTP2; QCheckBox *_enableHTTP2;
#endif // ENABLE_HTTP2
// Print/Export // Print/Export
QRadioButton *_wysiwyg; QRadioButton *_wysiwyg;
QRadioButton *_hires; QRadioButton *_hires;

View File

@ -24,8 +24,13 @@ public:
{return !(*this == other);} {return !(*this == other);}
private: private:
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
qreal _h, _s, _v, _a, _shift; qreal _h, _s, _v, _a, _shift;
qreal _state; qreal _state;
#else // QT6
float _h, _s, _v, _a, _shift;
float _state;
#endif // QT6
}; };
#ifndef QT_NO_DEBUG #ifndef QT_NO_DEBUG

View File

@ -22,9 +22,7 @@ static inline unsigned segments(qreal distance)
} }
Units PathItem::_units = Metric; Units PathItem::_units = Metric;
#ifdef ENABLE_TIMEZONES
QTimeZone PathItem::_timeZone = QTimeZone::utc(); QTimeZone PathItem::_timeZone = QTimeZone::utc();
#endif // ENABLE_TIMEZONES
PathItem::PathItem(const Path &path, Map *map, QGraphicsItem *parent) PathItem::PathItem(const Path &path, Map *map, QGraphicsItem *parent)
: GraphicsItem(parent), _path(path), _map(map) : GraphicsItem(parent), _path(path), _map(map)
@ -68,14 +66,22 @@ void PathItem::addSegment(const Coordinates &c1, const Coordinates &c2)
QLineF l(QPointF(c1.lon(), c1.lat()), QPointF(c2.lon() + 360, QLineF l(QPointF(c1.lon(), c1.lat()), QPointF(c2.lon() + 360,
c2.lat())); c2.lat()));
QLineF dl(QPointF(180, -90), QPointF(180, 90)); QLineF dl(QPointF(180, -90), QPointF(180, 90));
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
l.intersect(dl, &p); l.intersect(dl, &p);
#else // QT 5.15
l.intersects(dl, &p);
#endif // QT 5.15
_painterPath.lineTo(_map->ll2xy(Coordinates(180, p.y()))); _painterPath.lineTo(_map->ll2xy(Coordinates(180, p.y())));
_painterPath.moveTo(_map->ll2xy(Coordinates(-180, p.y()))); _painterPath.moveTo(_map->ll2xy(Coordinates(-180, p.y())));
} else { } else {
QLineF l(QPointF(c1.lon(), c1.lat()), QPointF(c2.lon() - 360, QLineF l(QPointF(c1.lon(), c1.lat()), QPointF(c2.lon() - 360,
c2.lat())); c2.lat()));
QLineF dl(QPointF(-180, -90), QPointF(-180, 90)); QLineF dl(QPointF(-180, -90), QPointF(-180, 90));
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
l.intersect(dl, &p); l.intersect(dl, &p);
#else // QT 5.15
l.intersects(dl, &p);
#endif // QT 5.15
_painterPath.lineTo(_map->ll2xy(Coordinates(-180, p.y()))); _painterPath.lineTo(_map->ll2xy(Coordinates(-180, p.y())));
_painterPath.moveTo(_map->ll2xy(Coordinates(180, p.y()))); _painterPath.moveTo(_map->ll2xy(Coordinates(180, p.y())));
} }

View File

@ -1,12 +1,9 @@
#ifndef PATHITEM_H #ifndef PATHITEM_H
#define PATHITEM_H #define PATHITEM_H
#include "common/config.h"
#include <QGraphicsObject> #include <QGraphicsObject>
#include <QPen> #include <QPen>
#ifdef ENABLE_TIMEZONES
#include <QTimeZone> #include <QTimeZone>
#endif // ENABLE_TIMEZONES
#include "data/path.h" #include "data/path.h"
#include "markeritem.h" #include "markeritem.h"
#include "units.h" #include "units.h"
@ -43,9 +40,7 @@ public:
void updateTicks(); void updateTicks();
static void setUnits(Units units) {_units = units;} static void setUnits(Units units) {_units = units;}
#ifdef ENABLE_TIMEZONES
static void setTimeZone(const QTimeZone &zone) {_timeZone = zone;} static void setTimeZone(const QTimeZone &zone) {_timeZone = zone;}
#endif // ENABLE_TIMEZONES
public slots: public slots:
void moveMarker(qreal distance); void moveMarker(qreal distance);
@ -60,9 +55,7 @@ protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event); void mousePressEvent(QGraphicsSceneMouseEvent *event);
static Units _units; static Units _units;
#ifdef ENABLE_TIMEZONES
static QTimeZone _timeZone; static QTimeZone _timeZone;
#endif // ENABLE_TIMEZONES
private: private:
const PathSegment *segment(qreal x) const; const PathSegment *segment(qreal x) const;

View File

@ -24,18 +24,18 @@ PDFExportDialog::PDFExportDialog(PDFExport &exp, Units units, QWidget *parent)
_fileSelect->setFile(_export.fileName); _fileSelect->setFile(_export.fileName);
_paperSize = new QComboBox(); _paperSize = new QComboBox();
_paperSize->addItem("A2", QPrinter::A2); _paperSize->addItem("A2", QPageSize::PageSizeId::A2);
_paperSize->addItem("A3", QPrinter::A3); _paperSize->addItem("A3", QPageSize::PageSizeId::A3);
_paperSize->addItem("A4", QPrinter::A4); _paperSize->addItem("A4", QPageSize::PageSizeId::A4);
_paperSize->addItem("A5", QPrinter::A5); _paperSize->addItem("A5", QPageSize::PageSizeId::A5);
_paperSize->addItem("A6", QPrinter::A6); _paperSize->addItem("A6", QPageSize::PageSizeId::A6);
_paperSize->addItem("B3", QPrinter::B3); _paperSize->addItem("B3", QPageSize::PageSizeId::B3);
_paperSize->addItem("B4", QPrinter::B4); _paperSize->addItem("B4", QPageSize::PageSizeId::B4);
_paperSize->addItem("B5", QPrinter::B5); _paperSize->addItem("B5", QPageSize::PageSizeId::B5);
_paperSize->addItem("B6", QPrinter::B6); _paperSize->addItem("B6", QPageSize::PageSizeId::B6);
_paperSize->addItem("Tabloid", QPrinter::Tabloid); _paperSize->addItem("Tabloid", QPageSize::PageSizeId::Tabloid);
_paperSize->addItem("Legal", QPrinter::Legal); _paperSize->addItem("Legal", QPageSize::PageSizeId::Legal);
_paperSize->addItem("Letter", QPrinter::Letter); _paperSize->addItem("Letter", QPageSize::PageSizeId::Letter);
if ((index = _paperSize->findData(_export.paperSize)) >= 0) if ((index = _paperSize->findData(_export.paperSize)) >= 0)
_paperSize->setCurrentIndex(index); _paperSize->setCurrentIndex(index);
@ -51,7 +51,7 @@ PDFExportDialog::PDFExportDialog(PDFExport &exp, Units units, QWidget *parent)
QHBoxLayout *orientationLayout = new QHBoxLayout(); QHBoxLayout *orientationLayout = new QHBoxLayout();
orientationLayout->addWidget(_portrait); orientationLayout->addWidget(_portrait);
orientationLayout->addWidget(_landscape); orientationLayout->addWidget(_landscape);
if (_export.orientation == QPrinter::Portrait) if (_export.orientation == QPageLayout::Orientation::Portrait)
_portrait->setChecked(true); _portrait->setChecked(true);
else else
_landscape->setChecked(true); _landscape->setChecked(true);
@ -116,9 +116,9 @@ void PDFExportDialog::accept()
return; return;
} }
QPrinter::Orientation orientation = _portrait->isChecked() QPageLayout::Orientation orientation = _portrait->isChecked()
? QPrinter::Portrait : QPrinter::Landscape; ? QPageLayout::Orientation::Portrait : QPageLayout::Orientation::Landscape;
QPrinter::PaperSize paperSize = static_cast<QPrinter::PaperSize> QPageSize::PageSizeId paperSize = static_cast<QPageSize::PageSizeId>
(_paperSize->itemData(_paperSize->currentIndex()).toInt()); (_paperSize->itemData(_paperSize->currentIndex()).toInt());
int resolution = _resolution->itemData(_resolution->currentIndex()).toInt(); int resolution = _resolution->itemData(_resolution->currentIndex()).toInt();

View File

@ -3,7 +3,6 @@
#include <QDialog> #include <QDialog>
#include <QPrinter> #include <QPrinter>
#include "margins.h"
#include "units.h" #include "units.h"
class QComboBox; class QComboBox;
@ -14,9 +13,9 @@ class MarginsFWidget;
struct PDFExport struct PDFExport
{ {
QString fileName; QString fileName;
QPrinter::PaperSize paperSize; QPageSize::PageSizeId paperSize;
QPrinter::Orientation orientation; QPageLayout::Orientation orientation;
MarginsF margins; QMarginsF margins;
int resolution; int resolution;
}; };

View File

@ -3,7 +3,6 @@
#include <QDialog> #include <QDialog>
#include <QMargins> #include <QMargins>
#include "margins.h"
class FileSelectWidget; class FileSelectWidget;
class MarginsWidget; class MarginsWidget;

View File

@ -4,9 +4,12 @@
#include <QStyleOptionFrame> #include <QStyleOptionFrame>
#include <QLabel> #include <QLabel>
#include <QMouseEvent> #include <QMouseEvent>
#include <QApplication>
#include <QDesktopWidget>
#include <QBasicTimer> #include <QBasicTimer>
#include <QScreen>
#include <QApplication>
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
#include <QDesktopWidget>
#endif // QT 5.15
#include "popup.h" #include "popup.h"
@ -36,10 +39,7 @@ PopupLabel *PopupLabel::_instance = 0;
PopupLabel::PopupLabel(const QString &text, QWidget *parent) PopupLabel::PopupLabel(const QString &text, QWidget *parent)
: QLabel(text, parent, Qt::ToolTip | Qt::BypassGraphicsProxyWidget : QLabel(text, parent, Qt::ToolTip | Qt::BypassGraphicsProxyWidget
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) | Qt::WindowDoesNotAcceptFocus)
| Qt::WindowDoesNotAcceptFocus
#endif // QT5
)
{ {
delete _instance; delete _instance;
_instance = this; _instance = this;
@ -74,7 +74,7 @@ void PopupLabel::paintEvent(QPaintEvent *event)
{ {
QStylePainter p(this); QStylePainter p(this);
QStyleOptionFrame opt; QStyleOptionFrame opt;
opt.init(this); opt.initFrom(this);
p.drawPrimitive(QStyle::PE_PanelTipLabel, opt); p.drawPrimitive(QStyle::PE_PanelTipLabel, opt);
p.end(); p.end();
QLabel::paintEvent(event); QLabel::paintEvent(event);
@ -125,7 +125,11 @@ bool PopupLabel::eventFilter(QObject *o, QEvent *ev)
void PopupLabel::place(const QPoint &pos, QWidget *w) void PopupLabel::place(const QPoint &pos, QWidget *w)
{ {
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
QRect screen = QApplication::desktop()->screenGeometry(w); QRect screen = QApplication::desktop()->screenGeometry(w);
#else // QT 5.15
QRect screen = w->screen()->geometry();
#endif // QT 5.15
QPoint p(pos.x() + 2, pos.y() + 16); QPoint p(pos.x() + 2, pos.y() + 16);
if (p.x() + width() > screen.x() + screen.width()) if (p.x() + width() > screen.x() + screen.width())

View File

@ -68,10 +68,11 @@
#define PDF_EXPORT_SETTINGS_GROUP "Export" #define PDF_EXPORT_SETTINGS_GROUP "Export"
#define PAPER_ORIENTATION_SETTING "orientation" #define PAPER_ORIENTATION_SETTING "orientation"
#define PAPER_ORIENTATION_DEFAULT QPrinter::Portrait #define PAPER_ORIENTATION_DEFAULT QPageLayout::Orientation::Portrait
#define PAPER_SIZE_SETTING "size" #define PAPER_SIZE_SETTING "size"
#define PAPER_SIZE_DEFAULT (IMPERIAL_UNITS() ? QPrinter::Letter \ #define PAPER_SIZE_DEFAULT (IMPERIAL_UNITS() \
: QPrinter::A4) ? QPageSize::PageSizeId::Letter \
: QPageSize::PageSizeId::A4)
#define PDF_MARGIN_LEFT_SETTING "marginLeft" #define PDF_MARGIN_LEFT_SETTING "marginLeft"
#define PDF_MARGIN_LEFT_DEFAULT 5 /* mm */ #define PDF_MARGIN_LEFT_DEFAULT 5 /* mm */
#define PDF_MARGIN_TOP_SETTING "marginTop" #define PDF_MARGIN_TOP_SETTING "marginTop"

View File

@ -18,7 +18,7 @@ void SliderInfoItem::updateBoundingRect()
{ {
QFontMetrics fm(_font); QFontMetrics fm(_font);
qreal width = qMax(fm.width(_x), fm.width(_y)); qreal width = qMax(fm.boundingRect(_x).width(), fm.boundingRect(_y).width());
qreal height = 2 * fm.height() - 2*fm.descent(); qreal height = 2 * fm.height() - 2*fm.descent();
_boundingRect = (_side == Right) _boundingRect = (_side == Right)
@ -35,16 +35,16 @@ void SliderInfoItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
QRectF rx, ry; QRectF rx, ry;
qreal width = qMax(fm.width(_x), fm.width(_y)); qreal width = qMax(fm.boundingRect(_x).width(), fm.boundingRect(_y).width());
if (_side == Right) { if (_side == Right) {
ry = QRectF(SIZE, -fm.height() + fm.descent(), fm.width(_y), ry = QRectF(SIZE, -fm.height() + fm.descent(), fm.boundingRect(_y).width(),
fm.height() - fm.descent()); fm.height() - fm.descent());
rx = QRectF(SIZE, 0, fm.width(_x), fm.height() rx = QRectF(SIZE, 0, fm.boundingRect(_x).width(), fm.height()
- fm.descent()); - fm.descent());
} else { } else {
ry = QRectF(-(width + SIZE), -fm.height() + fm.descent(), fm.width(_y), ry = QRectF(-(width + SIZE), -fm.height() + fm.descent(),
fm.height() - fm.descent()); fm.boundingRect(_y).width(), fm.height() - fm.descent());
rx = QRectF(-(width + SIZE), 0, fm.width(_x), fm.height() rx = QRectF(-(width + SIZE), 0, fm.boundingRect(_x).width(), fm.height()
- fm.descent()); - fm.descent());
} }

View File

@ -8,6 +8,7 @@
QString TrackItem::info() const QString TrackItem::info() const
{ {
ToolTip tt; ToolTip tt;
QLocale l;
if (!_name.isEmpty()) if (!_name.isEmpty())
tt.insert(tr("Name"), _name); tt.insert(tr("Name"), _name);
@ -22,13 +23,7 @@ QString TrackItem::info() const
if (_movingTime > 0) if (_movingTime > 0)
tt.insert(tr("Moving time"), Format::timeSpan(_movingTime)); tt.insert(tr("Moving time"), Format::timeSpan(_movingTime));
if (!_date.isNull()) if (!_date.isNull())
tt.insert(tr("Date"), tt.insert(tr("Date"), l.toString(_date.toTimeZone(_timeZone)));
#ifdef ENABLE_TIMEZONES
_date.toTimeZone(_timeZone)
#else // ENABLE_TIMEZONES
_date
#endif // ENABLE_TIMEZONES
.toString(Qt::SystemLocaleShortDate));
if (!_links.isEmpty()) { if (!_links.isEmpty()) {
QString links; QString links;
for (int i = 0; i < _links.size(); i++) { for (int i = 0; i < _links.size(); i++) {

View File

@ -16,13 +16,12 @@
Units WaypointItem::_units = Metric; Units WaypointItem::_units = Metric;
CoordinatesFormat WaypointItem::_format = DecimalDegrees; CoordinatesFormat WaypointItem::_format = DecimalDegrees;
#ifdef ENABLE_TIMEZONES
QTimeZone WaypointItem::_timeZone = QTimeZone::utc(); QTimeZone WaypointItem::_timeZone = QTimeZone::utc();
#endif // ENABLE_TIMEZONES
QString WaypointItem::info() const QString WaypointItem::info() const
{ {
ToolTip tt; ToolTip tt;
QLocale l;
if (!_waypoint.name().isEmpty()) if (!_waypoint.name().isEmpty())
tt.insert(qApp->translate("WaypointItem", "Name"), _waypoint.name()); tt.insert(qApp->translate("WaypointItem", "Name"), _waypoint.name());
@ -37,12 +36,8 @@ QString WaypointItem::info() const
} }
if (_waypoint.timestamp().isValid()) if (_waypoint.timestamp().isValid())
tt.insert(qApp->translate("WaypointItem", "Date"), tt.insert(qApp->translate("WaypointItem", "Date"),
#ifdef ENABLE_TIMEZONES l.toString(_waypoint.timestamp().toTimeZone(_timeZone),
_waypoint.timestamp().toTimeZone(_timeZone) QLocale::ShortFormat));
#else // ENABLE_TIMEZONES
_waypoint.timestamp()
#endif // ENABLE_TIMEZONES
.toString(Qt::SystemLocaleShortDate));
if (!_waypoint.description().isEmpty()) if (!_waypoint.description().isEmpty())
tt.insert(qApp->translate("WaypointItem", "Description"), tt.insert(qApp->translate("WaypointItem", "Description"),
_waypoint.description()); _waypoint.description());

View File

@ -1,13 +1,10 @@
#ifndef WAYPOINTITEM_H #ifndef WAYPOINTITEM_H
#define WAYPOINTITEM_H #define WAYPOINTITEM_H
#include "common/config.h"
#include <cmath> #include <cmath>
#include <QGraphicsItem> #include <QGraphicsItem>
#include <QFont> #include <QFont>
#ifdef ENABLE_TIMEZONES
#include <QTimeZone> #include <QTimeZone>
#endif // ENABLE_TIMEZONES
#include "data/waypoint.h" #include "data/waypoint.h"
#include "map/map.h" #include "map/map.h"
#include "units.h" #include "units.h"
@ -38,9 +35,7 @@ public:
static void setUnits(Units units) {_units = units;} static void setUnits(Units units) {_units = units;}
static void setCoordinatesFormat(CoordinatesFormat format) static void setCoordinatesFormat(CoordinatesFormat format)
{_format = format;} {_format = format;}
#ifdef ENABLE_TIMEZONES
static void setTimeZone(const QTimeZone &zone) {_timeZone = zone;} static void setTimeZone(const QTimeZone &zone) {_timeZone = zone;}
#endif // ENABLE_TIMEZONES
protected: protected:
void hoverEnterEvent(QGraphicsSceneHoverEvent *event); void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
@ -60,9 +55,7 @@ private:
static Units _units; static Units _units;
static CoordinatesFormat _format; static CoordinatesFormat _format;
#ifdef ENABLE_TIMEZONES
static QTimeZone _timeZone; static QTimeZone _timeZone;
#endif // ENABLE_TIMEZONES
}; };
#endif // WAYPOINTITEM_H #endif // WAYPOINTITEM_H

View File

@ -6,20 +6,4 @@
#define APP_NAME "GPXSee" #define APP_NAME "GPXSee"
#define APP_HOMEPAGE "http://www.gpxsee.org" #define APP_HOMEPAGE "http://www.gpxsee.org"
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 1)
#define ENABLE_HTTP2
#endif // QT >= 5.10.1
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
#define ENABLE_HIDPI
#endif // QT >= 5.6
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#define ENABLE_GEOJSON
#endif // QT >= 5.0
#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
#define ENABLE_TIMEZONES
#endif // QT >= 5.5
#endif /* CONFIG_H */ #endif /* CONFIG_H */

View File

@ -1,5 +1,6 @@
#include <QtGlobal> #include <QtGlobal>
#include <QDir> #include <QDir>
#include <QStandardPaths>
#include "programpaths.h" #include "programpaths.h"
@ -16,119 +17,6 @@
#define TYP_FILE "style.typ" #define TYP_FILE "style.typ"
#if QT_VERSION < QT_VERSION_CHECK(5, 4, 0)
#include <QApplication>
#if defined(Q_OS_WIN32)
#define USER_DIR QDir::homePath() + QString("/AppData/Roaming/") \
+ qApp->applicationName()
#define GLOBAL_DIR QApplication::applicationDirPath()
#elif defined(Q_OS_MAC)
#define USER_DIR QDir::homePath() \
+ QString("/Library/Application Support/") \
+ qApp->applicationName()
#define GLOBAL_DIR QApplication::applicationDirPath() \
+ QString("/../Resources")
#else
#define USER_DIR QDir::homePath() + QString("/.local/share/") \
+ qApp->applicationName()
#define GLOBAL_DIR QString(PREFIX "/share/") + qApp->applicationName()
#endif
static QString dir(const QString &dirName, bool writable = false)
{
QDir userDir(QDir(USER_DIR).filePath(dirName));
if (writable || userDir.exists())
return userDir.absolutePath();
else {
QDir globalDir(QDir(GLOBAL_DIR).filePath(dirName));
if (globalDir.exists())
return globalDir.absolutePath();
else
return QString();
}
}
static QString file(const QString &path, const QString &fileName)
{
if (path.isNull())
return QString();
QFileInfo fi(QDir(path).filePath(fileName));
return fi.exists() ? fi.absoluteFilePath() : QString();
}
QString ProgramPaths::mapDir(bool writable)
{
return dir(MAP_DIR, writable);
}
QString ProgramPaths::poiDir(bool writable)
{
return dir(POI_DIR, writable);
}
QString ProgramPaths::csvDir(bool writable)
{
return dir(CSV_DIR, writable);
}
QString ProgramPaths::demDir(bool writable)
{
return dir(DEM_DIR, writable);
}
QString ProgramPaths::styleDir(bool writable)
{
return dir(STYLE_DIR, writable);
}
QString ProgramPaths::tilesDir()
{
#if defined(Q_OS_WIN32)
return QDir::homePath() + QString("/AppData/Local/")
+ qApp->applicationName() + QString("/cache/") + QString(TILES_DIR);
#elif defined(Q_OS_MAC)
return QDir::homePath() + QString("/Library/Caches/")
+ qApp->applicationName() + QString("/" TILES_DIR);
#else
return QDir::homePath() + QString("/.cache/") + qApp->applicationName()
+ QString("/" TILES_DIR);
#endif
}
QString ProgramPaths::translationsDir()
{
return dir(TRANSLATIONS_DIR);
}
QString ProgramPaths::ellipsoidsFile()
{
return file(dir(CSV_DIR), ELLIPSOID_FILE);
}
QString ProgramPaths::gcsFile()
{
return file(dir(CSV_DIR), GCS_FILE);
}
QString ProgramPaths::pcsFile()
{
return file(dir(CSV_DIR), PCS_FILE);
}
QString ProgramPaths::typFile()
{
return file(dir(STYLE_DIR), TYP_FILE);
}
#else // QT_VERSION < 5
#include <QStandardPaths>
QString ProgramPaths::mapDir(bool writable) QString ProgramPaths::mapDir(bool writable)
{ {
if (writable) if (writable)
@ -214,5 +102,3 @@ QString ProgramPaths::typFile()
return QStandardPaths::locate(QStandardPaths::AppDataLocation, return QStandardPaths::locate(QStandardPaths::AppDataLocation,
STYLE_DIR "/" TYP_FILE, QStandardPaths::LocateFile); STYLE_DIR "/" TYP_FILE, QStandardPaths::LocateFile);
} }
#endif // QT_VERSION < 5

View File

@ -1,11 +0,0 @@
#ifndef ASSERT_H
#define ASSERT_H
template<bool> struct CompileTimeAssert;
template<> struct CompileTimeAssert <true> {};
#define STATIC_ASSERT(e) \
(CompileTimeAssert <(e) != 0>())
#endif // ASSERT_H

214
src/common/textcodec.cpp Normal file
View File

@ -0,0 +1,214 @@
#include <QVector>
#include "textcodec.h"
static const char32_t cp1250[] = {
0x20AC, 0x0000, 0x201A, 0x0000, 0x201E, 0x2026, 0x2020, 0x2021,
0x0000, 0x2030, 0x0160, 0x2039, 0x015A, 0x0164, 0x017D, 0x0179,
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
0x0000, 0x2122, 0x0161, 0x203A, 0x015B, 0x0165, 0x017E, 0x017A,
0x00A0, 0x02C7, 0x02D8, 0x0141, 0x00A4, 0x0104, 0x00A6, 0x00A7,
0x00A8, 0x00A9, 0x015E, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x017B,
0x00B0, 0x00B1, 0x02DB, 0x0142, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
0x00B8, 0x0105, 0x015F, 0x00BB, 0x013D, 0x02DD, 0x013E, 0x017C,
0x0154, 0x00C1, 0x00C2, 0x0102, 0x00C4, 0x0139, 0x0106, 0x00C7,
0x010C, 0x00C9, 0x0118, 0x00CB, 0x011A, 0x00CD, 0x00CE, 0x010E,
0x0110, 0x0143, 0x0147, 0x00D3, 0x00D4, 0x0150, 0x00D6, 0x00D7,
0x0158, 0x016E, 0x00DA, 0x0170, 0x00DC, 0x00DD, 0x0162, 0x00DF,
0x0155, 0x00E1, 0x00E2, 0x0103, 0x00E4, 0x013A, 0x0107, 0x00E7,
0x010D, 0x00E9, 0x0119, 0x00EB, 0x011B, 0x00ED, 0x00EE, 0x010F,
0x0111, 0x0144, 0x0148, 0x00F3, 0x00F4, 0x0151, 0x00F6, 0x00F7,
0x0159, 0x016F, 0x00FA, 0x0171, 0x00FC, 0x00FD, 0x0163, 0x02D9
};
static const char32_t cp1251[] = {
0x0402, 0x0403, 0x201A, 0x0453, 0x201E, 0x2026, 0x2020, 0x2021,
0x20AC, 0x2030, 0x0409, 0x2039, 0x040A, 0x040C, 0x040B, 0x040F,
0x0452, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
0x0000, 0x2122, 0x0459, 0x203A, 0x045A, 0x045C, 0x045B, 0x045F,
0x00A0, 0x040E, 0x045E, 0x0408, 0x00A4, 0x0490, 0x00A6, 0x00A7,
0x0401, 0x00A9, 0x0404, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x0407,
0x00B0, 0x00B1, 0x0406, 0x0456, 0x0491, 0x00B5, 0x00B6, 0x00B7,
0x0451, 0x2116, 0x0454, 0x00BB, 0x0458, 0x0405, 0x0455, 0x0457,
0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417,
0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F,
0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427,
0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F,
0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437,
0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F,
0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447,
0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F
};
static const char32_t cp1252[] = {
0x20AC, 0x0000, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0000, 0x017D, 0x0000,
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x0000, 0x017E, 0x0178,
0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF,
0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7,
0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF
};
static const char32_t cp1253[] = {
0x20AC, 0x0000, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
0x0000, 0x2030, 0x0000, 0x2039, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
0x0000, 0x2122, 0x0000, 0x203A, 0x0000, 0x0000, 0x0000, 0x0000,
0x00A0, 0x0385, 0x0386, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
0x00A8, 0x00A9, 0x0000, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x2015,
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x0384, 0x00B5, 0x00B6, 0x00B7,
0x0388, 0x0389, 0x038A, 0x00BB, 0x038C, 0x00BD, 0x038E, 0x038F,
0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397,
0x0398, 0x0399, 0x039A, 0x039B, 0x039C, 0x039D, 0x039E, 0x039F,
0x03A0, 0x03A1, 0x0000, 0x03A3, 0x03A4, 0x03A5, 0x03A6, 0x03A7,
0x03A8, 0x03A9, 0x03AA, 0x03AB, 0x03AC, 0x03AD, 0x03AE, 0x03AF,
0x03B0, 0x03B1, 0x03B2, 0x03B3, 0x03B4, 0x03B5, 0x03B6, 0x03B7,
0x03B8, 0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF,
0x03C0, 0x03C1, 0x03C2, 0x03C3, 0x03C4, 0x03C5, 0x03C6, 0x03C7,
0x03C8, 0x03C9, 0x03CA, 0x03CB, 0x03CC, 0x03CD, 0x03CE, 0x0000
};
static const char32_t cp1254[] = {
0x20AC, 0x0000, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0000, 0x0000, 0x0000,
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x0000, 0x0000, 0x0178,
0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
0x011E, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x0130, 0x015E, 0x00DF,
0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
0x011F, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7,
0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x0131, 0x015F, 0x00FF
};
static const char32_t cp1255[] = {
0x20AC, 0x0000, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
0x02C6, 0x2030, 0x0000, 0x2039, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
0x02DC, 0x2122, 0x0000, 0x203A, 0x0000, 0x0000, 0x0000, 0x0000,
0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x20AA, 0x00A5, 0x00A6, 0x00A7,
0x00A8, 0x00A9, 0x00D7, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
0x00B8, 0x00B9, 0x00F7, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
0x05B0, 0x05B1, 0x05B2, 0x05B3, 0x05B4, 0x05B5, 0x05B6, 0x05B7,
0x05B8, 0x05B9, 0x0000, 0x05BB, 0x05BC, 0x05BD, 0x05BE, 0x05BF,
0x05C0, 0x05C1, 0x05C2, 0x05C3, 0x05F0, 0x05F1, 0x05F2, 0x05F3,
0x05F4, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x05D0, 0x05D1, 0x05D2, 0x05D3, 0x05D4, 0x05D5, 0x05D6, 0x05D7,
0x05D8, 0x05D9, 0x05DA, 0x05DB, 0x05DC, 0x05DD, 0x05DE, 0x05DF,
0x05E0, 0x05E1, 0x05E2, 0x05E3, 0x05E4, 0x05E5, 0x05E6, 0x05E7,
0x05E8, 0x05E9, 0x05EA, 0x0000, 0x0000, 0x200E, 0x200F, 0x0000
};
static const char32_t cp1256[] = {
0x20AC, 0x067E, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
0x02C6, 0x2030, 0x0679, 0x2039, 0x0152, 0x0686, 0x0698, 0x0688,
0x06AF, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
0x06A9, 0x2122, 0x0691, 0x203A, 0x0153, 0x200C, 0x200D, 0x06BA,
0x00A0, 0x060C, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
0x00A8, 0x00A9, 0x06BE, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
0x00B8, 0x00B9, 0x061B, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x061F,
0x06C1, 0x0621, 0x0622, 0x0623, 0x0624, 0x0625, 0x0626, 0x0627,
0x0628, 0x0629, 0x062A, 0x062B, 0x062C, 0x062D, 0x062E, 0x062F,
0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x0636, 0x00D7,
0x0637, 0x0638, 0x0639, 0x063A, 0x0640, 0x0641, 0x0642, 0x0643,
0x00E0, 0x0644, 0x00E2, 0x0645, 0x0646, 0x0647, 0x0648, 0x00E7,
0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x0649, 0x064A, 0x00EE, 0x00EF,
0x064B, 0x064C, 0x064D, 0x064E, 0x00F4, 0x064F, 0x0650, 0x00F7,
0x0651, 0x00F9, 0x0652, 0x00FB, 0x00FC, 0x200E, 0x200F, 0x06D2,
};
static const char32_t cp1257[] = {
0x20AC, 0x0000, 0x201A, 0x0000, 0x201E, 0x2026, 0x2020, 0x2021,
0x0000, 0x2030, 0x0000, 0x2039, 0x0000, 0x00A8, 0x02C7, 0x00B8,
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
0x0000, 0x2122, 0x0000, 0x203A, 0x0000, 0x00AF, 0x02DB, 0x0000,
0x00A0, 0x0000, 0x00A2, 0x00A3, 0x00A4, 0x0000, 0x00A6, 0x00A7,
0x00D8, 0x00A9, 0x0156, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00C6,
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
0x00F8, 0x00B9, 0x0157, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00E6,
0x0104, 0x012E, 0x0100, 0x0106, 0x00C4, 0x00C5, 0x0118, 0x0112,
0x010C, 0x00C9, 0x0179, 0x0116, 0x0122, 0x0136, 0x012A, 0x013B,
0x0160, 0x0143, 0x0145, 0x00D3, 0x014C, 0x00D5, 0x00D6, 0x00D7,
0x0172, 0x0141, 0x015A, 0x016A, 0x00DC, 0x017B, 0x017D, 0x00DF,
0x0105, 0x012F, 0x0101, 0x0107, 0x00E4, 0x00E5, 0x0119, 0x0113,
0x010D, 0x00E9, 0x017A, 0x0117, 0x0123, 0x0137, 0x012B, 0x013C,
0x0161, 0x0144, 0x0146, 0x00F3, 0x014D, 0x00F5, 0x00F6, 0x00F7,
0x0173, 0x0142, 0x015B, 0x016B, 0x00FC, 0x017C, 0x017E, 0x02D9,
};
TextCodec::TextCodec() : _table(cp1252)
{
}
TextCodec::TextCodec(int codepage)
{
switch (codepage) {
case 65001:
_table = 0;
break;
case 1250:
_table = cp1250;
break;
case 1251:
_table = cp1251;
break;
case 1253:
_table = cp1253;
break;
case 1254:
_table = cp1254;
break;
case 1255:
_table = cp1255;
break;
case 1256:
_table = cp1256;
break;
case 1257:
_table = cp1257;
break;
default:
_table = cp1252;
}
}
QString TextCodec::toString(const QByteArray &ba) const
{
if (_table)
return from8bCp(ba);
else
return QString::fromUtf8(ba);
}
QString TextCodec::from8bCp(const QByteArray &ba) const
{
QVector<char32_t> ucs4(ba.size());
for (int i = 0; i < ba.size(); i++) {
quint8 c = (quint8)ba.at(i);
if (c < 0x80)
ucs4[i] = (char32_t)c;
else
ucs4[i] = _table[c - 0x80];
}
return QString::fromUcs4(ucs4.constData(), ucs4.size());
}

20
src/common/textcodec.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef TEXTCODEC_H
#define TEXTCODEC_H
#include <QString>
class TextCodec
{
public:
TextCodec();
TextCodec(int codepage);
QString toString(const QByteArray &ba) const;
private:
QString from8bCp(const QByteArray &ba) const;
const char32_t *_table;
};
#endif // TEXTCODEC_H

View File

@ -2,7 +2,6 @@
#include <QFile> #include <QFile>
#include <QFileInfo> #include <QFileInfo>
#include <QLineF> #include <QLineF>
#include "common/config.h"
#include "gpxparser.h" #include "gpxparser.h"
#include "tcxparser.h" #include "tcxparser.h"
#include "csvparser.h" #include "csvparser.h"
@ -13,9 +12,7 @@
#include "oziparsers.h" #include "oziparsers.h"
#include "locparser.h" #include "locparser.h"
#include "slfparser.h" #include "slfparser.h"
#ifdef ENABLE_GEOJSON
#include "geojsonparser.h" #include "geojsonparser.h"
#endif // ENABLE_GEOJSON
#include "exifparser.h" #include "exifparser.h"
#include "cupparser.h" #include "cupparser.h"
#include "gpiparser.h" #include "gpiparser.h"
@ -36,9 +33,7 @@ static WPTParser wpt;
static RTEParser rte; static RTEParser rte;
static LOCParser loc; static LOCParser loc;
static SLFParser slf; static SLFParser slf;
#ifdef ENABLE_GEOJSON
static GeoJSONParser geojson; static GeoJSONParser geojson;
#endif // ENABLE_GEOJSON
static EXIFParser exif; static EXIFParser exif;
static CUPParser cup; static CUPParser cup;
static GPIParser gpi; static GPIParser gpi;
@ -60,10 +55,8 @@ static QMap<QString, Parser*> parsers()
map.insert("rte", &rte); map.insert("rte", &rte);
map.insert("loc", &loc); map.insert("loc", &loc);
map.insert("slf", &slf); map.insert("slf", &slf);
#ifdef ENABLE_GEOJSON
map.insert("json", &geojson); map.insert("json", &geojson);
map.insert("geojson", &geojson); map.insert("geojson", &geojson);
#endif // ENABLE_GEOJSON
map.insert("jpeg", &exif); map.insert("jpeg", &exif);
map.insert("jpg", &exif); map.insert("jpg", &exif);
map.insert("cup", &cup); map.insert("cup", &cup);
@ -137,9 +130,7 @@ QString Data::formats()
+ qApp->translate("Data", "CSV files") + " (*.csv);;" + qApp->translate("Data", "CSV files") + " (*.csv);;"
+ qApp->translate("Data", "CUP files") + " (*.cup);;" + qApp->translate("Data", "CUP files") + " (*.cup);;"
+ qApp->translate("Data", "FIT files") + " (*.fit);;" + qApp->translate("Data", "FIT files") + " (*.fit);;"
#ifdef ENABLE_GEOJSON
+ qApp->translate("Data", "GeoJSON files") + " (*.geojson *.json);;" + qApp->translate("Data", "GeoJSON files") + " (*.geojson *.json);;"
#endif // ENABLE_GEOJSON
+ qApp->translate("Data", "GPI files") + " (*.gpi);;" + qApp->translate("Data", "GPI files") + " (*.gpi);;"
+ qApp->translate("Data", "GPX files") + " (*.gpx);;" + qApp->translate("Data", "GPX files") + " (*.gpx);;"
+ qApp->translate("Data", "IGC files") + " (*.igc);;" + qApp->translate("Data", "IGC files") + " (*.igc);;"

View File

@ -1,9 +1,5 @@
#include <QtEndian> #include <QtEndian>
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#include <QtCore/qmath.h>
#else // QT5
#include <QtMath> #include <QtMath>
#endif // QT5
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
#include "common/coordinates.h" #include "common/coordinates.h"

View File

@ -1,5 +1,4 @@
#include <QtEndian> #include <QtEndian>
#include "common/staticassert.h"
#include "fitparser.h" #include "fitparser.h"
@ -174,7 +173,7 @@ bool FITParser::parseDefinitionMessage(CTX &ctx, quint8 header)
// definition records // definition records
def->fields = new Field[def->numFields]; def->fields = new Field[def->numFields];
for (i = 0; i < def->numFields; i++) { for (i = 0; i < def->numFields; i++) {
STATIC_ASSERT(sizeof(def->fields[i]) == 3); static_assert(sizeof(def->fields[i]) == 3, "Invalid Field alignment");
if (!readData(ctx.file, (char*)&(def->fields[i]), if (!readData(ctx.file, (char*)&(def->fields[i]),
sizeof(def->fields[i]))) sizeof(def->fields[i])))
return false; return false;
@ -188,7 +187,7 @@ bool FITParser::parseDefinitionMessage(CTX &ctx, quint8 header)
def->devFields = new Field[def->numDevFields]; def->devFields = new Field[def->numDevFields];
for (i = 0; i < def->numDevFields; i++) { for (i = 0; i < def->numDevFields; i++) {
STATIC_ASSERT(sizeof(def->devFields[i]) == 3); static_assert(sizeof(def->fields[i]) == 3, "Invalid Field alignment");
if (!readData(ctx.file, (char*)&(def->devFields[i]), if (!readData(ctx.file, (char*)&(def->devFields[i]),
sizeof(def->devFields[i]))) sizeof(def->devFields[i])))
return false; return false;
@ -326,8 +325,8 @@ bool FITParser::parseData(CTX &ctx, const MessageDefinition *def)
} else if (def->globalId == COURSE_POINT) { } else if (def->globalId == COURSE_POINT) {
switch (field->id) { switch (field->id) {
case 1: case 1:
waypoint.setTimestamp(QDateTime::fromTime_t(val.toUInt() waypoint.setTimestamp(QDateTime::fromSecsSinceEpoch(val.toUInt()
+ 631065600)); + 631065600, Qt::UTC));
break; break;
case 2: case 2:
waypoint.rcoordinates().setLat( waypoint.rcoordinates().setLat(
@ -362,8 +361,8 @@ bool FITParser::parseData(CTX &ctx, const MessageDefinition *def)
} }
} else if (def->globalId == RECORD_MESSAGE) { } else if (def->globalId == RECORD_MESSAGE) {
if (ctx.trackpoint.coordinates().isValid()) { if (ctx.trackpoint.coordinates().isValid()) {
ctx.trackpoint.setTimestamp(QDateTime::fromTime_t(ctx.timestamp ctx.trackpoint.setTimestamp(QDateTime::fromSecsSinceEpoch(ctx.timestamp
+ 631065600)); + 631065600, Qt::UTC));
ctx.trackpoint.setRatio(ctx.ratio); ctx.trackpoint.setRatio(ctx.ratio);
ctx.segment.append(ctx.trackpoint); ctx.segment.append(ctx.trackpoint);
ctx.trackpoint = Trackpoint(); ctx.trackpoint = Trackpoint();
@ -411,7 +410,7 @@ bool FITParser::parseHeader(CTX &ctx)
quint16 crc; quint16 crc;
qint64 len; qint64 len;
STATIC_ASSERT(sizeof(hdr) == 12); static_assert(sizeof(hdr) == 12, "Invalid FileHeader alignment");
len = ctx.file->read((char*)&hdr, sizeof(hdr)); len = ctx.file->read((char*)&hdr, sizeof(hdr));
if (len < 0) { if (len < 0) {
_errorString = "I/O error"; _errorString = "I/O error";

View File

@ -1,6 +1,5 @@
#include <cstring> #include <cstring>
#include <QDataStream> #include <QDataStream>
#include <QTextCodec>
#include <QtEndian> #include <QtEndian>
#include <QUrl> #include <QUrl>
#include <QIODevice> #include <QIODevice>
@ -8,10 +7,9 @@
#include <QBuffer> #include <QBuffer>
#include <QImageReader> #include <QImageReader>
#include <QCryptographicHash> #include <QCryptographicHash>
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include <QTemporaryDir> #include <QTemporaryDir>
#endif // QT_VERSION >= 5
#include "common/garmin.h" #include "common/garmin.h"
#include "common/textcodec.h"
#include "gpiparser.h" #include "gpiparser.h"
@ -115,59 +113,76 @@ qint64 CryptDevice::readData(char *data, qint64 maxSize)
} }
static qint32 readInt24(QDataStream &stream) class DataStream : public QDataStream
{
public:
DataStream(QIODevice *d) : QDataStream(d) {}
void setCodepage(quint16 codepage) {_codec = TextCodec(codepage);}
quint16 readString(QString &str);
qint32 readInt24();
quint8 readRecordHeader(RecordHeader &hdr);
quint32 readTranslatedObjects(QList<TranslatedString> &objects);
quint32 skipRecord();
quint16 nextHeaderType();
private:
TextCodec _codec;
};
quint16 DataStream::readString(QString &str)
{
quint16 len;
*this >> len;
QByteArray ba;
ba.resize(len);
readRawData(ba.data(), len);
str = _codec.toString(ba);
return len + 2;
}
qint32 DataStream::readInt24()
{ {
unsigned char data[3]; unsigned char data[3];
quint32 val; quint32 val;
stream.readRawData((char*)data, sizeof(data)); readRawData((char*)data, sizeof(data));
val = data[0] | ((quint32)data[1]) << 8 | ((quint32)data[2]) << 16; val = data[0] | ((quint32)data[1]) << 8 | ((quint32)data[2]) << 16;
return (val > 0x7FFFFF) ? (val & 0x7FFFFF) - 0x800000 : val; return (val > 0x7FFFFF) ? (val & 0x7FFFFF) - 0x800000 : val;
} }
static quint16 nextHeaderType(QDataStream &stream) quint16 DataStream::nextHeaderType()
{ {
quint16 type = 0; quint16 type = 0;
if (stream.device()->peek((char*)&type, sizeof(type)) if (device()->peek((char*)&type, sizeof(type)) < (qint64)sizeof(type)) {
< (qint64)sizeof(type)) { setStatus(QDataStream::ReadCorruptData);
stream.setStatus(QDataStream::ReadCorruptData);
return 0xFFFF; return 0xFFFF;
} else } else
return qFromLittleEndian(type); return qFromLittleEndian(type);
} }
static quint8 readRecordHeader(QDataStream &stream, RecordHeader &hdr) quint8 DataStream::readRecordHeader(RecordHeader &hdr)
{ {
stream >> hdr.type >> hdr.flags >> hdr.size; *this >> hdr.type >> hdr.flags >> hdr.size;
if (hdr.flags & 0xA) if (hdr.flags & 0xA)
stream >> hdr.extra; *this >> hdr.extra;
return (hdr.flags & 0xA) ? 12 : 8; return (hdr.flags & 0xA) ? 12 : 8;
} }
static quint32 skipRecord(QDataStream &stream) quint32 DataStream::skipRecord()
{ {
RecordHeader rh; RecordHeader rh;
quint8 rs = readRecordHeader(stream, rh); quint8 rs = readRecordHeader(rh);
stream.skipRawData(rh.size); skipRawData(rh.size);
return rs + rh.size; return rs + rh.size;
} }
static quint16 readString(QDataStream &stream, QTextCodec *codec, QString &str) quint32 DataStream::readTranslatedObjects(QList<TranslatedString> &objects)
{
quint16 len;
stream >> len;
QByteArray ba;
ba.resize(len);
stream.readRawData(ba.data(), len);
str = codec ? codec->toUnicode(ba) : QString::fromLatin1(ba);
return len + 2;
}
static quint32 readTranslatedObjects(QDataStream &stream, QTextCodec *codec,
QList<TranslatedString> &objects)
{ {
qint32 size = 0, ret; qint32 size = 0, ret;
char lang[3]; char lang[3];
@ -175,34 +190,35 @@ static quint32 readTranslatedObjects(QDataStream &stream, QTextCodec *codec,
memset(lang, 0, sizeof(lang)); memset(lang, 0, sizeof(lang));
objects.clear(); objects.clear();
stream >> size; *this >> size;
ret = size + 4; ret = size + 4;
while (stream.status() == QDataStream::Ok && size > 0) { while (status() == QDataStream::Ok && size > 0) {
QString str; QString str;
stream.readRawData(lang, sizeof(lang) - 1); readRawData(lang, sizeof(lang) - 1);
size -= readString(stream, codec, str) + 2; size -= readString(str) + 2;
objects.append(TranslatedString(lang, str)); objects.append(TranslatedString(lang, str));
} }
if (size < 0) if (size < 0)
stream.setStatus(QDataStream::ReadCorruptData); setStatus(QDataStream::ReadCorruptData);
return ret; return ret;
} }
static quint32 readFprsRecord(QDataStream &stream)
static quint32 readFprsRecord(DataStream &stream)
{ {
RecordHeader rh; RecordHeader rh;
quint16 s1; quint16 s1;
quint8 rs, s2, s3, s4; quint8 rs, s2, s3, s4;
rs = readRecordHeader(stream, rh); rs = stream.readRecordHeader(rh);
stream >> s1 >> s2 >> s3 >> s4; stream >> s1 >> s2 >> s3 >> s4;
return rs + 5; return rs + 5;
} }
static quint32 readFileDataRecord(QDataStream &stream, QTextCodec *codec) static quint32 readFileDataRecord(DataStream &stream)
{ {
RecordHeader rh; RecordHeader rh;
quint32 ds, s1; quint32 ds, s1;
@ -210,11 +226,11 @@ static quint32 readFileDataRecord(QDataStream &stream, QTextCodec *codec)
quint8 rs; quint8 rs;
QList<TranslatedString> obj; QList<TranslatedString> obj;
rs = readRecordHeader(stream, rh); rs = stream.readRecordHeader(rh);
stream >> s1 >> s2 >> s3; stream >> s1 >> s2 >> s3;
ds = 8; ds = 8;
ds += readTranslatedObjects(stream, codec, obj); ds += stream.readTranslatedObjects(obj);
ds += readTranslatedObjects(stream, codec, obj); ds += stream.readTranslatedObjects(obj);
if (s1 & 0x10) { if (s1 & 0x10) {
quint8 ss1, ss2; quint8 ss1, ss2;
@ -231,7 +247,7 @@ static quint32 readFileDataRecord(QDataStream &stream, QTextCodec *codec)
} }
if (s1 & 0x400) { if (s1 & 0x400) {
QString str; QString str;
ds += readString(stream, codec, str); ds += stream.readString(str);
} }
if (s1 & 0x400000) { if (s1 & 0x400000) {
quint16 ss1; quint16 ss1;
@ -251,16 +267,15 @@ static quint32 readFileDataRecord(QDataStream &stream, QTextCodec *codec)
return rs + rh.size; return rs + rh.size;
} }
static quint32 readDescription(QDataStream &stream, QTextCodec *codec, static quint32 readDescription(DataStream &stream, Waypoint &waypoint)
Waypoint &waypoint)
{ {
RecordHeader rh; RecordHeader rh;
quint8 rs; quint8 rs;
quint32 ds; quint32 ds;
QList<TranslatedString> obj; QList<TranslatedString> obj;
rs = readRecordHeader(stream, rh); rs = stream.readRecordHeader(rh);
ds = readTranslatedObjects(stream, codec, obj); ds = stream.readTranslatedObjects(obj);
if (!obj.isEmpty()) if (!obj.isEmpty())
waypoint.setDescription(obj.first().str()); waypoint.setDescription(obj.first().str());
@ -270,24 +285,23 @@ static quint32 readDescription(QDataStream &stream, QTextCodec *codec,
return rs + rh.size; return rs + rh.size;
} }
static quint32 readNotes(QDataStream &stream, QTextCodec *codec, static quint32 readNotes(DataStream &stream, Waypoint &waypoint)
Waypoint &waypoint)
{ {
RecordHeader rh; RecordHeader rh;
quint8 rs, s1; quint8 rs, s1;
quint32 ds = 1; quint32 ds = 1;
rs = readRecordHeader(stream, rh); rs = stream.readRecordHeader(rh);
stream >> s1; stream >> s1;
if (s1 & 0x1) { if (s1 & 0x1) {
QList<TranslatedString> obj; QList<TranslatedString> obj;
ds += readTranslatedObjects(stream, codec, obj); ds += stream.readTranslatedObjects(obj);
if (!obj.isEmpty()) if (!obj.isEmpty())
waypoint.setComment(obj.first().str()); waypoint.setComment(obj.first().str());
} }
if (s1 & 0x2) { if (s1 & 0x2) {
QString str; QString str;
ds += readString(stream, codec, str); ds += stream.readString(str);
if (!str.isEmpty()) if (!str.isEmpty())
waypoint.setComment(str); waypoint.setComment(str);
} }
@ -298,8 +312,7 @@ static quint32 readNotes(QDataStream &stream, QTextCodec *codec,
return rs + rh.size; return rs + rh.size;
} }
static quint32 readContact(QDataStream &stream, QTextCodec *codec, static quint32 readContact(DataStream &stream, Waypoint &waypoint)
Waypoint &waypoint)
{ {
RecordHeader rh; RecordHeader rh;
quint8 rs; quint8 rs;
@ -308,25 +321,25 @@ static quint32 readContact(QDataStream &stream, QTextCodec *codec,
QString str; QString str;
QList<TranslatedString> obj; QList<TranslatedString> obj;
rs = readRecordHeader(stream, rh); rs = stream.readRecordHeader(rh);
stream >> flags; stream >> flags;
if (flags & 0x1) // phone if (flags & 0x1) // phone
ds += readString(stream, codec, str); ds += stream.readString(str);
if (flags & 0x2) // phone2 if (flags & 0x2) // phone2
ds += readString(stream, codec, str); ds += stream.readString(str);
if (flags & 0x4) // fax if (flags & 0x4) // fax
ds += readString(stream, codec, str); ds += stream.readString(str);
if (flags & 0x8) // mail if (flags & 0x8) // mail
ds += readString(stream, codec, str); ds += stream.readString(str);
if (flags & 0x10) { // web if (flags & 0x10) { // web
ds += readString(stream, codec, str); ds += stream.readString(str);
QUrl url(str); QUrl url(str);
waypoint.addLink(Link(url.scheme().isEmpty() waypoint.addLink(Link(url.scheme().isEmpty()
? "http://" + str : str, str)); ? "http://" + str : str, str));
} }
if (flags & 0x20) // unknown if (flags & 0x20) // unknown
ds += readTranslatedObjects(stream, codec, obj); ds += stream.readTranslatedObjects(obj);
if (ds != rh.size) if (ds != rh.size)
stream.setStatus(QDataStream::ReadCorruptData); stream.setStatus(QDataStream::ReadCorruptData);
@ -334,8 +347,7 @@ static quint32 readContact(QDataStream &stream, QTextCodec *codec,
return rs + rh.size; return rs + rh.size;
} }
static quint32 readAddress(QDataStream &stream, QTextCodec *codec, static quint32 readAddress(DataStream &stream, Waypoint &waypoint)
Waypoint &waypoint)
{ {
RecordHeader rh; RecordHeader rh;
quint8 rs; quint8 rs;
@ -345,35 +357,35 @@ static quint32 readAddress(QDataStream &stream, QTextCodec *codec,
QString str; QString str;
Address addr; Address addr;
rs = readRecordHeader(stream, rh); rs = stream.readRecordHeader(rh);
stream >> flags; stream >> flags;
if (flags & 0x1) { if (flags & 0x1) {
ds += readTranslatedObjects(stream, codec, obj); ds += stream.readTranslatedObjects(obj);
if (!obj.isEmpty()) if (!obj.isEmpty())
addr.setCity(obj.first().str()); addr.setCity(obj.first().str());
} }
if (flags & 0x2) { if (flags & 0x2) {
ds += readTranslatedObjects(stream, codec, obj); ds += stream.readTranslatedObjects(obj);
if (!obj.isEmpty()) if (!obj.isEmpty())
addr.setCountry(obj.first().str()); addr.setCountry(obj.first().str());
} }
if (flags & 0x4) { if (flags & 0x4) {
ds += readTranslatedObjects(stream, codec, obj); ds += stream.readTranslatedObjects(obj);
if (!obj.isEmpty()) if (!obj.isEmpty())
addr.setState(obj.first().str()); addr.setState(obj.first().str());
} }
if (flags & 0x8) { if (flags & 0x8) {
ds += readString(stream, codec, str); ds += stream.readString(str);
addr.setPostalCode(str); addr.setPostalCode(str);
} }
if (flags & 0x10) { if (flags & 0x10) {
ds += readTranslatedObjects(stream, codec, obj); ds += stream.readTranslatedObjects(obj);
if (!obj.isEmpty()) if (!obj.isEmpty())
addr.setStreet(obj.first().str()); addr.setStreet(obj.first().str());
} }
if (flags & 0x20) // unknown if (flags & 0x20) // unknown
ds += readString(stream, codec, str); ds += stream.readString(str);
waypoint.setAddress(addr); waypoint.setAddress(addr);
@ -383,21 +395,20 @@ static quint32 readAddress(QDataStream &stream, QTextCodec *codec,
return rs + rh.size; return rs + rh.size;
} }
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
static const QTemporaryDir &tempDir() static const QTemporaryDir &tempDir()
{ {
static QTemporaryDir dir; static QTemporaryDir dir;
return dir; return dir;
} }
static quint32 readImageInfo(QDataStream &stream, Waypoint &waypoint, static quint32 readImageInfo(DataStream &stream, Waypoint &waypoint,
const QString &fileName, int &imgId) const QString &fileName, int &imgId)
{ {
RecordHeader rh; RecordHeader rh;
quint8 rs, s1; quint8 rs, s1;
quint32 size; quint32 size;
rs = readRecordHeader(stream, rh); rs = stream.readRecordHeader(rh);
stream >> s1 >> size; stream >> s1 >> size;
QByteArray ba; QByteArray ba;
@ -424,7 +435,6 @@ static quint32 readImageInfo(QDataStream &stream, Waypoint &waypoint,
return rs + rh.size; return rs + rh.size;
} }
#endif // QT_VERSION >= 5
static int speed(quint8 flags) static int speed(quint8 flags)
{ {
@ -450,7 +460,7 @@ static int speed(quint8 flags)
} }
} }
static quint32 readCamera(QDataStream &stream, QVector<Waypoint> &waypoints, static quint32 readCamera(DataStream &stream, QVector<Waypoint> &waypoints,
QList<Area> &polygons) QList<Area> &polygons)
{ {
RecordHeader rh; RecordHeader rh;
@ -459,18 +469,18 @@ static quint32 readCamera(QDataStream &stream, QVector<Waypoint> &waypoints,
quint32 ds = 15; quint32 ds = 15;
rs = readRecordHeader(stream, rh); rs = stream.readRecordHeader(rh);
top = readInt24(stream); top = stream.readInt24();
right = readInt24(stream); right = stream.readInt24();
bottom = readInt24(stream); bottom = stream.readInt24();
left = readInt24(stream); left = stream.readInt24();
stream >> flags >> type >> s7; stream >> flags >> type >> s7;
if (s7) { if (s7) {
quint32 skip = s7 + 2 + s7/4; quint32 skip = s7 + 2 + s7/4;
stream.skipRawData(skip); stream.skipRawData(skip);
lat = readInt24(stream); lat = stream.readInt24();
lon = readInt24(stream); lon = stream.readInt24();
ds += skip + 6; ds += skip + 6;
} else { } else {
quint8 s8; quint8 s8;
@ -478,8 +488,8 @@ static quint32 readCamera(QDataStream &stream, QVector<Waypoint> &waypoints,
stream >> s8; stream >> s8;
quint32 skip = 3 + s8 + s8/4; quint32 skip = 3 + s8 + s8/4;
stream.skipRawData(skip); stream.skipRawData(skip);
lat = readInt24(stream); lat = stream.readInt24();
lon = readInt24(stream); lon = stream.readInt24();
ds += skip + 16; ds += skip + 16;
} }
@ -513,8 +523,8 @@ static quint32 readCamera(QDataStream &stream, QVector<Waypoint> &waypoints,
return rs + rh.size; return rs + rh.size;
} }
static quint32 readPOI(QDataStream &stream, QTextCodec *codec, static quint32 readPOI(DataStream &stream, QVector<Waypoint> &waypoints,
QVector<Waypoint> &waypoints, const QString &fileName, int &imgId) const QString &fileName, int &imgId)
{ {
RecordHeader rh; RecordHeader rh;
quint8 rs; quint8 rs;
@ -523,37 +533,35 @@ static quint32 readPOI(QDataStream &stream, QTextCodec *codec,
quint16 s3; quint16 s3;
QList<TranslatedString> obj; QList<TranslatedString> obj;
rs = readRecordHeader(stream, rh); rs = stream.readRecordHeader(rh);
stream >> lat >> lon >> s3; stream >> lat >> lon >> s3;
stream.skipRawData(s3); stream.skipRawData(s3);
ds = 10 + s3; ds = 10 + s3;
ds += readTranslatedObjects(stream, codec, obj); ds += stream.readTranslatedObjects(obj);
waypoints.append(Waypoint(Coordinates(toWGS32(lon), toWGS32(lat)))); waypoints.append(Waypoint(Coordinates(toWGS32(lon), toWGS32(lat))));
if (!obj.isEmpty()) if (!obj.isEmpty())
waypoints.last().setName(obj.first().str()); waypoints.last().setName(obj.first().str());
while (stream.status() == QDataStream::Ok && ds < rh.size) { while (stream.status() == QDataStream::Ok && ds < rh.size) {
switch(nextHeaderType(stream)) { switch(stream.nextHeaderType()) {
case 10: case 10:
ds += readDescription(stream, codec, waypoints.last()); ds += readDescription(stream, waypoints.last());
break; break;
case 11: case 11:
ds += readAddress(stream, codec, waypoints.last()); ds += readAddress(stream, waypoints.last());
break; break;
case 12: case 12:
ds += readContact(stream, codec, waypoints.last()); ds += readContact(stream, waypoints.last());
break; break;
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
case 13: case 13:
ds += readImageInfo(stream, waypoints.last(), fileName, imgId); ds += readImageInfo(stream, waypoints.last(), fileName, imgId);
break; break;
#endif // QT_VERSION >= 5
case 14: case 14:
ds += readNotes(stream, codec, waypoints.last()); ds += readNotes(stream, waypoints.last());
break; break;
default: default:
ds += skipRecord(stream); ds += stream.skipRecord();
} }
} }
@ -563,9 +571,8 @@ static quint32 readPOI(QDataStream &stream, QTextCodec *codec,
return rs + rh.size; return rs + rh.size;
} }
static quint32 readSpatialIndex(QDataStream &stream, QTextCodec *codec, static quint32 readSpatialIndex(DataStream &stream, QVector<Waypoint> &waypoints,
QVector<Waypoint> &waypoints, QList<Area> &polygons, const QString &fileName, QList<Area> &polygons, const QString &fileName, int &imgId)
int &imgId)
{ {
RecordHeader rh; RecordHeader rh;
quint32 ds, s5; quint32 ds, s5;
@ -573,25 +580,25 @@ static quint32 readSpatialIndex(QDataStream &stream, QTextCodec *codec,
quint16 s6; quint16 s6;
quint8 rs; quint8 rs;
rs = readRecordHeader(stream, rh); rs = stream.readRecordHeader(rh);
stream >> top >> right >> bottom >> left >> s5 >> s6; stream >> top >> right >> bottom >> left >> s5 >> s6;
stream.skipRawData(s6); stream.skipRawData(s6);
ds = 22 + s6; ds = 22 + s6;
if (rh.flags & 0x8) { if (rh.flags & 0x8) {
while (stream.status() == QDataStream::Ok && ds < rh.size) { while (stream.status() == QDataStream::Ok && ds < rh.size) {
switch(nextHeaderType(stream)) { switch(stream.nextHeaderType()) {
case 2: case 2:
ds += readPOI(stream, codec, waypoints, fileName, imgId); ds += readPOI(stream, waypoints, fileName, imgId);
break; break;
case 8: case 8:
ds += readSpatialIndex(stream, codec, waypoints, polygons, ds += readSpatialIndex(stream, waypoints, polygons,
fileName, imgId); fileName, imgId);
break; break;
case 19: case 19:
ds += readCamera(stream, waypoints, polygons); ds += readCamera(stream, waypoints, polygons);
break; break;
default: default:
ds += skipRecord(stream); ds += stream.skipRecord();
} }
} }
} }
@ -602,24 +609,23 @@ static quint32 readSpatialIndex(QDataStream &stream, QTextCodec *codec,
return rs + rh.size; return rs + rh.size;
} }
static void readPOIDatabase(QDataStream &stream, QTextCodec *codec, static void readPOIDatabase(DataStream &stream, QVector<Waypoint> &waypoints,
QVector<Waypoint> &waypoints, QList<Area> &polygons, const QString &fileName, QList<Area> &polygons, const QString &fileName, int &imgId)
int &imgId)
{ {
RecordHeader rh; RecordHeader rh;
QList<TranslatedString> obj; QList<TranslatedString> obj;
quint32 ds; quint32 ds;
readRecordHeader(stream, rh); stream.readRecordHeader(rh);
ds = readTranslatedObjects(stream, codec, obj); ds = stream.readTranslatedObjects(obj);
ds += readSpatialIndex(stream, codec, waypoints, polygons, fileName, imgId); ds += readSpatialIndex(stream, waypoints, polygons, fileName, imgId);
if (rh.flags & 0x8) { if (rh.flags & 0x8) {
while (stream.status() == QDataStream::Ok && ds < rh.size) { while (stream.status() == QDataStream::Ok && ds < rh.size) {
switch(nextHeaderType(stream)) { switch(stream.nextHeaderType()) {
case 5: // symbol case 5: // symbol
case 7: // category case 7: // category
default: default:
ds += skipRecord(stream); ds += stream.skipRecord();
} }
} }
} }
@ -628,26 +634,26 @@ static void readPOIDatabase(QDataStream &stream, QTextCodec *codec,
stream.setStatus(QDataStream::ReadCorruptData); stream.setStatus(QDataStream::ReadCorruptData);
} }
bool GPIParser::readData(QDataStream &stream, QTextCodec *codec, bool GPIParser::readData(DataStream &stream, QVector<Waypoint> &waypoints,
QVector<Waypoint> &waypoints, QList<Area> &polygons, const QString &fileName) QList<Area> &polygons, const QString &fileName)
{ {
int imgId = 0; int imgId = 0;
while (stream.status() == QDataStream::Ok) { while (stream.status() == QDataStream::Ok) {
switch (nextHeaderType(stream)) { switch (stream.nextHeaderType()) {
case 0x09: // POI database case 0x09: // POI database
readPOIDatabase(stream, codec, waypoints, polygons, fileName, readPOIDatabase(stream, waypoints, polygons, fileName,
imgId); imgId);
break; break;
case 0xffff: // EOF case 0xffff: // EOF
skipRecord(stream); stream.skipRecord();
if (stream.status() == QDataStream::Ok) if (stream.status() == QDataStream::Ok)
return true; return true;
break; break;
case 0x16: // route case 0x16: // route
case 0x15: // info header case 0x15: // info header
default: default:
skipRecord(stream); stream.skipRecord();
} }
} }
@ -656,7 +662,7 @@ bool GPIParser::readData(QDataStream &stream, QTextCodec *codec,
return false; return false;
} }
bool GPIParser::readGPIHeader(QDataStream &stream, QTextCodec **codec) bool GPIParser::readGPIHeader(DataStream &stream)
{ {
RecordHeader rh; RecordHeader rh;
char m1[6], m2[2]; char m1[6], m2[2];
@ -664,22 +670,16 @@ bool GPIParser::readGPIHeader(QDataStream &stream, QTextCodec **codec)
quint8 s2, s3; quint8 s2, s3;
quint32 ds; quint32 ds;
readRecordHeader(stream, rh); stream.readRecordHeader(rh);
stream.readRawData(m1, sizeof(m1)); stream.readRawData(m1, sizeof(m1));
stream.readRawData(m2, sizeof(m2)); stream.readRawData(m2, sizeof(m2));
stream >> codepage >> s2 >> s3; stream >> codepage >> s2 >> s3;
ds = sizeof(m1) + sizeof(m2) + 4; ds = sizeof(m1) + sizeof(m2) + 4;
if (codepage == 65001) stream.setCodepage(codepage);
*codec = QTextCodec::codecForName("UTF-8");
else if (codepage == 0)
*codec = 0;
else
*codec = QTextCodec::codecForName(QString("CP%1").arg(codepage)
.toLatin1());
if (s2 & 0x10) if (s2 & 0x10)
ds += readFileDataRecord(stream, *codec); ds += readFileDataRecord(stream);
if (stream.status() != QDataStream::Ok || ds != rh.size) { if (stream.status() != QDataStream::Ok || ds != rh.size) {
_errorString = "Invalid GPI header"; _errorString = "Invalid GPI header";
@ -688,7 +688,7 @@ bool GPIParser::readGPIHeader(QDataStream &stream, QTextCodec **codec)
return true; return true;
} }
bool GPIParser::readFileHeader(QDataStream &stream, quint32 &ebs) bool GPIParser::readFileHeader(DataStream &stream, quint32 &ebs)
{ {
RecordHeader rh; RecordHeader rh;
quint32 ds, s7; quint32 ds, s7;
@ -696,7 +696,7 @@ bool GPIParser::readFileHeader(QDataStream &stream, quint32 &ebs)
quint8 s5, s6, s8, s9; quint8 s5, s6, s8, s9;
char magic[6]; char magic[6];
readRecordHeader(stream, rh); stream.readRecordHeader(rh);
stream.readRawData(magic, sizeof(magic)); stream.readRawData(magic, sizeof(magic));
if (memcmp(magic, "GRMREC", sizeof(magic))) { if (memcmp(magic, "GRMREC", sizeof(magic))) {
_errorString = "Not a GPI file"; _errorString = "Not a GPI file";
@ -722,21 +722,19 @@ bool GPIParser::parse(QFile *file, QList<TrackData> &tracks,
{ {
Q_UNUSED(tracks); Q_UNUSED(tracks);
Q_UNUSED(routes); Q_UNUSED(routes);
QDataStream stream(file); DataStream stream(file);
QTextCodec *codec = 0;
quint32 ebs; quint32 ebs;
stream.setByteOrder(QDataStream::LittleEndian); stream.setByteOrder(QDataStream::LittleEndian);
if (!readFileHeader(stream, ebs) || !readGPIHeader(stream, &codec)) if (!readFileHeader(stream, ebs) || !readGPIHeader(stream))
return false; return false;
if (ebs) { if (ebs) {
CryptDevice dev(stream.device(), 0xf870b5, ebs); CryptDevice dev(stream.device(), 0xf870b5, ebs);
QDataStream cryptStream(&dev); DataStream cryptStream(&dev);
cryptStream.setByteOrder(QDataStream::LittleEndian); cryptStream.setByteOrder(QDataStream::LittleEndian);
return readData(cryptStream, codec, waypoints, polygons, return readData(cryptStream, waypoints, polygons, file->fileName());
file->fileName());
} else } else
return readData(stream, codec, waypoints, polygons, file->fileName()); return readData(stream, waypoints, polygons, file->fileName());
} }

View File

@ -3,8 +3,7 @@
#include "parser.h" #include "parser.h"
class QDataStream; class DataStream;
class QTextCodec;
class GPIParser : public Parser class GPIParser : public Parser
{ {
@ -15,11 +14,10 @@ public:
int errorLine() const {return 0;} int errorLine() const {return 0;}
private: private:
bool readFileHeader(QDataStream &stream, quint32 &ebs); bool readFileHeader(DataStream &stream, quint32 &ebs);
bool readGPIHeader(QDataStream &stream, QTextCodec **codec); bool readGPIHeader(DataStream &stream);
bool readData(QDataStream &stream, QTextCodec *codec, bool readData(DataStream &stream, QVector<Waypoint> &waypoints,
QVector<Waypoint> &waypoints, QList<Area> &polygons, QList<Area> &polygons, const QString &fileName);
const QString &fileName);
QString _errorString; QString _errorString;
}; };

View File

@ -41,23 +41,14 @@ Link GPXParser::link()
Coordinates GPXParser::coordinates() Coordinates GPXParser::coordinates()
{ {
bool res; bool res;
qreal lon, lat;
const QXmlStreamAttributes &attr = _reader.attributes(); const QXmlStreamAttributes &attr = _reader.attributes();
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) qreal lon = attr.value("lon").toDouble(&res);
lon = attr.value("lon").toString().toDouble(&res);
#else // QT_VERSION < 5
lon = attr.value("lon").toDouble(&res);
#endif // QT_VERSION < 5
if (!res || (lon < -180.0 || lon > 180.0)) { if (!res || (lon < -180.0 || lon > 180.0)) {
_reader.raiseError("Invalid longitude"); _reader.raiseError("Invalid longitude");
return Coordinates(); return Coordinates();
} }
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) qreal lat = attr.value("lat").toDouble(&res);
lat = attr.value("lat").toString().toDouble(&res);
#else // QT_VERSION < 5
lat = attr.value("lat").toDouble(&res);
#endif // QT_VERSION < 5
if (!res || (lat < -90.0 || lat > 90.0)) { if (!res || (lat < -90.0 || lat > 90.0)) {
_reader.raiseError("Invalid latitude"); _reader.raiseError("Invalid latitude");
return Coordinates(); return Coordinates();

View File

@ -44,11 +44,7 @@ bool KMLParser::coord(Trackpoint &trackpoint)
if (c > 2) if (c > 2)
return false; return false;
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
val[c] = QString(vp, cp - vp).toDouble(&res); val[c] = QString(vp, cp - vp).toDouble(&res);
#else // QT_VERSION < 5
val[c] = QStringRef(&data, vp - sp, cp - vp).toDouble(&res);
#endif // QT_VERSION < 5
if (!res) if (!res)
return false; return false;
@ -90,11 +86,7 @@ bool KMLParser::pointCoordinates(Waypoint &waypoint)
if (c > 1) if (c > 1)
return false; return false;
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
val[c] = QString(vp, cp - vp).toDouble(&res); val[c] = QString(vp, cp - vp).toDouble(&res);
#else // QT_VERSION < 5
val[c] = QStringRef(&data, vp - sp, cp - vp).toDouble(&res);
#endif // QT_VERSION < 5
if (!res) if (!res)
return false; return false;
@ -104,11 +96,7 @@ bool KMLParser::pointCoordinates(Waypoint &waypoint)
if (c < 1) if (c < 1)
return false; return false;
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
val[c] = QString(vp, cp - vp).toDouble(&res); val[c] = QString(vp, cp - vp).toDouble(&res);
#else // QT_VERSION < 5
val[c] = QStringRef(&data, vp - sp, cp - vp).toDouble(&res);
#endif // QT_VERSION < 5
if (!res) if (!res)
return false; return false;
@ -148,11 +136,7 @@ bool KMLParser::lineCoordinates(SegmentData &segment)
if (c > 1) if (c > 1)
return false; return false;
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
val[c] = QString(vp, cp - vp).toDouble(&res); val[c] = QString(vp, cp - vp).toDouble(&res);
#else // QT_VERSION < 5
val[c] = QStringRef(&data, vp - sp, cp - vp).toDouble(&res);
#endif // QT_VERSION < 5
if (!res) if (!res)
return false; return false;
@ -162,11 +146,7 @@ bool KMLParser::lineCoordinates(SegmentData &segment)
if (c < 1 || c > 2) if (c < 1 || c > 2)
return false; return false;
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
val[c] = QString(vp, cp - vp).toDouble(&res); val[c] = QString(vp, cp - vp).toDouble(&res);
#else // QT_VERSION < 5
val[c] = QStringRef(&data, vp - sp, cp - vp).toDouble(&res);
#endif // QT_VERSION < 5
if (!res) if (!res)
return false; return false;
@ -207,11 +187,7 @@ bool KMLParser::polygonCoordinates(QVector<Coordinates> &points)
if (c > 1) if (c > 1)
return false; return false;
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
val[c] = QString(vp, cp - vp).toDouble(&res); val[c] = QString(vp, cp - vp).toDouble(&res);
#else // QT_VERSION < 5
val[c] = QStringRef(&data, vp - sp, cp - vp).toDouble(&res);
#endif // QT_VERSION < 5
if (!res) if (!res)
return false; return false;
@ -221,11 +197,7 @@ bool KMLParser::polygonCoordinates(QVector<Coordinates> &points)
if (c < 1 || c > 2) if (c < 1 || c > 2)
return false; return false;
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
val[c] = QString(vp, cp - vp).toDouble(&res); val[c] = QString(vp, cp - vp).toDouble(&res);
#else // QT_VERSION < 5
val[c] = QStringRef(&data, vp - sp, cp - vp).toDouble(&res);
#endif // QT_VERSION < 5
if (!res) if (!res)
return false; return false;
@ -417,7 +389,7 @@ void KMLParser::schemaData(SegmentData &segment, int start)
while (_reader.readNextStartElement()) { while (_reader.readNextStartElement()) {
if (_reader.name() == QLatin1String("SimpleArrayData")) { if (_reader.name() == QLatin1String("SimpleArrayData")) {
QXmlStreamAttributes attr = _reader.attributes(); QXmlStreamAttributes attr = _reader.attributes();
QStringRef name = attr.value("name"); QString name(attr.value("name").toString());
if (name == QLatin1String("Heartrate")) if (name == QLatin1String("Heartrate"))
heartRate(segment, start); heartRate(segment, start);

View File

@ -3,23 +3,14 @@
Coordinates LOCParser::coordinates() Coordinates LOCParser::coordinates()
{ {
bool res; bool res;
qreal lon, lat;
const QXmlStreamAttributes &attr = _reader.attributes(); const QXmlStreamAttributes &attr = _reader.attributes();
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) qreal lon = attr.value("lon").toDouble(&res);
lon = attr.value("lon").toString().toDouble(&res);
#else // QT_VERSION < 5
lon = attr.value("lon").toDouble(&res);
#endif // QT_VERSION < 5
if (!res || (lon < -180.0 || lon > 180.0)) { if (!res || (lon < -180.0 || lon > 180.0)) {
_reader.raiseError("Invalid longitude"); _reader.raiseError("Invalid longitude");
return Coordinates(); return Coordinates();
} }
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) qreal lat = attr.value("lat").toDouble(&res);
lat = attr.value("lat").toString().toDouble(&res);
#else // QT_VERSION < 5
lat = attr.value("lat").toDouble(&res);
#endif // QT_VERSION < 5
if (!res || (lat < -90.0 || lat > 90.0)) { if (!res || (lat < -90.0 || lat > 90.0)) {
_reader.raiseError("Invalid latitude"); _reader.raiseError("Invalid latitude");
return Coordinates(); return Coordinates();

View File

@ -15,11 +15,7 @@ bool SLFParser::data(const QXmlStreamAttributes &attr, const char *name,
if (!attr.hasAttribute(name)) if (!attr.hasAttribute(name))
return false; return false;
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
val = attr.value(name).toString().toDouble(&res);
#else // QT_VERSION < 5
val = attr.value(name).toDouble(&res); val = attr.value(name).toDouble(&res);
#endif // QT_VERSION < 5
if (!res) if (!res)
_reader.raiseError("Invalid " + QString(name)); _reader.raiseError("Invalid " + QString(name));

View File

@ -31,7 +31,7 @@ static qreal avg(const QVector<qreal> &v)
static qreal median(QVector<qreal> &v) static qreal median(QVector<qreal> &v)
{ {
qSort(v.begin(), v.end()); std::sort(v.begin(), v.end());
return v.at(v.size() / 2); return v.at(v.size() / 2);
} }

View File

@ -1,18 +1,11 @@
#include "common/config.h"
#ifdef ENABLE_TIMEZONES
#include "GUI/timezoneinfo.h"
#endif // ENABLE_TIMEZONES
#include "GUI/app.h" #include "GUI/app.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
#ifdef ENABLE_HIDPI #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
#endif // ENABLE_HIDPI #endif // QT6
#ifdef ENABLE_TIMEZONES
qRegisterMetaTypeStreamOperators<TimeZoneInfo>("TimeZoneInfo");
#endif // ENABLE_TIMEZONES
App app(argc, argv); App app(argc, argv);
return app.run(); return app.run();

View File

@ -1,10 +1,6 @@
#include <QPainter> #include <QPainter>
#include <QImage> #include <QImage>
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#include <QtCore/qmath.h>
#else // QT5
#include <QtMath> #include <QtMath>
#endif // QT5
#include "bitmapline.h" #include "bitmapline.h"

View File

@ -26,9 +26,9 @@ void GMAP::subProduct(QXmlStreamReader &reader, QString &dataDir,
QString &baseMap) QString &baseMap)
{ {
while (reader.readNextStartElement()) { while (reader.readNextStartElement()) {
if (reader.name() == "Directory") if (reader.name() == QLatin1String("Directory"))
dataDir = reader.readElementText(); dataDir = reader.readElementText();
else if (reader.name() == "BaseMap") else if (reader.name() == QLatin1String("BaseMap"))
baseMap = reader.readElementText(); baseMap = reader.readElementText();
else else
reader.skipCurrentElement(); reader.skipCurrentElement();
@ -39,11 +39,11 @@ void GMAP::mapProduct(QXmlStreamReader &reader, QString &dataDir,
QString &typFile, QString &baseMap) QString &typFile, QString &baseMap)
{ {
while (reader.readNextStartElement()) { while (reader.readNextStartElement()) {
if (reader.name() == "Name") if (reader.name() == QLatin1String("Name"))
_name = reader.readElementText(); _name = reader.readElementText();
else if (reader.name() == "TYP") else if (reader.name() == QLatin1String("TYP"))
typFile = reader.readElementText(); typFile = reader.readElementText();
else if (reader.name() == "SubProduct") else if (reader.name() == QLatin1String("SubProduct"))
subProduct(reader, dataDir, baseMap); subProduct(reader, dataDir, baseMap);
else else
reader.skipCurrentElement(); reader.skipCurrentElement();
@ -60,7 +60,7 @@ bool GMAP::readXML(const QString &path, QString &dataDir, QString &typFile,
QXmlStreamReader reader(&file); QXmlStreamReader reader(&file);
if (reader.readNextStartElement()) { if (reader.readNextStartElement()) {
if (reader.name() == "MapProduct") if (reader.name() == QLatin1String("MapProduct"))
mapProduct(reader, dataDir, typFile, baseMap); mapProduct(reader, dataDir, typFile, baseMap);
else else
reader.raiseError("Not a GMAP XML file"); reader.raiseError("Not a GMAP XML file");
@ -159,7 +159,8 @@ bool GMAP::isGMAP(const QString &path)
return false; return false;
QXmlStreamReader reader(&file); QXmlStreamReader reader(&file);
if (reader.readNextStartElement() && reader.name() == "MapProduct") if (reader.readNextStartElement()
&& reader.name() == QLatin1String("MapProduct"))
return true; return true;
return false; return false;

View File

@ -1,4 +1,3 @@
#include <QTextCodec>
#include "huffmantext.h" #include "huffmantext.h"
#include "rgnfile.h" #include "rgnfile.h"
#include "lblfile.h" #include "lblfile.h"
@ -100,13 +99,7 @@ bool LBLFile::load(Handle &hdl, const RGNFile *rgn, Handle &rgnHdl)
return false; return false;
} }
if (codepage == 65001) _codec = TextCodec(codepage);
_codec = QTextCodec::codecForName("UTF-8");
else if (codepage == 0)
_codec = 0;
else
_codec = QTextCodec::codecForName(QString("CP%1").arg(codepage)
.toLatin1());
return true; return true;
} }
@ -200,12 +193,10 @@ Label LBLFile::str2label(const QVector<quint8> &str, bool capitalize) const
bap->append(c); bap->append(c);
} }
QString text(_codec ? _codec->toUnicode(label) : QString::fromLatin1(label)); QString text(_codec.toString(label));
QString shieldText(_codec ? _codec->toUnicode(shieldLabel)
: QString::fromLatin1(shieldLabel));
return Label(capitalize && isAllUpperCase(text) ? capitalized(text) : text, return Label(capitalize && isAllUpperCase(text) ? capitalized(text) : text,
Label::Shield(shieldType, shieldText)); Label::Shield(shieldType, _codec.toString(shieldLabel)));
} }
Label LBLFile::label8b(Handle &hdl, quint32 offset, bool capitalize) const Label LBLFile::label8b(Handle &hdl, quint32 offset, bool capitalize) const

View File

@ -1,10 +1,10 @@
#ifndef LBLFILE_H #ifndef LBLFILE_H
#define LBLFILE_H #define LBLFILE_H
#include "common/textcodec.h"
#include "subfile.h" #include "subfile.h"
#include "label.h" #include "label.h"
class QTextCodec;
class HuffmanText; class HuffmanText;
class RGNFile; class RGNFile;
@ -12,17 +12,16 @@ class LBLFile : public SubFile
{ {
public: public:
LBLFile(IMG *img) LBLFile(IMG *img)
: SubFile(img), _huffmanText(0), _table(0), _codec(0), _offset(0), : SubFile(img), _huffmanText(0), _table(0), _offset(0), _size(0),
_size(0), _poiOffset(0), _poiSize(0), _poiMultiplier(0), _multiplier(0),
_encoding(0) {}
LBLFile(const QString *path)
: SubFile(path), _huffmanText(0), _table(0), _codec(0), _offset(0),
_size(0), _poiOffset(0), _poiSize(0), _poiMultiplier(0), _multiplier(0),
_encoding(0) {}
LBLFile(SubFile *gmp, quint32 offset) : SubFile(gmp, offset),
_huffmanText(0), _table(0), _codec(0), _offset(0), _size(0),
_poiOffset(0), _poiSize(0), _poiMultiplier(0), _multiplier(0), _poiOffset(0), _poiSize(0), _poiMultiplier(0), _multiplier(0),
_encoding(0) {} _encoding(0) {}
LBLFile(const QString *path)
: SubFile(path), _huffmanText(0), _table(0), _offset(0), _size(0),
_poiOffset(0), _poiSize(0), _poiMultiplier(0), _multiplier(0),
_encoding(0) {}
LBLFile(SubFile *gmp, quint32 offset) : SubFile(gmp, offset),
_huffmanText(0), _table(0), _offset(0), _size(0), _poiOffset(0),
_poiSize(0), _poiMultiplier(0), _multiplier(0), _encoding(0) {}
~LBLFile(); ~LBLFile();
bool load(Handle &hdl, const RGNFile *rgn, Handle &rgnHdl); bool load(Handle &hdl, const RGNFile *rgn, Handle &rgnHdl);
@ -39,8 +38,7 @@ private:
HuffmanText *_huffmanText; HuffmanText *_huffmanText;
quint32 *_table; quint32 *_table;
TextCodec _codec;
QTextCodec *_codec;
quint32 _offset; quint32 _offset;
quint32 _size; quint32 _size;
quint32 _poiOffset; quint32 _poiOffset;

View File

@ -97,13 +97,13 @@ private:
#ifndef QT_NO_DEBUG #ifndef QT_NO_DEBUG
inline QDebug operator<<(QDebug dbg, const MapData::Point &point) inline QDebug operator<<(QDebug dbg, const MapData::Point &point)
{ {
dbg.nospace() << "Point(" << hex << point.type << ", " << point.label << ")"; dbg.nospace() << "Point(" << point.type << ", " << point.label << ")";
return dbg.space(); return dbg.space();
} }
inline QDebug operator<<(QDebug dbg, const MapData::Poly &poly) inline QDebug operator<<(QDebug dbg, const MapData::Poly &poly)
{ {
dbg.nospace() << "Poly(" << hex << poly.type << ", " << poly.label << ")"; dbg.nospace() << "Poly(" << poly.type << ", " << poly.label << ")";
return dbg.space(); return dbg.space();
} }
#endif // QT_NO_DEBUG #endif // QT_NO_DEBUG

View File

@ -315,7 +315,7 @@ void RasterTile::processLines(QList<TextItem*> &textItems)
{ {
QRect tileRect(_xy, _img.size()); QRect tileRect(_xy, _img.size());
qStableSort(_lines); std::stable_sort(_lines.begin(), _lines.end());
if (_zoom >= 22) if (_zoom >= 22)
processStreetNames(tileRect, textItems); processStreetNames(tileRect, textItems);
@ -417,7 +417,7 @@ void RasterTile::processShields(const QRect &tileRect,
void RasterTile::processPoints(QList<TextItem*> &textItems) void RasterTile::processPoints(QList<TextItem*> &textItems)
{ {
qSort(_points); std::sort(_points.begin(), _points.end());
for (int i = 0; i < _points.size(); i++) { for (int i = 0; i < _points.size(); i++) {
MapData::Point &point = _points[i]; MapData::Point &point = _points[i];

View File

@ -5,25 +5,62 @@
#define MAX_TEXT_ANGLE 30 #define MAX_TEXT_ANGLE 30
static bool intersection(const QLineF &line, const QRectF &rect, #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
QPointF *p) #define INTERSECTS intersect
#else // QT 5.15
#define INTERSECTS intersects
#endif // QT 5.15
static bool intersection(const QLineF &line, const QRectF &rect, QPointF *p)
{ {
if (line.intersect(QLineF(rect.topLeft(), rect.topRight()), p) if (line.INTERSECTS(QLineF(rect.topLeft(), rect.topRight()), p)
== QLineF::BoundedIntersection) == QLineF::BoundedIntersection)
return true; return true;
if (line.intersect(QLineF(rect.topLeft(), rect.bottomLeft()), p) if (line.INTERSECTS(QLineF(rect.topLeft(), rect.bottomLeft()), p)
== QLineF::BoundedIntersection) == QLineF::BoundedIntersection)
return true; return true;
if (line.intersect(QLineF(rect.bottomRight(), rect.bottomLeft()), p) if (line.INTERSECTS(QLineF(rect.bottomRight(), rect.bottomLeft()), p)
== QLineF::BoundedIntersection) == QLineF::BoundedIntersection)
return true; return true;
if (line.intersect(QLineF(rect.bottomRight(), rect.topRight()), p) if (line.INTERSECTS(QLineF(rect.bottomRight(), rect.topRight()), p)
== QLineF::BoundedIntersection) == QLineF::BoundedIntersection)
return true; return true;
return false; return false;
} }
static bool intersection(const QLineF &line, const QRectF &rect, QPointF *p1,
QPointF *p2)
{
QPointF *p = p1;
if (line.INTERSECTS(QLineF(rect.topLeft(), rect.topRight()), p)
== QLineF::BoundedIntersection)
p = p2;
if (line.INTERSECTS(QLineF(rect.topLeft(), rect.bottomLeft()), p)
== QLineF::BoundedIntersection) {
if (p == p2)
return true;
p = p2;
}
if (line.INTERSECTS(QLineF(rect.bottomRight(), rect.bottomLeft()), p)
== QLineF::BoundedIntersection) {
if (p == p2)
return true;
p = p2;
}
if (line.INTERSECTS(QLineF(rect.bottomRight(), rect.topRight()), p)
== QLineF::BoundedIntersection) {
if (p == p2)
return true;
}
Q_ASSERT(p != p2);
return false;
}
static QPainterPath subpath(const QList<QLineF> &lines, int start, int end, static QPainterPath subpath(const QList<QLineF> &lines, int start, int end,
qreal cut) qreal cut)
{ {
@ -64,8 +101,8 @@ static QList<QLineF> lineString(const QPolygonF &path,
const QRectF &boundingRect) const QRectF &boundingRect)
{ {
QList<QLineF> lines; QList<QLineF> lines;
int start = 0, end = path.count() - 1; int start = -1, end = -1;
QPointF p;
for (int i = 0; i < path.count(); i++) { for (int i = 0; i < path.count(); i++) {
if (boundingRect.contains(path.at(i))) { if (boundingRect.contains(path.at(i))) {
@ -80,6 +117,19 @@ static QList<QLineF> lineString(const QPolygonF &path,
} }
} }
if (start < 0) {
QPointF p1, p2;
for (int i = 1; i < path.count(); i++) {
QLineF l(path.at(i-1), path.at(i));
if (intersection(l, boundingRect, &p1, &p2)) {
lines.append(QLineF(p1, p2));
break;
}
}
} else {
QPointF p;
if (start > 0) { if (start > 0) {
QLineF l(path.at(start-1), path.at(start)); QLineF l(path.at(start-1), path.at(start));
if (intersection(l, boundingRect, &p)) if (intersection(l, boundingRect, &p))
@ -92,10 +142,12 @@ static QList<QLineF> lineString(const QPolygonF &path,
if (intersection(l, boundingRect, &p)) if (intersection(l, boundingRect, &p))
lines.append(QLineF(path.at(end), p)); lines.append(QLineF(path.at(end), p));
} }
}
return lines; return lines;
} }
static QPainterPath textPath(const QPolygonF &path, qreal textWidth, static QPainterPath textPath(const QPolygonF &path, qreal textWidth,
qreal charWidth, const QRectF &tileRect) qreal charWidth, const QRectF &tileRect)
{ {
@ -139,7 +191,7 @@ TextPathItem::TextPathItem(const QPolygonF &line, const QString *label,
const QRect &tileRect, const QFont *font, const QColor *color) const QRect &tileRect, const QFont *font, const QColor *color)
: TextItem(label), _font(font), _color(color) : TextItem(label), _font(font), _color(color)
{ {
qreal cw = font->pixelSize() * 0.7; qreal cw = font->pixelSize() * 0.6;
qreal textWidth = _text->size() * cw; qreal textWidth = _text->size() * cw;
qreal mw = font->pixelSize() / 2; qreal mw = font->pixelSize() / 2;
_path = textPath(line, textWidth, cw, tileRect.adjusted(mw, mw, -mw, -mw)); _path = textPath(line, textWidth, cw, tileRect.adjusted(mw, mw, -mw, -mw));
@ -159,7 +211,7 @@ TextPathItem::TextPathItem(const QPolygonF &line, const QString *label,
void TextPathItem::paint(QPainter *painter) const void TextPathItem::paint(QPainter *painter) const
{ {
QFontMetrics fm(*_font); QFontMetrics fm(*_font);
int textWidth = fm.width(*_text); int textWidth = fm.boundingRect(*_text).width();
qreal factor = (textWidth) / qMax(_path.length(), (qreal)textWidth); qreal factor = (textWidth) / qMax(_path.length(), (qreal)textWidth);
qreal percent = (1.0 - factor) / 2.0; qreal percent = (1.0 - factor) / 2.0;
@ -185,7 +237,7 @@ void TextPathItem::paint(QPainter *painter) const
painter->drawText(QPoint(1, fm.descent()), _text->at(i)); painter->drawText(QPoint(1, fm.descent()), _text->at(i));
painter->setTransform(t); painter->setTransform(t);
int width = fm.charWidth(*_text, i); int width = fm.horizontalAdvance(_text->at(i));
percent += ((qreal)width / (qreal)textWidth) * factor; percent += ((qreal)width / (qreal)textWidth) * factor;
} }
percent = (1.0 - factor) / 2.0; percent = (1.0 - factor) / 2.0;
@ -200,7 +252,7 @@ void TextPathItem::paint(QPainter *painter) const
painter->drawText(QPoint(0, fm.descent()), _text->at(i)); painter->drawText(QPoint(0, fm.descent()), _text->at(i));
painter->setTransform(t); painter->setTransform(t);
int width = fm.charWidth(*_text, i); int width = fm.horizontalAdvance(_text->at(i));
percent += ((qreal)width / (qreal)textWidth) * factor; percent += ((qreal)width / (qreal)textWidth) * factor;
} }

View File

@ -87,14 +87,8 @@ void TextPointItem::paint(QPainter *painter) const
painter->setPen(*_color); painter->setPen(*_color);
painter->drawText(_textRect, FLAGS, *_text); painter->drawText(_textRect, FLAGS, *_text);
} else { } else {
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
img.invertPixels(); img.invertPixels();
painter->drawImage(_textRect, img); painter->drawImage(_textRect, img);
#else // QT >= 5.4
QImage iimg(img.convertToFormat(QImage::Format_ARGB32));
iimg.invertPixels();
painter->drawImage(_textRect, iimg);
#endif // QT >= 5.4
} }
} }
} }

View File

@ -34,7 +34,7 @@ static bool yCmp(OziMap *m1, OziMap *m2)
void Atlas::computeZooms() void Atlas::computeZooms()
{ {
qSort(_maps.begin(), _maps.end(), resCmp); std::sort(_maps.begin(), _maps.end(), resCmp);
_zooms.append(Zoom(0, _maps.count() - 1)); _zooms.append(Zoom(0, _maps.count() - 1));
for (int i = 1; i < _maps.count(); i++) { for (int i = 1; i < _maps.count(); i++) {
@ -56,14 +56,14 @@ void Atlas::computeBounds()
for (int i = _zooms.at(z).first; i <= _zooms.at(z).last; i++) for (int i = _zooms.at(z).first; i <= _zooms.at(z).last; i++)
m.append(_maps.at(i)); m.append(_maps.at(i));
qSort(m.begin(), m.end(), xCmp); std::sort(m.begin(), m.end(), xCmp);
offsets[_maps.indexOf(m.first())].setX(0); offsets[_maps.indexOf(m.first())].setX(0);
for (int i = 1; i < m.size(); i++) { for (int i = 1; i < m.size(); i++) {
qreal w = m.first()->pp2xy(TL(m.at(i))).x(); qreal w = m.first()->pp2xy(TL(m.at(i))).x();
offsets[_maps.indexOf(m.at(i))].setX(w); offsets[_maps.indexOf(m.at(i))].setX(w);
} }
qSort(m.begin(), m.end(), yCmp); std::sort(m.begin(), m.end(), yCmp);
offsets[_maps.indexOf(m.first())].setY(0); offsets[_maps.indexOf(m.first())].setY(0);
for (int i = 1; i < m.size(); i++) { for (int i = 1; i < m.size(); i++) {
qreal h = m.first()->pp2xy(TL(m.at(i))).y(); qreal h = m.first()->pp2xy(TL(m.at(i))).y();

View File

@ -369,7 +369,7 @@ bool BSBMap::readRow(QFile &file, char bits, uchar *buf)
QImage BSBMap::readImage() QImage BSBMap::readImage()
{ {
QFile file(_fileName); QFile file(path());
char bits; char bits;
if (!file.open(QIODevice::ReadOnly)) if (!file.open(QIODevice::ReadOnly))
@ -391,8 +391,7 @@ QImage BSBMap::readImage()
} }
BSBMap::BSBMap(const QString &fileName, QObject *parent) BSBMap::BSBMap(const QString &fileName, QObject *parent)
: Map(fileName, parent), _fileName(fileName), _img(0), _ratio(1.0), : Map(fileName, parent), _img(0), _ratio(1.0), _dataOffset(-1), _valid(false)
_dataOffset(-1), _valid(false)
{ {
QFile file(fileName); QFile file(fileName);

View File

@ -47,7 +47,6 @@ private:
QImage readImage(); QImage readImage();
bool readRow(QFile &file, char bits, uchar *buf); bool readRow(QFile &file, char bits, uchar *buf);
QString _fileName;
QString _name; QString _name;
Projection _projection; Projection _projection;
Transform _transform; Transform _transform;

View File

@ -4,6 +4,7 @@
#include <QBasicTimer> #include <QBasicTimer>
#include <QDir> #include <QDir>
#include <QTimerEvent> #include <QTimerEvent>
#include "common/config.h"
#include "downloader.h" #include "downloader.h"
@ -83,9 +84,7 @@ private:
QNetworkAccessManager *Downloader::_manager = 0; QNetworkAccessManager *Downloader::_manager = 0;
int Downloader::_timeout = 30; int Downloader::_timeout = 30;
#ifdef ENABLE_HTTP2
bool Downloader::_http2 = true; bool Downloader::_http2 = true;
#endif // ENABLE_HTTP2
bool Downloader::doDownload(const Download &dl, bool Downloader::doDownload(const Download &dl,
const QByteArray &authorization, const Redirect *redirect) const QByteArray &authorization, const Redirect *redirect)
@ -114,10 +113,13 @@ bool Downloader::doDownload(const Download &dl,
request.setRawHeader("User-Agent", USER_AGENT); request.setRawHeader("User-Agent", USER_AGENT);
if (!authorization.isNull()) if (!authorization.isNull())
request.setRawHeader("Authorization", authorization); request.setRawHeader("Authorization", authorization);
#ifdef ENABLE_HTTP2 #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
request.setAttribute(QNetworkRequest::HTTP2AllowedAttribute, request.setAttribute(QNetworkRequest::HTTP2AllowedAttribute,
QVariant(_http2)); QVariant(_http2));
#endif // ENABLE_HTTP2 #else // QT 5.15
request.setAttribute(QNetworkRequest::Http2AllowedAttribute,
QVariant(_http2));
#endif // QT 5.15
Q_ASSERT(_manager); Q_ASSERT(_manager);
QNetworkReply *reply = _manager->get(request); QNetworkReply *reply = _manager->get(request);
@ -230,11 +232,9 @@ bool Downloader::get(const QList<Download> &list,
return finishEmitted; return finishEmitted;
} }
#ifdef ENABLE_HTTP2
void Downloader::enableHTTP2(bool enable) void Downloader::enableHTTP2(bool enable)
{ {
Q_ASSERT(_manager); Q_ASSERT(_manager);
_http2 = enable; _http2 = enable;
_manager->clearConnectionCache(); _manager->clearConnectionCache();
} }
#endif // ENABLE_HTTP2

View File

@ -7,7 +7,6 @@
#include <QList> #include <QList>
#include <QSet> #include <QSet>
#include <QHash> #include <QHash>
#include "common/config.h"
class Download class Download
@ -49,9 +48,7 @@ public:
static void setNetworkManager(QNetworkAccessManager *manager) static void setNetworkManager(QNetworkAccessManager *manager)
{_manager = manager;} {_manager = manager;}
static void setTimeout(int timeout) {_timeout = timeout;} static void setTimeout(int timeout) {_timeout = timeout;}
#ifdef ENABLE_HTTP2
static void enableHTTP2(bool enable); static void enableHTTP2(bool enable);
#endif // ENABLE_HTTP2
signals: signals:
void finished(); void finished();
@ -74,9 +71,7 @@ private:
static QNetworkAccessManager *_manager; static QNetworkAccessManager *_manager;
static int _timeout; static int _timeout;
#ifdef ENABLE_HTTP2
static bool _http2; static bool _http2;
#endif // ENABLE_HTTP2
}; };
#endif // DOWNLOADER_H #endif // DOWNLOADER_H

View File

@ -7,8 +7,7 @@
GeoTIFFMap::GeoTIFFMap(const QString &fileName, QObject *parent) GeoTIFFMap::GeoTIFFMap(const QString &fileName, QObject *parent)
: Map(fileName, parent), _fileName(fileName), _img(0), _ratio(1.0), : Map(fileName, parent), _img(0), _ratio(1.0), _valid(false)
_valid(false)
{ {
QImageReader ir(fileName); QImageReader ir(fileName);
if (!ir.canRead()) { if (!ir.canRead()) {
@ -36,7 +35,7 @@ GeoTIFFMap::~GeoTIFFMap()
QString GeoTIFFMap::name() const QString GeoTIFFMap::name() const
{ {
QFileInfo fi(_fileName); QFileInfo fi(path());
return fi.fileName(); return fi.fileName();
} }
@ -73,7 +72,7 @@ void GeoTIFFMap::setDevicePixelRatio(qreal deviceRatio, qreal mapRatio)
void GeoTIFFMap::load() void GeoTIFFMap::load()
{ {
if (!_img) if (!_img)
_img = new Image(_fileName); _img = new Image(path());
} }
void GeoTIFFMap::unload() void GeoTIFFMap::unload()

View File

@ -31,7 +31,6 @@ public:
QString errorString() const {return _errorString;} QString errorString() const {return _errorString;}
private: private:
QString _fileName;
Projection _projection; Projection _projection;
Transform _transform; Transform _transform;
Image *_img; Image *_img;

View File

@ -1,5 +1,4 @@
#include <QPainter> #include <QPainter>
#include "common/config.h"
#include "image.h" #include "image.h"
@ -7,11 +6,7 @@
void Image::draw(QPainter *painter, const QRectF &rect, Map::Flags flags) void Image::draw(QPainter *painter, const QRectF &rect, Map::Flags flags)
{ {
#ifdef ENABLE_HIDPI
qreal ratio = _img.devicePixelRatioF(); qreal ratio = _img.devicePixelRatioF();
#else // ENABLE_HIDPI
qreal ratio = 1.0;
#endif // ENABLE_HIDPI
QRectF sr(rect.topLeft() * ratio, rect.size() * ratio); QRectF sr(rect.topLeft() * ratio, rect.size() * ratio);
/* When OpenGL is used, big images are rendered incredibly slow or not at /* When OpenGL is used, big images are rendered incredibly slow or not at
@ -30,9 +25,7 @@ void Image::draw(QPainter *painter, const QRectF &rect, Map::Flags flags)
QRect tile(tl, QSize(TILE_SIZE, TILE_SIZE)); QRect tile(tl, QSize(TILE_SIZE, TILE_SIZE));
QPixmap *pm = new QPixmap(QPixmap::fromImage(_img.copy(tile))); QPixmap *pm = new QPixmap(QPixmap::fromImage(_img.copy(tile)));
list.append(pm); list.append(pm);
#ifdef ENABLE_HIDPI
pm->setDevicePixelRatio(ratio); pm->setDevicePixelRatio(ratio);
#endif // ENABLE_HIDPI
painter->drawPixmap(tl/ratio, *pm); painter->drawPixmap(tl/ratio, *pm);
} }
} }
@ -44,9 +37,5 @@ void Image::draw(QPainter *painter, const QRectF &rect, Map::Flags flags)
void Image::setDevicePixelRatio(qreal ratio) void Image::setDevicePixelRatio(qreal ratio)
{ {
#ifdef ENABLE_HIDPI
_img.setDevicePixelRatio(ratio); _img.setDevicePixelRatio(ratio);
#else // ENABLE_HIDPI
Q_UNUSED(ratio);
#endif // ENABLE_HIDPI
} }

View File

@ -1,11 +1,7 @@
#include <QFile> #include <QFile>
#include <QPainter> #include <QPainter>
#include <QPixmapCache> #include <QPixmapCache>
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#include <QtCore>
#else // QT_VERSION < 5
#include <QtConcurrent> #include <QtConcurrent>
#endif // QT_VERSION < 5
#include "common/rectc.h" #include "common/rectc.h"
#include "common/range.h" #include "common/range.h"
#include "common/wgs84.h" #include "common/wgs84.h"
@ -160,7 +156,7 @@ void IMGMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
QPoint ttl(tl.x() + i * TILE_SIZE, tl.y() + j * TILE_SIZE); QPoint ttl(tl.x() + i * TILE_SIZE, tl.y() + j * TILE_SIZE);
QString key = _data.at(n)->fileName() + "-" + QString::number(_zoom) QString key = _data.at(n)->fileName() + "-" + QString::number(_zoom)
+ "_" + QString::number(ttl.x()) + "_" + QString::number(ttl.y()); + "_" + QString::number(ttl.x()) + "_" + QString::number(ttl.y());
if (QPixmapCache::find(key, pm)) if (QPixmapCache::find(key, &pm))
painter->drawPixmap(ttl, pm); painter->drawPixmap(ttl, pm);
else { else {
QList<MapData::Poly> polygons, lines; QList<MapData::Poly> polygons, lines;

View File

@ -154,9 +154,21 @@ JNXMap::JNXMap(const QString &fileName, QObject *parent)
return; return;
} }
_file.close();
_valid = true; _valid = true;
} }
void JNXMap::load()
{
_file.open(QIODevice::ReadOnly);
}
void JNXMap::unload()
{
_file.close();
}
QPointF JNXMap::ll2xy(const Coordinates &c) QPointF JNXMap::ll2xy(const Coordinates &c)
{ {
const Zoom &z = _zooms.at(_zoom); const Zoom &z = _zooms.at(_zoom);
@ -235,9 +247,7 @@ bool JNXMap::cb(Tile *tile, void *context)
{ {
Ctx *ctx = static_cast<Ctx*>(context); Ctx *ctx = static_cast<Ctx*>(context);
QPixmap pm(pixmap(tile, ctx->file)); QPixmap pm(pixmap(tile, ctx->file));
#ifdef ENABLE_HIDPI
pm.setDevicePixelRatio(ctx->ratio); pm.setDevicePixelRatio(ctx->ratio);
#endif // ENABLE_HIDPI
ctx->painter->drawPixmap(tile->pos / ctx->ratio, pm); ctx->painter->drawPixmap(tile->pos / ctx->ratio, pm);
return true; return true;

View File

@ -31,6 +31,9 @@ public:
QPointF ll2xy(const Coordinates &c); QPointF ll2xy(const Coordinates &c);
Coordinates xy2ll(const QPointF &p); Coordinates xy2ll(const QPointF &p);
void load();
void unload();
void draw(QPainter *painter, const QRectF &rect, Flags flags); void draw(QPainter *painter, const QRectF &rect, Flags flags);
void setDevicePixelRatio(qreal /*deviceRatio*/, qreal mapRatio) void setDevicePixelRatio(qreal /*deviceRatio*/, qreal mapRatio)

View File

@ -1,6 +1,5 @@
#include <QFile> #include <QFile>
#include <QXmlStreamReader> #include <QXmlStreamReader>
#include "common/config.h"
#include "onlinemap.h" #include "onlinemap.h"
#include "wmtsmap.h" #include "wmtsmap.h"
#include "wmsmap.h" #include "wmsmap.h"
@ -17,9 +16,9 @@ MapSource::Config::Config() : type(OSM), zooms(OSM::ZOOMS), bounds(OSM::BOUNDS),
static CoordinateSystem coordinateSystem(QXmlStreamReader &reader) static CoordinateSystem coordinateSystem(QXmlStreamReader &reader)
{ {
QXmlStreamAttributes attr = reader.attributes(); QXmlStreamAttributes attr = reader.attributes();
if (attr.value("axis") == "yx") if (attr.value("axis") == QLatin1String("yx"))
return CoordinateSystem::YX; return CoordinateSystem::YX;
else if (attr.value("axis") == "xy") else if (attr.value("axis") == QLatin1String("xy"))
return CoordinateSystem::XY; return CoordinateSystem::XY;
else else
return CoordinateSystem::Unknown; return CoordinateSystem::Unknown;
@ -122,9 +121,9 @@ void MapSource::tile(QXmlStreamReader &reader, Config &config)
config.tileSize = size; config.tileSize = size;
} }
if (attr.hasAttribute("type")) { if (attr.hasAttribute("type")) {
if (attr.value("type") == "raster") if (attr.value("type") == QLatin1String("raster"))
config.scalable = false; config.scalable = false;
else if (attr.value("type") == "vector") else if (attr.value("type") == QLatin1String("vector"))
config.scalable = true; config.scalable = true;
else { else {
reader.raiseError("Invalid tile type"); reader.raiseError("Invalid tile type");
@ -132,33 +131,29 @@ void MapSource::tile(QXmlStreamReader &reader, Config &config)
} }
} }
if (attr.hasAttribute("pixelRatio")) { if (attr.hasAttribute("pixelRatio")) {
#ifdef ENABLE_HIDPI
qreal ratio = attr.value("pixelRatio").toString().toDouble(&ok); qreal ratio = attr.value("pixelRatio").toString().toDouble(&ok);
if (!ok || ratio < 0) { if (!ok || ratio < 0) {
reader.raiseError("Invalid tile pixelRatio"); reader.raiseError("Invalid tile pixelRatio");
return; return;
} else } else
config.tileRatio = ratio; config.tileRatio = ratio;
#else // ENABLE_HIDPI
reader.raiseError("HiDPI maps not supported");
#endif // ENABLE_HIDPI
} }
} }
void MapSource::map(QXmlStreamReader &reader, Config &config) void MapSource::map(QXmlStreamReader &reader, Config &config)
{ {
const QXmlStreamAttributes &attr = reader.attributes(); const QXmlStreamAttributes &attr = reader.attributes();
QStringRef type = attr.value("type"); QStringView type = attr.value("type");
if (type == "WMTS") if (type == QLatin1String("WMTS"))
config.type = WMTS; config.type = WMTS;
else if (type == "WMS") else if (type == QLatin1String("WMS"))
config.type = WMS; config.type = WMS;
else if (type == "TMS") else if (type == QLatin1String("TMS"))
config.type = TMS; config.type = TMS;
else if (type == "QuadTiles") else if (type == QLatin1String("QuadTiles"))
config.type = QuadTiles; config.type = QuadTiles;
else if (type == "OSM" || type.isEmpty()) else if (type == QLatin1String("OSM") || type.isEmpty())
config.type = OSM; config.type = OSM;
else { else {
reader.raiseError("Invalid map type"); reader.raiseError("Invalid map type");
@ -166,56 +161,44 @@ void MapSource::map(QXmlStreamReader &reader, Config &config)
} }
while (reader.readNextStartElement()) { while (reader.readNextStartElement()) {
if (reader.name() == "name") if (reader.name() == QLatin1String("name"))
config.name = reader.readElementText(); config.name = reader.readElementText();
else if (reader.name() == "url") { else if (reader.name() == QLatin1String("url")) {
config.rest = (reader.attributes().value("type") == "REST") config.rest = (reader.attributes().value("type")
? true : false; == QLatin1String("REST")) ? true : false;
config.url = reader.readElementText(); config.url = reader.readElementText();
} else if (reader.name() == "zoom") { } else if (reader.name() == QLatin1String("zoom")) {
config.zooms = zooms(reader); config.zooms = zooms(reader);
reader.skipCurrentElement(); reader.skipCurrentElement();
} else if (reader.name() == "bounds") { } else if (reader.name() == QLatin1String("bounds")) {
config.bounds = bounds(reader); config.bounds = bounds(reader);
reader.skipCurrentElement(); reader.skipCurrentElement();
} else if (reader.name() == "format") } else if (reader.name() == QLatin1String("format"))
config.format = reader.readElementText(); config.format = reader.readElementText();
else if (reader.name() == "layer") else if (reader.name() == QLatin1String("layer"))
config.layer = reader.readElementText(); config.layer = reader.readElementText();
else if (reader.name() == "style") else if (reader.name() == QLatin1String("style"))
config.style = reader.readElementText(); config.style = reader.readElementText();
else if (reader.name() == "set") { else if (reader.name() == QLatin1String("set")) {
config.coordinateSystem = coordinateSystem(reader); config.coordinateSystem = coordinateSystem(reader);
config.set = reader.readElementText(); config.set = reader.readElementText();
} else if (reader.name() == "dimension") { } else if (reader.name() == QLatin1String("dimension")) {
QXmlStreamAttributes attr = reader.attributes(); QXmlStreamAttributes attr = reader.attributes();
if (!attr.hasAttribute("id")) if (!attr.hasAttribute("id"))
reader.raiseError("Missing dimension id"); reader.raiseError("Missing dimension id");
else else
config.dimensions.append(KV<QString, QString> config.dimensions.append(KV<QString, QString>
(attr.value("id").toString(), reader.readElementText())); (attr.value("id").toString(), reader.readElementText()));
} else if (reader.name() == "crs") { } else if (reader.name() == QLatin1String("crs")) {
config.coordinateSystem = coordinateSystem(reader); config.coordinateSystem = coordinateSystem(reader);
config.crs = reader.readElementText(); config.crs = reader.readElementText();
} else if (reader.name() == "authorization") { } else if (reader.name() == QLatin1String("authorization")) {
QXmlStreamAttributes attr = reader.attributes(); QXmlStreamAttributes attr = reader.attributes();
config.authorization = Authorization( config.authorization = Authorization(
attr.value("username").toString(), attr.value("username").toString(),
attr.value("password").toString()); attr.value("password").toString());
reader.skipCurrentElement(); reader.skipCurrentElement();
} else if (reader.name() == "tilePixelRatio") { } else if (reader.name() == QLatin1String("tile")) {
// Legacy tilePixelRatio tag support
#ifdef ENABLE_HIDPI
bool ok;
qreal ratio = reader.readElementText().toDouble(&ok);
if (!ok || ratio <= 0)
reader.raiseError("Invalid tilePixelRatio");
else
config.tileRatio = ratio;
#else // ENABLE_HIDPI
reader.raiseError("HiDPI maps not supported");
#endif // ENABLE_HIDPI
} else if (reader.name() == "tile") {
tile(reader, config); tile(reader, config);
reader.skipCurrentElement(); reader.skipCurrentElement();
} else } else
@ -231,7 +214,7 @@ bool MapSource::isMap(const QString &path)
return false; return false;
QXmlStreamReader reader(&file); QXmlStreamReader reader(&file);
if (reader.readNextStartElement() && reader.name() == "map") if (reader.readNextStartElement() && reader.name() == QLatin1String("map"))
return true; return true;
return false; return false;
@ -248,7 +231,7 @@ Map *MapSource::loadMap(const QString &path)
QXmlStreamReader reader(&file); QXmlStreamReader reader(&file);
if (reader.readNextStartElement()) { if (reader.readNextStartElement()) {
if (reader.name() == "map") if (reader.name() == QLatin1String("map"))
map(reader, config); map(reader, config);
else else
reader.raiseError("Not an online map source file"); reader.raiseError("Not an online map source file");

View File

@ -121,11 +121,11 @@ void Matrix::zeroize()
#ifndef QT_NO_DEBUG #ifndef QT_NO_DEBUG
QDebug operator<<(QDebug dbg, const Matrix &matrix) QDebug operator<<(QDebug dbg, const Matrix &matrix)
{ {
dbg.nospace() << "Matrix(" << endl; dbg.nospace() << "Matrix(" << "\n";
for (size_t i = 0; i < matrix.h(); i++) { for (size_t i = 0; i < matrix.h(); i++) {
for (size_t j = 0; j < matrix.w(); j++) for (size_t j = 0; j < matrix.w(); j++)
dbg << "\t" << matrix.m(i, j); dbg << "\t" << matrix.m(i, j);
dbg << endl; dbg << "\n";
} }
dbg << ")"; dbg << ")";

View File

@ -6,11 +6,7 @@
#include <QPixmapCache> #include <QPixmapCache>
#include <QImageReader> #include <QImageReader>
#include <QBuffer> #include <QBuffer>
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#include <QtCore>
#else // QT_VERSION < 5
#include <QtConcurrent> #include <QtConcurrent>
#endif // QT_VERSION < 5
#include "common/rectc.h" #include "common/rectc.h"
#include "common/config.h" #include "common/config.h"
#include "osm.h" #include "osm.h"
@ -55,8 +51,8 @@ static double index2mercator(int index, int zoom)
} }
MBTilesMap::MBTilesMap(const QString &fileName, QObject *parent) MBTilesMap::MBTilesMap(const QString &fileName, QObject *parent)
: Map(fileName, parent), _fileName(fileName), _mapRatio(1.0), _tileRatio(1.0), : Map(fileName, parent), _mapRatio(1.0), _tileRatio(1.0), _scalable(false),
_scalable(false), _scaledSize(0), _valid(false) _scaledSize(0), _valid(false)
{ {
_db = QSqlDatabase::addDatabase("QSQLITE", fileName); _db = QSqlDatabase::addDatabase("QSQLITE", fileName);
_db.setDatabaseName(fileName); _db.setDatabaseName(fileName);
@ -142,7 +138,7 @@ MBTilesMap::MBTilesMap(const QString &fileName, QObject *parent)
if (query.value(0).toString() == "pbf") if (query.value(0).toString() == "pbf")
_scalable = true; _scalable = true;
} else } else
qWarning("%s: missing tiles format", qPrintable(_fileName)); qWarning("%s: missing tiles format", qPrintable(fileName));
} }
{ {
@ -150,8 +146,8 @@ MBTilesMap::MBTilesMap(const QString &fileName, QObject *parent)
if (query.first()) if (query.first())
_name = query.value(0).toString(); _name = query.value(0).toString();
else { else {
qWarning("%s: missing map name", qPrintable(_fileName)); qWarning("%s: missing map name", qPrintable(fileName));
_name = QFileInfo(_fileName).fileName(); _name = QFileInfo(fileName).fileName();
} }
} }
@ -294,10 +290,10 @@ void MBTilesMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
for (int j = 0; j < height; j++) { for (int j = 0; j < height; j++) {
QPixmap pm; QPixmap pm;
QPoint t(tile.x() + i, tile.y() + j); QPoint t(tile.x() + i, tile.y() + j);
QString key = _fileName + "-" + QString::number(_zoom) + "_" QString key = path() + "-" + QString::number(_zoom) + "_"
+ QString::number(t.x()) + "_" + QString::number(t.y()); + QString::number(t.x()) + "_" + QString::number(t.y());
if (QPixmapCache::find(key, pm)) { if (QPixmapCache::find(key, &pm)) {
QPointF tp(qMax(tl.x(), b.left()) + (t.x() - tile.x()) QPointF tp(qMax(tl.x(), b.left()) + (t.x() - tile.x())
* tileSize(), qMax(tl.y(), b.top()) + (t.y() - tile.y()) * tileSize(), qMax(tl.y(), b.top()) + (t.y() - tile.y())
* tileSize()); * tileSize());
@ -329,9 +325,7 @@ void MBTilesMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
void MBTilesMap::drawTile(QPainter *painter, QPixmap &pixmap, QPointF &tp) void MBTilesMap::drawTile(QPainter *painter, QPixmap &pixmap, QPointF &tp)
{ {
#ifdef ENABLE_HIDPI
pixmap.setDevicePixelRatio(imageRatio()); pixmap.setDevicePixelRatio(imageRatio());
#endif // ENABLE_HIDPI
painter->drawPixmap(tp, pixmap); painter->drawPixmap(tp, pixmap);
} }

View File

@ -45,7 +45,7 @@ private:
QSqlDatabase _db; QSqlDatabase _db;
QString _fileName, _name; QString _name;
RectC _bounds; RectC _bounds;
Range _zooms; Range _zooms;
int _zoom; int _zoom;

View File

@ -128,9 +128,7 @@ void OnlineMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
: QPointF(-_tileSize/2, -_tileSize/2); : QPointF(-_tileSize/2, -_tileSize/2);
if (!t.pixmap().isNull()) { if (!t.pixmap().isNull()) {
#ifdef ENABLE_HIDPI
t.pixmap().setDevicePixelRatio(imageRatio()); t.pixmap().setDevicePixelRatio(imageRatio());
#endif // ENABLE_HIDPI
painter->drawPixmap(tp, t.pixmap()); painter->drawPixmap(tp, t.pixmap());
} }
} }

View File

@ -5,6 +5,7 @@
#include <QBuffer> #include <QBuffer>
#include <QImageReader> #include <QImageReader>
#include <QPixmapCache> #include <QPixmapCache>
#include <QRegularExpression>
#include "common/coordinates.h" #include "common/coordinates.h"
#include "common/rectc.h" #include "common/rectc.h"
#include "common/config.h" #include "common/config.h"
@ -127,8 +128,8 @@ bool OziMap::setImageInfo(const QString &path)
if (!ii.exists()) { if (!ii.exists()) {
int last = _map.path.lastIndexOf('\\'); int last = _map.path.lastIndexOf('\\');
if (last >= 0 && last < _map.path.length() - 1) { if (last >= 0 && last < _map.path.length() - 1) {
QStringRef fn(&_map.path, last + 1, _map.path.length() - last - 1); QString fn(_map.path.mid(last + 1, _map.path.length() - last - 1));
ii.setFile(path + "/" + fn.toString()); ii.setFile(path + "/" + fn);
} }
} }
@ -166,7 +167,7 @@ bool OziMap::setTileInfo(const QStringList &tiles, const QString &path)
return false; return false;
} }
QRegExp rx("_[0-9]+_[0-9]+\\."); QRegularExpression rx("_[0-9]+_[0-9]+\\.");
for (int i = 0; i < tiles.size(); i++) { for (int i = 0; i < tiles.size(); i++) {
if (tiles.at(i).contains(rx)) { if (tiles.at(i).contains(rx)) {
_tile.path = QString(tiles.at(i)).replace(rx, "_%1_%2."); _tile.path = QString(tiles.at(i)).replace(rx, "_%1_%2.");
@ -249,9 +250,7 @@ void OziMap::drawTiled(QPainter *painter, const QRectF &rect) const
qWarning("%s: error loading tile image", qPrintable( qWarning("%s: error loading tile image", qPrintable(
_tile.path.arg(QString::number(x), QString::number(y)))); _tile.path.arg(QString::number(x), QString::number(y))));
else { else {
#ifdef ENABLE_HIDPI
pixmap.setDevicePixelRatio(_mapRatio); pixmap.setDevicePixelRatio(_mapRatio);
#endif // ENABLE_HIDPI
QPointF tp(tl.x() + i * ts.width(), tl.y() + j * ts.height()); QPointF tp(tl.x() + i * ts.width(), tl.y() + j * ts.height());
painter->drawPixmap(tp, pixmap); painter->drawPixmap(tp, pixmap);
} }
@ -284,9 +283,7 @@ void OziMap::drawOZF(QPainter *painter, const QRectF &rect) const
if (pixmap.isNull()) if (pixmap.isNull())
qWarning("%s: error loading tile image", qPrintable(key)); qWarning("%s: error loading tile image", qPrintable(key));
else { else {
#ifdef ENABLE_HIDPI
pixmap.setDevicePixelRatio(_mapRatio); pixmap.setDevicePixelRatio(_mapRatio);
#endif // ENABLE_HIDPI
QPointF tp(tl.x() + i * ts.width(), tl.y() + j * ts.height()); QPointF tp(tl.x() + i * ts.width(), tl.y() + j * ts.height());
painter->drawPixmap(tp, pixmap); painter->drawPixmap(tp, pixmap);
} }

View File

@ -2,11 +2,10 @@
#include <QDataStream> #include <QDataStream>
#include <QPixmapCache> #include <QPixmapCache>
#include <QPainter> #include <QPainter>
#include <QRegExp> #include <QRegularExpression>
#include <QtEndian> #include <QtEndian>
#include "common/rectc.h" #include "common/rectc.h"
#include "common/wgs84.h" #include "common/wgs84.h"
#include "common/config.h"
#include "calibrationpoint.h" #include "calibrationpoint.h"
#include "utm.h" #include "utm.h"
#include "pcs.h" #include "pcs.h"
@ -116,7 +115,7 @@ bool RMap::parseIMP(const QByteArray &data)
QVector<CalibrationPoint> calibrationPoints; QVector<CalibrationPoint> calibrationPoints;
const GCS *gcs = 0; const GCS *gcs = 0;
QString projection, datum; QString projection, datum;
QRegExp re("^P[0-9]+="); QRegularExpression re("^P[0-9]+=");
for (int i = 0; i < lines.count(); i++) { for (int i = 0; i < lines.count(); i++) {
const QString &line = lines.at(i); const QString &line = lines.at(i);
@ -161,16 +160,15 @@ bool RMap::parseIMP(const QByteArray &data)
} }
RMap::RMap(const QString &fileName, QObject *parent) RMap::RMap(const QString &fileName, QObject *parent)
: Map(fileName, parent), _mapRatio(1.0), _fileName(fileName), _zoom(0), : Map(fileName, parent), _file(fileName), _mapRatio(1.0), _zoom(0),
_valid(false) _valid(false)
{ {
QFile file(fileName); if (!_file.open(QIODevice::ReadOnly)) {
if (!file.open(QIODevice::ReadOnly)) { _errorString = _file.errorString();
_errorString = file.errorString();
return; return;
} }
QDataStream stream(&file); QDataStream stream(&_file);
stream.setByteOrder(QDataStream::LittleEndian); stream.setByteOrder(QDataStream::LittleEndian);
char magic[sizeof(MAGIC) - 1]; char magic[sizeof(MAGIC) - 1];
@ -229,7 +227,7 @@ RMap::RMap(const QString &fileName, QObject *parent)
_zooms.append(Zoom()); _zooms.append(Zoom());
Zoom &zoom = _zooms.last(); Zoom &zoom = _zooms.last();
CHECK(file.seek(zoomOffsets.at(i))); CHECK(_file.seek(zoomOffsets.at(i)));
quint32 width, height; quint32 width, height;
stream >> width >> height; stream >> width >> height;
@ -246,7 +244,7 @@ RMap::RMap(const QString &fileName, QObject *parent)
CHECK(stream.status() == QDataStream::Ok); CHECK(stream.status() == QDataStream::Ok);
} }
CHECK(file.seek(IMPOffset)); CHECK(_file.seek(IMPOffset));
quint32 IMPSize; quint32 IMPSize;
stream >> unknown >> IMPSize; stream >> unknown >> IMPSize;
CHECK(stream.status() == QDataStream::Ok); CHECK(stream.status() == QDataStream::Ok);
@ -254,11 +252,13 @@ RMap::RMap(const QString &fileName, QObject *parent)
QByteArray IMP(IMPSize + 1, 0); QByteArray IMP(IMPSize + 1, 0);
stream.readRawData(IMP.data(), IMP.size()); stream.readRawData(IMP.data(), IMP.size());
_valid = parseIMP(IMP); _valid = parseIMP(IMP);
_file.close();
} }
QString RMap::name() const QString RMap::name() const
{ {
QFileInfo fi(_fileName); QFileInfo fi(path());
return fi.baseName(); return fi.baseName();
} }
@ -316,7 +316,6 @@ Coordinates RMap::xy2ll(const QPointF &p)
void RMap::load() void RMap::load()
{ {
_file.setFileName(_fileName);
_file.open(QIODevice::ReadOnly); _file.open(QIODevice::ReadOnly);
} }
@ -396,7 +395,7 @@ void RMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
int y = round(tl.y() * _mapRatio + j * _tileSize.height()); int y = round(tl.y() * _mapRatio + j * _tileSize.height());
QPixmap pixmap; QPixmap pixmap;
QString key = _fileName + "/" + QString::number(_zoom) + "_" QString key = path() + "/" + QString::number(_zoom) + "_"
+ QString::number(x) + "_" + QString::number(y); + QString::number(x) + "_" + QString::number(y);
if (!QPixmapCache::find(key, &pixmap)) { if (!QPixmapCache::find(key, &pixmap)) {
pixmap = tile(x, y); pixmap = tile(x, y);
@ -407,9 +406,7 @@ void RMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
if (pixmap.isNull()) if (pixmap.isNull())
qWarning("%s: error loading tile image", qPrintable(key)); qWarning("%s: error loading tile image", qPrintable(key));
else { else {
#ifdef ENABLE_HIDPI
pixmap.setDevicePixelRatio(_mapRatio); pixmap.setDevicePixelRatio(_mapRatio);
#endif // ENABLE_HIDPI
QPointF tp(tl.x() + i * ts.width(), tl.y() + j * ts.height()); QPointF tp(tl.x() + i * ts.width(), tl.y() + j * ts.height());
painter->drawPixmap(tp, pixmap); painter->drawPixmap(tp, pixmap);
} }

View File

@ -53,7 +53,6 @@ private:
QSize _tileSize; QSize _tileSize;
QFile _file; QFile _file;
qreal _mapRatio; qreal _mapRatio;
QString _fileName;
int _zoom; int _zoom;
QVector<QRgb> _palette; QVector<QRgb> _palette;

View File

@ -3,11 +3,7 @@
#include <QEventLoop> #include <QEventLoop>
#include <QPixmapCache> #include <QPixmapCache>
#include <QImageReader> #include <QImageReader>
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#include <QtCore>
#else // QT_VERSION < 5
#include <QtConcurrent> #include <QtConcurrent>
#endif // QT_VERSION < 5
#include "tileloader.h" #include "tileloader.h"
@ -77,7 +73,7 @@ void TileLoader::loadTilesAsync(QVector<Tile> &list)
Tile &t = list[i]; Tile &t = list[i];
QString file(tileFile(t)); QString file(tileFile(t));
if (QPixmapCache::find(file, t.pixmap())) if (QPixmapCache::find(file, &t.pixmap()))
continue; continue;
QFileInfo fi(file); QFileInfo fi(file);
@ -116,7 +112,7 @@ void TileLoader::loadTilesSync(QVector<Tile> &list)
Tile &t = list[i]; Tile &t = list[i];
QString file(tileFile(t)); QString file(tileFile(t));
if (QPixmapCache::find(file, t.pixmap())) if (QPixmapCache::find(file, &t.pixmap()))
continue; continue;
QFileInfo fi(file); QFileInfo fi(file);

View File

@ -41,7 +41,7 @@ WMS::CTX::CTX(const Setup &setup) : setup(setup), formatSupported(false)
void WMS::get(QXmlStreamReader &reader, CTX &ctx) void WMS::get(QXmlStreamReader &reader, CTX &ctx)
{ {
while (reader.readNextStartElement()) { while (reader.readNextStartElement()) {
if (reader.name() == "OnlineResource") { if (reader.name() == QLatin1String("OnlineResource")) {
QXmlStreamAttributes attr = reader.attributes(); QXmlStreamAttributes attr = reader.attributes();
ctx.url = attr.value("xlink:href").toString(); ctx.url = attr.value("xlink:href").toString();
reader.skipCurrentElement(); reader.skipCurrentElement();
@ -53,7 +53,7 @@ void WMS::get(QXmlStreamReader &reader, CTX &ctx)
void WMS::http(QXmlStreamReader &reader, CTX &ctx) void WMS::http(QXmlStreamReader &reader, CTX &ctx)
{ {
while (reader.readNextStartElement()) { while (reader.readNextStartElement()) {
if (reader.name() == "Get") if (reader.name() == QLatin1String("Get"))
get(reader, ctx); get(reader, ctx);
else else
reader.skipCurrentElement(); reader.skipCurrentElement();
@ -63,7 +63,7 @@ void WMS::http(QXmlStreamReader &reader, CTX &ctx)
void WMS::dcpType(QXmlStreamReader &reader, CTX &ctx) void WMS::dcpType(QXmlStreamReader &reader, CTX &ctx)
{ {
while (reader.readNextStartElement()) { while (reader.readNextStartElement()) {
if (reader.name() == "HTTP") if (reader.name() == QLatin1String("HTTP"))
http(reader, ctx); http(reader, ctx);
else else
reader.skipCurrentElement(); reader.skipCurrentElement();
@ -73,11 +73,11 @@ void WMS::dcpType(QXmlStreamReader &reader, CTX &ctx)
void WMS::getMap(QXmlStreamReader &reader, CTX &ctx) void WMS::getMap(QXmlStreamReader &reader, CTX &ctx)
{ {
while (reader.readNextStartElement()) { while (reader.readNextStartElement()) {
if (reader.name() == "Format") { if (reader.name() == QLatin1String("Format")) {
QString format(reader.readElementText()); QString format(reader.readElementText());
if (bareFormat(format) == bareFormat(ctx.setup.format())) if (bareFormat(format) == bareFormat(ctx.setup.format()))
ctx.formatSupported = true; ctx.formatSupported = true;
} else if (reader.name() == "DCPType") } else if (reader.name() == QLatin1String("DCPType"))
dcpType(reader, ctx); dcpType(reader, ctx);
else else
reader.skipCurrentElement(); reader.skipCurrentElement();
@ -87,7 +87,7 @@ void WMS::getMap(QXmlStreamReader &reader, CTX &ctx)
void WMS::request(QXmlStreamReader &reader, CTX &ctx) void WMS::request(QXmlStreamReader &reader, CTX &ctx)
{ {
while (reader.readNextStartElement()) { while (reader.readNextStartElement()) {
if (reader.name() == "GetMap") if (reader.name() == QLatin1String("GetMap"))
getMap(reader, ctx); getMap(reader, ctx);
else else
reader.skipCurrentElement(); reader.skipCurrentElement();
@ -99,7 +99,7 @@ QString WMS::style(QXmlStreamReader &reader)
QString name; QString name;
while (reader.readNextStartElement()) { while (reader.readNextStartElement()) {
if (reader.name() == "Name") if (reader.name() == QLatin1String("Name"))
name = reader.readElementText(); name = reader.readElementText();
else else
reader.skipCurrentElement(); reader.skipCurrentElement();
@ -113,13 +113,13 @@ RectC WMS::geographicBoundingBox(QXmlStreamReader &reader)
double left = NAN, top = NAN, right = NAN, bottom = NAN; double left = NAN, top = NAN, right = NAN, bottom = NAN;
while (reader.readNextStartElement()) { while (reader.readNextStartElement()) {
if (reader.name() == "westBoundLongitude") if (reader.name() == QLatin1String("westBoundLongitude"))
left = reader.readElementText().toDouble(); left = reader.readElementText().toDouble();
else if (reader.name() == "eastBoundLongitude") else if (reader.name() == QLatin1String("eastBoundLongitude"))
right = reader.readElementText().toDouble(); right = reader.readElementText().toDouble();
else if (reader.name() == "northBoundLatitude") else if (reader.name() == QLatin1String("northBoundLatitude"))
top = reader.readElementText().toDouble(); top = reader.readElementText().toDouble();
else if (reader.name() == "southBoundLatitude") else if (reader.name() == QLatin1String("southBoundLatitude"))
bottom = reader.readElementText().toDouble(); bottom = reader.readElementText().toDouble();
else else
reader.skipCurrentElement(); reader.skipCurrentElement();
@ -140,13 +140,14 @@ void WMS::layer(QXmlStreamReader &reader, CTX &ctx,
int index; int index;
while (reader.readNextStartElement()) { while (reader.readNextStartElement()) {
if (reader.name() == "Name") if (reader.name() == QLatin1String("Name"))
name = reader.readElementText(); name = reader.readElementText();
else if (reader.name() == "CRS" || reader.name() == "SRS") else if (reader.name() == QLatin1String("CRS")
|| reader.name() == QLatin1String("SRS"))
CRSs.append(reader.readElementText()); CRSs.append(reader.readElementText());
else if (reader.name() == "Style") else if (reader.name() == QLatin1String("Style"))
styles.append(style(reader)); styles.append(style(reader));
else if (reader.name() == "ScaleHint") { else if (reader.name() == QLatin1String("ScaleHint")) {
QXmlStreamAttributes attr = reader.attributes(); QXmlStreamAttributes attr = reader.attributes();
double minHint = attr.value("min").toString().toDouble(); double minHint = attr.value("min").toString().toDouble();
double maxHint = attr.value("max").toString().toDouble(); double maxHint = attr.value("max").toString().toDouble();
@ -155,15 +156,15 @@ void WMS::layer(QXmlStreamReader &reader, CTX &ctx,
if (maxHint > 0) if (maxHint > 0)
scaleDenominator.setMax(hint2denominator(maxHint)); scaleDenominator.setMax(hint2denominator(maxHint));
reader.skipCurrentElement(); reader.skipCurrentElement();
} else if (reader.name() == "MinScaleDenominator") { } else if (reader.name() == QLatin1String("MinScaleDenominator")) {
double sd = reader.readElementText().toDouble(); double sd = reader.readElementText().toDouble();
if (sd > 0) if (sd > 0)
scaleDenominator.setMin(sd); scaleDenominator.setMin(sd);
} else if (reader.name() == "MaxScaleDenominator") { } else if (reader.name() == QLatin1String("MaxScaleDenominator")) {
double sd = reader.readElementText().toDouble(); double sd = reader.readElementText().toDouble();
if (sd > 0) if (sd > 0)
scaleDenominator.setMax(sd); scaleDenominator.setMax(sd);
} else if (reader.name() == "LatLonBoundingBox") { } else if (reader.name() == QLatin1String("LatLonBoundingBox")) {
QXmlStreamAttributes attr = reader.attributes(); QXmlStreamAttributes attr = reader.attributes();
boundingBox = RectC(Coordinates( boundingBox = RectC(Coordinates(
attr.value("minx").toString().toDouble(), attr.value("minx").toString().toDouble(),
@ -171,9 +172,9 @@ void WMS::layer(QXmlStreamReader &reader, CTX &ctx,
Coordinates(attr.value("maxx").toString().toDouble(), Coordinates(attr.value("maxx").toString().toDouble(),
attr.value("miny").toString().toDouble())); attr.value("miny").toString().toDouble()));
reader.skipCurrentElement(); reader.skipCurrentElement();
} else if (reader.name() == "EX_GeographicBoundingBox") } else if (reader.name() == QLatin1String("EX_GeographicBoundingBox"))
boundingBox = geographicBoundingBox(reader); boundingBox = geographicBoundingBox(reader);
else if (reader.name() == "Layer") else if (reader.name() == QLatin1String("Layer"))
layer(reader, ctx, CRSs, styles, scaleDenominator, boundingBox); layer(reader, ctx, CRSs, styles, scaleDenominator, boundingBox);
else else
reader.skipCurrentElement(); reader.skipCurrentElement();
@ -197,9 +198,9 @@ void WMS::capability(QXmlStreamReader &reader, CTX &ctx)
RectC boundingBox; RectC boundingBox;
while (reader.readNextStartElement()) { while (reader.readNextStartElement()) {
if (reader.name() == "Layer") if (reader.name() == QLatin1String("Layer"))
layer(reader, ctx, CRSs, styles, scaleDenominator, boundingBox); layer(reader, ctx, CRSs, styles, scaleDenominator, boundingBox);
else if (reader.name() == "Request") else if (reader.name() == QLatin1String("Request"))
request(reader, ctx); request(reader, ctx);
else else
reader.skipCurrentElement(); reader.skipCurrentElement();
@ -211,7 +212,7 @@ void WMS::capabilities(QXmlStreamReader &reader, CTX &ctx)
_version = reader.attributes().value("version").toString(); _version = reader.attributes().value("version").toString();
while (reader.readNextStartElement()) { while (reader.readNextStartElement()) {
if (reader.name() == "Capability") if (reader.name() == QLatin1String("Capability"))
capability(reader, ctx); capability(reader, ctx);
else else
reader.skipCurrentElement(); reader.skipCurrentElement();
@ -237,8 +238,8 @@ bool WMS::parseCapabilities()
reader.setDevice(&file); reader.setDevice(&file);
if (reader.readNextStartElement()) { if (reader.readNextStartElement()) {
if (reader.name() == "WMS_Capabilities" if (reader.name() == QLatin1String("WMS_Capabilities")
|| reader.name() == "WMT_MS_Capabilities") || reader.name() == QLatin1String("WMT_MS_Capabilities"))
capabilities(reader, ctx); capabilities(reader, ctx);
else else
reader.raiseError("Not a WMS Capabilities XML file"); reader.raiseError("Not a WMS Capabilities XML file");

View File

@ -200,9 +200,7 @@ void WMSMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
Tile &t = tiles[i]; Tile &t = tiles[i];
QPointF tp(t.xy().x() * tileSize(), t.xy().y() * tileSize()); QPointF tp(t.xy().x() * tileSize(), t.xy().y() * tileSize());
if (!t.pixmap().isNull()) { if (!t.pixmap().isNull()) {
#ifdef ENABLE_HIDPI
t.pixmap().setDevicePixelRatio(_mapRatio); t.pixmap().setDevicePixelRatio(_mapRatio);
#endif // ENABLE_HIDPI
painter->drawPixmap(tp, t.pixmap()); painter->drawPixmap(tp, t.pixmap());
} }
} }

View File

@ -28,21 +28,21 @@ WMTS::TileMatrix WMTS::tileMatrix(QXmlStreamReader &reader)
TileMatrix matrix; TileMatrix matrix;
while (reader.readNextStartElement()) { while (reader.readNextStartElement()) {
if (reader.name() == "Identifier") if (reader.name() == QLatin1String("Identifier"))
matrix.id = reader.readElementText(); matrix.id = reader.readElementText();
else if (reader.name() == "ScaleDenominator") else if (reader.name() == QLatin1String("ScaleDenominator"))
matrix.scaleDenominator = reader.readElementText().toDouble(); matrix.scaleDenominator = reader.readElementText().toDouble();
else if (reader.name() == "TopLeftCorner") { else if (reader.name() == QLatin1String("TopLeftCorner")) {
QString str = reader.readElementText(); QString str = reader.readElementText();
QTextStream ts(&str); QTextStream ts(&str);
ts >> matrix.topLeft.rx() >> matrix.topLeft.ry(); ts >> matrix.topLeft.rx() >> matrix.topLeft.ry();
} else if (reader.name() == "TileWidth") } else if (reader.name() == QLatin1String("TileWidth"))
matrix.tile.setWidth(reader.readElementText().toInt()); matrix.tile.setWidth(reader.readElementText().toInt());
else if (reader.name() == "TileHeight") else if (reader.name() == QLatin1String("TileHeight"))
matrix.tile.setHeight(reader.readElementText().toInt()); matrix.tile.setHeight(reader.readElementText().toInt());
else if (reader.name() == "MatrixWidth") else if (reader.name() == QLatin1String("MatrixWidth"))
matrix.matrix.setWidth(reader.readElementText().toInt()); matrix.matrix.setWidth(reader.readElementText().toInt());
else if (reader.name() == "MatrixHeight") else if (reader.name() == QLatin1String("MatrixHeight"))
matrix.matrix.setHeight(reader.readElementText().toInt()); matrix.matrix.setHeight(reader.readElementText().toInt());
else else
reader.skipCurrentElement(); reader.skipCurrentElement();
@ -57,14 +57,14 @@ WMTS::TileMatrix WMTS::tileMatrix(QXmlStreamReader &reader)
void WMTS::tileMatrixSet(QXmlStreamReader &reader, CTX &ctx) void WMTS::tileMatrixSet(QXmlStreamReader &reader, CTX &ctx)
{ {
while (reader.readNextStartElement()) { while (reader.readNextStartElement()) {
if (reader.name() == "Identifier") { if (reader.name() == QLatin1String("Identifier")) {
if (reader.readElementText() != _setup.set()) { if (reader.readElementText() != _setup.set()) {
skipParentElement(reader); skipParentElement(reader);
return; return;
} }
} else if (reader.name() == "SupportedCRS") } else if (reader.name() == QLatin1String("SupportedCRS"))
ctx.crs = reader.readElementText(); ctx.crs = reader.readElementText();
else if (reader.name() == "TileMatrix") else if (reader.name() == QLatin1String("TileMatrix"))
ctx.matrixes.insert(tileMatrix(reader)); ctx.matrixes.insert(tileMatrix(reader));
else else
reader.skipCurrentElement(); reader.skipCurrentElement();
@ -76,15 +76,15 @@ WMTS::MatrixLimits WMTS::tileMatrixLimits(QXmlStreamReader &reader)
MatrixLimits limits; MatrixLimits limits;
while (reader.readNextStartElement()) { while (reader.readNextStartElement()) {
if (reader.name() == "TileMatrix") if (reader.name() == QLatin1String("TileMatrix"))
limits.id = reader.readElementText(); limits.id = reader.readElementText();
else if (reader.name() == "MinTileRow") else if (reader.name() == QLatin1String("MinTileRow"))
limits.rect.setTop(reader.readElementText().toInt()); limits.rect.setTop(reader.readElementText().toInt());
else if (reader.name() == "MaxTileRow") else if (reader.name() == QLatin1String("MaxTileRow"))
limits.rect.setBottom(reader.readElementText().toInt()); limits.rect.setBottom(reader.readElementText().toInt());
else if (reader.name() == "MinTileCol") else if (reader.name() == QLatin1String("MinTileCol"))
limits.rect.setLeft(reader.readElementText().toInt()); limits.rect.setLeft(reader.readElementText().toInt());
else if (reader.name() == "MaxTileCol") else if (reader.name() == QLatin1String("MaxTileCol"))
limits.rect.setRight(reader.readElementText().toInt()); limits.rect.setRight(reader.readElementText().toInt());
else else
reader.skipCurrentElement(); reader.skipCurrentElement();
@ -101,7 +101,7 @@ QSet<WMTS::MatrixLimits> WMTS::tileMatrixSetLimits(QXmlStreamReader &reader)
QSet<MatrixLimits> limits; QSet<MatrixLimits> limits;
while (reader.readNextStartElement()) { while (reader.readNextStartElement()) {
if (reader.name() == "TileMatrixLimits") if (reader.name() == QLatin1String("TileMatrixLimits"))
limits.insert(tileMatrixLimits(reader)); limits.insert(tileMatrixLimits(reader));
else else
reader.skipCurrentElement(); reader.skipCurrentElement();
@ -113,14 +113,14 @@ QSet<WMTS::MatrixLimits> WMTS::tileMatrixSetLimits(QXmlStreamReader &reader)
void WMTS::tileMatrixSetLink(QXmlStreamReader &reader, CTX &ctx) void WMTS::tileMatrixSetLink(QXmlStreamReader &reader, CTX &ctx)
{ {
while (reader.readNextStartElement()) { while (reader.readNextStartElement()) {
if (reader.name() == "TileMatrixSet") { if (reader.name() == QLatin1String("TileMatrixSet")) {
if (reader.readElementText() == _setup.set()) if (reader.readElementText() == _setup.set())
ctx.hasSet = true; ctx.hasSet = true;
else { else {
skipParentElement(reader); skipParentElement(reader);
return; return;
} }
} else if (reader.name() == "TileMatrixSetLimits") } else if (reader.name() == QLatin1String("TileMatrixSetLimits"))
ctx.limits = tileMatrixSetLimits(reader); ctx.limits = tileMatrixSetLimits(reader);
else else
reader.skipCurrentElement(); reader.skipCurrentElement();
@ -132,10 +132,10 @@ RectC WMTS::wgs84BoundingBox(QXmlStreamReader &reader)
Coordinates topLeft, bottomRight; Coordinates topLeft, bottomRight;
while (reader.readNextStartElement()) { while (reader.readNextStartElement()) {
if (reader.name() == "LowerCorner") { if (reader.name() == QLatin1String("LowerCorner")) {
QString str = reader.readElementText(); QString str = reader.readElementText();
QTextStream(&str) >> topLeft.rlon() >> bottomRight.rlat(); QTextStream(&str) >> topLeft.rlon() >> bottomRight.rlat();
} else if (reader.name() == "UpperCorner") { } else if (reader.name() == QLatin1String("UpperCorner")) {
QString str = reader.readElementText(); QString str = reader.readElementText();
QTextStream(&str) >> bottomRight.rlon() >> topLeft.rlat(); QTextStream(&str) >> bottomRight.rlon() >> topLeft.rlat();
} else } else
@ -150,7 +150,7 @@ QString WMTS::style(QXmlStreamReader &reader)
QString id; QString id;
while (reader.readNextStartElement()) { while (reader.readNextStartElement()) {
if (reader.name() == "Identifier") if (reader.name() == QLatin1String("Identifier"))
id = reader.readElementText(); id = reader.readElementText();
else else
reader.skipCurrentElement(); reader.skipCurrentElement();
@ -162,31 +162,32 @@ QString WMTS::style(QXmlStreamReader &reader)
void WMTS::layer(QXmlStreamReader &reader, CTX &ctx) void WMTS::layer(QXmlStreamReader &reader, CTX &ctx)
{ {
while (reader.readNextStartElement()) { while (reader.readNextStartElement()) {
if (reader.name() == "Identifier") { if (reader.name() == QLatin1String("Identifier")) {
if (reader.readElementText() == _setup.layer()) if (reader.readElementText() == _setup.layer())
ctx.hasLayer = true; ctx.hasLayer = true;
else { else {
skipParentElement(reader); skipParentElement(reader);
return; return;
} }
} else if (reader.name() == "TileMatrixSetLink") } else if (reader.name() == QLatin1String("TileMatrixSetLink"))
tileMatrixSetLink(reader, ctx); tileMatrixSetLink(reader, ctx);
else if (reader.name() == "WGS84BoundingBox") else if (reader.name() == QLatin1String("WGS84BoundingBox"))
ctx.bbox = wgs84BoundingBox(reader); ctx.bbox = wgs84BoundingBox(reader);
else if (reader.name() == "ResourceURL") { else if (reader.name() == QLatin1String("ResourceURL")) {
const QXmlStreamAttributes &attr = reader.attributes(); const QXmlStreamAttributes &attr = reader.attributes();
if (attr.value("resourceType") == "tile" && _setup.rest()) if (attr.value("resourceType") == QLatin1String("tile")
&& _setup.rest())
_tileUrl = attr.value("template").toString(); _tileUrl = attr.value("template").toString();
reader.skipCurrentElement(); reader.skipCurrentElement();
} else if (reader.name() == "Style") { } else if (reader.name() == QLatin1String("Style")) {
const QXmlStreamAttributes &attr = reader.attributes(); const QXmlStreamAttributes &attr = reader.attributes();
bool isDefault = (attr.value("isDefault") == "true"); bool isDefault = (attr.value("isDefault") == QLatin1String("true"));
QString s = style(reader); QString s = style(reader);
if (isDefault) if (isDefault)
ctx.defaultStyle = s; ctx.defaultStyle = s;
if (s == _setup.style()) if (s == _setup.style())
ctx.hasStyle = true; ctx.hasStyle = true;
} else if (reader.name() == "Format") { } else if (reader.name() == QLatin1String("Format")) {
QString format(reader.readElementText()); QString format(reader.readElementText());
if (bareFormat(format) == bareFormat(_setup.format())) if (bareFormat(format) == bareFormat(_setup.format()))
ctx.hasFormat = true; ctx.hasFormat = true;
@ -198,9 +199,9 @@ void WMTS::layer(QXmlStreamReader &reader, CTX &ctx)
void WMTS::contents(QXmlStreamReader &reader, CTX &ctx) void WMTS::contents(QXmlStreamReader &reader, CTX &ctx)
{ {
while (reader.readNextStartElement()) { while (reader.readNextStartElement()) {
if (reader.name() == "TileMatrixSet") if (reader.name() == QLatin1String("TileMatrixSet"))
tileMatrixSet(reader, ctx); tileMatrixSet(reader, ctx);
else if (reader.name() == "Layer") else if (reader.name() == QLatin1String("Layer"))
layer(reader, ctx); layer(reader, ctx);
else else
reader.skipCurrentElement(); reader.skipCurrentElement();
@ -210,7 +211,7 @@ void WMTS::contents(QXmlStreamReader &reader, CTX &ctx)
void WMTS::capabilities(QXmlStreamReader &reader, CTX &ctx) void WMTS::capabilities(QXmlStreamReader &reader, CTX &ctx)
{ {
while (reader.readNextStartElement()) { while (reader.readNextStartElement()) {
if (reader.name() == "Contents") if (reader.name() == QLatin1String("Contents"))
contents(reader, ctx); contents(reader, ctx);
else else
reader.skipCurrentElement(); reader.skipCurrentElement();
@ -229,7 +230,7 @@ void WMTS::createZooms(const CTX &ctx)
mi->matrix, li == ctx.limits.constEnd() ? QRect() : li->rect)); mi->matrix, li == ctx.limits.constEnd() ? QRect() : li->rect));
} }
qSort(_zooms); std::sort(_zooms.begin(), _zooms.end());
} }
bool WMTS::parseCapabilities(CTX &ctx) bool WMTS::parseCapabilities(CTX &ctx)
@ -244,7 +245,7 @@ bool WMTS::parseCapabilities(CTX &ctx)
reader.setDevice(&file); reader.setDevice(&file);
if (reader.readNextStartElement()) { if (reader.readNextStartElement()) {
if (reader.name() == "Capabilities") if (reader.name() == QLatin1String("Capabilities"))
capabilities(reader, ctx); capabilities(reader, ctx);
else else
reader.raiseError("Not a Capabilities XML file"); reader.raiseError("Not a Capabilities XML file");

View File

@ -195,9 +195,7 @@ void WMTSMap::draw(QPainter *painter, const QRectF &rect, Flags flags)
Tile &t = tiles[i]; Tile &t = tiles[i];
QPointF tp(t.xy().x() * ts.width(), t.xy().y() * ts.height()); QPointF tp(t.xy().x() * ts.width(), t.xy().y() * ts.height());
if (!t.pixmap().isNull()) { if (!t.pixmap().isNull()) {
#ifdef ENABLE_HIDPI
t.pixmap().setDevicePixelRatio(imageRatio()); t.pixmap().setDevicePixelRatio(imageRatio());
#endif // ENABLE_HIDPI
painter->drawPixmap(tp, t.pixmap()); painter->drawPixmap(tp, t.pixmap());
} }
} }