Changeset View
Changeset View
Standalone View
Standalone View
gemini/cloud/dropbox/3rdparty/listmodel.h
Show All 40 Lines | 31 | enum Roles { | |||
---|---|---|---|---|---|
41 | CheckedRole, | 41 | CheckedRole, | ||
42 | NameRole, | 42 | NameRole, | ||
43 | SectionRole | 43 | SectionRole | ||
44 | }; | 44 | }; | ||
45 | ListItem(QObject* parent = 0) : QObject(parent) {} | 45 | ListItem(QObject* parent = 0) : QObject(parent) {} | ||
46 | virtual ~ListItem() {} | 46 | virtual ~ListItem() {} | ||
47 | virtual QString id() const = 0; | 47 | virtual QString id() const = 0; | ||
48 | virtual QVariant data(int role) const = 0; | 48 | virtual QVariant data(int role) const = 0; | ||
49 | // virtual QHash<int, QByteArray> roleNames() const = 0; | | |||
50 | 49 | | |||
51 | Q_SIGNALS: | 50 | Q_SIGNALS: | ||
52 | void dataChanged(); | 51 | void dataChanged(); | ||
53 | }; | 52 | }; | ||
54 | 53 | | |||
55 | class ListModel : public QAbstractListModel | 54 | class ListModel : public QAbstractListModel | ||
56 | { | 55 | { | ||
57 | Q_OBJECT | 56 | Q_OBJECT | ||
Show All 10 Lines | 59 | public: | |||
68 | bool removeRow(int row, const QModelIndex &parent = QModelIndex()); | 67 | bool removeRow(int row, const QModelIndex &parent = QModelIndex()); | ||
69 | bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); | 68 | bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()); | ||
70 | ListItem* takeRow(int row); | 69 | ListItem* takeRow(int row); | ||
71 | ListItem* getRow(int row); | 70 | ListItem* getRow(int row); | ||
72 | ListItem* find(const QString &id) const; | 71 | ListItem* find(const QString &id) const; | ||
73 | QModelIndex indexFromItem( const ListItem* item) const; | 72 | QModelIndex indexFromItem( const ListItem* item) const; | ||
74 | void clear(); | 73 | void clear(); | ||
75 | 74 | | |||
76 | //QHash<int, QByteArray> roleNames() const; | | |||
77 | | ||||
78 | int count() const; | 75 | int count() const; | ||
79 | int getCount() { return this->rowCount();} | 76 | int getCount() { return this->rowCount();} | ||
80 | Q_INVOKABLE QVariantMap get(int row) const; | 77 | Q_INVOKABLE QVariantMap get(int row) const; | ||
81 | 78 | | |||
82 | private Q_SLOTS: | 79 | private Q_SLOTS: | ||
83 | void handleItemChange(); | 80 | void handleItemChange(); | ||
84 | 81 | | |||
85 | Q_SIGNALS: | 82 | Q_SIGNALS: | ||
86 | void countChanged(); | 83 | void countChanged(); | ||
87 | 84 | | |||
85 | protected: | ||||
86 | QHash<int, QByteArray> roleNames() const; | ||||
87 | | ||||
88 | private: | 88 | private: | ||
89 | ListItem* m_prototype; | 89 | ListItem* m_prototype; | ||
90 | QList<ListItem*> m_list; | 90 | QList<ListItem*> m_list; | ||
91 | }; | 91 | }; | ||
92 | 92 | | |||
93 | #endif // LISTMODEL_H | 93 | #endif // LISTMODEL_H |