From adf1628e4a6294c98680b21fc670df1ea7f4ffc9 Mon Sep 17 00:00:00 2001 From: onil Date: Tue, 9 Mar 2010 23:34:56 +0000 Subject: [PATCH] git-svn-id: file:///svnroot/family-shop-mgr@22 26eb2498-383b-47a6-be48-5d6f36779e85 --- .../FamilyShoppingManagerMainWindow.cpp | 121 +++++++++++++++++++- .../FamilyShoppingManagerMainWindow.h | 12 ++ code/family-shop-mgr/ListManagerView.cpp | 19 +++ code/family-shop-mgr/ListManagerView.h | 2 - code/family-shop-mgr/family-shop-mgr.pro.user | 24 ++-- 5 files changed, 158 insertions(+), 20 deletions(-) diff --git a/code/family-shop-mgr/FamilyShoppingManagerMainWindow.cpp b/code/family-shop-mgr/FamilyShoppingManagerMainWindow.cpp index fe8187c..bb8329e 100644 --- a/code/family-shop-mgr/FamilyShoppingManagerMainWindow.cpp +++ b/code/family-shop-mgr/FamilyShoppingManagerMainWindow.cpp @@ -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(); +} diff --git a/code/family-shop-mgr/FamilyShoppingManagerMainWindow.h b/code/family-shop-mgr/FamilyShoppingManagerMainWindow.h index dbcae1a..63f8e87 100644 --- a/code/family-shop-mgr/FamilyShoppingManagerMainWindow.h +++ b/code/family-shop-mgr/FamilyShoppingManagerMainWindow.h @@ -23,6 +23,7 @@ #define FAMILYSHOPPINGMANAGERMAINWINDOW_H #include +#include 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 diff --git a/code/family-shop-mgr/ListManagerView.cpp b/code/family-shop-mgr/ListManagerView.cpp index c9050a7..11a8f52 100644 --- a/code/family-shop-mgr/ListManagerView.cpp +++ b/code/family-shop-mgr/ListManagerView.cpp @@ -41,6 +41,25 @@ 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 index 595d99d..c176958 100644 --- a/code/family-shop-mgr/ListManagerView.h +++ b/code/family-shop-mgr/ListManagerView.h @@ -32,8 +32,6 @@ public: ListManagerView(QString xmlFileName, QWidget *parent = 0); ~ListManagerView(); -private: - void updateActions(); }; diff --git a/code/family-shop-mgr/family-shop-mgr.pro.user b/code/family-shop-mgr/family-shop-mgr.pro.user index 2f5ac29..e0ed2f2 100644 --- a/code/family-shop-mgr/family-shop-mgr.pro.user +++ b/code/family-shop-mgr/family-shop-mgr.pro.user @@ -97,11 +97,11 @@ Debug - DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-GJlGaxlG0v,guid=0c8e1c6e41d3e6f2d1af89c24b6fc5bb + DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-ftBEZLbXAE,guid=e2c8517a9ef4dda368a3470a4b96c3aa DESKTOP_SESSION=default DISPLAY=:0.0 DM_CONTROL=/var/run/xdmctl - GPG_AGENT_INFO=/tmp/gpg-pfjgMn/S.gpg-agent:1953:1 + GPG_AGENT_INFO=/tmp/gpg-aqBEsG/S.gpg-agent:1905:1 GS_LIB=/home/onil/.fonts 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 GTK_RC_FILES=/etc/gtk/gtkrc:/home/onil/.gtkrc::/home/onil/.kde/share/config/gtkrc @@ -117,16 +117,16 @@ PWD=/home/onil/Documents QTDIR=/usr/share/qt4 QT_PLUGIN_PATH=/home/onil/.kde/lib/kde4/plugins/:/usr/lib/kde4/plugins/ - SESSION_MANAGER=local/onil-netbook:@/tmp/.ICE-unix/2044,unix/onil-netbook:/tmp/.ICE-unix/2044 + SESSION_MANAGER=local/onil-netbook:@/tmp/.ICE-unix/1998,unix/onil-netbook:/tmp/.ICE-unix/1998 SHELL=/bin/bash SHLVL=0 - SSH_AGENT_PID=1952 - SSH_AUTH_SOCK=/tmp/ssh-pIQBwR1902/agent.1902 + SSH_AGENT_PID=1904 + SSH_AUTH_SOCK=/tmp/ssh-gckQrI1854/agent.1854 USER=onil WINDOWPATH=7 XCURSOR_THEME=oxy-white XDG_DATA_DIRS=/usr/share:/usr/share:/usr/local/share - XDG_SESSION_COOKIE=67465ad3dd74e5003d0b02474b126985-1265616314.877010-1127570423 + XDG_SESSION_COOKIE=67465ad3dd74e5003d0b02474b126985-1268171689.363286-1127686922 XDM_MANAGED=method=classic @@ -147,11 +147,11 @@ Debug - DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-GJlGaxlG0v,guid=0c8e1c6e41d3e6f2d1af89c24b6fc5bb + DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-ftBEZLbXAE,guid=e2c8517a9ef4dda368a3470a4b96c3aa DESKTOP_SESSION=default DISPLAY=:0.0 DM_CONTROL=/var/run/xdmctl - GPG_AGENT_INFO=/tmp/gpg-pfjgMn/S.gpg-agent:1953:1 + GPG_AGENT_INFO=/tmp/gpg-aqBEsG/S.gpg-agent:1905:1 GS_LIB=/home/onil/.fonts 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 GTK_RC_FILES=/etc/gtk/gtkrc:/home/onil/.gtkrc::/home/onil/.kde/share/config/gtkrc @@ -167,16 +167,16 @@ PWD=/home/onil/Documents QTDIR=/usr/share/qt4 QT_PLUGIN_PATH=/home/onil/.kde/lib/kde4/plugins/:/usr/lib/kde4/plugins/ - SESSION_MANAGER=local/onil-netbook:@/tmp/.ICE-unix/2044,unix/onil-netbook:/tmp/.ICE-unix/2044 + SESSION_MANAGER=local/onil-netbook:@/tmp/.ICE-unix/1998,unix/onil-netbook:/tmp/.ICE-unix/1998 SHELL=/bin/bash SHLVL=0 - SSH_AGENT_PID=1952 - SSH_AUTH_SOCK=/tmp/ssh-pIQBwR1902/agent.1902 + SSH_AGENT_PID=1904 + SSH_AUTH_SOCK=/tmp/ssh-gckQrI1854/agent.1854 USER=onil WINDOWPATH=7 XCURSOR_THEME=oxy-white XDG_DATA_DIRS=/usr/share:/usr/share:/usr/local/share - XDG_SESSION_COOKIE=67465ad3dd74e5003d0b02474b126985-1265616314.877010-1127570423 + XDG_SESSION_COOKIE=67465ad3dd74e5003d0b02474b126985-1268171689.363286-1127686922 XDM_MANAGED=method=classic false -- 1.7.9.5