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

index fe8187c..bb8329e 100644 (file)
@@ -28,8 +28,8 @@
 
 /*******************************************************************/
 FamilyShoppingManagerMainWindow::FamilyShoppingManagerMainWindow(QWidget *parent)
-    : QMainWindow(parent), activityView(NULL), showCheckedItemsAction(NULL),
-    endShoppingAction(NULL), goShoppingAction(NULL), editMenu(NULL)
+    : QMainWindow(parent), activityView(NULL), editMenu(NULL),
+    showCheckedItemsAction(NULL), goShoppingAction(NULL), endShoppingAction(NULL)
 {
     aboutAction = new QAction(tr("&About"), this);
     connect(aboutAction, SIGNAL(triggered()), this, SLOT(showAbout()));
@@ -58,10 +58,22 @@ void FamilyShoppingManagerMainWindow::showListManager()
     setCentralWidget(activityView);
 
     editMenu = new QMenu(tr("&Edit"), this);
-    editMenu->addAction(tr("Add category"));
-    editMenu->addAction(tr("Remove category"));
-    editMenu->addAction(tr("Add item"));
-    editMenu->addAction(tr("Remove item"));
+    addCategoryAction = new QAction(tr("Add category"), this);
+    connect(addCategoryAction, SIGNAL(triggered()),
+            this, SLOT(insertRow()));
+    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);
     menuBar()->addMenu(editMenu);
 
     goShoppingAction = new QAction(tr("Go shopping!"), this);
@@ -108,3 +120,100 @@ void FamilyShoppingManagerMainWindow::showAbout()
     text += "Licence: GPL";
     QMessageBox::about(this,tr("About"), text);
 }
+
+/*******************************************************************/
+void FamilyShoppingManagerMainWindow::insertChild()
+{
+     QModelIndex index = ((ListManagerView*) activityView)->
+                         selectionModel()->currentIndex();
+     QAbstractItemModel *model = ((ListManagerView*) activityView)->model();
+
+     if (model->columnCount(index) == 0) {
+         if (!model->insertColumn(0, index))
+             return;
+     }
+
+     if (!model->insertRow(0, index))
+         return;
+
+     for (int column = 0; column < model->columnCount(index); ++column)
+     {
+         QModelIndex child = model->index(0, column, index);
+         model->setData(child, QVariant("[No data]"), Qt::EditRole);
+         if (!model->headerData(column, Qt::Horizontal).isValid())
+             model->setHeaderData(column, Qt::Horizontal,
+                                  QVariant("[No header]"), Qt::EditRole);
+     }
+
+     ((ListManagerView*) activityView)->selectionModel()->
+             setCurrentIndex(model->index(0, 0, index),
+                             QItemSelectionModel::ClearAndSelect);
+     ((ListManagerView*) activityView)->updateActions();
+ }
+
+/*******************************************************************/
+/*
+bool FamilyShoppingManagerMainWindow::insertColumn(const QModelIndex &parent)
+{
+    QAbstractItemModel *model = ((ListManagerView*) activityView)->model();
+    int column = ((ListManagerView*) activityView)->selectionModel()->
+            currentIndex().column();
+
+    // 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;
+}
+*/
+
+/*******************************************************************/
+void FamilyShoppingManagerMainWindow::insertRow()
+{
+     QModelIndex index = ((ListManagerView*) activityView)->
+                         selectionModel()->currentIndex();
+     QAbstractItemModel *model = ((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);
+     }
+}
+
+/*******************************************************************/
+/*
+bool FamilyShoppingManagerMainWindow::removeColumn(const QModelIndex &parent)
+{
+     QAbstractItemModel *model = ((ListManagerView*) activityView)->model();
+     int column = ((ListManagerView*) activityView)->selectionModel()->
+                  currentIndex().column();
+
+     // Insert columns in each child of the parent item.
+     bool changed = model->removeColumn(column, parent);
+
+     if (!parent.isValid() && changed)
+         ((ListManagerView*) activityView)->updateActions();
+
+     return changed;
+}
+ */
+
+/*******************************************************************/
+void FamilyShoppingManagerMainWindow::removeRow()
+{
+     QModelIndex index = ((ListManagerView*) activityView)->
+                         selectionModel()->currentIndex();
+     QAbstractItemModel *model = ((ListManagerView*) activityView)->model();
+     if (model->removeRow(index.row(), index.parent()))
+         ((ListManagerView*) activityView)->updateActions();
+}
index dbcae1a..63f8e87 100644 (file)
@@ -23,6 +23,7 @@
 #define FAMILYSHOPPINGMANAGERMAINWINDOW_H
 
 #include <QMainWindow>
+#include <QModelIndex>
 
 class FamilyShoppingManagerMainWindow : public QMainWindow
 {
@@ -37,6 +38,12 @@ private slots:
     void showGoShopping();
     void showAbout();
 
+    void insertChild();
+//    bool insertColumn(const QModelIndex &parent = QModelIndex());
+    void insertRow();
+//    bool removeColumn(const QModelIndex &parent = QModelIndex());
+    void removeRow();
+
 private:
     QWidget *activityView;
 
@@ -45,6 +52,11 @@ private:
     QAction *goShoppingAction;
     QAction *endShoppingAction;
     QAction *aboutAction;
+
+    QAction *addCategoryAction;
+    QAction *removeCategoryAction;
+    QAction *addItemAction;
+    QAction *removeItemAction;
 };
 
 #endif // FAMILYSHOPPINGMANAGERMAINWINDOW_H
index c9050a7..11a8f52 100644 (file)
@@ -41,6 +41,25 @@ ListManagerView::~ListManagerView()
 /*******************************************************************/\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
index 595d99d..c176958 100644 (file)
@@ -32,8 +32,6 @@ public:
     ListManagerView(QString xmlFileName, QWidget *parent = 0);\r
     ~ListManagerView();\r
 \r
-private:\r
-\r
     void updateActions();\r
 };\r
 \r
index 2f5ac29..e0ed2f2 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-GJlGaxlG0v,guid=0c8e1c6e41d3e6f2d1af89c24b6fc5bb</value>
+    <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-ftBEZLbXAE,guid=e2c8517a9ef4dda368a3470a4b96c3aa</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-pfjgMn/S.gpg-agent:1953:1</value>
+    <value type="QString">GPG_AGENT_INFO=/tmp/gpg-aqBEsG/S.gpg-agent:1905: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/2044,unix/onil-netbook:/tmp/.ICE-unix/2044</value>
+    <value type="QString">SESSION_MANAGER=local/onil-netbook:@/tmp/.ICE-unix/1998,unix/onil-netbook:/tmp/.ICE-unix/1998</value>
     <value type="QString">SHELL=/bin/bash</value>
     <value type="QString">SHLVL=0</value>
-    <value type="QString">SSH_AGENT_PID=1952</value>
-    <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-pIQBwR1902/agent.1902</value>
+    <value type="QString">SSH_AGENT_PID=1904</value>
+    <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-gckQrI1854/agent.1854</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-1265616314.877010-1127570423</value>
+    <value type="QString">XDG_SESSION_COOKIE=67465ad3dd74e5003d0b02474b126985-1268171689.363286-1127686922</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-GJlGaxlG0v,guid=0c8e1c6e41d3e6f2d1af89c24b6fc5bb</value>
+    <value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-ftBEZLbXAE,guid=e2c8517a9ef4dda368a3470a4b96c3aa</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-pfjgMn/S.gpg-agent:1953:1</value>
+    <value type="QString">GPG_AGENT_INFO=/tmp/gpg-aqBEsG/S.gpg-agent:1905: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/2044,unix/onil-netbook:/tmp/.ICE-unix/2044</value>
+    <value type="QString">SESSION_MANAGER=local/onil-netbook:@/tmp/.ICE-unix/1998,unix/onil-netbook:/tmp/.ICE-unix/1998</value>
     <value type="QString">SHELL=/bin/bash</value>
     <value type="QString">SHLVL=0</value>
-    <value type="QString">SSH_AGENT_PID=1952</value>
-    <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-pIQBwR1902/agent.1902</value>
+    <value type="QString">SSH_AGENT_PID=1904</value>
+    <value type="QString">SSH_AUTH_SOCK=/tmp/ssh-gckQrI1854/agent.1854</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-1265616314.877010-1127570423</value>
+    <value type="QString">XDG_SESSION_COOKIE=67465ad3dd74e5003d0b02474b126985-1268171689.363286-1127686922</value>
     <value type="QString">XDM_MANAGED=method=classic</value>
    </valuelist>
    <value key="abstractProcess.IgnoreReturnValue" type="bool">false</value>