swift
Loading...
Searching...
No Matches
testsharedstate.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 2020 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
10
11#include <QMetaType>
12
20
21namespace MiscTest
22{
24 class CTestFilter : public swift::misc::CValueObject<CTestFilter>
25 {
26 public:
27 bool matches(const swift::misc::CVariant &value) const
28 {
29 return value.canConvert<unsigned>() && (value.value<unsigned>() & m_mask);
30 }
31 QString convertToQString(bool = false) const { return QString::number(m_mask); }
32 CTestFilter(unsigned mask = ~0u) : m_mask(mask) {}
33
34 private:
35 unsigned m_mask = ~0u;
36 SWIFT_METACLASS(CTestFilter, SWIFT_METAMEMBER(mask));
37 };
38} // namespace MiscTest
39
41Q_DECLARE_METATYPE(MiscTest::CTestFilter);
43
44namespace MiscTest
45{
55
65
68 {
70 SWIFT_SHARED_STATE_CHANNEL("test_scalar_channel")
71 public:
74 void onValueChanged(const int &) override {}
75 };
76
86
96
98 class CTestListObserver : public swift::misc::shared_state::CListObserver<QList<int>, CTestFilter>
99 {
101 SWIFT_SHARED_STATE_CHANNEL("test_list_channel")
102 public:
105
108
110 void onElementAdded(const int &) override {}
111
113 void onElementsReplaced(const QList<int> &) override {}
115 };
116} // namespace MiscTest
117
CTestListJournal(QObject *parent)
Ctor.
CTestListMutator(QObject *parent)
Ctor.
void onElementAdded(const int &)
Called when an element matching the filter is added to the list.
void onElementsReplaced(const QList< int > &)
Called when the whole list is updated wholesale.
CTestListObserver(QObject *parent)
Ctor.
CTestScalarJournal(QObject *parent)
Ctor.
CTestScalarMutator(QObject *parent)
Ctor.
CTestScalarObserver(QObject *parent)
Ctor.
void onValueChanged(const int &)
Called when the scalar value changes.
T value() const
Return the value converted to the type T.
Definition variant.h:154
bool canConvert(int typeId) const
True if this variant can be converted to the type with the given metatype ID.
Base class for an object that shares state with a corresponding CListObserver subclass object.
Definition listjournal.h:53
Base class for an object that shares state with a corresponding CListObserver subclass object.
Definition listmutator.h:50
Base class for an object that shares state with a corresponding CListMutator subclass object.
Base class for an object that shares state with a corresponding CScalarObserver subclass object.
Base class for an object that shares state with a corresponding CScalarObserver subclass object.
Base class for an object that shares state with a corresponding CScalarMutator subclass object.
#define SWIFT_METAMEMBER(MEMBER,...)
Macro to define an element within a metaclass.
Definition metaclass.h:72
#define SWIFT_METACLASS(CLASS,...)
Macro to define a nested metaclass that describes the attributes of its enclosing class.
Definition metaclass.h:52
#define SWIFT_SHARED_STATE_CHANNEL(ID)
Put this macro in the private section of a class to set the channel of its child endpoints.
Definition datalink.h:27
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
QObject * parent() const const
QString number(double n, char format, int precision)