1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-06-28 12:09: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
}
}
}