mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
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>
This commit is contained in:
parent
8c89f6fe15
commit
a9bd0690fe
6 changed files with 63 additions and 13 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
QStringList res = s.split(",", QString::SkipEmptyParts);
|
||||
for (QString &str: res)
|
||||
str = str.trimmed();
|
||||
return res;
|
||||
}
|
||||
|
||||
void MainTab::on_buddy_editingFinished()
|
||||
{
|
||||
if (editMode == IGNORE || acceptingEdit == true || !current_dive)
|
||||
return;
|
||||
|
||||
if (same_string(displayed_dive.buddy, qPrintable(ui.buddy->toPlainText())))
|
||||
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()
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue