summaryrefslogtreecommitdiffstats
path: root/desktop-widgets/tab-widgets
diff options
context:
space:
mode:
Diffstat (limited to 'desktop-widgets/tab-widgets')
-rw-r--r--desktop-widgets/tab-widgets/maintab.cpp61
-rw-r--r--desktop-widgets/tab-widgets/maintab.h3
2 files changed, 8 insertions, 56 deletions
diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp
index 11ec9690b..19fa56332 100644
--- a/desktop-widgets/tab-widgets/maintab.cpp
+++ b/desktop-widgets/tab-widgets/maintab.cpp
@@ -372,6 +372,9 @@ void MainTab::divesEdited(const QVector<dive *> &, DiveField field)
updateDiveSite(current_dive);
emit diveSiteChanged();
break;
+ case DiveField::TAGS:
+ ui.tagWidget->setText(get_taglist_string(current_dive->tag_list));
+ break;
default:
break;
}
@@ -788,7 +791,6 @@ void MainTab::acceptChanges()
// three text fields are somewhat special and are represented as tags
// in the UI - they need somewhat smarter handling
saveTaggedStrings(selectedDives);
- saveTags(selectedDives);
if (cylindersModel->changed) {
mark_divelist_changed(true);
@@ -1108,57 +1110,11 @@ void MainTab::copyTagsToDisplayedDive()
{
taglist_free(displayed_dive.tag_list);
displayed_dive.tag_list = NULL;
- Q_FOREACH (const QString& tag, ui.tagWidget->getBlockStringList())
+ Q_FOREACH (const QString &tag, ui.tagWidget->getBlockStringList())
taglist_add_tag(&displayed_dive.tag_list, qPrintable(tag));
taglist_cleanup(&displayed_dive.tag_list);
}
-// 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(const QVector<dive *> &selectedDives)
-{
- struct dive *cd = current_dive;
- struct tag_entry *added_list = NULL;
- struct tag_entry *removed_list = NULL;
- struct tag_entry *tl;
-
- copyTagsToDisplayedDive();
-
- // figure out which tags were added and which tags were removed
- added_list = taglist_added(cd ? cd->tag_list : NULL, displayed_dive.tag_list);
- removed_list = taglist_added(displayed_dive.tag_list, cd ? cd->tag_list : NULL);
-
- // 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 (added_list == NULL && removed_list == NULL)
- return;
-
- MODIFY_DIVES(selectedDives,
- // 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 = new_tag_list;
- );
- taglist_free(added_list);
- taglist_free(removed_list);
-}
-
// buddy and divemaster are represented in the UI just like the tags, but the internal
// representation is just a string (with commas as delimiters). So we need to do the same
// thing we did for tags, just differently
@@ -1226,15 +1182,12 @@ int MainTab::diffTaggedStrings(QString currentString, QString displayedString, Q
return removedList.length() + addedList.length();
}
-void MainTab::on_tagWidget_textChanged()
+void MainTab::on_tagWidget_editingFinished()
{
- if (editMode == IGNORE || acceptingEdit == true)
- return;
-
- if (get_taglist_string(displayed_dive.tag_list) == ui.tagWidget->toPlainText())
+ if (editMode == IGNORE || acceptingEdit == true || !current_dive)
return;
- markChangedWidget(ui.tagWidget);
+ Command::editTags(getSelectedDivesCurrentLast(), ui.tagWidget->getBlockStringList(), current_dive);
}
void MainTab::on_location_diveSiteSelected()
diff --git a/desktop-widgets/tab-widgets/maintab.h b/desktop-widgets/tab-widgets/maintab.h
index 4bff215ce..3b9fa26d6 100644
--- a/desktop-widgets/tab-widgets/maintab.h
+++ b/desktop-widgets/tab-widgets/maintab.h
@@ -89,7 +89,7 @@ slots:
void on_timeEdit_timeChanged(const QTime & time);
void on_rating_valueChanged(int value);
void on_visibility_valueChanged(int value);
- void on_tagWidget_textChanged();
+ void on_tagWidget_editingFinished();
void editCylinderWidget(const QModelIndex &index);
void editWeightWidget(const QModelIndex &index);
void addDiveStarted();
@@ -119,7 +119,6 @@ private:
int lastTabSelectedDiveTrip;
void resetPallete();
void copyTagsToDisplayedDive();
- void saveTags(const QVector<dive *> &selectedDives);
void saveTaggedStrings(const QVector<dive *> &selectedDives);
int diffTaggedStrings(QString currentString, QString displayedString, QStringList &addedList, QStringList &removedList);
void markChangedWidget(QWidget *w);