1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-12-05 00:39:09 +01:00

Compare commits

...

6 Commits

Author SHA1 Message Date
2bd25dd9b0 Fixed build with Qt < 5.13 2023-04-25 23:33:54 +02:00
79e9a49245 Merge remote-tracking branch 'weblate/master' 2023-04-25 23:10:27 +02:00
simmon
e319ca4df1
Translated using Weblate (Korean)
Currently translated at 100.0% (467 of 467 strings)

Translation: GPXSee/Translations
Translate-URL: https://hosted.weblate.org/projects/gpxsee/translations/ko/
2023-04-25 23:09:42 +02:00
55724594ec This drives me crazy! 2023-04-25 23:08:27 +02:00
8cea06f2ad Improve SQLite-based maps error reporting 2023-04-25 22:52:55 +02:00
1d589e25d8 Some more Mapsforge microoptimizations + code cleanup 2023-04-25 22:11:47 +02:00
11 changed files with 66 additions and 37 deletions

View File

@ -1144,7 +1144,7 @@
<rule e="any" k="amenity" v="fuel" zoom-min="13">
<symbol id="fuel" src=":/mapsforge/symbols/transport/fuel.svg" />
<rule e="any" k="*" v="*" zoom-min="18">
<caption fill="#0092DA" font-size="12" font-style="bold" k="name" stroke="#FFFFFF"
<caption fill="#AC39AC" font-size="12" font-style="bold" k="name" stroke="#FFFFFF"
stroke-width="2.0" symbol-id="fuel" />
</rule>
</rule>

View File

@ -866,7 +866,7 @@
<location filename="../src/GUI/gui.cpp" line="907"/>
<location filename="../src/GUI/gui.cpp" line="925"/>
<source>CRS directory:</source>
<translation type="unfinished"></translation>
<translation>CRS :</translation>
</message>
<message>
<source>GCS/PCS directory:</source>

View File

@ -10,6 +10,7 @@
#endif // Q_OS_ANDROID
#include "util.h"
#define SQLITE_DB_MAGIC "SQLite format 3"
#ifdef Q_OS_ANDROID
static QString documentName(const QString &path)
@ -156,3 +157,21 @@ const QTemporaryDir &Util::tempDir()
static QTemporaryDir dir;
return dir;
}
bool Util::isSQLiteDB(const QString &path, QString &errorString)
{
QFile file(path);
char magic[sizeof(SQLITE_DB_MAGIC)];
if (!file.open(QFile::ReadOnly)) {
errorString = file.errorString();
return false;
}
if ((file.read(magic, sizeof(magic)) < (qint64)sizeof(magic))
|| memcmp(SQLITE_DB_MAGIC, magic, sizeof(SQLITE_DB_MAGIC))) {
errorString = "Not a SQLite database file";
return false;
}
return true;
}

View File

@ -16,6 +16,7 @@ namespace Util
QString file2name(const QString &path);
QString displayName(const QString &path);
const QTemporaryDir &tempDir();
bool isSQLiteDB(const QString &path, QString &errorString);
}
#endif // UTIL_H

View File

@ -200,6 +200,13 @@ QPainterPath RasterTile::painterPath(const Polygon &polygon, bool curve) const
{
QPainterPath path;
#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
int size = 0;
for (int i = 0; i < polygon.size(); i++)
size += polygon.at(i).size();
path.reserve(size);
#endif // QT 5.13
for (int i = 0; i < polygon.size(); i++) {
const QVector<Coordinates> &subpath = polygon.at(i);

View File

@ -138,12 +138,13 @@ void Style::area(QXmlStreamReader &reader, const QString &dir, qreal ratio,
PathRender ri(rule, _paths.size() + _circles.size());
const QXmlStreamAttributes &attr = reader.attributes();
QString file;
QColor fillColor;
int height = 0, width = 0;
bool ok;
ri._area = true;
if (attr.hasAttribute("fill"))
ri._fillColor = QColor(attr.value("fill").toString());
fillColor = QColor(attr.value("fill").toString());
if (attr.hasAttribute("stroke"))
ri._strokeColor = QColor(attr.value("stroke").toString());
if (attr.hasAttribute("stroke-width")) {
@ -171,7 +172,9 @@ void Style::area(QXmlStreamReader &reader, const QString &dir, qreal ratio,
}
if (!file.isNull())
ri._fillImage = image(file, width, height, ratio);
ri._brush = QBrush(image(file, width, height, ratio));
else if (fillColor.isValid())
ri._brush = QBrush(fillColor);
if (ri.rule()._type == Rule::AnyType || ri.rule()._type == Rule::WayType)
_paths.append(ri);
@ -652,10 +655,9 @@ QList<const Style::Symbol*> Style::areaSymbols(int zoom) const
QPen Style::PathRender::pen(int zoom) const
{
qreal width = (zoom >= 12)
? pow(1.5, zoom - 12) * _strokeWidth : _strokeWidth;
if (_strokeColor.isValid()) {
qreal width = (zoom >= 12)
? pow(1.5, zoom - 12) * _strokeWidth : _strokeWidth;
QPen p(QBrush(_strokeColor), width, Qt::SolidLine, _strokeCap,
_strokeJoin);
if (!_strokeDasharray.isEmpty()) {
@ -669,16 +671,6 @@ QPen Style::PathRender::pen(int zoom) const
return Qt::NoPen;
}
QBrush Style::PathRender::brush() const
{
if (!_fillImage.isNull())
return QBrush(_fillImage);
else if (_fillColor.isValid())
return QBrush(_fillColor);
else
return Qt::NoBrush;
}
qreal Style::CircleRender::radius(int zoom) const
{
return (_scale && zoom >= 12) ? pow(1.5, zoom - 12) * _radius : _radius;

View File

@ -11,17 +11,6 @@ class QXmlStreamReader;
namespace Mapsforge {
inline bool wcmp(const QByteArray &b1, const QByteArray &b2)
{
int len = b1.length();
if (!len)
return true;
if (len != b2.length())
return false;
return !memcmp(b1.constData(), b2.constData(), len);
}
class Style
{
public:
@ -87,10 +76,13 @@ public:
bool valueMatches(const QVector<MapData::Tag> &tags) const
{
for (int i = 0; i < _vals.size(); i++)
for (int j = 0; j < tags.size(); j++)
if (wcmp(_vals.at(i), tags.at(j).value))
for (int i = 0; i < _vals.size(); i++) {
for (int j = 0; j < tags.size(); j++) {
const QByteArray &ba = _vals.at(i);
if (!ba.size() || ba == tags.at(j).value)
return true;
}
}
return false;
}
@ -148,7 +140,7 @@ public:
int zOrder() const {return _zOrder;}
QPen pen(int zoom) const;
QBrush brush() const;
const QBrush &brush() const {return _brush;}
bool area() const {return _area;}
bool curve() const {return _curve;}
@ -156,12 +148,12 @@ public:
friend class Style;
int _zOrder;
QColor _fillColor, _strokeColor;
QColor _strokeColor;
qreal _strokeWidth;
QVector<qreal> _strokeDasharray;
Qt::PenCapStyle _strokeCap;
Qt::PenJoinStyle _strokeJoin;
QImage _fillImage;
QBrush _brush;
bool _area, _curve;
};

View File

@ -1,6 +1,7 @@
#include <QSqlQuery>
#include <QSqlRecord>
#include <QSqlField>
#include <QSqlError>
#include <QPainter>
#include <QPixmapCache>
#include <QImageReader>
@ -48,12 +49,15 @@ MBTilesMap::MBTilesMap(const QString &fileName, QObject *parent)
: Map(fileName, parent), _mapRatio(1.0), _tileRatio(1.0), _scalable(false),
_scaledSize(0), _valid(false)
{
if (!Util::isSQLiteDB(fileName, _errorString))
return;
_db = QSqlDatabase::addDatabase("QSQLITE", fileName);
_db.setDatabaseName(fileName);
_db.setConnectOptions("QSQLITE_OPEN_READONLY");
if (!_db.open()) {
_errorString = "Error opening database file";
_errorString = _db.lastError().text();
return;
}

View File

@ -413,6 +413,12 @@ OruxMap::OruxMap(const QString &fileName, QObject *parent)
if (dir.exists("OruxMapsImages.db")) {
QString dbFile(dir.absoluteFilePath("OruxMapsImages.db"));
if (!Util::isSQLiteDB(dbFile, _errorString)) {
_errorString = "OruxMapsImages.db: " + _errorString;
return;
}
_db = QSqlDatabase::addDatabase("QSQLITE", dbFile);
_db.setDatabaseName(dbFile);
_db.setConnectOptions("QSQLITE_OPEN_READONLY");

View File

@ -1,6 +1,7 @@
#include <QSqlQuery>
#include <QSqlRecord>
#include <QSqlField>
#include <QSqlError>
#include <QPainter>
#include <QPixmapCache>
#include <QImageReader>
@ -18,12 +19,15 @@ OsmdroidMap::OsmdroidMap(const QString &fileName, QObject *parent)
{
quint64 z, l = 0, r = 0, t = 0, b = 0;
if (!Util::isSQLiteDB(fileName, _errorString))
return;
_db = QSqlDatabase::addDatabase("QSQLITE", fileName);
_db.setDatabaseName(fileName);
_db.setConnectOptions("QSQLITE_OPEN_READONLY");
if (!_db.open()) {
_errorString = "Error opening database file";
_errorString = _db.lastError().text();
return;
}

View File

@ -1,6 +1,7 @@
#include <QSqlQuery>
#include <QSqlRecord>
#include <QSqlField>
#include <QSqlError>
#include <QPainter>
#include <QPixmapCache>
#include <QImageReader>
@ -16,12 +17,15 @@
SqliteMap::SqliteMap(const QString &fileName, QObject *parent)
: Map(fileName, parent), _mapRatio(1.0), _valid(false)
{
if (!Util::isSQLiteDB(fileName, _errorString))
return;
_db = QSqlDatabase::addDatabase("QSQLITE", fileName);
_db.setDatabaseName(fileName);
_db.setConnectOptions("QSQLITE_OPEN_READONLY");
if (!_db.open()) {
_errorString = "Error opening database file";
_errorString = _db.lastError().text();
return;
}