diff options
-rw-r--r-- | core/dive.h | 2 | ||||
-rw-r--r-- | core/divelist.h | 2 | ||||
-rw-r--r-- | core/divesite.c | 11 | ||||
-rw-r--r-- | core/divesite.h | 8 | ||||
-rw-r--r-- | core/subsurface-qt/DiveListNotifier.h | 5 | ||||
-rw-r--r-- | core/table.h | 3 | ||||
-rw-r--r-- | desktop-widgets/command_divelist.cpp | 6 | ||||
-rw-r--r-- | qt-models/divelocationmodel.cpp | 20 | ||||
-rw-r--r-- | qt-models/divelocationmodel.h | 2 |
9 files changed, 43 insertions, 16 deletions
diff --git a/core/dive.h b/core/dive.h index 2a66130b1..6d6ea5a90 100644 --- a/core/dive.h +++ b/core/dive.h @@ -407,7 +407,7 @@ struct dive *unregister_dive(int idx); extern void delete_single_dive(int idx); extern void insert_trip(dive_trip_t *trip, struct trip_table *trip_table_arg); -extern void remove_trip(const dive_trip_t *trip, struct trip_table *trip_table_arg); +extern int remove_trip(const dive_trip_t *trip, struct trip_table *trip_table_arg); extern void free_trip(dive_trip_t *trip); extern timestamp_t trip_date(const struct dive_trip *trip); diff --git a/core/divelist.h b/core/divelist.h index befbc780a..c09b8651a 100644 --- a/core/divelist.h +++ b/core/divelist.h @@ -38,7 +38,7 @@ extern void add_single_dive(int idx, struct dive *dive); extern void get_dive_gas(const struct dive *dive, int *o2_p, int *he_p, int *o2low_p); extern int get_divenr(const struct dive *dive); extern struct dive_trip *unregister_dive_from_trip(struct dive *dive); -extern void remove_dive(const struct dive *dive, struct dive_table *table); +extern int remove_dive(const struct dive *dive, struct dive_table *table); extern void remove_dive_from_trip(struct dive *dive, struct trip_table *trip_table_arg); extern dive_trip_t *alloc_trip(void); extern dive_trip_t *create_trip_from_dive(struct dive *dive); diff --git a/core/divesite.c b/core/divesite.c index 47a4852f3..892a2dd78 100644 --- a/core/divesite.c +++ b/core/divesite.c @@ -104,9 +104,9 @@ struct dive_site *get_dive_site_by_gps_proximity(const location_t *loc, int dist return res; } -void register_dive_site(struct dive_site *ds) +int register_dive_site(struct dive_site *ds) { - add_dive_site_to_table(ds, &dive_site_table); + return add_dive_site_to_table(ds, &dive_site_table); } static int compare_sites(const struct dive_site *a, const struct dive_site *b) @@ -127,7 +127,7 @@ static MAKE_GET_IDX(dive_site_table, struct dive_site *, dive_sites) MAKE_SORT(dive_site_table, struct dive_site *, dive_sites, compare_sites) static MAKE_REMOVE(dive_site_table, struct dive_site *, dive_site) -void add_dive_site_to_table(struct dive_site *ds, struct dive_site_table *ds_table) +int add_dive_site_to_table(struct dive_site *ds, struct dive_site_table *ds_table) { /* Take care to never have the same uuid twice. This could happen on * reimport of a log where the dive sites have diverged */ @@ -140,6 +140,7 @@ void add_dive_site_to_table(struct dive_site *ds, struct dive_site_table *ds_tab int idx = dive_site_table_get_insertion_index(ds_table, ds); add_to_dive_site_table(ds_table, idx, ds); + return idx; } struct dive_site *alloc_dive_site() @@ -197,9 +198,9 @@ void free_dive_site(struct dive_site *ds) } } -void unregister_dive_site(struct dive_site *ds) +int unregister_dive_site(struct dive_site *ds) { - remove_dive_site(ds, &dive_site_table); + return remove_dive_site(ds, &dive_site_table); } void delete_dive_site(struct dive_site *ds, struct dive_site_table *ds_table) diff --git a/core/divesite.h b/core/divesite.h index 49e6edea5..50bd0b406 100644 --- a/core/divesite.h +++ b/core/divesite.h @@ -47,16 +47,14 @@ static inline struct dive_site *get_dive_site(int nr, struct dive_site_table *ds int get_divesite_idx(const struct dive_site *ds, struct dive_site_table *ds_table); struct dive_site *get_dive_site_by_uuid(uint32_t uuid, struct dive_site_table *ds_table); void sort_dive_site_table(struct dive_site_table *ds_table); -void add_dive_site_to_table(struct dive_site *ds, struct dive_site_table *ds_table); -void register_dive_site(struct dive_site *ds); -void unregister_dive_site(struct dive_site *ds); +int add_dive_site_to_table(struct dive_site *ds, struct dive_site_table *ds_table); struct dive_site *alloc_or_get_dive_site(uint32_t uuid, struct dive_site_table *ds_table); struct dive_site *alloc_dive_site(); int nr_of_dives_at_dive_site(struct dive_site *ds); bool is_dive_site_used(struct dive_site *ds, bool select_only); void free_dive_site(struct dive_site *ds); -void unregister_dive_site(struct dive_site *ds); -void register_dive_site(struct dive_site *ds); +int unregister_dive_site(struct dive_site *ds); +int register_dive_site(struct dive_site *ds); void delete_dive_site(struct dive_site *ds, struct dive_site_table *ds_table); struct dive_site *create_dive_site(const char *name, struct dive_site_table *ds_table); struct dive_site *create_dive_site_with_gps(const char *name, const location_t *, struct dive_site_table *ds_table); diff --git a/core/subsurface-qt/DiveListNotifier.h b/core/subsurface-qt/DiveListNotifier.h index 124bde127..41a964955 100644 --- a/core/subsurface-qt/DiveListNotifier.h +++ b/core/subsurface-qt/DiveListNotifier.h @@ -43,7 +43,10 @@ signals: void currentDiveChanged(); void selectionChanged(); - // Dive site signals + // Dive site signals. Add and delete events are sent per dive site and + // provide an index into the global dive site table. + void diveSiteAdded(dive_site *ds, int idx); + void diveSiteDeleted(dive_site *ds, int idx); void diveSiteDiveCountChanged(dive_site *ds); public: // Desktop uses the QTreeView class to present the list of dives. The layout diff --git a/core/table.h b/core/table.h index 76074fe47..1abfa6be3 100644 --- a/core/table.h +++ b/core/table.h @@ -83,11 +83,12 @@ } #define MAKE_REMOVE(table_type, item_type, item_name) \ - void remove_##item_name(const item_type item, struct table_type *table) \ + int remove_##item_name(const item_type item, struct table_type *table) \ { \ int idx = get_idx_in_##table_type(table, item); \ if (idx >= 0) \ remove_from_##table_type(table, idx); \ + return idx; \ } #endif diff --git a/desktop-widgets/command_divelist.cpp b/desktop-widgets/command_divelist.cpp index 59dec85c3..8da0fab46 100644 --- a/desktop-widgets/command_divelist.cpp +++ b/desktop-widgets/command_divelist.cpp @@ -133,8 +133,9 @@ DivesAndTripsToAdd DiveListBase::removeDives(DivesAndSitesToRemove &divesAndSite divesAndSitesToDelete.dives.clear(); for (dive_site *ds: divesAndSitesToDelete.sites) { - unregister_dive_site(ds); + int idx = unregister_dive_site(ds); sitesToAdd.emplace_back(ds); + emit diveListNotifier.diveSiteDeleted(ds, idx); } divesAndSitesToDelete.sites.clear(); @@ -188,7 +189,8 @@ DivesAndSitesToRemove DiveListBase::addDives(DivesAndTripsToAdd &toAdd) // Finally, add any necessary dive sites for (OwningDiveSitePtr &ds: toAdd.sites) { sites.push_back(ds.get()); - register_dive_site(ds.release()); // Return ownership to backend + int idx = register_dive_site(ds.release()); // Return ownership to backend + emit diveListNotifier.diveSiteAdded(sites.back(), idx); } toAdd.sites.clear(); diff --git a/qt-models/divelocationmodel.cpp b/qt-models/divelocationmodel.cpp index 03c07a5e0..0a0eacaaf 100644 --- a/qt-models/divelocationmodel.cpp +++ b/qt-models/divelocationmodel.cpp @@ -25,6 +25,8 @@ LocationInformationModel *LocationInformationModel::instance() LocationInformationModel::LocationInformationModel(QObject *obj) : QAbstractTableModel(obj) { connect(&diveListNotifier, &DiveListNotifier::diveSiteDiveCountChanged, this, &LocationInformationModel::diveSiteDiveCountChanged); + connect(&diveListNotifier, &DiveListNotifier::diveSiteAdded, this, &LocationInformationModel::diveSiteAdded); + connect(&diveListNotifier, &DiveListNotifier::diveSiteDeleted, this, &LocationInformationModel::diveSiteDeleted); } int LocationInformationModel::columnCount(const QModelIndex &) const @@ -163,6 +165,24 @@ void LocationInformationModel::diveSiteDiveCountChanged(dive_site *ds) dataChanged(createIndex(idx, NUM_DIVES), createIndex(idx, NUM_DIVES)); } +void LocationInformationModel::diveSiteAdded(struct dive_site *, int idx) +{ + if (idx < 0) + return; + beginInsertRows(QModelIndex(), idx, idx); + // Row has already been added by Undo-Command. + endInsertRows(); +} + +void LocationInformationModel::diveSiteDeleted(struct dive_site *, int idx) +{ + if (idx < 0) + return; + beginRemoveRows(QModelIndex(), idx, idx); + // Row has already been added by Undo-Command. + endRemoveRows(); +} + GeoReferencingOptionsModel *GeoReferencingOptionsModel::instance() { static GeoReferencingOptionsModel *self = new GeoReferencingOptionsModel(); diff --git a/qt-models/divelocationmodel.h b/qt-models/divelocationmodel.h index 794056324..8f2e25190 100644 --- a/qt-models/divelocationmodel.h +++ b/qt-models/divelocationmodel.h @@ -34,6 +34,8 @@ public slots: void update(); QStringList allSiteNames() const; void diveSiteDiveCountChanged(struct dive_site *ds); + void diveSiteAdded(struct dive_site *ds, int idx); + void diveSiteDeleted(struct dive_site *ds, int idx); private: QStringList locationNames; }; |