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
24 #include "ShoppingTreeItem.h"
\r
27 ShoppingTreeItem::ShoppingTreeItem(QDomNode &node, ShoppingTreeItem *parent)
\r
30 parentItem = parent;
\r
33 /*******************************************************************/
\r
34 ShoppingTreeItem::~ShoppingTreeItem()
\r
36 QHash<int,ShoppingTreeItem*>::iterator it;
\r
37 for (it = childItems.begin(); it != childItems.end(); ++it)
\r
41 /*******************************************************************/
\r
42 QDomNode ShoppingTreeItem::node() const
\r
47 /*******************************************************************/
\r
48 ShoppingTreeItem *ShoppingTreeItem::parent()
\r
53 /*******************************************************************/
\r
54 ShoppingTreeItem *ShoppingTreeItem::child(int i)
\r
56 if (childItems.contains(i))
\r
57 return childItems[i];
\r
59 QDomNodeList childNodesList = domNode.childNodes();
\r
60 QList<QDomNode> childElementsList;
\r
62 for(int j = 0; !(childNode = childNodesList.at(j)).isNull(); j++)
\r
64 if(childNode.isElement())
\r
66 if(childNode.toElement().nodeName() == "category" ||
\r
67 childNode.toElement().nodeName() == "item")
\r
68 childElementsList.append(childNode);
\r
71 if (i >= 0 && i < childElementsList.count()) {
\r
72 childNode = childElementsList.at(i);
\r
73 ShoppingTreeItem *childItem = new ShoppingTreeItem(childNode, this);
\r
74 childItems[i] = childItem;
\r
80 /*******************************************************************/
\r
81 int ShoppingTreeItem::row()
\r
83 return parent()->childItems.key(this);
\r
86 /*******************************************************************/
\r
87 bool ShoppingTreeItem::addChild(ShoppingTreeItem *item, int row)
\r
89 offsetChildAtAdd(row);
\r
90 childItems.insert(row, item);
\r
94 /*******************************************************************/
\r
95 bool ShoppingTreeItem::removeChild(int row)
\r
97 delete childItems[row];
\r
98 childItems.remove(row);
\r
99 offsetChildAtRemove(row);
\r
103 /*******************************************************************/
\r
104 void ShoppingTreeItem::offsetChildAtAdd(int row)
\r
106 if(childItems.contains(row))
\r
108 offsetChildAtAdd(row + 1);
\r
109 childItems.insert(row + 1, childItems[row]);
\r
113 /*******************************************************************/
\r
114 void ShoppingTreeItem::offsetChildAtRemove(int row)
\r
116 if(childItems.contains(row + 1))
\r
118 childItems.insert(row, childItems[row + 1]);
\r
119 offsetChildAtRemove(row + 1);
\r