From 6e880b950c6bfbe167335fdf1cd100a308960b85 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 9 Jul 2018 22:21:42 +0200 Subject: [PATCH] Ref T268, interpolation setup provider (no QObject) can "emit signal" by using a virtual function --- .../simulation/interpolationsetupprovider.cpp | 44 +++++++++++++++---- .../simulation/interpolationsetupprovider.h | 12 ++++- 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/blackmisc/simulation/interpolationsetupprovider.cpp b/src/blackmisc/simulation/interpolationsetupprovider.cpp index fb88f9923..017f8e6d3 100644 --- a/src/blackmisc/simulation/interpolationsetupprovider.cpp +++ b/src/blackmisc/simulation/interpolationsetupprovider.cpp @@ -84,12 +84,11 @@ namespace BlackMisc bool IInterpolationSetupProvider::setInterpolationSetupGlobal(const CInterpolationAndRenderingSetupGlobal &setup) { { - QReadLocker l(&m_lockSetup); + QWriteLocker l(&m_lockSetup); if (m_globalSetup == setup) { return false; } + m_globalSetup = setup; } - - QWriteLocker l(&m_lockSetup); - m_globalSetup = setup; + this->emitInterpolationSetupChanged(); return true; } @@ -105,11 +104,25 @@ namespace BlackMisc return false; } } - QWriteLocker l(&m_lockSetup); - m_setups[callsign] = setup; + { + QWriteLocker l(&m_lockSetup); + m_setups[callsign] = setup; + } + this->emitInterpolationSetupChanged(); return true; } + bool IInterpolationSetupProvider::removeInterpolationSetupPerCallsign(const CCallsign &callsign) + { + bool removed = false; + { + QWriteLocker l(&m_lockSetup); + removed = m_setups.remove(callsign) > 0; + } + if (removed) { this->emitInterpolationSetupChanged(); } + return removed; + } + void IInterpolationSetupProvider::setLogCallsign(bool log, const CCallsign &callsign) { CInterpolationAndRenderingSetupPerCallsign setup = this->getInterpolationSetupPerCallsignOrDefault(callsign); @@ -134,9 +147,24 @@ namespace BlackMisc if (setup.isEqualToGlobal(global)) { continue; } setupsToKeep.insert(cs, setup); } + { + QWriteLocker l(&m_lockSetup); + m_setups = setupsToKeep; + } + this->emitInterpolationSetupChanged(); + } - QWriteLocker l(&m_lockSetup); - m_setups = setupsToKeep; + int IInterpolationSetupProvider::clearInterpolationSetupsPerCallsign() + { + int r = 0; + { + QWriteLocker l(&m_lockSetup); + r = m_setups.size(); + m_setups.clear(); + } + + if (r > 0) { this->emitInterpolationSetupChanged(); } + return r; } bool IInterpolationSetupProvider::logAnyCallsign() const diff --git a/src/blackmisc/simulation/interpolationsetupprovider.h b/src/blackmisc/simulation/interpolationsetupprovider.h index f9e6d5bec..542e6f6a3 100644 --- a/src/blackmisc/simulation/interpolationsetupprovider.h +++ b/src/blackmisc/simulation/interpolationsetupprovider.h @@ -63,7 +63,7 @@ namespace BlackMisc //! \threadsafe virtual bool setInterpolationSetupGlobal(const CInterpolationAndRenderingSetupGlobal &setup); - //! Insert specialized setup + //! Insert specialized setup per callsign //! \threadsafe virtual bool setInterpolationSetupPerCallsign(const CInterpolationAndRenderingSetupPerCallsign &setup, const Aviation::CCallsign &callsign, bool removeGlobalSetup = true); @@ -71,10 +71,17 @@ namespace BlackMisc //! \threadsafe void setLogCallsign(bool log, const Aviation::CCallsign &callsign); + //! Remove specialized setup per callsign + bool removeInterpolationSetupPerCallsign(const Aviation::CCallsign &callsign); + //! Clear all interpolation log callsigns //! \threadsafe void clearInterpolationLogCallsigns(); + //! Clear all setups + //! \threadsafe + int clearInterpolationSetupsPerCallsign(); + //! Log any callsign? //! \threadsafe bool logAnyCallsign() const; @@ -83,6 +90,9 @@ namespace BlackMisc //! \threadsafe SetupsPerCallsign getSetupsPerCallsign() const; + //! Pseudo signal, override to emit signal + virtual void emitInterpolationSetupChanged() {} + private: CInterpolationAndRenderingSetupGlobal m_globalSetup; SetupsPerCallsign m_setups;