-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathListModel.h
72 lines (57 loc) · 2.26 KB
/
ListModel.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
65
66
67
68
69
70
71
72
#ifndef LISTMODEL_H
#define LISTMODEL_H
#include <QAbstractListModel>
#include <QVariant>
#include <QList>
#include <QHash>
#include <QByteArray>
#include <QtAlgorithms>
#include <QQmlEngine>
#include "ListItem.h"
bool compareFunc(void *a, void *b);
namespace Models
{
class ListModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
Q_PROPERTY(bool sorting READ sortingEnabled WRITE setSorting NOTIFY sortingChanged)
public:
explicit ListModel(ListItem *prototype, QObject *parent = 0);
~ListModel();
// REIMPLEMENTED METHODS
int rowCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role) const;
bool setData(const QModelIndex &index, const QVariant &value, int role);
QHash<int, QByteArray> roleNames() const;
Q_INVOKABLE void appendRowFromQml(QObject *item);
void appendRow(ListItem *item);
void appendRows(QList<ListItem *> &items);
void insertRow(int row, ListItem *item);
ListItem* takeRow(int row = -2, const QModelIndex &index = QModelIndex());
QList<ListItem *> takeRows(int row = -2, int count = -1, const QModelIndex &index = QModelIndex());
bool removeRow(int row, const QModelIndex &index = QModelIndex());
bool removeRows(int row, int count, const QModelIndex &index = QModelIndex());
ListItem* find(int itemId) const;
int getRowFromItem(ListItem *item) const;
QModelIndex indexFromItem(ListItem *item) const;
QList<ListItem *> toList() const;
Q_INVOKABLE QVariant get(int index);
Q_INVOKABLE int rowIndexFromId(int id);
Q_INVOKABLE void clear();
bool sortingEnabled() const;
void setSorting(bool value);
protected:
ListItem *prototype;
QList<ListItem *> items;
bool sortEnabled;
private:
void sort();
private slots :
void updateItem();
signals :
void countChanged(int);
void sortingChanged(bool);
};
}
#endif // LISTMODEL_H