cb283b023257fe18d80842bbd8b35b209fe0ad1b
[family-shop-mgr] / code / family-shop-mgr / model / 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 enum ItemType{\r
33     item,\r
34     category\r
35 };\r
36 \r
37 class ShoppingTreeModel : public QAbstractItemModel\r
38 {\r
39     Q_OBJECT\r
40 \r
41 public:\r
42     ShoppingTreeModel(QString fileName, QObject *parent = 0);\r
43     ~ShoppingTreeModel();\r
44 \r
45     QVariant data(const QModelIndex &index, int role) const;\r
46     Qt::ItemFlags flags(const QModelIndex &index) const;\r
47     QVariant headerData(int section, Qt::Orientation orientation,\r
48                         int role = Qt::DisplayRole) const;\r
49     QModelIndex index(int row, int column,\r
50                       const QModelIndex &parent = QModelIndex()) const;\r
51     QModelIndex parent(const QModelIndex &child) const;\r
52     int rowCount(const QModelIndex &parent = QModelIndex()) const;\r
53     int columnCount(const QModelIndex &parent = QModelIndex()) const;\r
54     bool insertRows(int row, int count,\r
55                     const QModelIndex & parent = QModelIndex(),\r
56                     ItemType type = item);\r
57     bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());\r
58 \r
59 public slots:\r
60     void addCategory(QModelIndex & index);\r
61     void addItem(QModelIndex & index);\r
62     void removeElement(QModelIndex & index);\r
63     void save();\r
64 \r
65 signals:\r
66     void documentChanged();\r
67 \r
68 private:\r
69     QString m_fileName;\r
70     QDomDocument domDocument;\r
71     QDomNode rootItemNode;\r
72     ShoppingTreeItem *rootItem;\r
73 };\r
74 \r
75 #endif // SHOPPINGTREEMODEL_H\r