diff --git a/src/blackgui/components/aircraftcomponent.cpp b/src/blackgui/components/aircraftcomponent.cpp index c6c5ac239..f85eedbe5 100644 --- a/src/blackgui/components/aircraftcomponent.cpp +++ b/src/blackgui/components/aircraftcomponent.cpp @@ -10,7 +10,8 @@ #include "aircraftcomponent.h" #include "ui_aircraftcomponent.h" #include "enablefordockwidgetinfoarea.h" -#include "../guiutility.h" +#include "blackgui/guiutility.h" +#include "blackgui/guiapplication.h" #include "blackcore/contextnetwork.h" #include "blackcore/contextsimulator.h" #include "blackcore/network.h" @@ -43,6 +44,7 @@ namespace BlackGui connect(this->ui->tvp_AircraftInRange, &CSimulatedAircraftView::requestTextMessageWidget, this, &CAircraftComponent::requestTextMessageWidget); connect(this->ui->tvp_AircraftInRange, &CSimulatedAircraftView::requestHighlightInSimulator, this, &CAircraftComponent::ps_onMenuHighlightInSimulator); connect(this->ui->tvp_AirportsInRange, &CSimulatedAircraftView::rowCountChanged, this, &CAircraftComponent::ps_onRowCountChanged); + connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CAircraftComponent::ps_connectionStatusChanged); } CAircraftComponent::~CAircraftComponent() @@ -60,46 +62,48 @@ namespace BlackGui return this->ui->tvp_AirportsInRange->rowCount(); } + bool CAircraftComponent::setParentDockWidgetInfoArea(CDockWidgetInfoArea *parentDockableWidget) + { + CEnableForDockWidgetInfoArea::setParentDockWidgetInfoArea(parentDockableWidget); + bool c = connect(this->getParentInfoArea(), &CInfoArea::changedInfoAreaTabBarIndex, this, &CAircraftComponent::ps_infoAreaTabBarChanged); + Q_ASSERT_X(c, Q_FUNC_INFO, "failed connect"); + Q_ASSERT_X(parentDockableWidget, Q_FUNC_INFO, "missing parent"); + return c && parentDockableWidget; + } + void CAircraftComponent::update() { Q_ASSERT(this->ui->tvp_AircraftInRange); - Q_ASSERT(this->getIContextNetwork()); - Q_ASSERT(this->getIContextSimulator()); + Q_ASSERT(sGui->getIContextNetwork()); + Q_ASSERT(sGui->getIContextSimulator()); - if (this->getIContextNetwork()->isConnected()) + if (sGui->getIContextNetwork()->isConnected()) { bool visible = (this->isVisibleWidget() && this->currentWidget() == this->ui->tb_AircraftInRange); if (this->countAircraft() < 1 || visible) { - this->ui->tvp_AircraftInRange->updateContainer(this->getIContextNetwork()->getAircraftInRange()); + this->ui->tvp_AircraftInRange->updateContainer(sGui->getIContextNetwork()->getAircraftInRange()); } } - if (this->getIContextSimulator()->getSimulatorStatus() > 0) + if (sGui->getIContextSimulator()->getSimulatorStatus() > 0) { bool visible = (this->isVisibleWidget() && this->currentWidget() == this->ui->tb_AirportsInRange); if (this->countAirportsInRange() < 1 || visible) { - this->ui->tvp_AirportsInRange->updateContainer(this->getIContextSimulator()->getAirportsInRange()); + this->ui->tvp_AirportsInRange->updateContainer(sGui->getIContextSimulator()->getAirportsInRange()); } } } - void CAircraftComponent::runtimeHasBeenSet() - { - Q_ASSERT(this->getIContextNetwork()); - connect(this->getParentInfoArea(), &CInfoArea::changedInfoAreaTabBarIndex, this, &CAircraftComponent::ps_infoAreaTabBarChanged); - connect(this->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CAircraftComponent::ps_connectionStatusChanged); - } - void CAircraftComponent::ps_infoAreaTabBarChanged(int index) { // ignore in those cases if (!this->isVisibleWidget()) return; if (this->isParentDockWidgetFloating()) return; - if (!this->getIContextNetwork()->isConnected()) return; + if (!sGui->getIContextNetwork()->isConnected()) return; - // here I know I am the selected widget, update, but keep GUI responsive (hence - QTimer::singleShot(1000, this, SLOT(update())); + // here I know I am the selected widget, update, but keep GUI responsive (hence I use a timer) + QTimer::singleShot(1000, this, &CAircraftComponent::update); Q_UNUSED(index); } @@ -128,9 +132,9 @@ namespace BlackGui void CAircraftComponent::ps_onMenuHighlightInSimulator(const CSimulatedAircraft &aircraft) { - if (getIContextSimulator()) + if (sGui->getIContextSimulator()) { - getIContextSimulator()->highlightAircraft(aircraft, true, IContextSimulator::HighlightTime()); + sGui->getIContextSimulator()->highlightAircraft(aircraft, true, IContextSimulator::HighlightTime()); } } diff --git a/src/blackgui/components/aircraftcomponent.h b/src/blackgui/components/aircraftcomponent.h index 643945833..646fae7d0 100644 --- a/src/blackgui/components/aircraftcomponent.h +++ b/src/blackgui/components/aircraftcomponent.h @@ -13,7 +13,6 @@ #define BLACKGUI_AIRCRAFTCOMPONENT_H #include "blackgui/blackguiexport.h" -#include "blackgui/components/enableforruntime.h" #include "blackgui/components/enablefordockwidgetinfoarea.h" #include "blackgui/components/updatetimer.h" #include "blackcore/network.h" @@ -29,8 +28,7 @@ namespace BlackGui //! Aircraft widget class BLACKGUI_EXPORT CAircraftComponent : public QTabWidget, - public CEnableForDockWidgetInfoArea, - public CEnableForRuntime + public CEnableForDockWidgetInfoArea { Q_OBJECT @@ -47,6 +45,9 @@ namespace BlackGui //! Airports in range int countAirportsInRange() const; + //! \copydoc CEnableForDockWidgetInfoArea::setParentDockWidgetInfoArea + virtual bool setParentDockWidgetInfoArea(BlackGui::CDockWidgetInfoArea *parentDockableWidget) override; + signals: //! Request a text message void requestTextMessageWidget(const BlackMisc::Aviation::CCallsign &callsign); @@ -61,10 +62,6 @@ namespace BlackGui //! \copydoc CUpdateTimer::stopTimer void stopTimer() { Q_ASSERT(this->m_updateTimer); this->m_updateTimer->stopTimer(); } - protected: - //! \copydoc CEnableForRuntime::runtimeHasBeenSet - void runtimeHasBeenSet() override; - private slots: //! Info area tab bar has changed void ps_infoAreaTabBarChanged(int index); diff --git a/src/blackgui/components/atcstationcomponent.cpp b/src/blackgui/components/atcstationcomponent.cpp index 4383d9267..69c7134a4 100644 --- a/src/blackgui/components/atcstationcomponent.cpp +++ b/src/blackgui/components/atcstationcomponent.cpp @@ -8,8 +8,9 @@ */ #include "atcstationcomponent.h" -#include "../guiutility.h" #include "ui_atcstationcomponent.h" +#include "blackgui/guiutility.h" +#include "blackgui/guiapplication.h" #include "blackmisc/aviation/informationmessage.h" #include "blackmisc/logmessage.h" #include "blackmisc/weather/metar.h" @@ -70,6 +71,12 @@ namespace BlackGui connect(this->ui->tvp_AtcStationsBooked, &CAtcStationView::rowCountChanged, this, &CAtcStationComponent::ps_onCountChanged); connect(this->ui->pb_AtcStationsAtisReload, &QPushButton::clicked, this, &CAtcStationComponent::ps_requestAtis); + + // runtime based connects + this->connect(sGui->getIContextNetwork(), &IContextNetwork::changedAtcStationsOnlineDigest, this, &CAtcStationComponent::ps_changedAtcStationsOnline); + this->connect(sGui->getIContextNetwork(), &IContextNetwork::changedAtcStationsBookedDigest, this, &CAtcStationComponent::ps_changedAtcStationsBooked); + this->connect(sGui->getIContextNetwork(), &IContextNetwork::changedAtcStationOnlineConnectionStatus, this, &CAtcStationComponent::changedAtcStationOnlineConnectionStatus); + this->connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CAtcStationComponent::ps_connectionStatusChanged); } CAtcStationComponent::~CAtcStationComponent() @@ -85,25 +92,20 @@ namespace BlackGui return ui->tvp_AtcStationsOnline->rowCount(); } - void CAtcStationComponent::runtimeHasBeenSet() + bool CAtcStationComponent::setParentDockWidgetInfoArea(CDockWidgetInfoArea *parentDockableWidget) { - Q_ASSERT(this->getRuntime()); - Q_ASSERT(this->getIContextNetwork()); - if (this->getIContextNetwork()) - { - this->connect(this->getIContextNetwork(), &IContextNetwork::changedAtcStationsOnlineDigest, this, &CAtcStationComponent::ps_changedAtcStationsOnline); - this->connect(this->getIContextNetwork(), &IContextNetwork::changedAtcStationsBookedDigest, this, &CAtcStationComponent::ps_changedAtcStationsBooked); - this->connect(this->getIContextNetwork(), &IContextNetwork::changedAtcStationOnlineConnectionStatus, this, &CAtcStationComponent::changedAtcStationOnlineConnectionStatus); - this->connect(this->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CAtcStationComponent::ps_connectionStatusChanged); - } - connect(this->getParentInfoArea(), &CInfoArea::changedInfoAreaTabBarIndex, this, &CAtcStationComponent::ps_infoAreaTabBarChanged); + CEnableForDockWidgetInfoArea::setParentDockWidgetInfoArea(parentDockableWidget); + bool c = connect(this->getParentInfoArea(), &CInfoArea::changedInfoAreaTabBarIndex, this, &CAtcStationComponent::ps_infoAreaTabBarChanged); + Q_ASSERT_X(c, Q_FUNC_INFO, "failed connect"); + Q_ASSERT_X(parentDockableWidget, Q_FUNC_INFO, "missing parent"); + return c && parentDockableWidget; } void CAtcStationComponent::update() { Q_ASSERT(this->ui->tvp_AtcStationsBooked); Q_ASSERT(this->ui->tvp_AtcStationsOnline); - Q_ASSERT(this->getIContextNetwork()); + Q_ASSERT(sGui->getIContextNetwork()); // check if component is visible, if we have already data then skip udpate bool hasData = this->countBookedStations() > 0 || this->countOnlineStations() > 0; @@ -120,15 +122,15 @@ namespace BlackGui } // online stations, only when connected - if (this->getIContextNetwork()->isConnected()) + if (sGui->getIContextNetwork()->isConnected()) { // update if (this->m_timestampOnlineStationsChanged > this->m_timestampLastReadOnlineStations) { this->ui->tvp_AtcStationsOnline->updateContainerMaybeAsync( // test: filter by frequency, see if this is better - // this->getIContextNetwork()->getAtcStationsOnline().stationsWithValidVoiceRoom() - this->getIContextNetwork()->getAtcStationsOnline().stationsWithValidFrequency() + // sGui->getIContextNetwork()->getAtcStationsOnline().stationsWithValidVoiceRoom() + sGui->getIContextNetwork()->getAtcStationsOnline().stationsWithValidFrequency() ); this->m_timestampLastReadOnlineStations = QDateTime::currentDateTimeUtc(); this->m_timestampOnlineStationsChanged = this->m_timestampLastReadOnlineStations; @@ -152,7 +154,7 @@ namespace BlackGui QString icao(airportIcaoCode.isEmpty() ? this->ui->le_AtcStationsOnlineMetar->text().trimmed().toUpper() : airportIcaoCode.trimmed().toUpper()); this->ui->le_AtcStationsOnlineMetar->setText(icao); if (icao.length() != 4) { return; } - CMetar metar(this->getIContextNetwork()->getMetarForAirport(icao)); + CMetar metar(sGui->getIContextNetwork()->getMetarForAirport(icao)); if (metar == CMetar()) { this->ui->te_AtcStationsOnlineInfo->clear(); @@ -170,18 +172,18 @@ namespace BlackGui void CAtcStationComponent::ps_reloadAtcStationsBooked() { Q_ASSERT(this->ui->tvp_AtcStationsBooked); - Q_ASSERT(this->getIContextNetwork()); + Q_ASSERT(sGui->getIContextNetwork()); QObject *sender = QObject::sender(); - if (sender == this->ui->tvp_AtcStationsBooked && this->getIContextNetwork()) + if (sender == this->ui->tvp_AtcStationsBooked && sGui->getIContextNetwork()) { // trigger new read, which takes some time. A signal will be received when this is done CLogMessage(this).info("Requested new bookings"); - this->getIContextNetwork()->readAtcBookingsFromSource(); + sGui->getIContextNetwork()->readAtcBookingsFromSource(); } else { - this->ui->tvp_AtcStationsBooked->updateContainerMaybeAsync(this->getIContextNetwork()->getAtcStationsBooked()); + this->ui->tvp_AtcStationsBooked->updateContainerMaybeAsync(sGui->getIContextNetwork()->getAtcStationsBooked()); this->m_timestampLastReadBookedStations = QDateTime::currentDateTimeUtc(); } } @@ -214,9 +216,9 @@ namespace BlackGui void CAtcStationComponent::ps_testCreateDummyOnlineAtcStations(int number) { - if (this->getIContextNetwork()) + if (sGui->getIContextNetwork()) { - this->getIContextNetwork()->testCreateDummyOnlineAtcStations(number); + sGui->getIContextNetwork()->testCreateDummyOnlineAtcStations(number); } } @@ -255,7 +257,7 @@ namespace BlackGui { if (unit != CComSystem::Com1 && unit != CComSystem::Com2) { return; } if (!CComSystem::isValidComFrequency(frequency)) { return; } - this->getIContextOwnAircraft()->updateActiveComFrequency(frequency, unit, identifier()); + sGui->getIContextOwnAircraft()->updateActiveComFrequency(frequency, unit, identifier()); } void CAtcStationComponent::updateTreeView() @@ -307,8 +309,8 @@ namespace BlackGui void CAtcStationComponent::ps_requestAtis() { - if (!this->getIContextNetwork()->isConnected()) return; - this->getIContextNetwork()->requestAtisUpdates(); + if (!sGui->getIContextNetwork()->isConnected()) return; + sGui->getIContextNetwork()->requestAtisUpdates(); } } // namespace } // namespace diff --git a/src/blackgui/components/atcstationcomponent.h b/src/blackgui/components/atcstationcomponent.h index 4d935a11f..35dceae06 100644 --- a/src/blackgui/components/atcstationcomponent.h +++ b/src/blackgui/components/atcstationcomponent.h @@ -13,7 +13,6 @@ #define BLACKGUI_ATCSTATIONCOMPONENT_H #include "blackgui/blackguiexport.h" -#include "blackgui/components/enableforruntime.h" #include "blackgui/components/enablefordockwidgetinfoarea.h" #include "blackgui/components/updatetimer.h" #include "blackcore/network.h" @@ -33,7 +32,6 @@ namespace BlackGui class BLACKGUI_EXPORT CAtcStationComponent : public QTabWidget, public CEnableForDockWidgetInfoArea, - public CEnableForRuntime, public BlackMisc::CIdentifiable { Q_OBJECT @@ -51,6 +49,9 @@ namespace BlackGui //! Number of online stations int countOnlineStations() const; + //! \copydoc CEnableForDockWidgetInfoArea::setParentDockWidgetInfoArea + virtual bool setParentDockWidgetInfoArea(BlackGui::CDockWidgetInfoArea *parentDockableWidget) override; + signals: //! Request a text message void requestTextMessageWidget(const BlackMisc::Aviation::CCallsign &callsign); @@ -71,10 +72,6 @@ namespace BlackGui //! \copydoc Models::CAtcStationListModel::changedAtcStationConnectionStatus void changedAtcStationOnlineConnectionStatus(const BlackMisc::Aviation::CAtcStation &station, bool added); - protected: - //! \copydoc CEnableForRuntime::runtimeHasBeenSet - void runtimeHasBeenSet() override; - private slots: //! Get all METARs void ps_getMetarAsEntered() { this->getMetar(""); } diff --git a/src/blackgui/components/audiosetupcomponent.cpp b/src/blackgui/components/audiosetupcomponent.cpp index 31e52957a..9b4cf53cb 100644 --- a/src/blackgui/components/audiosetupcomponent.cpp +++ b/src/blackgui/components/audiosetupcomponent.cpp @@ -9,6 +9,7 @@ #include "audiosetupcomponent.h" #include "ui_audiosetupcomponent.h" +#include "blackgui/guiapplication.h" #include "blackcore/contextaudio.h" #include "blackmisc/logmessage.h" @@ -32,40 +33,38 @@ namespace BlackGui bool c = connect(this->ui->tb_ExpandNotificationSounds, &QToolButton::toggled, this, &CAudioSetupComponent::ps_onToggleNotificationSoundsVisibility); Q_ASSERT(c); + Q_UNUSED(c); c = connect(this->ui->cb_SetupAudioLoopback, &QCheckBox::toggled, this, &CAudioSetupComponent::ps_onLoopbackToggled); Q_ASSERT(c); Q_UNUSED(c); - } - CAudioSetupComponent::~CAudioSetupComponent() - { } - - void CAudioSetupComponent::runtimeHasBeenSet() - { - // based on audio context - Q_ASSERT_X(this->getIContextAudio(), Q_FUNC_INFO, "missing audio"); - if (this->getIContextAudio()) + if (sGui->getIContextAudio()) { this->initAudioDeviceLists(); // default - this->ui->cb_SetupAudioLoopback->setChecked(this->getIContextAudio()->isAudioLoopbackEnabled()); + this->ui->cb_SetupAudioLoopback->setChecked(sGui->getIContextAudio()->isAudioLoopbackEnabled()); // the connects depend on initAudioDeviceLists - bool connected = this->connect(this->ui->cb_SetupAudioInputDevice, static_cast (&QComboBox::currentIndexChanged), this, &CAudioSetupComponent::ps_audioDeviceSelected); - Q_ASSERT(connected); - connected = this->connect(this->ui->cb_SetupAudioOutputDevice, static_cast (&QComboBox::currentIndexChanged), this, &CAudioSetupComponent::ps_audioDeviceSelected); - Q_ASSERT(connected); - Q_UNUSED(connected); + c = this->connect(this->ui->cb_SetupAudioInputDevice, static_cast (&QComboBox::currentIndexChanged), this, &CAudioSetupComponent::ps_audioDeviceSelected); + Q_ASSERT(c); + Q_UNUSED(c); + + c = this->connect(this->ui->cb_SetupAudioOutputDevice, static_cast (&QComboBox::currentIndexChanged), this, &CAudioSetupComponent::ps_audioDeviceSelected); + Q_ASSERT(c); + Q_UNUSED(c); // context - this->connect(this->getIContextAudio(), &IContextAudio::changedAudioDevices, this, &CAudioSetupComponent::ps_onAudioDevicesChanged); - this->connect(this->getIContextAudio(), &IContextAudio::changedSelectedAudioDevices, this, &CAudioSetupComponent::ps_onCurrentAudioDevicesChanged); + this->connect(sGui->getIContextAudio(), &IContextAudio::changedAudioDevices, this, &CAudioSetupComponent::ps_onAudioDevicesChanged); + this->connect(sGui->getIContextAudio(), &IContextAudio::changedSelectedAudioDevices, this, &CAudioSetupComponent::ps_onCurrentAudioDevicesChanged); } this->ps_reloadSettings(); this->ui->tb_ExpandNotificationSounds->setChecked(false); // collapse } + CAudioSetupComponent::~CAudioSetupComponent() + { } + void CAudioSetupComponent::ps_reloadSettings() { CSettingsAudio as(m_audioSettings.get()); @@ -81,9 +80,9 @@ namespace BlackGui void CAudioSetupComponent::initAudioDeviceLists() { - if (!this->getIContextAudio()) { return; } - this->ps_onAudioDevicesChanged(this->getIContextAudio()->getAudioDevices()); - this->ps_onCurrentAudioDevicesChanged(this->getIContextAudio()->getCurrentAudioDevices()); + if (!sGui->getIContextAudio()) { return; } + this->ps_onAudioDevicesChanged(sGui->getIContextAudio()->getAudioDevices()); + this->ps_onCurrentAudioDevicesChanged(sGui->getIContextAudio()->getCurrentAudioDevices()); } bool CAudioSetupComponent::playNotificationSounds() const @@ -93,10 +92,10 @@ namespace BlackGui void CAudioSetupComponent::ps_audioDeviceSelected(int index) { - if (!this->getIContextAudio()) return; + if (!sGui->getIContextAudio()) return; if (index < 0) { return; } - CAudioDeviceInfoList devices = this->getIContextAudio()->getAudioDevices(); + CAudioDeviceInfoList devices = sGui->getIContextAudio()->getAudioDevices(); if (devices.isEmpty()) { return; } CAudioDeviceInfo selectedDevice; QObject *sender = QObject::sender(); @@ -105,14 +104,14 @@ namespace BlackGui CAudioDeviceInfoList inputDevices = devices.getInputDevices(); if (index >= inputDevices.size()) { return; } selectedDevice = inputDevices[index]; - this->getIContextAudio()->setCurrentAudioDevice(selectedDevice); + sGui->getIContextAudio()->setCurrentAudioDevice(selectedDevice); } else if (sender == this->ui->cb_SetupAudioOutputDevice) { CAudioDeviceInfoList outputDevices = devices.getOutputDevices(); if (index >= outputDevices.size()) { return; } selectedDevice = outputDevices[index]; - this->getIContextAudio()->setCurrentAudioDevice(selectedDevice); + sGui->getIContextAudio()->setCurrentAudioDevice(selectedDevice); } } @@ -151,9 +150,9 @@ namespace BlackGui void CAudioSetupComponent::ps_onLoopbackToggled(bool loopback) { - Q_ASSERT(this->getIContextAudio()); - if (this->getIContextAudio()->isAudioLoopbackEnabled() == loopback) { return; } - this->getIContextAudio()->enableAudioLoopback(loopback); + Q_ASSERT(sGui->getIContextAudio()); + if (sGui->getIContextAudio()->isAudioLoopbackEnabled() == loopback) { return; } + sGui->getIContextAudio()->enableAudioLoopback(loopback); } } // namespace diff --git a/src/blackgui/components/audiosetupcomponent.h b/src/blackgui/components/audiosetupcomponent.h index 23fbcc006..589b3dcc1 100644 --- a/src/blackgui/components/audiosetupcomponent.h +++ b/src/blackgui/components/audiosetupcomponent.h @@ -13,7 +13,6 @@ #define BLACKGUI_AUDIOSETUPCOMPONENT_H #include "blackgui/blackguiexport.h" -#include "blackgui/components/enableforruntime.h" #include "blackcore/settings/audio.h" #include "blackmisc/audio/audiodeviceinfolist.h" #include @@ -27,8 +26,7 @@ namespace BlackGui { //! Audio setup such as input / output devices class BLACKGUI_EXPORT CAudioSetupComponent : - public QFrame, - public CEnableForRuntime + public QFrame { Q_OBJECT @@ -42,10 +40,6 @@ namespace BlackGui //! Play notification sounds (at all) bool playNotificationSounds() const; - protected: - //! \copydoc CEnableForRuntime::runtimeHasBeenSet - virtual void runtimeHasBeenSet() override; - private slots: //! Reload settings void ps_reloadSettings(); diff --git a/src/blackgui/components/audiovolumecomponent.cpp b/src/blackgui/components/audiovolumecomponent.cpp index 4ef382aac..96cfc1f1c 100644 --- a/src/blackgui/components/audiovolumecomponent.cpp +++ b/src/blackgui/components/audiovolumecomponent.cpp @@ -7,6 +7,7 @@ * contained in the LICENSE file. */ +#include "blackgui/guiapplication.h" #include "blackcore/contextaudio.h" #include "blackmisc/audio/audioutils.h" #include "audiovolumecomponent.h" @@ -18,7 +19,6 @@ namespace BlackGui { namespace Components { - CAudioVolumeComponent::CAudioVolumeComponent(QWidget *parent) : QFrame(parent), ui(new Ui::CAudioVolumeComponent) @@ -26,33 +26,30 @@ namespace BlackGui ui->setupUi(this); bool c = connect(this->ui->pb_ShowWinMixer, &QPushButton::pressed, this, &CAudioVolumeComponent::ps_onWindowsMixerRequested); Q_ASSERT(c); + Q_UNUSED(c); c = connect(this->ui->hs_Volume, &QSlider::valueChanged, this, &CAudioVolumeComponent::ps_changeOutputVolumeFromSlider); Q_ASSERT(c); + Q_UNUSED(c); c = connect(this->ui->sb_Volume, static_cast (&QSpinBox::valueChanged), this, &CAudioVolumeComponent::ps_changeOutputVolumeFromSpinBox); Q_ASSERT(c); + Q_UNUSED(c); c = connect(this->ui->pb_Volume100, &QPushButton::clicked, this, &CAudioVolumeComponent::ps_setVolume100); Q_ASSERT(c); Q_UNUSED(c); - } - CAudioVolumeComponent::~CAudioVolumeComponent() - { } - - void CAudioVolumeComponent::runtimeHasBeenSet() - { - // from audio context - Q_ASSERT(this->getIContextAudio()); - bool c = connect(this->getIContextAudio(), &IContextAudio::changedMute, this, &CAudioVolumeComponent::ps_onMuteChanged); + c = connect(sGui->getIContextAudio(), &IContextAudio::changedMute, this, &CAudioVolumeComponent::ps_onMuteChanged); Q_ASSERT(c); - connect(this->getIContextAudio(), &IContextAudio::changedAudioVolume, this, &CAudioVolumeComponent::ps_onOutputVolumeChanged); - Q_ASSERT(c); - - // to audio audio context - c = connect(this->ui->pb_Mute, &QPushButton::toggled, this->getIContextAudio(), &IContextAudio::setMute); + Q_UNUSED(c); + connect(sGui->getIContextAudio(), &IContextAudio::changedAudioVolume, this, &CAudioVolumeComponent::ps_onOutputVolumeChanged); Q_ASSERT(c); Q_UNUSED(c); - if (this->getIContextAudio()->isUsingImplementingObject()) + // to audio audio context + c = connect(this->ui->pb_Mute, &QPushButton::toggled, sGui->getIContextAudio(), &IContextAudio::setMute); + Q_ASSERT(c); + Q_UNUSED(c); + + if (sGui->getIContextAudio()->isUsingImplementingObject()) { this->ui->lbl_ContextLocation->setText("local"); } @@ -62,9 +59,12 @@ namespace BlackGui } // init volume - this->ps_changeOutputVolumeFromSlider(this->getIContextAudio()->getVoiceOutputVolume()); // init volume + this->ps_changeOutputVolumeFromSlider(sGui->getIContextAudio()->getVoiceOutputVolume()); // init volume } + CAudioVolumeComponent::~CAudioVolumeComponent() + { } + void CAudioVolumeComponent::ps_onMuteChanged(bool muted) { if (muted == this->ui->pb_Mute->isChecked()) { return; } // avoid roundtrips @@ -111,20 +111,20 @@ namespace BlackGui } this->ui->hs_Volume->setToolTip(QString::number(volume)); - Q_ASSERT(this->getIContextAudio()); - if (this->getIContextAudio()->getVoiceOutputVolume() != volume) + Q_ASSERT(sGui->getIContextAudio()); + if (sGui->getIContextAudio()->getVoiceOutputVolume() != volume) { - this->getIContextAudio()->setVoiceOutputVolume(volume); + sGui->getIContextAudio()->setVoiceOutputVolume(volume); } } void CAudioVolumeComponent::ps_changeOutputVolumeFromSpinBox(int volume) { this->ui->sb_Volume->setToolTip(QString::number(volume)); - Q_ASSERT(this->getIContextAudio()); - if (this->getIContextAudio()->getVoiceOutputVolume() != volume) + Q_ASSERT(sGui->getIContextAudio()); + if (sGui->getIContextAudio()->getVoiceOutputVolume() != volume) { - this->getIContextAudio()->setVoiceOutputVolume(volume); + sGui->getIContextAudio()->setVoiceOutputVolume(volume); } } diff --git a/src/blackgui/components/audiovolumecomponent.h b/src/blackgui/components/audiovolumecomponent.h index 38143e07b..12f381b47 100644 --- a/src/blackgui/components/audiovolumecomponent.h +++ b/src/blackgui/components/audiovolumecomponent.h @@ -15,7 +15,6 @@ #include "blackgui/blackguiexport.h" #include #include -#include "enableforruntime.h" namespace Ui { class CAudioVolumeComponent; } namespace BlackGui @@ -24,8 +23,7 @@ namespace BlackGui { //! Audio volume, mixer class BLACKGUI_EXPORT CAudioVolumeComponent : - public QFrame, - public CEnableForRuntime + public QFrame { Q_OBJECT @@ -36,10 +34,6 @@ namespace BlackGui //! Destructor ~CAudioVolumeComponent(); - protected: - //! \copydoc CEnableForRuntime::runtimeHasBeenSet - void runtimeHasBeenSet() override; - private slots: //! Mute toggle void ps_onMuteChanged(bool muted); diff --git a/src/blackgui/components/cockpitcomcomponent.cpp b/src/blackgui/components/cockpitcomcomponent.cpp index 3d876b0f4..0df60ce55 100644 --- a/src/blackgui/components/cockpitcomcomponent.cpp +++ b/src/blackgui/components/cockpitcomcomponent.cpp @@ -10,6 +10,7 @@ #include "cockpitcomcomponent.h" #include "ui_cockpitcomcomponent.h" #include "../stylesheetutility.h" +#include "blackgui/guiapplication.h" #include "blackcore/contextnetwork.h" #include "blackcore/contextownaircraft.h" #include "blackcore/contextaudio.h" @@ -38,28 +39,8 @@ namespace BlackGui { ui->setupUi(this); this->initLeds(); - QObject::connect(this->ui->cbp_ComPanelTransponderMode, &CTransponderModeSelector::transponderModeChanged, this, &CCockpitComComponent::transponderModeChanged); - QObject::connect(this->ui->cbp_ComPanelTransponderMode, &CTransponderModeSelector::transponderStateIdentEnded, this, &CCockpitComComponent::transponderStateIdentEnded); - } - - CCockpitComComponent::~CCockpitComComponent() - { } - - void CCockpitComComponent::setSelectedTransponderModeStateIdent() - { - this->ui->cbp_ComPanelTransponderMode->setSelectedTransponderModeStateIdent(); - } - - void CCockpitComComponent::paintEvent(QPaintEvent *event) - { - Q_UNUSED(event); - CStyleSheetUtility::useStyleSheetInDerivedWidget(this); - } - - void CCockpitComComponent::runtimeHasBeenSet() - { - Q_ASSERT(this->getIContextOwnAircraft()); - Q_ASSERT(this->getIContextAudio()); + connect(this->ui->cbp_ComPanelTransponderMode, &CTransponderModeSelector::transponderModeChanged, this, &CCockpitComComponent::transponderModeChanged); + connect(this->ui->cbp_ComPanelTransponderMode, &CTransponderModeSelector::transponderStateIdentEnded, this, &CCockpitComComponent::transponderStateIdentEnded); // init from aircraft CSimulatedAircraft ownAircraft = this->getOwnAircraft(); @@ -81,11 +62,25 @@ namespace BlackGui connect(this->ui->frp_ComPanelSelcalBottom, &CSelcalCodeSelector::valueChanged, this, &CCockpitComComponent::ps_guiChangedSelcal); // hook up with changes from own aircraft context - this->connect(this->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CCockpitComComponent::ps_updateCockpitFromContext); - this->connect(this->getIContextOwnAircraft(), &IContextOwnAircraft::changedSelcal, this, &CCockpitComComponent::ps_onChangedSelcal); + this->connect(sGui->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CCockpitComComponent::ps_updateCockpitFromContext); + this->connect(sGui->getIContextOwnAircraft(), &IContextOwnAircraft::changedSelcal, this, &CCockpitComComponent::ps_onChangedSelcal); // hook up with audio context - this->connect(this->getIContextAudio(), &IContextAudio::changedVoiceRooms, this, &CCockpitComComponent::ps_onChangedVoiceRoomStatus); + this->connect(sGui->getIContextAudio(), &IContextAudio::changedVoiceRooms, this, &CCockpitComComponent::ps_onChangedVoiceRoomStatus); + } + + CCockpitComComponent::~CCockpitComComponent() + { } + + void CCockpitComComponent::setSelectedTransponderModeStateIdent() + { + this->ui->cbp_ComPanelTransponderMode->setSelectedTransponderModeStateIdent(); + } + + void CCockpitComComponent::paintEvent(QPaintEvent *event) + { + Q_UNUSED(event); + CStyleSheetUtility::useStyleSheetInDerivedWidget(this); } void CCockpitComComponent::ps_guiChangedCockpitValues() @@ -112,7 +107,7 @@ namespace BlackGui void CCockpitComComponent::ps_guiChangedSelcal() { - this->getIContextOwnAircraft()->updateSelcal(this->getSelcal(), identifier()); + sGui->getIContextOwnAircraft()->updateSelcal(this->getSelcal(), identifier()); } void CCockpitComComponent::ps_updateCockpitFromContext(const CSimulatedAircraft &ownAircraft, const CIdentifier &originator) @@ -137,9 +132,9 @@ namespace BlackGui this->ui->cbp_ComPanelTransponderMode->setSelectedTransponderMode(transponder.getTransponderMode()); - if (this->getIContextNetwork()) + if (sGui->getIContextNetwork()) { - CAtcStationList selectedStations = this->getIContextNetwork()->getSelectedAtcStations(); + CAtcStationList selectedStations = sGui->getIContextNetwork()->getSelectedAtcStations(); CAtcStation com1Station = selectedStations.size() > 0 ? selectedStations[0] : CAtcStation(); CAtcStation com2Station = selectedStations.size() > 1 ? selectedStations[1] : CAtcStation(); if (com1Station.getCallsign().isEmpty()) @@ -173,9 +168,9 @@ namespace BlackGui { CLogMessage().validationWarning("Invalid SELCAL code"); } - else if (this->getIContextAudio()) + else if (sGui->getIContextAudio()) { - this->getIContextAudio()->playSelcalTone(selcal); + sGui->getIContextAudio()->playSelcalTone(selcal); } else { @@ -240,14 +235,14 @@ namespace BlackGui CSimulatedAircraft CCockpitComComponent::getOwnAircraft() const { - Q_ASSERT(this->getIContextOwnAircraft()); - if (!this->getIContextOwnAircraft()) return CSimulatedAircraft(); - return this->getIContextOwnAircraft()->getOwnAircraft(); + Q_ASSERT(sGui->getIContextOwnAircraft()); + if (!sGui->getIContextOwnAircraft()) return CSimulatedAircraft(); + return sGui->getIContextOwnAircraft()->getOwnAircraft(); } bool CCockpitComComponent::updateOwnCockpitInContext(const CSimulatedAircraft &ownAircraft) { - return this->getIContextOwnAircraft()->updateCockpit(ownAircraft.getCom1System(), ownAircraft.getCom2System(), ownAircraft.getTransponder(), identifier()); + return sGui->getIContextOwnAircraft()->updateCockpit(ownAircraft.getCom1System(), ownAircraft.getCom2System(), ownAircraft.getTransponder(), identifier()); } void CCockpitComComponent::updateFrequencyDisplaysFromComSystems(const CComSystem &com1, const CComSystem &com2) @@ -286,8 +281,5 @@ namespace BlackGui this->ui->led_ComPanelCom2->setOn(room2.isConnected()); Q_UNUSED(connected); } - - - } // namespace } // namespace diff --git a/src/blackgui/components/cockpitcomcomponent.h b/src/blackgui/components/cockpitcomcomponent.h index 2cc7718d3..12c330b22 100644 --- a/src/blackgui/components/cockpitcomcomponent.h +++ b/src/blackgui/components/cockpitcomcomponent.h @@ -14,9 +14,9 @@ #include "blackgui/blackguiexport.h" #include "enablefordockwidgetinfoarea.h" -#include "enableforruntime.h" #include "blackmisc/identifiable.h" #include "blackmisc/aviation/transponder.h" +#include "blackmisc/simulation/simulatedaircraft.h" #include "blackmisc/audio/voiceroomlist.h" #include #include @@ -31,8 +31,7 @@ namespace BlackGui class BLACKGUI_EXPORT CCockpitComComponent : public QFrame, public BlackMisc::CIdentifiable, - public CEnableForDockWidgetInfoArea, - public CEnableForRuntime + public CEnableForDockWidgetInfoArea { Q_OBJECT @@ -58,9 +57,6 @@ namespace BlackGui //! \copydoc QWidget::paintEvent virtual void paintEvent(QPaintEvent *event) override; - //! \copydoc CEnableForRuntime::runtimeHasBeenSet - virtual void runtimeHasBeenSet() override; - private slots: //! Cockpit values have been changed in GUI void ps_guiChangedCockpitValues(); diff --git a/src/blackgui/components/cockpittranspondermodeledscomponent.cpp b/src/blackgui/components/cockpittranspondermodeledscomponent.cpp index 1760eaecc..0c37eea82 100644 --- a/src/blackgui/components/cockpittranspondermodeledscomponent.cpp +++ b/src/blackgui/components/cockpittranspondermodeledscomponent.cpp @@ -8,6 +8,7 @@ */ #include "cockpittranspondermodeledscomponent.h" +#include "blackgui/guiapplication.h" #include "blackcore/contextownaircraft.h" #include #include @@ -29,12 +30,7 @@ namespace BlackGui m_ledIdent(new CLedWidget(false, CLedWidget::Yellow, CLedWidget::Black, CLedWidget::Rounded, "ident", "", LedWidth, this)) { this->init(true); - } - - void CCockpitTransponderModeLedsComponent::runtimeHasBeenSet() - { - Q_ASSERT(this->getIContextOwnAircraft()); - connect(this->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CCockpitTransponderModeLedsComponent::ps_onAircraftCockpitChanged); + connect(sGui->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CCockpitTransponderModeLedsComponent::ps_onAircraftCockpitChanged); this->setMode(getOwnTransponder().getTransponderMode()); } @@ -48,7 +44,7 @@ namespace BlackGui { QWidget *w = qobject_cast(QObject::sender()); if (!w) { return; } - if (!this->getIContextOwnAircraft()) { return; } + if (!sGui->getIContextOwnAircraft()) { return; } CTransponder::TransponderMode mode; if (this->m_ledStandby.data() == w) { @@ -72,7 +68,7 @@ namespace BlackGui this->setMode(mode); CTransponder xpdr = ownAircraft.getTransponder(); xpdr.setTransponderMode(mode); - this->getIContextOwnAircraft()->updateCockpit(ownAircraft.getCom1System(), ownAircraft.getCom2System(), xpdr, identifier()); + sGui->getIContextOwnAircraft()->updateCockpit(ownAircraft.getCom1System(), ownAircraft.getCom2System(), xpdr, identifier()); } void CCockpitTransponderModeLedsComponent::init(bool horizontal) @@ -91,7 +87,7 @@ namespace BlackGui this->setLayout(ledLayout); // if context is already available set mode - if (this->getIContextOwnAircraft()) { this->setMode(getOwnTransponder().getTransponderMode()); } + if (sGui->getIContextOwnAircraft()) { this->setMode(getOwnTransponder().getTransponderMode()); } } void CCockpitTransponderModeLedsComponent::setMode(BlackMisc::Aviation::CTransponder::TransponderMode mode) @@ -125,14 +121,12 @@ namespace BlackGui CTransponder CCockpitTransponderModeLedsComponent::getOwnTransponder() const { - Q_ASSERT(getIContextOwnAircraft()); - return getIContextOwnAircraft()->getOwnAircraft().getTransponder(); + return sGui->getIContextOwnAircraft()->getOwnAircraft().getTransponder(); } CSimulatedAircraft CCockpitTransponderModeLedsComponent::getOwnAircraft() const { - Q_ASSERT(getIContextOwnAircraft()); - return getIContextOwnAircraft()->getOwnAircraft(); + return sGui->getIContextOwnAircraft()->getOwnAircraft(); } } // namespace diff --git a/src/blackgui/components/cockpittranspondermodeledscomponent.h b/src/blackgui/components/cockpittranspondermodeledscomponent.h index 7cd111f81..759ed1fee 100644 --- a/src/blackgui/components/cockpittranspondermodeledscomponent.h +++ b/src/blackgui/components/cockpittranspondermodeledscomponent.h @@ -13,7 +13,6 @@ #define BLACKMISC_COCKPITTRANSPONDERMODELEDSCOMPONENT_H #include "blackgui/blackguiexport.h" -#include "enableforruntime.h" #include "../led.h" #include "blackmisc/identifiable.h" #include "blackmisc/simulation/simulatedaircraft.h" @@ -28,7 +27,6 @@ namespace BlackGui //! LEDs representing transponder mode state class BLACKGUI_EXPORT CCockpitTransponderModeLedsComponent : public QFrame, - public CEnableForRuntime, public BlackMisc::CIdentifiable { Q_OBJECT @@ -37,10 +35,6 @@ namespace BlackGui //! Constructor explicit CCockpitTransponderModeLedsComponent(QWidget *parent = nullptr); - protected: - //! \copydoc CEnableForRuntime::runtimeHasBeenSet - virtual void runtimeHasBeenSet() override; - private slots: //! \copydoc IContextOwnAircraft::changedAircraftCockpit void ps_onAircraftCockpitChanged(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const BlackMisc::CIdentifier &originator); diff --git a/src/blackgui/components/coreinfoareacomponent.h b/src/blackgui/components/coreinfoareacomponent.h index a8854bb15..ff9292b4c 100644 --- a/src/blackgui/components/coreinfoareacomponent.h +++ b/src/blackgui/components/coreinfoareacomponent.h @@ -23,7 +23,6 @@ namespace BlackGui { namespace Components { - // break compile dependency class CLogComponent; class CCoreStatusComponent; diff --git a/src/blackgui/components/enablefordockwidgetinfoarea.h b/src/blackgui/components/enablefordockwidgetinfoarea.h index a606aec4e..ddf7bf3d8 100644 --- a/src/blackgui/components/enablefordockwidgetinfoarea.h +++ b/src/blackgui/components/enablefordockwidgetinfoarea.h @@ -64,7 +64,7 @@ namespace BlackGui protected: //! Constructor - //! \remarks Normally the infoa area will be provided later \sa setParentDockWidgetInfoArea + //! \remarks Normally the info area will be provided later \sa setParentDockWidgetInfoArea CEnableForDockWidgetInfoArea(CDockWidgetInfoArea *parentInfoArea = nullptr); private: diff --git a/src/blackgui/components/enableforruntime.cpp b/src/blackgui/components/enableforruntime.cpp deleted file mode 100644 index 36e9b8359..000000000 --- a/src/blackgui/components/enableforruntime.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* Copyright (C) 2013 - * swift project Community / Contributors - * - * This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -#include "enableforruntime.h" -#include "blackcore/contextallinterfaces.h" -#include - -using namespace BlackMisc::Audio; - -namespace BlackGui -{ - namespace Components - { - void CEnableForRuntime::setRuntime(BlackCore::CCoreFacade *runtime, bool runtimeOwner) - { - Q_ASSERT(runtime); - this->m_runtime = runtime; - this->m_runtimeOwner = runtimeOwner; - this->runtimeHasBeenSet(); - } - - void CEnableForRuntime::setRuntimeForComponents(BlackCore::CCoreFacade *runtime, QWidget *parent) - { - if (!parent) return; - - // tested for runtime, not too slow, only some ms - QList children = parent->findChildren(); - foreach(QWidget * widget, children) - { - if (widget->objectName().isEmpty()) continue; // rule out unamed widgets - CEnableForRuntime *rbc = dynamic_cast(widget); - if (rbc) rbc->setRuntime(runtime, false); - } - } - - void CEnableForRuntime::createRuntime(const BlackCore::CCoreFacadeConfig &config, QObject *parent) - { - this->m_runtime = new BlackCore::CCoreFacade(config, parent); - this->m_runtimeOwner = true; - } - - const BlackCore::IContextApplication *CEnableForRuntime::getIContextApplication() const - { - if (!this->m_runtime) return nullptr; - return this->m_runtime->getIContextApplication(); - } - - BlackCore::IContextApplication *CEnableForRuntime::getIContextApplication() - { - if (!this->m_runtime) return nullptr; - return this->m_runtime->getIContextApplication(); - } - - BlackCore::IContextAudio *CEnableForRuntime::getIContextAudio() - { - if (!this->m_runtime) return nullptr; - return this->m_runtime->getIContextAudio(); - } - - const BlackCore::IContextAudio *CEnableForRuntime::getIContextAudio() const - { - if (!this->m_runtime) return nullptr; - return this->m_runtime->getIContextAudio(); - } - - BlackCore::IContextNetwork *CEnableForRuntime::getIContextNetwork() - { - if (!this->m_runtime) return nullptr; - return this->m_runtime->getIContextNetwork(); - } - - const BlackCore::IContextNetwork *CEnableForRuntime::getIContextNetwork() const - { - if (!this->m_runtime) return nullptr; - return this->m_runtime->getIContextNetwork(); - } - - BlackCore::IContextOwnAircraft *CEnableForRuntime::getIContextOwnAircraft() - { - if (!this->m_runtime) return nullptr; - return this->m_runtime->getIContextOwnAircraft(); - } - - const BlackCore::IContextOwnAircraft *CEnableForRuntime::getIContextOwnAircraft() const - { - if (!this->m_runtime) return nullptr; - return this->m_runtime->getIContextOwnAircraft(); - } - - const BlackCore::IContextSimulator *CEnableForRuntime::getIContextSimulator() const - { - if (!this->m_runtime) return nullptr; - return this->m_runtime->getIContextSimulator(); - } - - BlackCore::IContextSimulator *CEnableForRuntime::getIContextSimulator() - { - if (!this->m_runtime) return nullptr; - return this->m_runtime->getIContextSimulator(); - } - - void CEnableForRuntime::playNotifcationSound(CNotificationSounds::Notification notification) const - { - if (!this->getIContextAudio()) return; - this->getIContextAudio()->playNotification(notification, true); - } - } -} diff --git a/src/blackgui/components/enableforruntime.h b/src/blackgui/components/enableforruntime.h deleted file mode 100644 index e46711dd2..000000000 --- a/src/blackgui/components/enableforruntime.h +++ /dev/null @@ -1,124 +0,0 @@ -/* Copyright (C) 2013 - * swift project Community / Contributors - * - * This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKGUI_ENABLEFORRUNTIME_H -#define BLACKGUI_ENABLEFORRUNTIME_H - -#include "blackgui/blackguiexport.h" -#include "blackcore/corefacade.h" -#include "blackmisc/audio/notificationsounds.h" -#include - -namespace BlackCore -{ - class CCoreFacade; - class CCoreFacadeConfig; - class IContextApplication; - class IContextAudio; - class IContextNetwork; - class IContextOwnAircraft; - class IContextSettings; - class IContextSimulator; -} - -namespace BlackGui -{ - namespace Components - { - - //! Component, which provides references to runtime objects - //! \details Access to runtime allows to encapsualate many aspects of data access and makes - //! the component widely independent from a central data provideer - //! \sa BlackCore::CCoreFacade - class BLACKGUI_EXPORT CEnableForRuntime - { - public: - //! Set runtime, usually set by runtime owner (must only be one, usually main window) - void setRuntime(BlackCore::CCoreFacade *runtime, bool runtimeOwner = false); - - //! Set runtime for each CRuntimeBasedComponent - static void setRuntimeForComponents(BlackCore::CCoreFacade *runtime, QWidget *parent); - - //! Log message category - static const BlackMisc::CLogCategoryList &getLogCategories() - { - static const BlackMisc::CLogCategoryList cats { BlackMisc::CLogCategory::guiComponent() }; - return cats; - } - - protected: - //! Constructor - //! \remarks Usually runtime will be provided later, not at initialization time. - //! If runtime is provided right now, make sure to call runtimeHasBeenSet afterwards - CEnableForRuntime(BlackCore::CCoreFacade *runtime = nullptr, bool runtimeOwner = false) : - m_runtime(runtime), m_runtimeOwner(runtimeOwner) - {} - - //! Runtime const - const BlackCore::CCoreFacade *getRuntime() const { return this->m_runtime;} - - //! Runtime non const - BlackCore::CCoreFacade *getRuntime() { return this->m_runtime;} - - //! Create a runtime (becomes owner). Only create one runtime. - void createRuntime(const BlackCore::CCoreFacadeConfig &config, QObject *parent); - - //! Context for application - const BlackCore::IContextApplication *getIContextApplication() const; - - //! Context for application - BlackCore::IContextApplication *getIContextApplication(); - - //! Context for audio - BlackCore::IContextAudio *getIContextAudio(); - - //! Context for audio - const BlackCore::IContextAudio *getIContextAudio() const; - - //! Context for network - BlackCore::IContextNetwork *getIContextNetwork(); - - //! Context for network - const BlackCore::IContextNetwork *getIContextNetwork() const; - - //! Context for own aircraft - const BlackCore::IContextOwnAircraft *getIContextOwnAircraft() const; - - //! Context for own aircraft - BlackCore::IContextOwnAircraft *getIContextOwnAircraft(); - - //! Context for simulator - const BlackCore::IContextSimulator *getIContextSimulator() const; - - //! Context for simulator - BlackCore::IContextSimulator *getIContextSimulator(); - - //! Owner? - bool isRuntimeOwner() const { return this->m_runtimeOwner; } - - //! "Callback" when runtime is initialized, done this way as we do not have signals/slots here - //! \remarks use this methods to hook up signal/slots with runtime - virtual void runtimeHasBeenSet() {} - - //! \copydoc BlackCore::CCoreFacade::hasRemoteApplicationContext - bool hasRemoteApplicationContext() const { return this->m_runtime->hasRemoteApplicationContext(); } - - //! Play a given notification sound - void playNotifcationSound(BlackMisc::Audio::CNotificationSounds::Notification notification) const; - - private: - BlackCore::CCoreFacade *m_runtime; - bool m_runtimeOwner; - }; - } -} // namespace - -#endif // guard diff --git a/src/blackgui/components/flightplancomponent.cpp b/src/blackgui/components/flightplancomponent.cpp index b362dfb53..9ca50e4db 100644 --- a/src/blackgui/components/flightplancomponent.cpp +++ b/src/blackgui/components/flightplancomponent.cpp @@ -8,7 +8,8 @@ */ #include "flightplancomponent.h" -#include "../stylesheetutility.h" +#include "blackgui/stylesheetutility.h" +#include "blackgui/guiapplication.h" #include "ui_flightplancomponent.h" #include "blackmisc/logmessage.h" #include "blackcore/contextnetwork.h" @@ -58,6 +59,9 @@ namespace BlackGui connect(this->ui->frp_SelcalCode, &CSelcalCodeSelector::valueChanged, this, &CFlightPlanComponent::ps_setSelcalInOwnAircraft); connect(this->ui->pb_CopyOver, &QPushButton::pressed, this, &CFlightPlanComponent::ps_copyRemarks); connect(this->ui->pb_RemarksGenerator, &QPushButton::clicked, this, &CFlightPlanComponent::ps_currentTabGenerator); + + this->ps_resetFlightPlan(); + this->ps_buildRemarksString(); } CFlightPlanComponent::~CFlightPlanComponent() @@ -66,8 +70,8 @@ namespace BlackGui void CFlightPlanComponent::loginDataSet() { if (this->m_flightPlan.wasSentOrLoaded()) { return; } // when loaded or sent do not override - if (!this->getIContextOwnAircraft()) { return; } - this->prefillWithAircraftData(this->getIContextOwnAircraft()->getOwnAircraft()); + if (!sGui->getIContextOwnAircraft()) { return; } + this->prefillWithAircraftData(sGui->getIContextOwnAircraft()->getOwnAircraft()); } void CFlightPlanComponent::prefillWithAircraftData(const BlackMisc::Simulation::CSimulatedAircraft &ownAircraft) @@ -115,13 +119,6 @@ namespace BlackGui return this->m_flightPlan; } - void CFlightPlanComponent::runtimeHasBeenSet() - { - // context dependent calls - this->ps_resetFlightPlan(); - this->ps_buildRemarksString(); - } - BlackMisc::CStatusMessageList CFlightPlanComponent::validateAndInitializeFlightPlan(BlackMisc::Aviation::CFlightPlan &flightPlan) { BlackMisc::CStatusMessageList messages; @@ -276,10 +273,10 @@ namespace BlackGui if (messages.isEmpty()) { // no error, send if possible - if (this->getIContextNetwork()->isConnected()) + if (sGui->getIContextNetwork()->isConnected()) { flightPlan.setWhenLastSentOrLoaded(QDateTime::currentDateTimeUtc()); - this->getIContextNetwork()->sendFlightPlan(flightPlan); + sGui->getIContextNetwork()->sendFlightPlan(flightPlan); this->ui->le_LastSent->setText(flightPlan.whenLastSentOrLoaded().toString()); CLogMessage(this).info("Sent flight plan"); } @@ -304,9 +301,9 @@ namespace BlackGui void CFlightPlanComponent::ps_resetFlightPlan() { - Q_ASSERT(this->getIContextNetwork()); - Q_ASSERT(this->getIContextOwnAircraft()); - if (this->getIContextOwnAircraft()) { this->prefillWithAircraftData(this->getIContextOwnAircraft()->getOwnAircraft()); } + Q_ASSERT(sGui->getIContextNetwork()); + Q_ASSERT(sGui->getIContextOwnAircraft()); + if (sGui->getIContextOwnAircraft()) { this->prefillWithAircraftData(sGui->getIContextOwnAircraft()->getOwnAircraft()); } this->ui->le_AircraftRegistration->clear(); this->ui->le_AirlineOperator->clear(); this->ui->le_CrusingAltitude->setText("FL70"); @@ -323,26 +320,26 @@ namespace BlackGui void CFlightPlanComponent::ps_setSelcalInOwnAircraft() { - if (!this->getIContextOwnAircraft()) return; + if (!sGui->getIContextOwnAircraft()) return; if (!this->ui->frp_SelcalCode->hasValidCode()) return; - this->getIContextOwnAircraft()->updateSelcal(this->ui->frp_SelcalCode->getSelcal(), flightPlanIdentifier()); + sGui->getIContextOwnAircraft()->updateSelcal(this->ui->frp_SelcalCode->getSelcal(), flightPlanIdentifier()); } void CFlightPlanComponent::ps_loadFlightPlanFromNetwork() { - if (!this->getIContextNetwork()) + if (!sGui->getIContextNetwork()) { CLogMessage(this).info("Cannot load flight plan, network not available"); return; } - if (!this->getIContextNetwork()->isConnected()) + if (!sGui->getIContextNetwork()->isConnected()) { CLogMessage(this).warning("Cannot load flight plan, network not connected"); return; } - CSimulatedAircraft ownAircraft = this->getIContextOwnAircraft()->getOwnAircraft(); - CFlightPlan loadedPlan = this->getIContextNetwork()->loadFlightPlanFromNetwork(ownAircraft.getCallsign()); + CSimulatedAircraft ownAircraft = sGui->getIContextOwnAircraft()->getOwnAircraft(); + CFlightPlan loadedPlan = sGui->getIContextNetwork()->loadFlightPlanFromNetwork(ownAircraft.getCallsign()); if (loadedPlan.wasSentOrLoaded()) { this->fillWithFlightPlanData(loadedPlan); diff --git a/src/blackgui/components/flightplancomponent.h b/src/blackgui/components/flightplancomponent.h index e61f702e2..e0a27ced9 100644 --- a/src/blackgui/components/flightplancomponent.h +++ b/src/blackgui/components/flightplancomponent.h @@ -13,9 +13,9 @@ #define BLACKGUI_FLIGHTPLANCOMPONENT_H #include "blackgui/blackguiexport.h" -#include "blackgui/components/enableforruntime.h" #include "blackmisc/identifier.h" #include "blackmisc/aviation/flightplan.h" +#include "blackmisc/simulation/simulatedaircraft.h" #include @@ -27,8 +27,7 @@ namespace BlackGui //! Flight plan widget class BLACKGUI_EXPORT CFlightPlanComponent : - public QTabWidget, - public CEnableForRuntime + public QTabWidget { Q_OBJECT @@ -52,10 +51,6 @@ namespace BlackGui //! Get this flight plan BlackMisc::Aviation::CFlightPlan getFlightPlan() const; - protected: - //! \copydoc CEnableForRuntime::runtimeHasBeenSet - void runtimeHasBeenSet() override; - private: QScopedPointer ui; diff --git a/src/blackgui/components/infobarstatuscomponent.cpp b/src/blackgui/components/infobarstatuscomponent.cpp index c71b83d71..21f90ba95 100644 --- a/src/blackgui/components/infobarstatuscomponent.cpp +++ b/src/blackgui/components/infobarstatuscomponent.cpp @@ -9,6 +9,7 @@ #include "infobarstatuscomponent.h" #include "ui_infobarstatuscomponent.h" +#include "blackgui/guiapplication.h" #include "blackcore/contextsimulator.h" #include "blackcore/contextnetwork.h" #include "blackcore/contextapplication.h" @@ -38,6 +39,32 @@ namespace BlackGui this->ui->lbl_Audio->setContextMenuPolicy(Qt::CustomContextMenu); connect(this->ui->lbl_Audio, &QLabel::customContextMenuRequested, this, &CInfoBarStatusComponent::ps_customAudioContextMenuRequested); + + if (sGui->getIContextSimulator()) + { + connect(sGui->getIContextSimulator(), &IContextSimulator::simulatorStatusChanged, this, &CInfoBarStatusComponent::ps_onSimulatorStatusChanged); + connect(sGui->getIContextSimulator(), &IContextSimulator::installedAircraftModelsChanged, this, &CInfoBarStatusComponent::ps_onMapperReady); + + // initial values + this->ps_onMapperReady(); + this->ps_onSimulatorStatusChanged(sGui->getIContextSimulator()->getSimulatorStatus()); + } + + if (sGui->getIContextNetwork()) + { + connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CInfoBarStatusComponent::ps_onNetworkConnectionChanged); + } + + if (sGui->getIContextApplication()) + { + this->ui->led_DBus->setOn(sGui->getIContextApplication()->isUsingImplementingObject()); + } + + if (sGui->getIContextAudio()) + { + this->ui->led_Audio->setOn(!sGui->getIContextAudio()->isMuted()); + connect(sGui->getIContextAudio(), &IContextAudio::changedMute, this, &CInfoBarStatusComponent::ps_onMuteChanged); + } } CInfoBarStatusComponent::~CInfoBarStatusComponent() @@ -66,48 +93,12 @@ namespace BlackGui this->ui->led_DBus->setOnToolTip(tooltip); } - void CInfoBarStatusComponent::runtimeHasBeenSet() - { - if (getIContextApplication()->isEmptyObject()) return; - - // TODO: remove checks when empty contexts are fully introduced - Q_ASSERT(getIContextSimulator()); - Q_ASSERT(getIContextAudio()); - Q_ASSERT(getIContextNetwork()); - - if (this->getIContextSimulator()) - { - connect(this->getIContextSimulator(), &IContextSimulator::simulatorStatusChanged, this, &CInfoBarStatusComponent::ps_onSimulatorStatusChanged); - connect(this->getIContextSimulator(), &IContextSimulator::installedAircraftModelsChanged, this, &CInfoBarStatusComponent::ps_onMapperReady); - - // initial values - this->ps_onMapperReady(); - this->ps_onSimulatorStatusChanged(this->getIContextSimulator()->getSimulatorStatus()); - } - - if (this->getIContextNetwork()) - { - connect(this->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CInfoBarStatusComponent::ps_onNetworkConnectionChanged); - } - - if (this->getIContextApplication()) - { - this->ui->led_DBus->setOn(this->getIContextApplication()->isUsingImplementingObject()); - } - - if (this->getIContextAudio()) - { - this->ui->led_Audio->setOn(!this->getIContextAudio()->isMuted()); - connect(getIContextAudio(), &IContextAudio::changedMute, this, &CInfoBarStatusComponent::ps_onMuteChanged); - } - } - void CInfoBarStatusComponent::ps_onSimulatorStatusChanged(int status) { if (status > 0 && (status & ISimulator::Connected)) { QString s( - getIContextSimulator()->getSimulatorPluginInfo().getDescription() + ": " + + sGui->getIContextSimulator()->getSimulatorPluginInfo().getDescription() + ": " + ISimulator::statusToString(status)); // at least connected @@ -148,7 +139,7 @@ namespace BlackGui break; case INetwork::Connected: this->ui->led_Network->setOn(true); - this->ui->led_Network->setOnToolTip("Connected: " + getIContextNetwork()->getConnectedServer().getName()); + this->ui->led_Network->setOnToolTip("Connected: " + sGui->getIContextNetwork()->getConnectedServer().getName()); break; case INetwork::Connecting: this->ui->led_Network->setTriStateColor(CLedWidget::Yellow); @@ -180,7 +171,7 @@ namespace BlackGui const QList actions = menuAudio.actions(); if (selectedItem == actions.at(0)) { - this->getIContextAudio()->setMute(!this->getIContextAudio()->isMuted()); + sGui->getIContextAudio()->setMute(!sGui->getIContextAudio()->isMuted()); } else if (actions.size() > 1 && selectedItem == actions.at(1)) { @@ -196,13 +187,13 @@ namespace BlackGui void CInfoBarStatusComponent::ps_onMapperReady() { - if (!getIContextSimulator()) + if (!sGui->getIContextSimulator()) { this->ui->led_MapperReady->setOn(false); return; } - int models = this->getIContextSimulator()->getInstalledModelsCount(); + int models = sGui->getIContextSimulator()->getInstalledModelsCount(); bool on = (models > 0); this->ui->led_MapperReady->setOn(on); if (on) diff --git a/src/blackgui/components/infobarstatuscomponent.h b/src/blackgui/components/infobarstatuscomponent.h index bc305d1bd..cee8aa7b8 100644 --- a/src/blackgui/components/infobarstatuscomponent.h +++ b/src/blackgui/components/infobarstatuscomponent.h @@ -13,7 +13,6 @@ #define BLACKGUI_INFOBARSTATUSCOMPONENT_H #include "blackgui/blackguiexport.h" -#include "enableforruntime.h" #include "blackcore/network.h" #include "../led.h" #include @@ -26,8 +25,7 @@ namespace BlackGui { //! Info bar displaying status (Network, Simulator, DBus) class BLACKGUI_EXPORT CInfoBarStatusComponent : - public QFrame, - public CEnableForRuntime + public QFrame { Q_OBJECT @@ -47,10 +45,6 @@ namespace BlackGui //! Tooltip for DBus void setDBusTooltip(const QString &tooltip); - protected: - //! \copydoc CEnableForRuntime::runtimeHasBeenSet - virtual void runtimeHasBeenSet() override; - private: QScopedPointer ui; diff --git a/src/blackgui/components/internalscomponent.cpp b/src/blackgui/components/internalscomponent.cpp index ec6db58f2..5f14b5cad 100644 --- a/src/blackgui/components/internalscomponent.cpp +++ b/src/blackgui/components/internalscomponent.cpp @@ -9,6 +9,7 @@ #include "internalscomponent.h" #include "ui_internalscomponent.h" +#include "blackgui/guiapplication.h" #include "blackcore/contextallinterfaces.h" #include @@ -22,7 +23,6 @@ namespace BlackGui { CInternalsComponent::CInternalsComponent(QWidget *parent) : QWidget(parent), - CEnableForRuntime(nullptr, false), ui(new Ui::CInternalsComponent) { ui->setupUi(this); @@ -41,15 +41,11 @@ namespace BlackGui connect(ui->cb_DebugContextSimulator, &QCheckBox::stateChanged, this, &CInternalsComponent::ps_enableDebug); connect(ui->cb_DebugDriver, &QCheckBox::stateChanged, this, &CInternalsComponent::ps_enableDebug); connect(ui->cb_DebugInterpolator, &QCheckBox::stateChanged, this, &CInternalsComponent::ps_enableDebug); + contextFlagsToGui(); } CInternalsComponent::~CInternalsComponent() { } - void CInternalsComponent::runtimeHasBeenSet() - { - contextFlagsToGui(); - } - void CInternalsComponent::showEvent(QShowEvent *event) { // force new data when visible @@ -59,8 +55,8 @@ namespace BlackGui void CInternalsComponent::ps_sendAircraftParts() { - Q_ASSERT(this->getIContextNetwork()); - if (!this->getIContextNetwork()->isConnected()) + Q_ASSERT(sGui->getIContextNetwork()); + if (!sGui->getIContextNetwork()->isConnected()) { CLogMessage(this).validationError("Cannot send aircraft parts, network not connected"); return; @@ -99,7 +95,7 @@ namespace BlackGui this->ps_guiToJson(); } - this->getIContextNetwork()->testAddAircraftParts(callsign, parts, this->ui->cb_AircraftPartsIncremental->isChecked()); + sGui->getIContextNetwork()->testAddAircraftParts(callsign, parts, this->ui->cb_AircraftPartsIncremental->isChecked()); CLogMessage(this).info("Added parts for %1") << callsign.toQString(); } @@ -134,24 +130,24 @@ namespace BlackGui void CInternalsComponent::ps_enableDebug(int state) { - Q_ASSERT(this->getIContextApplication()); - Q_ASSERT(this->getIContextAudio()); - Q_ASSERT(this->getIContextNetwork()); - Q_ASSERT(this->getIContextOwnAircraft()); - Q_ASSERT(this->getIContextSimulator()); + Q_ASSERT(sGui->getIContextApplication()); + Q_ASSERT(sGui->getIContextAudio()); + Q_ASSERT(sGui->getIContextNetwork()); + Q_ASSERT(sGui->getIContextOwnAircraft()); + Q_ASSERT(sGui->getIContextSimulator()); Qt::CheckState checkState = static_cast(state); bool debug = (checkState == Qt::Checked); QObject *sender = QObject::sender(); - if (sender == ui->cb_DebugContextApplication) { getIContextApplication()->setDebugEnabled(debug); } - else if (sender == ui->cb_DebugContextAudio) { getIContextAudio()->setDebugEnabled(debug); } - else if (sender == ui->cb_DebugContextNetwork) { getIContextNetwork()->setDebugEnabled(debug);} - else if (sender == ui->cb_DebugContextOwnAircraft) { getIContextOwnAircraft()->setDebugEnabled(debug); } - else if (sender == ui->cb_DebugContextSimulator) { getIContextSimulator()->setDebugEnabled(debug);} + if (sender == ui->cb_DebugContextApplication) { sGui->getIContextApplication()->setDebugEnabled(debug); } + else if (sender == ui->cb_DebugContextAudio) { sGui->getIContextAudio()->setDebugEnabled(debug); } + else if (sender == ui->cb_DebugContextNetwork) { sGui->getIContextNetwork()->setDebugEnabled(debug);} + else if (sender == ui->cb_DebugContextOwnAircraft) { sGui->getIContextOwnAircraft()->setDebugEnabled(debug); } + else if (sender == ui->cb_DebugContextSimulator) { sGui->getIContextSimulator()->setDebugEnabled(debug);} else if (sender == ui->cb_DebugDriver || sender == ui->cb_DebugInterpolator) { - this->getIContextSimulator()->enableDebugMessages( + sGui->getIContextSimulator()->enableDebugMessages( this->ui->cb_DebugDriver->isChecked(), this->ui->cb_DebugInterpolator->isChecked() ); @@ -215,10 +211,10 @@ namespace BlackGui void CInternalsComponent::contextFlagsToGui() { - ui->cb_DebugContextApplication->setChecked(getIContextApplication()->isDebugEnabled()); - ui->cb_DebugContextNetwork->setChecked(getIContextNetwork()->isDebugEnabled()); - ui->cb_DebugContextOwnAircraft->setChecked(getIContextOwnAircraft()->isDebugEnabled()); - ui->cb_DebugContextSimulator->setChecked(getIContextSimulator()->isDebugEnabled()); + ui->cb_DebugContextApplication->setChecked(sGui->getIContextApplication()->isDebugEnabled()); + ui->cb_DebugContextNetwork->setChecked(sGui->getIContextNetwork()->isDebugEnabled()); + ui->cb_DebugContextOwnAircraft->setChecked(sGui->getIContextOwnAircraft()->isDebugEnabled()); + ui->cb_DebugContextSimulator->setChecked(sGui->getIContextSimulator()->isDebugEnabled()); } } // namespace diff --git a/src/blackgui/components/internalscomponent.h b/src/blackgui/components/internalscomponent.h index 447330ade..628f2d339 100644 --- a/src/blackgui/components/internalscomponent.h +++ b/src/blackgui/components/internalscomponent.h @@ -13,7 +13,7 @@ #define BLACKGUI_INTERNALSCOMPONENT_H #include "blackgui/blackguiexport.h" -#include "enableforruntime.h" +#include "blackmisc/aviation/aircraftparts.h" #include #include @@ -23,11 +23,9 @@ namespace BlackGui { namespace Components { - //! Internals for debugging, statistics class BLACKGUI_EXPORT CInternalsComponent : - public QWidget, - public CEnableForRuntime + public QWidget { Q_OBJECT @@ -39,9 +37,6 @@ namespace BlackGui ~CInternalsComponent(); protected: - //! \copydoc CEnableForRuntime::runtimeHasBeenSet - virtual void runtimeHasBeenSet() override; - //! \copydoc QWidget::showEvent virtual void showEvent(QShowEvent *event) override; diff --git a/src/blackgui/components/logcomponent.h b/src/blackgui/components/logcomponent.h index 44b696b49..28d4fffac 100644 --- a/src/blackgui/components/logcomponent.h +++ b/src/blackgui/components/logcomponent.h @@ -13,7 +13,6 @@ #define BLACKGUI_LOGCOMPONENT_H #include "blackgui/blackguiexport.h" -#include "enableforruntime.h" #include "blackmisc/statusmessagelist.h" #include "blackgui/menudelegate.h" #include @@ -42,8 +41,7 @@ namespace BlackGui //! GUI displaying log and status messages class BLACKGUI_EXPORT CLogComponent : - public QFrame, - public CEnableForRuntime + public QFrame { Q_OBJECT diff --git a/src/blackgui/components/logincomponent.cpp b/src/blackgui/components/logincomponent.cpp index 75db8df8c..8c1110145 100644 --- a/src/blackgui/components/logincomponent.cpp +++ b/src/blackgui/components/logincomponent.cpp @@ -9,6 +9,8 @@ #include "logincomponent.h" #include "ui_logincomponent.h" +#include "blackgui/uppercasevalidator.h" +#include "blackgui/guiapplication.h" #include "blackcore/contextnetwork.h" #include "blackcore/contextownaircraft.h" #include "blackcore/contextaudio.h" @@ -17,7 +19,6 @@ #include "blackcore/simulator.h" #include "blackcore/setupreader.h" #include "blackmisc/logmessage.h" -#include "blackgui/uppercasevalidator.h" #include using namespace BlackMisc; @@ -32,7 +33,6 @@ namespace BlackGui { namespace Components { - CLoginComponent::CLoginComponent(QWidget *parent) : QFrame(parent), ui(new Ui::CLoginComponent) @@ -97,6 +97,22 @@ namespace BlackGui // server GUI element this->ui->frp_CurrentServer->setReadOnly(true); this->ui->frp_CurrentServer->showPasswordField(false); + + connect(sGui->getIContextNetwork(), &IContextNetwork::webServiceDataRead, this, &CLoginComponent::ps_onWebServiceDataRead); + + // inital setup, if data already available + ps_validateAircraftValues(); + ps_validateVatsimValues(); + ps_onWebServiceDataRead(CEntityFlags::VatsimDataFile, CEntityFlags::ReadFinished, -1); + CServerList otherServers(this->m_otherTrafficNetworkServers.get()); + + // add a testserver when no servers can be loaded + if (otherServers.isEmpty() && CProject::isRunningInBetaOrDeveloperEnvironment()) + { + otherServers.push_back(m_setup.get().fsdTestServersPlusHardcodedServers()); + CLogMessage(this).info("Added servers for testing"); + } + this->ui->cbp_OtherServers->setServers(otherServers); } CLoginComponent::~CLoginComponent() @@ -122,7 +138,7 @@ namespace BlackGui else { this->m_visible = true; - bool isConnected = this->getIContextNetwork()->isConnected(); + bool isConnected = sGui->getIContextNetwork()->isConnected(); this->setGuiVisibility(isConnected); this->setOkButtonString(isConnected); if (isConnected) { this->startLogoffTimerCountdown(); } @@ -130,26 +146,6 @@ namespace BlackGui } } - void CLoginComponent::runtimeHasBeenSet() - { - Q_ASSERT(getIContextNetwork()); - connect(getIContextNetwork(), &IContextNetwork::webServiceDataRead, this, &CLoginComponent::ps_onWebServiceDataRead); - - // inital setup, if data already available - ps_validateAircraftValues(); - ps_validateVatsimValues(); - ps_onWebServiceDataRead(CEntityFlags::VatsimDataFile, CEntityFlags::ReadFinished, -1); - CServerList otherServers(this->m_otherTrafficNetworkServers.get()); - - // add a testserver when no servers can be loaded - if (otherServers.isEmpty() && CProject::isRunningInBetaOrDeveloperEnvironment()) - { - otherServers.push_back(m_setup.get().fsdTestServersPlusHardcodedServers()); - CLogMessage(this).info("Added servers for testing"); - } - this->ui->cbp_OtherServers->setServers(otherServers); - } - void CLoginComponent::ps_loginCancelled() { this->m_logoffCountdownTimer->stop(); @@ -159,11 +155,7 @@ namespace BlackGui void CLoginComponent::ps_toggleNetworkConnection() { - Q_ASSERT(this->getIContextNetwork()); - Q_ASSERT(this->getIContextOwnAircraft()); - Q_ASSERT(this->getIContextAudio()); - - bool isConnected = this->getIContextNetwork()->isConnected(); + bool isConnected = sGui->getIContextNetwork()->isConnected(); CStatusMessage msg; if (!isConnected) { @@ -183,7 +175,7 @@ namespace BlackGui // sync values with GUI values CGuiAircraftValues aircraftValues = this->getAircraftValuesFromGui(); - CSimulatedAircraft ownAircraft = this->getIContextOwnAircraft()->getOwnAircraft(); + CSimulatedAircraft ownAircraft = sGui->getIContextOwnAircraft()->getOwnAircraft(); CAircraftIcaoCode aircraftCode(ownAircraft.getAircraftIcaoCode()); CAirlineIcaoCode airlineCode(ownAircraft.getAirlineIcaoCode()); @@ -202,13 +194,13 @@ namespace BlackGui if (ownAircraft.getCallsign().asString() != aircraftValues.ownCallsign) { ownAircraft.setCallsign(aircraftValues.ownCallsign); - this->getIContextOwnAircraft()->updateOwnCallsign(ownAircraft.getCallsign()); + sGui->getIContextOwnAircraft()->updateOwnCallsign(ownAircraft.getCallsign()); } if (setIcaoCodes) { ownAircraft.setIcaoCodes(aircraftCode, airlineCode); - this->getIContextOwnAircraft()->updateOwnIcaoCodes(ownAircraft.getAircraftIcaoCode(), ownAircraft.getAirlineIcaoCode()); + sGui->getIContextOwnAircraft()->updateOwnIcaoCodes(ownAircraft.getAircraftIcaoCode(), ownAircraft.getAirlineIcaoCode()); } // Login mode @@ -239,16 +231,16 @@ namespace BlackGui currentServer = this->getCurrentOtherServer(); } this->ui->frp_CurrentServer->setServer(currentServer); - this->getIContextOwnAircraft()->updateOwnAircraftPilot(currentServer.getUser()); + sGui->getIContextOwnAircraft()->updateOwnAircraftPilot(currentServer.getUser()); // Login - msg = this->getIContextNetwork()->connectToNetwork(currentServer, mode); + msg = sGui->getIContextNetwork()->connectToNetwork(currentServer, mode); } else { // disconnect from network - this->getIContextAudio()->leaveAllVoiceRooms(); - msg = this->getIContextNetwork()->disconnectFromNetwork(); + sGui->getIContextAudio()->leaveAllVoiceRooms(); + msg = sGui->getIContextNetwork()->disconnectFromNetwork(); } // log message and trigger events @@ -271,8 +263,7 @@ namespace BlackGui CEntityFlags::ReadState state = static_cast(stateI); if (entity != CEntityFlags::VatsimDataFile || state != CEntityFlags::ReadFinished) { return; } Q_UNUSED(number); - Q_ASSERT_X(getIContextNetwork(), Q_FUNC_INFO, "Missing context"); - CServerList vatsimFsdServers = this->getIContextNetwork()->getVatsimFsdServers(); + CServerList vatsimFsdServers = sGui->getIContextNetwork()->getVatsimFsdServers(); if (vatsimFsdServers.isEmpty()) { return; } this->ui->cbp_VatsimServer->setServers(vatsimFsdServers); } @@ -363,19 +354,19 @@ namespace BlackGui void CLoginComponent::setOwnModel() { - Q_ASSERT(this->getIContextOwnAircraft()); - Q_ASSERT(this->getIContextSimulator()); + Q_ASSERT(sGui->getIContextOwnAircraft()); + Q_ASSERT(sGui->getIContextSimulator()); static const CAircraftModel defaultModel( "", CAircraftModel::TypeOwnSimulatorModel, "default model", CAircraftIcaoCode("C172", "L1P", "Cessna", "172", "L", true, false, false, 0)); CAircraftModel model; - bool simulating = this->getIContextSimulator() && - (this->getIContextSimulator()->getSimulatorStatus() & ISimulator::Simulating); + bool simulating = sGui->getIContextSimulator() && + (sGui->getIContextSimulator()->getSimulatorStatus() & ISimulator::Simulating); if (simulating) { - model = this->getIContextOwnAircraft()->getOwnAircraft().getModel(); + model = sGui->getIContextOwnAircraft()->getOwnAircraft().getModel(); this->ui->le_SimulatorModel->setText(model.getModelString()); } else @@ -473,11 +464,8 @@ namespace BlackGui void CLoginComponent::ps_reverseLookupModel() { - Q_ASSERT(getIContextOwnAircraft()); - Q_ASSERT(getIContextSimulator()); - - if (!this->getIContextSimulator()->isSimulatorAvailable()) { return; } - CAircraftModel model(this->getIContextOwnAircraft()->getOwnAircraft().getModel()); + if (!sGui->getIContextSimulator()->isSimulatorAvailable()) { return; } + CAircraftModel model(sGui->getIContextOwnAircraft()->getOwnAircraft().getModel()); QString modelStr(model.hasModelString() ? model.getModelString() : ""); if (model.getAircraftIcaoCode().hasDesignator()) { diff --git a/src/blackgui/components/logincomponent.h b/src/blackgui/components/logincomponent.h index 589991979..cb3ba122b 100644 --- a/src/blackgui/components/logincomponent.h +++ b/src/blackgui/components/logincomponent.h @@ -13,9 +13,9 @@ #define BLACKGUI_LOGINCOMPONENT_H #include "blackgui/blackguiexport.h" -#include "blackgui/components/enableforruntime.h" #include "blackcore/data/globalsetup.h" #include "blackcore/settings/network.h" +#include "blackmisc/simulation/simulatedaircraft.h" #include "blackmisc/network/server.h" #include "blackmisc/network/entityflags.h" #include @@ -29,8 +29,7 @@ namespace BlackGui { //! Login component class BLACKGUI_EXPORT CLoginComponent : - public QFrame, - public CEnableForRuntime + public QFrame { Q_OBJECT @@ -55,10 +54,6 @@ namespace BlackGui //! Main info area chnaged void mainInfoAreaChanged(const QWidget *currentWidget); - protected: - //! \copydoc CEnableForRuntime::runtimeHasBeenSet - virtual void runtimeHasBeenSet() override; - private slots: //! Login cancelled void ps_loginCancelled(); diff --git a/src/blackgui/components/mainkeypadareacomponent.cpp b/src/blackgui/components/mainkeypadareacomponent.cpp index 9fa3c75a1..fd7111999 100644 --- a/src/blackgui/components/mainkeypadareacomponent.cpp +++ b/src/blackgui/components/mainkeypadareacomponent.cpp @@ -9,6 +9,7 @@ #include "mainkeypadareacomponent.h" #include "ui_mainkeypadareacomponent.h" +#include "blackgui/guiapplication.h" #include "blackcore/contextaudio.h" #include "blackcore/contextnetwork.h" #include "blackcore/contextownaircraft.h" @@ -54,6 +55,11 @@ namespace BlackGui // command line this->connect(this->ui->le_CommandLineInput, &QLineEdit::returnPressed, this, &CMainKeypadAreaComponent::ps_commandEntered); + + connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CMainKeypadAreaComponent::ps_connectionStatusChanged); + connect(sGui->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CMainKeypadAreaComponent::ps_ownAircraftCockpitChanged); + connect(sGui->getIContextAudio(), &IContextAudio::changedMute, this, &CMainKeypadAreaComponent::ps_muteChanged); + connect(this, &CMainKeypadAreaComponent::commandEntered, sGui->getCoreFacade(), &CCoreFacade::parseCommandLine); } CMainKeypadAreaComponent::~CMainKeypadAreaComponent() @@ -72,7 +78,7 @@ namespace BlackGui } } - foreach(int floatingIndex, floatingIndexes) + foreach (int floatingIndex, floatingIndexes) { QPushButton *pb = this->mainInfoAreaToButton(static_cast(floatingIndex)); if (pb) {pb->setChecked(true); } @@ -81,18 +87,6 @@ namespace BlackGui Q_UNUSED(dockedIndexes); } - void CMainKeypadAreaComponent::runtimeHasBeenSet() - { - Q_ASSERT(this->getIContextOwnAircraft()); - Q_ASSERT(this->getIContextNetwork()); - Q_ASSERT(this->getIContextAudio()); - - connect(this->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CMainKeypadAreaComponent::ps_connectionStatusChanged); - connect(this->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CMainKeypadAreaComponent::ps_ownAircraftCockpitChanged); - connect(this->getIContextAudio(), &IContextAudio::changedMute, this, &CMainKeypadAreaComponent::ps_muteChanged); - connect(this, &CMainKeypadAreaComponent::commandEntered, this->getRuntime(), &CCoreFacade::parseCommandLine); - } - void CMainKeypadAreaComponent::ps_buttonSelected() { QPushButton *senderButton = static_cast(QObject::sender()); @@ -106,7 +100,7 @@ namespace BlackGui senderButton->setChecked(true); // re-check if got unchecked, we use checked buttons like normal buttons return; } - else if (senderButton == this->ui->pb_CockpitIdent && this->getIContextOwnAircraft()) + else if (senderButton == this->ui->pb_CockpitIdent && sGui->getIContextOwnAircraft()) { emit identPressed(); } @@ -118,14 +112,14 @@ namespace BlackGui { emit changedOpacity(100); } - else if (senderButton == this->ui->pb_SoundMaxVolume && this->getIContextAudio()) + else if (senderButton == this->ui->pb_SoundMaxVolume && sGui->getIContextAudio()) { - this->getIContextAudio()->setVoiceOutputVolume(100); + sGui->getIContextAudio()->setVoiceOutputVolume(100); } - else if (senderButton == this->ui->pb_SoundMute && this->getIContextAudio()) + else if (senderButton == this->ui->pb_SoundMute && sGui->getIContextAudio()) { - bool mute = this->getIContextAudio()->isMuted(); - this->getIContextAudio()->setMute(!mute); + bool mute = sGui->getIContextAudio()->isMuted(); + sGui->getIContextAudio()->setMute(!mute); } else if (senderButton == this->ui->pb_Connect) { diff --git a/src/blackgui/components/mainkeypadareacomponent.h b/src/blackgui/components/mainkeypadareacomponent.h index f84ac4cea..2a0f531a4 100644 --- a/src/blackgui/components/mainkeypadareacomponent.h +++ b/src/blackgui/components/mainkeypadareacomponent.h @@ -14,7 +14,6 @@ #include "blackgui/blackguiexport.h" #include "maininfoareacomponent.h" -#include "enableforruntime.h" #include "blackcore/network.h" #include "blackmisc/identifier.h" @@ -28,12 +27,10 @@ namespace BlackGui { namespace Components { - //! Main keypad area as used with main info area //! \sa CMainInfoAreaComponent class BLACKGUI_EXPORT CMainKeypadAreaComponent : - public QFrame, - public CEnableForRuntime + public QFrame { Q_OBJECT @@ -68,10 +65,6 @@ namespace BlackGui //! Main info area changed void onMainInfoAreaChanged(int currentTabIndex, QList dockedIndexes, QList floatingIndexes); - protected: - //! \copydoc CEnableForRuntime::runtimeHasBeenSet - virtual void runtimeHasBeenSet() override; - private slots: //! Button was clicked void ps_buttonSelected(); diff --git a/src/blackgui/components/mappingcomponent.cpp b/src/blackgui/components/mappingcomponent.cpp index 61e80be63..2743a8093 100644 --- a/src/blackgui/components/mappingcomponent.cpp +++ b/src/blackgui/components/mappingcomponent.cpp @@ -7,13 +7,14 @@ * contained in the LICENSE file. */ -#include "blackcore/contextsimulator.h" -#include "blackcore/contextnetwork.h" -#include "blackcore/network.h" #include "blackgui/views/aircraftmodelview.h" #include "blackgui/filters/aircraftmodelfilterdialog.h" #include "blackgui/models/aircraftmodellistmodel.h" #include "blackgui/guiutility.h" +#include "blackgui/guiapplication.h" +#include "blackcore/contextsimulator.h" +#include "blackcore/contextnetwork.h" +#include "blackcore/network.h" #include "blackmisc/propertyindexlist.h" #include "blackmisc/logmessage.h" #include "blackmisc/pixmap.h" @@ -75,6 +76,20 @@ namespace BlackGui // Updates this->ui->tvp_AircraftModels->setDisplayAutomatically(false); this->m_updateTimer->setUpdateInterval(10 * 1000); + + connect(sGui->getIContextSimulator(), &IContextSimulator::installedAircraftModelsChanged, this, &CMappingComponent::ps_onAircraftModelsLoaded); + connect(sGui->getIContextSimulator(), &IContextSimulator::modelMatchingCompleted, this, &CMappingComponent::ps_onModelMatchingCompleted); + connect(sGui->getIContextSimulator(), &IContextSimulator::airspaceSnapshotHandled, this, &CMappingComponent::ps_onAirspaceSnapshotHandled); + connect(sGui->getIContextNetwork(), &IContextNetwork::changedRemoteAircraftModel, this, &CMappingComponent::ps_onRemoteAircraftModelChanged); + connect(sGui->getIContextNetwork(), &IContextNetwork::changedRemoteAircraftEnabled, this, &CMappingComponent::ps_onChangedAircraftEnabled); + connect(sGui->getIContextNetwork(), &IContextNetwork::changedFastPositionUpdates, this, &CMappingComponent::ps_onFastPositionUpdatesEnabled); + connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CMappingComponent::ps_onConnectionStatusChanged); + + // requires simulator context + connect(this->ui->tvp_SimulatedAircraft, &CAircraftModelView::objectChanged, this, &CMappingComponent::ps_onChangedSimulatedAircraftInView); + + // with external core models might be already available + this->ps_onAircraftModelsLoaded(); } CMappingComponent::~CMappingComponent() @@ -98,25 +113,6 @@ namespace BlackGui return this->ui->tvp_AircraftModels->container().findModelsStartingWith(modelName, cs); } - void CMappingComponent::runtimeHasBeenSet() - { - Q_ASSERT(getIContextSimulator()); - Q_ASSERT(getIContextNetwork()); - connect(getIContextSimulator(), &IContextSimulator::installedAircraftModelsChanged, this, &CMappingComponent::ps_onAircraftModelsLoaded); - connect(getIContextSimulator(), &IContextSimulator::modelMatchingCompleted, this, &CMappingComponent::ps_onModelMatchingCompleted); - connect(getIContextSimulator(), &IContextSimulator::airspaceSnapshotHandled, this, &CMappingComponent::ps_onAirspaceSnapshotHandled); - connect(getIContextNetwork(), &IContextNetwork::changedRemoteAircraftModel, this, &CMappingComponent::ps_onRemoteAircraftModelChanged); - connect(getIContextNetwork(), &IContextNetwork::changedRemoteAircraftEnabled, this, &CMappingComponent::ps_onChangedAircraftEnabled); - connect(getIContextNetwork(), &IContextNetwork::changedFastPositionUpdates, this, &CMappingComponent::ps_onFastPositionUpdatesEnabled); - connect(getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CMappingComponent::ps_onConnectionStatusChanged); - - // requires simulator context - connect(this->ui->tvp_SimulatedAircraft, &CAircraftModelView::objectChanged, this, &CMappingComponent::ps_onChangedSimulatedAircraftInView); - - // with external core models might be already available - this->ps_onAircraftModelsLoaded(); - } - void CMappingComponent::ps_onAircraftModelsLoaded() { if (ui->tvp_AircraftModels->displayAutomatically()) @@ -153,14 +149,14 @@ namespace BlackGui void CMappingComponent::ps_onChangedSimulatedAircraftInView(const BlackMisc::CVariant &object, const BlackMisc::CPropertyIndex &index) { const CSimulatedAircraft sa = object.to(); // changed in GUI - const CSimulatedAircraft saFromBackend = this->getIContextNetwork()->getAircraftInRangeForCallsign(sa.getCallsign()); + const CSimulatedAircraft saFromBackend = sGui->getIContextNetwork()->getAircraftInRangeForCallsign(sa.getCallsign()); if (!saFromBackend.hasValidCallsign()) { return; } // obviously deleted if (index.contains(CSimulatedAircraft::IndexEnabled)) { bool enabled = sa.propertyByIndex(index).toBool(); if (saFromBackend.isEnabled() == enabled) { return; } CLogMessage(this).info("Request to %1 aircraft %2") << (enabled ? "enable" : "disable") << saFromBackend.getCallsign().toQString(); - this->getIContextNetwork()->updateAircraftEnabled(saFromBackend.getCallsign(), enabled, mappingIdentifier()); + sGui->getIContextNetwork()->updateAircraftEnabled(saFromBackend.getCallsign(), enabled, mappingIdentifier()); } else { @@ -178,7 +174,6 @@ namespace BlackGui void CMappingComponent::ps_onModelSelectedInView(const QModelIndex &index) { - Q_ASSERT(this->getIContextSimulator()); const CAircraftModel model = this->ui->tvp_AircraftModels->at(index); this->ui->le_AircraftModel->setText(model.getModelString()); @@ -188,7 +183,7 @@ namespace BlackGui this->ui->lbl_AircraftIconDisplayed->setText(""); this->ui->lbl_AircraftIconDisplayed->setToolTip(model.getDescription()); QString modelString(model.getModelString()); - CPixmap pm = this->getIContextSimulator()->iconForModel(modelString); + CPixmap pm = sGui->getIContextSimulator()->iconForModel(modelString); if (pm.isNull()) { this->ui->lbl_AircraftIconDisplayed->setPixmap(CIcons::crossWhite16()); @@ -211,7 +206,6 @@ namespace BlackGui void CMappingComponent::ps_onSaveAircraft() { - Q_ASSERT(getIContextSimulator()); QString cs = ui->le_Callsign->text().trimmed(); if (!CCallsign::isValidAircraftCallsign(cs)) { @@ -241,12 +235,12 @@ namespace BlackGui return; } - CSimulatedAircraft aircraftFromBackend = this->getIContextNetwork()->getAircraftInRangeForCallsign(callsign); + CSimulatedAircraft aircraftFromBackend = sGui->getIContextNetwork()->getAircraftInRangeForCallsign(callsign); bool enabled = this->ui->cb_AircraftEnabled->isChecked(); bool changed = false; if (aircraftFromBackend.getModelString() != modelString) { - CAircraftModelList models = this->getIContextSimulator()->getInstalledModelsStartingWith(modelString); + CAircraftModelList models = sGui->getIContextSimulator()->getInstalledModelsStartingWith(modelString); if (models.isEmpty()) { CLogMessage(this).validationError("No model for title: %1") << modelString; @@ -260,12 +254,12 @@ namespace BlackGui CAircraftModel model(models.front()); model.setModelType(CAircraftModel::TypeManuallySet); CLogMessage(this).info("Requesting changes for %1") << callsign.asString(); - this->getIContextNetwork()->updateAircraftModel(aircraftFromBackend.getCallsign(), model, mappingIdentifier()); + sGui->getIContextNetwork()->updateAircraftModel(aircraftFromBackend.getCallsign(), model, mappingIdentifier()); changed = true; } if (aircraftFromBackend.isEnabled() != enabled) { - this->getIContextNetwork()->updateAircraftEnabled(aircraftFromBackend.getCallsign(), enabled, mappingIdentifier()); + sGui->getIContextNetwork()->updateAircraftEnabled(aircraftFromBackend.getCallsign(), enabled, mappingIdentifier()); changed = true; } @@ -299,8 +293,7 @@ namespace BlackGui void CMappingComponent::ps_onModelsUpdateRequested() { - Q_ASSERT(getIContextSimulator()); - CAircraftModelList ml(getIContextSimulator()->getInstalledModels()); + CAircraftModelList ml(sGui->getIContextSimulator()->getInstalledModels()); this->ui->tvp_AircraftModels->updateContainer(ml); // model completer @@ -349,33 +342,33 @@ namespace BlackGui void CMappingComponent::ps_onMenuChangeFastPositionUpdates(const CSimulatedAircraft &aircraft) { - if (getIContextNetwork()) + if (sGui->getIContextNetwork()) { - getIContextNetwork()->updateFastPositionEnabled(aircraft.getCallsign(), aircraft.fastPositionUpdates(), mappingIdentifier()); + sGui->getIContextNetwork()->updateFastPositionEnabled(aircraft.getCallsign(), aircraft.fastPositionUpdates(), mappingIdentifier()); } } void CMappingComponent::ps_onMenuHighlightInSimulator(const CSimulatedAircraft &aircraft) { - if (getIContextSimulator()) + if (sGui->getIContextSimulator()) { - getIContextSimulator()->highlightAircraft(aircraft, true, IContextSimulator::HighlightTime()); + sGui->getIContextSimulator()->highlightAircraft(aircraft, true, IContextSimulator::HighlightTime()); } } void CMappingComponent::ps_onMenuEnableAircraft(const CSimulatedAircraft &aircraft) { - if (getIContextNetwork()) + if (sGui->getIContextNetwork()) { - getIContextNetwork()->updateAircraftEnabled(aircraft.getCallsign(), aircraft.isEnabled(), mappingIdentifier()); + sGui->getIContextNetwork()->updateAircraftEnabled(aircraft.getCallsign(), aircraft.isEnabled(), mappingIdentifier()); } } void CMappingComponent::ps_onMenuRequestModelReload() { - if (this->getIContextSimulator()) + if (sGui->getIContextSimulator()) { - this->getIContextSimulator()->reloadInstalledModels(); + sGui->getIContextSimulator()->reloadInstalledModels(); CLogMessage(this).info("Requested to reload simulator aircraft models"); } } @@ -391,8 +384,6 @@ namespace BlackGui void CMappingComponent::updateSimulatedAircraftView(bool forceUpdate) { - Q_ASSERT_X(getIContextNetwork(), Q_FUNC_INFO, "missing network context"); - Q_ASSERT_X(getIContextSimulator(), Q_FUNC_INFO, "missing simulator context"); if (!forceUpdate && !this->isVisibleWidget()) { m_missedSimulatedAircraftUpdate = true; @@ -400,9 +391,9 @@ namespace BlackGui } m_missedSimulatedAircraftUpdate = false; - if (getIContextSimulator()->getSimulatorStatus() > 0) + if (sGui->getIContextSimulator()->getSimulatorStatus() > 0) { - const CSimulatedAircraftList aircraft(getIContextNetwork()->getAircraftInRange()); + const CSimulatedAircraftList aircraft(sGui->getIContextNetwork()->getAircraftInRange()); this->ui->tvp_SimulatedAircraft->updateContainer(aircraft); } else diff --git a/src/blackgui/components/mappingcomponent.h b/src/blackgui/components/mappingcomponent.h index d476783cf..147e2f057 100644 --- a/src/blackgui/components/mappingcomponent.h +++ b/src/blackgui/components/mappingcomponent.h @@ -13,7 +13,6 @@ #define BLACKGUI_MAPPINGCOMPONENT_H #include "blackgui/blackguiexport.h" -#include "blackgui/components/enableforruntime.h" #include "blackgui/components/enablefordockwidgetinfoarea.h" #include "blackgui/components/updatetimer.h" #include "blackgui/views/checkboxdelegate.h" @@ -34,8 +33,7 @@ namespace BlackGui //! Mappings, models etc. class BLACKGUI_EXPORT CMappingComponent : public QFrame, - public CEnableForDockWidgetInfoArea, - public CEnableForRuntime + public CEnableForDockWidgetInfoArea { Q_OBJECT @@ -59,10 +57,6 @@ namespace BlackGui //! Request a text message void requestTextMessageWidget(const BlackMisc::Aviation::CCallsign &callsign); - protected: - //! \copydoc CEnableForRuntime::runtimeHasBeenSet - virtual void runtimeHasBeenSet() override; - private slots: //! Aircraft models available void ps_onAircraftModelsLoaded(); diff --git a/src/blackgui/components/registercomponent.cpp b/src/blackgui/components/registercomponent.cpp index b2f00189a..915e79da7 100644 --- a/src/blackgui/components/registercomponent.cpp +++ b/src/blackgui/components/registercomponent.cpp @@ -9,6 +9,7 @@ #include "registercomponent.h" #include "ui_registercomponent.h" +#include "blackgui/guiapplication.h" #include "blackcore/contextapplication.h" using namespace BlackCore; @@ -23,6 +24,8 @@ namespace BlackGui m_updateTimer(new CUpdateTimer("CRegisterComponent", &CRegisterComponent::ps_update, this)) { ui->setupUi(this); + m_updateTimer->setUpdateIntervalSeconds(20); + connect(sGui->getIContextApplication(), &IContextApplication::registrationChanged, this, &CRegisterComponent::ps_update); } CRegisterComponent::~CRegisterComponent() @@ -30,15 +33,7 @@ namespace BlackGui void CRegisterComponent::ps_update() { - this->ui->tvp_RegisteredComponents->updateContainer(getIContextApplication()->getRegisteredApplications()); + this->ui->tvp_RegisteredComponents->updateContainer(sGui->getIContextApplication()->getRegisteredApplications()); } - - void CRegisterComponent::runtimeHasBeenSet() - { - Q_ASSERT_X(getIContextApplication(), Q_FUNC_INFO, "Missing context"); - m_updateTimer->setUpdateIntervalSeconds(20); - QObject::connect(getIContextApplication(), &IContextApplication::registrationChanged, this, &CRegisterComponent::ps_update); - } - } // ns } // ns diff --git a/src/blackgui/components/registercomponent.h b/src/blackgui/components/registercomponent.h index 960ea8cf7..4fb310442 100644 --- a/src/blackgui/components/registercomponent.h +++ b/src/blackgui/components/registercomponent.h @@ -10,7 +10,6 @@ #ifndef BLACKGUI_COMPONENTS_REGISTERCOMPONENT_H #define BLACKGUI_COMPONENTS_REGISTERCOMPONENT_H -#include "blackgui/components/enableforruntime.h" #include "blackgui/components/updatetimer.h" #include @@ -22,8 +21,7 @@ namespace BlackGui { //! Register components in the GUI class BLACKGUI_EXPORT CRegisterComponent : - public QFrame, - public CEnableForRuntime + public QFrame { Q_OBJECT @@ -34,10 +32,6 @@ namespace BlackGui //! Destructor ~CRegisterComponent(); - protected: - //! \copydoc CEnableForRuntime::runtimeHasBeenSet - virtual void runtimeHasBeenSet() override; - private slots: //! Update data void ps_update(); diff --git a/src/blackgui/components/remoteaircraftselector.cpp b/src/blackgui/components/remoteaircraftselector.cpp index 125a8a3d0..7912de890 100644 --- a/src/blackgui/components/remoteaircraftselector.cpp +++ b/src/blackgui/components/remoteaircraftselector.cpp @@ -9,6 +9,7 @@ #include "remoteaircraftselector.h" #include "ui_remoteaircraftselector.h" +#include "blackgui/guiapplication.h" #include "blackcore/contextnetwork.h" using namespace BlackMisc; @@ -20,13 +21,16 @@ namespace BlackGui { namespace Components { - CRemoteAircraftSelector::CRemoteAircraftSelector(QWidget *parent) : QFrame(parent), - CEnableForRuntime(nullptr, false), ui(new Ui::CRemoteAircraftSelector) { ui->setupUi(this); + bool s = connect(sGui->getIContextNetwork(), &IContextNetwork::removedAircraft, this, &CRemoteAircraftSelector::ps_onRemovedAircraft); + Q_ASSERT(s); + s = connect(sGui->getIContextNetwork(), &IContextNetwork::addedAircraft, this, &CRemoteAircraftSelector::ps_onAddedAircraft); + Q_ASSERT(s); + Q_UNUSED(s); } CRemoteAircraftSelector::~CRemoteAircraftSelector() { } @@ -39,16 +43,6 @@ namespace BlackGui return m_aircraft[index].getCallsign(); } - void CRemoteAircraftSelector::runtimeHasBeenSet() - { - Q_ASSERT(getIContextNetwork()); - bool s = connect(getIContextNetwork(), &IContextNetwork::removedAircraft, this, &CRemoteAircraftSelector::ps_onRemovedAircraft); - Q_ASSERT(s); - s = connect(getIContextNetwork(), &IContextNetwork::addedAircraft, this, &CRemoteAircraftSelector::ps_onAddedAircraft); - Q_ASSERT(s); - Q_UNUSED(s); - } - void CRemoteAircraftSelector::showEvent(QShowEvent *event) { // force new combobox when visible @@ -76,8 +70,7 @@ namespace BlackGui void CRemoteAircraftSelector::fillComboBox() { if (!this->isVisible()) { return; } // for performance reasons - Q_ASSERT(getIContextNetwork()); - m_aircraft = getIContextNetwork()->getAircraftInRange(); + m_aircraft = sGui->getIContextNetwork()->getAircraftInRange(); this->ui->cb_RemoteAircraftSelector->clear(); if (m_aircraft.isEmpty()) { return; } diff --git a/src/blackgui/components/remoteaircraftselector.h b/src/blackgui/components/remoteaircraftselector.h index 0612fee41..b68ec5b06 100644 --- a/src/blackgui/components/remoteaircraftselector.h +++ b/src/blackgui/components/remoteaircraftselector.h @@ -13,7 +13,6 @@ #define BLACKGUI_REMOTEAIRCRAFTSELECTOR_H #include "blackgui/blackguiexport.h" -#include "enableforruntime.h" #include "blackmisc/aviation/callsign.h" #include "blackmisc/simulation/simulatedaircraftlist.h" @@ -28,7 +27,7 @@ namespace BlackGui namespace Components { //! Select a remote aircraft - class BLACKGUI_EXPORT CRemoteAircraftSelector : public QFrame, public CEnableForRuntime + class BLACKGUI_EXPORT CRemoteAircraftSelector : public QFrame { Q_OBJECT @@ -43,9 +42,6 @@ namespace BlackGui BlackMisc::Aviation::CCallsign getSelectedCallsign() const; protected: - //! \copydoc CEnableForRuntime::runtimeHasBeenSet - virtual void runtimeHasBeenSet() override; - //! \copydoc QWidget::showEvent virtual void showEvent(QShowEvent *event) override; diff --git a/src/blackgui/components/settingscomponent.cpp b/src/blackgui/components/settingscomponent.cpp index f6e665323..27d5fa45c 100644 --- a/src/blackgui/components/settingscomponent.cpp +++ b/src/blackgui/components/settingscomponent.cpp @@ -11,6 +11,7 @@ #include "ui_settingscomponent.h" #include "blackgui/models/atcstationlistmodel.h" #include "blackgui/stylesheetutility.h" +#include "blackgui/guiapplication.h" #include "blackcore/contextnetwork.h" #include "blackcore/contextaudio.h" #include "blackmisc/dbusserver.h" @@ -38,6 +39,28 @@ namespace BlackGui { ui->setupUi(this); this->tabBar()->setExpanding(false); + + // Opacity, intervals + this->connect(this->ui->hs_SettingsGuiOpacity, &QSlider::valueChanged, this, &CSettingsComponent::changedWindowsOpacity); + this->connect(this->ui->hs_SettingsGuiAircraftRefreshTime, &QSlider::valueChanged, this, &CSettingsComponent::changedAircraftUpdateInterval); + this->connect(this->ui->hs_SettingsGuiAtcRefreshTime, &QSlider::valueChanged, this, &CSettingsComponent::changedAtcStationsUpdateInterval); + this->connect(this->ui->hs_SettingsGuiUserRefreshTime, &QSlider::valueChanged, this, &CSettingsComponent::changedUsersUpdateInterval); + + // Font + const QFont font = this->font(); + this->ui->cb_SettingsGuiFontStyle->setCurrentText(CStyleSheetUtility::fontAsCombinedWeightStyle(font)); + this->ui->cb_SettingsGuiFont->setCurrentFont(font); + this->ui->cb_SettingsGuiFontSize->setCurrentText(QString::number(font.pointSize())); + this->m_fontColor = QColor(CStyleSheetUtility::instance().fontColor()); + this->ui->le_SettingsGuiFontColor->setText(this->m_fontColor.name()); + bool connected = this->connect(this->ui->cb_SettingsGuiFont, SIGNAL(currentFontChanged(QFont)), this, SLOT(ps_fontChanged())); + Q_ASSERT(connected); + connected = this->connect(this->ui->cb_SettingsGuiFontSize, SIGNAL(currentIndexChanged(QString)), this, SLOT(ps_fontChanged())); + Q_ASSERT(connected); + connected = this->connect(this->ui->cb_SettingsGuiFontStyle, SIGNAL(currentIndexChanged(QString)), this, SLOT(ps_fontChanged())); + Q_ASSERT(connected); + this->connect(this->ui->tb_SettingsGuiFontColor, &QToolButton::clicked, this, &CSettingsComponent::ps_fontColorDialog); + Q_UNUSED(connected); } CSettingsComponent::~CSettingsComponent() @@ -76,37 +99,6 @@ namespace BlackGui this->setCurrentIndex(static_cast(tab)); } - /* - * Runtime set - */ - void CSettingsComponent::runtimeHasBeenSet() - { - // Opacity, intervals - this->connect(this->ui->hs_SettingsGuiOpacity, &QSlider::valueChanged, this, &CSettingsComponent::changedWindowsOpacity); - this->connect(this->ui->hs_SettingsGuiAircraftRefreshTime, &QSlider::valueChanged, this, &CSettingsComponent::changedAircraftUpdateInterval); - this->connect(this->ui->hs_SettingsGuiAtcRefreshTime, &QSlider::valueChanged, this, &CSettingsComponent::changedAtcStationsUpdateInterval); - this->connect(this->ui->hs_SettingsGuiUserRefreshTime, &QSlider::valueChanged, this, &CSettingsComponent::changedUsersUpdateInterval); - - // Font - const QFont font = this->font(); - this->ui->cb_SettingsGuiFontStyle->setCurrentText(CStyleSheetUtility::fontAsCombinedWeightStyle(font)); - this->ui->cb_SettingsGuiFont->setCurrentFont(font); - this->ui->cb_SettingsGuiFontSize->setCurrentText(QString::number(font.pointSize())); - this->m_fontColor = QColor(CStyleSheetUtility::instance().fontColor()); - this->ui->le_SettingsGuiFontColor->setText(this->m_fontColor.name()); - bool connected = this->connect(this->ui->cb_SettingsGuiFont, SIGNAL(currentFontChanged(QFont)), this, SLOT(ps_fontChanged())); - Q_ASSERT(connected); - connected = this->connect(this->ui->cb_SettingsGuiFontSize, SIGNAL(currentIndexChanged(QString)), this, SLOT(ps_fontChanged())); - Q_ASSERT(connected); - connected = this->connect(this->ui->cb_SettingsGuiFontStyle, SIGNAL(currentIndexChanged(QString)), this, SLOT(ps_fontChanged())); - Q_ASSERT(connected); - this->connect(this->ui->tb_SettingsGuiFontColor, &QToolButton::clicked, this, &CSettingsComponent::ps_fontColorDialog); - Q_UNUSED(connected); - } - - /* - * Font has been changed - */ void CSettingsComponent::ps_fontChanged() { QString fontSize = this->ui->cb_SettingsGuiFontSize->currentText().append("pt"); @@ -129,9 +121,6 @@ namespace BlackGui } } - /* - * Font color dialog - */ void CSettingsComponent::ps_fontColorDialog() { QColor c = QColorDialog::getColor(this->m_fontColor, this, "Font color"); diff --git a/src/blackgui/components/settingscomponent.h b/src/blackgui/components/settingscomponent.h index 3dd9b8399..f59851a7f 100644 --- a/src/blackgui/components/settingscomponent.h +++ b/src/blackgui/components/settingscomponent.h @@ -13,7 +13,6 @@ #define BLACKGUI_SETTINGSCOMPONENT_H #include "blackgui/blackguiexport.h" -#include "blackgui/components/enableforruntime.h" #include "blackmisc/network/server.h" #include #include @@ -28,8 +27,7 @@ namespace BlackGui { //! Settings component class BLACKGUI_EXPORT CSettingsComponent : - public QTabWidget, - public CEnableForRuntime + public QTabWidget { Q_OBJECT @@ -84,10 +82,6 @@ namespace BlackGui //! Set the tab void setSettingsTab(SettingTab tab); - protected: - //! \copydoc CEnableForRuntime::runtimeHasBeenSet - virtual void runtimeHasBeenSet() override; - private slots: //! Font has been changed void ps_fontChanged(); diff --git a/src/blackgui/components/settingshotkeycomponent.cpp b/src/blackgui/components/settingshotkeycomponent.cpp index ff7d6cb14..12f98257d 100644 --- a/src/blackgui/components/settingshotkeycomponent.cpp +++ b/src/blackgui/components/settingshotkeycomponent.cpp @@ -10,6 +10,7 @@ #include "settingshotkeycomponent.h" #include "ui_settingshotkeycomponent.h" #include "blackgui/hotkeydialog.h" +#include "blackgui/guiapplication.h" #include "blackcore/contextapplication.h" #include @@ -43,7 +44,7 @@ namespace BlackGui void CSettingsHotkeyComponent::ps_addEntry() { BlackMisc::CIdentifierList registeredApps; - if (getIContextApplication()) registeredApps = getIContextApplication()->getRegisteredApplications(); + if (sGui->getIContextApplication()) registeredApps = sGui->getIContextApplication()->getRegisteredApplications(); // add local application registeredApps.push_back(CIdentifier()); auto selectedActionHotkey = CHotkeyDialog::getActionHotkey(CActionHotkey(), registeredApps, this); @@ -67,7 +68,7 @@ namespace BlackGui Q_ASSERT(indexHotkey.data(CActionHotkeyListModel::ActionHotkeyRole).canConvert()); CActionHotkey actionHotkey = indexHotkey.data(CActionHotkeyListModel::ActionHotkeyRole).value(); BlackMisc::CIdentifierList registeredApps; - if (getIContextApplication()) registeredApps = getIContextApplication()->getRegisteredApplications(); + if (sGui->getIContextApplication()) registeredApps = sGui->getIContextApplication()->getRegisteredApplications(); // add local application registeredApps.push_back(CIdentifier()); auto selectedActionHotkey = CHotkeyDialog::getActionHotkey(actionHotkey, registeredApps, this); diff --git a/src/blackgui/components/settingshotkeycomponent.h b/src/blackgui/components/settingshotkeycomponent.h index 39359722b..b4807464f 100644 --- a/src/blackgui/components/settingshotkeycomponent.h +++ b/src/blackgui/components/settingshotkeycomponent.h @@ -13,7 +13,6 @@ #define BLACKGUI_COMPONENTS_SETTINGSHOTKEYCOMPONENT_H #include "blackgui/models/actionhotkeylistmodel.h" -#include "blackgui/components/enableforruntime.h" #include "blackcore/settings/application.h" #include "blackcore/actionbind.h" #include @@ -29,8 +28,7 @@ namespace BlackGui //! Configure hotkeys class BLACKGUI_EXPORT CSettingsHotkeyComponent : - public QFrame, - public CEnableForRuntime + public QFrame { Q_OBJECT diff --git a/src/blackgui/components/settingsnetworkcomponent.cpp b/src/blackgui/components/settingsnetworkcomponent.cpp index 213fbfbb2..efc78d997 100644 --- a/src/blackgui/components/settingsnetworkcomponent.cpp +++ b/src/blackgui/components/settingsnetworkcomponent.cpp @@ -9,6 +9,7 @@ #include "settingsnetworkcomponent.h" #include "ui_settingsnetworkcomponent.h" +#include "blackgui/guiapplication.h" #include "blackcore/contextnetwork.h" using namespace BlackCore; @@ -17,34 +18,26 @@ namespace BlackGui { namespace Components { - CSettingsNetworkComponent::CSettingsNetworkComponent(QWidget *parent) : QFrame(parent), ui(new Ui::CSettingsNetworkComponent) { ui->setupUi(this); connect(this->ui->cb_FastPositionUpdates, &QCheckBox::released, this, &CSettingsNetworkComponent::ps_guiValuesChanged); + bool enabled = sGui->getIContextNetwork()->isFastPositionSendingEnabled(); + this->ui->cb_FastPositionUpdates->setChecked(enabled); } CSettingsNetworkComponent::~CSettingsNetworkComponent() { } - void CSettingsNetworkComponent::runtimeHasBeenSet() - { - Q_ASSERT(this->getIContextNetwork()); - bool enabled = this->getIContextNetwork()->isFastPositionSendingEnabled(); - this->ui->cb_FastPositionUpdates->setChecked(enabled); - } - void CSettingsNetworkComponent::ps_guiValuesChanged() { - Q_ASSERT(this->getIContextNetwork()); QObject *sender = QObject::sender(); if (sender == ui->cb_FastPositionUpdates) { bool enabled = this->ui->cb_FastPositionUpdates->isChecked(); - this->getIContextNetwork()->enableFastPositionSending(enabled); + sGui->getIContextNetwork()->enableFastPositionSending(enabled); } } - } // ns } // ns diff --git a/src/blackgui/components/settingsnetworkcomponent.h b/src/blackgui/components/settingsnetworkcomponent.h index ab81c50c7..e3b5d5d9d 100644 --- a/src/blackgui/components/settingsnetworkcomponent.h +++ b/src/blackgui/components/settingsnetworkcomponent.h @@ -13,7 +13,6 @@ #define BLACKGUI_SETTINGSNETWORKCOMPONENT_H #include "blackgui/blackguiexport.h" -#include "blackgui/components/enableforruntime.h" #include namespace Ui { class CSettingsNetworkComponent; } @@ -25,8 +24,7 @@ namespace BlackGui //! General settings for network class BLACKGUI_EXPORT CSettingsNetworkComponent : - public QFrame, - public CEnableForRuntime + public QFrame { Q_OBJECT @@ -37,10 +35,6 @@ namespace BlackGui //! Destructor ~CSettingsNetworkComponent(); - protected: - //! \copydoc CEnableForRuntime::runtimeHasBeenSet - virtual void runtimeHasBeenSet() override; - private: //! GUI values have been changed void ps_guiValuesChanged(); diff --git a/src/blackgui/components/settingsnetworkserverscomponent.cpp b/src/blackgui/components/settingsnetworkserverscomponent.cpp index 1ad1232d2..c8b61f5fb 100644 --- a/src/blackgui/components/settingsnetworkserverscomponent.cpp +++ b/src/blackgui/components/settingsnetworkserverscomponent.cpp @@ -9,6 +9,7 @@ #include "settingsnetworkserverscomponent.h" #include "ui_settingsnetworkserverscomponent.h" +#include "blackgui/guiapplication.h" #include "blackcore/contextnetwork.h" #include "blackcore/setupreader.h" #include "blackcore/contextapplication.h" @@ -109,7 +110,7 @@ namespace BlackGui if (msgs.isEmpty() && sender == this->ui->pb_SaveServer) { - msg = this->getIContextApplication()->saveSettings(m_trafficNetworkServers.getKey()); + msg = sGui->getIContextApplication()->saveSettings(m_trafficNetworkServers.getKey()); } if (!msg.isEmpty()) diff --git a/src/blackgui/components/settingsnetworkserverscomponent.h b/src/blackgui/components/settingsnetworkserverscomponent.h index dc250fe2b..ecf69ecfa 100644 --- a/src/blackgui/components/settingsnetworkserverscomponent.h +++ b/src/blackgui/components/settingsnetworkserverscomponent.h @@ -13,7 +13,6 @@ #define BLACKGUI_SETTINGSNETWORKSERVERSCOMPONENT_H #include "blackgui/blackguiexport.h" -#include "blackgui/components/enableforruntime.h" #include "blackcore/data/globalsetup.h" #include "blackcore/settings/network.h" #include @@ -27,8 +26,7 @@ namespace BlackGui { //! Settings for network servers class BLACKGUI_EXPORT CSettingsNetworkServersComponent : - public QFrame, - public CEnableForRuntime + public QFrame { Q_OBJECT diff --git a/src/blackgui/components/settingssimulatorcomponent.cpp b/src/blackgui/components/settingssimulatorcomponent.cpp index e4c80c80f..6ffe57965 100644 --- a/src/blackgui/components/settingssimulatorcomponent.cpp +++ b/src/blackgui/components/settingssimulatorcomponent.cpp @@ -1,11 +1,12 @@ #include "settingssimulatorcomponent.h" #include "ui_settingssimulatorcomponent.h" +#include "blackgui/guiapplication.h" +#include "blackgui/pluginconfigwindow.h" +#include "blackgui/plugindetailswindow.h" #include "blackcore/contextsimulator.h" #include "blackcore/contextnetwork.h" #include "blackgui/pluginconfig.h" -#include "blackgui/pluginconfigwindow.h" -#include "blackgui/plugindetailswindow.h" #include "blackmisc/simulation/simulatorplugininfolist.h" #include "blackmisc/simulation/simulatedaircraftlist.h" #include "blackmisc/logmessage.h" @@ -26,7 +27,6 @@ namespace BlackGui { CSettingsSimulatorComponent::CSettingsSimulatorComponent(QWidget *parent) : QFrame(parent), - CEnableForRuntime(nullptr, false), ui(new Ui::CSettingsSimulatorComponent), m_plugins(new CPluginManagerSimulator(this)) { @@ -35,14 +35,6 @@ namespace BlackGui CLedWidget::LedShape shape = CLedWidget::Circle; this->ui->led_RestrictedRendering->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "Limited", "Unlimited", 14); this->ui->led_RenderingEnabled->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "Rendering enabled", "No aircraft will be rendered", 14); - } - - CSettingsSimulatorComponent::~CSettingsSimulatorComponent() - { } - - void CSettingsSimulatorComponent::runtimeHasBeenSet() - { - Q_ASSERT_X(this->getIContextSimulator(), Q_FUNC_INFO, "missing simulator"); // set values for (const auto &p : getAvailablePlugins()) @@ -52,7 +44,7 @@ namespace BlackGui } // connects - connect(this->getIContextSimulator(), &IContextSimulator::simulatorPluginChanged, this, &CSettingsSimulatorComponent::ps_simulatorPluginChanged); + connect(sGui->getIContextSimulator(), &IContextSimulator::simulatorPluginChanged, this, &CSettingsSimulatorComponent::ps_simulatorPluginChanged); connect(this->ui->ps_EnabledSimulators, &CPluginSelector::pluginStateChanged, this, &CSettingsSimulatorComponent::ps_pluginStateChanged); connect(this->ui->ps_EnabledSimulators, &CPluginSelector::pluginDetailsRequested, this, &CSettingsSimulatorComponent::ps_showPluginDetails); connect(this->ui->ps_EnabledSimulators, &CPluginSelector::pluginConfigRequested, this, &CSettingsSimulatorComponent::ps_showPluginConfig); @@ -65,21 +57,22 @@ namespace BlackGui connect(this->ui->sb_MaxDistance, &QSpinBox::editingFinished, this, &CSettingsSimulatorComponent::ps_onApplyMaxRenderedDistance); // values - this->ps_simulatorPluginChanged(getIContextSimulator()->getSimulatorPluginInfo()); + this->ps_simulatorPluginChanged(sGui->getIContextSimulator()->getSimulatorPluginInfo()); } + CSettingsSimulatorComponent::~CSettingsSimulatorComponent() + { } + void CSettingsSimulatorComponent::setGuiValues() { - Q_ASSERT(getIContextSimulator()); - // time sync this->ui->cb_TimeSync->setEnabled(m_pluginLoaded); this->ui->le_TimeSyncOffset->setEnabled(m_pluginLoaded); this->ui->pb_ApplyTimeSync->setEnabled(m_pluginLoaded); // led - this->ui->led_RestrictedRendering->setOn(m_pluginLoaded ? getIContextSimulator()->isRenderingRestricted() : false); - this->ui->lbl_RestrictionText->setText(m_pluginLoaded ? getIContextSimulator()->getRenderRestrictionText() : ""); + this->ui->led_RestrictedRendering->setOn(m_pluginLoaded ? sGui->getIContextSimulator()->isRenderingRestricted() : false); + this->ui->lbl_RestrictionText->setText(m_pluginLoaded ? sGui->getIContextSimulator()->getRenderRestrictionText() : ""); this->ui->sb_MaxDistance->setEnabled(m_pluginLoaded); this->ui->sb_MaxAircraft->setEnabled(m_pluginLoaded); @@ -90,21 +83,21 @@ namespace BlackGui if (m_pluginLoaded) { - bool timeSynced = this->getIContextSimulator()->isTimeSynchronized(); + bool timeSynced = sGui->getIContextSimulator()->isTimeSynchronized(); this->ui->cb_TimeSync->setChecked(timeSynced); - CTime timeOffset = this->getIContextSimulator()->getTimeSynchronizationOffset(); + CTime timeOffset = sGui->getIContextSimulator()->getTimeSynchronizationOffset(); this->ui->le_TimeSyncOffset->setText(timeOffset.formattedHrsMin()); - int maxAircraft = getIContextSimulator()->getMaxRenderedAircraft(); + int maxAircraft = sGui->getIContextSimulator()->getMaxRenderedAircraft(); this->ui->sb_MaxAircraft->setValue(maxAircraft); - CLength distanceBoundary(getIContextSimulator()->getRenderedDistanceBoundary()); + CLength distanceBoundary(sGui->getIContextSimulator()->getRenderedDistanceBoundary()); int distanceBoundaryNM = distanceBoundary.valueInteger(CLengthUnit::NM()); - CLength maxDistance(getIContextSimulator()->getMaxRenderedDistance()); + CLength maxDistance(sGui->getIContextSimulator()->getMaxRenderedDistance()); int distanceNM = maxDistance.isNull() ? distanceBoundaryNM : maxDistance.valueInteger(CLengthUnit::NM()); this->ui->sb_MaxDistance->setMaximum(distanceBoundaryNM); this->ui->sb_MaxDistance->setValue(distanceNM); - this->ui->led_RenderingEnabled->setOn(getIContextSimulator()->isRenderingEnabled()); + this->ui->led_RenderingEnabled->setOn(sGui->getIContextSimulator()->isRenderingEnabled()); } else { @@ -114,12 +107,12 @@ namespace BlackGui CSimulatorPluginInfoList CSettingsSimulatorComponent::getAvailablePlugins() const { - return getIContextSimulator()->getAvailableSimulatorPlugins(); + return sGui->getIContextSimulator()->getAvailableSimulatorPlugins(); } void CSettingsSimulatorComponent::ps_pluginStateChanged(const QString &identifier, bool enabled) { - Q_ASSERT(getIContextSimulator()); + Q_ASSERT(sGui->getIContextSimulator()); CSimulatorPluginInfoList simDrivers(getAvailablePlugins()); auto selected = std::find_if(simDrivers.begin(), simDrivers.end(), @@ -136,12 +129,12 @@ namespace BlackGui if (enabled) { - getIContextSimulator()->startSimulatorPlugin(*selected); + sGui->getIContextSimulator()->startSimulatorPlugin(*selected); CLogMessage(this).info("Started listening for %1") << selected->getName(); } else { - getIContextSimulator()->stopSimulatorPlugin(*selected); + sGui->getIContextSimulator()->stopSimulatorPlugin(*selected); CLogMessage(this).info("Stopped listening for %1") << selected->getName(); } @@ -150,18 +143,16 @@ namespace BlackGui void CSettingsSimulatorComponent::ps_onApplyMaxRenderedAircraft() { - Q_ASSERT(getIContextSimulator()); - // get initial aircraft to render int noRequested = this->ui->sb_MaxAircraft->value(); - int oldValue = this->getIContextSimulator()->getMaxRenderedAircraft(); + int oldValue = sGui->getIContextSimulator()->getMaxRenderedAircraft(); if (oldValue == noRequested) { return; } // set value - this->getIContextSimulator()->setMaxRenderedAircraft(noRequested); + sGui->getIContextSimulator()->setMaxRenderedAircraft(noRequested); // re-read real value - int noRendered = this->getIContextSimulator()->getMaxRenderedAircraft(); + int noRendered = sGui->getIContextSimulator()->getMaxRenderedAircraft(); if (noRequested == noRendered) { CLogMessage(this).info("Max.rendered aircraft: %1") << noRendered; @@ -176,11 +167,9 @@ namespace BlackGui void CSettingsSimulatorComponent::ps_onApplyMaxRenderedDistance() { - Q_ASSERT_X(getIContextSimulator(), Q_FUNC_INFO, "missing context"); - // get initial aircraft to render int maxDistanceNM = this->ui->sb_MaxDistance->value(); - CLength currentDistance(this->getIContextSimulator()->getMaxRenderedDistance()); + CLength currentDistance(sGui->getIContextSimulator()->getMaxRenderedDistance()); if (maxDistanceNM == currentDistance.valueInteger(CLengthUnit::NM())) { return; @@ -189,15 +178,14 @@ namespace BlackGui { CLength distance(maxDistanceNM, CLengthUnit::NM()); CLogMessage(this).info("Max.distance requested: %1") << distance.valueRoundedWithUnit(2, true); - this->getIContextSimulator()->setMaxRenderedDistance(distance); + sGui->getIContextSimulator()->setMaxRenderedDistance(distance); this->setGuiValues(); } } void CSettingsSimulatorComponent::ps_onApplyDisableRendering() { - Q_ASSERT(getIContextSimulator()); - this->getIContextSimulator()->setMaxRenderedAircraft(0); + sGui->getIContextSimulator()->setMaxRenderedAircraft(0); this->setGuiValues(); } @@ -216,14 +204,13 @@ namespace BlackGui } else { - getIContextSimulator()->setTimeSynchronization(timeSync, ost); + sGui->getIContextSimulator()->setTimeSynchronization(timeSync, ost); } } void CSettingsSimulatorComponent::ps_clearRestricedRendering() { - Q_ASSERT(getIContextSimulator()); - this->getIContextSimulator()->deleteAllRenderingRestrictions(); + sGui->getIContextSimulator()->deleteAllRenderingRestrictions(); this->setGuiValues(); } @@ -283,7 +270,6 @@ namespace BlackGui } CPluginConfigWindow *window = config->createConfigWindow(qApp->activeWindow()); - CEnableForRuntime::setRuntimeForComponents(getRuntime(), window); window->setAttribute(Qt::WA_DeleteOnClose); window->show(); } diff --git a/src/blackgui/components/settingssimulatorcomponent.h b/src/blackgui/components/settingssimulatorcomponent.h index 71613a724..e1a233795 100644 --- a/src/blackgui/components/settingssimulatorcomponent.h +++ b/src/blackgui/components/settingssimulatorcomponent.h @@ -13,8 +13,6 @@ #include "blackcore/pluginmanagersimulator.h" #include "blackgui/blackguiexport.h" #include "blackmisc/simulation/simulatorplugininfolist.h" -#include "enableforruntime.h" -#include "enableforruntime.h" #include namespace Ui { class CSettingsSimulatorComponent; } @@ -24,7 +22,7 @@ namespace BlackGui namespace Components { //! All simulator settings component (GUI) - class BLACKGUI_EXPORT CSettingsSimulatorComponent : public QFrame, public CEnableForRuntime + class BLACKGUI_EXPORT CSettingsSimulatorComponent : public QFrame { Q_OBJECT @@ -35,10 +33,6 @@ namespace BlackGui //! Destructor ~CSettingsSimulatorComponent(); - protected: - //! \copydoc CEnableForRuntime::runtimeHasBeenSet() - virtual void runtimeHasBeenSet() override; - private slots: //! Driver plugin enabled/disabled //! \todo Unload plugin if user disables it while running @@ -69,7 +63,6 @@ namespace BlackGui void ps_showPluginConfig(const QString &identifier); private: - //! Set the GUI values void setGuiValues(); diff --git a/src/blackgui/components/simulatorcomponent.cpp b/src/blackgui/components/simulatorcomponent.cpp index 66a24c62a..5f3faa2a0 100644 --- a/src/blackgui/components/simulatorcomponent.cpp +++ b/src/blackgui/components/simulatorcomponent.cpp @@ -9,6 +9,7 @@ #include "simulatorcomponent.h" #include "ui_simulatorcomponent.h" +#include "blackgui/guiapplication.h" #include "blackcore/contextsimulator.h" #include "blackcore/contextownaircraft.h" #include "blackcore/simulator.h" @@ -33,6 +34,13 @@ namespace BlackGui this->ui->tvp_LiveData->setIconMode(true); this->ui->tvp_LiveData->setAutoResizeFrequency(10); // only resize every n-th time this->addOrUpdateByName("info", "no data yet", CIcons::StandardIconWarning16); + + connect(sGui->getIContextSimulator(), &IContextSimulator::simulatorStatusChanged, this, &CSimulatorComponent::ps_onSimulatorStatusChanged); + this->setUpdateInterval(getUpdateIntervalMs()); + if (sGui->getIContextSimulator()->getSimulatorStatus() == 0) + { + this->stopTimer(); + } } CSimulatorComponent::~CSimulatorComponent() @@ -61,12 +69,10 @@ namespace BlackGui void CSimulatorComponent::update() { - Q_ASSERT_X(getIContextSimulator(), Q_FUNC_INFO, "No simulator context"); - if (!this->isVisibleWidget()) return; // no updates on invisible widgets - if (!this->getIContextOwnAircraft()) return; + if (!sGui->getIContextOwnAircraft()) return; - int simualtorStatus = this->getIContextSimulator()->getSimulatorStatus(); + int simualtorStatus = sGui->getIContextSimulator()->getSimulatorStatus(); if (simualtorStatus == 0) { addOrUpdateByName("info", tr("No simulator available"), CIcons::StandardIconWarning16); @@ -77,7 +83,7 @@ namespace BlackGui { this->addOrUpdateByName("info", tr("Simulator (%1) not yet running").arg( - getIContextSimulator()->getSimulatorPluginInfo().getSimulator() + sGui->getIContextSimulator()->getSimulatorPluginInfo().getSimulator() ), CIcons::StandardIconWarning16); return; @@ -89,7 +95,7 @@ namespace BlackGui this->clear(); } - CSimulatedAircraft ownAircraft = this->getIContextOwnAircraft()->getOwnAircraft(); + CSimulatedAircraft ownAircraft = sGui->getIContextOwnAircraft()->getOwnAircraft(); CAircraftSituation s = ownAircraft.getSituation(); CComSystem c1 = ownAircraft.getCom1System(); CComSystem c2 = ownAircraft.getCom2System(); @@ -109,19 +115,6 @@ namespace BlackGui this->addOrUpdateByName("Transponder", ownAircraft.getTransponderCodeFormatted(), CIcons::StandardIconRadio16); } - void CSimulatorComponent::runtimeHasBeenSet() - { - Q_ASSERT_X(this->getIContextSimulator(), Q_FUNC_INFO, "Missing simulator context"); - if (!this->getIContextSimulator()) { return; } - QObject::connect(this->getIContextSimulator(), &IContextSimulator::simulatorStatusChanged, this, &CSimulatorComponent::ps_onSimulatorStatusChanged); - - this->setUpdateInterval(getUpdateIntervalMs()); - if (getIContextSimulator()->getSimulatorStatus() == 0) - { - this->stopTimer(); - } - } - void CSimulatorComponent::ps_onSimulatorStatusChanged(int status) { if (status & ISimulator::Connected) @@ -139,10 +132,8 @@ namespace BlackGui int CSimulatorComponent::getUpdateIntervalMs() const { - Q_ASSERT(this->getIContextSimulator()); - // much slower updates via DBus - return this->getIContextSimulator()->isUsingImplementingObject() ? 500 : 5000; + return sGui->getIContextSimulator()->isUsingImplementingObject() ? 500 : 5000; } } } // namespace diff --git a/src/blackgui/components/simulatorcomponent.h b/src/blackgui/components/simulatorcomponent.h index d12dec4eb..112d0b94d 100644 --- a/src/blackgui/components/simulatorcomponent.h +++ b/src/blackgui/components/simulatorcomponent.h @@ -13,7 +13,6 @@ #define BLACKGUI_SIMULATORCOMPONENT_H #include "blackgui/blackguiexport.h" -#include "enableforruntime.h" #include "blackmisc/icon.h" #include "blackgui/components/enablefordockwidgetinfoarea.h" #include "blackgui/components/updatetimer.h" @@ -30,8 +29,7 @@ namespace BlackGui //! Simulator component class BLACKGUI_EXPORT CSimulatorComponent : public QTabWidget, - public CEnableForDockWidgetInfoArea, - public CEnableForRuntime + public CEnableForDockWidgetInfoArea { Q_OBJECT @@ -68,10 +66,6 @@ namespace BlackGui //! \copydoc CUpdateTimer::stopTimer void stopTimer() { Q_ASSERT(this->m_updateTimer); this->m_updateTimer->stopTimer(); } - protected: - //! \copydoc CEnableForRuntime::runtimeHasBeenSet - void runtimeHasBeenSet() override; - private slots: //! \copydoc ISimulator::simulatorStatusChanged void ps_onSimulatorStatusChanged(int status); diff --git a/src/blackgui/components/textmessagecomponent.cpp b/src/blackgui/components/textmessagecomponent.cpp index f8af3169a..34c033199 100644 --- a/src/blackgui/components/textmessagecomponent.cpp +++ b/src/blackgui/components/textmessagecomponent.cpp @@ -9,6 +9,7 @@ #include "textmessagecomponent.h" #include "ui_textmessagecomponent.h" +#include "blackgui/guiapplication.h" #include "blackcore/contextaudio.h" #include "blackmisc/network/user.h" #include "blackmisc/audio/notificationsounds.h" @@ -36,7 +37,6 @@ namespace BlackGui CTextMessageComponent::CTextMessageComponent(QWidget *parent) : QFrame(parent), - CEnableForRuntime(nullptr, false), ui(new Ui::CTextMessageComponent) { ui->setupUi(this); @@ -45,6 +45,10 @@ namespace BlackGui connect(this->ui->le_textMessages, &QLineEdit::returnPressed, this, &CTextMessageComponent::ps_textMessageEntered); this->ui->tvp_TextMessagesAll->setResizeMode(CTextMessageView::ResizingAuto); + + connect(sGui->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CTextMessageComponent::ps_onChangedAircraftCockpit); + connect(this->getDockWidgetInfoArea(), &CDockWidgetInfoArea::widgetTopLevelChanged, this, &CTextMessageComponent::ps_topLevelChanged); + connect(this, &CTextMessageComponent::commandEntered, sApp->getCoreFacade(), &CCoreFacade::parseCommandLine); } CTextMessageComponent::~CTextMessageComponent() @@ -63,7 +67,7 @@ namespace BlackGui case TextMessagesUnicom: return this->ui->tb_TextMessagesUnicom; default: - qFatal("Wrong index"); + Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong index"); break; } return nullptr; @@ -81,7 +85,7 @@ namespace BlackGui void CTextMessageComponent::displayTextMessage(const CTextMessageList &messages) { if (messages.isEmpty()) return; - foreach(CTextMessage message, messages) + foreach (CTextMessage message, messages) { bool relevantForMe = false; @@ -89,9 +93,9 @@ namespace BlackGui if (message.isSelcalMessage() && getOwnAircraft().isSelcalSelected(message.getSelcalCode())) { // this is SELCAL for me - if (this->getIContextAudio()) + if (sGui->getIContextAudio()) { - this->getIContextAudio()->playSelcalTone(message.getSelcalCode()); + sGui->getIContextAudio()->playSelcalTone(message.getSelcalCode()); } else { @@ -161,20 +165,6 @@ namespace BlackGui this->showCurrentFrequenciesFromCockpit(); } - void CTextMessageComponent::runtimeHasBeenSet() - { - Q_ASSERT(this->getIContextOwnAircraft()); - Q_ASSERT(this->getIContextNetwork()); - Q_ASSERT(this->getIContextAudio()); - - connect(this->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CTextMessageComponent::ps_onChangedAircraftCockpit); - connect(this->getDockWidgetInfoArea(), &CDockWidgetInfoArea::widgetTopLevelChanged, this, &CTextMessageComponent::ps_topLevelChanged); - connect(this, &CTextMessageComponent::commandEntered, this->getRuntime(), &CCoreFacade::parseCommandLine); - } - - /* - * Is the tab of the message's receiver selected? - */ bool CTextMessageComponent::isCorrespondingTextMessageTabSelected(CTextMessage textMessage) const { if (!this->isVisibleWidget()) { return false; } @@ -208,7 +198,7 @@ namespace BlackGui bool CTextMessageComponent::isNetworkConnected() const { - return this->getIContextNetwork() && this->getIContextNetwork()->isConnected() ; + return sGui->getIContextNetwork() && sGui->getIContextNetwork()->isConnected() ; } void CTextMessageComponent::showCurrentFrequenciesFromCockpit() @@ -248,9 +238,9 @@ namespace BlackGui this->connect(closeButton, &QPushButton::released, this, &CTextMessageComponent::ps_closeTextMessageTab); this->ui->tw_TextMessages->setCurrentIndex(index); - if (this->getIContextNetwork()) + if (sGui->getIContextNetwork()) { - QString realName = this->getIContextNetwork()->getUserForCallsign(CCallsign(tabName)).getRealName(); + QString realName = sGui->getIContextNetwork()->getUserForCallsign(CCallsign(tabName)).getRealName(); if (!realName.isEmpty()) this->ui->tw_TextMessages->setTabToolTip(index, realName); } return newTab; @@ -270,16 +260,16 @@ namespace BlackGui textEdit->insertTextMessage(textMessage); // sound - if (this->getIContextAudio()) + if (sGui->getIContextAudio()) { - this->getIContextAudio()->playNotification(CNotificationSounds::NotificationTextMessagePrivate, true); + sGui->getIContextAudio()->playNotification(CNotificationSounds::NotificationTextMessagePrivate, true); } } const CSimulatedAircraft CTextMessageComponent::getOwnAircraft() const { - Q_ASSERT(this->getIContextOwnAircraft()); - return this->getIContextOwnAircraft()->getOwnAircraft(); + Q_ASSERT(sGui->getIContextOwnAircraft()); + return sGui->getIContextOwnAircraft()->getOwnAircraft(); } QWidget *CTextMessageComponent::findTextMessageTabByCallsign(const CCallsign &callsign, bool callsignResolution) const @@ -289,7 +279,7 @@ namespace BlackGui if (!callsignResolution) { return nullptr; } // resolve callsign - CAtcStation station(getIContextNetwork()->getOnlineStationForCallsign(callsign)); + CAtcStation station(sGui->getIContextNetwork()->getOnlineStationForCallsign(callsign)); if (!station.getCallsign().isEmpty()) { if (this->getOwnAircraft().getCom1System().isActiveFrequencyWithin25kHzChannel(station.getFrequency())) @@ -447,18 +437,15 @@ namespace BlackGui void CTextMessageComponent::showCorrespondingTab(const CCallsign &callsign) { - Q_ASSERT(getIContextOwnAircraft()); - Q_ASSERT(getIContextNetwork()); - if (callsign.isEmpty()) { CLogMessage(this).warning("No callsign to display text message"); return; } QWidget *w = findTextMessageTabByCallsign(callsign, true); - if (!w && getIContextNetwork()) + if (!w && sGui->getIContextNetwork()) { - CSimulatedAircraft aircraft(getIContextNetwork()->getAircraftInRangeForCallsign(callsign)); + CSimulatedAircraft aircraft(sGui->getIContextNetwork()->getAircraftInRangeForCallsign(callsign)); if (!aircraft.getCallsign().isEmpty()) { // we assume a private message diff --git a/src/blackgui/components/textmessagecomponent.h b/src/blackgui/components/textmessagecomponent.h index 7c6661c43..d4f311569 100644 --- a/src/blackgui/components/textmessagecomponent.h +++ b/src/blackgui/components/textmessagecomponent.h @@ -13,7 +13,6 @@ #define BLACKGUI_TEXTMESSAGECOMPONENT_H #include "blackgui/blackguiexport.h" -#include "blackgui/components/enableforruntime.h" #include "blackgui/components/enablefordockwidgetinfoarea.h" #include "blackgui/textmessagetextedit.h" #include "blackmisc/identifier.h" @@ -33,7 +32,6 @@ namespace BlackGui //! Text message widget class BLACKGUI_EXPORT CTextMessageComponent : public QFrame, - public CEnableForRuntime, public CEnableForDockWidgetInfoArea { Q_OBJECT @@ -74,10 +72,6 @@ namespace BlackGui //! Display the tab for given callsign void showCorrespondingTab(const BlackMisc::Aviation::CCallsign &callsign); - protected: - //! \copydoc CEnableForRuntime::runtimeHasBeenSet - void runtimeHasBeenSet() override; - private: QScopedPointer ui; BlackMisc::CIdentifier m_identifier; @@ -93,7 +87,6 @@ namespace BlackGui //! Add new text message tab //! \param tabName name of the new tab, usually the channel name - //! \return QWidget *addNewTextMessageTab(const QString &tabName); //! Find text message tab by callsign diff --git a/src/blackgui/components/usercomponent.cpp b/src/blackgui/components/usercomponent.cpp index 716072caf..bccbdf23f 100644 --- a/src/blackgui/components/usercomponent.cpp +++ b/src/blackgui/components/usercomponent.cpp @@ -9,7 +9,8 @@ #include "usercomponent.h" #include "ui_usercomponent.h" -#include "../guiutility.h" +#include "blackgui/guiutility.h" +#include "blackgui/guiapplication.h" #include "blackmisc/network/userlist.h" #include "blackcore/contextnetwork.h" #include "blackcore/network.h" @@ -25,7 +26,6 @@ namespace BlackGui CUserComponent::CUserComponent(QWidget *parent) : QTabWidget(parent), CEnableForDockWidgetInfoArea(), - CEnableForRuntime(nullptr, false), ui(new Ui::CUserComponent), m_updateTimer(new CUpdateTimer("CUserComponent", &CUserComponent::update, this)) { @@ -33,6 +33,7 @@ namespace BlackGui this->tabBar()->setExpanding(false); connect(this->ui->tvp_AllUsers, &CUserView::rowCountChanged, this, &CUserComponent::ps_onCountChanged); connect(this->ui->tvp_Clients, &CClientView::rowCountChanged, this, &CUserComponent::ps_onCountChanged); + connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CUserComponent::ps_connectionStatusChanged); } CUserComponent::~CUserComponent() @@ -54,9 +55,9 @@ namespace BlackGui { Q_ASSERT(this->ui->tvp_AllUsers); Q_ASSERT(this->ui->tvp_Clients); - Q_ASSERT(this->getIContextNetwork()); + Q_ASSERT(sGui->getIContextNetwork()); - if (this->getIContextNetwork()->isConnected()) + if (sGui->getIContextNetwork()->isConnected()) { bool withData = countUsers() > 0 || countClients() > 0; if (withData && !isVisibleWidget()) @@ -66,17 +67,11 @@ namespace BlackGui } // load data - this->ui->tvp_Clients->updateContainer(this->getIContextNetwork()->getOtherClients()); - this->ui->tvp_AllUsers->updateContainer(this->getIContextNetwork()->getUsers()); + this->ui->tvp_Clients->updateContainer(sGui->getIContextNetwork()->getOtherClients()); + this->ui->tvp_AllUsers->updateContainer(sGui->getIContextNetwork()->getUsers()); } } - void CUserComponent::runtimeHasBeenSet() - { - Q_ASSERT(this->getIContextNetwork()); - this->connect(this->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CUserComponent::ps_connectionStatusChanged); - } - void CUserComponent::ps_onCountChanged(int count, bool withFilter) { Q_UNUSED(count); diff --git a/src/blackgui/components/usercomponent.h b/src/blackgui/components/usercomponent.h index a62e83394..2555f989a 100644 --- a/src/blackgui/components/usercomponent.h +++ b/src/blackgui/components/usercomponent.h @@ -13,7 +13,6 @@ #define BLACKGUI_USERCOMPONENT_H #include "blackgui/blackguiexport.h" -#include "blackgui/components/enableforruntime.h" #include "blackgui/components/enablefordockwidgetinfoarea.h" #include "blackgui/components/updatetimer.h" #include "blackcore/network.h" @@ -30,8 +29,7 @@ namespace BlackGui //! User componenet (users, clients) class BLACKGUI_EXPORT CUserComponent : public QTabWidget, - public CEnableForDockWidgetInfoArea, - public CEnableForRuntime + public CEnableForDockWidgetInfoArea { Q_OBJECT @@ -58,10 +56,6 @@ namespace BlackGui //! \copydoc CUpdateTimer::stopTimer void stopTimer() { Q_ASSERT(this->m_updateTimer); this->m_updateTimer->stopTimer(); } - protected: - //! \copydoc CEnableForRuntime::runtimeHasBeenSet - void runtimeHasBeenSet() override; - private slots: //! Number of elements changed void ps_onCountChanged(int count, bool withFilter); diff --git a/src/blackgui/components/voiceroomscomponent.cpp b/src/blackgui/components/voiceroomscomponent.cpp index ad2364632..a1ec98cef 100644 --- a/src/blackgui/components/voiceroomscomponent.cpp +++ b/src/blackgui/components/voiceroomscomponent.cpp @@ -9,6 +9,7 @@ #include "voiceroomscomponent.h" #include "ui_voiceroomscomponent.h" +#include "blackgui/guiapplication.h" #include "blackcore/contextaudio.h" #include "blackcore/contextownaircraft.h" #include "blackmisc/audio/notificationsounds.h" @@ -20,7 +21,6 @@ namespace BlackGui { namespace Components { - CVoiceRoomsComponent::CVoiceRoomsComponent(QWidget *parent) : QFrame(parent), ui(new Ui::CVoiceRoomsComponent) @@ -31,17 +31,13 @@ namespace BlackGui connect(ui->cb_CockpitVoiceRoom2Override, &QCheckBox::toggled, this, &CVoiceRoomsComponent::ps_onVoiceRoomOverrideChanged); connect(ui->le_CockpitVoiceRoomCom1, &QLineEdit::returnPressed, this, &CVoiceRoomsComponent::ps_onVoiceRoomUrlsReturnPressed); connect(ui->le_CockpitVoiceRoomCom2, &QLineEdit::returnPressed, this, &CVoiceRoomsComponent::ps_onVoiceRoomUrlsReturnPressed); + this->connect(sGui->getIContextAudio(), &IContextAudio::changedVoiceRooms, this, &CVoiceRoomsComponent::ps_updateAudioVoiceRoomsFromContext); + this->connect(sGui->getIContextAudio(), &IContextAudio::changedVoiceRoomMembers, this, &CVoiceRoomsComponent::ps_updateVoiceRoomMembers); } CVoiceRoomsComponent::~CVoiceRoomsComponent() { } - void CVoiceRoomsComponent::runtimeHasBeenSet() - { - this->connect(this->getIContextAudio(), &IContextAudio::changedVoiceRooms, this, &CVoiceRoomsComponent::ps_updateAudioVoiceRoomsFromContext); - this->connect(this->getIContextAudio(), &IContextAudio::changedVoiceRoomMembers, this, &CVoiceRoomsComponent::ps_updateVoiceRoomMembers); - } - void CVoiceRoomsComponent::ps_onVoiceRoomOverrideChanged(bool checked) { Q_UNUSED(checked); @@ -51,12 +47,12 @@ namespace BlackGui void CVoiceRoomsComponent::ps_onVoiceRoomUrlsReturnPressed() { - Q_ASSERT(this->getIContextOwnAircraft()); // voice room resolution is part of own aircraft + Q_ASSERT(sGui->getIContextOwnAircraft()); // voice room resolution is part of own aircraft QString url1; QString url2; if (this->ui->cb_CockpitVoiceRoom1Override->isChecked()) { url1 = this->ui->le_CockpitVoiceRoomCom1->text().trimmed(); } if (this->ui->cb_CockpitVoiceRoom2Override->isChecked()) { url2 = this->ui->le_CockpitVoiceRoomCom2->text().trimmed(); } - this->getIContextOwnAircraft()->setAudioVoiceRoomOverrideUrls(url1, url2); + sGui->getIContextOwnAircraft()->setAudioVoiceRoomOverrideUrls(url1, url2); } void CVoiceRoomsComponent::setVoiceRoomUrlFieldsReadOnlyState() @@ -81,7 +77,7 @@ namespace BlackGui if (room1.isConnected()) { this->ui->le_CockpitVoiceRoomCom1->setStyleSheet("background: green"); - if (this->getIContextAudio()) this->ui->tvp_CockpitVoiceRoom1->updateContainer(this->getIContextAudio()->getRoomUsers(BlackMisc::Aviation::CComSystem::Com1)); + if (sGui->getIContextAudio()) this->ui->tvp_CockpitVoiceRoom1->updateContainer(sGui->getIContextAudio()->getRoomUsers(BlackMisc::Aviation::CComSystem::Com1)); } else { @@ -105,22 +101,22 @@ namespace BlackGui this->ps_updateVoiceRoomMembers(); // notify - if (this->getIContextAudio()) + if (sGui->getIContextAudio()) { CNotificationSounds::Notification sound = connected ? CNotificationSounds::NotificationVoiceRoomJoined : CNotificationSounds::NotificationVoiceRoomLeft; - this->getIContextAudio()->playNotification(sound, true); + sGui->getIContextAudio()->playNotification(sound, true); } } } void CVoiceRoomsComponent::ps_updateVoiceRoomMembers() { - if (!this->getIContextAudio()) { return; } + if (!sGui->getIContextAudio()) { return; } if (!this->ui->le_CockpitVoiceRoomCom1->text().trimmed().isEmpty()) { - this->ui->tvp_CockpitVoiceRoom1->updateContainer(this->getIContextAudio()->getRoomUsers(BlackMisc::Aviation::CComSystem::Com1)); + this->ui->tvp_CockpitVoiceRoom1->updateContainer(sGui->getIContextAudio()->getRoomUsers(BlackMisc::Aviation::CComSystem::Com1)); } else { @@ -129,7 +125,7 @@ namespace BlackGui if (!this->ui->le_CockpitVoiceRoomCom2->text().trimmed().isEmpty()) { - this->ui->tvp_CockpitVoiceRoom2->updateContainer(this->getIContextAudio()->getRoomUsers(BlackMisc::Aviation::CComSystem::Com2)); + this->ui->tvp_CockpitVoiceRoom2->updateContainer(sGui->getIContextAudio()->getRoomUsers(BlackMisc::Aviation::CComSystem::Com2)); } else { diff --git a/src/blackgui/components/voiceroomscomponent.h b/src/blackgui/components/voiceroomscomponent.h index 8f0956eb2..902e09355 100644 --- a/src/blackgui/components/voiceroomscomponent.h +++ b/src/blackgui/components/voiceroomscomponent.h @@ -13,7 +13,6 @@ #define BLACKGUI_VOICEROOMSCOMPONENT_H #include "blackgui/blackguiexport.h" -#include "enableforruntime.h" #include "blackmisc/audio/voiceroomlist.h" #include #include @@ -26,8 +25,7 @@ namespace BlackGui { //! Displays the voice rooms class BLACKGUI_EXPORT CVoiceRoomsComponent : - public QFrame, - public CEnableForRuntime + public QFrame { Q_OBJECT @@ -38,10 +36,6 @@ namespace BlackGui //! Destructor ~CVoiceRoomsComponent(); - protected: - //! \copydoc CEnableForRuntime::runtimeHasBeenSet - virtual void runtimeHasBeenSet() override; - private slots: //! Override for voice was changed void ps_onVoiceRoomOverrideChanged(bool checked); diff --git a/src/plugins/simulator/fs9/fs9host.cpp b/src/plugins/simulator/fs9/fs9host.cpp index e771f2275..3e8cdc754 100644 --- a/src/plugins/simulator/fs9/fs9host.cpp +++ b/src/plugins/simulator/fs9/fs9host.cpp @@ -9,13 +9,13 @@ #define _CRT_SECURE_NO_WARNINGS +#include "blackcore/application.h" +#include "blackmisc/logmessage.h" #include "directplayerror.h" #include "directplayutils.h" #include "fs9host.h" #include "multiplayerpacketparser.h" #include "multiplayerpackets.h" -#include "blackmisc/project.h" -#include "blackmisc/logmessage.h" #include #include @@ -26,9 +26,8 @@ namespace BlackSimPlugin namespace Fs9 { CFs9Host::CFs9Host(QObject *owner) : - CDirectPlayPeer(owner, CProject::swiftVersionString()) - { - } + CDirectPlayPeer(owner, sApp->swiftVersionString()) + {} QString CFs9Host::getHostAddress() { @@ -78,7 +77,7 @@ namespace BlackSimPlugin { initDirectPlay(); createHostAddress(); - startHosting(CProject::swiftVersionString(), m_callsign.toQString()); + startHosting(sApp->swiftVersionString(), m_callsign.toQString()); } void CFs9Host::cleanup() @@ -142,7 +141,7 @@ namespace BlackSimPlugin } else { - BlackMisc::CLogMessage(this).info("Hosting successfully started"); + CLogMessage(this).info("Hosting successfully started"); m_hostStatus = Hosting; } @@ -172,7 +171,7 @@ namespace BlackSimPlugin if (m_hostStatus == Terminated) return hr; - BlackMisc::CLogMessage(this).info("Hosting terminated!"); + CLogMessage(this).info("Hosting terminated!"); if (FAILED(hr = m_directPlayPeer->TerminateSession(nullptr, 0, 0))) { return logDirectPlayError(hr); diff --git a/src/plugins/simulator/fs9/lobbyclient.cpp b/src/plugins/simulator/fs9/lobbyclient.cpp index 3fee3f91c..b178f0401 100644 --- a/src/plugins/simulator/fs9/lobbyclient.cpp +++ b/src/plugins/simulator/fs9/lobbyclient.cpp @@ -6,11 +6,13 @@ * including this file, may be copied, modified, propagated, or distributed except according to the terms * contained in the LICENSE file. */ + #define _CRT_SECURE_NO_WARNINGS +#include "blackcore/actionbind.h" +#include "blackcore/application.h" #include "directplayerror.h" #include "directplayutils.h" -#include "blackmisc/project.h" #include "fs9.h" #include "lobbyclient.h" #include "blackmisc/logmessage.h" @@ -30,6 +32,7 @@ namespace BlackSimPlugin m_callbackWrapper(this, &CLobbyClient::directPlayMessageHandler), m_lobbyCallbackWrapper(this, &CLobbyClient::directPlayLobbyMessageHandler) { + Q_ASSERT_X(sApp, Q_FUNC_INFO, "Missing global object"); initDirectPlay(); } @@ -208,7 +211,7 @@ namespace BlackSimPlugin // Set the device addresses apDevAddress[0] = pDeviceAddress; - QString session = BlackMisc::CProject::swiftVersionString(); + QString session = sApp->swiftVersionString(); QScopedArrayPointer wstrSessionName(new wchar_t[session.size() + 1]); session.toWCharArray(wstrSessionName.data()); wstrSessionName[session.size()] = 0; diff --git a/src/plugins/simulator/fsx/simulatorfsx.cpp b/src/plugins/simulator/fsx/simulatorfsx.cpp index ebd84f706..739242ac3 100644 --- a/src/plugins/simulator/fsx/simulatorfsx.cpp +++ b/src/plugins/simulator/fsx/simulatorfsx.cpp @@ -9,7 +9,7 @@ #include "simulatorfsx.h" #include "blackcore/interpolatorlinear.h" -#include "blackcore/registermetadata.h" +#include "blackcore/application.h" #include "blackmisc/simulation/fscommon/bcdconversions.h" #include "blackmisc/simulation/fsx/simconnectutilities.h" #include "blackmisc/simulation/fsx/fsxsimulatorsetup.h" @@ -47,8 +47,9 @@ namespace BlackSimPlugin QObject *parent) : CSimulatorFsCommon(info, ownAircraftProvider, remoteAircraftProvider, pluginStorageProvider, parent) { - Q_ASSERT(ownAircraftProvider); - Q_ASSERT(remoteAircraftProvider); + Q_ASSERT_X(ownAircraftProvider, Q_FUNC_INFO, "Missing provider"); + Q_ASSERT_X(remoteAircraftProvider, Q_FUNC_INFO, "Missing provider"); + Q_ASSERT_X(sApp, Q_FUNC_INFO, "Missing global object"); this->m_simulatorSetup = CFsxSimulatorSetup::getInitialSetup(); m_useFsuipc = true; // Temporarily enabled until Simconnect Weather is implemented. @@ -80,7 +81,7 @@ namespace BlackSimPlugin bool CSimulatorFsx::connectTo() { if (this->isConnected()) { return true; } - if (FAILED(SimConnect_Open(&m_hSimConnect, BlackMisc::CProject::swiftVersionChar(), nullptr, 0, 0, 0))) + if (FAILED(SimConnect_Open(&m_hSimConnect, sApp->swiftVersionChar(), nullptr, 0, 0, 0))) { // reset state as expected for unconnected if (m_simconnectTimerId >= 0) { killTimer(m_simconnectTimerId); } @@ -858,7 +859,7 @@ namespace BlackSimPlugin { Q_ASSERT_X(!CThreadUtils::isCurrentThreadApplicationThread(), Q_FUNC_INFO, "Expect to run in background"); HANDLE hSimConnect; - HRESULT result = SimConnect_Open(&hSimConnect, BlackMisc::CProject::swiftVersionChar(), nullptr, 0, 0, 0); + HRESULT result = SimConnect_Open(&hSimConnect, sApp->swiftVersionChar(), nullptr, 0, 0, 0); SimConnect_Close(hSimConnect); if (result == S_OK) { diff --git a/src/plugins/simulator/fsx/simulatorfsxsimconnectproc.cpp b/src/plugins/simulator/fsx/simulatorfsxsimconnectproc.cpp index f7a3e91d9..17c1ff2e3 100644 --- a/src/plugins/simulator/fsx/simulatorfsxsimconnectproc.cpp +++ b/src/plugins/simulator/fsx/simulatorfsxsimconnectproc.cpp @@ -8,15 +8,16 @@ */ #include "simulatorfsx.h" +#include "blackcore/application.h" #include "simconnectdatadefinition.h" #include "blackmisc/simulation/fscommon/bcdconversions.h" #include "blackmisc/simulation/fsx/simconnectutilities.h" #include "blackmisc/simulation/fsx/fsxsimulatorsetup.h" #include "blackmisc/simulation/simulatorplugininfo.h" -#include "blackmisc/project.h" #include "blackmisc/aviation/airportlist.h" #include "blackmisc/logmessage.h" +using namespace BlackCore; using namespace BlackMisc; using namespace BlackMisc::Simulation; using namespace BlackMisc::Aviation; @@ -43,7 +44,7 @@ namespace BlackSimPlugin .arg(event->szApplicationName) .arg(event->dwApplicationVersionMajor).arg(event->dwApplicationVersionMinor).arg(event->dwApplicationBuildMajor).arg(event->dwApplicationBuildMinor) .arg(event->dwSimConnectVersionMajor).arg(event->dwSimConnectVersionMinor).arg(event->dwSimConnectBuildMajor).arg(event->dwSimConnectBuildMinor); - CLogMessage(static_cast(nullptr)).info("Connect to FSX: %1") << CProject::swiftVersionString(); + CLogMessage(static_cast(nullptr)).info("Connect to FSX: %1") << sApp->swiftVersionString(); break; } case SIMCONNECT_RECV_ID_EXCEPTION: diff --git a/src/plugins/simulator/fsxconfig/simconnectsettingscomponent.cpp b/src/plugins/simulator/fsxconfig/simconnectsettingscomponent.cpp index 94f39c0e0..777e6dd0c 100644 --- a/src/plugins/simulator/fsxconfig/simconnectsettingscomponent.cpp +++ b/src/plugins/simulator/fsxconfig/simconnectsettingscomponent.cpp @@ -1,5 +1,15 @@ +/* Copyright (C) 2015 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + #include "simconnectsettingscomponent.h" #include "ui_simconnectsettingscomponent.h" +#include "blackgui/guiapplication.h" #include "blackcore/contextapplication.h" #include "blackcore/contextsimulator.h" #include "blackmisc/network/networkutils.h" @@ -20,7 +30,6 @@ namespace BlackSimPlugin { namespace Fsx { - CSimConnectSettingsComponent::CSimConnectSettingsComponent(QWidget *parent) : QFrame(parent), ui(new Ui::CSimConnectSettingsComponent) @@ -36,7 +45,7 @@ namespace BlackSimPlugin CSimConnectSettingsComponent::~CSimConnectSettingsComponent() { - + // void } void CSimConnectSettingsComponent::openSimConnectCfgFile() @@ -49,7 +58,7 @@ namespace BlackSimPlugin void CSimConnectSettingsComponent::deleteSimConnectCfgFile() { QString fileName = CSimConnectUtilities::getLocalSimConnectCfgFilename(); - bool result = getIContextApplication()->removeFile(fileName); + bool result = sGui->getIContextApplication()->removeFile(fileName); if (result) { QMessageBox::information(qApp->activeWindow(), tr("File deleted"), @@ -62,7 +71,7 @@ namespace BlackSimPlugin void CSimConnectSettingsComponent::checkSimConnectCfgFile() { QString fileName = CSimConnectUtilities::getLocalSimConnectCfgFilename(); - if (getIContextApplication()->existsFile(fileName)) + if (sGui->getIContextApplication()->existsFile(fileName)) { ui->le_SettingsFsxExistsSimconncetCfg->setText(fileName); } @@ -134,9 +143,9 @@ namespace BlackSimPlugin int p = port.toInt(); QString fileName; - if (getIContextSimulator()) + if (sGui->getIContextSimulator()) { - fileName = getIContextSimulator()->getSimulatorSetup().getStringValue(CFsxSimulatorSetup::KeyLocalSimConnectCfgFilename()); + fileName = sGui->getIContextSimulator()->getSimulatorSetup().getStringValue(CFsxSimulatorSetup::KeyLocalSimConnectCfgFilename()); } if (fileName.isEmpty()) @@ -151,7 +160,7 @@ namespace BlackSimPlugin return; } - if (getIContextApplication()->writeToFile(fileName, CSimConnectUtilities::simConnectCfg(address, p))) + if (sGui->getIContextApplication()->writeToFile(fileName, CSimConnectUtilities::simConnectCfg(address, p))) { QMessageBox::information(qApp->activeWindow(), tr("File saved"), tr("File %1 saved.").arg(fileName)); @@ -163,6 +172,5 @@ namespace BlackSimPlugin tr("Failed writing %1!").arg(fileName)); } } - - } -} + } // ns +} // ns diff --git a/src/plugins/simulator/fsxconfig/simconnectsettingscomponent.h b/src/plugins/simulator/fsxconfig/simconnectsettingscomponent.h index 8c1ab2545..dcc5dc9ef 100644 --- a/src/plugins/simulator/fsxconfig/simconnectsettingscomponent.h +++ b/src/plugins/simulator/fsxconfig/simconnectsettingscomponent.h @@ -14,11 +14,8 @@ #include #include -#include "blackgui/components/enableforruntime.h" -namespace Ui { -class CSimConnectSettingsComponent; -} +namespace Ui { class CSimConnectSettingsComponent; } namespace BlackSimPlugin { @@ -27,7 +24,7 @@ namespace BlackSimPlugin /** * A component that gathers all SimConnect-related settings. */ - class CSimConnectSettingsComponent : public QFrame, public BlackGui::Components::CEnableForRuntime + class CSimConnectSettingsComponent : public QFrame { Q_OBJECT @@ -56,10 +53,8 @@ namespace BlackSimPlugin private: QScopedPointer ui; - }; - - } -} + } // ns +} // ns #endif // guard diff --git a/src/swiftcore/swiftcore.cpp b/src/swiftcore/swiftcore.cpp index 2d938d458..13153fe22 100644 --- a/src/swiftcore/swiftcore.cpp +++ b/src/swiftcore/swiftcore.cpp @@ -14,8 +14,8 @@ #include "blackmisc/project.h" #include "blackmisc/dbusserver.h" #include "blackgui/guiapplication.h" +#include "blackgui/guiapplication.h" #include "blackgui/components/logcomponent.h" -#include "blackgui/components/enableforruntime.h" #include "blackgui/stylesheetutility.h" #include #include @@ -131,7 +131,6 @@ void CSwiftCore::initLogDisplay() void CSwiftCore::startCore(const QString &dBusAdress) { - if (getRuntime()) { return; } if (dBusAdress.isEmpty()) { return; } ui->pb_StartCore->setEnabled(false); @@ -140,27 +139,17 @@ void CSwiftCore::startCore(const QString &dBusAdress) QCoreApplication::processEvents(QEventLoop::AllEvents, 100); // context - this->createRuntime(sGui->isParserOptionSet("coreaudio") ? - CCoreFacadeConfig::forCoreAllLocalInDBus(dBusAdress) : - CCoreFacadeConfig::forCoreAllLocalInDBusNoAudio(dBusAdress), - this); - CEnableForRuntime::setRuntimeForComponents(this->getRuntime(), this); - connect(ui->le_CommandLineInput, &CCommandInput::commandEntered, getRuntime(), &CCoreFacade::parseCommandLine); + connect(ui->le_CommandLineInput, &CCommandInput::commandEntered, sGui->getCoreFacade(), &CCoreFacade::parseCommandLine); } void CSwiftCore::stopCore() { - if (!getRuntime()) { return; } - ui->pb_StartCore->setEnabled(true); ui->pb_StopCore->setEnabled(false); ui->gb_DBusMode->setDisabled(false); QCoreApplication::processEvents(QEventLoop::AllEvents, 100); - getRuntime()->gracefulShutdown(); - - // Force quit, since we cannot close the runtime - qApp->quit(); + sGui->exit(); } QString CSwiftCore::getDBusAddress() const diff --git a/src/swiftcore/swiftcore.h b/src/swiftcore/swiftcore.h index 9d6d0f75b..87783ddaf 100644 --- a/src/swiftcore/swiftcore.h +++ b/src/swiftcore/swiftcore.h @@ -14,7 +14,6 @@ #include "blackcore/corefacade.h" #include "blackgui/systemtraywindow.h" -#include "blackgui/components/enableforruntime.h" #include "blackmisc/statusmessage.h" #include "blackmisc/identifiable.h" @@ -25,8 +24,7 @@ namespace Ui { class CSwiftCore; } //! swift core control class CSwiftCore : public BlackGui::CSystemTrayWindow, - public BlackMisc::CIdentifiable, - public BlackGui::Components::CEnableForRuntime + public BlackMisc::CIdentifiable { Q_OBJECT diff --git a/src/swiftdata/swiftdata.cpp b/src/swiftdata/swiftdata.cpp index 5e69edcf7..f12ed22a3 100644 --- a/src/swiftdata/swiftdata.cpp +++ b/src/swiftdata/swiftdata.cpp @@ -13,7 +13,6 @@ #include "blackgui/components/datamaininfoareacomponent.h" #include "blackgui/components/datainfoareacomponent.h" #include "blackgui/components/logcomponent.h" -#include "blackgui/components/enableforruntime.h" #include "blackgui/stylesheetutility.h" #include "blackcore/webdataservices.h" #include "blackmisc/network/entityflags.h" diff --git a/src/swiftguistandard/swiftguistd.h b/src/swiftguistandard/swiftguistd.h index aef6737d6..547157162 100644 --- a/src/swiftguistandard/swiftguistd.h +++ b/src/swiftguistandard/swiftguistd.h @@ -19,7 +19,6 @@ #include "blackcore/contextallinterfaces.h" #include "blackcore/actionbind.h" #include "blackcore/data/globalsetup.h" -#include "blackgui/components/enableforruntime.h" #include "blackgui/components/maininfoareacomponent.h" #include "blackgui/components/navigatordialog.h" #include "blackgui/transpondermodeselector.h"