/*
 *  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.
 */

#include "TreeItem.h"

TreeItem::TreeItem(TreeItem *parent)
{
	mModel = 0;
	mParent = parent;
	mPage = 0;
}

TreeItem::TreeItem(const QMap<int, QVariant> &roles, TreeItem *parent)
{
	mModel = 0;
	mParent = parent;
	mData = roles;
	mPage = 0;
}

TreeItem::~TreeItem()
{
	mModel->deleteAllChilds(this);
}

TreeItem*
TreeItem::parent()
{
	return mParent;
}

void
TreeItem::setParent(TreeItem *parent)
{
	mParent = parent;
}

TreeItem*
TreeItem::child(int idx)
{
	return mChilds.value(idx);
}

TreeItem*
TreeItem::childTakeAt(int idx)
{
	return mChilds.takeAt(idx);
}

void
TreeItem::appendChild(TreeItem *item)
{
	item->setModel(mModel);
	item->mParent = this;
	mChilds.append(item);
}

void
TreeItem::insertChild(int idx, TreeItem *item)
{
	item->mModel = mModel;
	item->mParent = this;
	mChilds.insert(idx, item);
}

int
TreeItem::childCount() const
{
	return mChilds.count();
}

int
TreeItem::row() const
{
	if (mParent)
		return mParent->mChilds.indexOf(const_cast<TreeItem*>(this));
	
	return 0;
}

int
TreeItem::rowCount() const
{
	return mChilds.count();
}

int
TreeItem::columnCount() const
{
	return 1;
}

QVariant
TreeItem::data(int role) const
{
	return mData.value(role);
}

void
TreeItem::setData(QVariant &value, int role)
{
	mData.insert(role, value);
}

QWidget*
TreeItem::page()
{
	return mPage;
}

void
TreeItem::setPage(QWidget *page)
{
	mPage = page;
}

TreeModel*
TreeItem::model()
{
	return mModel;
}

void
TreeItem::setModel(TreeModel *model)
{
	mModel = model;
}

void
TreeItem::refresh()
{
}

void
TreeItem::displayContextMenu(const QModelIndex &index)
{
}
