From 9982f9cfb93877d4d4fb6d72ab6b845cbdbf5844 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 29 Jul 2019 16:54:44 +0200 Subject: [PATCH] Ref T709, update function where only changed members are changed --- .../simulation/settings/xswiftbussettings.cpp | 2 +- .../simulation/settings/xswiftbussettings.h | 4 +-- .../settings/xswiftbussettingsqtfree.cpp | 28 +++++++++++++++++-- .../settings/xswiftbussettingsqtfree.h | 7 +++-- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/blackmisc/simulation/settings/xswiftbussettings.cpp b/src/blackmisc/simulation/settings/xswiftbussettings.cpp index 40af310bd..dd550e75d 100644 --- a/src/blackmisc/simulation/settings/xswiftbussettings.cpp +++ b/src/blackmisc/simulation/settings/xswiftbussettings.cpp @@ -86,7 +86,7 @@ namespace BlackMisc return s; } - void CXSwiftBusSettings::jsonParsed() + void CXSwiftBusSettings::objectUpdated() { m_timestampMSecsSinceEpoch = m_msSinceEpochQtFree; } diff --git a/src/blackmisc/simulation/settings/xswiftbussettings.h b/src/blackmisc/simulation/settings/xswiftbussettings.h index 2f55f37fe..11733df03 100644 --- a/src/blackmisc/simulation/settings/xswiftbussettings.h +++ b/src/blackmisc/simulation/settings/xswiftbussettings.h @@ -80,8 +80,8 @@ namespace BlackMisc static const CXSwiftBusSettings &defaultValue(); protected: - //! \copydoc CXSwiftBusSettingsQtFree::jsonParsed - virtual void jsonParsed() override; + //! \copydoc CXSwiftBusSettingsQtFree::objectUpdated + virtual void objectUpdated() override; private: BLACK_METACLASS( diff --git a/src/blackmisc/simulation/settings/xswiftbussettingsqtfree.cpp b/src/blackmisc/simulation/settings/xswiftbussettingsqtfree.cpp index fc22dcf46..72d67223d 100644 --- a/src/blackmisc/simulation/settings/xswiftbussettingsqtfree.cpp +++ b/src/blackmisc/simulation/settings/xswiftbussettingsqtfree.cpp @@ -12,7 +12,9 @@ #include "rapidjson/document.h" // rapidjson's DOM-style API #include "rapidjson/prettywriter.h" // for stringify JSON +#include #include +#include #include using namespace BlackMisc::Simulation::Settings; @@ -35,6 +37,14 @@ namespace BlackMisc { namespace Settings { + // Qt free version + bool isFuzzyEqual(double v1, double v2) + { + // we can be a little fuzzy here + static const double Epsilon = 5 * std::numeric_limits::min(); + return (fabs(v1 - v2) < Epsilon); + } + CXSwiftBusSettingsQtFree::CXSwiftBusSettingsQtFree() {} @@ -72,7 +82,7 @@ namespace BlackMisc { m_msSinceEpochQtFree = settingsDoc[CXSwiftBusSettingsQtFree::JsonTimestamp].GetInt64(); c++; } - this->jsonParsed(); // post processing + this->objectUpdated(); // post processing return c == 6; } @@ -115,6 +125,20 @@ namespace BlackMisc ", ts: " + std::to_string(m_msSinceEpochQtFree); } + int CXSwiftBusSettingsQtFree::update(const CXSwiftBusSettingsQtFree &newValues) + { + int changed = 0; + if (m_dBusServerAddress != newValues.m_dBusServerAddress) { m_dBusServerAddress = newValues.m_dBusServerAddress; changed++; } + if (m_drawingLabels != newValues.m_drawingLabels) { m_drawingLabels = newValues.m_drawingLabels; changed++; } + if (m_maxPlanes != newValues.m_maxPlanes) { m_maxPlanes = newValues.m_maxPlanes; changed++; } + if (m_msSinceEpochQtFree != newValues.m_msSinceEpochQtFree) { m_msSinceEpochQtFree = newValues.m_msSinceEpochQtFree; changed++; } + if (m_followAircraftDistanceM != newValues.m_followAircraftDistanceM) { m_followAircraftDistanceM = newValues.m_followAircraftDistanceM; changed++; } + if (!isFuzzyEqual(m_maxDrawDistanceNM, newValues.m_maxDrawDistanceNM)) { m_maxDrawDistanceNM = newValues.m_maxDrawDistanceNM; changed++; } + + if (changed > 0) { this->objectUpdated(); } // post processing + return changed; + } + void CXSwiftBusSettingsQtFree::setCurrentUtcTime() { using namespace std::chrono; @@ -122,7 +146,7 @@ namespace BlackMisc m_msSinceEpochQtFree = static_cast(ms.count()); } - void CXSwiftBusSettingsQtFree::jsonParsed() + void CXSwiftBusSettingsQtFree::objectUpdated() { // void } diff --git a/src/blackmisc/simulation/settings/xswiftbussettingsqtfree.h b/src/blackmisc/simulation/settings/xswiftbussettingsqtfree.h index 6f2926502..1e6f9a4cb 100644 --- a/src/blackmisc/simulation/settings/xswiftbussettingsqtfree.h +++ b/src/blackmisc/simulation/settings/xswiftbussettingsqtfree.h @@ -69,6 +69,9 @@ namespace BlackMisc //! Convert to string std::string convertToString() const; + //! Update only changed values + int update(const CXSwiftBusSettingsQtFree &newValues); + //! Sets timestamp to now virtual void setCurrentUtcTime(); @@ -82,8 +85,8 @@ namespace BlackMisc static constexpr char JsonFollowAircraftDistanceM[] = "followAircraftDistance"; //! @} - //! Pasing completed - virtual void jsonParsed(); + //! Object has been updated + virtual void objectUpdated(); std::string m_dBusServerAddress { "tcp:host=127.0.0.1,port=45001" }; //!< DBus server int m_maxPlanes = 100; //!< max. planes in XPlane