From b1d53481ad5f28290ed932fcb2a34ea827b819ef Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Tue, 17 Aug 2021 11:19:41 -0700 Subject: profile: use undo infrastructure for editing nicknames This does the right thing even when removing a nickname by setting it to an empty string. The oddly named DiveListNotifier handles the need to redraw the profile when the name changes. Signed-off-by: Dirk Hohndel --- profile-widget/profilewidget2.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index 7f90c065f..ba29a9640 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -164,6 +164,7 @@ ProfileWidget2::ProfileWidget2(DivePlannerPointsModel *plannerModelIn, QWidget * connect(&diveListNotifier, &DiveListNotifier::eventsChanged, this, &ProfileWidget2::profileChanged); connect(&diveListNotifier, &DiveListNotifier::pictureOffsetChanged, this, &ProfileWidget2::pictureOffsetChanged); connect(&diveListNotifier, &DiveListNotifier::divesChanged, this, &ProfileWidget2::divesChanged); + connect(&diveListNotifier, &DiveListNotifier::deviceEdited, this, &ProfileWidget2::replot); #endif // SUBSURFACE_MOBILE #if !defined(QT_NO_DEBUG) && defined(SHOW_PLOT_INFO_TABLE) @@ -1451,14 +1452,8 @@ void ProfileWidget2::renameCurrentDC() QString newName = QInputDialog::getText(this, tr("Edit nickname"), tr("Set new nickname for %1 (serial %2):").arg(current_dc->model).arg(current_dc->serial), QLineEdit::Normal, get_dc_nickname(current_dc), &ok); - if (ok) { - // this needs to happen using the Undo code - // note that an empty nickname is valid - it simply removes the nickname for this dive computer - create_device_node(&device_table, current_dc->model, current_dc->serial, qPrintable(newName)); - - // now trigger the redraw of the profile with the updated nickname - } - + if (ok) + Command::editDeviceNickname(current_dc, newName); } void ProfileWidget2::hideEvents(DiveEventItem *item) -- cgit v1.2.3-70-g09d2