aboutsummaryrefslogtreecommitdiffstats
path: root/qt-ui/divelistview.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-06-14 06:17:38 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-06-14 06:17:38 -0700
commitd8c5f366c81b5e94fa1931cd994c97d5ec493a75 (patch)
tree1cf460b8f67fe2786bdc382b2d26b26205ba1984 /qt-ui/divelistview.cpp
parent5e51d1e354b2ea31f3fc735a836ac39a7ff89dd5 (diff)
downloadsubsurface-d8c5f366c81b5e94fa1931cd994c97d5ec493a75.tar.gz
First deselect, then select
For reasons I still don't understand, sometimes (but not always) when clicking on a trip header we appear to get a select notification for the trip and at the same time deselect notifications for every dive in the trip. This seems wrong but I can't seem to figure out why it happens - and of course it causes us to have a mixed up interpretation of what is selected in our internal selection tracking. Simply acting on the new selection after the newly deselected items are handled appears to fix the issue, but I do worry about this change. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/divelistview.cpp')
-rw-r--r--qt-ui/divelistview.cpp27
1 files changed, 13 insertions, 14 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp
index 744f3d911..980939355 100644
--- a/qt-ui/divelistview.cpp
+++ b/qt-ui/divelistview.cpp
@@ -245,48 +245,47 @@ void DiveListView::selectionChanged(const QItemSelection& selected, const QItemS
disconnect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(selectionChanged(QItemSelection,QItemSelection)));
disconnect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(currentChanged(QModelIndex,QModelIndex)));
- Q_FOREACH(const QModelIndex& index, newSelected.indexes()) {
+ Q_FOREACH(const QModelIndex& index, newDeselected.indexes()) {
if (index.column() != 0)
continue;
-
const QAbstractItemModel *model = index.model();
struct dive *dive = (struct dive*) model->data(index, TreeItemDT::DIVE_ROLE).value<void*>();
if (!dive) { // it's a trip!
if (model->rowCount(index)) {
- QItemSelection selection;
struct dive *child = (struct dive*) model->data(index.child(0,0), TreeItemDT::DIVE_ROLE).value<void*>();
while (child) {
- select_dive(get_index_for_dive(child));
+ deselect_dive(get_index_for_dive(child));
child = child->next;
}
- 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);
- if (!isExpanded(index))
- expand(index);
}
} else {
- select_dive(get_index_for_dive(dive));
+ deselect_dive(get_index_for_dive(dive));
}
}
- Q_FOREACH(const QModelIndex& index, newDeselected.indexes()) {
+ Q_FOREACH(const QModelIndex& index, newSelected.indexes()) {
if (index.column() != 0)
continue;
+
const QAbstractItemModel *model = index.model();
struct dive *dive = (struct dive*) model->data(index, TreeItemDT::DIVE_ROLE).value<void*>();
if (!dive) { // it's a trip!
if (model->rowCount(index)) {
+ QItemSelection selection;
struct dive *child = (struct dive*) model->data(index.child(0,0), TreeItemDT::DIVE_ROLE).value<void*>();
while (child) {
- deselect_dive(get_index_for_dive(child));
+ select_dive(get_index_for_dive(child));
child = child->next;
}
+ 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);
+ if (!isExpanded(index))
+ expand(index);
}
} else {
- deselect_dive(get_index_for_dive(dive));
+ select_dive(get_index_for_dive(dive));
}
}
-
QTreeView::selectionChanged(selectionModel()->selection(), newDeselected);
connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(selectionChanged(QItemSelection,QItemSelection)));
connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(currentChanged(QModelIndex,QModelIndex)));