refactor: Fix Qt 5.15 deprecation warnings

This commit is contained in:
Lars Toenning
2024-03-16 12:41:12 +01:00
parent e1f52f3e88
commit 56bd6f0c42
22 changed files with 38 additions and 181 deletions

View File

@@ -41,7 +41,6 @@ set(SWIFT_MISC_PCH
<QJsonValue>
<QJsonValueRef>
<QLatin1Char>
<QLatin1Literal>
<QLatin1String>
<QList>
<QLoggingCategory>

View File

@@ -263,7 +263,7 @@ namespace BlackSample
timer.start();
situations.convertFromJson(json);
out << "Convert 100,000 aircraft situations from JSON: " << timer.elapsed() << "ms" << endl
out << "Convert 100,000 aircraft situations from JSON: " << timer.elapsed() << "ms" << Qt::endl
<< Qt::endl;
timer.start();
@@ -272,7 +272,7 @@ namespace BlackSample
timer.start();
models.convertFromJson(json);
out << "Convert 10,000 aircraft models from JSON (naive): " << timer.elapsed() << "ms" << endl
out << "Convert 10,000 aircraft models from JSON (naive): " << timer.elapsed() << "ms" << Qt::endl
<< Qt::endl;
timer.start();
@@ -281,7 +281,7 @@ namespace BlackSample
timer.start();
models.convertFromMemoizedJson(json);
out << "Convert 10,000 aircraft models from JSON (memoize): " << timer.elapsed() << "ms" << endl
out << "Convert 10,000 aircraft models from JSON (memoize): " << timer.elapsed() << "ms" << Qt::endl
<< Qt::endl;
return EXIT_SUCCESS;
@@ -383,7 +383,7 @@ namespace BlackSample
auto c = s.contains(upperRegex);
Q_UNUSED(c);
}
out << "Check 100,000 strings for containing uppercase letter: (regex) " << timer.elapsed() << "ms" << endl
out << "Check 100,000 strings for containing uppercase letter: (regex) " << timer.elapsed() << "ms" << Qt::endl
<< Qt::endl;
timer.start();
@@ -400,7 +400,7 @@ namespace BlackSample
auto i = s.indexOf(upperRegex);
Q_UNUSED(i);
}
out << "Check 100,000 strings for index of first uppercase letter: (regex) " << timer.elapsed() << "ms" << endl
out << "Check 100,000 strings for index of first uppercase letter: (regex) " << timer.elapsed() << "ms" << Qt::endl
<< Qt::endl;
auto temp = strings;
@@ -417,7 +417,7 @@ namespace BlackSample
{
s.remove(upperRegex);
}
out << "Remove from 100,000 strings all uppercase letters: (regex) " << timer.elapsed() << "ms" << endl
out << "Remove from 100,000 strings all uppercase letters: (regex) " << timer.elapsed() << "ms" << Qt::endl
<< Qt::endl;
timer.start();

View File

@@ -52,7 +52,7 @@ void CWeatherDataPrinter::fetchAndPrintWeatherData(const CCoordinateGeodetic &po
void CWeatherDataPrinter::printWeatherData(const CWeatherGrid &weatherGrid)
{
QTextStream qtout(stdout);
qtout << "... finished." << endl;
qtout << "... finished." << Qt::endl;
qtout << weatherGrid.getDescription();
qtout << endl;
qtout << Qt::endl;
}

View File

@@ -26,7 +26,7 @@ namespace BlackCore::Afv::Connection
connect(m_voiceServerTimer, &QTimer::timeout, this, &CClientConnection::voiceServerHeartbeat); // sends heartbeat to server
connect(m_udpSocket, &QUdpSocket::readyRead, this, &CClientConnection::readPendingDatagrams);
connect(m_udpSocket, qOverload<QAbstractSocket::SocketError>(&QUdpSocket::error), this, &CClientConnection::handleSocketError);
connect(m_udpSocket, &QAbstractSocket::errorOccurred, this, &CClientConnection::handleSocketError);
}
void CClientConnection::connectTo(const QString &userName, const QString &password, const QString &callsign, const QString &client, ConnectionCallback callback)

View File

@@ -38,7 +38,6 @@
#include <QHttpMultiPart>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QNetworkConfigurationManager>
#include <QProcess>
#include <QRegularExpression>
#include <QSslSocket>
@@ -971,19 +970,6 @@ namespace BlackCore
// Init network
Q_ASSERT_X(m_accessManager, Q_FUNC_INFO, "Need QAM");
CLogMessage::preformatted(CNetworkUtils::createNetworkReport(m_accessManager));
// enable by setting accessible
// http://doc.qt.io/qt-5/qnetworkaccessmanager.html#setNetworkAccessible
m_accessManager->setNetworkAccessible(QNetworkAccessManager::Accessible);
// create a network report in the log
QTimer::singleShot(4000, this, [=] {
if (!sApp || sApp->isShuttingDown()) { return; }
const QString r = CNetworkUtils::createNetworkAccessManagerReport(m_accessManager);
CLogMessage(this).info(u"Network report:\n%1") << r;
});
}
CApplication *BlackCore::CApplication::instance()

View File

@@ -418,7 +418,7 @@ namespace BlackCore::Db
if (size < 1) break;
QByteArray ba;
ba.append(content.mid(contentIndex));
ba.append(content.mid(contentIndex).toUtf8());
ba = QByteArray::fromBase64(ba);
ba.insert(0, CCompressUtils::lengthHeader(size)); // adding 4 bytes length header
byteData = qUncompress(ba);

View File

@@ -1037,7 +1037,7 @@ namespace BlackGui::Components
{
auto item = list->findItems(enabledOption, Qt::MatchExactly);
Q_ASSERT_X(item.size() == 1, Q_FUNC_INFO, "Expected exactly one item per option");
list->setItemSelected(item[0], true);
item[0]->setSelected(true);
}
list->blockSignals(false);
}

View File

@@ -29,7 +29,7 @@ namespace BlackGui::Components
// Widget style
connect(ui->hs_SettingsGuiOpacity, &QSlider::valueChanged, this, &CSettingsGuiComponent::changedWindowsOpacity);
connect(ui->cb_SettingsGuiWidgetStyle, qOverload<const QString &>(&QComboBox::currentIndexChanged), this, &CSettingsGuiComponent::widgetStyleChanged, Qt::QueuedConnection);
connect(ui->cb_SettingsGuiWidgetStyle, qOverload<int>(&QComboBox::currentIndexChanged), this, &CSettingsGuiComponent::widgetStyleChanged, Qt::QueuedConnection);
ui->comp_SettingsFonts->setStyleSheetDefaultColor();
@@ -87,8 +87,9 @@ namespace BlackGui::Components
}
}
void CSettingsGuiComponent::widgetStyleChanged(const QString &widgetStyle)
void CSettingsGuiComponent::widgetStyleChanged(int index)
{
const QString widgetStyle = ui->cb_SettingsGuiWidgetStyle->itemText(index);
const CGeneralGuiSettings settings = m_guiSettings.getThreadLocal();
if (!settings.isDifferentValidWidgetStyle(widgetStyle)) { return; }

View File

@@ -51,7 +51,7 @@ namespace BlackGui::Components
void guiSettingsChanged();
//! Widget style has changed
void widgetStyleChanged(const QString &widgetStyle);
void widgetStyleChanged(int index);
QScopedPointer<Ui::CSettingsGuiComponent> ui;
BlackMisc::CSetting<Settings::TGeneralGui> m_guiSettings { this, &CSettingsGuiComponent::guiSettingsChanged };

View File

@@ -646,14 +646,6 @@ namespace BlackGui
a = menu.addAction(CIcons::swift24(), "Check for updates");
c = connect(a, &QAction::triggered, this, &CGuiApplication::checkNewVersionMenu);
Q_ASSERT_X(c, Q_FUNC_INFO, "Connect failed");
a = menu.addAction(CIcons::monitorError16(), "Network config. (console)");
c = connect(a, &QAction::triggered, this, [=]() {
if (!sGui || sGui->isShuttingDown()) { return; }
const QString r = CNetworkUtils::createNetworkAccessManagerReport(this->getNetworkAccessManager());
CLogMessage(this).info(r);
});
Q_ASSERT_X(c, Q_FUNC_INFO, "Connect failed");
Q_UNUSED(c)
}

View File

@@ -132,7 +132,7 @@ namespace BlackGui
signalMapperToggleFloating->setMapping(toggleFloatingMenuAction, i);
}
c = connect(signalMapperToggleFloating, qOverload<int>(&QSignalMapper::mapped), this, &CInfoArea::toggleFloatingByIndex);
c = connect(signalMapperToggleFloating, &QSignalMapper::mappedInt, this, &CInfoArea::toggleFloatingByIndex);
BLACK_VERIFY_X(c, Q_FUNC_INFO, "Cannot connect mapper"); // do not make that shutdown reason in a release build
menu->addMenu(subMenuDisplay);

View File

@@ -230,7 +230,7 @@ namespace BlackGui::Menus
CMenuAction CMenuActions::addAction(const CMenuAction &menuAction)
{
Q_ASSERT_X(!menuAction.getPath().isEmpty(), Q_FUNC_INFO, "Need path");
m_actions.insertMulti(menuAction.getPath(), menuAction);
m_actions.insert(menuAction.getPath(), menuAction);
return menuAction;
}

View File

@@ -23,8 +23,8 @@ namespace BlackGui
QVBoxLayout *layout = new QVBoxLayout;
setLayout(layout);
connect(m_detailsButtonMapper, qOverload<const QString &>(&QSignalMapper::mapped), this, &CPluginSelector::pluginDetailsRequested);
connect(m_configButtonMapper, qOverload<const QString &>(&QSignalMapper::mapped), this, &CPluginSelector::pluginConfigRequested);
connect(m_detailsButtonMapper, &QSignalMapper::mappedString, this, &CPluginSelector::pluginDetailsRequested);
connect(m_configButtonMapper, &QSignalMapper::mappedString, this, &CPluginSelector::pluginConfigRequested);
}
void CPluginSelector::addPlugin(const QString &identifier, const QString &name, bool hasConfig, bool enabled)

View File

@@ -11,7 +11,7 @@
#include <QIcon>
#include <QImage>
#include <QMap>
#include <QMatrix>
#include <QTransform>
#include <QPainter>
#include <QSize>
#include <QtGlobal>
@@ -1301,9 +1301,9 @@ namespace BlackMisc
QPixmap CIcons::rotate(int rotateDegrees, const QPixmap &original)
{
QMatrix rm;
rm.rotate(rotateDegrees);
QPixmap rotated = original.transformed(rm);
QTransform rt;
rt.rotate(rotateDegrees);
QPixmap rotated = original.transformed(rt);
int xoffset = (rotated.width() - original.width()) / 2;
int yoffset = (rotated.height() - original.height()) / 2;
rotated = rotated.copy(xoffset, yoffset, original.width(), original.height());

View File

@@ -111,7 +111,7 @@ namespace BlackMisc
QByteArray baseData;
baseData.append(getMachineId());
baseData.append(reinterpret_cast<const char *>(&m_processId), sizeof(m_processId));
baseData.append(getName());
baseData.append(getName().toUtf8());
return QUuid::createUuidV5(ns, baseData);
}

View File

@@ -13,7 +13,6 @@
#include <QList>
#include <QNetworkInterface>
#include <QNetworkReply>
#include <QNetworkConfiguration>
#include <QObject>
#include <QSignalMapper>
#include <QTcpSocket>
@@ -62,11 +61,11 @@ namespace BlackMisc::Network
QTcpSocket socket;
QSignalMapper mapper;
QObject::connect(&socket, &QTcpSocket::connected, &mapper, qOverload<>(&QSignalMapper::map));
QObject::connect(&socket, qOverload<QAbstractSocket::SocketError>(&QTcpSocket::error), &mapper, qOverload<>(&QSignalMapper::map));
QObject::connect(&socket, &QAbstractSocket::errorOccurred, &mapper, qOverload<>(&QSignalMapper::map));
mapper.setMapping(&socket, 0);
CEventLoop eventLoop;
eventLoop.stopWhen(&mapper, qOverload<int>(&QSignalMapper::mapped));
eventLoop.stopWhen(&mapper, &QSignalMapper::mappedInt);
socket.connectToHost(hostAddress, static_cast<quint16>(port));
const bool timedOut = !eventLoop.exec(timeoutMs);
@@ -282,109 +281,6 @@ namespace BlackMisc::Network
return false;
}
CStatusMessageList CNetworkUtils::createNetworkReport(const QNetworkAccessManager *am)
{
return CNetworkUtils::createNetworkReport(QUrl(), am);
}
CStatusMessageList CNetworkUtils::createNetworkReport(const QUrl &url, const QNetworkAccessManager *qam)
{
static const CLogCategoryList cats({ CLogCategories::network() });
CStatusMessageList msgs;
if (!url.isEmpty())
{
const QString host = url.host();
const bool canPing = Network::canPing(host);
const CStatusMessage ping(cats, canPing ? CStatusMessage::SeverityInfo : CStatusMessage::SeverityError, "Host: " + host + " ping: " + boolToYesNo(canPing));
msgs.push_back(ping);
QString msg;
const bool canConnect = CNetworkUtils::canConnect(url, msg, getTimeoutMs() * 2);
if (canConnect)
{
msgs.push_back(CStatusMessage(cats, CStatusMessage::SeverityInfo, u"Can connect to " % url.toString()));
}
else
{
msgs.push_back(CStatusMessage(cats, CStatusMessage::SeverityError, u"Cannot connect to " % url.toString() % u" msg: " % msg));
}
}
if (qam)
{
const QString msg = CNetworkUtils::createNetworkAccessManagerReport(qam);
const bool accessible = qam->networkAccessible() == QNetworkAccessManager::Accessible;
msgs.push_back(CStatusMessage(cats, accessible ? CStatusMessage::SeverityInfo : CStatusMessage::SeverityError, msg));
}
return msgs;
}
QString CNetworkUtils::createNetworkAccessManagerReport(const QNetworkAccessManager *qam)
{
static const QMetaEnum enumAccessible = QMetaEnum::fromType<QNetworkAccessManager::NetworkAccessibility>();
static const QString info("Accessible: '%1' (%2) config: %3");
const bool accessible = qam->networkAccessible() == QNetworkAccessManager::Accessible;
return info.arg(boolToYesNo(accessible), enumAccessible.valueToKey(qam->networkAccessible()), CNetworkUtils::networkConfigurationToString(qam->configuration()));
}
QString CNetworkUtils::networkConfigurationToString(const QNetworkConfiguration &configuration)
{
static const QString s("'%1' '%2' valid: '%3' '%4' '%5'");
const QString stateFlagsStr = networkStatesToString(configuration.state());
return s.arg(configuration.name(), configuration.identifier(), boolToYesNo(configuration.isValid()), stateFlagsStr, networkTypeToString(configuration.type()));
}
const QString &CNetworkUtils::networkTypeToString(QNetworkConfiguration::Type type)
{
static const QString iap("InternetAccessPoint");
static const QString sn("ServiceNetwork");
static const QString i("Invalid");
static const QString uc("UserChoice");
switch (type)
{
case QNetworkConfiguration::InternetAccessPoint: return iap;
case QNetworkConfiguration::ServiceNetwork: return sn;
case QNetworkConfiguration::UserChoice: return uc;
default:
case QNetworkConfiguration::Invalid: break;
}
return i;
}
const QString &CNetworkUtils::networkStateToString(QNetworkConfiguration::StateFlag state)
{
static const QString disco("Discovered");
static const QString a("Active");
static const QString u("Undefined");
static const QString d("Defined");
switch (state)
{
case QNetworkConfiguration::Defined: return d;
case QNetworkConfiguration::Active: return a;
case QNetworkConfiguration::Discovered: return disco;
default:
case QNetworkConfiguration::Undefined: break;
}
return u;
}
QString CNetworkUtils::networkStatesToString(QNetworkConfiguration::StateFlags states)
{
QStringList statesSl;
if (states.testFlag(QNetworkConfiguration::Active)) { statesSl << networkStateToString(QNetworkConfiguration::Active); }
if (states.testFlag(QNetworkConfiguration::Discovered)) { statesSl << networkStateToString(QNetworkConfiguration::Discovered); }
if (states.testFlag(QNetworkConfiguration::Defined)) { statesSl << networkStateToString(QNetworkConfiguration::Defined); }
if (states.testFlag(QNetworkConfiguration::Undefined)) { statesSl << networkStateToString(QNetworkConfiguration::Undefined); }
return statesSl.join(", ");
}
const QString &CNetworkUtils::networkOperationToString(QNetworkAccessManager::Operation operation)
{
static const QString h("HEAD");

View File

@@ -12,7 +12,6 @@
#include <QNetworkRequest>
#include <QNetworkAccessManager>
#include <QNetworkConfiguration>
#include <QString>
#include <QStringList>
#include <QtGlobal>
@@ -124,28 +123,6 @@ namespace BlackMisc::Network
//! Looks like PHP error messages
static bool looksLikePhpErrorMessage(const QString &errorMessage);
//! Status about network
static BlackMisc::CStatusMessageList createNetworkReport(const QNetworkAccessManager *am);
//! Status about network, can be used when an URL fails to resolve issues
//! \remark that can take a moment to complete, as it checks network
static BlackMisc::CStatusMessageList createNetworkReport(const QUrl &url, const QNetworkAccessManager *qam = nullptr);
//! Report for QAM
static QString createNetworkAccessManagerReport(const QNetworkAccessManager *qam);
//! Configuration as string
static QString networkConfigurationToString(const QNetworkConfiguration &configuration);
//! Type to string
static const QString &networkTypeToString(QNetworkConfiguration::Type type);
//! State to string
static const QString &networkStateToString(QNetworkConfiguration::StateFlag state);
//! States to string
static QString networkStatesToString(QNetworkConfiguration::StateFlags states);
//! Operation to string
static const QString &networkOperationToString(QNetworkAccessManager::Operation operation);

View File

@@ -51,9 +51,14 @@ namespace BlackMisc::SharedState::DBus
void CDuplex::requestPeerSubscriptions()
{
QSet<QString> channels;
for (auto client : m_hub->clients())
for (const auto &client : m_hub->clients())
{
if (client != this) { channels.unite(client->m_subscriptions.keys().toSet()); }
if (client != this)
{
const auto &keys = client->m_subscriptions.keys();
const QSet subscriptions(keys.begin(), keys.end());
channels.unite(subscriptions);
}
}
for (const auto &channel : channels)
{

View File

@@ -1389,7 +1389,7 @@ namespace BlackMisc::Simulation
if (log) { log->push_back(subMsgs); }
CCallsign::addLogDetailsToList(log, remoteModel.getCallsign(), QStringLiteral("--- End calculating #%1 ---").arg(c));
c++;
scoreMap.insertMulti(score, model);
scoreMap.insert(score, model);
}
CCallsign::addLogDetailsToList(log, remoteModel.getCallsign(), QStringLiteral("--- End scoring ---"));
return scoreMap;

View File

@@ -30,6 +30,7 @@
#include <Qt>
#include <QHash>
#include <QMap>
#include <QMultiMap>
#include <atomic>
BLACK_DECLARE_SEQUENCE_MIXINS(BlackMisc::Simulation, CAircraftModel, CAircraftModelList)
@@ -46,7 +47,7 @@ namespace BlackMisc
namespace Simulation
{
//! Individual (matching) score for each model
using ScoredModels = QMap<int, CAircraftModel>;
using ScoredModels = QMultiMap<int, CAircraftModel>;
//! Value object encapsulating a list of aircraft models
class BLACKMISC_EXPORT CAircraftModelList :

View File

@@ -391,7 +391,7 @@ namespace BlackMisc::Simulation
QMultiMap<int, CSimulatorInfo> counts;
for (int i = 0; i < m_counts.size(); i++)
{
counts.insertMulti(m_counts[i], simulator(i));
counts.insert(m_counts[i], simulator(i));
}
return counts;
}

View File

@@ -37,7 +37,7 @@ namespace BlackMisc
{
if ((latin >= 'a' && latin <= 'z') || (latin >= 'A' && latin <= 'Z') || (latin >= '0' && latin <= '9') || allow.contains(latin))
{
result += c;
result += c.toLatin1();
}
else
{