From 5f11c94f02eca651e07f5a0c2cc4e55dcbf2df0b Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 12 Oct 2019 15:30:11 -0700 Subject: Mobile: improve helper function to track selected dives While on mobile there should always be only one selected dive, it's very cheap to make sure that amount_selected is tracked correctly. The incrementing of amount_selected is done in case an invalid id is passed in. Suggested-by: Berthold Stoeger Signed-off-by: Dirk Hohndel --- mobile-widgets/qmlmanager.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'mobile-widgets') diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index 08ce7fca7..aab3f1d08 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -1378,10 +1378,17 @@ bool QMLManager::undoDelete(int id) void QMLManager::selectDive(int id) { int i; + extern int amount_selected; struct dive *dive = NULL; - for_each_dive (i, dive) + amount_selected = 0; + for_each_dive (i, dive) { dive->selected = (dive->id == id); + if (dive->selected) + amount_selected++; + } + if (amount_selected == 0) + qWarning("QManager::selectDive() called with unknown id"); } void QMLManager::deleteDive(int id) -- cgit v1.2.3-70-g09d2