1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-06-28 03:59:15 +02:00

Added support for Qt6

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

View File

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

View File

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

View File

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

View File

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

View File

@ -97,13 +97,13 @@ private:
#ifndef QT_NO_DEBUG
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();
}
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();
}
#endif // QT_NO_DEBUG

View File

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

View File

@ -5,25 +5,62 @@
#define MAX_TEXT_ANGLE 30
static bool intersection(const QLineF &line, const QRectF &rect,
QPointF *p)
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
#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)
return true;
if (line.intersect(QLineF(rect.topLeft(), rect.bottomLeft()), p)
if (line.INTERSECTS(QLineF(rect.topLeft(), rect.bottomLeft()), p)
== QLineF::BoundedIntersection)
return true;
if (line.intersect(QLineF(rect.bottomRight(), rect.bottomLeft()), p)
if (line.INTERSECTS(QLineF(rect.bottomRight(), rect.bottomLeft()), p)
== QLineF::BoundedIntersection)
return true;
if (line.intersect(QLineF(rect.bottomRight(), rect.topRight()), p)
if (line.INTERSECTS(QLineF(rect.bottomRight(), rect.topRight()), p)
== QLineF::BoundedIntersection)
return true;
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,
qreal cut)
{
@ -64,8 +101,8 @@ static QList<QLineF> lineString(const QPolygonF &path,
const QRectF &boundingRect)
{
QList<QLineF> lines;
int start = 0, end = path.count() - 1;
QPointF p;
int start = -1, end = -1;
for (int i = 0; i < path.count(); i++) {
if (boundingRect.contains(path.at(i))) {
@ -80,22 +117,37 @@ static QList<QLineF> lineString(const QPolygonF &path,
}
}
if (start > 0) {
QLineF l(path.at(start-1), path.at(start));
if (intersection(l, boundingRect, &p))
lines.append(QLineF(p, path.at(start)));
}
for (int i = start + 1; i <= end; i++)
lines.append(QLineF(path.at(i-1), path.at(i)));
if (end < path.count() - 1) {
QLineF l(path.at(end), path.at(end+1));
if (intersection(l, boundingRect, &p))
lines.append(QLineF(path.at(end), p));
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) {
QLineF l(path.at(start-1), path.at(start));
if (intersection(l, boundingRect, &p))
lines.append(QLineF(p, path.at(start)));
}
for (int i = start + 1; i <= end; i++)
lines.append(QLineF(path.at(i-1), path.at(i)));
if (end < path.count() - 1) {
QLineF l(path.at(end), path.at(end+1));
if (intersection(l, boundingRect, &p))
lines.append(QLineF(path.at(end), p));
}
}
return lines;
}
static QPainterPath textPath(const QPolygonF &path, qreal textWidth,
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)
: TextItem(label), _font(font), _color(color)
{
qreal cw = font->pixelSize() * 0.7;
qreal cw = font->pixelSize() * 0.6;
qreal textWidth = _text->size() * cw;
qreal mw = font->pixelSize() / 2;
_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
{
QFontMetrics fm(*_font);
int textWidth = fm.width(*_text);
int textWidth = fm.boundingRect(*_text).width();
qreal factor = (textWidth) / qMax(_path.length(), (qreal)textWidth);
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->setTransform(t);
int width = fm.charWidth(*_text, i);
int width = fm.horizontalAdvance(_text->at(i));
percent += ((qreal)width / (qreal)textWidth) * factor;
}
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->setTransform(t);
int width = fm.charWidth(*_text, i);
int width = fm.horizontalAdvance(_text->at(i));
percent += ((qreal)width / (qreal)textWidth) * factor;
}

View File

@ -87,14 +87,8 @@ void TextPointItem::paint(QPainter *painter) const
painter->setPen(*_color);
painter->drawText(_textRect, FLAGS, *_text);
} else {
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
img.invertPixels();
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()
{
qSort(_maps.begin(), _maps.end(), resCmp);
std::sort(_maps.begin(), _maps.end(), resCmp);
_zooms.append(Zoom(0, _maps.count() - 1));
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++)
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);
for (int i = 1; i < m.size(); i++) {
qreal w = m.first()->pp2xy(TL(m.at(i))).x();
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);
for (int i = 1; i < m.size(); i++) {
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()
{
QFile file(_fileName);
QFile file(path());
char bits;
if (!file.open(QIODevice::ReadOnly))
@ -391,8 +391,7 @@ QImage BSBMap::readImage()
}
BSBMap::BSBMap(const QString &fileName, QObject *parent)
: Map(fileName, parent), _fileName(fileName), _img(0), _ratio(1.0),
_dataOffset(-1), _valid(false)
: Map(fileName, parent), _img(0), _ratio(1.0), _dataOffset(-1), _valid(false)
{
QFile file(fileName);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,4 @@
#include <QPainter>
#include "common/config.h"
#include "image.h"
@ -7,11 +6,7 @@
void Image::draw(QPainter *painter, const QRectF &rect, Map::Flags flags)
{
#ifdef ENABLE_HIDPI
qreal ratio = _img.devicePixelRatioF();
#else // ENABLE_HIDPI
qreal ratio = 1.0;
#endif // ENABLE_HIDPI
QRectF sr(rect.topLeft() * ratio, rect.size() * ratio);
/* 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));
QPixmap *pm = new QPixmap(QPixmap::fromImage(_img.copy(tile)));
list.append(pm);
#ifdef ENABLE_HIDPI
pm->setDevicePixelRatio(ratio);
#endif // ENABLE_HIDPI
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)
{
#ifdef ENABLE_HIDPI
_img.setDevicePixelRatio(ratio);
#else // ENABLE_HIDPI
Q_UNUSED(ratio);
#endif // ENABLE_HIDPI
}

View File

@ -1,11 +1,7 @@
#include <QFile>
#include <QPainter>
#include <QPixmapCache>
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#include <QtCore>
#else // QT_VERSION < 5
#include <QtConcurrent>
#endif // QT_VERSION < 5
#include "common/rectc.h"
#include "common/range.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);
QString key = _data.at(n)->fileName() + "-" + QString::number(_zoom)
+ "_" + QString::number(ttl.x()) + "_" + QString::number(ttl.y());
if (QPixmapCache::find(key, pm))
if (QPixmapCache::find(key, &pm))
painter->drawPixmap(ttl, pm);
else {
QList<MapData::Poly> polygons, lines;

View File

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

View File

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

View File

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

View File

@ -121,11 +121,11 @@ void Matrix::zeroize()
#ifndef QT_NO_DEBUG
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 j = 0; j < matrix.w(); j++)
dbg << "\t" << matrix.m(i, j);
dbg << endl;
dbg << "\n";
}
dbg << ")";

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,11 +3,7 @@
#include <QEventLoop>
#include <QPixmapCache>
#include <QImageReader>
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#include <QtCore>
#else // QT_VERSION < 5
#include <QtConcurrent>
#endif // QT_VERSION < 5
#include "tileloader.h"
@ -77,7 +73,7 @@ void TileLoader::loadTilesAsync(QVector<Tile> &list)
Tile &t = list[i];
QString file(tileFile(t));
if (QPixmapCache::find(file, t.pixmap()))
if (QPixmapCache::find(file, &t.pixmap()))
continue;
QFileInfo fi(file);
@ -116,7 +112,7 @@ void TileLoader::loadTilesSync(QVector<Tile> &list)
Tile &t = list[i];
QString file(tileFile(t));
if (QPixmapCache::find(file, t.pixmap()))
if (QPixmapCache::find(file, &t.pixmap()))
continue;
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)
{
while (reader.readNextStartElement()) {
if (reader.name() == "OnlineResource") {
if (reader.name() == QLatin1String("OnlineResource")) {
QXmlStreamAttributes attr = reader.attributes();
ctx.url = attr.value("xlink:href").toString();
reader.skipCurrentElement();
@ -53,7 +53,7 @@ void WMS::get(QXmlStreamReader &reader, CTX &ctx)
void WMS::http(QXmlStreamReader &reader, CTX &ctx)
{
while (reader.readNextStartElement()) {
if (reader.name() == "Get")
if (reader.name() == QLatin1String("Get"))
get(reader, ctx);
else
reader.skipCurrentElement();
@ -63,7 +63,7 @@ void WMS::http(QXmlStreamReader &reader, CTX &ctx)
void WMS::dcpType(QXmlStreamReader &reader, CTX &ctx)
{
while (reader.readNextStartElement()) {
if (reader.name() == "HTTP")
if (reader.name() == QLatin1String("HTTP"))
http(reader, ctx);
else
reader.skipCurrentElement();
@ -73,11 +73,11 @@ void WMS::dcpType(QXmlStreamReader &reader, CTX &ctx)
void WMS::getMap(QXmlStreamReader &reader, CTX &ctx)
{
while (reader.readNextStartElement()) {
if (reader.name() == "Format") {
if (reader.name() == QLatin1String("Format")) {
QString format(reader.readElementText());
if (bareFormat(format) == bareFormat(ctx.setup.format()))
ctx.formatSupported = true;
} else if (reader.name() == "DCPType")
} else if (reader.name() == QLatin1String("DCPType"))
dcpType(reader, ctx);
else
reader.skipCurrentElement();
@ -87,7 +87,7 @@ void WMS::getMap(QXmlStreamReader &reader, CTX &ctx)
void WMS::request(QXmlStreamReader &reader, CTX &ctx)
{
while (reader.readNextStartElement()) {
if (reader.name() == "GetMap")
if (reader.name() == QLatin1String("GetMap"))
getMap(reader, ctx);
else
reader.skipCurrentElement();
@ -99,7 +99,7 @@ QString WMS::style(QXmlStreamReader &reader)
QString name;
while (reader.readNextStartElement()) {
if (reader.name() == "Name")
if (reader.name() == QLatin1String("Name"))
name = reader.readElementText();
else
reader.skipCurrentElement();
@ -113,13 +113,13 @@ RectC WMS::geographicBoundingBox(QXmlStreamReader &reader)
double left = NAN, top = NAN, right = NAN, bottom = NAN;
while (reader.readNextStartElement()) {
if (reader.name() == "westBoundLongitude")
if (reader.name() == QLatin1String("westBoundLongitude"))
left = reader.readElementText().toDouble();
else if (reader.name() == "eastBoundLongitude")
else if (reader.name() == QLatin1String("eastBoundLongitude"))
right = reader.readElementText().toDouble();
else if (reader.name() == "northBoundLatitude")
else if (reader.name() == QLatin1String("northBoundLatitude"))
top = reader.readElementText().toDouble();
else if (reader.name() == "southBoundLatitude")
else if (reader.name() == QLatin1String("southBoundLatitude"))
bottom = reader.readElementText().toDouble();
else
reader.skipCurrentElement();
@ -140,13 +140,14 @@ void WMS::layer(QXmlStreamReader &reader, CTX &ctx,
int index;
while (reader.readNextStartElement()) {
if (reader.name() == "Name")
if (reader.name() == QLatin1String("Name"))
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());
else if (reader.name() == "Style")
else if (reader.name() == QLatin1String("Style"))
styles.append(style(reader));
else if (reader.name() == "ScaleHint") {
else if (reader.name() == QLatin1String("ScaleHint")) {
QXmlStreamAttributes attr = reader.attributes();
double minHint = attr.value("min").toString().toDouble();
double maxHint = attr.value("max").toString().toDouble();
@ -155,15 +156,15 @@ void WMS::layer(QXmlStreamReader &reader, CTX &ctx,
if (maxHint > 0)
scaleDenominator.setMax(hint2denominator(maxHint));
reader.skipCurrentElement();
} else if (reader.name() == "MinScaleDenominator") {
} else if (reader.name() == QLatin1String("MinScaleDenominator")) {
double sd = reader.readElementText().toDouble();
if (sd > 0)
scaleDenominator.setMin(sd);
} else if (reader.name() == "MaxScaleDenominator") {
} else if (reader.name() == QLatin1String("MaxScaleDenominator")) {
double sd = reader.readElementText().toDouble();
if (sd > 0)
scaleDenominator.setMax(sd);
} else if (reader.name() == "LatLonBoundingBox") {
} else if (reader.name() == QLatin1String("LatLonBoundingBox")) {
QXmlStreamAttributes attr = reader.attributes();
boundingBox = RectC(Coordinates(
attr.value("minx").toString().toDouble(),
@ -171,9 +172,9 @@ void WMS::layer(QXmlStreamReader &reader, CTX &ctx,
Coordinates(attr.value("maxx").toString().toDouble(),
attr.value("miny").toString().toDouble()));
reader.skipCurrentElement();
} else if (reader.name() == "EX_GeographicBoundingBox")
} else if (reader.name() == QLatin1String("EX_GeographicBoundingBox"))
boundingBox = geographicBoundingBox(reader);
else if (reader.name() == "Layer")
else if (reader.name() == QLatin1String("Layer"))
layer(reader, ctx, CRSs, styles, scaleDenominator, boundingBox);
else
reader.skipCurrentElement();
@ -197,9 +198,9 @@ void WMS::capability(QXmlStreamReader &reader, CTX &ctx)
RectC boundingBox;
while (reader.readNextStartElement()) {
if (reader.name() == "Layer")
if (reader.name() == QLatin1String("Layer"))
layer(reader, ctx, CRSs, styles, scaleDenominator, boundingBox);
else if (reader.name() == "Request")
else if (reader.name() == QLatin1String("Request"))
request(reader, ctx);
else
reader.skipCurrentElement();
@ -211,7 +212,7 @@ void WMS::capabilities(QXmlStreamReader &reader, CTX &ctx)
_version = reader.attributes().value("version").toString();
while (reader.readNextStartElement()) {
if (reader.name() == "Capability")
if (reader.name() == QLatin1String("Capability"))
capability(reader, ctx);
else
reader.skipCurrentElement();
@ -237,8 +238,8 @@ bool WMS::parseCapabilities()
reader.setDevice(&file);
if (reader.readNextStartElement()) {
if (reader.name() == "WMS_Capabilities"
|| reader.name() == "WMT_MS_Capabilities")
if (reader.name() == QLatin1String("WMS_Capabilities")
|| reader.name() == QLatin1String("WMT_MS_Capabilities"))
capabilities(reader, ctx);
else
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];
QPointF tp(t.xy().x() * tileSize(), t.xy().y() * tileSize());
if (!t.pixmap().isNull()) {
#ifdef ENABLE_HIDPI
t.pixmap().setDevicePixelRatio(_mapRatio);
#endif // ENABLE_HIDPI
painter->drawPixmap(tp, t.pixmap());
}
}

View File

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