-
Notifications
You must be signed in to change notification settings - Fork 1
/
VariantListModel.h
48 lines (40 loc) · 1.27 KB
/
VariantListModel.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
#pragma once
#include <QAbstractListModel>
#include <QList>
#include <QObject>
#include <QVariant>
class VariantListModel : public QAbstractListModel {
Q_OBJECT
Q_PROPERTY(int count READ count NOTIFY countChanged)
public:
explicit VariantListModel();
~VariantListModel();
public: // QAbstractItemModel interface reimplemented
int rowCount(const QModelIndex& parent = QModelIndex()) const;
bool setData(const QModelIndex& index, const QVariant& value, int role);
QVariant data(const QModelIndex& index, int role) const;
QHash<int, QByteArray> roleNames() const;
public slots: // public API
void clear();
int count() const;
bool isEmpty() const;
void append(const QVariant& item);
void prepend(const QVariant& item);
void insert(int idx, const QVariant& item);
void appendList(const QVariantList& itemList);
void prependList(const QVariantList& itemList);
void replace(int pos, const QVariant& item);
void insertList(int idx, const QVariantList& itemList);
void move(int idx, int pos);
void remove(int idx);
QVariant get(int idx) const;
QVariantList list() const;
signals: // notifiers
void countChanged(int count);
protected:
void updateCounter();
private:
int m_count;
QVariantList m_items;
QHash<int, QByteArray> m_roles;
};