OK Folks, my first commit after quite a while, and while Quassel looks the same as...
[quassel.git] / src / client / treemodel.h
1 /***************************************************************************
2  *   Copyright (C) 2005-07 by The Quassel Team                             *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #ifndef _TREEMODEL_H_
22 #define _TREEMODEL_H_
23
24 #include <QList>
25 #include <QVariant>
26 #include <QAbstractItemModel>
27
28 /*****************************************
29  *  general item used in the Tree Model
30  *****************************************/
31 class TreeItem : public QObject {
32   Q_OBJECT
33   
34 public:
35   TreeItem(const QList<QVariant> &data, TreeItem *parent = 0);
36   TreeItem(TreeItem *parent = 0);
37   virtual ~TreeItem();
38   
39   void appendChild(TreeItem *child);
40   void removeChild(int row);
41                    
42   TreeItem *child(int row);
43   int childCount() const;
44   int columnCount() const;
45   virtual QVariant data(int column, int role) const;
46   int row() const;
47   TreeItem *parent();
48     
49 protected:
50   QList<TreeItem*> childItems;
51   TreeItem *parentItem;
52   QList<QVariant> itemData;
53 };
54
55
56 /*****************************************
57  * TreeModel
58  *****************************************/
59 class TreeModel : public QAbstractItemModel {
60   Q_OBJECT
61   
62 public:
63   TreeModel(const QList<QVariant> &, QObject *parent = 0);
64   virtual ~TreeModel();
65   
66   QVariant data(const QModelIndex &index, int role) const;
67   virtual Qt::ItemFlags flags(const QModelIndex &index) const;
68   QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
69   QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
70   QModelIndex parent(const QModelIndex &index) const;
71   int rowCount(const QModelIndex &parent = QModelIndex()) const;
72   int columnCount(const QModelIndex &parent = QModelIndex()) const;
73
74   void clear();
75
76 protected:
77   bool removeRow(int row, const QModelIndex &parent = QModelIndex());
78   bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
79
80   TreeItem *rootItem;
81 };
82
83 #endif