Auto status change to "Under Review"
@@ -12,6 +12,11 public: | |||||
12 |
|
12 | |||
13 | std::shared_ptr<SelectionZoneAction> |
|
13 | std::shared_ptr<SelectionZoneAction> | |
14 | addSectionZoneAction(const QString &name, SelectionZoneAction::ExecuteFunction function); |
|
14 | addSectionZoneAction(const QString &name, SelectionZoneAction::ExecuteFunction function); | |
|
15 | ||||
|
16 | std::shared_ptr<SelectionZoneAction> | |||
|
17 | addSectionZoneAction(const QStringList &subMenuList, const QString &name, | |||
|
18 | SelectionZoneAction::ExecuteFunction function); | |||
|
19 | ||||
15 | QVector<std::shared_ptr<SelectionZoneAction> > selectionZoneActions() const; |
|
20 | QVector<std::shared_ptr<SelectionZoneAction> > selectionZoneActions() const; | |
16 |
|
21 | |||
17 | private: |
|
22 | private: |
@@ -37,6 +37,15 public: | |||||
37 | */ |
|
37 | */ | |
38 | explicit SelectionZoneAction(const QString &name, ExecuteFunction fun); |
|
38 | explicit SelectionZoneAction(const QString &name, ExecuteFunction fun); | |
39 |
|
39 | |||
|
40 | /** | |||
|
41 | * @param name the name of the action, displayed to the user | |||
|
42 | * @param subMenusList the list of sub menus where the action should be inserted | |||
|
43 | * @param fun the function that will be called when the action is executed | |||
|
44 | * @sa execute() | |||
|
45 | */ | |||
|
46 | explicit SelectionZoneAction(const QStringList &subMenuList, const QString &name, | |||
|
47 | ExecuteFunction fun); | |||
|
48 | ||||
40 | /// Sets the function which determine if the action should be enabled or disabled |
|
49 | /// Sets the function which determine if the action should be enabled or disabled | |
41 | void setEnableFunction(EnableFunction fun); |
|
50 | void setEnableFunction(EnableFunction fun); | |
42 |
|
51 | |||
@@ -48,6 +57,9 public: | |||||
48 | /// The name of the action |
|
57 | /// The name of the action | |
49 | QString name() const noexcept; |
|
58 | QString name() const noexcept; | |
50 |
|
59 | |||
|
60 | /// The path in the sub menus, if any | |||
|
61 | QStringList subMenuList() const noexcept; | |||
|
62 | ||||
51 | public slots: |
|
63 | public slots: | |
52 | /// Executes the action |
|
64 | /// Executes the action | |
53 | void execute(const QVector<VisualizationSelectionZoneItem *> &item); |
|
65 | void execute(const QVector<VisualizationSelectionZoneItem *> &item); |
@@ -20,6 +20,16 ActionsGuiController::addSectionZoneAction(const QString &name, | |||||
20 | return action; |
|
20 | return action; | |
21 | } |
|
21 | } | |
22 |
|
22 | |||
|
23 | std::shared_ptr<SelectionZoneAction> | |||
|
24 | ActionsGuiController::addSectionZoneAction(const QStringList &subMenuList, const QString &name, | |||
|
25 | SelectionZoneAction::ExecuteFunction function) | |||
|
26 | { | |||
|
27 | auto action = std::make_shared<SelectionZoneAction>(subMenuList, name, function); | |||
|
28 | impl->m_SelectionZoneActions.push_back(action); | |||
|
29 | ||||
|
30 | return action; | |||
|
31 | } | |||
|
32 | ||||
23 | QVector<std::shared_ptr<SelectionZoneAction> > ActionsGuiController::selectionZoneActions() const |
|
33 | QVector<std::shared_ptr<SelectionZoneAction> > ActionsGuiController::selectionZoneActions() const | |
24 | { |
|
34 | { | |
25 | return impl->m_SelectionZoneActions; |
|
35 | return impl->m_SelectionZoneActions; |
@@ -4,20 +4,29 | |||||
4 | Q_LOGGING_CATEGORY(LOG_SelectionZoneAction, "SelectionZoneAction") |
|
4 | Q_LOGGING_CATEGORY(LOG_SelectionZoneAction, "SelectionZoneAction") | |
5 |
|
5 | |||
6 | struct SelectionZoneAction::SelectionZoneActionPrivate { |
|
6 | struct SelectionZoneAction::SelectionZoneActionPrivate { | |
7 | explicit SelectionZoneActionPrivate(const QString &name, |
|
7 | explicit SelectionZoneActionPrivate(const QString &name, const QStringList &subMenuList, | |
8 | SelectionZoneAction::ExecuteFunction fun) |
|
8 | SelectionZoneAction::ExecuteFunction fun) | |
9 | : m_Name{name}, m_Fun{std::move(fun)} |
|
9 | : m_Name{name}, m_SubMenuList{subMenuList}, m_Fun{std::move(fun)} | |
10 | { |
|
10 | { | |
11 | } |
|
11 | } | |
12 |
|
12 | |||
13 | QString m_Name; |
|
13 | QString m_Name; | |
|
14 | QStringList m_SubMenuList; | |||
14 | QKeySequence m_DisplayedShortcut; |
|
15 | QKeySequence m_DisplayedShortcut; | |
15 | SelectionZoneAction::ExecuteFunction m_Fun; |
|
16 | SelectionZoneAction::ExecuteFunction m_Fun; | |
16 | SelectionZoneAction::EnableFunction m_EnableFun = [](auto zones) { return true; }; |
|
17 | SelectionZoneAction::EnableFunction m_EnableFun = [](auto zones) { return true; }; | |
17 | }; |
|
18 | }; | |
18 |
|
19 | |||
19 | SelectionZoneAction::SelectionZoneAction(const QString &name, ExecuteFunction fun) |
|
20 | SelectionZoneAction::SelectionZoneAction(const QString &name, ExecuteFunction fun) | |
20 |
: impl{spimpl::make_unique_impl<SelectionZoneActionPrivate>(name, |
|
21 | : impl{spimpl::make_unique_impl<SelectionZoneActionPrivate>(name, QStringList{}, | |
|
22 | std::move(fun))} | |||
|
23 | { | |||
|
24 | } | |||
|
25 | ||||
|
26 | SelectionZoneAction::SelectionZoneAction(const QStringList &subMenuList, const QString &name, | |||
|
27 | SelectionZoneAction::ExecuteFunction fun) | |||
|
28 | : impl{spimpl::make_unique_impl<SelectionZoneActionPrivate>(name, subMenuList, | |||
|
29 | std::move(fun))} | |||
21 | { |
|
30 | { | |
22 | } |
|
31 | } | |
23 |
|
32 | |||
@@ -41,6 +50,11 QString SelectionZoneAction::name() const noexcept | |||||
41 | return impl->m_Name; |
|
50 | return impl->m_Name; | |
42 | } |
|
51 | } | |
43 |
|
52 | |||
|
53 | QStringList SelectionZoneAction::subMenuList() const noexcept | |||
|
54 | { | |||
|
55 | return impl->m_SubMenuList; | |||
|
56 | } | |||
|
57 | ||||
44 | void SelectionZoneAction::execute(const QVector<VisualizationSelectionZoneItem *> &item) |
|
58 | void SelectionZoneAction::execute(const QVector<VisualizationSelectionZoneItem *> &item) | |
45 | { |
|
59 | { | |
46 | impl->m_Fun(item); |
|
60 | impl->m_Fun(item); |
@@ -24,40 +24,40 void VisualizationActionManager::installSelectionZoneActions() | |||||
24 | auto alignEnableFuntion = [](auto items) { return items.count() > 1; }; |
|
24 | auto alignEnableFuntion = [](auto items) { return items.count() > 1; }; | |
25 |
|
25 | |||
26 | // Vertical alignment actions |
|
26 | // Vertical alignment actions | |
27 | auto alignLeftAction |
|
27 | auto alignLeftAction = actionController.addSectionZoneAction( | |
28 |
|
|
28 | QStringList{"Align Vertically"}, "Left", [](auto zones) { | |
29 |
|
|
29 | Q_ASSERT(zones.count() > 1); | |
30 |
|
|
30 | auto ref = zones.takeFirst(); | |
31 |
|
|
31 | ref->alignZonesVerticallyOnLeft(zones, false); | |
32 |
|
|
32 | }); | |
33 | alignLeftAction->setEnableFunction(alignEnableFuntion); |
|
33 | alignLeftAction->setEnableFunction(alignEnableFuntion); | |
34 |
|
34 | |||
35 | auto alignLeftBorderAction |
|
35 | auto alignLeftBorderAction = actionController.addSectionZoneAction( | |
36 |
|
|
36 | QStringList{"Align Vertically"}, "Left Borders", [](auto zones) { | |
37 |
|
|
37 | Q_ASSERT(zones.count() > 1); | |
38 |
|
|
38 | auto ref = zones.takeFirst(); | |
39 |
|
|
39 | ref->alignZonesVerticallyOnLeft(zones, true); | |
40 |
|
|
40 | }); | |
41 | alignLeftBorderAction->setEnableFunction(alignEnableFuntion); |
|
41 | alignLeftBorderAction->setEnableFunction(alignEnableFuntion); | |
42 |
|
42 | |||
43 | auto alignRightAction |
|
43 | auto alignRightAction = actionController.addSectionZoneAction( | |
44 |
|
|
44 | QStringList{"Align Vertically"}, "Right", [](auto zones) { | |
45 |
|
|
45 | Q_ASSERT(zones.count() > 1); | |
46 |
|
|
46 | auto ref = zones.takeFirst(); | |
47 |
|
|
47 | ref->alignZonesVerticallyOnRight(zones, false); | |
48 |
|
|
48 | }); | |
49 | alignRightAction->setEnableFunction(alignEnableFuntion); |
|
49 | alignRightAction->setEnableFunction(alignEnableFuntion); | |
50 |
|
50 | |||
51 | auto alignRightBorderAction |
|
51 | auto alignRightBorderAction = actionController.addSectionZoneAction( | |
52 |
|
|
52 | QStringList{"Align Vertically"}, "Right Borders", [](auto zones) { | |
53 |
|
|
53 | Q_ASSERT(zones.count() > 1); | |
54 |
|
|
54 | auto ref = zones.takeFirst(); | |
55 |
|
|
55 | ref->alignZonesVerticallyOnRight(zones, true); | |
56 |
|
|
56 | }); | |
57 | alignRightBorderAction->setEnableFunction(alignEnableFuntion); |
|
57 | alignRightBorderAction->setEnableFunction(alignEnableFuntion); | |
58 |
|
58 | |||
59 | auto alignLeftAndRightAction = actionController.addSectionZoneAction( |
|
59 | auto alignLeftAndRightAction = actionController.addSectionZoneAction( | |
60 |
"Align Vertically |
|
60 | QStringList{"Align Vertically"}, "Left and Right", [](auto zones) { | |
61 | Q_ASSERT(zones.count() > 1); |
|
61 | Q_ASSERT(zones.count() > 1); | |
62 | auto ref = zones.takeFirst(); |
|
62 | auto ref = zones.takeFirst(); | |
63 | ref->alignZonesVerticallyOnLeft(zones, false); |
|
63 | ref->alignZonesVerticallyOnLeft(zones, false); | |
@@ -66,40 +66,40 void VisualizationActionManager::installSelectionZoneActions() | |||||
66 | alignLeftAndRightAction->setEnableFunction(alignEnableFuntion); |
|
66 | alignLeftAndRightAction->setEnableFunction(alignEnableFuntion); | |
67 |
|
67 | |||
68 | // Temporal alignment actions |
|
68 | // Temporal alignment actions | |
69 | auto alignLeftTemporallyAction |
|
69 | auto alignLeftTemporallyAction = actionController.addSectionZoneAction( | |
70 |
|
|
70 | QStringList{"Align Temporally"}, "Left", [](auto zones) { | |
71 |
|
|
71 | Q_ASSERT(zones.count() > 1); | |
72 |
|
|
72 | auto ref = zones.takeFirst(); | |
73 |
|
|
73 | ref->alignZonesTemporallyOnLeft(zones, false); | |
74 |
|
|
74 | }); | |
75 | alignLeftTemporallyAction->setEnableFunction(alignEnableFuntion); |
|
75 | alignLeftTemporallyAction->setEnableFunction(alignEnableFuntion); | |
76 |
|
76 | |||
77 | auto alignLeftBorderTemporallyAction |
|
77 | auto alignLeftBorderTemporallyAction = actionController.addSectionZoneAction( | |
78 |
|
|
78 | QStringList{"Align Temporally"}, "Left Borders", [](auto zones) { | |
79 |
|
|
79 | Q_ASSERT(zones.count() > 1); | |
80 |
|
|
80 | auto ref = zones.takeFirst(); | |
81 |
|
|
81 | ref->alignZonesTemporallyOnLeft(zones, true); | |
82 |
|
|
82 | }); | |
83 | alignLeftBorderTemporallyAction->setEnableFunction(alignEnableFuntion); |
|
83 | alignLeftBorderTemporallyAction->setEnableFunction(alignEnableFuntion); | |
84 |
|
84 | |||
85 | auto alignRightTemporallyAction |
|
85 | auto alignRightTemporallyAction = actionController.addSectionZoneAction( | |
86 |
|
|
86 | QStringList{"Align Temporally"}, "Right", [](auto zones) { | |
87 |
|
|
87 | Q_ASSERT(zones.count() > 1); | |
88 |
|
|
88 | auto ref = zones.takeFirst(); | |
89 |
|
|
89 | ref->alignZonesTemporallyOnRight(zones, false); | |
90 |
|
|
90 | }); | |
91 | alignRightTemporallyAction->setEnableFunction(alignEnableFuntion); |
|
91 | alignRightTemporallyAction->setEnableFunction(alignEnableFuntion); | |
92 |
|
92 | |||
93 | auto alignRightBorderTemporallyAction |
|
93 | auto alignRightBorderTemporallyAction = actionController.addSectionZoneAction( | |
94 |
|
|
94 | QStringList{"Align Temporally"}, "Right Borders", [](auto zones) { | |
95 |
|
|
95 | Q_ASSERT(zones.count() > 1); | |
96 |
|
|
96 | auto ref = zones.takeFirst(); | |
97 |
|
|
97 | ref->alignZonesTemporallyOnRight(zones, true); | |
98 |
|
|
98 | }); | |
99 | alignRightBorderTemporallyAction->setEnableFunction(alignEnableFuntion); |
|
99 | alignRightBorderTemporallyAction->setEnableFunction(alignEnableFuntion); | |
100 |
|
100 | |||
101 | auto alignLeftAndRightTemporallyAction = actionController.addSectionZoneAction( |
|
101 | auto alignLeftAndRightTemporallyAction = actionController.addSectionZoneAction( | |
102 |
"Align Temporally |
|
102 | QStringList{"Align Temporally"}, "Left and Right", [](auto zones) { | |
103 | Q_ASSERT(zones.count() > 1); |
|
103 | Q_ASSERT(zones.count() > 1); | |
104 | auto ref = zones.takeFirst(); |
|
104 | auto ref = zones.takeFirst(); | |
105 | ref->alignZonesTemporallyOnLeft(zones, false); |
|
105 | ref->alignZonesTemporallyOnLeft(zones, false); |
@@ -617,6 +617,7 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept | |||||
617 | graphMenu.addAction(tr("Undo Zoom"), [this]() { undoZoom(); }); |
|
617 | graphMenu.addAction(tr("Undo Zoom"), [this]() { undoZoom(); }); | |
618 | } |
|
618 | } | |
619 |
|
619 | |||
|
620 | // Selection Zone Actions | |||
620 | auto selectionZoneItem = impl->selectionZoneAt(pos, plot()); |
|
621 | auto selectionZoneItem = impl->selectionZoneAt(pos, plot()); | |
621 | if (selectionZoneItem) { |
|
622 | if (selectionZoneItem) { | |
622 | auto selectedItems = parentVisualizationWidget()->selectionZoneManager().selectedItems(); |
|
623 | auto selectedItems = parentVisualizationWidget()->selectionZoneManager().selectedItems(); | |
@@ -628,13 +629,39 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept | |||||
628 | graphMenu.addSeparator(); |
|
629 | graphMenu.addSeparator(); | |
629 | } |
|
630 | } | |
630 |
|
631 | |||
|
632 | QHash<QString, QMenu *> subMenus; | |||
|
633 | QHash<QString, bool> subMenusEnabled; | |||
|
634 | ||||
631 | for (auto zoneAction : zoneActions) { |
|
635 | for (auto zoneAction : zoneActions) { | |
632 | auto action = graphMenu.addAction(zoneAction->name()); |
|
636 | ||
633 |
a |
|
637 | auto isEnabled = zoneAction->isEnabled(selectedItems); | |
|
638 | ||||
|
639 | auto menu = &graphMenu; | |||
|
640 | for (auto subMenuName : zoneAction->subMenuList()) { | |||
|
641 | if (!subMenus.contains(subMenuName)) { | |||
|
642 | menu = menu->addMenu(subMenuName); | |||
|
643 | subMenus[subMenuName] = menu; | |||
|
644 | subMenusEnabled[subMenuName] = isEnabled; | |||
|
645 | } | |||
|
646 | else { | |||
|
647 | menu = subMenus.value(subMenuName); | |||
|
648 | if (isEnabled) { | |||
|
649 | // The sub menu is enabled if at least one of its actions is enabled | |||
|
650 | subMenusEnabled[subMenuName] = true; | |||
|
651 | } | |||
|
652 | } | |||
|
653 | } | |||
|
654 | ||||
|
655 | auto action = menu->addAction(zoneAction->name()); | |||
|
656 | action->setEnabled(isEnabled); | |||
634 | action->setShortcut(zoneAction->displayedShortcut()); |
|
657 | action->setShortcut(zoneAction->displayedShortcut()); | |
635 | QObject::connect(action, &QAction::triggered, |
|
658 | QObject::connect(action, &QAction::triggered, | |
636 | [zoneAction, selectedItems]() { zoneAction->execute(selectedItems); }); |
|
659 | [zoneAction, selectedItems]() { zoneAction->execute(selectedItems); }); | |
637 | } |
|
660 | } | |
|
661 | ||||
|
662 | for (auto it = subMenus.cbegin(); it != subMenus.cend(); ++it) { | |||
|
663 | it.value()->setEnabled(subMenusEnabled[it.key()]); | |||
|
664 | } | |||
638 | } |
|
665 | } | |
639 |
|
666 | |||
640 | if (!graphMenu.isEmpty()) { |
|
667 | if (!graphMenu.isEmpty()) { |
General Comments 4
Status change > Approved
Status change > Approved
You need to be logged in to leave comments.
Login now