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
|
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version
2 of the License, or (at your option) any later version.
*/
#ifndef SMTREEMODEL_H
#define SMTREEMODEL_H
#include <QAbstractItemModel>
#include <QStringList>
class SmTreeItem;
class SmTreeModel : public QAbstractItemModel {
Q_OBJECT
public:
explicit SmTreeModel(const QStringList &headers, QObject *parent = 0);
virtual ~SmTreeModel();
// counts
int rowCount(const QModelIndex &parent) const;
int columnCount(const QModelIndex &parent) const;
// index, parent and flags
QModelIndex index(int row, int column, const QModelIndex &parent) const;
QModelIndex parent(const QModelIndex &child) const;
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
// headers + data
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role);
virtual QVariant data(const QModelIndex &index, int role) const;
virtual bool setData(const QModelIndex &index, const QVariant &value, int role);
virtual QModelIndex find(const QVariant &value, int column = 0, const QModelIndex &parent = QModelIndex()) const;
// root + parent item
bool setRoot(SmTreeItem *rootItem);
SmTreeItem *root() const { return mRootItem; }
SmTreeItem *parentItem(const QModelIndex &child) const;
void reparent(const QModelIndex &idx, const QModelIndex &newParent);
// row manipulation
bool insertRows(int row, int count, const QModelIndex &parent);
bool removeRows(int row, int count, const QModelIndex &parent);
bool addRow(const QList<QVariant> &data, const QModelIndex &parent);
protected:
SmTreeItem *itemAt(const QModelIndex &index) const;
private:
QStringList mHeaders;
SmTreeItem *mRootItem;
};
#endif
|