@@ -27,6 +27,9 public: | |||||
27 | using ExecuteFunction |
|
27 | using ExecuteFunction | |
28 | = std::function<void(const QVector<VisualizationSelectionZoneItem *> &item)>; |
|
28 | = std::function<void(const QVector<VisualizationSelectionZoneItem *> &item)>; | |
29 |
|
29 | |||
|
30 | using EnableFunction | |||
|
31 | = std::function<bool(const QVector<VisualizationSelectionZoneItem *> &item)>; | |||
|
32 | ||||
30 | /** |
|
33 | /** | |
31 | * @param name the name of the action, displayed to the user |
|
34 | * @param name the name of the action, displayed to the user | |
32 | * @param fun the function that will be called when the action is executed |
|
35 | * @param fun the function that will be called when the action is executed | |
@@ -34,6 +37,9 public: | |||||
34 | */ |
|
37 | */ | |
35 | explicit SelectionZoneAction(const QString &name, ExecuteFunction fun); |
|
38 | explicit SelectionZoneAction(const QString &name, ExecuteFunction fun); | |
36 |
|
39 | |||
|
40 | /// Sets the function which determine if the action should be enabled or disabled | |||
|
41 | void setEnableFunction(EnableFunction fun); | |||
|
42 | ||||
37 | /// The name of the action |
|
43 | /// The name of the action | |
38 | QString name() const noexcept; |
|
44 | QString name() const noexcept; | |
39 |
|
45 | |||
@@ -41,6 +47,9 public slots: | |||||
41 | /// Executes the action |
|
47 | /// Executes the action | |
42 | void execute(const QVector<VisualizationSelectionZoneItem *> &item); |
|
48 | void execute(const QVector<VisualizationSelectionZoneItem *> &item); | |
43 |
|
49 | |||
|
50 | /// Returns true if the action is enabled | |||
|
51 | bool isEnabled(const QVector<VisualizationSelectionZoneItem *> &item); | |||
|
52 | ||||
44 | private: |
|
53 | private: | |
45 | class SelectionZoneActionPrivate; |
|
54 | class SelectionZoneActionPrivate; | |
46 | spimpl::unique_impl_ptr<SelectionZoneActionPrivate> impl; |
|
55 | spimpl::unique_impl_ptr<SelectionZoneActionPrivate> impl; |
@@ -12,6 +12,7 struct SelectionZoneAction::SelectionZoneActionPrivate { | |||||
12 |
|
12 | |||
13 | QString m_Name; |
|
13 | QString m_Name; | |
14 | SelectionZoneAction::ExecuteFunction m_Fun; |
|
14 | SelectionZoneAction::ExecuteFunction m_Fun; | |
|
15 | SelectionZoneAction::EnableFunction m_EnableFun = [](auto zones) { return true; }; | |||
15 | }; |
|
16 | }; | |
16 |
|
17 | |||
17 | SelectionZoneAction::SelectionZoneAction(const QString &name, ExecuteFunction fun) |
|
18 | SelectionZoneAction::SelectionZoneAction(const QString &name, ExecuteFunction fun) | |
@@ -19,6 +20,11 SelectionZoneAction::SelectionZoneAction(const QString &name, ExecuteFunction fu | |||||
19 | { |
|
20 | { | |
20 | } |
|
21 | } | |
21 |
|
22 | |||
|
23 | void SelectionZoneAction::setEnableFunction(EnableFunction fun) | |||
|
24 | { | |||
|
25 | impl->m_EnableFun = std::move(fun); | |||
|
26 | } | |||
|
27 | ||||
22 | QString SelectionZoneAction::name() const noexcept |
|
28 | QString SelectionZoneAction::name() const noexcept | |
23 | { |
|
29 | { | |
24 | return impl->m_Name; |
|
30 | return impl->m_Name; | |
@@ -28,3 +34,8 void SelectionZoneAction::execute(const QVector<VisualizationSelectionZoneItem * | |||||
28 | { |
|
34 | { | |
29 | impl->m_Fun(item); |
|
35 | impl->m_Fun(item); | |
30 | } |
|
36 | } | |
|
37 | ||||
|
38 | bool SelectionZoneAction::isEnabled(const QVector<VisualizationSelectionZoneItem *> &item) | |||
|
39 | { | |||
|
40 | return impl->m_EnableFun(item); | |||
|
41 | } |
@@ -10,6 +10,7 VisualizationActionManager::VisualizationActionManager() {} | |||||
10 | void VisualizationActionManager::installSelectionZoneActions() |
|
10 | void VisualizationActionManager::installSelectionZoneActions() | |
11 | { |
|
11 | { | |
12 | auto &actionController = sqpApp->actionsGuiController(); |
|
12 | auto &actionController = sqpApp->actionsGuiController(); | |
|
13 | ||||
13 | actionController.addSectionZoneAction("Remove Selected Zone(s)", [](auto &zones) { |
|
14 | actionController.addSectionZoneAction("Remove Selected Zone(s)", [](auto &zones) { | |
14 | for (auto selectionZone : zones) { |
|
15 | for (auto selectionZone : zones) { | |
15 | if (auto graph = selectionZone->parentGraphWidget()) { |
|
16 | if (auto graph = selectionZone->parentGraphWidget()) { | |
@@ -17,6 +18,13 void VisualizationActionManager::installSelectionZoneActions() | |||||
17 | } |
|
18 | } | |
18 | } |
|
19 | } | |
19 | }); |
|
20 | }); | |
20 | actionController.addSectionZoneAction("Align Left", [](auto &zones) {}); |
|
21 | ||
21 | actionController.addSectionZoneAction("Align Right", [](auto &zones) {}); |
|
22 | auto alignEnableFuntion = [](auto &items) { return items.count() > 0; }; | |
|
23 | ||||
|
24 | auto alignLeftAction = actionController.addSectionZoneAction("Align Left Vertically", [](auto &zones) {}); | |||
|
25 | alignLeftAction->setEnableFunction(alignEnableFuntion); | |||
|
26 | ||||
|
27 | auto alignRightAction | |||
|
28 | = actionController.addSectionZoneAction("Align Right vertically", [](auto &zones) {}); | |||
|
29 | alignRightAction->setEnableFunction(alignEnableFuntion); | |||
22 | } |
|
30 | } |
@@ -621,6 +621,7 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept | |||||
621 |
|
621 | |||
622 | for (auto zoneAction : zoneActions) { |
|
622 | for (auto zoneAction : zoneActions) { | |
623 | auto action = graphMenu.addAction(zoneAction->name()); |
|
623 | auto action = graphMenu.addAction(zoneAction->name()); | |
|
624 | action->setEnabled(zoneAction->isEnabled(selectedItems)); | |||
624 | QObject::connect(action, &QAction::triggered, [zoneAction, &selectedItems]() { |
|
625 | QObject::connect(action, &QAction::triggered, [zoneAction, &selectedItems]() { | |
625 | zoneAction->execute(selectedItems); |
|
626 | zoneAction->execute(selectedItems); | |
626 | }); |
|
627 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now