-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTreeModel.h
87 lines (78 loc) · 2.17 KB
/
TreeModel.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef TREEMODEL_H
#define TREEMODEL_H
#include <QAbstractListModel>
#include <QStringList>
#include <QTreeView>
class TreeItem;
class TreeModel : public QAbstractListModel
{
public:
TreeModel(QStringList& header);
~TreeModel();
void setRowHeight(int height) { m_nHeight = height; }
QModelIndex index(int row, int column, const QModelIndex &parent) const;
QModelIndex parent(const QModelIndex &index) const;
//Qt::ItemFlags flags(const QModelIndex &index) const;
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
QVariant data(const QModelIndex &index, int role) const;
bool hasChildren ( const QModelIndex & parent = QModelIndex() ) const;
void doReset() { emit reset(); }
//Qt::ItemFlags flags(const QModelIndex &index) const;
TreeItem* rootItem;
private:
int m_nHeight;
};
class UserTreeModel : public TreeModel
{
public:
UserTreeModel(QStringList& header) : TreeModel(header) {}
QVariant data(const QModelIndex &index, int role) const;
Qt::ItemFlags flags(const QModelIndex &index) const;
};
class GameTreeModel : public TreeModel
{
public:
GameTreeModel(QStringList& header) : TreeModel(header) {}
QVariant data(const QModelIndex &index, int role) const;
};
/*class ServerTreeModel : public TreeModel
{
public:
};*/
class TreeItem
{
public:
TreeItem(const QStringList &data, TreeItem *parent = 0);
TreeItem(QString data, TreeItem *parent = 0);
TreeItem(TreeItem* parent = 0);
virtual ~TreeItem();
void appendChild(TreeItem *child);
void removeChild(TreeItem *item);
void removeAll();
void setData(QStringList& data) { itemData = data; }
void setIcon(QIcon icon) { m_icon = icon; }
QIcon icon() const { return m_icon; }
TreeItem *child(int row);
int childCount() const;
int columnCount() const;
QVariant data(int column) const;
int row() const;
TreeItem *parent();
private:
QList<TreeItem*> childItems;
QIcon m_icon;
QStringList itemData;
TreeItem *parentItem;
};
class GameTreeItem : public TreeItem
{
public:
GameTreeItem(TreeItem* parent = 0)
: TreeItem(parent)
{
}
bool m_bPassworded;
};
#endif