Skip to content

Commit

Permalink
profile: remove [disable|enable]Shortcuts() signals
Browse files Browse the repository at this point in the history
When switching to the "plan" or "add" (which should rather be
called "edit", by the way) mode of the profile, the "shortcuts"
for copy&paste, undo&redo, etc. are disabled. When switching
to "profile" mode, they are reenabled.

This was done in a most convoluted way:

- The MainWindow calls the set*State() function of the profile.
- The Profile emits [disable|enable]Shortcuts() signals.
- The MainWindow catches these signals and does the enabling
  or disabling.

Not only is this very hard to reason about, it is also in
contradiction to the profile being part of the display layer.

Moreover, in editCurrentDive() the MainWindow disabled the
shortcuts itself, so this was all redundant.

For the sake of sanity, let's just move this logic to the
MainWindow, unslotify the [disable|enable]Shortcuts() functions
and make them private.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
  • Loading branch information
bstoeger authored and dirkhh committed Apr 10, 2021
1 parent 11c54b8 commit 4daf687
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 11 deletions.
6 changes: 3 additions & 3 deletions desktop-widgets/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,6 @@ MainWindow::MainWindow() : QMainWindow(),

// now let's set up some connections
connect(graphics, &ProfileWidget2::enableToolbar ,this, &MainWindow::setEnabledToolbar);
connect(graphics, &ProfileWidget2::disableShortcuts, this, &MainWindow::disableShortcuts);
connect(graphics, &ProfileWidget2::enableShortcuts, this, &MainWindow::enableShortcuts);
connect(graphics, &ProfileWidget2::editCurrentDive, this, &MainWindow::editCurrentDive);

connect(&diveListNotifier, &DiveListNotifier::settingsChanged, graphics, &ProfileWidget2::settingsChanged);
Expand Down Expand Up @@ -771,6 +769,7 @@ void MainWindow::on_actionReplanDive_triggered()
// put us in PLAN mode
setApplicationState(ApplicationState::PlanDive);

disableShortcuts(true);
graphics->setPlanState(&displayed_dive, 0);
plannerWidgets->replanDive();
}
Expand All @@ -783,6 +782,7 @@ void MainWindow::on_actionDivePlanner_triggered()
// put us in PLAN mode
setApplicationState(ApplicationState::PlanDive);

disableShortcuts(true);
graphics->setPlanState(&displayed_dive, 0);
plannerWidgets->planDive();
}
Expand Down Expand Up @@ -1515,7 +1515,7 @@ void MainWindow::editCurrentDive()
if (mainTab->isEditing() || DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING)
return;

disableShortcuts();
disableShortcuts(false);
copy_dive(current_dive, &displayed_dive); // Work on a copy of the dive
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD);
DivePlannerPointsModel::instance()->loadFromDive(&displayed_dive);
Expand Down
4 changes: 2 additions & 2 deletions desktop-widgets/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@ public
void setEnabledToolbar(bool arg1);
// Some shortcuts like "change DC" or "copy/paste dive components"
// should only be enabled when the profile's visible.
void disableShortcuts(bool disablePaste = true);
void enableShortcuts();
void startDiveSiteEdit();

private:
Expand Down Expand Up @@ -237,6 +235,8 @@ public
void setQuadrantWidget(QSplitter &splitter, const Quadrant &q, int pos);
void setQuadrantWidgets(QSplitter &splitter, const Quadrant &left, const Quadrant &right);
void registerApplicationState(ApplicationState state, Quadrants q);
void disableShortcuts(bool disablePaste = true);
void enableShortcuts();

QMenu *connections;
QAction *share_on_fb;
Expand Down
4 changes: 0 additions & 4 deletions profile-widget/profilewidget2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1127,8 +1127,6 @@ void ProfileWidget2::setProfileState()
disconnectTemporaryConnections();
/* show the same stuff that the profile shows. */

emit enableShortcuts();

currentState = PROFILE;
emit enableToolbar(true);
setBackgroundBrush(getColor(::BACKGROUND, isGrayscale));
Expand Down Expand Up @@ -1279,7 +1277,6 @@ void ProfileWidget2::setAddState(const dive *d, int dc)
mouseFollowerHorizontal->setLine(timeAxis->line());
mouseFollowerVertical->setLine(QLineF(0, profileYAxis->pos().y(), 0, timeAxis->pos().y()));
disconnectTemporaryConnections();
emit disableShortcuts(false);
actionsForKeys[Qt::Key_Left]->setShortcut(Qt::Key_Left);
actionsForKeys[Qt::Key_Right]->setShortcut(Qt::Key_Right);
actionsForKeys[Qt::Key_Up]->setShortcut(Qt::Key_Up);
Expand Down Expand Up @@ -1310,7 +1307,6 @@ void ProfileWidget2::setPlanState(const dive *d, int dc)
mouseFollowerHorizontal->setLine(timeAxis->line());
mouseFollowerVertical->setLine(QLineF(0, profileYAxis->pos().y(), 0, timeAxis->pos().y()));
disconnectTemporaryConnections();
emit disableShortcuts(true);
actionsForKeys[Qt::Key_Left]->setShortcut(Qt::Key_Left);
actionsForKeys[Qt::Key_Right]->setShortcut(Qt::Key_Right);
actionsForKeys[Qt::Key_Up]->setShortcut(Qt::Key_Up);
Expand Down
2 changes: 0 additions & 2 deletions profile-widget/profilewidget2.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ class ProfileWidget2 : public QGraphicsView {
signals:
void fontPrintScaleChanged(double scale);
void enableToolbar(bool enable);
void enableShortcuts();
void disableShortcuts(bool paste);
void editCurrentDive();

public
Expand Down

0 comments on commit 4daf687

Please sign in to comment.