##// END OF EJS Templates
Put the align actions in sub menus
trabillard -
r1118:f354146de80e
parent child
Show More
@@ -12,6 +12,11 public:
12 12
13 13 std::shared_ptr<SelectionZoneAction>
14 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 20 QVector<std::shared_ptr<SelectionZoneAction> > selectionZoneActions() const;
16 21
17 22 private:
@@ -37,6 +37,15 public:
37 37 */
38 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 49 /// Sets the function which determine if the action should be enabled or disabled
41 50 void setEnableFunction(EnableFunction fun);
42 51
@@ -48,6 +57,9 public:
48 57 /// The name of the action
49 58 QString name() const noexcept;
50 59
60 /// The path in the sub menus, if any
61 QStringList subMenuList() const noexcept;
62
51 63 public slots:
52 64 /// Executes the action
53 65 void execute(const QVector<VisualizationSelectionZoneItem *> &item);
@@ -20,6 +20,16 ActionsGuiController::addSectionZoneAction(const QString &name,
20 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 33 QVector<std::shared_ptr<SelectionZoneAction> > ActionsGuiController::selectionZoneActions() const
24 34 {
25 35 return impl->m_SelectionZoneActions;
@@ -4,20 +4,29
4 4 Q_LOGGING_CATEGORY(LOG_SelectionZoneAction, "SelectionZoneAction")
5 5
6 6 struct SelectionZoneAction::SelectionZoneActionPrivate {
7 explicit SelectionZoneActionPrivate(const QString &name,
7 explicit SelectionZoneActionPrivate(const QString &name, const QStringList &subMenuList,
8 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 13 QString m_Name;
14 QStringList m_SubMenuList;
14 15 QKeySequence m_DisplayedShortcut;
15 16 SelectionZoneAction::ExecuteFunction m_Fun;
16 17 SelectionZoneAction::EnableFunction m_EnableFun = [](auto zones) { return true; };
17 18 };
18 19
19 20 SelectionZoneAction::SelectionZoneAction(const QString &name, ExecuteFunction fun)
20 : impl{spimpl::make_unique_impl<SelectionZoneActionPrivate>(name, std::move(fun))}
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 50 return impl->m_Name;
42 51 }
43 52
53 QStringList SelectionZoneAction::subMenuList() const noexcept
54 {
55 return impl->m_SubMenuList;
56 }
57
44 58 void SelectionZoneAction::execute(const QVector<VisualizationSelectionZoneItem *> &item)
45 59 {
46 60 impl->m_Fun(item);
@@ -24,40 +24,40 void VisualizationActionManager::installSelectionZoneActions()
24 24 auto alignEnableFuntion = [](auto items) { return items.count() > 1; };
25 25
26 26 // Vertical alignment actions
27 auto alignLeftAction
28 = actionController.addSectionZoneAction("Align Vertically / Left", [](auto zones) {
29 Q_ASSERT(zones.count() > 1);
30 auto ref = zones.takeFirst();
31 ref->alignZonesVerticallyOnLeft(zones, false);
32 });
27 auto alignLeftAction = actionController.addSectionZoneAction(
28 QStringList{"Align Vertically"}, "Left", [](auto zones) {
29 Q_ASSERT(zones.count() > 1);
30 auto ref = zones.takeFirst();
31 ref->alignZonesVerticallyOnLeft(zones, false);
32 });
33 33 alignLeftAction->setEnableFunction(alignEnableFuntion);
34 34
35 auto alignLeftBorderAction
36 = actionController.addSectionZoneAction("Align Vertically / Left Borders", [](auto zones) {
37 Q_ASSERT(zones.count() > 1);
38 auto ref = zones.takeFirst();
39 ref->alignZonesVerticallyOnLeft(zones, true);
40 });
35 auto alignLeftBorderAction = actionController.addSectionZoneAction(
36 QStringList{"Align Vertically"}, "Left Borders", [](auto zones) {
37 Q_ASSERT(zones.count() > 1);
38 auto ref = zones.takeFirst();
39 ref->alignZonesVerticallyOnLeft(zones, true);
40 });
41 41 alignLeftBorderAction->setEnableFunction(alignEnableFuntion);
42 42
43 auto alignRightAction
44 = actionController.addSectionZoneAction("Align Vertically / Right", [](auto zones) {
45 Q_ASSERT(zones.count() > 1);
46 auto ref = zones.takeFirst();
47 ref->alignZonesVerticallyOnRight(zones, false);
48 });
43 auto alignRightAction = actionController.addSectionZoneAction(
44 QStringList{"Align Vertically"}, "Right", [](auto zones) {
45 Q_ASSERT(zones.count() > 1);
46 auto ref = zones.takeFirst();
47 ref->alignZonesVerticallyOnRight(zones, false);
48 });
49 49 alignRightAction->setEnableFunction(alignEnableFuntion);
50 50
51 auto alignRightBorderAction
52 = actionController.addSectionZoneAction("Align Vertically / Right Borders", [](auto zones) {
53 Q_ASSERT(zones.count() > 1);
54 auto ref = zones.takeFirst();
55 ref->alignZonesVerticallyOnRight(zones, true);
56 });
51 auto alignRightBorderAction = actionController.addSectionZoneAction(
52 QStringList{"Align Vertically"}, "Right Borders", [](auto zones) {
53 Q_ASSERT(zones.count() > 1);
54 auto ref = zones.takeFirst();
55 ref->alignZonesVerticallyOnRight(zones, true);
56 });
57 57 alignRightBorderAction->setEnableFunction(alignEnableFuntion);
58 58
59 59 auto alignLeftAndRightAction = actionController.addSectionZoneAction(
60 "Align Vertically / Left and Right", [](auto zones) {
60 QStringList{"Align Vertically"}, "Left and Right", [](auto zones) {
61 61 Q_ASSERT(zones.count() > 1);
62 62 auto ref = zones.takeFirst();
63 63 ref->alignZonesVerticallyOnLeft(zones, false);
@@ -66,40 +66,40 void VisualizationActionManager::installSelectionZoneActions()
66 66 alignLeftAndRightAction->setEnableFunction(alignEnableFuntion);
67 67
68 68 // Temporal alignment actions
69 auto alignLeftTemporallyAction
70 = actionController.addSectionZoneAction("Align Temporally / Left", [](auto zones) {
71 Q_ASSERT(zones.count() > 1);
72 auto ref = zones.takeFirst();
73 ref->alignZonesTemporallyOnLeft(zones, false);
74 });
69 auto alignLeftTemporallyAction = actionController.addSectionZoneAction(
70 QStringList{"Align Temporally"}, "Left", [](auto zones) {
71 Q_ASSERT(zones.count() > 1);
72 auto ref = zones.takeFirst();
73 ref->alignZonesTemporallyOnLeft(zones, false);
74 });
75 75 alignLeftTemporallyAction->setEnableFunction(alignEnableFuntion);
76 76
77 auto alignLeftBorderTemporallyAction
78 = actionController.addSectionZoneAction("Align Temporally / Left Borders", [](auto zones) {
79 Q_ASSERT(zones.count() > 1);
80 auto ref = zones.takeFirst();
81 ref->alignZonesTemporallyOnLeft(zones, true);
82 });
77 auto alignLeftBorderTemporallyAction = actionController.addSectionZoneAction(
78 QStringList{"Align Temporally"}, "Left Borders", [](auto zones) {
79 Q_ASSERT(zones.count() > 1);
80 auto ref = zones.takeFirst();
81 ref->alignZonesTemporallyOnLeft(zones, true);
82 });
83 83 alignLeftBorderTemporallyAction->setEnableFunction(alignEnableFuntion);
84 84
85 auto alignRightTemporallyAction
86 = actionController.addSectionZoneAction("Align Temporally / Right", [](auto zones) {
87 Q_ASSERT(zones.count() > 1);
88 auto ref = zones.takeFirst();
89 ref->alignZonesTemporallyOnRight(zones, false);
90 });
85 auto alignRightTemporallyAction = actionController.addSectionZoneAction(
86 QStringList{"Align Temporally"}, "Right", [](auto zones) {
87 Q_ASSERT(zones.count() > 1);
88 auto ref = zones.takeFirst();
89 ref->alignZonesTemporallyOnRight(zones, false);
90 });
91 91 alignRightTemporallyAction->setEnableFunction(alignEnableFuntion);
92 92
93 auto alignRightBorderTemporallyAction
94 = actionController.addSectionZoneAction("Align Temporally / Right Borders", [](auto zones) {
95 Q_ASSERT(zones.count() > 1);
96 auto ref = zones.takeFirst();
97 ref->alignZonesTemporallyOnRight(zones, true);
98 });
93 auto alignRightBorderTemporallyAction = actionController.addSectionZoneAction(
94 QStringList{"Align Temporally"}, "Right Borders", [](auto zones) {
95 Q_ASSERT(zones.count() > 1);
96 auto ref = zones.takeFirst();
97 ref->alignZonesTemporallyOnRight(zones, true);
98 });
99 99 alignRightBorderTemporallyAction->setEnableFunction(alignEnableFuntion);
100 100
101 101 auto alignLeftAndRightTemporallyAction = actionController.addSectionZoneAction(
102 "Align Temporally / Left and Right", [](auto zones) {
102 QStringList{"Align Temporally"}, "Left and Right", [](auto zones) {
103 103 Q_ASSERT(zones.count() > 1);
104 104 auto ref = zones.takeFirst();
105 105 ref->alignZonesTemporallyOnLeft(zones, false);
@@ -617,6 +617,7 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept
617 617 graphMenu.addAction(tr("Undo Zoom"), [this]() { undoZoom(); });
618 618 }
619 619
620 // Selection Zone Actions
620 621 auto selectionZoneItem = impl->selectionZoneAt(pos, plot());
621 622 if (selectionZoneItem) {
622 623 auto selectedItems = parentVisualizationWidget()->selectionZoneManager().selectedItems();
@@ -628,13 +629,39 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept
628 629 graphMenu.addSeparator();
629 630 }
630 631
632 QHash<QString, QMenu *> subMenus;
633 QHash<QString, bool> subMenusEnabled;
634
631 635 for (auto zoneAction : zoneActions) {
632 auto action = graphMenu.addAction(zoneAction->name());
633 action->setEnabled(zoneAction->isEnabled(selectedItems));
636
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 657 action->setShortcut(zoneAction->displayedShortcut());
635 658 QObject::connect(action, &QAction::triggered,
636 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 667 if (!graphMenu.isEmpty()) {
General Comments 4
Under Review
author

Auto status change to "Under Review"

Approved

Status change > Approved

Approved

Status change > Approved

You need to be logged in to leave comments. Login now