##// END OF EJS Templates
Add a lambda in SeletionZoneAction to enable or disable the action
trabillard -
r1115:c55ac7376de6
parent child
Show More
@@ -27,6 +27,9 public:
27 27 using ExecuteFunction
28 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 34 * @param name the name of the action, displayed to the user
32 35 * @param fun the function that will be called when the action is executed
@@ -34,6 +37,9 public:
34 37 */
35 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 43 /// The name of the action
38 44 QString name() const noexcept;
39 45
@@ -41,6 +47,9 public slots:
41 47 /// Executes the action
42 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 53 private:
45 54 class SelectionZoneActionPrivate;
46 55 spimpl::unique_impl_ptr<SelectionZoneActionPrivate> impl;
@@ -12,6 +12,7 struct SelectionZoneAction::SelectionZoneActionPrivate {
12 12
13 13 QString m_Name;
14 14 SelectionZoneAction::ExecuteFunction m_Fun;
15 SelectionZoneAction::EnableFunction m_EnableFun = [](auto zones) { return true; };
15 16 };
16 17
17 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 28 QString SelectionZoneAction::name() const noexcept
23 29 {
24 30 return impl->m_Name;
@@ -28,3 +34,8 void SelectionZoneAction::execute(const QVector<VisualizationSelectionZoneItem *
28 34 {
29 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 10 void VisualizationActionManager::installSelectionZoneActions()
11 11 {
12 12 auto &actionController = sqpApp->actionsGuiController();
13
13 14 actionController.addSectionZoneAction("Remove Selected Zone(s)", [](auto &zones) {
14 15 for (auto selectionZone : zones) {
15 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 actionController.addSectionZoneAction("Align Right", [](auto &zones) {});
21
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 622 for (auto zoneAction : zoneActions) {
623 623 auto action = graphMenu.addAction(zoneAction->name());
624 action->setEnabled(zoneAction->isEnabled(selectedItems));
624 625 QObject::connect(action, &QAction::triggered, [zoneAction, &selectedItems]() {
625 626 zoneAction->execute(selectedItems);
626 627 });
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