git-svn-id: file:///svnroot/family-shop-mgr@4 26eb2498-383b-47a6-be48-5d6f36779e85
[family-shop-mgr] / code / family-shop-mgr / ShoppingTreeModel.cpp
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 #include "ShoppingTreeModel.h"\r
23 \r
24 #include "ShoppingTreeItem.h"\r
25 #include <QFile>\r
26 \r
27 ShoppingTreeModel::ShoppingTreeModel(const QString &xmlFileName, QObject *parent) : QAbstractItemModel(parent), m_document("ShoppingList")\r
28 {\r
29     QFile file(xmlFileName);\r
30     if(!file.open(QIODevice::ReadOnly))\r
31         return;\r
32     if(!m_document.setContent(&file))\r
33     {\r
34         file.close(();\r
35         return;\r
36     }\r
37     file.close();\r
38     QVector<QVariant> rootData;\r
39     foreach (QString header, headers)\r
40         rootData << header;\r
41 \r
42     rootItem = new TreeItem(rootData);\r
43     setupModelData(data.split(QString("\n")), rootItem);\r
44 }\r