refactor: Fix readability-static-accessed-through-instance warnings

This commit is contained in:
Lars Toenning
2025-10-25 22:21:29 +02:00
parent 5eafb1282d
commit 469d9b8421
28 changed files with 59 additions and 55 deletions

View File

@@ -46,6 +46,7 @@ Checks: >
readability-use-anyofallof,
readability-redundant-member-init,
cppcoreguidelines-init-variables,
readability-static-accessed-through-instance,
CheckOptions:
- key: readability-identifier-naming.ClassCase

View File

@@ -838,7 +838,7 @@ namespace swift::core
{
const CStatusMessage m = this->supportsContexts() ? this->getIContextApplication()->saveSettings() :
CSettingsCache::instance()->saveToStore();
CLogMessage(this).preformatted(m);
CLogMessage::preformatted(m);
}
// from here on we really rip apart the application object
@@ -870,7 +870,7 @@ namespace swift::core
// clean up all in "deferred delete state"
qApp->sendPostedEvents(nullptr, QEvent::DeferredDelete);
sApp->processEventsFor(500);
processEventsFor(500);
// completed
m_shutdown = true;

View File

@@ -142,7 +142,7 @@ namespace swift::core::context
ownAircraft.setPilot(m_currentNetworkServer.get().getUser());
// If we already have a model from somehwere, keep it, otherwise init default
ownAircraft.setModel(this->reverseLookupModel(ownAircraft.getModel()));
ownAircraft.setModel(reverseLookupModel(ownAircraft.getModel()));
if (!ownAircraft.getAircraftIcaoCode().hasValidDesignator())
{
ownAircraft.setModel(getDefaultOwnAircraftModel());
@@ -205,7 +205,7 @@ namespace swift::core::context
bool CContextOwnAircraft::updateOwnModel(const CAircraftModel &model, const CIdentifier &identifier)
{
CAircraftModel updateModel(this->reverseLookupModel(model));
CAircraftModel updateModel(reverseLookupModel(model));
{
QWriteLocker l(&m_lockAircraft);
const bool changed = (m_ownAircraft.getModel() != updateModel);

View File

@@ -179,7 +179,7 @@ namespace swift::core::db
if (processEvents && c % 125 == 0)
{
if (!sApp || sApp->isShuttingDown()) { return models; }
sApp->processEventsFor(25);
CApplication::processEventsFor(25);
}
const QString ms(model.getModelString());
@@ -222,7 +222,7 @@ namespace swift::core::db
if (processEvents && c % 125 == 0)
{
if (!sApp || sApp->isShuttingDown()) { return models; }
sApp->processEventsFor(25);
CApplication::processEventsFor(25);
}
const QString ms(model.getModelString());
@@ -268,7 +268,7 @@ namespace swift::core::db
if (modified || model.hasValidDbKey())
{
c++;
if (processEvents && c % 125 == 0) { sApp->processEventsFor(25); }
if (processEvents && c % 125 == 0) { CApplication::processEventsFor(25); }
}
}
CLogMessage(static_cast<CDatabaseUtils *>(nullptr)).info(u"Consolidated %1 models in %2ms")
@@ -374,7 +374,7 @@ namespace swift::core::db
const int percentage = c * 100 / maxModelsCount;
progressIndicator->updateProgressIndicatorAndProcessEvents(percentage);
}
else { sApp->processEventsFor(10); }
else { CApplication::processEventsFor(10); }
}
// values to be skipped

View File

@@ -199,7 +199,7 @@ namespace swift::gui::components
ui->cb_SetupAudioNotificationLogoff->isChecked());
const CStatusMessage msg = m_audioSettings.set(as);
CLogMessage(this).preformatted(msg);
CLogMessage::preformatted(msg);
const auto *sender = qobject_cast<const QCheckBox *>(QObject::sender());
if (checked && sGui && sGui->getCContextAudioBase() && sender)

View File

@@ -175,7 +175,7 @@ namespace swift::gui::components
if (ui->cb_Silent->isChecked())
{
// allow UI updates
sApp->processEventsFor(50);
CApplication::processEventsFor(50);
return true;
}
const QMessageBox::StandardButton reply = QMessageBox::question(

View File

@@ -31,7 +31,7 @@ namespace swift::gui::components
//! \fixme KB 201709 It is hard to judge if it is a good idea to trigger cache admit in a UI component
// althought admit happens in background, this component might trigger cache reads not needed (though it is not
// very likely)
this->admitCaches();
admitCaches();
ui->lbl_DatabaseUrl->setTextFormat(Qt::RichText);
ui->lbl_DatabaseUrl->setTextInteractionFlags(Qt::TextBrowserInteraction);

View File

@@ -298,7 +298,7 @@ namespace swift::gui::components
QWidget *CFirstModelSetComponent::mainWindow()
{
QWidget *pw = sGui->mainApplicationWidget();
QWidget *pw = CGuiApplication::mainApplicationWidget();
return pw ? pw : this;
}

View File

@@ -250,8 +250,8 @@ namespace swift::gui::components
void CInfoBarStatusComponent::updateSpacing()
{
if (!sGui || sGui->isShuttingDown() || !sGui->mainApplicationWidget()) { return; }
const int w = sGui->mainApplicationWidget()->width();
if (!sGui || sGui->isShuttingDown() || !CGuiApplication::mainApplicationWidget()) { return; }
const int w = CGuiApplication::mainApplicationWidget()->width();
const int s = (w >= 400) ? 6 : 2;
this->setSpacing(s);
}

View File

@@ -56,7 +56,7 @@ namespace swift::gui::components
void CSettingsHotkeyComponent::saveSettings()
{
const CStatusMessage msg = m_actionHotkeys.save();
CLogMessage(this).preformatted(msg);
CLogMessage::preformatted(msg);
}
void CSettingsHotkeyComponent::registerDummyPttEntry()

View File

@@ -166,8 +166,8 @@ namespace swift::gui::components
// override if values are not empty
const CSpecializedSimulatorSettings ss = m_settings.getSpecializedSettings(simulator);
const QString sd = CFileUtils::fixWindowsUncPath(
CFileUtils::normalizeFilePathToQtStandard(ss.defaultSimulatorDirectory(simulator)));
const QString sd = CFileUtils::fixWindowsUncPath(CFileUtils::normalizeFilePathToQtStandard(
CSpecializedSimulatorSettings::defaultSimulatorDirectory(simulator)));
if (!sd.isEmpty())
{
ui->le_SimulatorDirectory->setText(sd);
@@ -181,7 +181,7 @@ namespace swift::gui::components
m_unsavedChanges = true;
}
const QStringList excludes(ss.defaultModelExcludeDirectoryPatterns(simulator));
const QStringList excludes(CSpecializedSimulatorSettings::defaultModelExcludeDirectoryPatterns(simulator));
if (!excludes.isEmpty())
{
this->displayExcludeDirectoryPatterns(excludes);

View File

@@ -222,8 +222,9 @@ namespace swift::gui::components
// get initial aircraft to render
CInterpolationAndRenderingSetupGlobal setup =
sGui->getIContextSimulator()->getInterpolationAndRenderingSetupGlobal();
const int noRequested =
ui->le_MaxAircraft->text().isEmpty() ? setup.InfiniteAircraft() : ui->le_MaxAircraft->text().toInt();
const int noRequested = ui->le_MaxAircraft->text().isEmpty() ?
CInterpolationAndRenderingSetupGlobal::InfiniteAircraft() :
ui->le_MaxAircraft->text().toInt();
const int oldValue = setup.getMaxRenderedAircraft();
if (oldValue == noRequested) { return; }
@@ -301,7 +302,7 @@ namespace swift::gui::components
bool ok = false;
CSimulatorSettings settings = CSettingsSimulatorComponent::getSimulatorSettings(ok);
if (!ok || !settings.setComIntegrated(ui->cb_ComSync->isChecked())) { return; }
this->setSimulatorSettings(settings);
setSimulatorSettings(settings);
}
void CSettingsSimulatorComponent::onApplyCGSource()
@@ -310,7 +311,7 @@ namespace swift::gui::components
const CSimulatorSettings::CGSource source = ui->comp_CGSourceSelector->getValue();
CSimulatorSettings settings = CSettingsSimulatorComponent::getSimulatorSettings(ok);
if (!ok || !settings.setCGSource(source)) { return; }
this->setSimulatorSettings(settings);
setSimulatorSettings(settings);
}
void CSettingsSimulatorComponent::onApplyRecordGnd()
@@ -332,7 +333,7 @@ namespace swift::gui::components
const bool c1 = settings.setRecordOwnAircraftGnd(ui->cb_RecordOwnGndPositions->isChecked());
const bool c2 = settings.setRecordedGndRadius(radius);
if (!c1 && !c2) { return; }
this->setSimulatorSettings(settings);
setSimulatorSettings(settings);
}
void CSettingsSimulatorComponent::onReload() { this->setGuiValues(); }

View File

@@ -198,7 +198,7 @@ namespace swift::gui::components
const QString platform = this->getSelectedOrDefaultPlatform().getPlatformName();
const QStringList settings({ channel, platform });
const CStatusMessage m = m_updateSettings.setAndSave(settings);
if (m.isFailure()) { CLogMessage(this).preformatted(m); }
if (m.isFailure()) { CLogMessage::preformatted(m); }
}
void CUpdateInfoComponent::channelChanged() { this->uiSelectionChanged(); }

View File

@@ -75,7 +75,7 @@ namespace swift::gui::editors
}
catch (const CJsonException &ex)
{
CLogMessage(this).preformatted(CStatusMessage::fromJsonException(ex, this, "Parse error"));
CLogMessage::preformatted(CStatusMessage::fromJsonException(ex, this, "Parse error"));
return parts;
}
return parts;

View File

@@ -364,7 +364,7 @@ namespace swift::gui
CLogSubscriber logSub(this, [&](const CStatusMessage &message) {
// handles an error in restoreGeometry/State
const int ret =
QMessageBox::critical(sGui->mainApplicationWidget(), sGui->getApplicationNameAndVersion(),
QMessageBox::critical(mainApplicationWidget(), sGui->getApplicationNameAndVersion(),
QStringLiteral("Restoring the window state/geometry failed!\n"
"You need to reset the window size (command -%1).\n\n"
"Original msg: %2\n\n"

View File

@@ -229,7 +229,7 @@ namespace swift::gui
if (resetTimeMs > 0)
{
QPointer<CLedWidget> myself(this);
m_resetTimer.singleShot(resetTimeMs, this, [=] {
QTimer::singleShot(resetTimeMs, this, [=] {
if (!myself) { return; }
this->resetState();
});
@@ -252,7 +252,7 @@ namespace swift::gui
void CLedWidget::setTriState(int resetTimeMs)
{
if (resetTimeMs > 0) { m_resetTimer.singleShot(resetTimeMs, this, &CLedWidget::resetState); }
if (resetTimeMs > 0) { QTimer::singleShot(resetTimeMs, this, &CLedWidget::resetState); }
else
{
m_resetTimer.stop();

View File

@@ -71,8 +71,7 @@ namespace swift::gui
void CTextMessageTextEdit::redrawHtml()
{
const QString html(
this->toHtml(m_latestFirst ? m_messages.reversed() : m_messages, m_withSender, m_withRecipient));
const QString html(toHtml(m_latestFirst ? m_messages.reversed() : m_messages, m_withSender, m_withRecipient));
m_textDocument.setHtml(html);
this->moveCursor(m_latestFirst ? QTextCursor::Start : QTextCursor::End);
}

View File

@@ -206,7 +206,7 @@ namespace swift::misc
CApplicationInfo::Application CApplicationInfo::guessApplication()
{
const QString a(QCoreApplication::instance()->applicationName().toLower());
const QString a(QCoreApplication::applicationName().toLower());
if (a.contains("test")) { return CApplicationInfo::UnitTest; } // names like testcore
if (a.contains("sample")) { return CApplicationInfo::Sample; }
if (a.contains("core")) { return CApplicationInfo::PilotClientCore; }

View File

@@ -122,7 +122,7 @@ namespace swift::misc::aviation
{
// actually we would expect all DB data to be valid, however right now
// we only check special cases
if (this->getDesignator() == this->getUnassignedDesignator()) { return msg; } // DB ZZZZ
if (this->getDesignator() == getUnassignedDesignator()) { return msg; } // DB ZZZZ
}
if (!hasKnownDesignator())

View File

@@ -128,13 +128,12 @@ namespace swift::misc::aviation
m_isParsed = true;
if (m_remarks.isEmpty()) { return; }
const QString remarks = m_remarks.toUpper();
const QString callsign =
CCallsign::unifyCallsign(this->getRemark(remarks, "REG/")); // registration is a callsign
const QString callsign = CCallsign::unifyCallsign(getRemark(remarks, "REG/")); // registration is a callsign
if (CCallsign::isValidAircraftCallsign(callsign)) { m_registration = CCallsign(callsign, CCallsign::Aircraft); }
m_voiceCapabilities = m_voiceCapabilities.isUnknown() ? CVoiceCapabilities(m_remarks) : m_voiceCapabilities;
m_flightOperator =
this->getRemark(remarks, "OPR/"); // operator, e.g. British airways, sometimes people use ICAO code here
m_selcalCode = CSelcal(this->getRemark(remarks, "SEL/"));
getRemark(remarks, "OPR/"); // operator, e.g. British airways, sometimes people use ICAO code here
m_selcalCode = CSelcal(getRemark(remarks, "SEL/"));
m_radioTelephony = getRemark(remarks, "CALLSIGN/"); // used similar to radio telephony
if (m_radioTelephony.isEmpty()) { m_radioTelephony = getRemark(remarks, "RT/"); }
if (!m_flightOperator.isEmpty() && CAirlineIcaoCode::isValidAirlineDesignator(m_flightOperator))

View File

@@ -262,7 +262,7 @@ namespace swift::misc
m_revisionFileName(revisionFileName)
{}
const QString &CDataCacheSerializer::persistentStore() const { return m_cache->persistentStore(); }
const QString &CDataCacheSerializer::persistentStore() const { return CDataCache::persistentStore(); }
void CDataCacheSerializer::saveToStore(const swift::misc::CVariantMap &values,
const swift::misc::CValueCachePacket &baseline)

View File

@@ -211,12 +211,12 @@ namespace swift::misc
if (ok)
{
CLogMessage(this).info(u"Adding '%1' to the new connection '%2'")
<< key << this->getDBusInterfaceFromClassInfo(i.value());
<< key << getDBusInterfaceFromClassInfo(i.value());
}
else
{
CLogMessage(this).info(u"Adding '%1' failed, connection '%2', error '%3'")
<< key << this->getDBusInterfaceFromClassInfo(i.value()) << connection.lastError().message();
<< key << getDBusInterfaceFromClassInfo(i.value()) << connection.lastError().message();
success = false;
}
}

View File

@@ -132,6 +132,7 @@ namespace swift::misc::simulation
QJsonObject CAircraftModel::toMemoizedJson(MemoHelper::CMemoizer &helper) const
{
QJsonObject json;
// NOLINTBEGIN(readability-static-accessed-through-instance)
introspect<CAircraftModel>().forEachMember([&, this](auto member) {
if constexpr (!decltype(member)::has(MetaFlags<DisabledForJson>()))
{
@@ -139,11 +140,13 @@ namespace swift::misc::simulation
json << std::make_pair(CExplicitLatin1String(member.latin1Name()), std::cref(maybeMemo));
}
});
// NOLINTEND(readability-static-accessed-through-instance)
return json;
}
void CAircraftModel::convertFromMemoizedJson(const QJsonObject &json, const MemoHelper::CUnmemoizer &helper)
{
// NOLINTBEGIN(readability-static-accessed-through-instance)
introspect<CAircraftModel>().forEachMember([&, this](auto member) {
if constexpr (!decltype(member)::has(MetaFlags<DisabledForJson>()))
{
@@ -151,6 +154,7 @@ namespace swift::misc::simulation
if (it != json.end()) { it.value() >> helper.maybeUnmemoize(member.in(*this)).get(); }
}
});
// NOLINTEND(readability-static-accessed-through-instance)
}
QString CAircraftModel::asHtmlSummary(const QString &separator) const

View File

@@ -38,7 +38,7 @@ namespace swift::simplugin::emulated
this->onSettingsChanged(); // init from settings
m_myAircraft = this->getOwnAircraft(); // sync with provider
m_monitorWidget = new CSimulatorEmulatedMonitorDialog(this, sGui->mainApplicationWidget());
m_monitorWidget = new CSimulatorEmulatedMonitorDialog(this, CGuiApplication::mainApplicationWidget());
connect(qApp, &QApplication::aboutToQuit, this, &CSimulatorEmulated::closeMonitor);
connect(sGui, &CGuiApplication::aboutToShutdown, this, &CSimulatorEmulated::closeMonitor, Qt::QueuedConnection);

View File

@@ -386,7 +386,7 @@ namespace swift::simplugin::flightgear
if (!m_serviceProxy) { return; }
CLogMessage(this).info(u"FG DBus service unregistered");
if (m_dbusMode == P2P) { m_dBusConnection.disconnectFromPeer(m_dBusConnection.name()); }
if (m_dbusMode == P2P) { QDBusConnection::disconnectFromPeer(m_dBusConnection.name()); }
m_dBusConnection = QDBusConnection { "default" };
if (m_watcher) { m_watcher->setConnection(m_dBusConnection); }
delete m_serviceProxy;
@@ -1043,11 +1043,11 @@ namespace swift::simplugin::flightgear
m_conn = QDBusConnection::sessionBus();
if (!m_conn.isConnected())
{
m_conn.disconnectFromBus(m_conn.name());
QDBusConnection::disconnectFromBus(m_conn.name());
return;
}
checkConnectionCommon();
m_conn.disconnectFromBus(m_conn.name());
QDBusConnection::disconnectFromBus(m_conn.name());
}
void CSimulatorFlightgearListener::checkConnectionViaPeer(const QString &address)
@@ -1056,11 +1056,11 @@ namespace swift::simplugin::flightgear
if (!m_conn.isConnected())
{
// This is required to cleanup the connection in QtDBus
m_conn.disconnectFromPeer(m_conn.name());
QDBusConnection::disconnectFromPeer(m_conn.name());
return;
}
checkConnectionCommon();
m_conn.disconnectFromPeer(m_conn.name());
QDBusConnection::disconnectFromPeer(m_conn.name());
}
void CSimulatorFlightgearListener::checkConnectionCommon()
@@ -1103,7 +1103,7 @@ namespace swift::simplugin::flightgear
void CSimulatorFlightgearListener::serviceRegistered(const QString &serviceName)
{
if (serviceName == fgswiftbusServiceName()) { emit simulatorStarted(getPluginInfo()); }
m_conn.disconnectFromBus(m_conn.name());
QDBusConnection::disconnectFromBus(m_conn.name());
}
void CSimulatorFlightgearListener::fgSwiftBusServerSettingChanged()

View File

@@ -44,7 +44,7 @@ namespace swift::simplugin::common
{
if (!m_interpolationDisplayDialog)
{
QWidget *parentWidget = sGui ? sGui->mainApplicationWidget() : nullptr;
QWidget *parentWidget = sGui ? CGuiApplication::mainApplicationWidget() : nullptr;
auto *dialog = new CInterpolationLogDisplayDialog(this, nullptr, parentWidget);
m_interpolationDisplayDialog = dialog;
m_interpolationDisplayDialog->setModal(false);

View File

@@ -542,7 +542,7 @@ namespace swift::simplugin::xplane
if (!m_serviceProxy) { return; }
CLogMessage(this).info(u"XPlane xSwiftBus service unregistered");
if (m_dbusMode == P2P) { m_dBusConnection.disconnectFromPeer(m_dBusConnection.name()); }
if (m_dbusMode == P2P) { QDBusConnection::disconnectFromPeer(m_dBusConnection.name()); }
m_dBusConnection = QDBusConnection { "default" };
if (m_watcher) { m_watcher->setConnection(m_dBusConnection); }
delete m_serviceProxy;
@@ -1373,11 +1373,11 @@ namespace swift::simplugin::xplane
m_DBusConnection = QDBusConnection::sessionBus();
if (!m_DBusConnection.isConnected())
{
m_DBusConnection.disconnectFromBus(m_DBusConnection.name());
QDBusConnection::disconnectFromBus(m_DBusConnection.name());
return;
}
checkConnectionCommon(); // bus
m_DBusConnection.disconnectFromBus(m_DBusConnection.name());
QDBusConnection::disconnectFromBus(m_DBusConnection.name());
}
void CSimulatorXPlaneListener::checkConnectionViaPeer(const QString &address)
@@ -1386,11 +1386,11 @@ namespace swift::simplugin::xplane
if (!m_DBusConnection.isConnected())
{
// This is required to cleanup the connection in QtDBus
m_DBusConnection.disconnectFromPeer(m_DBusConnection.name());
QDBusConnection::disconnectFromPeer(m_DBusConnection.name());
return;
}
checkConnectionCommon(); // peer
m_DBusConnection.disconnectFromPeer(m_DBusConnection.name());
QDBusConnection::disconnectFromPeer(m_DBusConnection.name());
}
void CSimulatorXPlaneListener::checkConnectionCommon()
@@ -1441,7 +1441,7 @@ namespace swift::simplugin::xplane
void CSimulatorXPlaneListener::serviceRegistered(const QString &serviceName)
{
if (serviceName == xswiftbusServiceName()) { emit simulatorStarted(getPluginInfo()); }
m_DBusConnection.disconnectFromBus(m_DBusConnection.name());
QDBusConnection::disconnectFromBus(m_DBusConnection.name());
}
void CSimulatorXPlaneListener::onXSwiftBusServerSettingChanged()

View File

@@ -183,7 +183,7 @@ void CSwiftLauncher::clearWindowsRegistry()
CSwiftLauncher::~CSwiftLauncher() = default;
QString CSwiftLauncher::getCmdLine() const { return this->toCmdLine(m_executable, m_executableArgs); }
QString CSwiftLauncher::getCmdLine() const { return toCmdLine(m_executable, m_executableArgs); }
bool CSwiftLauncher::startDetached()
{
@@ -500,7 +500,7 @@ void CSwiftLauncher::checkRunningApplicationsAndCore()
if (m_startMappingToolWaitCycles > 0) { m_startMappingToolWaitCycles--; }
if (m_startGuiWaitCycles > 0) { m_startGuiWaitCycles--; }
const CApplicationInfoList runningApps = sGui->getRunningApplications();
const CApplicationInfoList runningApps = CGuiApplication::getRunningApplications();
const bool foundLocalCore = runningApps.containsApplication(CApplicationInfo::PilotClientCore);
const bool foundLocalMappingTool = runningApps.containsApplication(CApplicationInfo::MappingTool);
const bool foundLocalPilotClientGui = runningApps.containsApplication(CApplicationInfo::PilotClientGui);