mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
selection: add selection flag for trips
In analogy to dives add a selection flag for trips. The reason being that search for a selected trip can be painfully slow when we do it through Qt's proxy model. Make sure to deselect trips when they are removed from the core. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
649b2f2a9e
commit
09b7fcbcf4
4 changed files with 36 additions and 3 deletions
|
@ -13,6 +13,14 @@
|
||||||
|
|
||||||
namespace Command {
|
namespace Command {
|
||||||
|
|
||||||
|
// Helper function that takes care to unselect trips that are removed from the backend
|
||||||
|
static void remove_trip_from_backend(dive_trip *trip)
|
||||||
|
{
|
||||||
|
if (trip->selected)
|
||||||
|
deselect_trip(trip);
|
||||||
|
remove_trip(trip, &trip_table); // Remove trip from backend
|
||||||
|
}
|
||||||
|
|
||||||
// This helper function removes a dive, takes ownership of the dive and adds it to a DiveToAdd structure.
|
// This helper function removes a dive, takes ownership of the dive and adds it to a DiveToAdd structure.
|
||||||
// If the trip the dive belongs to becomes empty, it is removed and added to the tripsToAdd vector.
|
// If the trip the dive belongs to becomes empty, it is removed and added to the tripsToAdd vector.
|
||||||
// It is crucial that dives are added in reverse order of deletion, so that the indices are correctly
|
// It is crucial that dives are added in reverse order of deletion, so that the indices are correctly
|
||||||
|
@ -32,7 +40,7 @@ DiveToAdd DiveListBase::removeDive(struct dive *d, std::vector<OwningTripPtr> &t
|
||||||
diveSiteCountChanged(d->dive_site);
|
diveSiteCountChanged(d->dive_site);
|
||||||
res.site = unregister_dive_from_dive_site(d);
|
res.site = unregister_dive_from_dive_site(d);
|
||||||
if (res.trip && res.trip->dives.nr == 0) {
|
if (res.trip && res.trip->dives.nr == 0) {
|
||||||
remove_trip(res.trip, &trip_table); // Remove trip from backend
|
remove_trip_from_backend(res.trip); // Remove trip from backend
|
||||||
tripsToAdd.emplace_back(res.trip); // Take ownership of trip
|
tripsToAdd.emplace_back(res.trip); // Take ownership of trip
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,7 +273,7 @@ static OwningTripPtr moveDiveToTrip(DiveToTrip &diveToTrip)
|
||||||
// Remove dive from trip - if this is the last dive in the trip, remove the whole trip.
|
// Remove dive from trip - if this is the last dive in the trip, remove the whole trip.
|
||||||
dive_trip *trip = unregister_dive_from_trip(diveToTrip.dive);
|
dive_trip *trip = unregister_dive_from_trip(diveToTrip.dive);
|
||||||
if (trip && trip->dives.nr == 0) {
|
if (trip && trip->dives.nr == 0) {
|
||||||
remove_trip(trip, &trip_table); // Remove trip from backend
|
remove_trip_from_backend(trip); // Remove trip from backend
|
||||||
res.reset(trip);
|
res.reset(trip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,13 @@
|
||||||
|
|
||||||
#include "selection.h"
|
#include "selection.h"
|
||||||
#include "divelist.h"
|
#include "divelist.h"
|
||||||
#include "display.h" // for amount_selected
|
#include "trip.h"
|
||||||
#include "subsurface-qt/divelistnotifier.h"
|
#include "subsurface-qt/divelistnotifier.h"
|
||||||
|
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
int amount_selected;
|
int amount_selected;
|
||||||
|
static int amount_trips_selected;
|
||||||
|
|
||||||
extern "C" void select_dive(struct dive *dive)
|
extern "C" void select_dive(struct dive *dive)
|
||||||
{
|
{
|
||||||
|
@ -155,6 +156,11 @@ void setSelection(const std::vector<dive *> &selection, dive *currentDive)
|
||||||
QVector<dive *> divesToSelect;
|
QVector<dive *> divesToSelect;
|
||||||
divesToSelect.reserve(selection.size());
|
divesToSelect.reserve(selection.size());
|
||||||
|
|
||||||
|
// Since we select only dives, there are no selected trips!
|
||||||
|
amount_trips_selected = 0;
|
||||||
|
for (int i = 0; i < trip_table.nr; ++i)
|
||||||
|
trip_table.trips[i]->selected = false;
|
||||||
|
|
||||||
// TODO: We might want to keep track of selected dives in a more efficient way!
|
// TODO: We might want to keep track of selected dives in a more efficient way!
|
||||||
int i;
|
int i;
|
||||||
dive *d;
|
dive *d;
|
||||||
|
@ -231,3 +237,19 @@ extern "C" void select_newest_visible_dive()
|
||||||
// No visible dive -> deselect all
|
// No visible dive -> deselect all
|
||||||
select_single_dive(nullptr);
|
select_single_dive(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" void select_trip(struct dive_trip *trip)
|
||||||
|
{
|
||||||
|
if (trip && !trip->selected) {
|
||||||
|
trip->selected = true;
|
||||||
|
amount_trips_selected++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" void deselect_trip(struct dive_trip *trip)
|
||||||
|
{
|
||||||
|
if (trip && trip->selected) {
|
||||||
|
trip->selected = false;
|
||||||
|
amount_trips_selected--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -21,6 +21,8 @@ extern struct dive *last_selected_dive(void);
|
||||||
extern bool consecutive_selected(void);
|
extern bool consecutive_selected(void);
|
||||||
extern void select_newest_visible_dive();
|
extern void select_newest_visible_dive();
|
||||||
extern void select_single_dive(struct dive *d); // wrapper for setSelection() with a single dive. NULL clears the selection.
|
extern void select_single_dive(struct dive *d); // wrapper for setSelection() with a single dive. NULL clears the selection.
|
||||||
|
extern void select_trip(struct dive_trip *trip);
|
||||||
|
extern void deselect_trip(struct dive_trip *trip);
|
||||||
|
|
||||||
#if DEBUG_SELECTION_TRACKING
|
#if DEBUG_SELECTION_TRACKING
|
||||||
extern void dump_selection(void);
|
extern void dump_selection(void);
|
||||||
|
|
|
@ -17,6 +17,7 @@ typedef struct dive_trip
|
||||||
/* Used by the io-routines to mark trips that have already been written. */
|
/* Used by the io-routines to mark trips that have already been written. */
|
||||||
bool saved;
|
bool saved;
|
||||||
bool autogen;
|
bool autogen;
|
||||||
|
bool selected;
|
||||||
} dive_trip_t;
|
} dive_trip_t;
|
||||||
|
|
||||||
typedef struct trip_table {
|
typedef struct trip_table {
|
||||||
|
|
Loading…
Add table
Reference in a new issue