summaryrefslogtreecommitdiffstats
path: root/qt-ui
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 12:18:12 -0700
commit4c588c1f00393bf7ecb8aa69e50f677a4074538d (patch)
treeeef321af9bf05a358a30ffc0859253048f2b3035 /qt-ui
parent51183f4ee7b78505af97bae9c28521cb6aed51b4 (diff)
downloadsubsurface-4c588c1f00393bf7ecb8aa69e50f677a4074538d.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>
Diffstat (limited to 'qt-ui')
-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 314626c5d..2dd33544c 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -1089,23 +1089,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;
);
}