refs #652 Convenience to support changing only an indexed property of a cached value.

This commit is contained in:
Mathew Sutcliffe
2016-04-30 23:15:50 +01:00
parent 7b04a20e9f
commit ed2c8130ae
2 changed files with 9 additions and 0 deletions

View File

@@ -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;

View File

@@ -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(); }