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 #ifndef SHOPPINGTREEMODEL_H
\r
23 #define SHOPPINGTREEMODEL_H
\r
25 #include <QAbstractItemModel>
\r
26 #include <QDomDocument>
\r
27 #include <QModelIndex>
\r
32 class ShoppingTreeItem;
\r
34 class ShoppingTreeModel : public QAbstractItemModel
\r
39 ShoppingTreeModel(const QString &xmlFileName, QObject *parent = 0);
\r
40 ~ShoppingTreeModel();
\r
42 QVariant data(const QModelIndex &index, int role) const;
\r
43 QVariant headerData(int section, Qt::Orientation orientation,
\r
44 int role = Qt::DisplayRole) const;
\r
45 QModelIndex index(int row, int column,
\r
46 const QModelIndex &parent = QModelIndex()) const;
\r
47 QModelIndex parent(const QModelIndex &index) const;
\r
49 int rowCount(const QModelIndex &parent = QModelIndex()) const;
\r
50 int columnCount(const QModelIndex &parent = QModelIndex()) const;
\r
52 Qt::ItemFlags flags(const QModelIndex &index) const;
\r
53 bool setData(const QModelIndex &index, const QVariant &value,
\r
54 int role = Qt::EditRole);
\r
55 bool setHeaderData(int section, Qt::Orientation orientation,
\r
56 const QVariant &value, int role = Qt::EditRole);
\r
58 bool insertColumns(int position, int columns,
\r
59 const QModelIndex &parent = QModelIndex());
\r
60 bool removeColumns(int position, int columns,
\r
61 const QModelIndex &parent = QModelIndex());
\r
62 bool insertRows(int position, int rows,
\r
63 const QModelIndex &parent = QModelIndex());
\r
64 bool removeRows(int position, int rows,
\r
65 const QModelIndex &parent = QModelIndex());
\r
68 void xmlParseError(QString error, int line, int column);
\r
69 void invalidDocument();
\r
72 void registerInsertedChild(ShoppingTreeItem *item);
\r
73 void deleteRemovedChild(ShoppingTreeItem *item);
\r
76 void parseCategoryElement(const QDomElement &element,
\r
77 ShoppingTreeItem *parentItem = 0);
\r
78 QVector<QVariant> getColumnsFromItemElement(const QDomElement &element);
\r
79 bool updateDomElement(ShoppingTreeItem *item, int column);
\r
80 void updateXmlFile() const;
\r
83 ShoppingTreeItem *getItem(const QModelIndex &index) const;
\r
85 ShoppingTreeItem *rootItem;
\r
86 QString m_xmlFileName;
\r
87 QDomDocument m_document;
\r
88 QHash<ShoppingTreeItem *, QDomElement> m_domElementForItem;
\r
91 #endif // SHOPPINGTREEMODEL_H
\r