00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef MODEL_H
00025 #define MODEL_H
00026
00027 #include <QAbstractItemModel>
00028 #include <QVector>
00029
00030 class Model : public QAbstractItemModel
00031 {
00032 Q_OBJECT
00033
00034 public:
00035 Model(int rows, int columns, QObject *parent = 0);
00036 ~Model();
00037
00038 QModelIndex index(int row, int column, const QModelIndex &parent) const;
00039 QModelIndex parent(const QModelIndex &child) const;
00040
00041 int rowCount(const QModelIndex &parent) const;
00042 int columnCount(const QModelIndex &parent) const;
00043
00044 QVariant data(const QModelIndex &index, int role) const;
00045 QVariant headerData(int section, Qt::Orientation orientation, int role) const;
00046
00047 bool hasChildren(const QModelIndex &parent) const;
00048 Qt::ItemFlags flags(const QModelIndex &index) const;
00049 bool isDragEnabled(const QModelIndex &index) const;
00050
00051 private:
00052
00053 struct Node
00054 {
00055 Node(Node *parent = 0) : parent(parent), children(0) {}
00056 ~Node() { delete children; }
00057 Node *parent;
00058 QVector<Node> *children;
00059 };
00060
00061 Node *node(int row, Node *parent) const;
00062 Node *parent(Node *child) const;
00063 int row(Node *node) const;
00064
00065 int rc, cc;
00066 QVector<Node> *tree;
00067 };
00068
00069 #endif