refs #581 CValueCachePacket contains an inhibitions list that can be used to disable specific notification slots.

This commit is contained in:
Mathew Sutcliffe
2016-02-04 00:57:40 +00:00
parent c1d3e2aabb
commit bc2e0faa36
2 changed files with 13 additions and 5 deletions

View File

@@ -467,7 +467,7 @@ namespace BlackMisc
QList<NotifySlot> notifySlots;
forEachIntersection(m_elements, values, [changedBy, this, &notifySlots, &values](const QString &, const ElementPtr &element, CValueCachePacket::const_iterator it)
forEachIntersection(m_elements, values, [changedBy, this, &notifySlots, &values](const QString &key, const ElementPtr &element, CValueCachePacket::const_iterator it)
{
if (changedBy == this) // round trip
{
@@ -482,7 +482,10 @@ namespace BlackMisc
element->m_value.uniqueWrite() = it.value();
element->m_timestamp = it.timestamp();
element->m_saved = values.isSaved();
if (element->m_notifySlot && ! notifySlots.contains(element->m_notifySlot)) { notifySlots.push_back(element->m_notifySlot); }
if (element->m_notifySlot && ! notifySlots.contains(element->m_notifySlot) && ! values.isInhibited(parent(), key))
{
notifySlots.push_back(element->m_notifySlot);
}
}
else
{

View File

@@ -25,12 +25,10 @@ namespace BlackMisc
public CDictionary<QString, std::pair<CVariant, qint64>, QMap>,
public Mixin::MetaType<CValueCachePacket>,
public Mixin::DBusByTuple<CValueCachePacket>,
public Mixin::JsonByTuple<CValueCachePacket>,
public Mixin::EqualsByTuple<CValueCachePacket>
{
public:
BLACKMISC_DECLARE_USING_MIXIN_DBUS(CValueCachePacket)
BLACKMISC_DECLARE_USING_MIXIN_JSON(CValueCachePacket)
//! \copydoc BlackMisc::CValueObject::base_type
using base_type = CDictionary;
@@ -56,6 +54,12 @@ namespace BlackMisc
//! Insert values from another packet.
void insert(const CValueCachePacket &other) { CDictionary::insert(other); }
//! Add a page owner and key to the list of inhibited notifications.
void inhibit(QObject *pageOwner, const QString &key) { m_inhibitions.push_back(std::make_pair(reinterpret_cast<quintptr>(pageOwner), key)); }
//! Query whether a particular owner/key pair should have its notification inhibited.
bool isInhibited(QObject *pageOwner, const QString &key) const { return m_inhibitions.contains(std::make_pair(reinterpret_cast<quintptr>(pageOwner), key)); }
//! Discard timestamps and return as variant map.
CVariantMap toVariantMap() const;
@@ -89,6 +93,7 @@ namespace BlackMisc
private:
BLACK_ENABLE_TUPLE_CONVERSION(CValueCachePacket)
bool m_saved = false;
CSequence<std::pair<quintptr, QString>> m_inhibitions;
};
/*!
@@ -347,6 +352,6 @@ namespace BlackMisc
} // namespace
Q_DECLARE_METATYPE(BlackMisc::CValueCachePacket)
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::CValueCachePacket, (attr(o.m_saved)))
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::CValueCachePacket, (attr(o.m_saved), attr(o.m_inhibitions)))
#endif