Blokkal
an Extendable KDE Blogging Client
SourceForge.net Logo

blokkaltreemodel.h

00001 /***************************************************************************
00002  *   Copyright (C) 2007 - 2008 by Martin Mueller                           *
00003  *   orvio@orvio.de                                                        *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 #ifndef BLOKKALTREEMODEL_H
00021 #define BLOKKALTREEMODEL_H
00022 
00023 #include <QtCore/QAbstractItemModel>
00024 
00025 #include "blokkal_export.h"
00026 
00027 namespace Blokkal {
00028 
00034 class BLOKKAL_EXPORT TreeModel : public QAbstractItemModel
00035 {
00036 Q_OBJECT
00037 protected:
00042         class BLOKKAL_EXPORT TreeItemNode {
00043         public:
00052                 TreeItemNode( TreeItemNode * parent, void * data );
00053 
00058                 ~TreeItemNode( void );
00059 
00061                 TreeItemNode * const parent;
00062 
00064                 QList<TreeItemNode*> children;
00065 
00067                 QVariant data;
00068 
00070                 Qt::CheckState checked;
00071         };
00072 
00073 public:
00079         TreeModel( Blokkal::TreeModel::TreeItemNode * root = 0, QObject * parent = 0 );
00080         ~TreeModel( void );
00081 
00082         virtual QModelIndex index( int row,
00083                                    int column,
00084                                    const QModelIndex & parent = QModelIndex() ) const;
00085         virtual QModelIndex parent( const QModelIndex & child ) const;
00086         virtual int rowCount( const QModelIndex & parent = QModelIndex() ) const;
00087         virtual int columnCount( const QModelIndex & parent = QModelIndex() ) const;
00088         virtual QVariant data( const QModelIndex & index,
00089                                int role = Qt::DisplayRole) const;
00090         
00091         virtual Qt::ItemFlags flags( const QModelIndex & index ) const;
00092         virtual bool setData( const QModelIndex & index,
00093                               const QVariant & value,
00094                               int role = Qt::EditRole );
00095 
00096 protected:
00097         TreeItemNode * root( void ) const;
00098 
00099 private:
00100         class Private;
00101         Private * const d;
00102 };
00103 
00104 }
00105 
00106 #endif