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

Drop Qt5Compat dependency

Use QStringConverter instead of QTextCodec on Qt > 6.5.
Qt6 builds now require Qt build with ICU support for the non-UTF encodings to
work!
This commit is contained in:
Martin Tůma 2024-01-18 10:04:38 +01:00
parent 9cacf1906e
commit 7f7de87e99
9 changed files with 73 additions and 36 deletions

View File

@ -18,8 +18,10 @@ QT += core \
svg \ svg \
serialport serialport
greaterThan(QT_MAJOR_VERSION, 5) { greaterThan(QT_MAJOR_VERSION, 5) {
QT += openglwidgets \ QT += openglwidgets
core5compat lessThan(QT_MINOR_VERSION, 5) {
QT += core5compat
}
} }
CONFIG += object_parallel_to_source CONFIG += object_parallel_to_source

View File

@ -1,6 +1,7 @@
#include <QTextCodec>
#include "textcodec.h" #include "textcodec.h"
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
static QTextCodec *codec(int mib) static QTextCodec *codec(int mib)
{ {
QTextCodec *c = QTextCodec::codecForMib(mib); QTextCodec *c = QTextCodec::codecForMib(mib);
@ -10,6 +11,10 @@ static QTextCodec *codec(int mib)
return c; return c;
} }
TextCodec::TextCodec() : _codec(0)
{
}
TextCodec::TextCodec(int codepage) TextCodec::TextCodec(int codepage)
{ {
switch (codepage) { switch (codepage) {
@ -64,7 +69,30 @@ TextCodec::TextCodec(int codepage)
} }
} }
QString TextCodec::toString(const QByteArray &ba) const QString TextCodec::toString(const QByteArray &ba)
{ {
return _codec ? _codec->toUnicode(ba) : QString::fromUtf8(ba); return _codec ? _codec->toUnicode(ba) : QString::fromUtf8(ba);
} }
#else // QT 6.5
TextCodec::TextCodec()
{
}
TextCodec::TextCodec(int codepage)
{
if (codepage != 65001) {
QByteArray cp(QByteArray("CP") + QByteArray::number(codepage));
_decoder = QStringDecoder(cp.constData());
if (!_decoder.isValid())
qWarning("%d: Unknown codepage, using UTF-8", codepage);
}
}
QString TextCodec::toString(const QByteArray &ba)
{
return _decoder.isValid() ? _decoder.decode(ba) : QString::fromUtf8(ba);
}
#endif // QT 6.5

View File

@ -3,19 +3,26 @@
#include <QString> #include <QString>
#include <QMap> #include <QMap>
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
class QTextCodec; #include <QTextCodec>
#else // QT 6.5
#include <QStringDecoder>
#endif // QT 6.5
class TextCodec class TextCodec
{ {
public: public:
TextCodec() : _codec(0) {} TextCodec();
TextCodec(int codepage); TextCodec(int codepage);
QString toString(const QByteArray &ba) const; QString toString(const QByteArray &ba);
private: private:
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
QTextCodec *_codec; QTextCodec *_codec;
#else // QT 6.5
QStringDecoder _decoder;
#endif // QT 6.5
}; };
#endif // TEXTCODEC_H #endif // TEXTCODEC_H

View File

@ -138,7 +138,7 @@ void LBLFile::clear()
} }
Label LBLFile::str2label(const QVector<quint8> &str, bool capitalize, Label LBLFile::str2label(const QVector<quint8> &str, bool capitalize,
bool convert) const bool convert)
{ {
Shield::Type shieldType = Shield::None; Shield::Type shieldType = Shield::None;
QByteArray label, shieldLabel; QByteArray label, shieldLabel;
@ -247,7 +247,7 @@ Label LBLFile::label6b(const SubFile *file, Handle &fileHdl, quint32 size,
} }
Label LBLFile::label8b(const SubFile *file, Handle &fileHdl, quint32 size, Label LBLFile::label8b(const SubFile *file, Handle &fileHdl, quint32 size,
bool capitalize, bool convert) const bool capitalize, bool convert)
{ {
QVector<quint8> str; QVector<quint8> str;
quint8 c; quint8 c;
@ -264,7 +264,7 @@ Label LBLFile::label8b(const SubFile *file, Handle &fileHdl, quint32 size,
} }
Label LBLFile::labelHuffman(Handle &hdl, const SubFile *file, Handle &fileHdl, Label LBLFile::labelHuffman(Handle &hdl, const SubFile *file, Handle &fileHdl,
quint32 size, bool capitalize, bool convert) const quint32 size, bool capitalize, bool convert)
{ {
QVector<quint8> str; QVector<quint8> str;
@ -305,7 +305,7 @@ Label LBLFile::labelHuffman(Handle &hdl, const SubFile *file, Handle &fileHdl,
} }
Label LBLFile::label(Handle &hdl, quint32 offset, bool poi, bool capitalize, Label LBLFile::label(Handle &hdl, quint32 offset, bool poi, bool capitalize,
bool convert) const bool convert)
{ {
quint32 labelOffset; quint32 labelOffset;
if (poi) { if (poi) {
@ -328,7 +328,7 @@ Label LBLFile::label(Handle &hdl, quint32 offset, bool poi, bool capitalize,
} }
Label LBLFile::label(Handle &hdl, const SubFile *file, Handle &fileHdl, Label LBLFile::label(Handle &hdl, const SubFile *file, Handle &fileHdl,
quint32 size, bool capitalize, bool convert) const quint32 size, bool capitalize, bool convert)
{ {
switch (_encoding) { switch (_encoding) {
case 6: case 6:

View File

@ -30,9 +30,9 @@ public:
void clear(); void clear();
Label label(Handle &hdl, quint32 offset, bool poi = false, Label label(Handle &hdl, quint32 offset, bool poi = false,
bool capitalize = true, bool convert = false) const; bool capitalize = true, bool convert = false);
Label label(Handle &hdl, const SubFile *file, Handle &fileHdl, Label label(Handle &hdl, const SubFile *file, Handle &fileHdl,
quint32 size, bool capitalize = true, bool convert = false) const; quint32 size, bool capitalize = true, bool convert = false);
quint8 imageIdSize() const {return _imgIdSize;} quint8 imageIdSize() const {return _imgIdSize;}
QPixmap image(Handle &hdl, quint32 id) const; QPixmap image(Handle &hdl, quint32 id) const;
@ -44,13 +44,13 @@ private:
}; };
Label str2label(const QVector<quint8> &str, bool capitalize, Label str2label(const QVector<quint8> &str, bool capitalize,
bool convert) const; bool convert);
Label label6b(const SubFile *file, Handle &fileHdl, quint32 size, Label label6b(const SubFile *file, Handle &fileHdl, quint32 size,
bool capitalize, bool convert) const; bool capitalize, bool convert) const;
Label label8b(const SubFile *file, Handle &fileHdl, quint32 size, Label label8b(const SubFile *file, Handle &fileHdl, quint32 size,
bool capitalize, bool convert) const; bool capitalize, bool convert);
Label labelHuffman(Handle &hdl, const SubFile *file, Handle &fileHdl, Label labelHuffman(Handle &hdl, const SubFile *file, Handle &fileHdl,
quint32 size, bool capitalize, bool convert) const; quint32 size, bool capitalize, bool convert);
bool loadRasterTable(Handle &hdl, quint32 offset, quint32 size, bool loadRasterTable(Handle &hdl, quint32 offset, quint32 size,
quint32 recordSize); quint32 recordSize);

View File

@ -329,7 +329,7 @@ bool NETFile::readShape(const NODFile *nod, SubFile::Handle &nodHdl,
} }
bool NETFile::linkLabel(Handle &hdl, quint32 offset, bool NETFile::linkLabel(Handle &hdl, quint32 offset,
const LBLFile *lbl, Handle &lblHdl, Label &label) const LBLFile *lbl, Handle &lblHdl, Label &label) const
{ {
if (!seek(hdl, offset)) if (!seek(hdl, offset))
return false; return false;
@ -392,7 +392,7 @@ NETFile::~NETFile()
} }
bool NETFile::link(const SubDiv *subdiv, quint32 shift, Handle &hdl, bool NETFile::link(const SubDiv *subdiv, quint32 shift, Handle &hdl,
const NODFile *nod, Handle &nodHdl2, Handle &nodHdl, const LBLFile *lbl, const NODFile *nod, Handle &nodHdl2, Handle &nodHdl, LBLFile *lbl,
Handle &lblHdl, const NODFile::BlockInfo &blockInfo, quint8 linkId, Handle &lblHdl, const NODFile::BlockInfo &blockInfo, quint8 linkId,
quint8 lineId, QList<MapData::Poly> *lines) const quint8 lineId, QList<MapData::Poly> *lines) const
{ {

View File

@ -30,13 +30,13 @@ public:
bool lblOffset(Handle &hdl, quint32 netOffset, quint32 &lblOffset) const; bool lblOffset(Handle &hdl, quint32 netOffset, quint32 &lblOffset) const;
bool link(const SubDiv *subdiv, quint32 shift, Handle &hdl, bool link(const SubDiv *subdiv, quint32 shift, Handle &hdl,
const NODFile *nod, Handle &nodHdl2, Handle &nodHdl, const LBLFile *lbl, const NODFile *nod, Handle &nodHdl2, Handle &nodHdl, LBLFile *lbl,
Handle &lblHdl, const NODFile::BlockInfo &blockInfo, quint8 linkId, Handle &lblHdl, const NODFile::BlockInfo &blockInfo, quint8 linkId,
quint8 lineId, QList<MapData::Poly> *lines) const; quint8 lineId, QList<MapData::Poly> *lines) const;
bool hasLinks() const {return (_links.size > 0);} bool hasLinks() const {return (_links.size > 0);}
private: private:
bool linkLabel(Handle &hdl, quint32 offset, const LBLFile *lbl, bool linkLabel(Handle &hdl, quint32 offset, LBLFile *lbl,
Handle &lblHdl, Label &label) const; Handle &lblHdl, Label &label) const;
bool readShape(const NODFile *nod, SubFile::Handle &nodHdl, bool readShape(const NODFile *nod, SubFile::Handle &nodHdl,
NODFile::AdjacencyInfo &adj, BitStream4R &bs, const SubDiv *subdiv, NODFile::AdjacencyInfo &adj, BitStream4R &bs, const SubDiv *subdiv,

View File

@ -107,7 +107,7 @@ bool RGNFile::readObstructionInfo(Handle &hdl, quint8 flags, quint32 size,
return true; return true;
} }
bool RGNFile::readLabel(Handle &hdl, const LBLFile *lbl, Handle &lblHdl, bool RGNFile::readLabel(Handle &hdl, LBLFile *lbl, Handle &lblHdl,
quint8 flags, quint32 size, MapData::Point *point) const quint8 flags, quint32 size, MapData::Point *point) const
{ {
if (!(flags & 1)) if (!(flags & 1))
@ -122,7 +122,7 @@ bool RGNFile::readLabel(Handle &hdl, const LBLFile *lbl, Handle &lblHdl,
} }
bool RGNFile::readClassFields(Handle &hdl, SegmentType segmentType, bool RGNFile::readClassFields(Handle &hdl, SegmentType segmentType,
void *object, const LBLFile *lbl, Handle &lblHdl) const void *object, LBLFile *lbl, Handle &lblHdl) const
{ {
quint8 flags; quint8 flags;
quint32 rs = 0; quint32 rs = 0;
@ -257,7 +257,7 @@ void RGNFile::clear()
} }
bool RGNFile::polyObjects(Handle &hdl, const SubDiv *subdiv, bool RGNFile::polyObjects(Handle &hdl, const SubDiv *subdiv,
SegmentType segmentType, const LBLFile *lbl, Handle &lblHdl, NETFile *net, SegmentType segmentType, LBLFile *lbl, Handle &lblHdl, NETFile *net,
Handle &netHdl, QList<MapData::Poly> *polys) const Handle &netHdl, QList<MapData::Poly> *polys) const
{ {
const SubDiv::Segment &segment = (segmentType == Line) const SubDiv::Segment &segment = (segmentType == Line)
@ -340,7 +340,7 @@ bool RGNFile::polyObjects(Handle &hdl, const SubDiv *subdiv,
} }
bool RGNFile::extPolyObjects(Handle &hdl, const SubDiv *subdiv, quint32 shift, bool RGNFile::extPolyObjects(Handle &hdl, const SubDiv *subdiv, quint32 shift,
SegmentType segmentType, const LBLFile *lbl, Handle &lblHdl, SegmentType segmentType, LBLFile *lbl, Handle &lblHdl,
QList<MapData::Poly> *polys) const QList<MapData::Poly> *polys) const
{ {
quint32 labelPtr, len; quint32 labelPtr, len;
@ -457,7 +457,7 @@ bool RGNFile::extPolyObjects(Handle &hdl, const SubDiv *subdiv, quint32 shift,
} }
bool RGNFile::pointObjects(Handle &hdl, const SubDiv *subdiv, bool RGNFile::pointObjects(Handle &hdl, const SubDiv *subdiv,
SegmentType segmentType, const LBLFile *lbl, Handle &lblHdl, SegmentType segmentType, LBLFile *lbl, Handle &lblHdl,
QList<MapData::Point> *points) const QList<MapData::Point> *points) const
{ {
const SubDiv::Segment &segment = (segmentType == IndexedPoint) const SubDiv::Segment &segment = (segmentType == IndexedPoint)
@ -502,7 +502,7 @@ bool RGNFile::pointObjects(Handle &hdl, const SubDiv *subdiv,
} }
bool RGNFile::extPointObjects(Handle &hdl, const SubDiv *subdiv, bool RGNFile::extPointObjects(Handle &hdl, const SubDiv *subdiv,
const LBLFile *lbl, Handle &lblHdl, QList<MapData::Point> *points) const LBLFile *lbl, Handle &lblHdl, QList<MapData::Point> *points) const
{ {
const SubDiv::Segment &segment = subdiv->extPoints(); const SubDiv::Segment &segment = subdiv->extPoints();
@ -554,7 +554,7 @@ bool RGNFile::extPointObjects(Handle &hdl, const SubDiv *subdiv,
bool RGNFile::links(Handle &hdl, const SubDiv *subdiv, quint32 shift, bool RGNFile::links(Handle &hdl, const SubDiv *subdiv, quint32 shift,
const NETFile *net, Handle &netHdl, const NODFile *nod, Handle &nodHdl, const NETFile *net, Handle &netHdl, const NODFile *nod, Handle &nodHdl,
Handle &nodHdl2, const LBLFile *lbl, Handle &lblHdl, Handle &nodHdl2, LBLFile *lbl, Handle &lblHdl,
QList<MapData::Poly> *lines) const QList<MapData::Poly> *lines) const
{ {
quint32 size, blockIndexId; quint32 size, blockIndexId;

View File

@ -33,18 +33,18 @@ public:
bool load(Handle &hdl); bool load(Handle &hdl);
bool polyObjects(Handle &hdl, const SubDiv *subdiv, SegmentType segmentType, bool polyObjects(Handle &hdl, const SubDiv *subdiv, SegmentType segmentType,
const LBLFile *lbl, Handle &lblHdl, NETFile *net, Handle &netHdl, LBLFile *lbl, Handle &lblHdl, NETFile *net, Handle &netHdl,
QList<MapData::Poly> *polys) const; QList<MapData::Poly> *polys) const;
bool pointObjects(Handle &hdl, const SubDiv *subdiv, SegmentType segmentType, bool pointObjects(Handle &hdl, const SubDiv *subdiv, SegmentType segmentType,
const LBLFile *lbl, Handle &lblHdl, QList<MapData::Point> *points) const; LBLFile *lbl, Handle &lblHdl, QList<MapData::Point> *points) const;
bool extPolyObjects(Handle &hdl, const SubDiv *subdiv, quint32 shift, bool extPolyObjects(Handle &hdl, const SubDiv *subdiv, quint32 shift,
SegmentType segmentType, const LBLFile *lbl, Handle &lblHdl, SegmentType segmentType, LBLFile *lbl, Handle &lblHdl,
QList<MapData::Poly> *polys) const; QList<MapData::Poly> *polys) const;
bool extPointObjects(Handle &hdl, const SubDiv *subdiv, const LBLFile *lbl, bool extPointObjects(Handle &hdl, const SubDiv *subdiv, LBLFile *lbl,
Handle &lblHdl, QList<MapData::Point> *points) const; Handle &lblHdl, QList<MapData::Point> *points) const;
bool links(Handle &hdl, const SubDiv *subdiv, quint32 shift, bool links(Handle &hdl, const SubDiv *subdiv, quint32 shift,
const NETFile *net, Handle &netHdl, const NODFile *nod, Handle &nodHdl, const NETFile *net, Handle &netHdl, const NODFile *nod, Handle &nodHdl,
Handle &nodHdl2, const LBLFile *lbl, Handle &lblHdl, Handle &nodHdl2, LBLFile *lbl, Handle &lblHdl,
QList<MapData::Poly> *lines) const; QList<MapData::Poly> *lines) const;
bool subdivInit(Handle &hdl, SubDiv *subdiv) const; bool subdivInit(Handle &hdl, SubDiv *subdiv) const;
@ -55,7 +55,7 @@ public:
private: private:
bool segments(Handle &hdl, SubDiv *subdiv, SubDiv::Segment seg[5]) const; bool segments(Handle &hdl, SubDiv *subdiv, SubDiv::Segment seg[5]) const;
bool readClassFields(Handle &hdl, SegmentType segmentType, void *object, bool readClassFields(Handle &hdl, SegmentType segmentType, void *object,
const LBLFile *lbl, Handle &lblHdl) const; LBLFile *lbl, Handle &lblHdl) const;
bool skipLclFields(Handle &hdl, const quint32 flags[3]) const; bool skipLclFields(Handle &hdl, const quint32 flags[3]) const;
bool skipGblFields(Handle &hdl, quint32 flags) const; bool skipGblFields(Handle &hdl, quint32 flags) const;
bool readRasterInfo(Handle &hdl, const LBLFile *lbl, quint32 size, bool readRasterInfo(Handle &hdl, const LBLFile *lbl, quint32 size,
@ -64,7 +64,7 @@ private:
MapData::Point *point) const; MapData::Point *point) const;
bool readObstructionInfo(Handle &hdl, quint8 flags, quint32 size, bool readObstructionInfo(Handle &hdl, quint8 flags, quint32 size,
MapData::Point *point) const; MapData::Point *point) const;
bool readLabel(Handle &hdl, const LBLFile *lbl, Handle &lblHdl, bool readLabel(Handle &hdl, LBLFile *lbl, Handle &lblHdl,
quint8 flags, quint32 size, MapData::Point *point) const; quint8 flags, quint32 size, MapData::Point *point) const;
HuffmanTable *_huffmanTable; HuffmanTable *_huffmanTable;