mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-06-26 19:19:16 +02: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:
@ -1,6 +1,7 @@
|
||||
#include <QTextCodec>
|
||||
#include "textcodec.h"
|
||||
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
|
||||
|
||||
static QTextCodec *codec(int mib)
|
||||
{
|
||||
QTextCodec *c = QTextCodec::codecForMib(mib);
|
||||
@ -10,6 +11,10 @@ static QTextCodec *codec(int mib)
|
||||
return c;
|
||||
}
|
||||
|
||||
TextCodec::TextCodec() : _codec(0)
|
||||
{
|
||||
}
|
||||
|
||||
TextCodec::TextCodec(int 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);
|
||||
}
|
||||
|
||||
#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
|
||||
|
@ -3,19 +3,26 @@
|
||||
|
||||
#include <QString>
|
||||
#include <QMap>
|
||||
|
||||
class QTextCodec;
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
|
||||
#include <QTextCodec>
|
||||
#else // QT 6.5
|
||||
#include <QStringDecoder>
|
||||
#endif // QT 6.5
|
||||
|
||||
class TextCodec
|
||||
{
|
||||
public:
|
||||
TextCodec() : _codec(0) {}
|
||||
TextCodec();
|
||||
TextCodec(int codepage);
|
||||
|
||||
QString toString(const QByteArray &ba) const;
|
||||
QString toString(const QByteArray &ba);
|
||||
|
||||
private:
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
|
||||
QTextCodec *_codec;
|
||||
#else // QT 6.5
|
||||
QStringDecoder _decoder;
|
||||
#endif // QT 6.5
|
||||
};
|
||||
|
||||
#endif // TEXTCODEC_H
|
||||
|
Reference in New Issue
Block a user