/*
 *  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_MODEL_H
#define TREE_MODEL_H

#include <QAbstractItemModel>
#include <QModelIndex>
#include <QVariant>

class TreeItem;

class TreeModel: public QAbstractItemModel
{
	Q_OBJECT;
	
public:
	TreeModel(QObject *parent = 0);
	~TreeModel();
	
	QVariant data(const QModelIndex &index, int role) const;
	Qt::ItemFlags flags(const QModelIndex &index) const;
	QVariant headerData(int section, Qt::Orientation orientation,
		int role = Qt::DisplayRole) const;
	
	QModelIndex index(int row, int column, const QModelIndex &parent = 
		QModelIndex()) const;
	QModelIndex parent(const QModelIndex &index) const;
	
	int rowCount(const QModelIndex &parent = QModelIndex()) const;
	int columnCount(const QModelIndex &parent = QModelIndex()) const;
	
public slots:
	int refresh();
	
/*	void setActive(const QModelIndex &index, const QModelIndex &prev);*/
	void setActive(const QModelIndex &index);
	void repaintItemData(TreeItem *item);
	
	void appendChild(TreeItem *parent, TreeItem *child);
	void insertChild(TreeItem *parent, int idx, TreeItem *child);
	void deleteChild(TreeItem *parent, int idx);
	void deleteAllChilds(TreeItem *parent);
	void execContextMenu(const QModelIndex &index);
	
signals:
	void pageActivated(QWidget *page);
	void pageDeleted(QWidget *page);
	
private:
	QModelIndex toModelIndex(TreeItem *item);
	
private:
	TreeItem *mRootItem;
};

#endif
