git-svn-id: file:///svnroot/family-shop-mgr@35 26eb2498-383b-47a6-be48-5d6f36779e85
authoronil <u.irigoyen@gmail.com>
Sat, 29 May 2010 21:56:00 +0000 (21:56 +0000)
committeronil <u.irigoyen@gmail.com>
Sat, 29 May 2010 21:56:00 +0000 (21:56 +0000)
12 files changed:
code/family-shop-mgr/GUI/FamilyShoppingManagerMainWindow.cpp [new file with mode: 0644]
code/family-shop-mgr/GUI/FamilyShoppingManagerMainWindow.h [new file with mode: 0644]
code/family-shop-mgr/GUI/GoShoppingView.cpp [new file with mode: 0644]
code/family-shop-mgr/GUI/GoShoppingView.h [new file with mode: 0644]
code/family-shop-mgr/GUI/ListManagerView.cpp [new file with mode: 0644]
code/family-shop-mgr/GUI/ListManagerView.h [new file with mode: 0644]
code/family-shop-mgr/family-shop-mgr.pro
code/family-shop-mgr/family-shop-mgr.pro.user
code/family-shop-mgr/model/ShoppingTreeItem.cpp
code/family-shop-mgr/model/ShoppingTreeItem.h
code/family-shop-mgr/model/ShoppingTreeModel.cpp
code/family-shop-mgr/model/ShoppingTreeModel.h

diff --git a/code/family-shop-mgr/GUI/FamilyShoppingManagerMainWindow.cpp b/code/family-shop-mgr/GUI/FamilyShoppingManagerMainWindow.cpp
new file mode 100644 (file)
index 0000000..1041806
--- /dev/null
@@ -0,0 +1,211 @@
+/*
+ * 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(((ListManagerView*) activityView)->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(((ListManagerView*) activityView)->addItem(name))
+        ((ListManagerView*) activityView)->updateActions();
+
+    delete ok;
+}
+
+/*******************************************************************/
+void FamilyShoppingManagerMainWindow::removeCategoryOrItem()
+{
+     QModelIndex index = ((ListManagerView*) activityView)->
+                         selectionModel()->currentIndex();
+     ShoppingTreeModel *model = (ShoppingTreeModel*)
+                                ((ListManagerView*) activityView)->model();
+     if (model->removeElement(index))
+         ((ListManagerView*) activityView)->updateActions();
+}
diff --git a/code/family-shop-mgr/GUI/FamilyShoppingManagerMainWindow.h b/code/family-shop-mgr/GUI/FamilyShoppingManagerMainWindow.h
new file mode 100644 (file)
index 0000000..44c1356
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * 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
diff --git a/code/family-shop-mgr/GUI/GoShoppingView.cpp b/code/family-shop-mgr/GUI/GoShoppingView.cpp
new file mode 100644 (file)
index 0000000..37275e4
--- /dev/null
@@ -0,0 +1,44 @@
+/*\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
diff --git a/code/family-shop-mgr/GUI/GoShoppingView.h b/code/family-shop-mgr/GUI/GoShoppingView.h
new file mode 100644 (file)
index 0000000..edbdf1d
--- /dev/null
@@ -0,0 +1,38 @@
+/*\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
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
diff --git a/code/family-shop-mgr/GUI/ListManagerView.h b/code/family-shop-mgr/GUI/ListManagerView.h
new file mode 100644 (file)
index 0000000..b6058f3
--- /dev/null
@@ -0,0 +1,41 @@
+/*\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
+    bool addCategory(QString name);\r
+    bool addItem(QString name);\r
+\r
+    void updateActions();\r
+};\r
+\r
+#endif // LISTMANAGERVIEW_H\r
index c9eaa1b..0dd20ed 100644 (file)
@@ -2,7 +2,8 @@
 # Project created by QtCreator 2009-12-01T15:41:15
 # -------------------------------------------------
 QT += xml
-TARGET = build/family-shop-mgr
+DESTDIR = build
+TARGET = family-shop-mgr
 TEMPLATE = app
 INCLUDEPATH += model \
     GUI \
index ad776c1..b2b4ade 100644 (file)
   <valuemap type="QVariantMap">
    <value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value>
    <valuelist key="abstractProcess.Environment" type="QVariantList">
-    <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-eKukEAYkED,guid=329729b2f92e20a20feb0a184bfff74d</value>
+    <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-ExayC5LFdT,guid=91cfee0822f9bc5c87c57e114c0164f3</value>
     <value type="QString">DESKTOP_SESSION=default</value>
     <value type="QString">DISPLAY=:0.0</value>
     <value type="QString">DM_CONTROL=/var/run/xdmctl</value>
-    <value type="QString">GPG_AGENT_INFO=/tmp/gpg-qWEYAr/S.gpg-agent:1575:1</value>
+    <value type="QString">GPG_AGENT_INFO=/tmp/gpg-zgiVeL/S.gpg-agent:1570:1</value>
     <value type="QString">GS_LIB=/home/onil/.fonts</value>
     <value type="QString">GTK2_RC_FILES=/etc/gtk-2.0/gtkrc:/home/onil/.gtkrc-2.0:/home/onil/.gtkrc-2.0-kde4:/home/onil/.kde/share/config/gtkrc-2.0</value>
     <value type="QString">GTK_RC_FILES=/etc/gtk/gtkrc:/home/onil/.gtkrc::/home/onil/.kde/share/config/gtkrc</value>
     <value type="QString">PWD=/home/onil/Documents</value>
     <value type="QString">QTDIR=/usr/share/qt4</value>
     <value type="QString">QT_PLUGIN_PATH=/home/onil/.kde/lib/kde4/plugins/:/usr/lib/kde4/plugins/</value>
-    <value type="QString">SESSION_MANAGER=local/onil-netbook:@/tmp/.ICE-unix/1718,unix/onil-netbook:/tmp/.ICE-unix/1718</value>
+    <value type="QString">SESSION_MANAGER=local/onil-netbook:@/tmp/.ICE-unix/1710,unix/onil-netbook:/tmp/.ICE-unix/1710</value>
     <value type="QString">SHELL=/bin/bash</value>
     <value type="QString">SHLVL=0</value>
-    <value type="QString">SSH_AGENT_PID=1574</value>
-    <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-kcUDTw1523/agent.1523</value>
+    <value type="QString">SSH_AGENT_PID=1569</value>
+    <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-vZSFlh1518/agent.1518</value>
     <value type="QString">USER=onil</value>
     <value type="QString">WINDOWPATH=7</value>
     <value type="QString">XCURSOR_THEME=oxy-white</value>
     <value type="QString">XDG_DATA_DIRS=/usr/share:/usr/share:/usr/local/share</value>
-    <value type="QString">XDG_SESSION_COOKIE=67465ad3dd74e5003d0b02474b126985-1275066187.875603-169541383</value>
+    <value type="QString">XDG_SESSION_COOKIE=67465ad3dd74e5003d0b02474b126985-1275159795.162730-875997727</value>
     <value type="QString">XDM_MANAGED=method=classic</value>
    </valuelist>
    <valuelist key="abstractProcess.arguments" type="QVariantList">
   <valuemap type="QVariantMap">
    <value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value>
    <valuelist key="abstractProcess.Environment" type="QVariantList">
-    <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-eKukEAYkED,guid=329729b2f92e20a20feb0a184bfff74d</value>
+    <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-ExayC5LFdT,guid=91cfee0822f9bc5c87c57e114c0164f3</value>
     <value type="QString">DESKTOP_SESSION=default</value>
     <value type="QString">DISPLAY=:0.0</value>
     <value type="QString">DM_CONTROL=/var/run/xdmctl</value>
-    <value type="QString">GPG_AGENT_INFO=/tmp/gpg-qWEYAr/S.gpg-agent:1575:1</value>
+    <value type="QString">GPG_AGENT_INFO=/tmp/gpg-zgiVeL/S.gpg-agent:1570:1</value>
     <value type="QString">GS_LIB=/home/onil/.fonts</value>
     <value type="QString">GTK2_RC_FILES=/etc/gtk-2.0/gtkrc:/home/onil/.gtkrc-2.0:/home/onil/.gtkrc-2.0-kde4:/home/onil/.kde/share/config/gtkrc-2.0</value>
     <value type="QString">GTK_RC_FILES=/etc/gtk/gtkrc:/home/onil/.gtkrc::/home/onil/.kde/share/config/gtkrc</value>
     <value type="QString">PWD=/home/onil/Documents</value>
     <value type="QString">QTDIR=/usr/share/qt4</value>
     <value type="QString">QT_PLUGIN_PATH=/home/onil/.kde/lib/kde4/plugins/:/usr/lib/kde4/plugins/</value>
-    <value type="QString">SESSION_MANAGER=local/onil-netbook:@/tmp/.ICE-unix/1718,unix/onil-netbook:/tmp/.ICE-unix/1718</value>
+    <value type="QString">SESSION_MANAGER=local/onil-netbook:@/tmp/.ICE-unix/1710,unix/onil-netbook:/tmp/.ICE-unix/1710</value>
     <value type="QString">SHELL=/bin/bash</value>
     <value type="QString">SHLVL=0</value>
-    <value type="QString">SSH_AGENT_PID=1574</value>
-    <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-kcUDTw1523/agent.1523</value>
+    <value type="QString">SSH_AGENT_PID=1569</value>
+    <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-vZSFlh1518/agent.1518</value>
     <value type="QString">USER=onil</value>
     <value type="QString">WINDOWPATH=7</value>
     <value type="QString">XCURSOR_THEME=oxy-white</value>
     <value type="QString">XDG_DATA_DIRS=/usr/share:/usr/share:/usr/local/share</value>
-    <value type="QString">XDG_SESSION_COOKIE=67465ad3dd74e5003d0b02474b126985-1275066187.875603-169541383</value>
+    <value type="QString">XDG_SESSION_COOKIE=67465ad3dd74e5003d0b02474b126985-1275159795.162730-875997727</value>
     <value type="QString">XDM_MANAGED=method=classic</value>
    </valuelist>
    <value key="abstractProcess.IgnoreReturnValue" type="bool">false</value>
index 6e473e7..77c33eb 100644 (file)
 #include "ShoppingTreeItem.h"\r
 \r
 \r
-ShoppingTreeItem::ShoppingTreeItem(QDomNode &node, int row, ShoppingTreeItem *parent)\r
+ShoppingTreeItem::ShoppingTreeItem(QDomNode &node, ShoppingTreeItem *parent)\r
 {\r
     domNode = node;\r
-    rowNumber = row;\r
     parentItem = parent;\r
 }\r
 \r
@@ -71,7 +70,7 @@ ShoppingTreeItem *ShoppingTreeItem::child(int i)
     }\r
     if (i >= 0 && i < childElementsList.count()) {\r
         childNode = childElementsList.at(i);\r
-        ShoppingTreeItem *childItem = new ShoppingTreeItem(childNode, i, this);\r
+        ShoppingTreeItem *childItem = new ShoppingTreeItem(childNode, this);\r
         childItems[i] = childItem;\r
         return childItem;\r
     }\r
@@ -81,5 +80,42 @@ ShoppingTreeItem *ShoppingTreeItem::child(int i)
 /*******************************************************************/\r
 int ShoppingTreeItem::row()\r
 {\r
-    return rowNumber;\r
+    return parent()->childItems.key(this);\r
+}\r
+\r
+/*******************************************************************/\r
+bool ShoppingTreeItem::addChild(ShoppingTreeItem *item, int row)\r
+{\r
+    offsetChildAtAdd(row);\r
+    childItems.insert(row, item);\r
+    return true;\r
+}\r
+\r
+/*******************************************************************/\r
+bool ShoppingTreeItem::removeChild(int row)\r
+{\r
+    delete childItems[row];\r
+    childItems.remove(row);\r
+    offsetChildAtRemove(row);\r
+    return true;\r
+}\r
+\r
+/*******************************************************************/\r
+void ShoppingTreeItem::offsetChildAtAdd(int row)\r
+{\r
+    if(childItems.contains(row))\r
+    {\r
+        offsetChildAtAdd(row + 1);\r
+        childItems.insert(row + 1, childItems[row]);\r
+    }\r
+}\r
+\r
+/*******************************************************************/\r
+void ShoppingTreeItem::offsetChildAtRemove(int row)\r
+{\r
+    if(childItems.contains(row + 1))\r
+    {\r
+        childItems.insert(row, childItems[row + 1]);\r
+        offsetChildAtRemove(row + 1);\r
+    }\r
 }\r
index d0a14a4..5c4ec80 100644 (file)
 class ShoppingTreeItem\r
 {\r
 public:\r
-    ShoppingTreeItem(QDomNode &node, int row, ShoppingTreeItem *parent = 0);\r
+    ShoppingTreeItem(QDomNode &node, ShoppingTreeItem *parent = 0);\r
     ~ShoppingTreeItem();\r
     ShoppingTreeItem *child(int i);\r
     ShoppingTreeItem *parent();\r
     QDomNode node() const;\r
+    bool addChild(ShoppingTreeItem* item, int row = 0);\r
+    bool removeChild(int row);\r
+    void offsetChildAtAdd(int row);\r
+    void offsetChildAtRemove(int row);\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
index ee00a89..60314b2 100644 (file)
@@ -59,7 +59,7 @@ QVariant ShoppingTreeModel::data(const QModelIndex &index, int role) const
     if (!index.isValid())\r
         return QVariant();\r
 \r
-    if (role != Qt::DisplayRole)\r
+    if (role != Qt::DisplayRole && role != Qt::EditRole)\r
         return QVariant();\r
 \r
     ShoppingTreeItem *item = static_cast<ShoppingTreeItem*>(index.internalPointer());\r
@@ -72,7 +72,7 @@ QVariant ShoppingTreeModel::data(const QModelIndex &index, int role) const
         case 1:\r
             if(node.toElement().nodeName() == "item")\r
             {\r
-                return node.firstChildElement("quantity").text();\r
+                return node.firstChildElement("quantity").text().toInt();\r
             }\r
             return QVariant();\r
         case 2:\r
@@ -202,7 +202,6 @@ bool ShoppingTreeModel::insertRows(int row, int count, const QModelIndex &parent
             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
@@ -223,14 +222,20 @@ bool ShoppingTreeModel::insertRows(int row, int count, const QModelIndex &parent
             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
+        else\r
+            return false;\r
+\r
+        parentItem->node().insertAfter(newElement, parentItem->child(row + i)->node());\r
+        ShoppingTreeItem* newItem = new ShoppingTreeItem(newElement, parentItem);\r
+        parentItem->addChild(newItem, row + i);\r
     }\r
     emit documentChanged();\r
+    return true;\r
 }\r
 \r
 /*******************************************************************/\r
-ShoppingTreeModel::removeRows(int row, int count, const QModelIndex &parent)\r
+bool ShoppingTreeModel::removeRows(int row, int count, const QModelIndex &parent)\r
 {\r
     ShoppingTreeItem *parentItem;\r
 \r
@@ -241,52 +246,111 @@ ShoppingTreeModel::removeRows(int row, int count, const QModelIndex &parent)
 \r
     for(int i = 0; i < count; i++)\r
     {\r
-        parentItem->node().removeChild(parentItem->child(i)->node());\r
+        parentItem->node().removeChild(parentItem->child(row)->node());\r
+        parentItem->removeChild(row);\r
     }\r
     emit documentChanged();\r
+    return true;\r
 }\r
 \r
 /*******************************************************************/\r
-ShoppingTreeModel::addCategory(QModelIndex &index)\r
+bool ShoppingTreeModel::addCategory(QModelIndex &index, QString name)\r
 {\r
     ShoppingTreeItem *selectedItem;\r
 \r
-    if (!parent.isValid())\r
+    if (!index.isValid())\r
         selectedItem = rootItem;\r
     else\r
-        selectedItem = static_cast<ShoppingTreeItem*>(parent.internalPointer());\r
+        selectedItem = static_cast<ShoppingTreeItem*>(index.internalPointer());\r
 \r
-    insertRows(selectedItem->row(), 1, parent(index), category);\r
+    bool success = insertRows(selectedItem->row(), 1, parent(index), category);\r
+    if(!name.isEmpty())\r
+    {\r
+        selectedItem->parent()->child(selectedItem->row() + 1)\r
+            ->node().setNodeValue(name);\r
+        emit documentChanged();\r
+    }\r
+    return success;\r
 }\r
 \r
 /*******************************************************************/\r
-ShoppingTreeModel::addItem(QModelIndex &index)\r
+bool ShoppingTreeModel::addItem(QModelIndex &index, QString name)\r
 {\r
     ShoppingTreeItem *selectedItem;\r
 \r
-    if (!parent.isValid())\r
+    if (!index.isValid())\r
         selectedItem = rootItem;\r
     else\r
-        selectedItem = static_cast<ShoppingTreeItem*>(parent.internalPointer());\r
+        selectedItem = static_cast<ShoppingTreeItem*>(index.internalPointer());\r
 \r
-    insertRows(selectedItem->row(), 1, parent(index), item);\r
+    bool success = insertRows(selectedItem->row(), 1, parent(index), item);\r
+    if(!name.isEmpty())\r
+    {\r
+        selectedItem->parent()->child(selectedItem->row() + 1)\r
+            ->node().setNodeValue(name);\r
+        emit documentChanged();\r
+    }\r
+    return success;\r
 }\r
 \r
 /*******************************************************************/\r
-ShoppingTreeModel::removeElement(QModelIndex &index)\r
+bool ShoppingTreeModel::removeElement(QModelIndex &index)\r
 {\r
     ShoppingTreeItem *selectedItem;\r
 \r
-    if (!parent.isValid())\r
+    if (!index.isValid())\r
         selectedItem = rootItem;\r
     else\r
-        selectedItem = static_cast<ShoppingTreeItem*>(parent.internalPointer());\r
+        selectedItem = static_cast<ShoppingTreeItem*>(index.internalPointer());\r
+\r
+    return removeRows(selectedItem->row(), 1, parent(index));\r
+}\r
+\r
+/*******************************************************************/\r
+bool ShoppingTreeModel::setData(const QModelIndex &index, const QVariant &value, int role)\r
+{\r
+    if (!index.isValid())\r
+        return false;\r
+\r
+    if (role != Qt::EditRole)\r
+        return false;\r
+\r
+    ShoppingTreeItem *item = static_cast<ShoppingTreeItem*>(index.internalPointer());\r
+\r
+    QDomNode node = item->node();\r
 \r
-    removeRows(selectedItem->row(), 1, parent(index));\r
+    switch (index.column()) {\r
+        case 0:\r
+            node.firstChildElement("title").setNodeValue(value.toString());\r
+            return true;\r
+        case 1:\r
+            if(node.toElement().nodeName() == "item")\r
+            {\r
+                node.firstChildElement("quantity").setNodeValue(value.toString());\r
+                return true;\r
+            }\r
+            return false;\r
+        case 2:\r
+            if(node.toElement().nodeName() == "item")\r
+            {\r
+                node.firstChildElement("store").setNodeValue(value.toString());\r
+                return true;\r
+            }\r
+            return false;\r
+        case 3:\r
+            if(node.toElement().nodeName() == "item")\r
+            {\r
+                node.firstChildElement("checked").setNodeValue(value.toString());\r
+                return true;\r
+            }\r
+            return false;\r
+        default:\r
+            return false;\r
+    }\r
 }\r
 \r
 /*******************************************************************/\r
-ShoppingTreeModel::save()\r
+void ShoppingTreeModel::save()\r
 {\r
     QFile file(m_fileName);\r
     file.remove();\r
index cb283b0..4c54931 100644 (file)
@@ -55,11 +55,12 @@ public:
                     const QModelIndex & parent = QModelIndex(),\r
                     ItemType type = item);\r
     bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());\r
+    bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole);\r
 \r
 public slots:\r
-    void addCategory(QModelIndex & index);\r
-    void addItem(QModelIndex & index);\r
-    void removeElement(QModelIndex & index);\r
+    bool addCategory(QModelIndex & index, QString name = QString());\r
+    bool addItem(QModelIndex & index, QString name = QString());\r
+    bool removeElement(QModelIndex & index);\r
     void save();\r
 \r
 signals:\r