git-svn-id: file:///svnroot/family-shop-mgr@35 26eb2498-383b-47a6-be48-5d6f36779e85
[family-shop-mgr] / code / family-shop-mgr / GUI / ListManagerView.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/17/2009\r
19  *\r
20  */\r
21 \r
22 #include "ListManagerView.h"\r
23 \r
24 #include "ShoppingTreeModel.h"\r
25 \r
26 /*******************************************************************/\r
27 ListManagerView::ListManagerView(QString xmlFileName, QWidget *parent)\r
28     :QTreeView(parent)\r
29 {\r
30     ShoppingTreeModel *model = new ShoppingTreeModel(xmlFileName, this);\r
31     this->setModel(model);\r
32     this->setAnimated(true);\r
33     this->setAutoExpandDelay(1);\r
34     this->setAutoScroll(true);\r
35     this->setExpandsOnDoubleClick(true);\r
36     this->setSortingEnabled(true);\r
37     for(int column = 0; column < model->columnCount(); column++)\r
38         this->resizeColumnToContents(column);\r
39 }\r
40 \r
41 /*******************************************************************/\r
42 ListManagerView::~ListManagerView()\r
43 {\r
44 }\r
45 \r
46 /*******************************************************************/\r
47 void ListManagerView::updateActions()\r
48 {\r
49     /*\r
50     bool hasSelection = !this->selectionModel()->selection().isEmpty();\r
51     removeRowAction->setEnabled(hasSelection);\r
52     removeColumnAction->setEnabled(hasSelection);\r
53 \r
54     bool hasCurrent = this->selectionModel()->currentIndex().isValid();\r
55     insertRowAction->setEnabled(hasCurrent);\r
56     insertColumnAction->setEnabled(hasCurrent);\r
57 \r
58     if (hasCurrent)\r
59     {\r
60         this->closePersistentEditor(view->selectionModel()->currentIndex());\r
61 \r
62         int row = this->selectionModel()->currentIndex().row();\r
63         int column = this->selectionModel()->currentIndex().column();\r
64         if (this->selectionModel()->currentIndex().parent().isValid())\r
65             statusBar()->showMessage(tr("Position: (%1,%2)").arg(row).arg(column));\r
66         else\r
67             statusBar()->showMessage(tr("Position: (%1,%2) in top level").arg(row).arg(column));\r
68     }\r
69     */\r
70 }\r
71 \r
72 bool ListManagerView::addCategory(QString name)\r
73 {\r
74     return ((ShoppingTreeModel*) this->model())->addCategory(this->selectedIndexes().last(), name);\r
75 }\r
76 \r
77 bool ListManagerView::addItem(QString name)\r
78 {\r
79     return ((ShoppingTreeModel*) this->model())->addItem(this->selectedIndexes().last(), name);\r
80 }\r