From ed2c8130aed41219b1b33aaec985474fc5284cd2 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Sat, 30 Apr 2016 23:15:50 +0100 Subject: [PATCH] refs #652 Convenience to support changing only an indexed property of a cached value. --- src/blackmisc/datacache.h | 3 +++ src/blackmisc/valuecache.h | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/blackmisc/datacache.h b/src/blackmisc/datacache.h index 2d6ae27e0..812904394 100644 --- a/src/blackmisc/datacache.h +++ b/src/blackmisc/datacache.h @@ -267,7 +267,10 @@ namespace BlackMisc } //! Data cache doesn't support setAndSave (because set() already causes save anyway). + //! @{ CStatusMessage setAndSave(const typename Trait::type &value, qint64 timestamp = 0) = delete; + CStatusMessage setAndSaveProperty(const CPropertyIndex &index, const CVariant &value, qint64 timestamp = 0) = delete; + //! @} //! Data cache doesn't support save (because currently set value is saved already). CStatusMessage save() = delete; diff --git a/src/blackmisc/valuecache.h b/src/blackmisc/valuecache.h index 034865b8d..c7b2f2b6f 100644 --- a/src/blackmisc/valuecache.h +++ b/src/blackmisc/valuecache.h @@ -312,6 +312,12 @@ namespace BlackMisc //! 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); } + //! Write a property of the value. Must be called from the thread in which the owner lives. + CStatusMessage setProperty(const CPropertyIndex &index, const CVariant &value, qint64 timestamp = 0) { auto v = get(); v.setPropertyByIndex(value, index); return set(v, timestamp); } + + //! Write a property and save in the same step. Must be called from the thread in which the owner lives. + CStatusMessage setAndSaveProperty(const CPropertyIndex &index, const CVariant &value, qint64 timestamp = 0) { auto v = get(); v.setPropertyByIndex(value, index); return setAndSave(v, timestamp); } + //! Is current thread the owner thread, so CCached::set is safe bool isOwnerThread() const { return QThread::currentThread() == m_page.thread(); }