From c53a3f4a253da96795e0050334d4418658fbe580 Mon Sep 17 00:00:00 2001 From: pavelpa Date: Tue, 19 Jan 2010 17:34:18 +0000 Subject: [PATCH] single-click is used to open event dialog --- src/gui/mainwindow.cpp | 21 +++++++-------------- src/gui/mainwindow.h | 2 +- src/mvc/treeview.cpp | 24 +++++++++++++++++------- src/mvc/treeview.h | 2 +- 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 9d58b29..b133986 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -17,6 +17,8 @@ #include "daynavigatorwidget.h" #include "mapwindow.h" +const int confId = 1; + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { @@ -64,10 +66,10 @@ MainWindow::MainWindow(QWidget *parent) actTreeView->setModel(new EventModel()); actTreeView->setItemDelegate(new Delegate(actTreeView)); - // event double clicked - connect(dayTreeView, SIGNAL(doubleClicked(const QModelIndex &)), SLOT(itemDoubleClicked(const QModelIndex &))); - connect(favTreeView, SIGNAL(doubleClicked(const QModelIndex &)), SLOT(itemDoubleClicked(const QModelIndex &))); - connect(actTreeView, SIGNAL(doubleClicked(const QModelIndex &)), SLOT(itemDoubleClicked(const QModelIndex &))); + // event clicked + connect(dayTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &))); + connect(favTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &))); + connect(actTreeView, SIGNAL(clicked(const QModelIndex &)), SLOT(itemClicked(const QModelIndex &))); // request for map to be displayed connect(dayTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &))); connect(favTreeView, SIGNAL(requestForMap(const QModelIndex &)), SLOT(displayMap(const QModelIndex &))); @@ -77,7 +79,6 @@ MainWindow::MainWindow(QWidget *parent) // TESTING: load some 'fav' data if(Conference::getAll().count()) // no conference(s) in the DB { - int confId = 1; static_cast(favTreeView->model())->loadFavEvents(Conference::getById(confId).start(),confId); favTreeView->reset(); } @@ -89,7 +90,6 @@ MainWindow::MainWindow(QWidget *parent) } else { - int confId = 1; QDate aStartDate = Conference::getById(confId).start(); QDate aEndDate = Conference::getById(confId).end(); dayNavigator->setDates(aStartDate, aEndDate); @@ -129,7 +129,6 @@ void MainWindow::importSchedule() if(Conference::getAll().count()) { - int confId = 1; // 'dayNavigator' emits signal 'dateChanged' after setting valid START:END dates QDate aStartDate = Conference::getById(confId).start(); QDate aEndDate = Conference::getById(confId).end(); @@ -154,7 +153,6 @@ void MainWindow::aboutApp() void MainWindow::updateDayView(const QDate &aDate) { - int confId = 1; static_cast(dayTreeView->model())->loadEvents(aDate,confId); dayTreeView->reset(); dayNavigator->show(); @@ -162,7 +160,6 @@ void MainWindow::updateDayView(const QDate &aDate) void MainWindow::updateTab(const int aIndex) { - int confId = 1; switch(aIndex) { case 0://index 0 of tabWidget: dayViewTab @@ -191,13 +188,10 @@ void MainWindow::updateTab(const int aIndex) } }; - - } void MainWindow::updateActivitiesDayView(const QDate &aDate) { - int confId = 1; static_cast(actTreeView->model())->loadEventsByActivities(aDate,confId); actTreeView->reset(); activityDayNavigator->show(); @@ -205,13 +199,12 @@ void MainWindow::updateActivitiesDayView(const QDate &aDate) void MainWindow::updateFavouritesDayView(const QDate &aDate) { - int confId = 1; static_cast(favTreeView->model())->loadFavEvents(aDate,confId); favTreeView->reset(); favouriteDayNavigator->show(); } -void MainWindow::itemDoubleClicked(const QModelIndex &aIndex) +void MainWindow::itemClicked(const QModelIndex &aIndex) { // have to handle only events, not time-groups if(!aIndex.parent().isValid()) // time-group diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index 65719d0..59cadf0 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -22,7 +22,7 @@ private slots: void updateTab(const int n); void updateActivitiesDayView(const QDate &aDate); void updateFavouritesDayView(const QDate &aDate); - void itemDoubleClicked(const QModelIndex &aIndex); + void itemClicked(const QModelIndex &aIndex); void displayMap(const QModelIndex &aIndex); private: SqlEngine *mSqlEngine; diff --git a/src/mvc/treeview.cpp b/src/mvc/treeview.cpp index 2004973..7abe943 100644 --- a/src/mvc/treeview.cpp +++ b/src/mvc/treeview.cpp @@ -21,16 +21,21 @@ void TreeView::mouseReleaseEvent(QMouseEvent *aEvent) QModelIndex index = currentIndex(); QPoint point = aEvent->pos(); - testForControlClicked(index,point); - - // pass the event to the Base class, so item clicks/events are handled correctly - QTreeView::mouseReleaseEvent(aEvent); + // test whether we have handled the mouse event + if(!testForControlClicked(index,point)) + { + // pass the event to the Base class, so item clicks/events are handled correctly + QTreeView::mouseReleaseEvent(aEvent); + } } -void TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aPoint) +// returns bool if some Control was clicked +bool TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aPoint) { + bool handled = false; + if(!aIndex.isValid()) - return; + return handled; QRect rect = visualRect(aIndex); // visual QRect of selected/clicked item in the list Delegate *delegate = static_cast(itemDelegate(aIndex)); @@ -55,6 +60,7 @@ void TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aP event.update("favourite"); // since the Favourite icon has changed, update TreeView accordingly static_cast(model())->emitDataChangedSignal(aIndex,aIndex); + handled = true; } break; case Delegate::AlarmControlOn: @@ -88,7 +94,7 @@ void TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aP event.update("alarm"); // since the Alarm icon has changed, update TreeView accordingly static_cast(model())->emitDataChangedSignal(aIndex,aIndex); - + handled = true; } break; case Delegate::MapControl: @@ -96,13 +102,17 @@ void TreeView::testForControlClicked(const QModelIndex &aIndex, const QPoint &aP // handle Alarm Control clicked qDebug() << "MAP CLICKED: " << qVariantValue(aIndex.data()); emit(requestForMap(aIndex)); + handled = true; } break; case Delegate::ControlNone: default: { // item was clicked, but not a control + handled = false; } }; + + return handled; } diff --git a/src/mvc/treeview.h b/src/mvc/treeview.h index 8851ca5..7f2d198 100644 --- a/src/mvc/treeview.h +++ b/src/mvc/treeview.h @@ -11,7 +11,7 @@ public: ~TreeView() {} private: void mouseReleaseEvent(QMouseEvent *aEvent); - void testForControlClicked(const QModelIndex &aIndex, const QPoint &aPoint); + bool testForControlClicked(const QModelIndex &aIndex, const QPoint &aPoint); signals: void requestForMap(const QModelIndex &aIndex); }; -- 2.39.5