Ref T709, update function where only changed members are changed

This commit is contained in:
Klaus Basan
2019-07-29 16:54:44 +02:00
committed by Mat Sutcliffe
parent 15c8207dee
commit 3eb53aec82
4 changed files with 34 additions and 7 deletions

View File

@@ -86,7 +86,7 @@ namespace BlackMisc
return s; return s;
} }
void CXSwiftBusSettings::jsonParsed() void CXSwiftBusSettings::objectUpdated()
{ {
m_timestampMSecsSinceEpoch = m_msSinceEpochQtFree; m_timestampMSecsSinceEpoch = m_msSinceEpochQtFree;
} }

View File

@@ -80,8 +80,8 @@ namespace BlackMisc
static const CXSwiftBusSettings &defaultValue(); static const CXSwiftBusSettings &defaultValue();
protected: protected:
//! \copydoc CXSwiftBusSettingsQtFree::jsonParsed //! \copydoc CXSwiftBusSettingsQtFree::objectUpdated
virtual void jsonParsed() override; virtual void objectUpdated() override;
private: private:
BLACK_METACLASS( BLACK_METACLASS(

View File

@@ -12,7 +12,9 @@
#include "rapidjson/document.h" // rapidjson's DOM-style API #include "rapidjson/document.h" // rapidjson's DOM-style API
#include "rapidjson/prettywriter.h" // for stringify JSON #include "rapidjson/prettywriter.h" // for stringify JSON
#include <climits>
#include <string> #include <string>
#include <cmath>
#include <chrono> #include <chrono>
using namespace BlackMisc::Simulation::Settings; using namespace BlackMisc::Simulation::Settings;
@@ -35,6 +37,14 @@ namespace BlackMisc
{ {
namespace Settings 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<double>::min();
return (fabs(v1 - v2) < Epsilon);
}
CXSwiftBusSettingsQtFree::CXSwiftBusSettingsQtFree() CXSwiftBusSettingsQtFree::CXSwiftBusSettingsQtFree()
{} {}
@@ -72,7 +82,7 @@ namespace BlackMisc
{ {
m_msSinceEpochQtFree = settingsDoc[CXSwiftBusSettingsQtFree::JsonTimestamp].GetInt64(); c++; m_msSinceEpochQtFree = settingsDoc[CXSwiftBusSettingsQtFree::JsonTimestamp].GetInt64(); c++;
} }
this->jsonParsed(); // post processing this->objectUpdated(); // post processing
return c == 6; return c == 6;
} }
@@ -115,6 +125,20 @@ namespace BlackMisc
", ts: " + std::to_string(m_msSinceEpochQtFree); ", 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() void CXSwiftBusSettingsQtFree::setCurrentUtcTime()
{ {
using namespace std::chrono; using namespace std::chrono;
@@ -122,7 +146,7 @@ namespace BlackMisc
m_msSinceEpochQtFree = static_cast<int64_t>(ms.count()); m_msSinceEpochQtFree = static_cast<int64_t>(ms.count());
} }
void CXSwiftBusSettingsQtFree::jsonParsed() void CXSwiftBusSettingsQtFree::objectUpdated()
{ {
// void // void
} }

View File

@@ -69,6 +69,9 @@ namespace BlackMisc
//! Convert to string //! Convert to string
std::string convertToString() const; std::string convertToString() const;
//! Update only changed values
int update(const CXSwiftBusSettingsQtFree &newValues);
//! Sets timestamp to now //! Sets timestamp to now
virtual void setCurrentUtcTime(); virtual void setCurrentUtcTime();
@@ -82,8 +85,8 @@ namespace BlackMisc
static constexpr char JsonFollowAircraftDistanceM[] = "followAircraftDistance"; static constexpr char JsonFollowAircraftDistanceM[] = "followAircraftDistance";
//! @} //! @}
//! Pasing completed //! Object has been updated
virtual void jsonParsed(); virtual void objectUpdated();
std::string m_dBusServerAddress { "tcp:host=127.0.0.1,port=45001" }; //!< DBus server std::string m_dBusServerAddress { "tcp:host=127.0.0.1,port=45001" }; //!< DBus server
int m_maxPlanes = 100; //!< max. planes in XPlane int m_maxPlanes = 100; //!< max. planes in XPlane