a4039843b40004e89d1612b5dcc90fc0c85bf04f
[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 <QtCore>
25
26 /*****************************************
27  *  general item used in the Tree Model
28  *****************************************/
29 class TreeItem : public QObject {
30   Q_OBJECT
31   
32 public:
33   TreeItem(const QList<QVariant> &data, TreeItem *parent = 0);
34   TreeItem(TreeItem *parent = 0);
35   virtual ~TreeItem();
36   
37   void appendChild(TreeItem *child);
38   void removeChild(int row);
39                    
40   TreeItem *child(int row);
41   int childCount() const;
42   int columnCount() const;
43   virtual QVariant data(int column, int role) const;
44   int row() const;
45   TreeItem *parent();
46     
47 protected:
48   QList<TreeItem*> childItems;
49   TreeItem *parentItem;
50   QList<QVariant> itemData;
51 };
52
53
54 /*****************************************
55  * TreeModel
56  *****************************************/
57 class TreeModel : public QAbstractItemModel {
58   Q_OBJECT
59   
60 public:
61   TreeModel(const QList<QVariant> &, QObject *parent = 0);
62   virtual ~TreeModel();
63   
64   QVariant data(const QModelIndex &index, int role) const;
65   virtual Qt::ItemFlags flags(const QModelIndex &index) const;
66   QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
67   QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
68   QModelIndex parent(const QModelIndex &index) const;
69   int rowCount(const QModelIndex &parent = QModelIndex()) const;
70   int columnCount(const QModelIndex &parent = QModelIndex()) const;
71
72 protected:
73   bool removeRow(int row, const QModelIndex &parent = QModelIndex());
74   
75   TreeItem *rootItem;
76 };
77
78 #endif