swift
Loading...
Searching...
No Matches
listobserver.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 2017 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
7
9#include "misc/variantlist.h"
10
12{
14 {
15 dataLink->subscribe(m_observer.data());
16 m_watcher = dataLink->watcher();
17 connect(m_watcher, &CDataLinkConnectionWatcher::connected, this, &CGenericListObserver::reconstruct);
18 }
19
21 {
22 m_observer->setEventSubscription(filter);
23 if (m_watcher && m_watcher->isConnected())
24 {
25 reconstruct();
26 }
27 }
28
29 void CGenericListObserver::reconstruct()
30 {
31 m_observer->requestAsync(m_observer->eventSubscription(), [this](const CVariant &list) {
32 QMutexLocker lock(&m_listMutex);
33 m_list = list.value<CVariantList>();
34 lock.unlock();
35 onGenericElementsReplaced(allValues());
36 });
37 }
38
40 {
41 QMutexLocker lock(&m_listMutex);
42 return m_list;
43 }
44
46 {
47 QMutexLocker lock(&m_listMutex);
48 return m_list.removeIf(
49 [filter = m_observer->eventSubscription()](const CVariant &value) { return !value.matches(filter); });
50 }
51
52 void CGenericListObserver::handleEvent(const CVariant &param)
53 {
54 QMutexLocker lock(&m_listMutex);
55 m_list.push_back(param);
56 lock.unlock();
57 onGenericElementAdded(param);
58 }
59} // namespace swift::misc::shared_state
void push_back(const T &value)
Appends an element at the end of the sequence.
Definition sequence.h:308
Wrapper around QVariant which provides transparent access to CValueObject methods of the contained ob...
Definition variant.h:69
Value object encapsulating a list of variants.
Definition variantlist.h:29
int cleanValues()
Remove any old values that no longer match the filter.
void setFilter(const CVariant &filter)
Set list filter as variant.
virtual void initialize(IDataLink *)
Subscribe using the given transport mechanism.
CVariantList allValues() const
Get filtered list value as variant list.
Utilities for sharing state between multiple objects.
Definition application.h:48
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)