Cleanup: Improve Connection Handling in Profile.

- improve naming;
- remove unneeded disconnects.

Signed-off-by: Michael Keller <github@ike.ch>
This commit is contained in:
=Michael Keller 2024-05-25 00:33:44 +12:00 committed by bstoeger
parent 8c14fb971c
commit ecc6f64d10
2 changed files with 14 additions and 16 deletions

View file

@ -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) {

View file

@ -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<std::unique_ptr<DiveHandler>> handles;
int handleIndex(const DiveHandler *h) const;
void disconnectPlannerModel();
#ifndef SUBSURFACE_MOBILE
void connectPlannerModel();
void repositionDiveHandlers();