git-svn-id: file:///svnroot/family-shop-mgr@25 26eb2498-383b-47a6-be48-5d6f36779e85
[family-shop-mgr] / code / family-shop-mgr / FamilyShoppingManagerMainWindow.cpp
index 4b821f7..6e56f7f 100644 (file)
@@ -22,6 +22,7 @@
 #include "FamilyShoppingManagerMainWindow.h"
 #include <QMenuBar>
 #include <QMessageBox>
+#include <QInputDialog>
 
 #include "ListManagerView.h"
 #include "GoShoppingView.h"
@@ -29,7 +30,7 @@
 
 /*******************************************************************/
 FamilyShoppingManagerMainWindow::FamilyShoppingManagerMainWindow(QWidget *parent)
-    : QMainWindow(parent), activityView(NULL), editMenu(NULL),
+    : QMainWindow(parent), activityView(NULL), //editMenu(NULL),
     showCheckedItemsAction(NULL), goShoppingAction(NULL), endShoppingAction(NULL)
 {
     aboutAction = new QAction(tr("&About"), this);
@@ -58,11 +59,11 @@ void FamilyShoppingManagerMainWindow::showListManager()
     activityView = new ListManagerView("ShoppingList.xml", this);
     setCentralWidget(activityView);
 
-    editMenu = new QMenu(tr("&Edit"), this);
+//    editMenu = new QMenu(tr("&Edit"), this);
     addCategoryAction = new QAction(tr("Add category"), this);
     connect(addCategoryAction, SIGNAL(triggered()),
             this, SLOT(addCategory()));
-    editMenu->addAction(addCategoryAction);
+//    editMenu->addAction(addCategoryAction);
 //    removeCategoryAction = new QAction(tr("Remove category"), this);
 //    connect(removeCategoryAction, SIGNAL(triggered()),
 //            this, SLOT(removeRow()));
@@ -75,7 +76,7 @@ void FamilyShoppingManagerMainWindow::showListManager()
 //    connect(removeItemAction, SIGNAL(triggered()),
 //            this, SLOT(removeRow()));
 //    editMenu->addAction(removeItemAction);
-    menuBar()->addMenu(editMenu);
+    menuBar()->addAction(addCategoryAction);
 
     goShoppingAction = new QAction(tr("Go shopping!"), this);
     connect(goShoppingAction, SIGNAL(triggered()),
@@ -90,7 +91,7 @@ void FamilyShoppingManagerMainWindow::showListManager()
 void FamilyShoppingManagerMainWindow::showGoShopping()
 {
     menuBar()->clear();
-    delete editMenu;
+//    delete editMenu;
     delete goShoppingAction;
 
     delete activityView;
@@ -160,8 +161,16 @@ void FamilyShoppingManagerMainWindow::addCategory()
     ShoppingTreeModel *model = (ShoppingTreeModel*)
                                ((ListManagerView*) activityView)->model();
 
-    if(model->addCategory("New category"))
+    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;
 }
 
 /*******************************************************************/
@@ -172,8 +181,17 @@ void FamilyShoppingManagerMainWindow::addSubCategory()
     ShoppingTreeModel *model = (ShoppingTreeModel*)
                                ((ListManagerView*) activityView)->model();
 
-    if(model->addSubCategory("New sub-category", index.row()+1, index))
+    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;
 }
 
 /*******************************************************************/
@@ -184,8 +202,17 @@ void FamilyShoppingManagerMainWindow::addItem()
     ShoppingTreeModel *model = (ShoppingTreeModel*)
                                ((ListManagerView*) activityView)->model();
 
-    if(model->addItem("New item", index.row()+1, index))
+    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;
 }
 
 /*******************************************************************/