From ea124f5ccd238494027bae297b109cffc2d30bc7 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Wed, 18 Jul 2012 17:55:32 +0300 Subject: [PATCH] Changed MeasureName(N) to work dynamically --- Library/Measure.cpp | 29 +++++++++++++++++------------ Library/Measure.h | 4 ++-- Library/Meter.cpp | 11 +++++------ 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/Library/Measure.cpp b/Library/Measure.cpp index 5eafadd8..9354244e 100644 --- a/Library/Measure.cpp +++ b/Library/Measure.cpp @@ -125,18 +125,7 @@ void CMeasure::ReadOptions(CConfigParser& parser, const WCHAR* section) m_Invert = 0!=parser.ReadInt(section, L"InvertMeasure", 0); - if (!m_Initialized) - { - m_Disabled = 0!=parser.ReadInt(section, L"Disabled", 0); - } - else - { - const std::wstring& result = parser.ReadString(section, L"Disabled", L"0"); - if (parser.GetLastReplaced()) - { - m_Disabled = 0!=parser.ParseInt(result.c_str(), 0); - } - } + m_Disabled = 0!=parser.ReadInt(section, L"Disabled", 0); int updateDivider = parser.ReadInt(section, L"UpdateDivider", 1); if (updateDivider != m_UpdateDivider) @@ -183,6 +172,22 @@ void CMeasure::ReadOptions(CConfigParser& parser, const WCHAR* section) InitializeGroup(group); } +void CMeasure::Disable() +{ + m_Disabled = true; + + // Change the option as well to avoid reset in ReadOptions(). + m_MeterWindow->GetParser().SetValue(m_Name, L"Disabled", L"1"); +} + +void CMeasure::Enable() +{ + m_Disabled = false; + + // Change the option as well to avoid reset in ReadOptions(). + m_MeterWindow->GetParser().SetValue(m_Name, L"Disabled", L"0"); +} + /* ** Substitues text using a straight find and replace method */ diff --git a/Library/Measure.h b/Library/Measure.h index 9f607539..c4e005e5 100644 --- a/Library/Measure.h +++ b/Library/Measure.h @@ -57,8 +57,8 @@ public: const WCHAR* GetName() { return m_Name.c_str(); } const std::wstring& GetOriginalName() { return m_Name; } - void Disable() { m_Disabled = true; } - void Enable() { m_Disabled = false; } + void Disable(); + void Enable(); bool IsDisabled() { return m_Disabled; } bool HasDynamicVariables() { return m_DynamicVariables; } diff --git a/Library/Meter.cpp b/Library/Meter.cpp index 51abb537..ad47ac0a 100644 --- a/Library/Meter.cpp +++ b/Library/Meter.cpp @@ -233,10 +233,7 @@ void CMeter::ReadOptions(CConfigParser& parser, const WCHAR* section) parser.SetStyleTemplate(style); } - if (!m_Initialized) - { - BindMeasures(parser, section); - } + BindMeasures(parser, section); int oldX = m_X; std::wstring& x = (std::wstring&)parser.ReadString(section, L"X", L"0"); @@ -437,14 +434,16 @@ bool CMeter::Update() } /* -** Reads and binds the primary MeasureName. +** Reads and binds the primary MeasureName. This must always be called in overridden +** BindMeasures() implementations. ** */ bool CMeter::BindPrimaryMeasure(CConfigParser& parser, const WCHAR* section, bool optional) { + m_Measures.clear(); + const std::wstring& measureName = parser.ReadString(section, L"MeasureName", L""); - // The meter is not bound to anything CMeasure* measure = parser.GetMeasure(measureName); if (measure) {