From 7a58cc2222a1f9bc1856651f7bc165daa392d73a Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 26 Jul 2018 21:40:30 +0200 Subject: [PATCH] Ref T292, Ref T285 moved setToConnectedSimulator into simulator selector so it can be used elsewhere --- src/blackgui/components/mappingcomponent.cpp | 40 ++---------- src/blackgui/components/mappingcomponent.h | 4 -- src/blackgui/components/simulatorselector.cpp | 61 +++++++++++++++++-- src/blackgui/components/simulatorselector.h | 11 ++++ 4 files changed, 72 insertions(+), 44 deletions(-) diff --git a/src/blackgui/components/mappingcomponent.cpp b/src/blackgui/components/mappingcomponent.cpp index 5babbaa2b..e103a6654 100644 --- a/src/blackgui/components/mappingcomponent.cpp +++ b/src/blackgui/components/mappingcomponent.cpp @@ -120,13 +120,14 @@ namespace BlackGui // Updates connect(&m_updateTimer, &QTimer::timeout, this, &CMappingComponent::timerUpdate); + m_updateTimer.setObjectName(this->objectName() + "::updateTimer"); ui->tvp_AircraftModels->setDisplayAutomatically(false); this->settingsChanged(); // selector ui->comp_SimulatorSelector->setRememberSelection(false); // pilot client UI ui->comp_SimulatorSelector->setMode(CSimulatorSelector::RadioButtons); - this->setSimulatorSelector(); + ui->comp_SimulatorSelector->setToConnectedSimulator(); connect(ui->comp_SimulatorSelector, &CSimulatorSelector::changed, this, &CMappingComponent::onModelSetSimulatorChanged); // connect @@ -146,7 +147,7 @@ namespace BlackGui connect(ui->tw_SpecializedViews, &QTabWidget::currentChanged, this, &CMappingComponent::onTabWidgetChanged); // requires simulator context - connect(ui->tvp_RenderedAircraft, &CAircraftModelView::objectChanged, this, &CMappingComponent::onChangedSimulatedAircraftInView); + connect(ui->tvp_RenderedAircraft, &CAircraftModelView::objectChanged, this, &CMappingComponent::onChangedSimulatedAircraftInView, Qt::QueuedConnection); // with external core models might be already available // nevertheless, wait some time to allow to init @@ -279,35 +280,9 @@ namespace BlackGui return callsign; } - void CMappingComponent::setSimulatorSelector() - { - if (sGui && sGui->supportsContexts() && sGui->getIContextSimulator()) - { - const CSimulatorPluginInfo pluginInfo = sGui->getIContextSimulator()->getSimulatorPluginInfo(); - if (pluginInfo.isValid()) - { - ui->comp_SimulatorSelector->setReadOnly(true); - ui->comp_SimulatorSelector->setValue(pluginInfo.getSimulator()); - } - else - { - ui->comp_SimulatorSelector->setReadOnly(false); - const CSimulatorInfo simulator = sGui->getIContextSimulator()->getModelSetLoaderSimulator(); - if (simulator.isSingleSimulator()) - { - ui->comp_SimulatorSelector->setValue(simulator); - } - } - } - else - { - ui->comp_SimulatorSelector->setReadOnly(false); - } - } - void CMappingComponent::onModelSetSimulatorChanged(const CSimulatorInfo &simulator) { - if (this->isSimulatorAvailable()) { return; } + if (!sGui || this->isSimulatorAvailable()) { return; } sGui->getIContextSimulator()->setModelSetLoaderSimulator(simulator); // completer will be changed in onModelSetChanged @@ -316,12 +291,7 @@ namespace BlackGui void CMappingComponent::onSimulatorPluginChanged(const CSimulatorPluginInfo &pluginInfo) { Q_UNUSED(pluginInfo); - QPointer myself(this); - QTimer::singleShot(25, this, [ = ] - { - if (myself.isNull()) { return; } - myself->setSimulatorSelector(); - }); + ui->comp_SimulatorSelector->setToConnectedSimulator(50); } void CMappingComponent::onSaveAircraft() diff --git a/src/blackgui/components/mappingcomponent.h b/src/blackgui/components/mappingcomponent.h index 010a62fa7..116461916 100644 --- a/src/blackgui/components/mappingcomponent.h +++ b/src/blackgui/components/mappingcomponent.h @@ -33,7 +33,6 @@ class QCompleter; class QModelIndex; -class QWidget; namespace BlackMisc { @@ -174,9 +173,6 @@ namespace BlackGui //! Check callsign entered BlackMisc::Aviation::CCallsign validateRenderedCallsign(); - //! Set the status of the simulator - void setSimulatorSelector(); - //! Changed selector void onModelSetSimulatorChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator); diff --git a/src/blackgui/components/simulatorselector.cpp b/src/blackgui/components/simulatorselector.cpp index 78b2bdf54..040e50721 100644 --- a/src/blackgui/components/simulatorselector.cpp +++ b/src/blackgui/components/simulatorselector.cpp @@ -8,8 +8,10 @@ */ #include "blackgui/components/simulatorselector.h" +#include "blackgui/guiapplication.h" #include "blackgui/guiutility.h" #include "blackmisc/compare.h" +#include "blackcore/context/contextsimulator.h" #include "ui_simulatorselector.h" #include @@ -19,6 +21,7 @@ #include using namespace BlackMisc::Simulation; +using namespace BlackCore::Context; namespace BlackGui { @@ -84,7 +87,7 @@ namespace BlackGui void CSimulatorSelector::setValue(const CSimulatorInfo &simulator) { - const CSimulatorInfo current(getValue()); + const CSimulatorInfo current(this->getValue()); if (simulator == current) { return; } // avoid unnecessary signals // checkboxes @@ -108,6 +111,49 @@ namespace BlackGui this->setValue(simulator); } + void CSimulatorSelector::setToConnectedSimulator(bool makeReadOnly) + { + if (sGui && sGui->supportsContexts() && sGui->getIContextSimulator()) + { + const CSimulatorPluginInfo pluginInfo = sGui->getIContextSimulator()->getSimulatorPluginInfo(); + if (pluginInfo.isValid()) + { + this->setMode(RadioButtons); + this->setReadOnly(makeReadOnly); + this->setValue(pluginInfo.getSimulator()); + } + else + { + if (makeReadOnly) { this->setReadOnly(false); } + const CSimulatorInfo simulator = sGui->getIContextSimulator()->getModelSetLoaderSimulator(); + if (simulator.isSingleSimulator()) + { + this->setValue(simulator); + } + } + } + else + { + if (makeReadOnly) { this->setReadOnly(false); } + } + } + + void CSimulatorSelector::setToConnectedSimulator(int deferredMs, bool makeReadOnly) + { + if (deferredMs < 1) + { + this->setToConnectedSimulator(makeReadOnly); + return; + } + + QPointer myself(this); + QTimer::singleShot(deferredMs, this, [ = ] + { + if (!sGui || sGui->isShuttingDown() || !myself) { return; } + this->setToConnectedSimulator(makeReadOnly); + }); + } + void CSimulatorSelector::checkAll() { // checkboxes @@ -204,16 +250,14 @@ namespace BlackGui { if (m_mode != RadioButtons) { return; } if (!checked) { return; } // only the checked ones are relevant, as the unchecked ones are accompanied with checked events - this->rememberSelection(); - emit this->changed(this->getValue()); + m_digestButtonsChanged.inputSignal(); } void CSimulatorSelector::checkBoxChanged(bool checked) { if (m_mode != CheckBoxes) { return; } Q_UNUSED(checked); - this->rememberSelection(); - emit this->changed(this->getValue()); + m_digestButtonsChanged.inputSignal(); } void CSimulatorSelector::rememberSelection() @@ -258,5 +302,12 @@ namespace BlackGui this->setToLastSelection(); }); } + + void CSimulatorSelector::emitChangedSignal() + { + const CSimulatorInfo simulator(this->getValue()); + this->rememberSelection(); + emit this->changed(simulator); + } } // ns } // ns diff --git a/src/blackgui/components/simulatorselector.h b/src/blackgui/components/simulatorselector.h index 3e7106c18..80fc84cb6 100644 --- a/src/blackgui/components/simulatorselector.h +++ b/src/blackgui/components/simulatorselector.h @@ -15,6 +15,7 @@ #include "blackgui/blackguiexport.h" #include "blackmisc/simulation/simulatorinfo.h" #include "blackmisc/simulation/data/modelcaches.h" +#include "blackmisc/digestsignal.h" #include #include @@ -63,6 +64,12 @@ namespace BlackGui //! Set to last selection void setToLastSelection(); + //! Set to the connected simulator + void setToConnectedSimulator(bool makeReadOnly = true); + + //! Set to the connected simulator but deferred + void setToConnectedSimulator(int deferredMs, bool makeReadOnly = true); + //! Set all, only making sense with checkboxes void checkAll(); @@ -119,10 +126,14 @@ namespace BlackGui //! Trigger CSimulatorSelector::setToLastSelection void triggerSetToLastSelection(); + //! Emit the CSimulatorSelector::changed signal + void emitChangedSignal(); + QScopedPointer ui; Mode m_mode = CheckBoxes; bool m_noSelectionMeansAll = false; //!< for filters, no selection means all bool m_rememberSelection = false; //!< remember last selection + BlackMisc::CDigestSignal m_digestButtonsChanged { this, &CSimulatorSelector::emitChangedSignal, 250, 3 }; BlackMisc::CData m_currentSimulator { this, &CSimulatorSelector::changedLastSelectionRb }; //!< current simulator (used with radio buttons) BlackMisc::CData m_currentSimulators { this, &CSimulatorSelector::changedLastSelectionCb }; //!< current simulators (used with multiple checkboxes) };