summaryrefslogtreecommitdiffstats
path: root/qt-ui/divelistview.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-05-13 22:14:59 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-05-13 21:37:08 -0500
commitee7f579242568d86e7ec744c17585066c30fa943 (patch)
tree56931e11aa77752f0a04b0eb2807f074807b5c47 /qt-ui/divelistview.cpp
parenta6d9f274454c09b39d79a6300de85b4c99722770 (diff)
downloadsubsurface-ee7f579242568d86e7ec744c17585066c30fa943.tar.gz
Trying to make the DiveList selection behave correctly
And rip out all the code that Dirk put there to do that. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/divelistview.cpp')
-rw-r--r--qt-ui/divelistview.cpp59
1 files changed, 58 insertions, 1 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp
index 0bf0b35ba..af0ef8b0c 100644
--- a/qt-ui/divelistview.cpp
+++ b/qt-ui/divelistview.cpp
@@ -9,9 +9,66 @@
#include "modeldelegates.h"
#include <QApplication>
#include <QHeaderView>
+#include <QDebug>
+#include <QKeyEvent>
-DiveListView::DiveListView(QWidget *parent) : QTreeView(parent)
+
+DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelection(false)
{
setUniformRowHeights(true);
setItemDelegateForColumn(TreeItemDT::RATING, new StarWidgetsDelegate());
+
+}
+
+void DiveListView::setModel(QAbstractItemModel* model)
+{
+ QTreeView::setModel(model);
+}
+
+void DiveListView::setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags command)
+{
+ if (mouseClickSelection)
+ QTreeView::setSelection(rect, command);
+}
+
+void DiveListView::mousePressEvent(QMouseEvent* event)
+{
+ mouseClickSelection = true;
+ QTreeView::mousePressEvent(event);
+}
+
+void DiveListView::mouseReleaseEvent(QMouseEvent* event)
+{
+ mouseClickSelection = false;
+ QTreeView::mouseReleaseEvent(event);
+}
+
+void DiveListView::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected)
+{
+ Q_FOREACH(const QModelIndex& index, deselected.indexes()) {
+ const QAbstractItemModel *model = index.model();
+ struct dive *dive = (struct dive*) model->data(index, TreeItemDT::DIVE_ROLE).value<void*>();
+ if (!dive) { // is's a trip!
+ if (model->rowCount(index)) {
+ expand(index); // leave this - even if it looks like it shouldn't be here. looks like I'v found a Qt bug.
+ }
+ }
+ }
+
+ Q_FOREACH(const QModelIndex& index, selected.indexes()) {
+ const QAbstractItemModel *model = index.model();
+ struct dive *dive = (struct dive*) model->data(index, TreeItemDT::DIVE_ROLE).value<void*>();
+ if (!dive) { // is's a trip!
+ if (model->rowCount(index)) {
+ expand(index);
+ QItemSelection selection;
+ selection.select(index.child(0,0), index.child(model->rowCount(index) -1 , 0));
+ selectionModel()->select(selection, QItemSelectionModel::Select | QItemSelectionModel::Rows);
+ selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select | QItemSelectionModel::NoUpdate);
+ }
+ }
+ else {
+ expand(index.parent());
+ }
+ }
}