From 8bb6459d7fc661798fd0d2f133f934ed82874eaa Mon Sep 17 00:00:00 2001 From: onil Date: Sat, 29 May 2010 21:59:26 +0000 Subject: [PATCH 1/1] git-svn-id: file:///svnroot/family-shop-mgr@36 26eb2498-383b-47a6-be48-5d6f36779e85 --- .../FamilyShoppingManagerMainWindow.cpp | 211 -------------- .../FamilyShoppingManagerMainWindow.h | 62 ---- code/family-shop-mgr/GoShoppingView.cpp | 44 --- code/family-shop-mgr/GoShoppingView.h | 38 --- code/family-shop-mgr/ListManagerView.cpp | 70 ----- code/family-shop-mgr/ListManagerView.h | 38 --- code/family-shop-mgr/ShoppingTreeItem.cpp | 85 ------ code/family-shop-mgr/ShoppingTreeItem.h | 45 --- code/family-shop-mgr/ShoppingTreeModel.cpp | 300 -------------------- code/family-shop-mgr/ShoppingTreeModel.h | 75 ----- code/family-shop-mgr/family-shop-mgr.pro | 31 -- 11 files changed, 999 deletions(-) delete mode 100644 code/family-shop-mgr/FamilyShoppingManagerMainWindow.cpp delete mode 100644 code/family-shop-mgr/FamilyShoppingManagerMainWindow.h delete mode 100644 code/family-shop-mgr/GoShoppingView.cpp delete mode 100644 code/family-shop-mgr/GoShoppingView.h delete mode 100644 code/family-shop-mgr/ListManagerView.cpp delete mode 100644 code/family-shop-mgr/ListManagerView.h delete mode 100644 code/family-shop-mgr/ShoppingTreeItem.cpp delete mode 100644 code/family-shop-mgr/ShoppingTreeItem.h delete mode 100644 code/family-shop-mgr/ShoppingTreeModel.cpp delete mode 100644 code/family-shop-mgr/ShoppingTreeModel.h delete mode 100644 code/family-shop-mgr/family-shop-mgr.pro diff --git a/code/family-shop-mgr/FamilyShoppingManagerMainWindow.cpp b/code/family-shop-mgr/FamilyShoppingManagerMainWindow.cpp deleted file mode 100644 index 269c3fe..0000000 --- a/code/family-shop-mgr/FamilyShoppingManagerMainWindow.cpp +++ /dev/null @@ -1,211 +0,0 @@ -/* - * 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 . - * - * Author: Unai IRIGOYEN - * Date: 12/07/2009 - * - */ - -#include "FamilyShoppingManagerMainWindow.h" -#include -#include -#include - -#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(); -} diff --git a/code/family-shop-mgr/FamilyShoppingManagerMainWindow.h b/code/family-shop-mgr/FamilyShoppingManagerMainWindow.h deleted file mode 100644 index 3187ca5..0000000 --- a/code/family-shop-mgr/FamilyShoppingManagerMainWindow.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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 . - * - * Author: Unai IRIGOYEN - * Date: 12/07/2009 - * - */ - -#ifndef FAMILYSHOPPINGMANAGERMAINWINDOW_H -#define FAMILYSHOPPINGMANAGERMAINWINDOW_H - -#include -#include - -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 diff --git a/code/family-shop-mgr/GoShoppingView.cpp b/code/family-shop-mgr/GoShoppingView.cpp deleted file mode 100644 index 37275e4..0000000 --- a/code/family-shop-mgr/GoShoppingView.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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 . - * - * Author: Unai IRIGOYEN - * Date: 12/17/2009 - * - */ - -#include "GoShoppingView.h" - -#include "ShoppingTreeModel.h" - -/*******************************************************************/ -GoShoppingView::GoShoppingView(QString xmlFileName, QWidget *parent) - :QTreeView(parent) -{ - ShoppingTreeModel *model = new ShoppingTreeModel(xmlFileName, this); - this->setModel(model); - this->setAnimated(true); - this->setAutoExpandDelay(1); - this->setAutoScroll(true); - this->setExpandsOnDoubleClick(true); - this->setSortingEnabled(true); - for(int column = 0; column < model->columnCount(); column++) - this->resizeColumnToContents(column); -} - -/*******************************************************************/ -GoShoppingView::~GoShoppingView() -{ -} diff --git a/code/family-shop-mgr/GoShoppingView.h b/code/family-shop-mgr/GoShoppingView.h deleted file mode 100644 index edbdf1d..0000000 --- a/code/family-shop-mgr/GoShoppingView.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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 . - * - * Author: Unai IRIGOYEN - * Date: 12/17/2009 - * - */ - -#ifndef GOSHOPPINGVIEW_H -#define GOSHOPPINGVIEW_H - -#include - -class GoShoppingView : public QTreeView -{ -Q_OBJECT - -public: - GoShoppingView(QString xmlFileName, QWidget *parent = 0); - ~GoShoppingView(); - -private: -}; - -#endif // GOSHOPPINGVIEW_H diff --git a/code/family-shop-mgr/ListManagerView.cpp b/code/family-shop-mgr/ListManagerView.cpp deleted file mode 100644 index 99816fb..0000000 --- a/code/family-shop-mgr/ListManagerView.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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 . - * - * Author: Unai IRIGOYEN - * Date: 12/17/2009 - * - */ - -#include "ListManagerView.h" - -#include "ShoppingTreeModel.h" - -/*******************************************************************/ -ListManagerView::ListManagerView(QString xmlFileName, QWidget *parent) - :QTreeView(parent) -{ - ShoppingTreeModel *model = new ShoppingTreeModel(xmlFileName, this); - this->setModel(model); - this->setAnimated(true); - this->setAutoExpandDelay(1); - this->setAutoScroll(true); - this->setExpandsOnDoubleClick(true); - this->setSortingEnabled(true); - for(int column = 0; column < model->columnCount(); column++) - this->resizeColumnToContents(column); -} - -/*******************************************************************/ -ListManagerView::~ListManagerView() -{ -} - -/*******************************************************************/ -void ListManagerView::updateActions() -{ - /* - bool hasSelection = !this->selectionModel()->selection().isEmpty(); - removeRowAction->setEnabled(hasSelection); - removeColumnAction->setEnabled(hasSelection); - - bool hasCurrent = this->selectionModel()->currentIndex().isValid(); - insertRowAction->setEnabled(hasCurrent); - insertColumnAction->setEnabled(hasCurrent); - - if (hasCurrent) - { - this->closePersistentEditor(view->selectionModel()->currentIndex()); - - int row = this->selectionModel()->currentIndex().row(); - int column = this->selectionModel()->currentIndex().column(); - if (this->selectionModel()->currentIndex().parent().isValid()) - statusBar()->showMessage(tr("Position: (%1,%2)").arg(row).arg(column)); - else - statusBar()->showMessage(tr("Position: (%1,%2) in top level").arg(row).arg(column)); - } - */ -} diff --git a/code/family-shop-mgr/ListManagerView.h b/code/family-shop-mgr/ListManagerView.h deleted file mode 100644 index c176958..0000000 --- a/code/family-shop-mgr/ListManagerView.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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 . - * - * Author: Unai IRIGOYEN - * Date: 12/17/2009 - * - */ - -#ifndef LISTMANAGERVIEW_H -#define LISTMANAGERVIEW_H - -#include - -class ListManagerView : public QTreeView -{ -Q_OBJECT - -public: - ListManagerView(QString xmlFileName, QWidget *parent = 0); - ~ListManagerView(); - - void updateActions(); -}; - -#endif // LISTMANAGERVIEW_H diff --git a/code/family-shop-mgr/ShoppingTreeItem.cpp b/code/family-shop-mgr/ShoppingTreeItem.cpp deleted file mode 100644 index 6e473e7..0000000 --- a/code/family-shop-mgr/ShoppingTreeItem.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* - * 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 . - * - * Author: Unai IRIGOYEN - * Date: 12/07/2009 - * - */ - -#include - -#include "ShoppingTreeItem.h" - - -ShoppingTreeItem::ShoppingTreeItem(QDomNode &node, int row, ShoppingTreeItem *parent) -{ - domNode = node; - rowNumber = row; - parentItem = parent; -} - -/*******************************************************************/ -ShoppingTreeItem::~ShoppingTreeItem() -{ - QHash::iterator it; - for (it = childItems.begin(); it != childItems.end(); ++it) - delete it.value(); -} - -/*******************************************************************/ -QDomNode ShoppingTreeItem::node() const -{ - return domNode; -} - -/*******************************************************************/ -ShoppingTreeItem *ShoppingTreeItem::parent() -{ - return parentItem; -} - -/*******************************************************************/ -ShoppingTreeItem *ShoppingTreeItem::child(int i) -{ - if (childItems.contains(i)) - return childItems[i]; - - QDomNodeList childNodesList = domNode.childNodes(); - QList childElementsList; - QDomNode childNode; - for(int j = 0; !(childNode = childNodesList.at(j)).isNull(); j++) - { - if(childNode.isElement()) - { - if(childNode.toElement().nodeName() == "category" || - childNode.toElement().nodeName() == "item") - childElementsList.append(childNode); - } - } - if (i >= 0 && i < childElementsList.count()) { - childNode = childElementsList.at(i); - ShoppingTreeItem *childItem = new ShoppingTreeItem(childNode, i, this); - childItems[i] = childItem; - return childItem; - } - return 0; -} - -/*******************************************************************/ -int ShoppingTreeItem::row() -{ - return rowNumber; -} diff --git a/code/family-shop-mgr/ShoppingTreeItem.h b/code/family-shop-mgr/ShoppingTreeItem.h deleted file mode 100644 index d0a14a4..0000000 --- a/code/family-shop-mgr/ShoppingTreeItem.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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 . - * - * Author: Unai IRIGOYEN - * Date: 12/07/2009 - * - */ - -#ifndef SHOPPINGTREEITEM_H -#define SHOPPINGTREEITEM_H - -#include -#include - -class ShoppingTreeItem -{ -public: - ShoppingTreeItem(QDomNode &node, int row, ShoppingTreeItem *parent = 0); - ~ShoppingTreeItem(); - ShoppingTreeItem *child(int i); - ShoppingTreeItem *parent(); - QDomNode node() const; - int row(); - -private: - QDomNode domNode; - QHash childItems; - ShoppingTreeItem *parentItem; - int rowNumber; -}; - -#endif // SHOPPINGTREEITEM_H diff --git a/code/family-shop-mgr/ShoppingTreeModel.cpp b/code/family-shop-mgr/ShoppingTreeModel.cpp deleted file mode 100644 index ee00a89..0000000 --- a/code/family-shop-mgr/ShoppingTreeModel.cpp +++ /dev/null @@ -1,300 +0,0 @@ -/* - * 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 . - * - * Author: Unai IRIGOYEN - * Date: 12/07/2009 - * - */ - -#include - -#include "ShoppingTreeItem.h" -#include "ShoppingTreeModel.h" - -ShoppingTreeModel::ShoppingTreeModel(QString fileName, QObject *parent) - : QAbstractItemModel(parent),m_fileName(fileName) -{ - connect(this, SIGNAL(documentChanged()), this, SLOT(save())); - QFile file(m_fileName); - if (!file.open(QIODevice::ReadOnly)) - return; - if (!domDocument.setContent(&file)) { - file.close(); - return; - } - file.close(); - - rootItemNode = domDocument.firstChildElement("shoppingList"); - rootItem = new ShoppingTreeItem(rootItemNode, 0); -} - -/*******************************************************************/ -ShoppingTreeModel::~ShoppingTreeModel() -{ - delete rootItem; -} - -/*******************************************************************/ -int ShoppingTreeModel::columnCount(const QModelIndex &/*parent*/) const -{ - return 4; -} - -/*******************************************************************/ -QVariant ShoppingTreeModel::data(const QModelIndex &index, int role) const -{ - if (!index.isValid()) - return QVariant(); - - if (role != Qt::DisplayRole) - return QVariant(); - - ShoppingTreeItem *item = static_cast(index.internalPointer()); - - QDomNode node = item->node(); - - switch (index.column()) { - case 0: - return node.firstChildElement("title").text(); - case 1: - if(node.toElement().nodeName() == "item") - { - return node.firstChildElement("quantity").text(); - } - return QVariant(); - case 2: - if(node.toElement().nodeName() == "item") - { - return node.firstChildElement("store").text(); - } - return QVariant(); - case 3: - if(node.toElement().nodeName() == "item") - { - return (bool) node.firstChildElement("checked").text().toInt(); - } - return QVariant(); - default: - return QVariant(); - } -} - -/*******************************************************************/ -Qt::ItemFlags ShoppingTreeModel::flags(const QModelIndex &index) const -{ - if (!index.isValid()) - return 0; - - return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable; -} - -/*******************************************************************/ -QVariant ShoppingTreeModel::headerData(int section, Qt::Orientation orientation, - int role) const -{ - if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { - switch (section) { - case 0: - return tr("Category/Item name"); - case 1: - return tr("Quantity"); - case 2: - return tr("Store"); - case 3: - return tr("Checked"); - default: - return QVariant(); - } - } - - return QVariant(); -} - -/*******************************************************************/ -QModelIndex ShoppingTreeModel::index(int row, int column, const QModelIndex &parent) - const -{ - if (!hasIndex(row, column, parent)) - return QModelIndex(); - - ShoppingTreeItem *parentItem; - - if (!parent.isValid()) - parentItem = rootItem; - else - parentItem = static_cast(parent.internalPointer()); - - ShoppingTreeItem *childItem = parentItem->child(row); - if (childItem) - return createIndex(row, column, childItem); - else - return QModelIndex(); -} - -/*******************************************************************/ -QModelIndex ShoppingTreeModel::parent(const QModelIndex &child) const -{ - if (!child.isValid()) - return QModelIndex(); - - ShoppingTreeItem *childItem = static_cast(child.internalPointer()); - ShoppingTreeItem *parentItem = childItem->parent(); - - if (!parentItem || parentItem == rootItem) - return QModelIndex(); - - return createIndex(parentItem->row(), 0, parentItem); -} - -/*******************************************************************/ -int ShoppingTreeModel::rowCount(const QModelIndex &parent) const -{ - if (parent.column() > 0) - return 0; - - ShoppingTreeItem *parentItem; - - if (!parent.isValid()) - parentItem = rootItem; - else - parentItem = static_cast(parent.internalPointer()); - - int childCount = 0; - for(QDomElement childElement = parentItem->node().firstChildElement(); - !childElement.isNull(); childElement = childElement.nextSiblingElement()) - { - if(childElement.nodeName() == "category" || childElement.nodeName() == "item") - childCount++; - } - return childCount; -} - -/*******************************************************************/ -bool ShoppingTreeModel::insertRows(int row, int count, const QModelIndex &parent, ItemType type) -{ - ShoppingTreeItem *parentItem; - - if (!parent.isValid()) - parentItem = rootItem; - else - parentItem = static_cast(parent.internalPointer()); - - for(int i = 0; i < count; i++) - { - QDomElement newElement; - QDomElement titleElement; - titleElement.setTagName("title"); - if(type == category) - { - newElement.setTagName("category"); - titleElement.setNodeValue(tr("new category")); - newElement.appendChild(titleElement); - parentItem->node().insertAfter(newElement, parentItem->child(row + i)->node()); - } - else if(type == item) - { - newElement.setTagName("item"); - titleElement.setNodeValue(tr("new item")); - newElement.appendChild(titleElement); - QDomElement quantityElement; - quantityElement.setTagName("quantity"); - newElement.appendChild(quantityElement); - QDomElement storeElement; - storeElement.setTagName("store"); - newElement.appendChild(storeElement); - QDomElement checkedElement; - checkedElement.setTagName("checked"); - checkedElement.setNodeValue("0"); - newElement.appendChild(checkedElement); - QDomElement lastModifiedElement; - lastModifiedElement.setTagName("lastModified"); - lastModifiedElement.setNodeValue(QDateTime::currentDateTime().toString("dd/MM/yyyy-hh:mm:ss")); - newElement.appendChild(lastModifiedElement); - parentItem->node().insertAfter(newElement, parentItem->child(row + i)->node()); - } - } - emit documentChanged(); -} - -/*******************************************************************/ -ShoppingTreeModel::removeRows(int row, int count, const QModelIndex &parent) -{ - ShoppingTreeItem *parentItem; - - if (!parent.isValid()) - parentItem = rootItem; - else - parentItem = static_cast(parent.internalPointer()); - - for(int i = 0; i < count; i++) - { - parentItem->node().removeChild(parentItem->child(i)->node()); - } - emit documentChanged(); -} - -/*******************************************************************/ -ShoppingTreeModel::addCategory(QModelIndex &index) -{ - ShoppingTreeItem *selectedItem; - - if (!parent.isValid()) - selectedItem = rootItem; - else - selectedItem = static_cast(parent.internalPointer()); - - insertRows(selectedItem->row(), 1, parent(index), category); -} - -/*******************************************************************/ -ShoppingTreeModel::addItem(QModelIndex &index) -{ - ShoppingTreeItem *selectedItem; - - if (!parent.isValid()) - selectedItem = rootItem; - else - selectedItem = static_cast(parent.internalPointer()); - - insertRows(selectedItem->row(), 1, parent(index), item); -} - -/*******************************************************************/ -ShoppingTreeModel::removeElement(QModelIndex &index) -{ - ShoppingTreeItem *selectedItem; - - if (!parent.isValid()) - selectedItem = rootItem; - else - selectedItem = static_cast(parent.internalPointer()); - - removeRows(selectedItem->row(), 1, parent(index)); -} - -/*******************************************************************/ -ShoppingTreeModel::save() -{ - QFile file(m_fileName); - file.remove(); - if (!file.open(QIODevice::WriteOnly)) - return; - if (!file.write(domDocument.toString(4).toUtf8())) { - file.close(); - return; - } - file.close(); -} diff --git a/code/family-shop-mgr/ShoppingTreeModel.h b/code/family-shop-mgr/ShoppingTreeModel.h deleted file mode 100644 index cb283b0..0000000 --- a/code/family-shop-mgr/ShoppingTreeModel.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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 . - * - * Author: Unai IRIGOYEN - * Date: 12/07/2009 - * - */ - -#ifndef SHOPPINGTREEMODEL_H -#define SHOPPINGTREEMODEL_H - -#include -#include -#include -#include - -class ShoppingTreeItem; - -enum ItemType{ - item, - category -}; - -class ShoppingTreeModel : public QAbstractItemModel -{ - Q_OBJECT - -public: - ShoppingTreeModel(QString fileName, QObject *parent = 0); - ~ShoppingTreeModel(); - - QVariant data(const QModelIndex &index, int role) const; - Qt::ItemFlags flags(const QModelIndex &index) const; - QVariant headerData(int section, Qt::Orientation orientation, - int role = Qt::DisplayRole) const; - QModelIndex index(int row, int column, - const QModelIndex &parent = QModelIndex()) const; - QModelIndex parent(const QModelIndex &child) const; - int rowCount(const QModelIndex &parent = QModelIndex()) const; - int columnCount(const QModelIndex &parent = QModelIndex()) const; - bool insertRows(int row, int count, - const QModelIndex & parent = QModelIndex(), - ItemType type = item); - bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex()); - -public slots: - void addCategory(QModelIndex & index); - void addItem(QModelIndex & index); - void removeElement(QModelIndex & index); - void save(); - -signals: - void documentChanged(); - -private: - QString m_fileName; - QDomDocument domDocument; - QDomNode rootItemNode; - ShoppingTreeItem *rootItem; -}; - -#endif // SHOPPINGTREEMODEL_H diff --git a/code/family-shop-mgr/family-shop-mgr.pro b/code/family-shop-mgr/family-shop-mgr.pro deleted file mode 100644 index 0dd20ed..0000000 --- a/code/family-shop-mgr/family-shop-mgr.pro +++ /dev/null @@ -1,31 +0,0 @@ -# ------------------------------------------------- -# 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 -- 1.7.9.5