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,
\r
25 ShoppingTreeItem *parent) : m_itemType(NotDefined)
\r
27 parentItem = parent;
\r
31 ShoppingTreeItem::~ShoppingTreeItem()
\r
33 qDeleteAll(childItems);
\r
36 ShoppingTreeItem *ShoppingTreeItem::child(int number)
\r
38 return childItems.value(number);
\r
41 int ShoppingTreeItem::childCount() const
\r
43 return childItems.count();
\r
46 int ShoppingTreeItem::childNumber() const
\r
49 return parentItem->childItems.indexOf(const_cast<ShoppingTreeItem*>(this));
\r
54 int ShoppingTreeItem::columnCount() const
\r
56 return itemData.count();
\r
59 QVariant ShoppingTreeItem::data(int column) const
\r
61 return itemData.value(column);
\r
64 bool ShoppingTreeItem::insertChildren(int position, int count, int columns)
\r
66 if (position < 0 || position > childItems.size())
\r
69 for (int row = 0; row < count; ++row) {
\r
70 QVector<QVariant> data(columns);
\r
71 ShoppingTreeItem *item = new ShoppingTreeItem(data, this);
\r
72 childItems.insert(position, item);
\r
73 emit childInserted(item);
\r
79 bool ShoppingTreeItem::insertColumns(int position, int columns)
\r
81 if (position < 0 || position > itemData.size())
\r
84 for (int column = 0; column < columns; ++column)
\r
85 itemData.insert(position, QVariant());
\r
87 foreach (ShoppingTreeItem *child, childItems)
\r
88 child->insertColumns(position, columns);
\r
93 ShoppingTreeItem *ShoppingTreeItem::parent()
\r
98 bool ShoppingTreeItem::removeChildren(int position, int count)
\r
100 if (position < 0 || position + count > childItems.size())
\r
103 for (int row = 0; row < count; ++row)
\r
105 ShoppingTreeItem *item = childItems.takeAt(position);
\r
106 emit childRemoved(item);
\r
113 bool ShoppingTreeItem::removeColumns(int position, int columns)
\r
115 if (position < 0 || position + columns > itemData.size())
\r
118 for (int column = 0; column < columns; ++column)
\r
119 itemData.remove(position);
\r
121 foreach (ShoppingTreeItem *child, childItems)
\r
122 child->removeColumns(position, columns);
\r
127 bool ShoppingTreeItem::setData(int column, const QVariant &value)
\r
129 if (column < 0 || column >= itemData.size())
\r
132 if(m_itemType == Category && column != 0)
\r
135 itemData[column] = value;
\r
136 emit dataChanged(column);
\r
140 bool ShoppingTreeItem::setItemType(ItemType type)
\r
142 if(type == NotDefined)
\r
147 // release enough resources in case we call wait more than once
\r
148 m_typeSemaphore.release(1000);
\r
150 return (m_itemType == type) ? true : false;
\r
153 ShoppingTreeItem::ItemType ShoppingTreeItem::getItemType() const
\r
158 void ShoppingTreeItem::waitItemTypeDefinition()
\r
160 m_typeSemaphore.acquire();
\r