From f311582c28b1f639c9ffd5d6ee660a566c5235da Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Tue, 19 Aug 2014 21:54:23 +0100 Subject: [PATCH] refs #315 Style --- src/blackcore/context_application.cpp | 5 ++--- src/blackcore/context_application_impl.cpp | 10 ++++------ src/blackcore/context_audio_impl.cpp | 22 +++++++--------------- src/blackcore/context_ownaircraft_impl.cpp | 4 +--- src/blackcore/context_runtime.cpp | 9 +++------ src/blackcore/context_runtime.h | 8 ++++---- src/blackcore/context_settings_impl.cpp | 2 +- src/blackcore/context_settings_impl.h | 6 +++--- src/blackcore/context_simulator.h | 2 +- src/blackcore/context_simulator_impl.cpp | 13 +++++++------ src/blackcore/context_simulator_impl.h | 2 +- 11 files changed, 34 insertions(+), 49 deletions(-) diff --git a/src/blackcore/context_application.cpp b/src/blackcore/context_application.cpp index ee515fa60..970819297 100644 --- a/src/blackcore/context_application.cpp +++ b/src/blackcore/context_application.cpp @@ -88,7 +88,7 @@ namespace BlackCore void IContextApplication::changeSettings(uint typeValue) { - IContextSettings::SettingsType type = static_cast(typeValue); + auto type = static_cast(typeValue); switch (type) { case IContextSettings::SettingsHotKeys: @@ -109,8 +109,7 @@ namespace BlackCore { if (IContextApplication::s_oldHandler) IContextApplication::s_oldHandler(type, messageContext, message); if (IContextApplication::s_contexts.isEmpty()) return; - IContextApplication *ctx; - foreach(ctx, IContextApplication::s_contexts) + foreach(IContextApplication *ctx, IContextApplication::s_contexts) { ctx->messageHandler(type, messageContext, message); } diff --git a/src/blackcore/context_application_impl.cpp b/src/blackcore/context_application_impl.cpp index f15f95b86..82790c28f 100644 --- a/src/blackcore/context_application_impl.cpp +++ b/src/blackcore/context_application_impl.cpp @@ -61,14 +61,13 @@ namespace BlackCore this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, { fileName, content.left(25) }); if (fileName.isEmpty()) return false; QFile file(fileName); - bool success = false; - if ((success = file.open(QIODevice::WriteOnly | QIODevice::Text))) + if (file.open(QIODevice::WriteOnly | QIODevice::Text)) { QTextStream out(&file); out << content; - file.close(); + return true; } - return success; + else return false; } /* @@ -80,8 +79,7 @@ namespace BlackCore QFile file(fileName); QString content; if (fileName.isEmpty()) return content; - bool success = false; - if ((success = file.open(QIODevice::ReadOnly | QIODevice::Text))) + if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream in(&file); in >> content; diff --git a/src/blackcore/context_audio_impl.cpp b/src/blackcore/context_audio_impl.cpp index c54c8116e..662a2a3a0 100644 --- a/src/blackcore/context_audio_impl.cpp +++ b/src/blackcore/context_audio_impl.cpp @@ -301,7 +301,7 @@ namespace BlackCore Q_ASSERT(this->m_voice); this->getRuntime()->logSlot(c_logContext, Q_FUNC_INFO, QString::number(notification)); - BlackSound::CNotificationSounds::Notification notificationSound = static_cast(notification); + auto notificationSound = static_cast(notification); if (considerSettings) { Q_ASSERT(this->getIContextSettings()); @@ -388,16 +388,12 @@ namespace BlackCore break; case IVoiceChannel::ConnectingFailed: case IVoiceChannel::DisconnectedError: - { - const QString e = QString("Voice room COM1 error"); - qWarning(e.toUtf8().constData()); - - // no break here! - } + qWarning() << "Voice room COM1 error"; + // intentional fall-through case IVoiceChannel::Disconnected: - // good chance to update aircraft if (this->getIContextOwnAircraft()) { + // good chance to update aircraft m_channelCom1->setMyAircraftCallsign(this->getIContextOwnAircraft()->getOwnAircraft().getCallsign()); m_channelCom2->setMyAircraftCallsign(this->getIContextOwnAircraft()->getOwnAircraft().getCallsign()); } @@ -423,16 +419,12 @@ namespace BlackCore break; case IVoiceChannel::ConnectingFailed: case IVoiceChannel::DisconnectedError: - { - const QString e = QString("Voice room COM2 error"); - qWarning(e.toUtf8().constData()); - - // no break here! - } + qWarning() << "Voice room COM2 error"; + // intentional fall-through case IVoiceChannel::Disconnected: - // good chance to update aircraft if (this->getIContextOwnAircraft()) { + // good chance to update aircraft m_channelCom1->setMyAircraftCallsign(this->getIContextOwnAircraft()->getOwnAircraft().getCallsign()); m_channelCom2->setMyAircraftCallsign(this->getIContextOwnAircraft()->getOwnAircraft().getCallsign()); } diff --git a/src/blackcore/context_ownaircraft_impl.cpp b/src/blackcore/context_ownaircraft_impl.cpp index 60fbf8337..7dd4dc0bd 100644 --- a/src/blackcore/context_ownaircraft_impl.cpp +++ b/src/blackcore/context_ownaircraft_impl.cpp @@ -76,12 +76,10 @@ namespace BlackCore if (!this->getIContextAudio()) return; // no place to set rooms if (!this->m_automaticVoiceRoomResolution) return; // not responsible - CVoiceRoomList rooms; - // requires correct frequencies set // but local network uses exactly this object here, so if frequencies are set here, // they are for network context as well - rooms = this->getIContextNetwork()->getSelectedVoiceRooms(); + CVoiceRoomList rooms = this->getIContextNetwork()->getSelectedVoiceRooms(); if (!this->m_voiceRoom1UrlOverride.isEmpty()) rooms[0] = CVoiceRoom(this->m_voiceRoom1UrlOverride); if (!this->m_voiceRoom2UrlOverride.isEmpty()) rooms[1] = CVoiceRoom(this->m_voiceRoom2UrlOverride); diff --git a/src/blackcore/context_runtime.cpp b/src/blackcore/context_runtime.cpp index d06db9f4d..66c08537a 100644 --- a/src/blackcore/context_runtime.cpp +++ b/src/blackcore/context_runtime.cpp @@ -305,7 +305,6 @@ namespace BlackCore this->connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, this, &CRuntime::gracefulShutdown); // upfront reading of settings, as DBus server already relies on settings - CContextSettings *settings = nullptr; QString dbusAddress; QMap times; QTime time; @@ -316,7 +315,7 @@ namespace BlackCore if (config.hasDBusAddress()) dbusAddress = config.getDBusAddress(); // bootstrap / explicit if (config.hasLocalSettings()) { - settings = new CContextSettings(config.getModeSettings(), this); + auto *settings = new CContextSettings(config.getModeSettings(), this); if (settings) settings->read(); if (dbusAddress.isEmpty()) dbusAddress = settings->getNetworkSettings().getDBusServerAddress(); @@ -396,7 +395,7 @@ namespace BlackCore void CRuntime::initPostSetup() { - bool c; + bool c = false; Q_UNUSED(c); // for release version if (this->m_contextSettings && this->m_contextApplication) @@ -548,11 +547,9 @@ namespace BlackCore void CRuntime::disconnectLogSignals(const QString &name) { if (!this->m_logSignalConnections.contains(name)) return; - QMultiMap::const_iterator i = this->m_logSignalConnections.constFind(name); - while (i != this->m_logSignalConnections.end() && i.key() == name) + for (auto i = this->m_logSignalConnections.lowerBound(name), end = this->m_logSignalConnections.upperBound(name); i != end; ++i) { disconnect(i.value()); - ++i; } this->m_logSignalConnections.remove(name); } diff --git a/src/blackcore/context_runtime.h b/src/blackcore/context_runtime.h index 8e21d81c3..370a85ab3 100644 --- a/src/blackcore/context_runtime.h +++ b/src/blackcore/context_runtime.h @@ -225,10 +225,10 @@ namespace BlackCore const IContextAudio *getIContextAudio() const; //! Context for application - const IContextApplication *getIContextApplication() const; + IContextApplication *getIContextApplication(); //! Context for application - IContextApplication *getIContextApplication(); + const IContextApplication *getIContextApplication() const; //! Context for own aircraft IContextOwnAircraft *getIContextOwnAircraft(); @@ -243,10 +243,10 @@ namespace BlackCore const IContextSettings *getIContextSettings() const; //! Context for simulator - const IContextSimulator *getIContextSimulator() const; + IContextSimulator *getIContextSimulator(); //! Context for simulator - IContextSimulator *getIContextSimulator(); + const IContextSimulator *getIContextSimulator() const; // ------- Context as implementing (local) class diff --git a/src/blackcore/context_settings_impl.cpp b/src/blackcore/context_settings_impl.cpp index 8b49c8db8..5512f9d9f 100644 --- a/src/blackcore/context_settings_impl.cpp +++ b/src/blackcore/context_settings_impl.cpp @@ -230,7 +230,7 @@ namespace BlackCore { if (command == CSettingUtilities::CmdUpdate()) { - BlackMisc::Settings::CSettingKeyboardHotkeyList hotkeys = value.value(); + auto hotkeys = value.value(); this->m_hotkeys = hotkeys; msgs.push_back(this->write()); // write settings emit this->changedSettings(static_cast(SettingsHotKeys)); diff --git a/src/blackcore/context_settings_impl.h b/src/blackcore/context_settings_impl.h index 98c6447d1..34d30f942 100644 --- a/src/blackcore/context_settings_impl.h +++ b/src/blackcore/context_settings_impl.h @@ -43,9 +43,6 @@ namespace BlackCore //! Destructor virtual ~CContextSettings() {} - //! settings file - const QString &getSettingsDirectory() const { return BlackMisc::Settings::CSettingUtilities::getSettingsDirectory(); } - //! \copydoc IContextSettings::value() virtual BlackMisc::CStatusMessageList value(const QString &path, const QString &command, const BlackMisc::CVariant &value) override; @@ -78,6 +75,9 @@ namespace BlackCore virtual QString getSettingsAsJsonString() const override; private: + //! settings directory + const QString &getSettingsDirectory() const { return BlackMisc::Settings::CSettingUtilities::getSettingsDirectory(); } + BlackMisc::Settings::CSettingsNetwork m_settingsNetwork; BlackMisc::Settings::CSettingsAudio m_settingsAudio; BlackSim::Settings::CSettingsSimulator m_settingsSimulator; diff --git a/src/blackcore/context_simulator.h b/src/blackcore/context_simulator.h index bf4691025..0efd2ed67 100644 --- a/src/blackcore/context_simulator.h +++ b/src/blackcore/context_simulator.h @@ -64,7 +64,7 @@ namespace BlackCore signals: //! Emitted when the simulator connection changes - void connectionChanged(bool value); + void connectionChanged(bool connected); //! Emitted when own aircraft model changes (TODO move to own aircraft context?) void ownAircraftModelChanged(BlackMisc::Network::CAircraftModel model); diff --git a/src/blackcore/context_simulator_impl.cpp b/src/blackcore/context_simulator_impl.cpp index d1fa22d57..0ecfc272c 100644 --- a/src/blackcore/context_simulator_impl.cpp +++ b/src/blackcore/context_simulator_impl.cpp @@ -140,8 +140,7 @@ namespace BlackCore return false; } - ISimulatorFactory *factory = nullptr; - QSet::iterator iterator = std::find_if(m_simulatorFactories.begin(), m_simulatorFactories.end(), [ = ](const ISimulatorFactory * factory) + auto iterator = std::find_if(m_simulatorFactories.begin(), m_simulatorFactories.end(), [ = ](const ISimulatorFactory * factory) { return factory->getSimulatorInfo() == simulatorInfo; }); @@ -155,7 +154,7 @@ namespace BlackCore return false; } - factory = *iterator; + ISimulatorFactory *factory = *iterator; Q_ASSERT(factory); ISimulator *newSimulator = factory->create(this); @@ -164,7 +163,7 @@ namespace BlackCore this->unloadSimulatorPlugin(); // old plugin unloaded m_simulator = newSimulator; - connect(m_simulator, SIGNAL(statusChanged(ISimulator::Status)), this, SLOT(ps_setConnectionStatus(ISimulator::Status))); + connect(m_simulator, &ISimulator::statusChanged, this, &CContextSimulator::ps_setConnectionStatus); connect(m_simulator, &ISimulator::aircraftModelChanged, this, &IContextSimulator::ownAircraftModelChanged); if (this->getIContextApplication() && this->getIContextApplication()->usingLocalObjects()) { @@ -194,6 +193,8 @@ namespace BlackCore Q_ASSERT(this->getIContextSettings()); if (!this->getIContextSettings()) return false; + // TODO warnings if we didn't load the plugin which the settings asked for + CSimulatorInfoList plugins = this->getAvailableSimulatorPlugins(); if (plugins.size() == 1) { @@ -220,7 +221,7 @@ namespace BlackCore { if (m_simulator) { - disconnect(m_simulator); // disconnect as receiver straight away + this->QObject::disconnect(m_simulator); // disconnect as receiver straight away m_simulator->disconnectFrom(); // disconnect from simulator m_simulator->deleteLater(); } @@ -308,7 +309,7 @@ namespace BlackCore Q_ASSERT(this->getIContextSettings()); Q_ASSERT(this->m_simulator); if (!this->getIContextSettings()) return; - IContextSettings::SettingsType settingsType = static_cast(type); + auto settingsType = static_cast(type); if (settingsType != IContextSettings::SettingsSimulator) return; // plugin diff --git a/src/blackcore/context_simulator_impl.h b/src/blackcore/context_simulator_impl.h index b1b42e441..7a5bd34dc 100644 --- a/src/blackcore/context_simulator_impl.h +++ b/src/blackcore/context_simulator_impl.h @@ -75,7 +75,7 @@ namespace BlackCore virtual bool loadSimulatorPlugin(const BlackSim::CSimulatorInfo &simulatorInfo) override; //! \copydoc IContextSimulator::loadSimulatorPluginFromSettings() - virtual bool loadSimulatorPluginFromSettings(); + virtual bool loadSimulatorPluginFromSettings() override; //! \copydoc IContextSimulator::unloadSimulatorPlugin() virtual void unloadSimulatorPlugin() override;