diff options
-rw-r--r-- | desktop-widgets/command.cpp | 5 | ||||
-rw-r--r-- | desktop-widgets/command.h | 1 | ||||
-rw-r--r-- | desktop-widgets/command_divesite.cpp | 23 | ||||
-rw-r--r-- | desktop-widgets/command_divesite.h | 12 | ||||
-rw-r--r-- | desktop-widgets/locationinformation.cpp | 17 | ||||
-rw-r--r-- | desktop-widgets/locationinformation.h | 2 | ||||
-rw-r--r-- | desktop-widgets/locationinformation.ui | 6 |
7 files changed, 53 insertions, 13 deletions
diff --git a/desktop-widgets/command.cpp b/desktop-widgets/command.cpp index 1d34d268b..f476a66d0 100644 --- a/desktop-widgets/command.cpp +++ b/desktop-widgets/command.cpp @@ -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)); diff --git a/desktop-widgets/command.h b/desktop-widgets/command.h index 4f89eb4c0..38b97121b 100644 --- a/desktop-widgets/command.h +++ b/desktop-widgets/command.h @@ -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 diff --git a/desktop-widgets/command_divesite.cpp b/desktop-widgets/command_divesite.cpp index b3a4911e5..5d32a902d 100644 --- a/desktop-widgets/command_divesite.cpp +++ b/desktop-widgets/command_divesite.cpp @@ -159,4 +159,27 @@ void EditDiveSiteDescription::undo() 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 diff --git a/desktop-widgets/command_divesite.h b/desktop-widgets/command_divesite.h index f436a84b4..ef3b2506f 100644 --- a/desktop-widgets/command_divesite.h +++ b/desktop-widgets/command_divesite.h @@ -67,6 +67,18 @@ private: 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 #endif // COMMAND_DIVESITE_H diff --git a/desktop-widgets/locationinformation.cpp b/desktop-widgets/locationinformation.cpp index 28f3fa619..f02b45bd0 100644 --- a/desktop-widgets/locationinformation.cpp +++ b/desktop-widgets/locationinformation.cpp @@ -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() diff --git a/desktop-widgets/locationinformation.h b/desktop-widgets/locationinformation.h index b97ceca18..86b82c3e3 100644 --- a/desktop-widgets/locationinformation.h +++ b/desktop-widgets/locationinformation.h @@ -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: diff --git a/desktop-widgets/locationinformation.ui b/desktop-widgets/locationinformation.ui index 38da223fd..10ffe8ff2 100644 --- a/desktop-widgets/locationinformation.ui +++ b/desktop-widgets/locationinformation.ui @@ -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> |