git-svn-id: file:///svnroot/family-shop-mgr@35 26eb2498-383b-47a6-be48-5d6f36779e85
[family-shop-mgr] / code / family-shop-mgr / GUI / ListManagerView.cpp
diff --git a/code/family-shop-mgr/GUI/ListManagerView.cpp b/code/family-shop-mgr/GUI/ListManagerView.cpp
new file mode 100644 (file)
index 0000000..8dfe6ec
--- /dev/null
@@ -0,0 +1,80 @@
+/*\r
+ * This file is part of family-shop-mgr.\r
+ *\r
+ * family-shop-mgr is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * family-shop-mgr is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with family-shop-mgr.  If not, see <http://www.gnu.org/licenses/>.\r
+ *\r
+ * Author: Unai IRIGOYEN\r
+ * Date: 12/17/2009\r
+ *\r
+ */\r
+\r
+#include "ListManagerView.h"\r
+\r
+#include "ShoppingTreeModel.h"\r
+\r
+/*******************************************************************/\r
+ListManagerView::ListManagerView(QString xmlFileName, QWidget *parent)\r
+    :QTreeView(parent)\r
+{\r
+    ShoppingTreeModel *model = new ShoppingTreeModel(xmlFileName, this);\r
+    this->setModel(model);\r
+    this->setAnimated(true);\r
+    this->setAutoExpandDelay(1);\r
+    this->setAutoScroll(true);\r
+    this->setExpandsOnDoubleClick(true);\r
+    this->setSortingEnabled(true);\r
+    for(int column = 0; column < model->columnCount(); column++)\r
+        this->resizeColumnToContents(column);\r
+}\r
+\r
+/*******************************************************************/\r
+ListManagerView::~ListManagerView()\r
+{\r
+}\r
+\r
+/*******************************************************************/\r
+void ListManagerView::updateActions()\r
+{\r
+    /*\r
+    bool hasSelection = !this->selectionModel()->selection().isEmpty();\r
+    removeRowAction->setEnabled(hasSelection);\r
+    removeColumnAction->setEnabled(hasSelection);\r
+\r
+    bool hasCurrent = this->selectionModel()->currentIndex().isValid();\r
+    insertRowAction->setEnabled(hasCurrent);\r
+    insertColumnAction->setEnabled(hasCurrent);\r
+\r
+    if (hasCurrent)\r
+    {\r
+        this->closePersistentEditor(view->selectionModel()->currentIndex());\r
+\r
+        int row = this->selectionModel()->currentIndex().row();\r
+        int column = this->selectionModel()->currentIndex().column();\r
+        if (this->selectionModel()->currentIndex().parent().isValid())\r
+            statusBar()->showMessage(tr("Position: (%1,%2)").arg(row).arg(column));\r
+        else\r
+            statusBar()->showMessage(tr("Position: (%1,%2) in top level").arg(row).arg(column));\r
+    }\r
+    */\r
+}\r
+\r
+bool ListManagerView::addCategory(QString name)\r
+{\r
+    return ((ShoppingTreeModel*) this->model())->addCategory(this->selectedIndexes().last(), name);\r
+}\r
+\r
+bool ListManagerView::addItem(QString name)\r
+{\r
+    return ((ShoppingTreeModel*) this->model())->addItem(this->selectedIndexes().last(), name);\r
+}\r