forked from oKcerG/SortFilterProxyModel
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathproxyrole.h
More file actions
153 lines (112 loc) · 4.06 KB
/
proxyrole.h
File metadata and controls
153 lines (112 loc) · 4.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#ifndef PROXYROLE_H
#define PROXYROLE_H
#include <QObject>
#include <QMutex>
#include <QQmlScriptString>
#include <QQmlExpression>
#include <qqml.h>
#include "qqmlsortfilterproxymodel.h"
namespace qqsfpm {
class ProxyRole : public QObject
{
Q_OBJECT
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
public:
explicit ProxyRole(QObject *parent = nullptr);
const QString& name() const;
void setName(const QString& name);
QVariant roleData(const QModelIndex& sourceIndex, const QQmlSortFilterProxyModel& proxyModel);
virtual void proxyModelCompleted(const QQmlSortFilterProxyModel& proxyModel);
protected:
void invalidate();
Q_SIGNALS:
void nameAboutToBeChanged();
void nameChanged();
void invalidated();
private:
virtual QVariant data(const QModelIndex& sourceIndex, const QQmlSortFilterProxyModel& proxyModel) = 0;
QString m_name;
QMutex m_mutex;
};
class JoinRole : public ProxyRole
{
Q_OBJECT
Q_PROPERTY(QStringList roleNames READ roleNames WRITE setRoleNames NOTIFY roleNamesChanged)
Q_PROPERTY(QString separator READ separator WRITE setSeparator NOTIFY separatorChanged)
public:
using ProxyRole::ProxyRole;
QStringList roleNames() const;
void setRoleNames(const QStringList& roleNames);
QString separator() const;
void setSeparator(const QString& separator);
Q_SIGNALS:
void roleNamesChanged();
void separatorChanged();
private:
QStringList m_roleNames;
QVariant data(const QModelIndex& sourceIndex, const QQmlSortFilterProxyModel& proxyModel) override;
QString m_separator = " ";
};
class SwitchRoleAttached : public QObject
{
Q_OBJECT
Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged)
public:
SwitchRoleAttached(QObject* parent);
QVariant value() const;
void setValue(QVariant value);
Q_SIGNALS:
void valueChanged();
private:
QVariant m_value;
};
class SwitchRole : public ProxyRole
{
Q_OBJECT
Q_PROPERTY(QString defaultRoleName READ defaultRoleName WRITE setDefaultRoleName NOTIFY defaultRoleNameChanged)
Q_PROPERTY(QVariant defaultValue READ defaultValue WRITE setDefaultValue NOTIFY defaultValueChanged)
Q_PROPERTY(QQmlListProperty<qqsfpm::Filter> filters READ filters)
public:
using ProxyRole::ProxyRole;
QString defaultRoleName() const;
void setDefaultRoleName(const QString& defaultRoleName);
QVariant defaultValue() const;
void setDefaultValue(const QVariant& defaultValue);
QQmlListProperty<Filter> filters();
void proxyModelCompleted(const QQmlSortFilterProxyModel& proxyModel) override;
static SwitchRoleAttached* qmlAttachedProperties(QObject* object);
Q_SIGNALS:
void defaultRoleNameChanged();
void defaultValueChanged();
private:
QVariant data(const QModelIndex& sourceIndex, const QQmlSortFilterProxyModel& proxyModel) override;
static void append_filter(QQmlListProperty<Filter>* list, Filter* filter);
static int count_filter(QQmlListProperty<Filter>* list);
static Filter* at_filter(QQmlListProperty<Filter>* list, int index);
static void clear_filters(QQmlListProperty<Filter>* list);
QString m_defaultRoleName;
QVariant m_defaultValue;
QList<Filter*> m_filters;
};
class ExpressionRole : public ProxyRole
{
Q_OBJECT
Q_PROPERTY(QQmlScriptString expression READ expression WRITE setExpression NOTIFY expressionChanged)
public:
using ProxyRole::ProxyRole;
const QQmlScriptString& expression() const;
void setExpression(const QQmlScriptString& scriptString);
void proxyModelCompleted(const QQmlSortFilterProxyModel& proxyModel) override;
Q_SIGNALS:
void expressionChanged();
private:
QVariant data(const QModelIndex& sourceIndex, const QQmlSortFilterProxyModel& proxyModel) override;
void updateContext(const QQmlSortFilterProxyModel& proxyModel);
void updateExpression();
QQmlScriptString m_scriptString;
QQmlExpression* m_expression = nullptr;
QQmlContext* m_context = nullptr;
};
}
QML_DECLARE_TYPEINFO(qqsfpm::SwitchRole, QML_HAS_ATTACHED_PROPERTIES)
#endif // PROXYROLE_H