Use QStringConverter to replace QTextCodec.

This commit is contained in:
Roman Telezhynskyi 2023-02-11 16:14:15 +02:00
parent f5f4b1e4c8
commit 787cfcfc16
24 changed files with 578 additions and 148 deletions

View File

@ -33,7 +33,10 @@
#include "../vformat/vdimensions.h"
class QxtCsvModel;
class QTextCodec;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
class VTextCodec;
#endif
enum class IndividualMeasurementsColumns: qint8
{
@ -75,7 +78,7 @@ public:
void SetWithHeader(bool withHeader);
void SetSeparator(const QChar &separator);
void SetCodec(QTextCodec *codec);
void SetCodec(VTextCodec *codec);
protected:
void changeEvent(QEvent* event) override;
@ -92,7 +95,7 @@ private:
QString m_fileName;
bool m_withHeader{false};
QChar m_separator{','};
QTextCodec *m_codec{nullptr};
VTextCodec *m_codec{nullptr};
QVector<int> m_columnsMap{};
MeasurementsType m_type;
QList<MeasurementDimension_p> m_dimensions{};
@ -150,7 +153,7 @@ inline void DialogMeasurementsCSVColumns::SetSeparator(const QChar &separator)
}
//---------------------------------------------------------------------------------------------------------------------
inline void DialogMeasurementsCSVColumns::SetCodec(QTextCodec *codec)
inline void DialogMeasurementsCSVColumns::SetCodec(VTextCodec *codec)
{
m_codec = codec;
}

View File

@ -59,6 +59,12 @@
#include "../vmisc/dialogs/dialogselectlanguage.h"
#include "mapplication.h" // Should be last because of definning qApp
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include "../vmisc/vtextcodec.h"
#else
#include <QTextCodec>
#endif
#if QT_VERSION < QT_VERSION_CHECK(5, 12, 0)
#include "../vmisc/backport/qscopeguard.h"
#else
@ -71,7 +77,6 @@
#include <QComboBox>
#include <QProcess>
#include <QtNumeric>
#include <QTextCodec>
#include <QTimer>
#include <chrono>
@ -849,7 +854,7 @@ void TMainWindow::ExportToCSVData(const QString &fileName, bool withHeader, int
}
QString error;
csv.toCSV(fileName, error, withHeader, separator, QTextCodec::codecForMib(mib));
csv.toCSV(fileName, error, withHeader, separator, VTextCodec::codecForMib(mib));
}
//---------------------------------------------------------------------------------------------------------------------
@ -1102,12 +1107,12 @@ void TMainWindow::ImportDataFromCSV()
}
columns->SetWithHeader(dialog.IsWithHeader());
columns->SetSeparator(dialog.GetSeparator());
columns->SetCodec(QTextCodec::codecForMib(dialog.GetSelectedMib()));
columns->SetCodec(VTextCodec::codecForMib(dialog.GetSelectedMib()));
if (columns->exec() == QDialog::Accepted)
{
QxtCsvModel csv(fileName, nullptr, dialog.IsWithHeader(), dialog.GetSeparator(),
QTextCodec::codecForMib(dialog.GetSelectedMib()));
VTextCodec::codecForMib(dialog.GetSelectedMib()));
const QVector<int> map = columns->ColumnsMap();
if (m_m->Type() == MeasurementsType::Individual)

View File

@ -36,7 +36,12 @@
#include "../vmisc/dialogs/dialogexporttocsv.h"
#include "../vlayout/vlayoutgenerator.h"
#include <QDebug>
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include "../vmisc/vtextcodec.h"
#else
#include <QTextCodec>
#endif
VCommandLinePtr VCommandLine::instance = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
@ -736,7 +741,7 @@ void VCommandLine::InitCommandLineOptions()
"Qt. Default value depend from system. On Windows, the codec will be based on a system locale. On Unix "
"systems, the codec will might fall back to using the iconv library if no builtin codec for the locale can be "
"found. Valid values for this installation:") + DialogExportToCSV::MakeHelpCodecsList(),
translate("VCommandLine", "Codec name"), QString(QTextCodec::codecForLocale()->name())},
translate("VCommandLine", "Codec name"), QString(VTextCodec::codecForLocale()->name())},
{LONG_OPTION_CSVSEPARATOR,
translate("VCommandLine", "Specify csv separator character. Default value is '%1'. Valid characters:")
.arg(VCommonSettings::GetDefCSVSeparator()) + DialogExportToCSV::MakeHelpSeparatorList(),

View File

@ -49,11 +49,16 @@
#include "../ifc/xml/vvitconverter.h"
#include "../vwidgets/vwidgetpopup.h"
#include "../vwidgets/vmaingraphicsscene.h"
#include "../vtools/undocommands/undogroup.h"
#include "../vformat/vpatternrecipe.h"
#include "../vlayout/dialogs/watermarkwindow.h"
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include "../vmisc/vtextcodec.h"
#else
#include <QTextCodec>
#endif
#if QT_VERSION < QT_VERSION_CHECK(5, 7, 0)
#include "../vmisc/backport/qoverload.h"
#endif // QT_VERSION < QT_VERSION_CHECK(5, 7, 0)
@ -201,7 +206,6 @@
#include <thread>
#include <QFileSystemWatcher>
#include <QComboBox>
#include <QTextCodec>
#include <QDoubleSpinBox>
#include <QProgressBar>
#include <QGlobalStatic>
@ -1924,7 +1928,7 @@ void MainWindow::ExportToCSVData(const QString &fileName, bool withHeader, int m
SavePreviewCalculation(true);
QString error;
csv.toCSV(fileName, error, withHeader, separator, QTextCodec::codecForMib(mib));
csv.toCSV(fileName, error, withHeader, separator, VTextCodec::codecForMib(mib));
}
//---------------------------------------------------------------------------------------------------------------------
@ -6735,10 +6739,10 @@ auto MainWindow::DoFMExport(const VCommandLinePtr &expParams) -> bool
}
const QString codecName = expParams->OptCSVCodecName();
int mib = QTextCodec::codecForLocale()->mibEnum();
int mib = VTextCodec::codecForLocale()->mibEnum();
if (not codecName.isEmpty())
{
if (QTextCodec *codec = QTextCodec::codecForName(codecName.toLatin1()))
if (VTextCodec *codec = VTextCodec::codecForName(codecName.toLatin1()))
{
mib = codec->mibEnum();
}

View File

@ -48,6 +48,12 @@
#include "../vmisc/vvalentinasettings.h"
#include "../vdxf/libdxfrw/drw_base.h"
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include "../vmisc/vtextcodec.h"
#else
#include <QTextCodec>
#endif
#include <QFileDialog>
#include <QFileInfo>
#include <QGraphicsScene>
@ -62,7 +68,6 @@
#include <functional>
#include <QPageSize>
#include <QDebug>
#include <QTextCodec>
#if defined(Q_OS_WIN32) && QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
#include <QWinTaskbarButton>
@ -1308,7 +1313,7 @@ bool MainWindowsNoGUI::ExportFMeasurementsToCSVData(const QString &fileName, boo
}
QString error;
const bool success = csv.toCSV(fileName, error, withHeader, separator, QTextCodec::codecForMib(mib));
const bool success = csv.toCSV(fileName, error, withHeader, separator, VTextCodec::codecForMib(mib));
if (not success)
{

View File

@ -791,7 +791,9 @@ bool VDomDocument::SaveDocument(const QString &fileName, QString &error)
}
// Left these strings in case we will need them for testing purposes
// QTextStream out(&file);
//#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
// out.setCodec("UTF-8");
//#endif
// save(out, indent);
success = file.commit();

View File

@ -372,6 +372,7 @@ bool SupportedLocale(const QLocale &locale)
locale.decimalPoint().size() == 1 &&
locale.groupSeparator().size() == 1;
#else
Q_UNUSED(locale)
return true;
#endif
}
@ -417,7 +418,11 @@ QChar LocaleSign0(const QLocale &locale)
return sign.front();
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return {'0'};
#else
return QChar('0');
#endif
}
//---------------------------------------------------------------------------------------------------------------------
@ -429,7 +434,11 @@ QChar LocaleSign1(const QLocale &locale)
return sign.front();
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return {'1'};
#else
return QChar('1');
#endif
}
//---------------------------------------------------------------------------------------------------------------------
@ -441,7 +450,11 @@ QChar LocaleSign2(const QLocale &locale)
return sign.front();
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return {'2'};
#else
return QChar('2');
#endif
}
//---------------------------------------------------------------------------------------------------------------------
@ -453,7 +466,11 @@ QChar LocaleSign3(const QLocale &locale)
return sign.front();
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return {'3'};
#else
return QChar('3');
#endif
}
//---------------------------------------------------------------------------------------------------------------------
@ -465,7 +482,11 @@ QChar LocaleSign4(const QLocale &locale)
return sign.front();
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return {'4'};
#else
return QChar('4');
#endif
}
//---------------------------------------------------------------------------------------------------------------------
@ -477,7 +498,11 @@ QChar LocaleSign5(const QLocale &locale)
return sign.front();
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return {'5'};
#else
return QChar('5');
#endif
}
//---------------------------------------------------------------------------------------------------------------------
@ -489,7 +514,11 @@ QChar LocaleSign6(const QLocale &locale)
return sign.front();
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return {'6'};
#else
return QChar('6');
#endif
}
//---------------------------------------------------------------------------------------------------------------------
@ -501,7 +530,11 @@ QChar LocaleSign7(const QLocale &locale)
return sign.front();
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return {'7'};
#else
return QChar('7');
#endif
}
//---------------------------------------------------------------------------------------------------------------------
@ -513,7 +546,11 @@ QChar LocaleSign8(const QLocale &locale)
return sign.front();
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return {'8'};
#else
return QChar('8');
#endif
}
//---------------------------------------------------------------------------------------------------------------------
@ -525,7 +562,11 @@ QChar LocaleSign9(const QLocale &locale)
return sign.front();
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return {'9'};
#else
return QChar('9');
#endif
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -110,7 +110,6 @@ typedef float dfloat32; /* 32 bit floating point */
typedef double ddouble64; /* 64 bit floating point */
typedef long double ddouble80; /* 80 bit floating point */
namespace DRW {
//! Version numbers for the DXF Format.

View File

@ -4,46 +4,16 @@
#include <algorithm>
#include <cstring>
#include <QString>
#include <QTextCodec>
#include <QDebug>
#include "../drw_base.h"
#include "../vmisc/vabstractvalapplication.h"
#include "../ifc/exception/vexception.h"
namespace
{
QMap<QString, QStringList> QtCodecs()
{
return QMap<QString, QStringList>
{
{"ANSI_874", {"ANSI_874", "CP874", "windows-874", "MS874", "x-windows-874", "TIS-620", "IBM1162",
"x-IBM874"}}, // Latin/Thai
{"ANSI_932", {"ANSI_932", "CP932", "SHIFT-JIS", "SHIFT_JIS", "CSSHIFTJIS", "CSWINDOWS31J", "MS_KANJI",
"X-MS-CP932", "X-SJIS", "EUCJP", "EUC-JP", "CSEUCPKDFMTJAPANESE", "X-EUC", "X-EUC-JP", "IBM-943",
"JIS7"}}, // Japanese
{"ANSI_936", {"ANSI_936", "GBK", "CP936", "MS936", "Windows-936", "GB2312",
"CHINESE"}}, // Chinese PRC GBK (XGB) simplified
{"ANSI_949", {"ANSI_949", "Windows-949", "MS949", "CP949"}}, // Korean
{"ANSI_950", {"ANSI_950", "BIG5", "windows-950-2000", "csBig5", "windows-950", "x-windows-950", "x-big5",
"ms950"}}, // Chinese Big5 (Taiwan, Hong Kong SAR)
{"ANSI_1250", {"ANSI_1250", "CP1250", "windows-1250", "ibm-1250_P100-1995",
"ibm-1250"}}, //Central Europe and Eastern Europe
{"ANSI_1251", {"ANSI_1251", "CP1251", "windows-1251", "ANSI1251", "ibm-5347_P100-1998",
"ibm-5347"}}, // Cyrillic script
{"ANSI_1252", {"ANSI_1252", "CP1252", "windows-1252", "LATIN1", "ISO-8859-1", "CP819", "CSISO", "IBM819",
"ISO_8859-1", "APPLE ROMAN", "ISO8859-1", "ISO8859-15", "ISO-IR-100", "L1",
"IBM 850", "850"}}, // Western Europe
{"ANSI_1253", {"ANSI_1253", "CP1253", "windows-1253"}}, // Greek
{"ANSI_1254", {"ANSI_1254", "CP1254", "windows-1254"}}, // Turkish
{"ANSI_1255", {"ANSI_1255", "CP1255", "windows-1255"}}, // Hebrew
{"ANSI_1256", {"ANSI_1256", "CP1256", "windows-1256", "x-windows-1256S"}}, // Arabic
{"ANSI_1257", {"ANSI_1257", "CP1257", "windows-1257"}}, // Baltic
{"ANSI_1258", {"ANSI_1258", "CP1258", "windows-1258"}}, // Vietnamese
{"UTF-8", {"UTF-8", "UTF8", "UTF8-BIT"}},
{"UTF-16", {"UTF-16", "UTF16", "UTF16-BIT"}},
};
}
} // namespace
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include "../vmisc/vtextcodec.h"
#else
#include <QTextCodec>
#endif
DRW_TextCodec::DRW_TextCodec()
: version(DRW::AC1021)
@ -123,29 +93,22 @@ void DRW_TextCodec::setCodePage(const std::string &c, bool dxfFormat){
if (version < DRW::AC1021)
{
if (cp == "UTF-8")
{ //DXF older than 2007 are write in win codepages
{ // DXF older than 2007 are write in win codepages
cp = "ANSI_1252";
}
conv = DRW_TextCodec::CodecForName(QString::fromStdString(cp));
}
else
{
if (dxfFormat)
{
conv = DRW_TextCodec::CodecForName(QString::fromStdString("UTF-8"));
}
else
{
conv = DRW_TextCodec::CodecForName(QString::fromStdString("UTF-16"));
}
conv = DRW_TextCodec::CodecForName(dxfFormat ? QStringLiteral("UTF-8") : QStringLiteral("UTF-16"));
}
if (conv == nullptr)
{
const QString errorMsg = QCoreApplication::translate("DRW_TextCodec", "No available codec for code page '%1'.")
.arg(cp.c_str());
VAbstractApplication::VApp()->IsPedantic() ? throw VException(errorMsg) :
qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
VAbstractApplication::VApp()->IsPedantic()
? throw VException(errorMsg) : qWarning() << VAbstractValApplication::warningMessageSignature + errorMsg;
if (version < DRW::AC1021 && cp == "UTF-8")
{
@ -157,7 +120,7 @@ void DRW_TextCodec::setCodePage(const std::string &c, bool dxfFormat){
QMap<QString, QStringList> DRW_TextCodec::DXFCodePageMap()
{
return QMap<QString, QStringList>
static auto map = QMap<QString, QStringList>
{
{"ANSI_874", {"ANSI_874", "CP874", "ISO8859-11", "TIS-620"}}, // Latin/Thai
{"ANSI_932", {"ANSI_932", "SHIFT-JIS", "SHIFT_JIS", "CSSHIFTJIS", "CSWINDOWS31J", "MS_KANJI", "X-MS-CP932",
@ -170,8 +133,8 @@ QMap<QString, QStringList> DRW_TextCodec::DXFCodePageMap()
"BIG5-HKSCS"}}, // Chinese Big5 (Taiwan, Hong Kong SAR)
{"ANSI_1250", {"ANSI_1250", "CP1250", "ISO8859-2"}}, //Central Europe and Eastern Europe
{"ANSI_1251", {"ANSI_1251", "CP1251", "ISO8859-5", "KOI8-R", "KOI8-U", "IBM 866"}}, // Cyrillic script
{"ANSI_1252", {"ANSI_1252", "CP1252", "LATIN1", "ISO-8859-1", "CP819", "CSISO", "IBM819", "ISO_8859-1",
"APPLE ROMAN", "ISO8859-1", "ISO8859-15", "ISO-IR-100", "L1", "IBM 850"}}, // Western Europe
{"ANSI_1252", {"ANSI_1252", "CP1252", "LATIN1", "ISO-8859-1", "CP819", "CSISO", "IBM819", "L1",
"ISO_8859-1", "APPLE ROMAN", "ISO8859-1", "ISO8859-15", "ISO-IR-100", "IBM 850"}}, // Western Europe
{"ANSI_1253", {"ANSI_1253", "CP1253", "ISO8859-7"}}, // Greek
{"ANSI_1254", {"ANSI_1254", "CP1254", "ISO8859-9", "iso8859-3"}}, // Turkish
{"ANSI_1255", {"ANSI_1255", "CP1255", "ISO8859-8"}}, // Hebrew
@ -181,17 +144,19 @@ QMap<QString, QStringList> DRW_TextCodec::DXFCodePageMap()
{"UTF-8", {"UTF-8", "UTF8", "UTF8-BIT"}},
{"UTF-16", {"UTF-16", "UTF16", "UTF16-BIT"}},
};
return map;
}
QTextCodec *DRW_TextCodec::CodecForName(const QString &name)
VTextCodec *DRW_TextCodec::CodecForName(const QString &name)
{
QMap<QString, QStringList> knownCodecs = QtCodecs();
QMap<QString, QStringList> knownCodecs = DXFCodePageMap();
if (knownCodecs.contains(name))
{
QStringList aliases = knownCodecs.value(name);
for (auto &alias : aliases)
{
if (QTextCodec *codec = QTextCodec::codecForName(alias.toLatin1()))
if (VTextCodec *codec = VTextCodec::codecForName(alias.toLatin1()))
{
return codec;
}

View File

@ -4,9 +4,13 @@
#include <string>
#include <QtGlobal>
#include "../drw_base.h"
#include "../vmisc/defglobal.h"
class QTextCodec;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include "../vmisc/vtextcodec.h"
#else
#include "../vmisc/defglobal.h"
#include <QTextCodec>
#endif
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
class QStringList;
@ -27,7 +31,7 @@ public:
std::string getCodePage() const {return cp;}
static QMap<QString, QStringList> DXFCodePageMap();
static QTextCodec* CodecForName(const QString &name);
static VTextCodec* CodecForName(const QString &name);
private:
static auto correctCodePage(const std::string& s) -> std::string;
@ -37,7 +41,7 @@ private:
Q_DISABLE_COPY_MOVE(DRW_TextCodec) // NOLINT
DRW::Version version{DRW::UNKNOWNV};
std::string cp{};
QTextCodec *conv{nullptr};
VTextCodec *conv{nullptr};
};
#endif // DRW_TEXTCODEC_H

View File

@ -41,12 +41,17 @@
#include <QPainterPath>
#include <QPen>
#include <QPolygonF>
#include <QTextCodec>
#include <QTextItem>
#include <Qt>
#include <QtDebug>
#include <QtMath>
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include "../vmisc/vtextcodec.h"
#else
#include <QTextCodec>
#endif
#include "../vmisc/def.h"
#if QT_VERSION < QT_VERSION_CHECK(5, 5, 0)
#include "../vmisc/diagnostic.h"
@ -1251,7 +1256,7 @@ auto VDxfEngine::AAMAPoint(const QPointF &pos, const UTF8STRING &layer) const ->
}
//---------------------------------------------------------------------------------------------------------------------
auto VDxfEngine::FromUnicodeToCodec(const QString &str, QTextCodec *codec) -> std::string
auto VDxfEngine::FromUnicodeToCodec(const QString &str, VTextCodec *codec) -> std::string
{
return codec->fromUnicode(str).toStdString();
}

View File

@ -39,6 +39,7 @@
#include <string>
#include "../vmisc/def.h"
#include "../vmisc/defglobal.h"
#include "dxfdef.h"
#include "libdxfrw/drw_base.h"
@ -50,7 +51,10 @@ class DRW_Entity;
class dx_ifaceBlock;
class VLayoutPoint;
class DRW_Point;
class QTextCodec;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
class VTextCodec;
#endif
class VDxfEngine final : public QPaintEngine
{
@ -158,7 +162,7 @@ private:
Q_REQUIRED_RESULT auto CreateAAMAPolygon(const QVector<C> &polygon, const UTF8STRING &layer,
bool forceClosed) -> P *;
static auto FromUnicodeToCodec(const QString &str, QTextCodec *codec) -> std::string;
static auto FromUnicodeToCodec(const QString &str, VTextCodec *codec) -> std::string;
auto GetFileNameForLocale() const -> std::string;
};

View File

@ -125,4 +125,9 @@ using vsizetype = qsizetype;
using vsizetype = int;
#endif
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
class QTextCodec;
using VTextCodec = QTextCodec;
#endif
#endif // DEFGLOBAL_H

View File

@ -35,9 +35,14 @@
#include <QPushButton>
#include <QShowEvent>
#include <QTextCodec>
#include <QDebug>
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include "../vtextcodec.h"
#else
#include <QTextCodec>
#endif
#if QT_VERSION < QT_VERSION_CHECK(5, 7, 0)
#include "../vmisc/backport/qoverload.h"
#endif // QT_VERSION < QT_VERSION_CHECK(5, 7, 0)
@ -51,10 +56,10 @@ DialogExportToCSV::DialogExportToCSV(QWidget *parent)
{
ui->setupUi(this);
const QList<int> mibs = QTextCodec::availableMibs();
const QList<int> mibs = VTextCodec::availableMibs();
for (auto mib : mibs)
{
if (QTextCodec *codec = QTextCodec::codecForMib(mib))
if (VTextCodec *codec = VTextCodec::codecForMib(mib))
{
ui->comboBoxCodec->addItem(codec->name(), mib);
}
@ -214,7 +219,7 @@ void DialogExportToCSV::ShowPreview()
ui->groupBoxPreview->setVisible(true);
QxtCsvModel csv(m_fileName, nullptr, IsWithHeader(), GetSeparator(), QTextCodec::codecForMib(GetSelectedMib()));
QxtCsvModel csv(m_fileName, nullptr, IsWithHeader(), GetSeparator(), VTextCodec::codecForMib(GetSelectedMib()));
const int columns = csv.columnCount();
const int rows = csv.rowCount();
@ -285,10 +290,10 @@ void DialogExportToCSV::ShowFilePreview(const QString &fileName)
QString DialogExportToCSV::MakeHelpCodecsList()
{
QString out = QStringLiteral("\n");
const QList<int> list = QTextCodec::availableMibs();
const QList<int> list = VTextCodec::availableMibs();
for (int i = 0; i < list.size(); ++i)
{
if (QTextCodec *codec = QTextCodec::codecForMib(list.at(i)))
if (VTextCodec *codec = VTextCodec::codecForMib(list.at(i)))
{
out += QStringLiteral("\t* ") + codec->name();
out += i < list.size()-1 ? QLatin1String(",\n") : QLatin1String(".\n");

View File

@ -41,6 +41,12 @@
#include <QTextStream>
#include <Qt>
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include "../vmisc/vtextcodec.h"
#else
#include <QTextCodec>
#endif
#if QT_VERSION < QT_VERSION_CHECK(5, 5, 0)
#include "../vmisc/diagnostic.h"
#endif // QT_VERSION < QT_VERSION_CHECK(5, 5, 0)
@ -85,7 +91,7 @@ QxtCsvModel::QxtCsvModel(QObject *parent) : QAbstractTableModel(parent)
\sa setSource
*/
QxtCsvModel::QxtCsvModel(QIODevice *file, QObject *parent, bool withHeader, QChar separator, QTextCodec* codec)
QxtCsvModel::QxtCsvModel(QIODevice *file, QObject *parent, bool withHeader, QChar separator, VTextCodec* codec)
: QAbstractTableModel(parent)
{
QXT_INIT_PRIVATE(QxtCsvModel)
@ -102,7 +108,7 @@ QxtCsvModel::QxtCsvModel(QIODevice *file, QObject *parent, bool withHeader, QCha
\sa setSource
*/
QxtCsvModel::QxtCsvModel(const QString &filename, QObject *parent, bool withHeader, QChar separator, QTextCodec* codec)
QxtCsvModel::QxtCsvModel(const QString &filename, QObject *parent, bool withHeader, QChar separator, VTextCodec* codec)
: QAbstractTableModel(parent)
{
QXT_INIT_PRIVATE(QxtCsvModel)
@ -183,7 +189,7 @@ QVariant QxtCsvModel::headerData(int section, Qt::Orientation orientation, int r
Reads in a CSV file from the provided \a file using \a codec.
*/
void QxtCsvModel::setSource(const QString &filename, bool withHeader, QChar separator, QTextCodec* codec)
void QxtCsvModel::setSource(const QString &filename, bool withHeader, QChar separator, VTextCodec* codec)
{
QFile src(filename);
setSource(&src, withHeader, separator, codec);
@ -198,7 +204,7 @@ void QxtCsvModel::setSource(const QString &filename, bool withHeader, QChar sepa
\sa quoteMode
*/
void QxtCsvModel::setSource(QIODevice *file, bool withHeader, QChar separator, QTextCodec* codec)
void QxtCsvModel::setSource(QIODevice *file, bool withHeader, QChar separator, VTextCodec* codec)
{
QxtCsvModelPrivate* d_ptr = &qxt_d();
bool headerSet = !withHeader;
@ -221,10 +227,10 @@ void QxtCsvModel::setSource(QIODevice *file, bool withHeader, QChar separator, Q
QChar ch, buffer(0);
bool readCR = false;
QTextStream stream(file);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
codec ? stream.setCodec(codec) : stream.setAutoDetectUnicode(true);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
codec ? stream.setEncoding(codec->Encoding()) : stream.setAutoDetectUnicode(true);
#else
stream.setAutoDetectUnicode(true);
codec ? stream.setCodec(codec) : stream.setAutoDetectUnicode(true);
#endif
while (not stream.atEnd())
{
@ -594,7 +600,7 @@ static QString qxt_addCsvQuotes(QxtCsvModel::QuoteMode mode, QString field)
Fields in the output file will be separated by \a separator. Set \a withHeader to true
to output a row of headers at the top of the file.
*/
bool QxtCsvModel::toCSV(QIODevice* dest, QString &error, bool withHeader, QChar separator, QTextCodec* codec) const
bool QxtCsvModel::toCSV(QIODevice* dest, QString &error, bool withHeader, QChar separator, VTextCodec* codec) const
{
const QxtCsvModelPrivate& d_ptr = qxt_d();
int row, col, rows, cols;
@ -610,12 +616,16 @@ bool QxtCsvModel::toCSV(QIODevice* dest, QString &error, bool withHeader, QChar
}
}
QTextStream stream(dest);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
if (codec)
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
stream.setEncoding(codec->Encoding());
#else
stream.setCodec(codec);
}
#endif
}
if (withHeader)
{
data = QString();
@ -664,7 +674,7 @@ bool QxtCsvModel::toCSV(QIODevice* dest, QString &error, bool withHeader, QChar
to output a row of headers at the top of the file.
*/
bool QxtCsvModel::toCSV(const QString &filename, QString &error, bool withHeader, QChar separator,
QTextCodec* codec) const
VTextCodec* codec) const
{
QFile dest(filename);
return toCSV(&dest, error, withHeader, separator, codec);

View File

@ -49,7 +49,10 @@
#include "def.h"
class QxtCsvModelPrivate;
class QTextCodec;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
class VTextCodec;
#endif
class QxtCsvModel final : public QAbstractTableModel
{
@ -57,9 +60,9 @@ class QxtCsvModel final : public QAbstractTableModel
public:
explicit QxtCsvModel(QObject *parent = nullptr);
explicit QxtCsvModel(QIODevice *file, QObject *parent = nullptr, bool withHeader = false, QChar separator = ',',
QTextCodec *codec = nullptr);
VTextCodec *codec = nullptr);
explicit QxtCsvModel(const QString &filename, QObject *parent = nullptr, bool withHeader = false,
QChar separator = ',', QTextCodec *codec = nullptr);
QChar separator = ',', VTextCodec *codec = nullptr);
virtual ~QxtCsvModel() = default;
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override;
@ -91,14 +94,14 @@ public:
bool removeColumn(int col, const QModelIndex& parent = QModelIndex());
virtual bool removeColumns(int col, int count, const QModelIndex& parent = QModelIndex()) override;
void setSource(QIODevice *file, bool withHeader = false, QChar separator = ',', QTextCodec* codec = nullptr);
void setSource(QIODevice *file, bool withHeader = false, QChar separator = ',', VTextCodec* codec = nullptr);
void setSource(const QString &filename, bool withHeader = false, QChar separator = ',',
QTextCodec* codec = nullptr);
VTextCodec* codec = nullptr);
bool toCSV(QIODevice *file, QString &error, bool withHeader = false, QChar separator = ',',
QTextCodec* codec = nullptr) const;
VTextCodec* codec = nullptr) const;
bool toCSV(const QString &filename, QString &error, bool withHeader = false, QChar separator = ',',
QTextCodec* codec = nullptr) const;
VTextCodec* codec = nullptr) const;
enum QuoteOption { NoQuotes = 0,
SingleQuote = 1,

View File

@ -39,7 +39,13 @@
#include <QWidget>
#include <QStandardPaths>
#include "../vmisc/compatibility.h"
#include "compatibility.h"
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include "../vmisc/vtextcodec.h"
#else
#include <QTextCodec>
#endif
#ifdef Q_OS_UNIX
# include <unistd.h>
@ -145,6 +151,19 @@ VAbstractApplication::VAbstractApplication(int &argc, char **argv)
connect(this, &QApplication::aboutToQuit, this, &VAbstractApplication::AboutToQuit);
}
//---------------------------------------------------------------------------------------------------------------------
VAbstractApplication::~VAbstractApplication()
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QHashIterator<QStringConverter::Encoding, VTextCodec *> i(m_codecs);
while (i.hasNext())
{
i.next();
delete i.value();
}
#endif
}
//---------------------------------------------------------------------------------------------------------------------
/**
* @brief translationsPath return path to the root directory that contain QM files.
@ -360,6 +379,28 @@ QFileDialog::Options VAbstractApplication::NativeFileDialog(QFileDialog::Options
return options;
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
//---------------------------------------------------------------------------------------------------------------------
VTextCodec *VAbstractApplication::TextCodecCache(QStringConverter::Encoding encoding) const
{
if (m_codecs.contains(encoding))
{
return m_codecs.value(encoding);
}
return nullptr;
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractApplication::CacheTextCodec(QStringConverter::Encoding encoding, VTextCodec *codec)
{
if (not m_codecs.contains(encoding))
{
m_codecs.insert(encoding, codec);
}
}
#endif
//---------------------------------------------------------------------------------------------------------------------
void VAbstractApplication::CheckSystemLocale()
{

View File

@ -49,6 +49,10 @@ class QUndoStack;
class VAbstractApplication;// use in define
class VCommonSettings;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
class VTextCodec;
#endif
QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Wsuggest-final-types")
QT_WARNING_DISABLE_GCC("-Wsuggest-final-methods")
@ -58,7 +62,7 @@ class VAbstractApplication : public QApplication
Q_OBJECT // NOLINT
public:
VAbstractApplication(int &argc, char ** argv);
virtual ~VAbstractApplication() =default;
virtual ~VAbstractApplication();
virtual const VTranslateVars *TrVars()=0;
@ -84,6 +88,11 @@ public:
QFileDialog::Options NativeFileDialog(QFileDialog::Options options = QFileDialog::Options()) const;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
VTextCodec * TextCodecCache(QStringConverter::Encoding encoding) const;
void CacheTextCodec(QStringConverter::Encoding encoding, VTextCodec *codec);
#endif
#if defined(Q_OS_WIN)
static void WinAttachConsole();
#endif
@ -116,6 +125,10 @@ protected slots:
private:
Q_DISABLE_COPY_MOVE(VAbstractApplication) // NOLINT
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QHash<QStringConverter::Encoding, VTextCodec *> m_codecs{};
#endif
void ClearTranslation();
};

View File

@ -35,13 +35,19 @@
#include <QMessageLogger>
#include <QVariant>
#include <QtDebug>
#include <QTextCodec>
#include <QFont>
#include <QGlobalStatic>
#include <QMarginsF>
#include <QColor>
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include "vtextcodec.h"
#else
#include <QTextCodec>
#endif
#include "../vmisc/def.h"
#include "../vmisc/defglobal.h"
#include "../vmisc/compatibility.h"
#include "../vmisc/literals.h"
@ -1009,7 +1015,7 @@ auto VCommonSettings::GetCSVCodec() const -> int
//---------------------------------------------------------------------------------------------------------------------
auto VCommonSettings::GetDefCSVCodec() -> int
{
return QTextCodec::codecForLocale()->mibEnum();
return VTextCodec::codecForLocale()->mibEnum();
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -9,45 +9,53 @@ VLib {
}
name: "VMiscLib"
files: [
"def.cpp",
"testpath.cpp",
"vabstractvalapplication.cpp",
"vabstractapplication.cpp",
"projectversion.cpp",
"vcommonsettings.cpp",
"vvalentinasettings.cpp",
"commandoptions.cpp",
"qxtcsvmodel.cpp",
"vtablesearch.cpp",
"literals.cpp",
"vmodifierkey.cpp",
"compatibility.h",
"lambdaconstants.h",
"def.h",
"testpath.h",
"vabstractvalapplication.h",
"vmath.h",
"vabstractapplication.h",
"projectversion.h",
"vcommonsettings.h",
"vvalentinasettings.h",
"debugbreak.h",
"vlockguard.h",
"vsysexits.h",
"commandoptions.h",
"qxtcsvmodel.h",
"vtablesearch.h",
"diagnostic.h",
"customevents.h",
"defglobal.h",
"testvapplication.h",
"literals.h",
"qt_dispatch/qt_dispatch.h",
"vdatastreamenum.h",
"vmodifierkey.h",
"typedef.h",
]
files: {
var files = [
"def.cpp",
"testpath.cpp",
"vabstractvalapplication.cpp",
"vabstractapplication.cpp",
"projectversion.cpp",
"vcommonsettings.cpp",
"vvalentinasettings.cpp",
"commandoptions.cpp",
"qxtcsvmodel.cpp",
"vtablesearch.cpp",
"literals.cpp",
"vmodifierkey.cpp",
"compatibility.h",
"lambdaconstants.h",
"def.h",
"testpath.h",
"vabstractvalapplication.h",
"vmath.h",
"vabstractapplication.h",
"projectversion.h",
"vcommonsettings.h",
"vvalentinasettings.h",
"debugbreak.h",
"vlockguard.h",
"vsysexits.h",
"commandoptions.h",
"qxtcsvmodel.h",
"vtablesearch.h",
"diagnostic.h",
"customevents.h",
"defglobal.h",
"testvapplication.h",
"literals.h",
"qt_dispatch/qt_dispatch.h",
"vdatastreamenum.h",
"vmodifierkey.h",
"typedef.h",
]
if (Utilities.versionCompare(Qt.core.version, "6") >= 0) {
files.push("vtextcodec.cpp", "vtextcodec.h");
}
return files;
}
Group {
name: "AppImage"

View File

@ -0,0 +1,174 @@
/************************************************************************
**
** @file vtextcodec.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 11 2, 2023
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2023 Valentina project
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#include "vtextcodec.h"
#include <QMap>
#include <QStringConverter>
#include "vabstractapplication.h"
#include "compatibility.h"
namespace
{
//---------------------------------------------------------------------------------------------------------------------
auto QtCodecs() -> QMap<QStringConverter::Encoding, QStringList>
{
static auto codecs = QMap<QStringConverter::Encoding, QStringList>
{
{QStringConverter::Latin1, {"ISO-8859-1", "ANSI_1252", "CP1252", "windows-1252", "LATIN1", "CP819", "CSISO",
"IBM819", "ISO_8859-1", "APPLE ROMAN", "ISO8859-1", "ISO8859-15", "ISO-IR-100", "L1", "IBM 850",
"850"}}, // Western Europe
{QStringConverter::Utf8, {"UTF-8", "UTF8", "UTF8-BIT"}},
{QStringConverter::Utf16, {"UTF-16", "UTF16", "UTF16-BIT"}},
{QStringConverter::Utf16BE, {"UTF-16BE"}},
{QStringConverter::Utf16LE, {"UTF-16LE"}},
{QStringConverter::Utf32, {"UTF-32"}},
{QStringConverter::Utf32BE, {"UTF-32BE"}},
{QStringConverter::Utf32LE, {"UTF-32LE"}},
{QStringConverter::System, {"System"}},
};
return codecs;
}
//---------------------------------------------------------------------------------------------------------------------
auto CodecMibs() -> QMap<QStringConverter::Encoding, int>
{
static auto mibs = QMap<QStringConverter::Encoding, int>
{
{QStringConverter::Utf8, 106},
{QStringConverter::Utf16, 1015},
{QStringConverter::Utf16BE, 1013},
{QStringConverter::Utf16LE, 1014},
{QStringConverter::Utf32, 1017},
{QStringConverter::Utf32BE, 1018},
{QStringConverter::Utf32LE, 1019},
{QStringConverter::Latin1, 4},
{QStringConverter::System, 0},
};
return mibs;
}
} // namespace
//---------------------------------------------------------------------------------------------------------------------
VTextCodec::VTextCodec(QStringConverter::Encoding encoding)
: m_encoding(encoding)
{}
//---------------------------------------------------------------------------------------------------------------------
auto VTextCodec::codecForName(const QString &name) -> VTextCodec *
{
QMap<QStringConverter::Encoding, QStringList> codecs = QtCodecs();
auto i = codecs.constBegin();
while (i != codecs.constEnd())
{
QStringList aliases = i.value();
if (aliases.contains(name))
{
return MakeCodec(i.key());
}
++i;
}
return nullptr;
}
//---------------------------------------------------------------------------------------------------------------------
auto VTextCodec::codecForLocale() -> VTextCodec *
{
return MakeCodec(QStringConverter::System);
}
//---------------------------------------------------------------------------------------------------------------------
auto VTextCodec::codecForMib(int mib) -> VTextCodec *
{
QMap<QStringConverter::Encoding, int> mibs = CodecMibs();
auto i = mibs.constBegin();
while (i != mibs.constEnd())
{
if (mib == i.value())
{
return MakeCodec(i.key());
}
++i;
}
return nullptr;
}
//---------------------------------------------------------------------------------------------------------------------
auto VTextCodec::availableMibs() -> QList<int>
{
return CodecMibs().values();
}
//---------------------------------------------------------------------------------------------------------------------
auto VTextCodec::availableCodecs() -> QList<QByteArray>
{
QMap<QStringConverter::Encoding, QStringList> codecs = QtCodecs();
QList<QByteArray> names;
names.reserve(codecs.size());
auto i = codecs.constBegin();
while (i != codecs.constEnd())
{
names.append(ConstFirst(i.value()).toLatin1());
}
return names;
}
//---------------------------------------------------------------------------------------------------------------------
auto VTextCodec::name() const -> QString
{
return ConstFirst(QtCodecs().value(m_encoding));
}
//---------------------------------------------------------------------------------------------------------------------
auto VTextCodec::mibEnum() const -> int
{
return CodecMibs().value(m_encoding, 0);
}
//---------------------------------------------------------------------------------------------------------------------
auto VTextCodec::MakeCodec(QStringConverter::Encoding encoding) -> VTextCodec *
{
VTextCodec *codec = VAbstractApplication::VApp()->TextCodecCache(encoding);
if (codec != nullptr)
{
return codec;
}
codec = new VTextCodec(encoding);
VAbstractApplication::VApp()->CacheTextCodec(encoding, codec);
return codec;
}

View File

@ -0,0 +1,78 @@
/************************************************************************
**
** @file vtextcodec.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @date 11 2, 2023
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2023 Valentina project
** <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef VTEXTCODEC_H
#define VTEXTCODEC_H
class VTextCodec
{
public:
virtual ~VTextCodec() = default;
static auto codecForName(const QString &name) -> VTextCodec *;
static auto codecForLocale() -> VTextCodec *;
static auto codecForMib(int mib) -> VTextCodec *;
static auto availableMibs() -> QList<int>;
static auto availableCodecs() -> QList<QByteArray>;
auto fromUnicode(const QString &str) const -> QByteArray;
auto toUnicode(const char *chars) const -> QString;
auto name() const -> QString;
auto mibEnum() const -> int;
auto Encoding() const -> QStringConverter::Encoding;
protected:
explicit VTextCodec(QStringConverter::Encoding encoding);
private:
Q_DISABLE_COPY_MOVE(VTextCodec) // NOLINT
QStringConverter::Encoding m_encoding{QStringConverter::Utf8};
static auto MakeCodec(QStringConverter::Encoding encoding) -> VTextCodec *;
};
//---------------------------------------------------------------------------------------------------------------------
inline auto VTextCodec::Encoding() const -> QStringConverter::Encoding
{
return m_encoding;
}
//---------------------------------------------------------------------------------------------------------------------
inline auto VTextCodec::fromUnicode(const QString &str) const -> QByteArray
{
return QStringEncoder(m_encoding)(str);
}
//---------------------------------------------------------------------------------------------------------------------
inline auto VTextCodec::toUnicode(const char *chars) const -> QString
{
return QStringDecoder(m_encoding)(chars);
}
#endif // VTEXTCODEC_H

View File

@ -69,7 +69,11 @@ QChar VPELocaleSign0(const QLocale &locale)
return sign.front();
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return {'0'};
#else
return QChar('0');
#endif
}
//---------------------------------------------------------------------------------------------------------------------
@ -81,7 +85,11 @@ QChar VPELocaleSign1(const QLocale &locale)
return sign.front();
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return {'1'};
#else
return QChar('1');
#endif
}
//---------------------------------------------------------------------------------------------------------------------
@ -93,7 +101,11 @@ QChar VPELocaleSign2(const QLocale &locale)
return sign.front();
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return {'2'};
#else
return QChar('2');
#endif
}
//---------------------------------------------------------------------------------------------------------------------
@ -105,7 +117,11 @@ QChar VPELocaleSign3(const QLocale &locale)
return sign.front();
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return {'3'};
#else
return QChar('3');
#endif
}
//---------------------------------------------------------------------------------------------------------------------
@ -117,7 +133,11 @@ QChar VPELocaleSign4(const QLocale &locale)
return sign.front();
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return {'4'};
#else
return QChar('4');
#endif
}
//---------------------------------------------------------------------------------------------------------------------
@ -129,7 +149,11 @@ QChar VPELocaleSign5(const QLocale &locale)
return sign.front();
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return {'5'};
#else
return QChar('5');
#endif
}
//---------------------------------------------------------------------------------------------------------------------
@ -141,7 +165,11 @@ QChar VPELocaleSign6(const QLocale &locale)
return sign.front();
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return {'6'};
#else
return QChar('6');
#endif
}
//---------------------------------------------------------------------------------------------------------------------
@ -153,7 +181,11 @@ QChar VPELocaleSign7(const QLocale &locale)
return sign.front();
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return {'7'};
#else
return QChar('7');
#endif
}
//---------------------------------------------------------------------------------------------------------------------
@ -165,7 +197,11 @@ QChar VPELocaleSign8(const QLocale &locale)
return sign.front();
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return {'8'};
#else
return QChar('8');
#endif
}
//---------------------------------------------------------------------------------------------------------------------
@ -177,7 +213,11 @@ QChar VPELocaleSign9(const QLocale &locale)
return sign.front();
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
return {'9'};
#else
return QChar('9');
#endif
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -27,7 +27,6 @@
*************************************************************************/
#include "tst_dxf.h"
#include <QTextCodec>
#include <QtTest>
#include "../vmisc/def.h"
@ -35,6 +34,12 @@
#include "../vdxf/dxfdef.h"
#include "../vdxf/libdxfrw/intern/drw_textcodec.h"
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include "../vmisc/vtextcodec.h"
#else
#include <QTextCodec>
#endif
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
#include "../vmisc/backport/text.h"
#endif
@ -44,7 +49,7 @@ namespace
//---------------------------------------------------------------------------------------------------------------------
QStringList AvailableCodecs()
{
QList<QByteArray> codecs = QTextCodec::availableCodecs();
QList<QByteArray> codecs = VTextCodec::availableCodecs();
QSet<QString> uniqueNames;
for(auto &codec: codecs)
{
@ -53,7 +58,7 @@ QStringList AvailableCodecs()
return ConvertToList(uniqueNames);
}
}
} // namespace
//---------------------------------------------------------------------------------------------------------------------
TST_DXF::TST_DXF(QObject *parent)
@ -113,7 +118,7 @@ void TST_DXF::TestCodecPage()
QVERIFY (not dxfCodePage.isEmpty());
QTextCodec *codec = DRW_TextCodec::CodecForName(dxfCodePage);
VTextCodec *codec = DRW_TextCodec::CodecForName(dxfCodePage);
QVERIFY2(codec != nullptr, qUtf8Printable(QStringLiteral("No codec for dxf codepage %1 found.")
.arg(dxfCodePage)));