From 44b2e27d11a90fa38cabcae02f0d4fe345433b53 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Fri, 9 Feb 2018 04:25:23 +0100 Subject: [PATCH] Ref T246, use different caches to remember single/multi simulator selections * selector UI "can remember" * different caches --- .../components/copyconfigurationcomponent.h | 2 +- .../distributorpreferencescomponent.cpp | 1 + .../settingssimulatorbasicscomponent.cpp | 1 + src/blackgui/components/simulatorselector.cpp | 28 +++++++++++++++++-- src/blackgui/components/simulatorselector.h | 14 ++++++++-- src/blackmisc/simulation/data/modelcaches.h | 19 +++++++++++-- 6 files changed, 57 insertions(+), 8 deletions(-) diff --git a/src/blackgui/components/copyconfigurationcomponent.h b/src/blackgui/components/copyconfigurationcomponent.h index dd7f7efc1..dfdf00b49 100644 --- a/src/blackgui/components/copyconfigurationcomponent.h +++ b/src/blackgui/components/copyconfigurationcomponent.h @@ -135,7 +135,7 @@ namespace BlackGui // those caches do not harm if they exists default initialized //! \fixme this is a workaround, as it creates files on disk even if those are not copied. It was much nicer if the cache would init themself if the file appears BlackMisc::CData m_lastServer { this }; //!< recently used server (VATSIM, other) - BlackMisc::CData m_modelSetCurrentSimulator { this }; + BlackMisc::CData m_modelSetCurrentSimulator { this }; BlackMisc::CData m_modelsCurrentSimulator { this }; BlackMisc::CData m_lastAircraftModel { this }; //!< recently used aircraft model BlackMisc::CData m_launcherSetup { this }; diff --git a/src/blackgui/components/distributorpreferencescomponent.cpp b/src/blackgui/components/distributorpreferencescomponent.cpp index 32c811b43..a766f4d51 100644 --- a/src/blackgui/components/distributorpreferencescomponent.cpp +++ b/src/blackgui/components/distributorpreferencescomponent.cpp @@ -48,6 +48,7 @@ namespace BlackGui ui->setupUi(this); ui->comp_SimulatorSelector->setMode(CSimulatorSelector::RadioButtons); + ui->comp_SimulatorSelector->setRememberSelection(true); ui->comp_SimulatorSelector->setValue(simulator); connect(ui->pb_All, &QPushButton::pressed, this, &CDistributorPreferencesComponent::ps_loadAll); diff --git a/src/blackgui/components/settingssimulatorbasicscomponent.cpp b/src/blackgui/components/settingssimulatorbasicscomponent.cpp index a62e7c10e..4cf740ece 100644 --- a/src/blackgui/components/settingssimulatorbasicscomponent.cpp +++ b/src/blackgui/components/settingssimulatorbasicscomponent.cpp @@ -38,6 +38,7 @@ namespace BlackGui ui->setupUi(this); this->setSmallLayout(true); // no disadvantage, so I always set it ui->comp_SimulatorSelector->setMode(CSimulatorSelector::RadioButtons); + ui->comp_SimulatorSelector->setRememberSelection(true); ui->comp_SimulatorSelector->setToLastSelection(); connect(ui->pb_ExcludeFileDialog, &QPushButton::clicked, this, &CSettingsSimulatorBasicsComponent::excludeFileDialog); connect(ui->pb_ModelFileDialog, &QPushButton::clicked, this, &CSettingsSimulatorBasicsComponent::modelFileDialog); diff --git a/src/blackgui/components/simulatorselector.cpp b/src/blackgui/components/simulatorselector.cpp index a5443d3eb..18237f68d 100644 --- a/src/blackgui/components/simulatorselector.cpp +++ b/src/blackgui/components/simulatorselector.cpp @@ -58,6 +58,7 @@ namespace BlackGui ui->wi_RadioButtons->setVisible(true); break; } + this->setToLastSelection(); } CSimulatorInfo CSimulatorSelector::getValue() const @@ -99,8 +100,10 @@ namespace BlackGui void CSimulatorSelector::setToLastSelection() { - const CSimulatorInfo sim = m_currentSimulator.get(); - this->setValue(sim); + const CSimulatorInfo simulator = (m_mode == RadioButtons) ? + m_currentSimulator.get() : + m_currentSimulators.get(); + this->setValue(simulator); } void CSimulatorSelector::setAll() @@ -166,6 +169,7 @@ 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()); } @@ -173,7 +177,27 @@ namespace BlackGui { if (m_mode != CheckBoxes) { return; } Q_UNUSED(checked); + this->rememberSelection(); emit this->changed(this->getValue()); } + + void CSimulatorSelector::rememberSelection() + { + if (!m_rememberSelection) { return; } + if (m_mode == RadioButtons) + { + m_currentSimulator.set(this->getValue()); + } + else + { + m_currentSimulators.set(this->getValue()); + } + } + + void CSimulatorSelector::changedLastSelection() + { + // forece decoupled update + QTimer::singleShot(100, this, &CSimulatorSelector::setToLastSelection); + } } // ns } // ns diff --git a/src/blackgui/components/simulatorselector.h b/src/blackgui/components/simulatorselector.h index cfd8b00f0..d5c74aaf8 100644 --- a/src/blackgui/components/simulatorselector.h +++ b/src/blackgui/components/simulatorselector.h @@ -75,6 +75,9 @@ namespace BlackGui //! Set left margin void setLeftMargin(int margin); + //! Remember selection + void setRememberSelection(bool remember) { m_rememberSelection = remember; } + signals: //! Value has been changed void changed(const BlackMisc::Simulation::CSimulatorInfo &simulator); @@ -86,11 +89,18 @@ namespace BlackGui //! Checkbox changed void checkBoxChanged(bool checked); - private: + //! Remember last selection + void rememberSelection(); + + //! Last selection has been changed + void changedLastSelection(); + QScopedPointer ui; Mode m_mode = CheckBoxes; bool m_noSelectionMeansAll = false; //!< for filters, no selection means all - BlackMisc::CDataReadOnly m_currentSimulator { this }; //!< current simulator + bool m_rememberSelection = false; //!< remember last selection + BlackMisc::CData m_currentSimulator { this, &CSimulatorSelector::changedLastSelection }; //!< current simulator (used with radio buttons) + BlackMisc::CData m_currentSimulators { this, &CSimulatorSelector::changedLastSelection }; //!< current simulators (used with multiple checkboxes) }; } // ns } // ns diff --git a/src/blackmisc/simulation/data/modelcaches.h b/src/blackmisc/simulation/data/modelcaches.h index dd089abe7..f4be6e084 100644 --- a/src/blackmisc/simulation/data/modelcaches.h +++ b/src/blackmisc/simulation/data/modelcaches.h @@ -112,7 +112,7 @@ namespace BlackMisc }; //! Last selection - struct TModelSetLastSelection : public BlackMisc::TDataTrait + struct TSimulatorLastSelection : public BlackMisc::TDataTrait { //! First load is synchronous static constexpr bool isPinned() { return true; } @@ -121,7 +121,20 @@ namespace BlackMisc static const BlackMisc::Simulation::CSimulatorInfo &defaultValue() { return CSimulatorInfo::guessDefaultSimulator(); } //! Key - static const char *key() { return "modelsetlastselection"; } + static const char *key() { return "simulatorlastselection"; } + }; + + //! Last selections + struct TSimulatorLastSelections : public BlackMisc::TDataTrait + { + //! First load is synchronous + static constexpr bool isPinned() { return true; } + + //! Default simulator + static const BlackMisc::Simulation::CSimulatorInfo &defaultValue() { return CSimulatorInfo::guessDefaultSimulator(); } + + //! Key + static const char *key() { return "simulatorlastselections"; } }; //! @} @@ -319,7 +332,7 @@ namespace BlackMisc BlackMisc::CData m_modelCacheFs9 {this, &CModelSetCaches::changedFs9}; //!< FS9 cache BlackMisc::CData m_modelCacheP3D {this, &CModelSetCaches::changedP3D }; //!< P3D cache BlackMisc::CData m_modelCacheXP {this, &CModelSetCaches::changedXP }; //!< XP cache - BlackMisc::CData m_currentSimulator { this }; //!< current simulator + BlackMisc::CData m_currentSimulator { this }; //!< current simulator //! Non virtual version (can be used in ctor) void synchronizeCacheImpl(const BlackMisc::Simulation::CSimulatorInfo &simulator);