mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
refactor: Remove Qt5 compatibility layer
This commit is contained in:
@@ -141,8 +141,8 @@ namespace swift::core::fsd
|
||||
"Can't change server details while still connected");
|
||||
|
||||
const QString codecName(server.getFsdSetup().getTextCodec());
|
||||
QTextCodec *textCodec = QTextCodec::codecForName(codecName.toLocal8Bit());
|
||||
if (!textCodec) { textCodec = QTextCodec::codecForName("utf-8"); }
|
||||
auto codec = QStringDecoder::encodingForName(codecName);
|
||||
if (!codec.has_value()) { codec = QStringConverter::Utf8; }
|
||||
const int protocolRev = (server.getServerType() == CServer::FSDServerVatsim) ?
|
||||
PROTOCOL_REVISION_VATSIM_VELOCITY :
|
||||
PROTOCOL_REVISION_CLASSIC;
|
||||
@@ -150,7 +150,8 @@ namespace swift::core::fsd
|
||||
QWriteLocker l(&m_lockUserClientBuffered);
|
||||
m_server = server;
|
||||
m_protocolRevision = protocolRev;
|
||||
m_fsdTextCodec = textCodec;
|
||||
m_encoder = QStringEncoder(codec.value_or(QStringConverter::Utf8));
|
||||
m_decoder = QStringDecoder(codec.value_or(QStringConverter::Utf8));
|
||||
}
|
||||
|
||||
void CFSDClient::setCallsign(const CCallsign &callsign)
|
||||
@@ -781,7 +782,7 @@ namespace swift::core::fsd
|
||||
void CFSDClient::sendMessageString(const QString &message)
|
||||
{
|
||||
if (message.isEmpty()) { return; }
|
||||
const QByteArray bufferEncoded = m_fsdTextCodec->fromUnicode(message);
|
||||
const QByteArray bufferEncoded = m_encoder(message);
|
||||
if (m_printToConsole) { qDebug() << "FSD Sent=>" << bufferEncoded; }
|
||||
if (!m_unitTestMode) { m_socket->write(bufferEncoded); }
|
||||
|
||||
@@ -2199,7 +2200,7 @@ namespace swift::core::fsd
|
||||
{
|
||||
const QByteArray dataEncoded = m_socket->readLine();
|
||||
if (dataEncoded.isEmpty()) { continue; }
|
||||
const QString data = m_fsdTextCodec->toUnicode(dataEncoded);
|
||||
const QString data = m_decoder(dataEncoded);
|
||||
this->parseMessage(data);
|
||||
lines++;
|
||||
|
||||
|
||||
@@ -42,7 +42,6 @@
|
||||
#include <QReadWriteLock>
|
||||
#include <QString>
|
||||
#include <QTcpSocket>
|
||||
#include <QTextCodec>
|
||||
#include <QTimer>
|
||||
#include <QtGlobal>
|
||||
|
||||
@@ -651,7 +650,8 @@ namespace swift::core::fsd
|
||||
// User data
|
||||
swift::misc::network::CServer m_server;
|
||||
swift::misc::network::CLoginMode m_loginMode;
|
||||
QTextCodec *m_fsdTextCodec = nullptr;
|
||||
QStringEncoder m_encoder;
|
||||
QStringDecoder m_decoder;
|
||||
SimType m_simType = SimType::Unknown;
|
||||
PilotRating m_pilotRating = PilotRating::Unknown;
|
||||
AtcRating m_atcRating = AtcRating::Unknown;
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace swift::gui::editors
|
||||
ui->setupUi(this);
|
||||
this->resetToDefaultValues();
|
||||
ui->cb_Override->setChecked(true);
|
||||
ui->le_TextCodec->setCompleter(new QCompleter(textCodecNames(true, true), this));
|
||||
ui->le_TextCodec->setCompleter(new QCompleter(QStringDecoder::availableCodecs(), this));
|
||||
connect(ui->cb_Override, &QCheckBox::toggled, this, &CFsdSetupForm::enabledToggled, Qt::QueuedConnection);
|
||||
connect(ui->pb_SetDefaults, &QPushButton::clicked, this, &CFsdSetupForm::resetToDefaultValues);
|
||||
}
|
||||
|
||||
@@ -698,7 +698,6 @@ target_link_libraries(misc
|
||||
Qt::Network
|
||||
Qt::Multimedia
|
||||
nlohmann_json::nlohmann_json
|
||||
Qt::Core5Compat # for QStringRef
|
||||
PRIVATE
|
||||
Qt::Xml
|
||||
SimpleCrypt
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
#include <QByteArray>
|
||||
#include <QDebug>
|
||||
#include <QString>
|
||||
#include <QStringRef>
|
||||
#include <QStringView>
|
||||
#include <QTextStream>
|
||||
#include <QtGlobal>
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ namespace swift::misc::network
|
||||
{
|
||||
msgs.push_back(CStatusMessage(CStatusMessage::SeverityError, u"No codec"));
|
||||
}
|
||||
if (!textCodecNames(true, true).contains(this->getTextCodec()))
|
||||
if (!QStringDecoder::availableCodecs().contains(this->getTextCodec()))
|
||||
{
|
||||
msgs.push_back(CStatusMessage(CStatusMessage::SeverityError, u"Unrecognized codec name"));
|
||||
}
|
||||
|
||||
@@ -657,13 +657,13 @@ namespace swift::misc::simulation::fscommon
|
||||
// manually parsing because QSettings did not work properly
|
||||
const QString fileContent = CFileUtils::readFileToString(configFile);
|
||||
if (fileContent.isEmpty()) { continue; }
|
||||
const QList<QStringRef> lines = splitLinesRefs(fileContent);
|
||||
const QList<QStringView> lines = splitLinesRefs(fileContent);
|
||||
static const QString p("Path=");
|
||||
for (const QStringRef &line : lines)
|
||||
for (const QStringView &line : lines)
|
||||
{
|
||||
const int i = line.lastIndexOf(p, -1, Qt::CaseInsensitive);
|
||||
if (i < 0 || line.endsWith('=')) { continue; }
|
||||
const QStringRef path = line.mid(i + p.length());
|
||||
const QStringView path = line.mid(i + p.length());
|
||||
const QDir dir(QDir::fromNativeSeparators(
|
||||
pathPrefix.isEmpty() ? path.toString() :
|
||||
CFileUtils::appendFilePathsAndFixUnc(pathPrefix, path.toString())));
|
||||
@@ -785,20 +785,20 @@ namespace swift::misc::simulation::fscommon
|
||||
{
|
||||
const QString fileContent = CFileUtils::readFileToString(fsxFile);
|
||||
if (fileContent.isEmpty()) { return QSet<QString>(); }
|
||||
const QList<QStringRef> lines = splitLinesRefs(fileContent);
|
||||
const QList<QStringView> lines = splitLinesRefs(fileContent);
|
||||
static const QString p("SimObjectPaths.");
|
||||
|
||||
const QFileInfo fsxFileInfo(fsxFile);
|
||||
const QString relPath = fsxFileInfo.absolutePath();
|
||||
|
||||
QSet<QString> paths;
|
||||
for (const QStringRef &line : lines)
|
||||
for (const QStringView &line : lines)
|
||||
{
|
||||
const int i1 = line.lastIndexOf(p, -1, Qt::CaseInsensitive);
|
||||
if (i1 < 0) { continue; }
|
||||
const int i2 = line.lastIndexOf('=');
|
||||
if (i2 < 0 || i1 >= i2 || line.endsWith('=')) { continue; }
|
||||
const QStringRef path = line.mid(i2 + 1);
|
||||
const QStringView path = line.mid(i2 + 1);
|
||||
QString soPath = QDir::fromNativeSeparators(path.toString());
|
||||
if (logConfigPathReading())
|
||||
{
|
||||
@@ -857,20 +857,20 @@ namespace swift::misc::simulation::fscommon
|
||||
{
|
||||
const QString fileContent = CFileUtils::readFileToString(msfsFile);
|
||||
if (fileContent.isEmpty()) { return QSet<QString>(); }
|
||||
const QList<QStringRef> lines = splitLinesRefs(fileContent);
|
||||
const QList<QStringView> lines = splitLinesRefs(fileContent);
|
||||
static const QString p("SimObjectPaths.");
|
||||
|
||||
const QFileInfo fsxFileInfo(msfsFile);
|
||||
const QString relPath = fsxFileInfo.absolutePath();
|
||||
|
||||
QSet<QString> paths;
|
||||
for (const QStringRef &line : lines)
|
||||
for (const QStringView &line : lines)
|
||||
{
|
||||
const int i1 = line.lastIndexOf(p, -1, Qt::CaseInsensitive);
|
||||
if (i1 < 0) { continue; }
|
||||
const int i2 = line.lastIndexOf('=');
|
||||
if (i2 < 0 || i1 >= i2 || line.endsWith('=')) { continue; }
|
||||
const QStringRef path = line.mid(i2 + 1);
|
||||
const QStringView path = line.mid(i2 + 1);
|
||||
QString soPath = QDir::fromNativeSeparators(path.toString());
|
||||
if (logConfigPathReading())
|
||||
{
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include <QChar>
|
||||
#include <QRegularExpression>
|
||||
#include <QStringBuilder>
|
||||
#include <QTextCodec>
|
||||
|
||||
namespace swift::misc
|
||||
{
|
||||
@@ -17,7 +16,7 @@ namespace swift::misc
|
||||
return removeChars(s, [](QChar c) { return c == u' ' || c == u':' || c == u'_' || c == u'-' || c == u'.'; });
|
||||
}
|
||||
|
||||
QList<QStringRef> splitLinesRefs(const QString &s)
|
||||
QList<QStringView> splitLinesRefs(const QString &s)
|
||||
{
|
||||
return splitStringRefs(s, [](QChar c) { return c == '\n' || c == '\r'; });
|
||||
}
|
||||
@@ -210,44 +209,6 @@ namespace swift::misc
|
||||
return s.contains(' ') ? s.left(s.indexOf(' ')) : s;
|
||||
}
|
||||
|
||||
QStringList simpleTextCodecNamesImpl()
|
||||
{
|
||||
QStringList codecs;
|
||||
for (const QByteArray &ba : QTextCodec::availableCodecs())
|
||||
{
|
||||
const QString c(QString::fromLocal8Bit(ba));
|
||||
codecs << c;
|
||||
}
|
||||
return codecs;
|
||||
}
|
||||
|
||||
QStringList mibTextCodecNamesImpl()
|
||||
{
|
||||
QStringList codecs;
|
||||
for (int mib : QTextCodec::availableMibs())
|
||||
{
|
||||
const QByteArray ba(QTextCodec::codecForMib(mib)->name());
|
||||
const QString c(QString::fromLocal8Bit(ba));
|
||||
codecs << c;
|
||||
}
|
||||
return codecs;
|
||||
}
|
||||
|
||||
QStringList textCodecNames(bool simpleNames, bool mibNames)
|
||||
{
|
||||
static const QStringList simple(simpleTextCodecNamesImpl());
|
||||
static const QStringList mib(mibTextCodecNamesImpl());
|
||||
if (simpleNames && mibNames)
|
||||
{
|
||||
QStringList s(simple);
|
||||
s.append(mib);
|
||||
return s;
|
||||
}
|
||||
if (simpleNames) { return simple; }
|
||||
if (mibNames) { return mib; }
|
||||
return QStringList();
|
||||
}
|
||||
|
||||
// http://www.codegur.online/14009522/how-to-remove-accents-diacritic-marks-from-a-string-in-qt
|
||||
// https://stackoverflow.com/questions/14009522/how-to-remove-accents-diacritic-marks-from-a-string-in-qt
|
||||
// https://german.stackexchange.com/questions/4992/conversion-table-for-diacritics-e-g-%C3%BC-%E2%86%92-ue
|
||||
@@ -458,11 +419,11 @@ namespace swift::misc
|
||||
QMap<QString, QString> parseIniValues(const QString &data)
|
||||
{
|
||||
QMap<QString, QString> map;
|
||||
QList<QStringRef> lines = splitLinesRefs(data);
|
||||
for (const QStringRef &l : lines)
|
||||
QList<QStringView> lines = splitLinesRefs(data);
|
||||
for (const QStringView &l : lines)
|
||||
{
|
||||
if (l.isEmpty()) { continue; }
|
||||
const int i = l.indexOf("=");
|
||||
const int i = l.indexOf('=');
|
||||
if (i < 0 || i >= l.length() + 1) { continue; }
|
||||
|
||||
const QString key = l.left(i).trimmed().toString();
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#include <QMapIterator>
|
||||
#include <QSet>
|
||||
#include <QString>
|
||||
#include <QStringRef>
|
||||
#include <QStringView>
|
||||
#include <QtGlobal>
|
||||
|
||||
@@ -89,9 +88,9 @@ namespace swift::misc
|
||||
//! Split a string into multiple strings, using a predicate function to identify the split points.
|
||||
//! \warning The returned refs are only valid during the lifetime of the original string.
|
||||
template <class F>
|
||||
QList<QStringRef> splitStringRefs(const QString &s, F predicate)
|
||||
QList<QStringView> splitStringRefs(const QString &s, F predicate)
|
||||
{
|
||||
QList<QStringRef> result;
|
||||
QList<QStringView> result;
|
||||
auto notPredicate = [=](auto c) { return !predicate(c); };
|
||||
auto begin = s.begin();
|
||||
while (true)
|
||||
@@ -99,14 +98,14 @@ namespace swift::misc
|
||||
begin = std::find_if(begin, s.end(), notPredicate);
|
||||
if (begin == s.end()) { return result; }
|
||||
auto end = std::find_if(begin, s.end(), predicate);
|
||||
result.push_back(QStringRef(&s, std::distance(s.begin(), begin), std::distance(begin, end)));
|
||||
result.push_back(QStringView(s).slice(std::distance(s.begin(), begin), std::distance(begin, end)));
|
||||
begin = end;
|
||||
}
|
||||
}
|
||||
|
||||
//! Split a string into multiple lines. Blank lines are skipped.
|
||||
//! \warning The returned refs are only valid during the lifetime of the original string.
|
||||
SWIFT_MISC_EXPORT QList<QStringRef> splitLinesRefs(const QString &s);
|
||||
SWIFT_MISC_EXPORT QList<QStringView> splitLinesRefs(const QString &s);
|
||||
|
||||
//! It would be risky to call splitStringRefs with an rvalue, so forbid it.
|
||||
template <class F>
|
||||
@@ -119,7 +118,7 @@ namespace swift::misc
|
||||
template <class F>
|
||||
QStringList splitString(const QString &s, F predicate)
|
||||
{
|
||||
return makeRange(splitStringRefs(s, predicate)).transform([](QStringRef sr) { return sr.toString(); });
|
||||
return makeRange(splitStringRefs(s, predicate)).transform([](QStringView sv) { return sv.toString(); });
|
||||
}
|
||||
|
||||
//! Split a string into multiple lines. Blank lines are skipped.
|
||||
@@ -256,9 +255,6 @@ namespace swift::misc
|
||||
//! Strip a designator from a combined string
|
||||
SWIFT_MISC_EXPORT QString stripDesignatorFromCompleterString(const QString &candidate);
|
||||
|
||||
//! Strip a designator from a combined string
|
||||
SWIFT_MISC_EXPORT QStringList textCodecNames(bool simpleNames, bool mibNames);
|
||||
|
||||
//! Remove accents / diacritic marks from a string
|
||||
SWIFT_MISC_EXPORT QString simplifyAccents(const QString &candidate);
|
||||
|
||||
@@ -333,11 +329,6 @@ namespace swift::misc
|
||||
static QString toQString(const QString &s) { return s; }
|
||||
};
|
||||
template <>
|
||||
struct TString<QStringRef>
|
||||
{
|
||||
static QString toQString(const QStringRef &sr) { return sr.toString(); }
|
||||
};
|
||||
template <>
|
||||
struct TString<QStringView>
|
||||
{
|
||||
static QString toQString(QStringView sv) { return sv.toString(); }
|
||||
|
||||
Reference in New Issue
Block a user