Undo: implement undo of dive site notes editing

Simply copy the code of description editing.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2019-03-14 00:00:54 +01:00 committed by Dirk Hohndel
parent 2bb2643ae4
commit 4d183e0d75
7 changed files with 53 additions and 13 deletions

View file

@ -93,6 +93,11 @@ void editDiveSiteDescription(dive_site *ds, const QString &value)
execute(new EditDiveSiteDescription(ds, value));
}
void editDiveSiteNotes(dive_site *ds, const QString &value)
{
execute(new EditDiveSiteNotes(ds, value));
}
void addDiveSite(const QString &name)
{
execute(new AddDiveSite(name));

View file

@ -43,6 +43,7 @@ void mergeDives(const QVector <dive *> &dives);
void deleteDiveSites(const QVector <dive_site *> &sites);
void editDiveSiteName(dive_site *ds, const QString &value);
void editDiveSiteDescription(dive_site *ds, const QString &value);
void editDiveSiteNotes(dive_site *ds, const QString &value);
void addDiveSite(const QString &name);
} // namespace Command

View file

@ -159,4 +159,27 @@ void EditDiveSiteDescription::undo()
redo();
}
EditDiveSiteNotes::EditDiveSiteNotes(dive_site *dsIn, const QString &notes) : ds(dsIn),
value(notes)
{
setText(tr("Edit dive site notes"));
}
bool EditDiveSiteNotes::workToBeDone()
{
return value != QString(ds->notes);
}
void EditDiveSiteNotes::redo()
{
swap(ds->notes, value);
emit diveListNotifier.diveSiteChanged(ds, LocationInformationModel::NOTES); // Inform frontend of changed dive site.
}
void EditDiveSiteNotes::undo()
{
// Undo and redo do the same
redo();
}
} // namespace Command

View file

@ -67,6 +67,18 @@ private:
QString value; // Value to be set
};
class EditDiveSiteNotes : public Base {
public:
EditDiveSiteNotes(dive_site *ds, const QString &notes);
private:
bool workToBeDone() override;
void undo() override;
void redo() override;
dive_site *ds;
QString value; // Value to be set
};
} // namespace Command
#endif // COMMAND_DIVESITE_H

View file

@ -136,6 +136,9 @@ void LocationInformationWidget::diveSiteChanged(struct dive_site *ds, int field)
case LocationInformationModel::DESCRIPTION:
ui.diveSiteDescription->setText(diveSite->description);
return;
case LocationInformationModel::NOTES:
ui.diveSiteNotes->setText(diveSite->notes);
return;
default:
return;
}
@ -192,14 +195,6 @@ void LocationInformationWidget::acceptChanges()
// now update the diveSite
copy_taxonomy(&taxonomy, &diveSite->taxonomy);
uiString = copy_qstring(ui.diveSiteNotes->document()->toPlainText());
if (!same_string(uiString, diveSite->notes)) {
free(diveSite->notes);
diveSite->notes = uiString;
} else {
free(uiString);
}
if (!ui.diveSiteCoordinates->text().isEmpty())
parseGpsText(ui.diveSiteCoordinates->text(), diveSite->location);
mark_divelist_changed(true);
@ -300,10 +295,10 @@ void LocationInformationWidget::on_diveSiteName_editingFinished()
Command::editDiveSiteName(diveSite, ui.diveSiteName->text());
}
void LocationInformationWidget::on_diveSiteNotes_textChanged()
void LocationInformationWidget::on_diveSiteNotes_editingFinished()
{
if (diveSite && !same_string(qPrintable(ui.diveSiteNotes->toPlainText()), diveSite->notes))
markChangedWidget(ui.diveSiteNotes);
if (diveSite)
Command::editDiveSiteNotes(diveSite, ui.diveSiteNotes->toPlainText());
}
void LocationInformationWidget::resetPallete()

View file

@ -33,7 +33,7 @@ public slots:
void on_diveSiteCoordinates_textChanged(const QString& text);
void on_diveSiteDescription_editingFinished();
void on_diveSiteName_editingFinished();
void on_diveSiteNotes_textChanged();
void on_diveSiteNotes_editingFinished();
void reverseGeocode();
void mergeSelectedDiveSites();
private slots:

View file

@ -55,7 +55,7 @@
</widget>
</item>
<item row="7" column="2" rowspan="2" colspan="3">
<widget class="QPlainTextEdit" name="diveSiteNotes">
<widget class="TextEdit" name="diveSiteNotes">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
@ -179,6 +179,10 @@
<header>desktop-widgets/kmessagewidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>TextEdit</class>
<header>desktop-widgets/textedit.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>diveSiteName</tabstop>