mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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:
parent
2bb2643ae4
commit
4d183e0d75
7 changed files with 53 additions and 13 deletions
|
@ -93,6 +93,11 @@ void editDiveSiteDescription(dive_site *ds, const QString &value)
|
||||||
execute(new EditDiveSiteDescription(ds, value));
|
execute(new EditDiveSiteDescription(ds, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void editDiveSiteNotes(dive_site *ds, const QString &value)
|
||||||
|
{
|
||||||
|
execute(new EditDiveSiteNotes(ds, value));
|
||||||
|
}
|
||||||
|
|
||||||
void addDiveSite(const QString &name)
|
void addDiveSite(const QString &name)
|
||||||
{
|
{
|
||||||
execute(new AddDiveSite(name));
|
execute(new AddDiveSite(name));
|
||||||
|
|
|
@ -43,6 +43,7 @@ void mergeDives(const QVector <dive *> &dives);
|
||||||
void deleteDiveSites(const QVector <dive_site *> &sites);
|
void deleteDiveSites(const QVector <dive_site *> &sites);
|
||||||
void editDiveSiteName(dive_site *ds, const QString &value);
|
void editDiveSiteName(dive_site *ds, const QString &value);
|
||||||
void editDiveSiteDescription(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);
|
void addDiveSite(const QString &name);
|
||||||
|
|
||||||
} // namespace Command
|
} // namespace Command
|
||||||
|
|
|
@ -159,4 +159,27 @@ void EditDiveSiteDescription::undo()
|
||||||
redo();
|
redo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EditDiveSiteNotes::EditDiveSiteNotes(dive_site *dsIn, const QString ¬es) : 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
|
} // namespace Command
|
||||||
|
|
|
@ -67,6 +67,18 @@ private:
|
||||||
QString value; // Value to be set
|
QString value; // Value to be set
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class EditDiveSiteNotes : public Base {
|
||||||
|
public:
|
||||||
|
EditDiveSiteNotes(dive_site *ds, const QString ¬es);
|
||||||
|
private:
|
||||||
|
bool workToBeDone() override;
|
||||||
|
void undo() override;
|
||||||
|
void redo() override;
|
||||||
|
|
||||||
|
dive_site *ds;
|
||||||
|
QString value; // Value to be set
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace Command
|
} // namespace Command
|
||||||
|
|
||||||
#endif // COMMAND_DIVESITE_H
|
#endif // COMMAND_DIVESITE_H
|
||||||
|
|
|
@ -136,6 +136,9 @@ void LocationInformationWidget::diveSiteChanged(struct dive_site *ds, int field)
|
||||||
case LocationInformationModel::DESCRIPTION:
|
case LocationInformationModel::DESCRIPTION:
|
||||||
ui.diveSiteDescription->setText(diveSite->description);
|
ui.diveSiteDescription->setText(diveSite->description);
|
||||||
return;
|
return;
|
||||||
|
case LocationInformationModel::NOTES:
|
||||||
|
ui.diveSiteNotes->setText(diveSite->notes);
|
||||||
|
return;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -192,14 +195,6 @@ void LocationInformationWidget::acceptChanges()
|
||||||
// now update the diveSite
|
// now update the diveSite
|
||||||
copy_taxonomy(&taxonomy, &diveSite->taxonomy);
|
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())
|
if (!ui.diveSiteCoordinates->text().isEmpty())
|
||||||
parseGpsText(ui.diveSiteCoordinates->text(), diveSite->location);
|
parseGpsText(ui.diveSiteCoordinates->text(), diveSite->location);
|
||||||
mark_divelist_changed(true);
|
mark_divelist_changed(true);
|
||||||
|
@ -300,10 +295,10 @@ void LocationInformationWidget::on_diveSiteName_editingFinished()
|
||||||
Command::editDiveSiteName(diveSite, ui.diveSiteName->text());
|
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))
|
if (diveSite)
|
||||||
markChangedWidget(ui.diveSiteNotes);
|
Command::editDiveSiteNotes(diveSite, ui.diveSiteNotes->toPlainText());
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocationInformationWidget::resetPallete()
|
void LocationInformationWidget::resetPallete()
|
||||||
|
|
|
@ -33,7 +33,7 @@ public slots:
|
||||||
void on_diveSiteCoordinates_textChanged(const QString& text);
|
void on_diveSiteCoordinates_textChanged(const QString& text);
|
||||||
void on_diveSiteDescription_editingFinished();
|
void on_diveSiteDescription_editingFinished();
|
||||||
void on_diveSiteName_editingFinished();
|
void on_diveSiteName_editingFinished();
|
||||||
void on_diveSiteNotes_textChanged();
|
void on_diveSiteNotes_editingFinished();
|
||||||
void reverseGeocode();
|
void reverseGeocode();
|
||||||
void mergeSelectedDiveSites();
|
void mergeSelectedDiveSites();
|
||||||
private slots:
|
private slots:
|
||||||
|
|
|
@ -55,7 +55,7 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="7" column="2" rowspan="2" colspan="3">
|
<item row="7" column="2" rowspan="2" colspan="3">
|
||||||
<widget class="QPlainTextEdit" name="diveSiteNotes">
|
<widget class="TextEdit" name="diveSiteNotes">
|
||||||
<property name="focusPolicy">
|
<property name="focusPolicy">
|
||||||
<enum>Qt::ClickFocus</enum>
|
<enum>Qt::ClickFocus</enum>
|
||||||
</property>
|
</property>
|
||||||
|
@ -179,6 +179,10 @@
|
||||||
<header>desktop-widgets/kmessagewidget.h</header>
|
<header>desktop-widgets/kmessagewidget.h</header>
|
||||||
<container>1</container>
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>TextEdit</class>
|
||||||
|
<header>desktop-widgets/textedit.h</header>
|
||||||
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<tabstops>
|
<tabstops>
|
||||||
<tabstop>diveSiteName</tabstop>
|
<tabstop>diveSiteName</tabstop>
|
||||||
|
|
Loading…
Add table
Reference in a new issue