+++ /dev/null
-/*
- * This file is part of family-shop-mgr.
- *
- * family-shop-mgr is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * family-shop-mgr is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with family-shop-mgr. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Unai IRIGOYEN
- * Date: 12/07/2009
- *
- */
-
-#include "FamilyShoppingManagerMainWindow.h"
-#include <QMenuBar>
-#include <QMessageBox>
-#include <QInputDialog>
-
-#include "ListManagerView.h"
-#include "GoShoppingView.h"
-#include "ShoppingTreeModel.h"
-
-/*******************************************************************/
-FamilyShoppingManagerMainWindow::FamilyShoppingManagerMainWindow(QWidget *parent)
- : QMainWindow(parent), activityView(NULL), //editMenu(NULL),
- showCheckedItemsAction(NULL), goShoppingAction(NULL), endShoppingAction(NULL)
-{
- aboutAction = new QAction(tr("&About"), this);
- aboutAction->setSoftKeyRole(QAction::PositiveSoftKey);
- connect(aboutAction, SIGNAL(triggered()), this, SLOT(showAbout()));
- menuBar()->addAction(aboutAction);
-
-
- showListManager();
-}
-
-/*******************************************************************/
-FamilyShoppingManagerMainWindow::~FamilyShoppingManagerMainWindow()
-{
- delete activityView;
-}
-
-/*******************************************************************/
-void FamilyShoppingManagerMainWindow::showListManager()
-{
- menuBar()->clear();
-
- delete showCheckedItemsAction;
- delete endShoppingAction;
-
- delete activityView;
- activityView = new ListManagerView("ShoppingList.xml", this);
-
- addCategoryAction = new QAction(tr("Add category"), this);
- addCategoryAction->setSoftKeyRole(QAction::PositiveSoftKey);
- connect(addCategoryAction, SIGNAL(triggered()),
- this, SLOT(addCategory()));
- menuBar()->addAction(addCategoryAction);
- removeCategoryAction = new QAction(tr("Remove category"), this);
- removeCategoryAction->setSoftKeyRole(QAction::NegativeSoftKey);
- connect(removeCategoryAction, SIGNAL(triggered()),
- this, SLOT(removeCategoryOrItem()));
- menuBar()->addAction(removeCategoryAction);
- addItemAction = new QAction(tr("Add item"), this);
- addItemAction->setSoftKeyRole(QAction::PositiveSoftKey);
- connect(addItemAction, SIGNAL(triggered()),
- this, SLOT(addItem()));
- menuBar()->addAction(addItemAction);
- removeItemAction = new QAction(tr("Remove item"), this);
- removeItemAction->setSoftKeyRole(QAction::NegativeSoftKey);
- connect(removeItemAction, SIGNAL(triggered()),
- this, SLOT(removeCategoryOrItem()));
- menuBar()->addAction(removeItemAction);
-
- goShoppingAction = new QAction(tr("Go shopping!"), this);
- goShoppingAction->setSoftKeyRole(QAction::PositiveSoftKey);
- connect(goShoppingAction, SIGNAL(triggered()),
- this, SLOT(showGoShopping()));
- menuBar()->addAction(goShoppingAction);
-
- menuBar()->addAction(aboutAction);
-
- setCentralWidget(activityView);
- update();
-}
-
-/*******************************************************************/
-void FamilyShoppingManagerMainWindow::showGoShopping()
-{
- menuBar()->clear();
-
- delete addCategoryAction;
- delete addItemAction;
- delete removeCategoryAction;
- delete removeItemAction;
- delete goShoppingAction;
-
- delete activityView;
- activityView = new GoShoppingView("ShoppingList.xml", this);
- setCentralWidget(activityView);
-
- showCheckedItemsAction = new QAction(tr("&Show checked"), this);
- showCheckedItemsAction->setCheckable(true);
- showCheckedItemsAction->setSoftKeyRole(QAction::PositiveSoftKey);
- connect(showCheckedItemsAction, SIGNAL(toggled(bool)),
- activityView, SLOT(showChecked(bool)));
- menuBar()->addAction(showCheckedItemsAction);
-
- endShoppingAction = new QAction(tr("&End shopping"), this);
- endShoppingAction->setSoftKeyRole(QAction::NegativeSoftKey);
- connect(endShoppingAction, SIGNAL(triggered()),
- this, SLOT(showListManager()));
- menuBar()->addAction(endShoppingAction);
-
- menuBar()->addAction(aboutAction);
- update();
-}
-
-/*******************************************************************/
-void FamilyShoppingManagerMainWindow::showAbout()
-{
- QString text;
- text = tr("Application name:") + " Family shopping manager\n\n";
- text += tr("Project maintainer:") + "\n";
- text += "\tUnai IRIGOYEN";
- text += "\n\n";
- text += tr("Developers:") + "\n";
- text += "\tUnai IRIGOYEN";
- text += "\n\n";
- text += tr("Licence:") + " GPLv3";
- QMessageBox::about(this,tr("About"), text);
-}
-
-/*******************************************************************/
-void FamilyShoppingManagerMainWindow::addCategory()
-{
- ShoppingTreeModel *model = (ShoppingTreeModel*)
- ((ListManagerView*) activityView)->model();
-
- bool* ok = new bool(false);
- QString name = QInputDialog::getText(this, tr("Enter category name"),
- tr("Category name:"),
- QLineEdit::Normal, QString(), ok);
- if(!ok)
- return;
-
- if(model->addCategory(name))
- ((ListManagerView*) activityView)->updateActions();
- delete ok;
-}
-
-/*******************************************************************/
-void FamilyShoppingManagerMainWindow::addSubCategory()
-{
- QModelIndex index = ((ListManagerView*) activityView)->
- selectionModel()->currentIndex().parent();
- ShoppingTreeModel *model = (ShoppingTreeModel*)
- ((ListManagerView*) activityView)->model();
-
- bool* ok = new bool(false);
- QString name = QInputDialog::getText(this, tr("Enter category name"),
- tr("Category name:"),
- QLineEdit::Normal, QString(), ok);
- if(!ok)
- return;
-
- if(model->addSubCategory(name, index.row()+1, index))
- ((ListManagerView*) activityView)->updateActions();
-
- delete ok;
-}
-
-/*******************************************************************/
-void FamilyShoppingManagerMainWindow::addItem()
-{
- QModelIndex index = ((ListManagerView*) activityView)->
- selectionModel()->currentIndex().parent();
- ShoppingTreeModel *model = (ShoppingTreeModel*)
- ((ListManagerView*) activityView)->model();
-
- bool* ok = new bool(false);
- QString name = QInputDialog::getText(this, tr("Enter item name"),
- tr("Item name:"),
- QLineEdit::Normal, QString(), ok);
- if(!ok)
- return;
-
- if(model->addItem(name, index.row()+1, index))
- ((ListManagerView*) activityView)->updateActions();
-
- delete ok;
-}
-
-/*******************************************************************/
-void FamilyShoppingManagerMainWindow::removeCategoryOrItem()
-{
- QModelIndex index = ((ListManagerView*) activityView)->
- selectionModel()->currentIndex();
- ShoppingTreeModel *model = (ShoppingTreeModel*)
- ((ListManagerView*) activityView)->model();
- if (model->removeCategoryOrItem(index))
- ((ListManagerView*) activityView)->updateActions();
-}
+++ /dev/null
-/*
- * This file is part of family-shop-mgr.
- *
- * family-shop-mgr is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * family-shop-mgr is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with family-shop-mgr. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author: Unai IRIGOYEN
- * Date: 12/07/2009
- *
- */
-
-#ifndef FAMILYSHOPPINGMANAGERMAINWINDOW_H
-#define FAMILYSHOPPINGMANAGERMAINWINDOW_H
-
-#include <QMainWindow>
-#include <QModelIndex>
-
-class FamilyShoppingManagerMainWindow : public QMainWindow
-{
- Q_OBJECT
-
-public:
- FamilyShoppingManagerMainWindow(QWidget *parent = 0);
- ~FamilyShoppingManagerMainWindow();
-
-private slots:
- void showListManager();
- void showGoShopping();
- void showAbout();
-
- void addCategory();
- void addSubCategory();
- void addItem();
- void removeCategoryOrItem();
- //void insertChild();
-
-private:
- QWidget *activityView;
-
- QAction *showCheckedItemsAction;
- QAction *goShoppingAction;
- QAction *endShoppingAction;
- QAction *aboutAction;
-
- QAction *addCategoryAction;
- QAction *addSubCategoryAction();
- QAction *removeCategoryAction;
- QAction *addItemAction;
- QAction *removeItemAction;
-};
-
-#endif // FAMILYSHOPPINGMANAGERMAINWINDOW_H
+++ /dev/null
-/*\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 "GoShoppingView.h"\r
-\r
-#include "ShoppingTreeModel.h"\r
-\r
-/*******************************************************************/\r
-GoShoppingView::GoShoppingView(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
-GoShoppingView::~GoShoppingView()\r
-{\r
-}\r
+++ /dev/null
-/*\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
-#ifndef GOSHOPPINGVIEW_H\r
-#define GOSHOPPINGVIEW_H\r
-\r
-#include <QTreeView>\r
-\r
-class GoShoppingView : public QTreeView\r
-{\r
-Q_OBJECT\r
-\r
-public:\r
- GoShoppingView(QString xmlFileName, QWidget *parent = 0);\r
- ~GoShoppingView();\r
-\r
-private:\r
-};\r
-\r
-#endif // GOSHOPPINGVIEW_H\r
+++ /dev/null
-/*\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
+++ /dev/null
-/*\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
-#ifndef LISTMANAGERVIEW_H\r
-#define LISTMANAGERVIEW_H\r
-\r
-#include <QTreeView>\r
-\r
-class ListManagerView : public QTreeView\r
-{\r
-Q_OBJECT\r
-\r
-public:\r
- ListManagerView(QString xmlFileName, QWidget *parent = 0);\r
- ~ListManagerView();\r
-\r
- void updateActions();\r
-};\r
-\r
-#endif // LISTMANAGERVIEW_H\r
+++ /dev/null
-/*\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/07/2009\r
- *\r
- */\r
-\r
-#include <QtXml>\r
-\r
-#include "ShoppingTreeItem.h"\r
-\r
-\r
-ShoppingTreeItem::ShoppingTreeItem(QDomNode &node, int row, ShoppingTreeItem *parent)\r
-{\r
- domNode = node;\r
- rowNumber = row;\r
- parentItem = parent;\r
-}\r
-\r
-/*******************************************************************/\r
-ShoppingTreeItem::~ShoppingTreeItem()\r
-{\r
- QHash<int,ShoppingTreeItem*>::iterator it;\r
- for (it = childItems.begin(); it != childItems.end(); ++it)\r
- delete it.value();\r
-}\r
-\r
-/*******************************************************************/\r
-QDomNode ShoppingTreeItem::node() const\r
-{\r
- return domNode;\r
-}\r
-\r
-/*******************************************************************/\r
-ShoppingTreeItem *ShoppingTreeItem::parent()\r
-{\r
- return parentItem;\r
-}\r
-\r
-/*******************************************************************/\r
-ShoppingTreeItem *ShoppingTreeItem::child(int i)\r
-{\r
- if (childItems.contains(i))\r
- return childItems[i];\r
-\r
- QDomNodeList childNodesList = domNode.childNodes();\r
- QList<QDomNode> childElementsList;\r
- QDomNode childNode;\r
- for(int j = 0; !(childNode = childNodesList.at(j)).isNull(); j++)\r
- {\r
- if(childNode.isElement())\r
- {\r
- if(childNode.toElement().nodeName() == "category" ||\r
- childNode.toElement().nodeName() == "item")\r
- childElementsList.append(childNode);\r
- }\r
- }\r
- if (i >= 0 && i < childElementsList.count()) {\r
- childNode = childElementsList.at(i);\r
- ShoppingTreeItem *childItem = new ShoppingTreeItem(childNode, i, this);\r
- childItems[i] = childItem;\r
- return childItem;\r
- }\r
- return 0;\r
-}\r
-\r
-/*******************************************************************/\r
-int ShoppingTreeItem::row()\r
-{\r
- return rowNumber;\r
-}\r
+++ /dev/null
-/*\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/07/2009\r
- *\r
- */\r
-\r
-#ifndef SHOPPINGTREEITEM_H\r
-#define SHOPPINGTREEITEM_H\r
-\r
-#include <QDomNode>\r
-#include <QHash>\r
-\r
-class ShoppingTreeItem\r
-{\r
-public:\r
- ShoppingTreeItem(QDomNode &node, int row, ShoppingTreeItem *parent = 0);\r
- ~ShoppingTreeItem();\r
- ShoppingTreeItem *child(int i);\r
- ShoppingTreeItem *parent();\r
- QDomNode node() const;\r
- int row();\r
-\r
-private:\r
- QDomNode domNode;\r
- QHash<int,ShoppingTreeItem*> childItems;\r
- ShoppingTreeItem *parentItem;\r
- int rowNumber;\r
-};\r
-\r
-#endif // SHOPPINGTREEITEM_H\r
+++ /dev/null
-/*\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/07/2009\r
- *\r
- */\r
-\r
-#include <QtXml>\r
-\r
-#include "ShoppingTreeItem.h"\r
-#include "ShoppingTreeModel.h"\r
-\r
-ShoppingTreeModel::ShoppingTreeModel(QString fileName, QObject *parent)\r
- : QAbstractItemModel(parent),m_fileName(fileName)\r
-{\r
- connect(this, SIGNAL(documentChanged()), this, SLOT(save()));\r
- QFile file(m_fileName);\r
- if (!file.open(QIODevice::ReadOnly))\r
- return;\r
- if (!domDocument.setContent(&file)) {\r
- file.close();\r
- return;\r
- }\r
- file.close();\r
-\r
- rootItemNode = domDocument.firstChildElement("shoppingList");\r
- rootItem = new ShoppingTreeItem(rootItemNode, 0);\r
-}\r
-\r
-/*******************************************************************/\r
-ShoppingTreeModel::~ShoppingTreeModel()\r
-{\r
- delete rootItem;\r
-}\r
-\r
-/*******************************************************************/\r
-int ShoppingTreeModel::columnCount(const QModelIndex &/*parent*/) const\r
-{\r
- return 4;\r
-}\r
-\r
-/*******************************************************************/\r
-QVariant ShoppingTreeModel::data(const QModelIndex &index, int role) const\r
-{\r
- if (!index.isValid())\r
- return QVariant();\r
-\r
- if (role != Qt::DisplayRole)\r
- return QVariant();\r
-\r
- ShoppingTreeItem *item = static_cast<ShoppingTreeItem*>(index.internalPointer());\r
-\r
- QDomNode node = item->node();\r
-\r
- switch (index.column()) {\r
- case 0:\r
- return node.firstChildElement("title").text();\r
- case 1:\r
- if(node.toElement().nodeName() == "item")\r
- {\r
- return node.firstChildElement("quantity").text();\r
- }\r
- return QVariant();\r
- case 2:\r
- if(node.toElement().nodeName() == "item")\r
- {\r
- return node.firstChildElement("store").text();\r
- }\r
- return QVariant();\r
- case 3:\r
- if(node.toElement().nodeName() == "item")\r
- {\r
- return (bool) node.firstChildElement("checked").text().toInt();\r
- }\r
- return QVariant();\r
- default:\r
- return QVariant();\r
- }\r
-}\r
-\r
-/*******************************************************************/\r
-Qt::ItemFlags ShoppingTreeModel::flags(const QModelIndex &index) const\r
-{\r
- if (!index.isValid())\r
- return 0;\r
-\r
- return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;\r
-}\r
-\r
-/*******************************************************************/\r
-QVariant ShoppingTreeModel::headerData(int section, Qt::Orientation orientation,\r
- int role) const\r
-{\r
- if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {\r
- switch (section) {\r
- case 0:\r
- return tr("Category/Item name");\r
- case 1:\r
- return tr("Quantity");\r
- case 2:\r
- return tr("Store");\r
- case 3:\r
- return tr("Checked");\r
- default:\r
- return QVariant();\r
- }\r
- }\r
-\r
- return QVariant();\r
-}\r
-\r
-/*******************************************************************/\r
-QModelIndex ShoppingTreeModel::index(int row, int column, const QModelIndex &parent)\r
- const\r
-{\r
- if (!hasIndex(row, column, parent))\r
- return QModelIndex();\r
-\r
- ShoppingTreeItem *parentItem;\r
-\r
- if (!parent.isValid())\r
- parentItem = rootItem;\r
- else\r
- parentItem = static_cast<ShoppingTreeItem*>(parent.internalPointer());\r
-\r
- ShoppingTreeItem *childItem = parentItem->child(row);\r
- if (childItem)\r
- return createIndex(row, column, childItem);\r
- else\r
- return QModelIndex();\r
-}\r
-\r
-/*******************************************************************/\r
-QModelIndex ShoppingTreeModel::parent(const QModelIndex &child) const\r
-{\r
- if (!child.isValid())\r
- return QModelIndex();\r
-\r
- ShoppingTreeItem *childItem = static_cast<ShoppingTreeItem*>(child.internalPointer());\r
- ShoppingTreeItem *parentItem = childItem->parent();\r
-\r
- if (!parentItem || parentItem == rootItem)\r
- return QModelIndex();\r
-\r
- return createIndex(parentItem->row(), 0, parentItem);\r
-}\r
-\r
-/*******************************************************************/\r
-int ShoppingTreeModel::rowCount(const QModelIndex &parent) const\r
-{\r
- if (parent.column() > 0)\r
- return 0;\r
-\r
- ShoppingTreeItem *parentItem;\r
-\r
- if (!parent.isValid())\r
- parentItem = rootItem;\r
- else\r
- parentItem = static_cast<ShoppingTreeItem*>(parent.internalPointer());\r
-\r
- int childCount = 0;\r
- for(QDomElement childElement = parentItem->node().firstChildElement();\r
- !childElement.isNull(); childElement = childElement.nextSiblingElement())\r
- {\r
- if(childElement.nodeName() == "category" || childElement.nodeName() == "item")\r
- childCount++;\r
- }\r
- return childCount;\r
-}\r
-\r
-/*******************************************************************/\r
-bool ShoppingTreeModel::insertRows(int row, int count, const QModelIndex &parent, ItemType type)\r
-{\r
- ShoppingTreeItem *parentItem;\r
-\r
- if (!parent.isValid())\r
- parentItem = rootItem;\r
- else\r
- parentItem = static_cast<ShoppingTreeItem*>(parent.internalPointer());\r
-\r
- for(int i = 0; i < count; i++)\r
- {\r
- QDomElement newElement;\r
- QDomElement titleElement;\r
- titleElement.setTagName("title");\r
- if(type == category)\r
- {\r
- newElement.setTagName("category");\r
- titleElement.setNodeValue(tr("new category"));\r
- newElement.appendChild(titleElement);\r
- parentItem->node().insertAfter(newElement, parentItem->child(row + i)->node());\r
- }\r
- else if(type == item)\r
- {\r
- newElement.setTagName("item");\r
- titleElement.setNodeValue(tr("new item"));\r
- newElement.appendChild(titleElement);\r
- QDomElement quantityElement;\r
- quantityElement.setTagName("quantity");\r
- newElement.appendChild(quantityElement);\r
- QDomElement storeElement;\r
- storeElement.setTagName("store");\r
- newElement.appendChild(storeElement);\r
- QDomElement checkedElement;\r
- checkedElement.setTagName("checked");\r
- checkedElement.setNodeValue("0");\r
- newElement.appendChild(checkedElement);\r
- QDomElement lastModifiedElement;\r
- lastModifiedElement.setTagName("lastModified");\r
- lastModifiedElement.setNodeValue(QDateTime::currentDateTime().toString("dd/MM/yyyy-hh:mm:ss"));\r
- newElement.appendChild(lastModifiedElement);\r
- parentItem->node().insertAfter(newElement, parentItem->child(row + i)->node());\r
- }\r
- }\r
- emit documentChanged();\r
-}\r
-\r
-/*******************************************************************/\r
-ShoppingTreeModel::removeRows(int row, int count, const QModelIndex &parent)\r
-{\r
- ShoppingTreeItem *parentItem;\r
-\r
- if (!parent.isValid())\r
- parentItem = rootItem;\r
- else\r
- parentItem = static_cast<ShoppingTreeItem*>(parent.internalPointer());\r
-\r
- for(int i = 0; i < count; i++)\r
- {\r
- parentItem->node().removeChild(parentItem->child(i)->node());\r
- }\r
- emit documentChanged();\r
-}\r
-\r
-/*******************************************************************/\r
-ShoppingTreeModel::addCategory(QModelIndex &index)\r
-{\r
- ShoppingTreeItem *selectedItem;\r
-\r
- if (!parent.isValid())\r
- selectedItem = rootItem;\r
- else\r
- selectedItem = static_cast<ShoppingTreeItem*>(parent.internalPointer());\r
-\r
- insertRows(selectedItem->row(), 1, parent(index), category);\r
-}\r
-\r
-/*******************************************************************/\r
-ShoppingTreeModel::addItem(QModelIndex &index)\r
-{\r
- ShoppingTreeItem *selectedItem;\r
-\r
- if (!parent.isValid())\r
- selectedItem = rootItem;\r
- else\r
- selectedItem = static_cast<ShoppingTreeItem*>(parent.internalPointer());\r
-\r
- insertRows(selectedItem->row(), 1, parent(index), item);\r
-}\r
-\r
-/*******************************************************************/\r
-ShoppingTreeModel::removeElement(QModelIndex &index)\r
-{\r
- ShoppingTreeItem *selectedItem;\r
-\r
- if (!parent.isValid())\r
- selectedItem = rootItem;\r
- else\r
- selectedItem = static_cast<ShoppingTreeItem*>(parent.internalPointer());\r
-\r
- removeRows(selectedItem->row(), 1, parent(index));\r
-}\r
-\r
-/*******************************************************************/\r
-ShoppingTreeModel::save()\r
-{\r
- QFile file(m_fileName);\r
- file.remove();\r
- if (!file.open(QIODevice::WriteOnly))\r
- return;\r
- if (!file.write(domDocument.toString(4).toUtf8())) {\r
- file.close();\r
- return;\r
- }\r
- file.close();\r
-}\r
+++ /dev/null
-/*\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/07/2009\r
- *\r
- */\r
-\r
-#ifndef SHOPPINGTREEMODEL_H\r
-#define SHOPPINGTREEMODEL_H\r
-\r
-#include <QAbstractItemModel>\r
-#include <QDomDocument>\r
-#include <QModelIndex>\r
-#include <QVariant>\r
-\r
-class ShoppingTreeItem;\r
-\r
-enum ItemType{\r
- item,\r
- category\r
-};\r
-\r
-class ShoppingTreeModel : public QAbstractItemModel\r
-{\r
- Q_OBJECT\r
-\r
-public:\r
- ShoppingTreeModel(QString fileName, QObject *parent = 0);\r
- ~ShoppingTreeModel();\r
-\r
- QVariant data(const QModelIndex &index, int role) const;\r
- Qt::ItemFlags flags(const QModelIndex &index) const;\r
- QVariant headerData(int section, Qt::Orientation orientation,\r
- int role = Qt::DisplayRole) const;\r
- QModelIndex index(int row, int column,\r
- const QModelIndex &parent = QModelIndex()) const;\r
- QModelIndex parent(const QModelIndex &child) const;\r
- int rowCount(const QModelIndex &parent = QModelIndex()) const;\r
- int columnCount(const QModelIndex &parent = QModelIndex()) const;\r
- bool insertRows(int row, int count,\r
- const QModelIndex & parent = QModelIndex(),\r
- ItemType type = item);\r
- bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());\r
-\r
-public slots:\r
- void addCategory(QModelIndex & index);\r
- void addItem(QModelIndex & index);\r
- void removeElement(QModelIndex & index);\r
- void save();\r
-\r
-signals:\r
- void documentChanged();\r
-\r
-private:\r
- QString m_fileName;\r
- QDomDocument domDocument;\r
- QDomNode rootItemNode;\r
- ShoppingTreeItem *rootItem;\r
-};\r
-\r
-#endif // SHOPPINGTREEMODEL_H\r
+++ /dev/null
-# -------------------------------------------------
-# Project created by QtCreator 2009-12-01T15:41:15
-# -------------------------------------------------
-QT += xml
-DESTDIR = build
-TARGET = family-shop-mgr
-TEMPLATE = app
-INCLUDEPATH += model \
- GUI \
- sync \
-
-SOURCES += main.cpp \
- GUI/FamilyShoppingManagerMainWindow.cpp \
- GUI/GoShoppingView.cpp \
- GUI/ListManagerView.cpp \
- model/ShoppingTreeModel.cpp \
- model/ShoppingTreeItem.cpp \
-
-HEADERS += GUI/FamilyShoppingManagerMainWindow.h \
- GUI/GoShoppingView.h \
- GUI/ListManagerView.h \
- model/ShoppingTreeModel.h \
- model/ShoppingTreeItem.h \
-
-TRANSLATIONS = localization/family-shop-mgr_fr.ts \
- localization/family-shop-mgr_es.ts \
- localization/family-shop-mgr_nl.ts \
- localization/family-shop-mgr_eu.ts
-
-MOC_DIR = tmp
-OBJECTS_DIR = tmp