forked from 0x20/tab-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtqmembermodel.h
64 lines (46 loc) · 1.65 KB
/
tqmembermodel.h
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
#ifndef TQMEMBERMODEL_H
#define TQMEMBERMODEL_H
#include <QAbstractListModel>
struct BarMember {
QString name;
QString internal_name;
int balance;
int items;
};
enum MemberModelRoles {
MEMBER_ROLE_NAME = Qt::UserRole + 1,
MEMBER_ROLE_INTERNAL_NAME,
MEMBER_ROLE_BALANCE,
MEMBER_ROLE_ITEMS,
};
class TqMemberModel : public QAbstractListModel
{
Q_OBJECT
QVector<BarMember> m_members;
QMap<QString, int> m_memberPositions;
public:
explicit TqMemberModel(QObject *parent = nullptr);
// Loading
Q_INVOKABLE bool loadFromJson(QMap<QString, QVariant> data);
Q_INVOKABLE int memberPosition(QString internal_name) const;
Q_INVOKABLE void applyDelta(QString internal_name, int dBalance, int dItems);
Q_INVOKABLE QVariant get(QVariant id);
Q_PROPERTY(int count READ getCount NOTIFY countChanged)
// Header:
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override;
// Basic functionality:
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
// Editable:
bool setData(const QModelIndex &index, const QVariant &value,
int role = Qt::EditRole) override;
Qt::ItemFlags flags(const QModelIndex& index) const override;
// Role names
QHash<int, QByteArray> roleNames() const override;
signals:
void countChanged(int count);
private:
int getCount() const;
};
#endif // TQMEMBERMODEL_H