From 76c5d4de56ccbec67c7baebc46af58750312c340 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Sat, 9 Jul 2011 22:45:53 +0200 Subject: Add a "modified" signal to resources This way, an object can be informed when a resource changes (e.g. by a lua function). --- src/FbTk/Resource.hh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/FbTk/Resource.hh b/src/FbTk/Resource.hh index 518d0aa..32d24b6 100644 --- a/src/FbTk/Resource.hh +++ b/src/FbTk/Resource.hh @@ -28,10 +28,11 @@ #include #include #include - #include #include + #include "ResTraits.hh" +#include "Signal.hh" #include "XrmDatabaseHelper.hh" namespace FbTk { @@ -206,11 +207,15 @@ public: m_rm.removeResource(*this); // remove this from resource handler } - void setDefaultValue() { m_value = m_defaultval; } + void setDefaultValue() { + m_value = m_defaultval; + m_modified_sig.emit(m_value); + } /// sets resource from string, specialized, must be implemented void setFromString(const char *strval) { try { m_value = Traits::fromString(strval); + m_modified_sig.emit(m_value); } catch(ConversionError &e) { std::cerr << name() << ": " << e.what() << std::endl; @@ -225,6 +230,7 @@ public: virtual void setFromLua(lua::state &l) { try { m_value = Traits::fromLua(l); + m_modified_sig.emit(m_value); } catch(ConversionError &e) { std::cerr << name() << ": " << e.what() << std::endl; @@ -239,9 +245,13 @@ public: const T& operator*() const { return m_value; } T *operator->() { return &m_value; } const T *operator->() const { return &m_value; } + + Signal& modifiedSig() { return m_modified_sig; } + private: T m_value, m_defaultval; ResourceManager_base &m_rm; + Signal m_modified_sig; }; -- cgit v0.11.2