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
|
/*
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>
#include <QHash>
#include <QIcon>
class SmTreeItem;
class SmTreeModel : public QAbstractItemModel {
Q_OBJECT
public:
explicit SmTreeModel(const QStringList &headers, QObject *parent = 0);
virtual ~SmTreeModel();
// counts
virtual int rowCount(const QModelIndex &parent) const;
virtual int columnCount(const QModelIndex &parent) const;
// index, parent and flags
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const;
virtual QModelIndex parent(const QModelIndex &child) const;
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
// headers + data
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;
virtual const QHash<QString, int> headerData() const;
virtual 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 &pIdx = QModelIndex()) const;
virtual QModelIndex findRecursive(const QVariant &value, int column, const QModelIndex &start) const;
virtual bool matchRecursive(const QModelIndex &pIdx, const QRegExp ®ex, int column = 0) const;
virtual bool checkParents(const SmTreeItem *item, const QRegExp ®ex, int column) const;
// root + parent item
bool setRoot(SmTreeItem *rootItem);
SmTreeItem *root() const { return mRootItem; }
QModelIndex rootIndex() const;
SmTreeItem *parentItem(const QModelIndex &child) const;
void reparent(const QModelIndex &idx, const QModelIndex &newParent, bool sorted = false);
// row manipulation
virtual bool insertRows(int row, int count, const QModelIndex &pIdx);
virtual bool removeRows(int row, int count, const QModelIndex &pIdx);
bool addRow(const QList<QVariant> &data, const QModelIndex &pIdx, bool sorted = false);
bool appendRow(const QList<QVariant> &data, const QModelIndex &pIdx);
//misc
void setDecorationIcon(const QIcon &icon) { mDecorationIcon = icon; }
const QIcon decorationIcon() const { return mDecorationIcon; }
protected:
SmTreeItem *itemAt(const QModelIndex &index) const;
private:
QStringList mHeaders;
SmTreeItem *mRootItem;
QHash<QString, int> mHeaderData;
QIcon mDecorationIcon;
};
#endif
|