2 * This file is part of family-shop-mgr.
\r
4 * family-shop-mgr is free software: you can redistribute it and/or modify
\r
5 * it under the terms of the GNU General Public License as published by
\r
6 * the Free Software Foundation, either version 3 of the License, or
\r
7 * (at your option) any later version.
\r
9 * family-shop-mgr is distributed in the hope that it will be useful,
\r
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
12 * GNU General Public License for more details.
\r
14 * You should have received a copy of the GNU General Public License
\r
15 * along with family-shop-mgr. If not, see <http://www.gnu.org/licenses/>.
\r
17 * Author: Unai IRIGOYEN
\r
22 #include "ShoppingTreeItem.h"
\r
24 ShoppingTreeItem::ShoppingTreeItem(const QVector<QVariant> &data, ShoppingTreeItem *parent)
\r
26 parentItem = parent;
\r
30 ShoppingTreeItem::~ShoppingTreeItem()
\r
32 qDeleteAll(childItems);
\r
35 ShoppingTreeItem *ShoppingTreeItem::child(int number)
\r
37 return childItems.value(number);
\r
40 int ShoppingTreeItem::childCount() const
\r
42 return childItems.count();
\r
45 int ShoppingTreeItem::childNumber() const
\r
48 return parentItem->childItems.indexOf(const_cast<ShoppingTreeItem*>(this));
\r
53 int ShoppingTreeItem::columnCount() const
\r
55 return itemData.count();
\r
58 QVariant ShoppingTreeItem::data(int column) const
\r
60 return itemData.value(column);
\r
63 bool ShoppingTreeItem::insertChildren(int position, int count, int columns)
\r
65 if (position < 0 || position > childItems.size())
\r
68 for (int row = 0; row < count; ++row) {
\r
69 QVector<QVariant> data(columns);
\r
70 ShoppingTreeItem *item = new ShoppingTreeItem(data, this);
\r
71 childItems.insert(position, item);
\r
77 bool ShoppingTreeItem::insertColumns(int position, int columns)
\r
79 if (position < 0 || position > itemData.size())
\r
82 for (int column = 0; column < columns; ++column)
\r
83 itemData.insert(position, QVariant());
\r
85 foreach (ShoppingTreeItem *child, childItems)
\r
86 child->insertColumns(position, columns);
\r
91 ShoppingTreeItem *ShoppingTreeItem::parent()
\r
96 bool ShoppingTreeItem::removeChildren(int position, int count)
\r
98 if (position < 0 || position + count > childItems.size())
\r
101 for (int row = 0; row < count; ++row)
\r
102 delete childItems.takeAt(position);
\r
107 bool ShoppingTreeItem::removeColumns(int position, int columns)
\r
109 if (position < 0 || position + columns > itemData.size())
\r
112 for (int column = 0; column < columns; ++column)
\r
113 itemData.remove(position);
\r
115 foreach (ShoppingTreeItem *child, childItems)
\r
116 child->removeColumns(position, columns);
\r
121 bool ShoppingTreeItem::setData(int column, const QVariant &value)
\r
123 if (column < 0 || column >= itemData.size())
\r
126 itemData[column] = value;
\r