summaryrefslogtreecommitdiffstats
path: root/smtreeitem.cpp
blob: 43998c375a181b08e98ce7652ff6e9b3d79c03a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
  as published by the Free Software Foundation; either version
  2 of the License, or (at your option) any later version.
*/

#include "smtreeitem.h"

SmTreeItem::SmTreeItem(const QList<QVariant> &data, SmTreeItem *parent) : mData(data), mParent(parent) {}

SmTreeItem::SmTreeItem(int rows, SmTreeItem *parent) : mParent(parent){
	for(int i = 0; i < rows; ++i){
		mData << QVariant();
	}
}

SmTreeItem::~SmTreeItem(){
	qDeleteAll(mChildren);
}

void SmTreeItem::appendChild(SmTreeItem *child){
	mChildren.append(child);
}

SmTreeItem *SmTreeItem::child(int row){
	return mChildren.at(row);
}

int SmTreeItem::childCount() const{
	return mChildren.count();
}

int SmTreeItem::columnCount() const{
	return mData.count();
}

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

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

QVariant SmTreeItem::data(int column) const{
	return mData.at(column);
}

void SmTreeItem::setData(int column, QVariant &data){
	mData[column] = data;
}

bool SmTreeItem::insertChild(int where, SmTreeItem *child){
	if((where < 0) || (where > mChildren.count())){
		return false;
	}
	mChildren.insert(where, child);
	return true;
}

bool SmTreeItem::removeChild(int where){
	if((where < 0) || (where >= mChildren.count())){
		return false;
	}
	delete mChildren.takeAt(where);
	return true;
}