refs #644 Add method CCached::save, like setAndSave but using the currently set value.

Implemented with a flag in CValueCachePacket to indicate a request to save only.
This commit is contained in:
Mathew Sutcliffe
2016-04-27 19:39:49 +01:00
parent d9d30a339a
commit f4eadddee7
4 changed files with 41 additions and 14 deletions

View File

@@ -35,10 +35,13 @@ namespace BlackMisc
using base_type = CDictionary;
//! Constructor.
CValueCachePacket(bool saved = false) : m_saved(saved) {}
CValueCachePacket(bool saved = false, bool valuesChanged = true) : m_saved(saved), m_valuesChanged(valuesChanged) {}
//! Construct from CVariantMap and a timestamp.
CValueCachePacket(const CVariantMap &values, qint64 timestamp, bool saved = false);
CValueCachePacket(const CVariantMap &values, qint64 timestamp, bool saved = false, bool valuesChanged = true);
//! Values have been changed.
bool valuesChanged() const { return m_valuesChanged; }
//! Values are to be saved.
//! @{
@@ -90,10 +93,12 @@ namespace BlackMisc
private:
bool m_saved = false;
bool m_valuesChanged = true;
BLACK_METACLASS(
CValueCachePacket,
BLACK_METAMEMBER(saved)
BLACK_METAMEMBER(saved),
BLACK_METAMEMBER(valuesChanged)
);
};
@@ -304,6 +309,9 @@ namespace BlackMisc
//! Write and save in the same step. Must be called from the thread in which the owner lives.
CStatusMessage setAndSave(const T &value, qint64 timestamp = 0) { return m_page.setValue(m_element, CVariant::from(value), timestamp, true); }
//! Save using the currently set value. Must be called from the thread in which the owner lives.
CStatusMessage save() { return m_page.setValue(m_element, {}, 0, true, true); }
//! Is current thread the owner thread, so CCached::set is safe
bool isOwnerThread() const { return QThread::currentThread() == m_page.thread(); }