From d449ac3208a0e923aa5500295d2f4ab842dc84cc Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Tue, 10 Feb 2015 06:31:37 -0800 Subject: Only update tags in the selected dives if they were changed If current_dive and displayed_dive still have the same tags then we shouldn't touch the tags of other selected dives. Fixes #826 Signed-off-by: Dirk Hohndel --- dive.c | 18 ++++++++++++++++++ dive.h | 1 + qt-ui/maintab.cpp | 3 +++ 3 files changed, 22 insertions(+) diff --git a/dive.c b/dive.c index c120dde0e..aebeeca2e 100644 --- a/dive.c +++ b/dive.c @@ -2618,6 +2618,24 @@ bool taglist_contains(struct tag_entry *tag_list, const char *tag) return false; } +// check if all tags in subtl are included in supertl (so subtl is a subset of supertl) +static bool taglist_contains_all(struct tag_entry *subtl, struct tag_entry *supertl) +{ + while (subtl) { + if (!taglist_contains(supertl, subtl->tag->name)) + return false; + subtl = subtl->next; + } + return true; + +} + +// if tl1 is both a subset and superset of tl2 they must be the same +bool taglist_equal(struct tag_entry *tl1, struct tag_entry *tl2) +{ + return taglist_contains_all(tl1, tl2) && taglist_contains_all(tl2, tl1); +} + // count the dives where the tag list contains the given tag int count_dives_with_tag(const char *tag) { diff --git a/dive.h b/dive.h index 56f38f948..b350527a7 100644 --- a/dive.h +++ b/dive.h @@ -238,6 +238,7 @@ void taglist_init_global(); void taglist_free(struct tag_entry *tag_list); bool taglist_contains(struct tag_entry *tag_list, const char *tag); +bool taglist_equal(struct tag_entry *tl1, struct tag_entry *tl2); int count_dives_with_tag(const char *tag); int count_dives_with_person(const char *person); int count_dives_with_location(const char *location); diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 00aae5f29..88cfd8849 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -1099,6 +1099,9 @@ void MainTab::saveTags() Q_FOREACH (const QString& tag, ui.tagWidget->getBlockStringList()) taglist_add_tag(&displayed_dive.tag_list, tag.toUtf8().data()); taglist_cleanup(&displayed_dive.tag_list); + // we need to check if the tags were changed before just overwriting them + if (taglist_equal(displayed_dive.tag_list, cd->tag_list)) + return; MODIFY_SELECTED_DIVES( QString tag; taglist_free(mydive->tag_list); -- cgit v1.2.3-70-g09d2