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 /*******************************************************************/
\r
25 ShoppingTreeItem::ShoppingTreeItem(const QVector<QVariant> &data,
\r
26 ShoppingTreeItem *parent) : m_itemType(NotDefined)
\r
28 parentItem = parent;
\r
32 /*******************************************************************/
\r
33 ShoppingTreeItem::~ShoppingTreeItem()
\r
35 qDeleteAll(childItems);
\r
38 /*******************************************************************/
\r
39 ShoppingTreeItem *ShoppingTreeItem::child(int number)
\r
41 return childItems.value(number);
\r
44 /*******************************************************************/
\r
45 int ShoppingTreeItem::childCount() const
\r
47 return childItems.count();
\r
50 /*******************************************************************/
\r
51 int ShoppingTreeItem::childNumber() const
\r
54 return parentItem->childItems.indexOf(const_cast<ShoppingTreeItem*>(this));
\r
59 /*******************************************************************/
\r
60 int ShoppingTreeItem::columnCount() const
\r
62 return itemData.count();
\r
65 /*******************************************************************/
\r
66 QVariant ShoppingTreeItem::data(int column) const
\r
68 return itemData.value(column);
\r
71 /*******************************************************************/
\r
72 bool ShoppingTreeItem::insertChildren(int position, int count, int columns)
\r
74 if (position < 0 || position > childItems.size())
\r
77 for (int row = 0; row < count; ++row) {
\r
78 QVector<QVariant> data(columns);
\r
79 ShoppingTreeItem *item = new ShoppingTreeItem(data, this);
\r
80 childItems.insert(position, item);
\r
81 emit childInserted(item);
\r
87 /*******************************************************************/
\r
88 bool ShoppingTreeItem::insertColumns(int position, int columns)
\r
90 if (position < 0 || position > itemData.size())
\r
93 for (int column = 0; column < columns; ++column)
\r
94 itemData.insert(position, QVariant());
\r
96 foreach (ShoppingTreeItem *child, childItems)
\r
97 child->insertColumns(position, columns);
\r
102 /*******************************************************************/
\r
103 ShoppingTreeItem *ShoppingTreeItem::parent()
\r
108 /*******************************************************************/
\r
109 bool ShoppingTreeItem::removeChildren(int position, int count)
\r
111 if (position < 0 || position + count > childItems.size())
\r
114 for (int row = 0; row < count; ++row)
\r
116 ShoppingTreeItem *item = childItems.takeAt(position);
\r
117 emit childRemoved(item);
\r
124 /*******************************************************************/
\r
125 bool ShoppingTreeItem::removeColumns(int position, int columns)
\r
127 if (position < 0 || position + columns > itemData.size())
\r
130 for (int column = 0; column < columns; ++column)
\r
131 itemData.remove(position);
\r
133 foreach (ShoppingTreeItem *child, childItems)
\r
134 child->removeColumns(position, columns);
\r
139 /*******************************************************************/
\r
140 bool ShoppingTreeItem::setData(int column, const QVariant &value)
\r
142 if (column < 0 || column >= itemData.size())
\r
145 if(m_itemType == Category && column != 0)
\r
148 itemData[column] = value;
\r
149 emit dataChanged(column);
\r
153 /*******************************************************************/
\r
154 bool ShoppingTreeItem::setItemType(ItemType type)
\r
156 if(type == NotDefined)
\r
161 // release enough resources in case we call wait more than once
\r
162 m_typeSemaphore.release(1000);
\r
164 return (m_itemType == type) ? true : false;
\r
167 /*******************************************************************/
\r
168 ShoppingTreeItem::ItemType ShoppingTreeItem::getItemType() const
\r
173 /*******************************************************************/
\r
174 void ShoppingTreeItem::waitItemTypeDefinition()
\r
176 m_typeSemaphore.acquire();
\r