aboutsummaryrefslogtreecommitdiffstats
path: root/desktop-widgets
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-02-07 21:00:09 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-04-12 18:19:07 +0300
commita9bd0690fe1d6bd841b0ede2ac53b280ef907b93 (patch)
tree663bd078f59c8e08902b31fe59395b7327728ee7 /desktop-widgets
parent8c89f6fe1520d9d88fb81acab995ba803f5c4ac1 (diff)
downloadsubsurface-a9bd0690fe1d6bd841b0ede2ac53b280ef907b93.tar.gz
Undo: implement undo of buddy editing
This was mostly trivial by reusing the code for tag-editing. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets')
-rw-r--r--desktop-widgets/command.cpp5
-rw-r--r--desktop-widgets/command.h1
-rw-r--r--desktop-widgets/command_edit.cpp33
-rw-r--r--desktop-widgets/command_edit.h9
-rw-r--r--desktop-widgets/tab-widgets/maintab.cpp24
-rw-r--r--desktop-widgets/tab-widgets/maintab.h2
6 files changed, 62 insertions, 12 deletions
diff --git a/desktop-widgets/command.cpp b/desktop-widgets/command.cpp
index 0f08d0637..f1c0a67dd 100644
--- a/desktop-widgets/command.cpp
+++ b/desktop-widgets/command.cpp
@@ -180,4 +180,9 @@ void editTags(const QVector<dive *> &dives, const QStringList &newList, struct d
execute(new EditTags(dives, newList, d));
}
+void editBuddies(const QVector<dive *> &dives, const QStringList &newList, struct dive *d)
+{
+ execute(new EditBuddies(dives, newList, d));
+}
+
} // namespace Command
diff --git a/desktop-widgets/command.h b/desktop-widgets/command.h
index e94023c81..4ab07b132 100644
--- a/desktop-widgets/command.h
+++ b/desktop-widgets/command.h
@@ -62,6 +62,7 @@ void editWaterTemp(const QVector<dive *> dives, int newValue, int oldValue);
void editDiveSite(const QVector<dive *> dives, struct dive_site *newValue, struct dive_site *oldValue);
void editDiveSiteNew(const QVector<dive *> dives, const QString &newName, struct dive_site *oldValue);
void editTags(const QVector<dive *> &dives, const QStringList &newList, struct dive *d);
+void editBuddies(const QVector<dive *> &dives, const QStringList &newList, struct dive *d);
} // namespace Command
diff --git a/desktop-widgets/command_edit.cpp b/desktop-widgets/command_edit.cpp
index c3a47016e..165bbbe90 100644
--- a/desktop-widgets/command_edit.cpp
+++ b/desktop-widgets/command_edit.cpp
@@ -3,6 +3,7 @@
#include "command_edit.h"
#include "core/divelist.h"
#include "core/qthelper.h" // for copy_qstring
+#include "desktop-widgets/mapwidget.h" // TODO: Replace desktop-dependency by signal
namespace Command {
@@ -450,4 +451,36 @@ DiveField EditTags::fieldId() const
return DiveField::TAGS;
}
+// String list helper
+static QStringList stringToList(const QString &s)
+{
+ QStringList res = s.split(",", QString::SkipEmptyParts);
+ for (QString &str: res)
+ str = str.trimmed();
+ return res;
+}
+
+// ***** Buddies *****
+QStringList EditBuddies::data(struct dive *d) const
+{
+ return stringToList(d->buddy);
+}
+
+void EditBuddies::set(struct dive *d, const QStringList &v) const
+{
+ QString text = v.join(", ");
+ free(d->buddy);
+ d->buddy = copy_qstring(text);
+}
+
+QString EditBuddies::fieldName() const
+{
+ return tr("buddies");
+}
+
+DiveField EditBuddies::fieldId() const
+{
+ return DiveField::BUDDY;
+}
+
} // namespace Command
diff --git a/desktop-widgets/command_edit.h b/desktop-widgets/command_edit.h
index fab951799..d77c46a27 100644
--- a/desktop-widgets/command_edit.h
+++ b/desktop-widgets/command_edit.h
@@ -173,6 +173,15 @@ public:
DiveField fieldId() const override;
};
+class EditBuddies : public EditTagsBase {
+public:
+ using EditTagsBase::EditTagsBase; // Use constructor of base class.
+ QStringList data(struct dive *d) const override;
+ void set(struct dive *d, const QStringList &v) const override;
+ QString fieldName() const override;
+ DiveField fieldId() const override;
+};
+
} // namespace Command
#endif
diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp
index 19fa56332..eff22192b 100644
--- a/desktop-widgets/tab-widgets/maintab.cpp
+++ b/desktop-widgets/tab-widgets/maintab.cpp
@@ -375,6 +375,9 @@ void MainTab::divesEdited(const QVector<dive *> &, DiveField field)
case DiveField::TAGS:
ui.tagWidget->setText(get_taglist_string(current_dive->tag_list));
break;
+ case DiveField::BUDDY:
+ ui.buddy->setText(current_dive->buddy);
+ break;
default:
break;
}
@@ -979,21 +982,20 @@ void MainTab::markChangedWidget(QWidget *w)
modified = true;
}
-void MainTab::on_buddy_textChanged()
+static QStringList stringToList(const QString &s)
{
- if (editMode == IGNORE || acceptingEdit == true)
- return;
+ QStringList res = s.split(",", QString::SkipEmptyParts);
+ for (QString &str: res)
+ str = str.trimmed();
+ return res;
+}
- if (same_string(displayed_dive.buddy, qPrintable(ui.buddy->toPlainText())))
+void MainTab::on_buddy_editingFinished()
+{
+ if (editMode == IGNORE || acceptingEdit == true || !current_dive)
return;
- QStringList text_list = ui.buddy->toPlainText().split(",", QString::SkipEmptyParts);
- for (int i = 0; i < text_list.size(); i++)
- text_list[i] = text_list[i].trimmed();
- QString text = text_list.join(", ");
- free(displayed_dive.buddy);
- displayed_dive.buddy = copy_qstring(text);
- markChangedWidget(ui.buddy);
+ Command::editBuddies(getSelectedDivesCurrentLast(), stringToList(ui.buddy->toPlainText()), current_dive);
}
void MainTab::on_divemaster_textChanged()
diff --git a/desktop-widgets/tab-widgets/maintab.h b/desktop-widgets/tab-widgets/maintab.h
index 3b9fa26d6..88c2b4738 100644
--- a/desktop-widgets/tab-widgets/maintab.h
+++ b/desktop-widgets/tab-widgets/maintab.h
@@ -75,7 +75,7 @@ slots:
void rejectChanges();
void on_location_diveSiteSelected();
void on_divemaster_textChanged();
- void on_buddy_textChanged();
+ void on_buddy_editingFinished();
void on_suit_editingFinished();
void on_diveTripLocation_textEdited(const QString& text);
void on_notes_textChanged();