aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-05-02 12:18:12 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-05-02 17:02:21 -0700
commit02ed0ccabb88118f0e1fb56d1ef57d247fedebdc (patch)
tree6ae45ad55c598f9f0b678072213115d6a0a73466
parente077206bb8aa5a08945b56da1b4dafa32acb6c65 (diff)
downloadsubsurface-02ed0ccabb88118f0e1fb56d1ef57d247fedebdc.tar.gz
Improve multi dive tag list edits
The old behavior was kind of crude. Just smack the tags that were on the displayed dive on all selected dives. This seems to make more sense. We figure out which tags were added to the displayed dive and add them to all selected dives. And we remove all tags that were removed from the displayed dive from all selected dives. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--qt-ui/maintab.cpp36
1 files changed, 31 insertions, 5 deletions
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 88cfd8849..2fafb65ff 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -1091,23 +1091,49 @@ void MainTab::on_timeEdit_timeChanged(const QTime &time)
}
// changing the tags on multiple dives is semantically strange - what's the right thing to do?
+// here's what I think... add the tags that were added to the displayed dive and remove the tags
+// that were removed from it
void MainTab::saveTags()
{
struct dive *cd = current_dive;
+ struct tag_entry *added_list = NULL;
+ struct tag_entry *removed_list = NULL;
+ struct tag_entry *tl;
+
taglist_free(displayed_dive.tag_list);
displayed_dive.tag_list = NULL;
Q_FOREACH (const QString& tag, ui.tagWidget->getBlockStringList())
taglist_add_tag(&displayed_dive.tag_list, tag.toUtf8().data());
taglist_cleanup(&displayed_dive.tag_list);
+
+ // figure out which tags were added and which tags were removed
+ added_list = taglist_added(cd->tag_list, displayed_dive.tag_list);
+ removed_list = taglist_added(displayed_dive.tag_list, cd->tag_list);
+ // dump_taglist("added tags:", added_list);
+ // dump_taglist("removed tags:", removed_list);
+
// we need to check if the tags were changed before just overwriting them
- if (taglist_equal(displayed_dive.tag_list, cd->tag_list))
+ if (added_list == NULL && removed_list == NULL)
return;
+
MODIFY_SELECTED_DIVES(
- QString tag;
+ // create a new tag list and all the existing tags that were not
+ // removed and then all the added tags
+ struct tag_entry *new_tag_list;
+ new_tag_list = NULL;
+ tl = mydive->tag_list;
+ while (tl) {
+ if (!taglist_contains(removed_list, tl->tag->name))
+ taglist_add_tag(&new_tag_list, tl->tag->name);
+ tl = tl->next;
+ }
+ tl = added_list;
+ while (tl) {
+ taglist_add_tag(&new_tag_list, tl->tag->name);
+ tl = tl->next;
+ }
taglist_free(mydive->tag_list);
- mydive->tag_list = NULL;
- Q_FOREACH (tag, ui.tagWidget->getBlockStringList())
- taglist_add_tag(&mydive->tag_list, tag.toUtf8().data());
+ mydive->tag_list = new_tag_list;
);
}