forked from Aseman-Land/TelegramQML
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtelegramabstractlistmodel.h
More file actions
73 lines (58 loc) · 2.13 KB
/
telegramabstractlistmodel.h
File metadata and controls
73 lines (58 loc) · 2.13 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
#ifndef TELEGRAMABSTRACTLISTMODEL_H
#define TELEGRAMABSTRACTLISTMODEL_H
#include "telegramqml_global.h"
#include "telegramtools.h"
#include "tqbaseobject.h"
#include <QAbstractListModel>
#include <QQmlListProperty>
class TELEGRAMQMLSHARED_EXPORT TelegramAbstractListModel : public QAbstractListModel, public TqBaseObject
{
Q_OBJECT
Q_PROPERTY(int count READ count NOTIFY countChanged)
Q_PROPERTY(bool isEmpty READ isEmpty NOTIFY isEmptyChanged)
Q_PROPERTY(QString errorText READ errorText NOTIFY errorChanged)
Q_PROPERTY(qint32 errorCode READ errorCode NOTIFY errorChanged)
Q_PROPERTY(QQmlListProperty<QObject> items READ items NOTIFY itemsChanged)
Q_CLASSINFO("DefaultProperty", "items")
public:
TelegramAbstractListModel(QObject *parent = 0);
~TelegramAbstractListModel();
Q_INVOKABLE QStringList roles() const;
int rowCount(const QModelIndex &) const { return count(); }
virtual int count() const = 0;
bool isEmpty() const { return count() == 0; }
QString errorText() const { return mErrorText; }
qint32 errorCode() const { return mErrorCode; }
QQmlListProperty<QObject> items();
static QStringList requiredProperties() {
return QStringList();
}
public Q_SLOTS:
QVariant get(int index, int role) const;
QVariant get(int index, const QString &roleName) const;
QVariantMap get(int index) const;
int indexOf(int role, const QVariant &value);
Q_SIGNALS:
void countChanged();
void errorChanged();
void itemsChanged();
void isEmptyChanged();
protected:
void setError(const QString &errorText, qint32 errorCode) {
mErrorText = TelegramTools::convertErrorToText(errorText);
mErrorCode = errorCode;
Q_EMIT errorChanged();
}
private:
static void append(QQmlListProperty<QObject> *p, QObject *v);
static int count(QQmlListProperty<QObject> *p);
static QObject *at(QQmlListProperty<QObject> *p, int idx);
static void clear(QQmlListProperty<QObject> *p);
protected:
QList<QObject*> _items;
private:
QString mErrorText;
qint32 mErrorCode;
int _cacheCount;
};
#endif // TELEGRAMABSTRACTLISTMODEL_H