git-svn-id: file:///svnroot/family-shop-mgr@8 26eb2498-383b-47a6-be48-5d6f36779e85
[family-shop-mgr] / code / family-shop-mgr / ShoppingTreeModel.h
1 /*\r
2  * This file is part of family-shop-mgr.\r
3  *\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
8  *\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
13  *\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
16  *\r
17  * Author: Unai IRIGOYEN\r
18  * Date: 12/07/2009\r
19  *\r
20  */\r
21 \r
22 #ifndef SHOPPINGTREEMODEL_H\r
23 #define SHOPPINGTREEMODEL_H\r
24 \r
25 #include <QAbstractItemModel>\r
26 #include <QDomDocument>\r
27 #include <QModelIndex>\r
28 #include <QVariant>\r
29 \r
30 class ShoppingTreeItem;\r
31 \r
32 class ShoppingTreeModel : public QAbstractItemModel\r
33 {\r
34 Q_OBJECT\r
35 \r
36 public:\r
37     ShoppingTreeModel(const QString &xmlFileName, QObject *parent = 0);\r
38     ~ShoppingTreeModel();\r
39 \r
40     QVariant data(const QModelIndex &index, int role) const;\r
41     QVariant headerData(int section, Qt::Orientation orientation,\r
42                         int role = Qt::DisplayRole) const;\r
43     QModelIndex index(int row, int column,\r
44                       const QModelIndex &parent = QModelIndex()) const;\r
45     QModelIndex parent(const QModelIndex &index) const;\r
46 \r
47     int rowCount(const QModelIndex &parent = QModelIndex()) const;\r
48     int columnCount(const QModelIndex &parent = QModelIndex()) const;\r
49 \r
50     Qt::ItemFlags flags(const QModelIndex &index) const;\r
51     bool setData(const QModelIndex &index, const QVariant &value,\r
52                  int role = Qt::EditRole);\r
53     bool setHeaderData(int section, Qt::Orientation orientation,\r
54                        const QVariant &value, int role = Qt::EditRole);\r
55 \r
56     bool insertColumns(int position, int columns,\r
57                        const QModelIndex &parent = QModelIndex());\r
58     bool removeColumns(int position, int columns,\r
59                        const QModelIndex &parent = QModelIndex());\r
60     bool insertRows(int position, int rows,\r
61                     const QModelIndex &parent = QModelIndex());\r
62     bool removeRows(int position, int rows,\r
63                     const QModelIndex &parent = QModelIndex());\r
64 \r
65 signals:\r
66     void xmlParseError(QString error, int line, int column);\r
67     void invalidDocument();\r
68 \r
69 protected:\r
70     void parseCategoryElement(const QDomElement &element,\r
71                               ShoppingTreeItem *parentItem = 0);\r
72     QVector<QVariant> getColumnsFromItemElement(const QDomElement &element) const;\r
73 \r
74 private:\r
75     ShoppingTreeItem *getItem(const QModelIndex &index) const;\r
76 \r
77     ShoppingTreeItem *rootItem;\r
78     QDomDocument m_document;\r
79     QHash<ShoppingTreeItem *, QDomElement> m_domElementForItem;\r
80 };\r
81 \r
82 #endif // SHOPPINGTREEMODEL_H\r