*/
#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(new ListManagerView(this))
+ : QMainWindow(parent), activityView(NULL), editMenu(NULL),
+ showCheckedItemsAction(NULL), goShoppingAction(NULL), endShoppingAction(NULL)
{
- ui->setupUi(this);
- connect(ui->manageButton, SIGNAL(clicked()), this, SLOT(openListManager()));
- connect(ui->goShoppingButton, SIGNAL(clicked()), this, SLOT(openGoShopping()));
+ aboutAction = new QAction(tr("&About"), this);
+ connect(aboutAction, SIGNAL(triggered()), this, SLOT(showAbout()));
+ menuBar()->addAction(aboutAction);
+
+
+ showListManager();
}
-FamilyShoppingManagerStartView::~FamilyShoppingManagerStartView()
+/*******************************************************************/
+FamilyShoppingManagerMainWindow::~FamilyShoppingManagerMainWindow()
{
- delete ui;
delete activityView;
}
-void FamilyShoppingManagerStartView::openListManager()
+/*******************************************************************/
+void FamilyShoppingManagerMainWindow::showListManager()
{
- this->hide();
+ menuBar()->clear();
+
+ delete showCheckedItemsAction;
+ delete endShoppingAction;
+
+ delete activityView;
activityView = new ListManagerView("ShoppingList.xml", this);
+ setCentralWidget(activityView);
+
+ editMenu = new QMenu(tr("&Edit"), this);
+ addCategoryAction = new QAction(tr("Add category"), this);
+ connect(addCategoryAction, SIGNAL(triggered()),
+ 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);
+ menuBar()->addMenu(editMenu);
+
+ goShoppingAction = new QAction(tr("Go shopping!"), this);
+ connect(goShoppingAction, SIGNAL(triggered()),
+ this, SLOT(showGoShopping()));
+ menuBar()->addAction(goShoppingAction);
+
+ menuBar()->addAction(aboutAction);
+ update();
}
-void FamilyShoppingManagerStartView::openGoShopping()
+/*******************************************************************/
+void FamilyShoppingManagerMainWindow::showGoShopping()
{
- //this->hide();
+ menuBar()->clear();
+ delete editMenu;
+ delete goShoppingAction;
+
+ delete activityView;
activityView = new GoShoppingView("ShoppingList.xml", this);
+ setCentralWidget(activityView);
+
+ showCheckedItemsAction = new QAction(tr("&Show checked"), this);
+ showCheckedItemsAction->setCheckable(true);
+ connect(showCheckedItemsAction, SIGNAL(toggled(bool)),
+ activityView, SLOT(showChecked(bool)));
+ menuBar()->addAction(showCheckedItemsAction);
+
+ endShoppingAction = new QAction(tr("&End shopping"), this);
+ connect(endShoppingAction, SIGNAL(triggered()),
+ this, SLOT(showListManager()));
+ menuBar()->addAction(endShoppingAction);
+
+ menuBar()->addAction(aboutAction);
+ update();
+}
+
+/*******************************************************************/
+void FamilyShoppingManagerMainWindow::showAbout()
+{
+ QString text;
+ text = "Application name: Family shopping manager\n";
+ text += "Author: Unai IRIGOYEN\n\n";
+ 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();
+ }
+ */
+
+/*******************************************************************/
+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(model->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(model->addItem(name, index.row()+1, index))
+ ((ListManagerView*) activityView)->updateActions();
+
+ delete ok;
+}
+
+/*******************************************************************/
+void FamilyShoppingManagerMainWindow::removeCategoryOrItem()
+{
+ QModelIndex index = ((ListManagerView*) activityView)->
+ selectionModel()->currentIndex();
+ ShoppingTreeModel *model = (ShoppingTreeModel*)
+ ((ListManagerView*) activityView)->model();
+ if (model->removeCategoryOrItem(index))
+ ((ListManagerView*) activityView)->updateActions();
}