git-svn-id: file:///svnroot/family-shop-mgr@23 26eb2498-383b-47a6-be48-5d6f36779e85
authoronil <u.irigoyen@gmail.com>
Wed, 10 Mar 2010 10:40:09 +0000 (10:40 +0000)
committeronil <u.irigoyen@gmail.com>
Wed, 10 Mar 2010 10:40:09 +0000 (10:40 +0000)
code/family-shop-mgr/FamilyShoppingManagerMainWindow.cpp
code/family-shop-mgr/FamilyShoppingManagerMainWindow.h
code/family-shop-mgr/ShoppingTreeModel.cpp
code/family-shop-mgr/ShoppingTreeModel.h
code/family-shop-mgr/family-shop-mgr.pro.user

index bb8329e..4b821f7 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "ListManagerView.h"
 #include "GoShoppingView.h"
+#include "ShoppingTreeModel.h"
 
 /*******************************************************************/
 FamilyShoppingManagerMainWindow::FamilyShoppingManagerMainWindow(QWidget *parent)
@@ -60,20 +61,20 @@ void FamilyShoppingManagerMainWindow::showListManager()
     editMenu = new QMenu(tr("&Edit"), this);
     addCategoryAction = new QAction(tr("Add category"), this);
     connect(addCategoryAction, SIGNAL(triggered()),
-            this, SLOT(insertRow()));
+            this, SLOT(addCategory()));
     editMenu->addAction(addCategoryAction);
-    removeCategoryAction = new QAction(tr("Remove category"), this);
-    connect(removeCategoryAction, SIGNAL(triggered()),
-            this, SLOT(removeRow()));
-    editMenu->addAction(removeCategoryAction);
-    addItemAction = new QAction(tr("Add item"), this);
-    connect(addItemAction, SIGNAL(triggered()),
-            this, SLOT(insertRow()));
-    editMenu->addAction(addItemAction);
-    removeItemAction = new QAction(tr("Remove item"), this);
-    connect(removeItemAction, SIGNAL(triggered()),
-            this, SLOT(removeRow()));
-    editMenu->addAction(removeItemAction);
+//    removeCategoryAction = new QAction(tr("Remove category"), this);
+//    connect(removeCategoryAction, SIGNAL(triggered()),
+//            this, SLOT(removeRow()));
+//    editMenu->addAction(removeCategoryAction);
+//    addItemAction = new QAction(tr("Add item"), this);
+//    connect(addItemAction, SIGNAL(triggered()),
+//            this, SLOT(insertRow()));
+//    editMenu->addAction(addItemAction);
+//    removeItemAction = new QAction(tr("Remove item"), this);
+//    connect(removeItemAction, SIGNAL(triggered()),
+//            this, SLOT(removeRow()));
+//    editMenu->addAction(removeItemAction);
     menuBar()->addMenu(editMenu);
 
     goShoppingAction = new QAction(tr("Go shopping!"), this);
@@ -122,6 +123,7 @@ void FamilyShoppingManagerMainWindow::showAbout()
 }
 
 /*******************************************************************/
+/*
 void FamilyShoppingManagerMainWindow::insertChild()
 {
      QModelIndex index = ((ListManagerView*) activityView)->
@@ -150,70 +152,49 @@ void FamilyShoppingManagerMainWindow::insertChild()
                              QItemSelectionModel::ClearAndSelect);
      ((ListManagerView*) activityView)->updateActions();
  }
+ */
 
 /*******************************************************************/
-/*
-bool FamilyShoppingManagerMainWindow::insertColumn(const QModelIndex &parent)
+void FamilyShoppingManagerMainWindow::addCategory()
 {
-    QAbstractItemModel *model = ((ListManagerView*) activityView)->model();
-    int column = ((ListManagerView*) activityView)->selectionModel()->
-            currentIndex().column();
+    ShoppingTreeModel *model = (ShoppingTreeModel*)
+                               ((ListManagerView*) activityView)->model();
 
-    // Insert a column in the parent item.
-    bool changed = model->insertColumn(column + 1, parent);
-    if (changed)
-        model->setHeaderData(column + 1, Qt::Horizontal,
-                             QVariant("[No header]"), Qt::EditRole);
-
-    ((ListManagerView*) activityView)->updateActions();
-
-    return changed;
+    if(model->addCategory("New category"))
+        ((ListManagerView*) activityView)->updateActions();
 }
-*/
 
 /*******************************************************************/
-void FamilyShoppingManagerMainWindow::insertRow()
+void FamilyShoppingManagerMainWindow::addSubCategory()
 {
-     QModelIndex index = ((ListManagerView*) activityView)->
-                         selectionModel()->currentIndex();
-     QAbstractItemModel *model = ((ListManagerView*) activityView)->model();
+    QModelIndex index = ((ListManagerView*) activityView)->
+                        selectionModel()->currentIndex().parent();
+    ShoppingTreeModel *model = (ShoppingTreeModel*)
+                               ((ListManagerView*) activityView)->model();
 
-     if (!model->insertRow(index.row()+1, index.parent()))
-         return;
-
-     ((ListManagerView*) activityView)->updateActions();
-
-     for(int column = 0; column < model->columnCount(index.parent()); ++column)
-     {
-         QModelIndex child = model->index(index.row()+1, column, index.parent());
-         model->setData(child, QVariant("New Item"), Qt::EditRole);
-     }
+    if(model->addSubCategory("New sub-category", index.row()+1, index))
+        ((ListManagerView*) activityView)->updateActions();
 }
 
 /*******************************************************************/
-/*
-bool FamilyShoppingManagerMainWindow::removeColumn(const QModelIndex &parent)
+void FamilyShoppingManagerMainWindow::addItem()
 {
-     QAbstractItemModel *model = ((ListManagerView*) activityView)->model();
-     int column = ((ListManagerView*) activityView)->selectionModel()->
-                  currentIndex().column();
+    QModelIndex index = ((ListManagerView*) activityView)->
+                        selectionModel()->currentIndex().parent();
+    ShoppingTreeModel *model = (ShoppingTreeModel*)
+                               ((ListManagerView*) activityView)->model();
 
-     // Insert columns in each child of the parent item.
-     bool changed = model->removeColumn(column, parent);
-
-     if (!parent.isValid() && changed)
-         ((ListManagerView*) activityView)->updateActions();
-
-     return changed;
+    if(model->addItem("New item", index.row()+1, index))
+        ((ListManagerView*) activityView)->updateActions();
 }
- */
 
 /*******************************************************************/
-void FamilyShoppingManagerMainWindow::removeRow()
+void FamilyShoppingManagerMainWindow::removeCategoryOrItem()
 {
      QModelIndex index = ((ListManagerView*) activityView)->
                          selectionModel()->currentIndex();
-     QAbstractItemModel *model = ((ListManagerView*) activityView)->model();
-     if (model->removeRow(index.row(), index.parent()))
+     ShoppingTreeModel *model = (ShoppingTreeModel*)
+                                ((ListManagerView*) activityView)->model();
+     if (model->removeCategoryOrItem(index))
          ((ListManagerView*) activityView)->updateActions();
 }
index 63f8e87..701dc62 100644 (file)
@@ -38,11 +38,11 @@ private slots:
     void showGoShopping();
     void showAbout();
 
-    void insertChild();
-//    bool insertColumn(const QModelIndex &parent = QModelIndex());
-    void insertRow();
-//    bool removeColumn(const QModelIndex &parent = QModelIndex());
-    void removeRow();
+    void addCategory();
+    void addSubCategory();
+    void addItem();
+    void removeCategoryOrItem();
+    //void insertChild();
 
 private:
     QWidget *activityView;
@@ -54,6 +54,7 @@ private:
     QAction *aboutAction;
 
     QAction *addCategoryAction;
+    QAction *addSubCategoryAction();
     QAction *removeCategoryAction;
     QAction *addItemAction;
     QAction *removeItemAction;
index 5f2985f..d304c41 100644 (file)
@@ -115,6 +115,64 @@ ShoppingTreeModel::~ShoppingTreeModel()
 }\r
 \r
 /*******************************************************************/\r
+bool ShoppingTreeModel::addCategory(QString name)\r
+{\r
+    QModelIndex parent = QModelIndex();\r
+\r
+    if (!this->insertRow(parent.row()+1, parent))\r
+        return false;\r
+\r
+    for(int column = 0; column < this->columnCount(parent); ++column)\r
+    {\r
+        QModelIndex child = this->index(parent.row()+1, column, parent);\r
+        ShoppingTreeItem* item = this->getItem(child);\r
+        item->setItemType(ShoppingTreeItem::Category);\r
+        this->setData(child, QVariant(name), Qt::EditRole);\r
+    }\r
+    return true;\r
+}\r
+\r
+/*******************************************************************/\r
+bool ShoppingTreeModel::addSubCategory(QString name, int position,\r
+                    const QModelIndex &parent)\r
+{\r
+    if (!this->insertRow(position, parent))\r
+        return false;\r
+\r
+    for(int column = 0; column < this->columnCount(parent); ++column)\r
+    {\r
+        QModelIndex child = this->index(parent.row()+1, column, parent);\r
+        ShoppingTreeItem* item = this->getItem(child);\r
+        item->setItemType(ShoppingTreeItem::Category);\r
+        this->setData(child, QVariant(name), Qt::EditRole);\r
+    }\r
+    return true;\r
+}\r
+\r
+/*******************************************************************/\r
+bool ShoppingTreeModel::addItem(QString name, int position,\r
+             const QModelIndex &parent)\r
+{\r
+    if (!this->insertRow(position, parent))\r
+        return false;\r
+\r
+    for(int column = 0; column < this->columnCount(parent); ++column)\r
+    {\r
+        QModelIndex child = this->index(parent.row()+1, column, parent);\r
+        ShoppingTreeItem* item = this->getItem(child);\r
+        item->setItemType(ShoppingTreeItem::Item);\r
+        this->setData(child, QVariant(name), Qt::EditRole);\r
+    }\r
+    return true;\r
+}\r
+\r
+/*******************************************************************/\r
+bool ShoppingTreeModel::removeCategoryOrItem(const QModelIndex &index)\r
+{\r
+    return this->removeRow(index.row(), index.parent());\r
+}\r
+\r
+/*******************************************************************/\r
 QVariant ShoppingTreeModel::data(const QModelIndex &index, int role) const\r
 {\r
     if(!index.isValid())\r
@@ -140,7 +198,8 @@ Qt::ItemFlags ShoppingTreeModel::flags(const QModelIndex &index) const
 ShoppingTreeItem *ShoppingTreeModel::getItem(const QModelIndex &index) const\r
 {\r
     if(index.isValid()){\r
-        ShoppingTreeItem *item = static_cast<ShoppingTreeItem*>(index.internalPointer());\r
+        ShoppingTreeItem *item =\r
+                static_cast<ShoppingTreeItem*>(index.internalPointer());\r
         if(item) return item;\r
     }\r
 \r
index 31301d6..66829bf 100644 (file)
@@ -39,6 +39,13 @@ public:
     ShoppingTreeModel(const QString &xmlFileName, QObject *parent = 0);\r
     ~ShoppingTreeModel();\r
 \r
+    bool addCategory(QString name);\r
+    bool addSubCategory(QString name, int position,\r
+                        const QModelIndex &parent = QModelIndex());\r
+    bool addItem(QString name, int position,\r
+                 const QModelIndex &parent = QModelIndex());\r
+    bool removeCategoryOrItem(const QModelIndex &index = QModelIndex());\r
+\r
     QVariant data(const QModelIndex &index, int role) const;\r
     QVariant headerData(int section, Qt::Orientation orientation,\r
                         int role = Qt::DisplayRole) const;\r
@@ -55,6 +62,7 @@ public:
     bool setHeaderData(int section, Qt::Orientation orientation,\r
                        const QVariant &value, int role = Qt::EditRole);\r
 \r
+private:\r
     bool insertColumns(int position, int columns,\r
                            const QModelIndex &parent = QModelIndex());\r
     bool removeColumns(int position, int columns,\r
index e0ed2f2..0eb46bd 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-ftBEZLbXAE,guid=e2c8517a9ef4dda368a3470a4b96c3aa</value>
+    <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-q1EKrknBIg,guid=8a525aab18f7fc1a86808b054b97539c</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-aqBEsG/S.gpg-agent:1905:1</value>
+    <value type="QString">GPG_AGENT_INFO=/tmp/gpg-7ScX2l/S.gpg-agent:1982: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/1998,unix/onil-netbook:/tmp/.ICE-unix/1998</value>
+    <value type="QString">SESSION_MANAGER=local/onil-netbook:@/tmp/.ICE-unix/2071,unix/onil-netbook:/tmp/.ICE-unix/2071</value>
     <value type="QString">SHELL=/bin/bash</value>
     <value type="QString">SHLVL=0</value>
-    <value type="QString">SSH_AGENT_PID=1904</value>
-    <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-gckQrI1854/agent.1854</value>
+    <value type="QString">SSH_AGENT_PID=1981</value>
+    <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-Lrqsxa1931/agent.1931</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-1268171689.363286-1127686922</value>
+    <value type="QString">XDG_SESSION_COOKIE=67465ad3dd74e5003d0b02474b126985-1268208539.486626-183142450</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-ftBEZLbXAE,guid=e2c8517a9ef4dda368a3470a4b96c3aa</value>
+    <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-q1EKrknBIg,guid=8a525aab18f7fc1a86808b054b97539c</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-aqBEsG/S.gpg-agent:1905:1</value>
+    <value type="QString">GPG_AGENT_INFO=/tmp/gpg-7ScX2l/S.gpg-agent:1982: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/1998,unix/onil-netbook:/tmp/.ICE-unix/1998</value>
+    <value type="QString">SESSION_MANAGER=local/onil-netbook:@/tmp/.ICE-unix/2071,unix/onil-netbook:/tmp/.ICE-unix/2071</value>
     <value type="QString">SHELL=/bin/bash</value>
     <value type="QString">SHLVL=0</value>
-    <value type="QString">SSH_AGENT_PID=1904</value>
-    <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-gckQrI1854/agent.1854</value>
+    <value type="QString">SSH_AGENT_PID=1981</value>
+    <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-Lrqsxa1931/agent.1931</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-1268171689.363286-1127686922</value>
+    <value type="QString">XDG_SESSION_COOKIE=67465ad3dd74e5003d0b02474b126985-1268208539.486626-183142450</value>
     <value type="QString">XDM_MANAGED=method=classic</value>
    </valuelist>
    <value key="abstractProcess.IgnoreReturnValue" type="bool">false</value>