/*
 *  Copyright (C) 2007-2008 CMM Sigma Andrzej Chmielowiec <cmmsigma@cmmsigma.eu>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 3
 *  as published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 */

#ifndef TREE_ITEM_H
#define TREE_ITEM_H

#include <QtGui>
#include <QList>
#include <QVariant>

#include "TreeModel.h"

class TreeItem: public QObject
{
	Q_OBJECT;
	
public:
	TreeItem(TreeItem *parent = 0);
	TreeItem(const QMap<int, QVariant> &roles, TreeItem *parent = 0);
	~TreeItem();
	
	TreeItem *parent();
	void setParent(TreeItem *parent);
	
	TreeItem *child(int idx);
	TreeItem *childTakeAt(int idx);
	void appendChild(TreeItem *item);
	void insertChild(int idx, TreeItem *item);
	int childCount() const;
	
	int row() const;
	int rowCount() const;
	int columnCount() const;
	
	QVariant data(int role) const;
	void setData(QVariant &value, int role);
	
	QWidget *page();
	void setPage(QWidget *page);
	
	TreeModel *model();
	void setModel(TreeModel *model);
	virtual void displayContextMenu(const QModelIndex &index);
	
public slots:
	virtual void refresh();
	
private:
	TreeModel *mModel;
	TreeItem *mParent;
	QList<TreeItem*> mChilds;
	QMap<int, QVariant> mData;
	QWidget *mPage;
};

#endif
