From dea58bd67cd72897d6aa38470322064947ffca08 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 11 Mar 2022 21:45:46 +0100 Subject: [PATCH] profile: automatically enter edit mode The edit mode was hidden in a context-menu. With fine-grained undo there seems to be no need to explicitly exit edit mode. Therefore, always switch to edit mode when displaying a manually added dive. Signed-off-by: Berthold Stoeger --- desktop-widgets/profilewidget.cpp | 23 ++++++++++++----------- desktop-widgets/profilewidget.h | 2 +- profile-widget/profilewidget2.cpp | 3 --- profile-widget/profilewidget2.h | 1 - 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/desktop-widgets/profilewidget.cpp b/desktop-widgets/profilewidget.cpp index 71a1c0dcd..6785ca8b5 100644 --- a/desktop-widgets/profilewidget.cpp +++ b/desktop-widgets/profilewidget.cpp @@ -119,7 +119,6 @@ ProfileWidget::ProfileWidget() : originalDive(nullptr), placingCommand(false) connect(&diveListNotifier, &DiveListNotifier::divesChanged, this, &ProfileWidget::divesChanged); connect(&diveListNotifier, &DiveListNotifier::settingsChanged, view.get(), &ProfileWidget2::settingsChanged); - connect(view.get(), &ProfileWidget2::editCurrentDive, this, &ProfileWidget::editDive); connect(view.get(), &ProfileWidget2::stopAdded, this, &ProfileWidget::stopAdded); connect(view.get(), &ProfileWidget2::stopRemoved, this, &ProfileWidget::stopRemoved); connect(view.get(), &ProfileWidget2::stopMoved, this, &ProfileWidget::stopMoved); @@ -185,11 +184,21 @@ void ProfileWidget::setDive(const struct dive *d) void ProfileWidget::plotCurrentDive() { // Exit edit mode if the dive changed - if (editedDive && originalDive != current_dive) + if (editedDive && (originalDive != current_dive || editedDc != dc_number)) exitEditMode(); + // If this is a manually added dive and we are not in the planner + // or already editing the dive, switch to edit mode. + if (current_dive && !editedDive && + DivePlannerPointsModel::instance()->currentMode() == DivePlannerPointsModel::NOTHING) { + struct divecomputer *dc = get_dive_dc(current_dive, dc_number); + if (dc && same_string(dc->model, "manually added dive") && dc->samples) + editDive(); + } + setEnabledToolbar(current_dive != nullptr); if (editedDive) { + setDive(current_dive); view->plotDive(editedDive.get(), editedDc); } else if (current_dive) { setDive(current_dive); @@ -244,21 +253,13 @@ void ProfileWidget::unsetProfTissues() void ProfileWidget::editDive() { - // We only allow editing of the profile for manually added dives - // and when no other editing is in progress. - if (!current_dive || - (!same_string(current_dive->dc.model, "manually added dive") && current_dive->dc.samples) || - (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING) || - editedDive) - return; - editedDive.reset(alloc_dive()); editedDc = dc_number; copy_dive(current_dive, editedDive.get()); // Work on a copy of the dive originalDive = current_dive; DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD); DivePlannerPointsModel::instance()->loadFromDive(editedDive.get()); - view->setEditState(editedDive.get(), 0); + view->setEditState(editedDive.get(), editedDc); } void ProfileWidget::exitEditMode() diff --git a/desktop-widgets/profilewidget.h b/desktop-widgets/profilewidget.h index cdbd0baf3..0af81d13b 100644 --- a/desktop-widgets/profilewidget.h +++ b/desktop-widgets/profilewidget.h @@ -48,7 +48,7 @@ private: void editDive(); void exitEditMode(); std::unique_ptr editedDive; - int editedDc; + unsigned int editedDc; dive *originalDive; bool placingCommand; }; diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index b84d8176f..ba17e4b23 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -589,9 +589,6 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event) changeMode->addAction(gettextFromC::tr(divemode_text_ui[PSCR]), [this, seconds](){ addDivemodeSwitch(seconds, PSCR); }); - if (same_string(get_dive_dc_const(d, dc)->model, "manually added dive") || !get_dive_dc_const(d, dc)->samples) - m.addAction(tr("Edit the profile"), this, &ProfileWidget2::editCurrentDive); - if (DiveEventItem *item = dynamic_cast(sceneItem)) { m.addAction(tr("Remove event"), [this,item] { removeEvent(item); }); m.addAction(tr("Hide similar events"), [this, item] { hideEvents(item); }); diff --git a/profile-widget/profilewidget2.h b/profile-widget/profilewidget2.h index c613063ee..474e05870 100644 --- a/profile-widget/profilewidget2.h +++ b/profile-widget/profilewidget2.h @@ -65,7 +65,6 @@ public: State currentState; signals: - void editCurrentDive(); void stopAdded(); // only emitted in edit mode void stopRemoved(int count); // only emitted in edit mode void stopMoved(int count); // only emitted in edit mode