##// END OF EJS Templates
Add action to remove the selected zone with the "del" buttons
trabillard -
r1082:eff9e479c5d5
parent child
Show More
@@ -40,6 +40,11 public:
40 40 /// Sets the function which determine if the action should be enabled or disabled
41 41 void setEnableFunction(EnableFunction fun);
42 42
43 /// Sets the shortcut displayed by the action.
44 /// Note: The shortcut is only displayed and not active because it is not permanently stored
45 void setDisplayedShortcut(const QKeySequence &shortcut);
46 QKeySequence displayedShortcut() const;
47
43 48 /// The name of the action
44 49 QString name() const noexcept;
45 50
@@ -11,6 +11,7 struct SelectionZoneAction::SelectionZoneActionPrivate {
11 11 }
12 12
13 13 QString m_Name;
14 QKeySequence m_DisplayedShortcut;
14 15 SelectionZoneAction::ExecuteFunction m_Fun;
15 16 SelectionZoneAction::EnableFunction m_EnableFun = [](auto zones) { return true; };
16 17 };
@@ -25,6 +26,16 void SelectionZoneAction::setEnableFunction(EnableFunction fun)
25 26 impl->m_EnableFun = std::move(fun);
26 27 }
27 28
29 void SelectionZoneAction::setDisplayedShortcut(const QKeySequence &shortcut)
30 {
31 impl->m_DisplayedShortcut = shortcut;
32 }
33
34 QKeySequence SelectionZoneAction::displayedShortcut() const
35 {
36 return impl->m_DisplayedShortcut;
37 }
38
28 39 QString SelectionZoneAction::name() const noexcept
29 40 {
30 41 return impl->m_Name;
@@ -11,13 +11,15 void VisualizationActionManager::installSelectionZoneActions()
11 11 {
12 12 auto &actionController = sqpApp->actionsGuiController();
13 13
14 actionController.addSectionZoneAction("Remove Selected Zone(s)", [](auto zones) {
15 for (auto selectionZone : zones) {
16 if (auto graph = selectionZone->parentGraphWidget()) {
17 graph->removeSelectionZone(selectionZone);
18 }
19 }
20 });
14 auto removeZonesAction
15 = actionController.addSectionZoneAction("Remove Selected Zone(s)", [](auto zones) {
16 for (auto selectionZone : zones) {
17 if (auto graph = selectionZone->parentGraphWidget()) {
18 graph->removeSelectionZone(selectionZone);
19 }
20 }
21 });
22 removeZonesAction->setDisplayedShortcut(QKeySequence::Delete);
21 23
22 24 auto alignEnableFuntion = [](auto items) { return items.count() > 1; };
23 25
@@ -380,10 +380,16 void VisualizationGraphWidget::addSelectionZones(const QVector<SqpRange> &ranges
380 380
381 381 void VisualizationGraphWidget::removeSelectionZone(VisualizationSelectionZoneItem *selectionZone)
382 382 {
383 parentVisualizationWidget()->selectionZoneManager().setSelected(selectionZone, false);
384
385 if (impl->m_HoveredZone == selectionZone) {
386 impl->m_HoveredZone = nullptr;
387 setCursor(Qt::ArrowCursor);
388 }
389
383 390 impl->m_SelectionZones.removeAll(selectionZone);
384 391 plot().removeItem(selectionZone);
385 392 plot().replot(QCustomPlot::rpQueuedReplot);
386 parentVisualizationWidget()->selectionZoneManager().setSelected(selectionZone, false);
387 393 }
388 394
389 395 void VisualizationGraphWidget::undoZoom()
@@ -625,6 +631,7 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept
625 631 for (auto zoneAction : zoneActions) {
626 632 auto action = graphMenu.addAction(zoneAction->name());
627 633 action->setEnabled(zoneAction->isEnabled(selectedItems));
634 action->setShortcut(zoneAction->displayedShortcut());
628 635 QObject::connect(action, &QAction::triggered,
629 636 [zoneAction, selectedItems]() { zoneAction->execute(selectedItems); });
630 637 }
@@ -24,7 +24,7 void VisualizationSelectionZoneManager::setSelected(VisualizationSelectionZoneIt
24 24 {
25 25 if (value != item->selected()) {
26 26 item->setSelected(value);
27 item->parentPlot()->replot();
27 item->parentPlot()->replot(QCustomPlot::rpQueuedReplot);
28 28 }
29 29
30 30 if (!value && impl->m_SelectedItems.contains(item)) {
@@ -2,6 +2,7
2 2 #include "Visualization/IVisualizationWidgetVisitor.h"
3 3 #include "Visualization/VisualizationActionManager.h"
4 4 #include "Visualization/VisualizationGraphWidget.h"
5 #include "Visualization/VisualizationSelectionZoneItem.h"
5 6 #include "Visualization/VisualizationSelectionZoneManager.h"
6 7 #include "Visualization/VisualizationTabWidget.h"
7 8 #include "Visualization/VisualizationZoneWidget.h"
@@ -88,8 +89,21 VisualizationWidget::VisualizationWidget(QWidget *parent)
88 89
89 90 sqpApp->dragDropGuiController().addDragDropTabBar(ui->tabWidget->tabBar());
90 91
92 // Actions
91 93 impl->m_ActionManager.installSelectionZoneActions();
92 94
95 auto removeZoneAction = new QAction("Remove selected zone(s)");
96 removeZoneAction->setShortcut(QKeySequence::Delete);
97 connect(removeZoneAction, &QAction::triggered, [this]() {
98 auto selection = impl->m_ZoneSelectionManager->selectedItems();
99 for (auto selectionZone : selection) {
100 if (auto graph = selectionZone->parentGraphWidget()) {
101 graph->removeSelectionZone(selectionZone);
102 }
103 }
104 });
105 addAction(removeZoneAction);
106
93 107 // Adds default tab
94 108 addTabView();
95 109 }
General Comments 0
You need to be logged in to leave comments. Login now