From ecc6f64d10e9da2ad1a60b20498453e57dd39ed1 Mon Sep 17 00:00:00 2001 From: =Michael Keller Date: Sat, 25 May 2024 00:33:44 +1200 Subject: [PATCH] Cleanup: Improve Connection Handling in Profile. - improve naming; - remove unneeded disconnects. Signed-off-by: Michael Keller --- profile-widget/profilewidget2.cpp | 28 +++++++++++++--------------- profile-widget/profilewidget2.h | 2 +- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index ea99f1d2f..08194a57b 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -404,7 +404,7 @@ void ProfileWidget2::clear() #ifndef SUBSURFACE_MOBILE clearPictures(); #endif - disconnectTemporaryConnections(); + disconnectPlannerModel(); profileScene->clear(); handles.clear(); gases.clear(); @@ -426,7 +426,7 @@ void ProfileWidget2::setProfileState() if (currentState == PROFILE) return; - disconnectTemporaryConnections(); + disconnectPlannerModel(); currentState = PROFILE; setBackgroundBrush(getColor(::BACKGROUND, profileScene->isGrayscale)); @@ -444,16 +444,6 @@ void ProfileWidget2::setProfileState() } #ifndef SUBSURFACE_MOBILE -void ProfileWidget2::connectPlannerModel() -{ - connect(plannerModel, &DivePlannerPointsModel::dataChanged, this, &ProfileWidget2::replot); - connect(plannerModel, &DivePlannerPointsModel::cylinderModelEdited, this, &ProfileWidget2::replot); - connect(plannerModel, &DivePlannerPointsModel::modelReset, this, &ProfileWidget2::pointsReset); - connect(plannerModel, &DivePlannerPointsModel::rowsInserted, this, &ProfileWidget2::pointInserted); - connect(plannerModel, &DivePlannerPointsModel::rowsRemoved, this, &ProfileWidget2::pointsRemoved); - connect(plannerModel, &DivePlannerPointsModel::rowsMoved, this, &ProfileWidget2::pointsMoved); -} - void ProfileWidget2::setEditState(const dive *d, int dc) { if (currentState == EDIT) @@ -462,7 +452,6 @@ void ProfileWidget2::setEditState(const dive *d, int dc) setProfileState(d, dc); mouseFollowerHorizontal->setVisible(true); mouseFollowerVertical->setVisible(true); - disconnectTemporaryConnections(); connectPlannerModel(); @@ -480,7 +469,6 @@ void ProfileWidget2::setPlanState(const dive *d, int dc) setProfileState(d, dc); mouseFollowerHorizontal->setVisible(true); mouseFollowerVertical->setVisible(true); - disconnectTemporaryConnections(); connectPlannerModel(); @@ -800,9 +788,19 @@ void ProfileWidget2::editName(DiveEventItem *item) Command::renameEvent(mutable_dive(), dc, event, qPrintable(newName)); } } + +void ProfileWidget2::connectPlannerModel() +{ + connect(plannerModel, &DivePlannerPointsModel::dataChanged, this, &ProfileWidget2::replot); + connect(plannerModel, &DivePlannerPointsModel::cylinderModelEdited, this, &ProfileWidget2::replot); + connect(plannerModel, &DivePlannerPointsModel::modelReset, this, &ProfileWidget2::pointsReset); + connect(plannerModel, &DivePlannerPointsModel::rowsInserted, this, &ProfileWidget2::pointInserted); + connect(plannerModel, &DivePlannerPointsModel::rowsRemoved, this, &ProfileWidget2::pointsRemoved); + connect(plannerModel, &DivePlannerPointsModel::rowsMoved, this, &ProfileWidget2::pointsMoved); +} #endif -void ProfileWidget2::disconnectTemporaryConnections() +void ProfileWidget2::disconnectPlannerModel() { #ifndef SUBSURFACE_MOBILE if (plannerModel) { diff --git a/profile-widget/profilewidget2.h b/profile-widget/profilewidget2.h index 1e91aff20..b20eb5cef 100644 --- a/profile-widget/profilewidget2.h +++ b/profile-widget/profilewidget2.h @@ -115,7 +115,6 @@ private: void setupSceneAndFlags(); void addItemsToScene(); void setupItemOnScene(); - void disconnectTemporaryConnections(); struct plot_data *getEntryFromPos(QPointF pos); void clearPictures(); void plotPicturesInternal(const struct dive *d, bool synchronous); @@ -184,6 +183,7 @@ private: std::vector> handles; int handleIndex(const DiveHandler *h) const; + void disconnectPlannerModel(); #ifndef SUBSURFACE_MOBILE void connectPlannerModel(); void repositionDiveHandlers();