aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/divelist.c11
-rw-r--r--desktop-widgets/divelistview.cpp11
-rw-r--r--qt-models/divetripmodel.cpp16
-rw-r--r--qt-models/divetripmodel.h3
4 files changed, 29 insertions, 12 deletions
diff --git a/core/divelist.c b/core/divelist.c
index 902bbb5ac..1c6ad9fc0 100644
--- a/core/divelist.c
+++ b/core/divelist.c
@@ -1065,9 +1065,9 @@ struct dive *unregister_dive(int idx)
if (!dive)
return NULL; /* this should never happen */
remove_dive_from_trip(dive, false);
- if (dive->selected)
- deselect_dive(idx);
unregister_dive_from_table(&dive_table, idx);
+ if (dive->selected)
+ amount_selected--;
return dive;
}
@@ -1075,7 +1075,12 @@ struct dive *unregister_dive(int idx)
* but doesn't deal with updating dive trips, etc */
void delete_single_dive(int idx)
{
- struct dive *dive = unregister_dive(idx);
+ struct dive *dive = get_dive(idx);
+ if (!dive)
+ return; /* this should never happen */
+ if (dive->selected)
+ deselect_dive(idx);
+ dive = unregister_dive(idx);
free_dive(dive);
}
diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp
index e8c6ea0dc..ebeb1f6ef 100644
--- a/desktop-widgets/divelistview.cpp
+++ b/desktop-widgets/divelistview.cpp
@@ -181,10 +181,19 @@ void DiveListView::rowsInserted(const QModelIndex &parent, int start, int end)
// First, let the QTreeView do its thing.
QTreeView::rowsInserted(parent, start, end);
+ QAbstractItemModel *m = model();
+ QItemSelectionModel *s = selectionModel();
+
+ // Check whether any of the items is selected
+ for (int i = start; i <= end; ++i) {
+ QModelIndex index = m->index(i, 0, parent);
+ if (m->data(index, DiveTripModel::SELECTED_ROLE).toBool())
+ s->select(index, QItemSelectionModel::Select | QItemSelectionModel::Rows);
+ }
+
// Now check for each inserted row whether this is a trip and expand the first column
if (parent.isValid()) // Trips don't have a parent
return;
- QAbstractItemModel *m = model();
for (int i = start; i <= end; ++i) {
if (m->rowCount(m->index(i, 0)) != 0)
setFirstColumnSpanned(i, QModelIndex(), true);
diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp
index 7a2c6d68d..f8b5e0deb 100644
--- a/qt-models/divetripmodel.cpp
+++ b/qt-models/divetripmodel.cpp
@@ -297,16 +297,18 @@ QVariant DiveItem::data(int column, int role) const
break;
}
break;
- }
-
- if (role == DiveTripModel::STAR_ROLE) {
+ case DiveTripModel::STAR_ROLE:
retVal = d->rating;
- }
- if (role == DiveTripModel::DIVE_ROLE) {
+ break;
+ case DiveTripModel::DIVE_ROLE:
retVal = QVariant::fromValue<void *>(d);
- }
- if (role == DiveTripModel::DIVE_IDX) {
+ break;
+ case DiveTripModel::DIVE_IDX:
retVal = get_divenr(d);
+ break;
+ case DiveTripModel::SELECTED_ROLE:
+ retVal = d->selected;
+ break;
}
return retVal;
}
diff --git a/qt-models/divetripmodel.h b/qt-models/divetripmodel.h
index a298b1e72..aa2e046d7 100644
--- a/qt-models/divetripmodel.h
+++ b/qt-models/divetripmodel.h
@@ -88,7 +88,8 @@ public:
DIVE_ROLE,
TRIP_ROLE,
SORT_ROLE,
- DIVE_IDX
+ DIVE_IDX,
+ SELECTED_ROLE
};
enum Layout {
TREE,