##// END OF EJS Templates
Merge branch 'feature/VariableMenu1' into develop
Alexandre Leroux -
r217:b575895e8245 merge
parent child
Show More
@@ -0,0 +1,19
1 #ifndef SCIQLOP_IVARIABLECONTAINER_H
2 #define SCIQLOP_IVARIABLECONTAINER_H
3
4 class Variable;
5
6 /**
7 * @brief The IVariableContainer interface represents an UI object that can accommodate a variable
8 */
9 class IVariableContainer {
10
11 public:
12 virtual ~IVariableContainer() = default;
13
14 /// Checks if the container can handle the variable passed in parameter
15 virtual bool canDrop(const Variable &variable) const = 0;
16 };
17
18
19 #endif // SCIQLOP_IVARIABLECONTAINER_H
@@ -0,0 +1,42
1 #ifndef SCIQLOP_GENERATEVARIABLEMENUOPERATION_H
2 #define SCIQLOP_GENERATEVARIABLEMENUOPERATION_H
3
4 #include "Visualization/IVisualizationWidgetVisitor.h"
5
6 #include <Common/spimpl.h>
7
8 #include <QLoggingCategory>
9
10 class QMenu;
11 class Variable;
12
13 Q_DECLARE_LOGGING_CATEGORY(LOG_GenerateVariableMenuOperation)
14
15 /**
16 * @brief The GenerateVariableMenuOperation class defines an operation that traverses all of
17 * visualization widgets to determine which can accommodate a variable. The result of the operation
18 * is a menu that contains actions to add the variable into the containers.
19 */
20 class GenerateVariableMenuOperation : public IVisualizationWidgetVisitor {
21 public:
22 /**
23 * Ctor
24 * @param menu the menu to which to attach the generated menu
25 * @param variable the variable for which to generate the menu
26 */
27 explicit GenerateVariableMenuOperation(QMenu *menu, std::shared_ptr<Variable> variable);
28
29 void visitEnter(VisualizationWidget *widget) override final;
30 void visitLeave(VisualizationWidget *widget) override final;
31 void visitEnter(VisualizationTabWidget *tabWidget) override final;
32 void visitLeave(VisualizationTabWidget *tabWidget) override final;
33 void visitEnter(VisualizationZoneWidget *zoneWidget) override final;
34 void visitLeave(VisualizationZoneWidget *zoneWidget) override final;
35 void visit(VisualizationGraphWidget *graphWidget) override final;
36
37 private:
38 class GenerateVariableMenuOperationPrivate;
39 spimpl::unique_impl_ptr<GenerateVariableMenuOperationPrivate> impl;
40 };
41
42 #endif // SCIQLOP_GENERATEVARIABLEMENUOPERATION_H
@@ -0,0 +1,200
1 #include "Visualization/operations/GenerateVariableMenuOperation.h"
2
3 #include "Visualization/VisualizationGraphWidget.h"
4 #include "Visualization/VisualizationTabWidget.h"
5 #include "Visualization/VisualizationZoneWidget.h"
6
7 #include <Variable/Variable.h>
8
9 #include <QMenu>
10 #include <QStack>
11
12 Q_LOGGING_CATEGORY(LOG_GenerateVariableMenuOperation, "GenerateVariableMenuOperation")
13
14 namespace {
15
16 /// Helper assigned to build the hierarchical menu associated with a variable
17 struct MenuBuilder {
18 /**
19 * Ctor
20 * @param menu the parent menu
21 */
22 explicit MenuBuilder(QMenu *menu)
23 {
24 if (menu) {
25 m_Menus.push(menu);
26 }
27 else {
28 qCCritical(LOG_GenerateVariableMenuOperation())
29 << QObject::tr("No parent menu has been defined");
30 }
31 }
32
33 /**
34 * Adds action to the current menu
35 * @param actionName the name of the action
36 * @param actionFunction the function that will be executed when the action is triggered
37 */
38 template <typename ActionFun>
39 void addAction(const QString &actionName, ActionFun actionFunction)
40 {
41 if (auto currMenu = currentMenu()) {
42 currMenu->addAction(actionName, actionFunction);
43 }
44 else {
45 qCCritical(LOG_GenerateVariableMenuOperation())
46 << QObject::tr("No current menu to attach the action");
47 }
48 }
49
50 /**
51 * Adds a new menu to the current menu
52 * @param name the name of the menu
53 */
54 void addMenu(const QString &name)
55 {
56 if (auto currMenu = currentMenu()) {
57 m_Menus.push(currMenu->addMenu(name));
58 }
59 else {
60 qCCritical(LOG_GenerateVariableMenuOperation())
61 << QObject::tr("No current menu to attach the new menu");
62 }
63 }
64
65 /// Adds a separator to the current menu. The separator is added only if the menu already
66 /// contains entries
67 void addSeparator()
68 {
69 if (auto currMenu = currentMenu()) {
70 if (!currMenu->isEmpty()) {
71 currMenu->addSeparator();
72 }
73 }
74 else {
75 qCCritical(LOG_GenerateVariableMenuOperation())
76 << QObject::tr("No current menu to attach the separator");
77 }
78 }
79
80 /// Closes the current menu
81 void closeMenu()
82 {
83 if (!m_Menus.isEmpty()) {
84 if (auto closedMenu = m_Menus.pop()) {
85 // Purge menu : if the closed menu has no entries, we remove it from its parent (the
86 // current menu)
87 if (auto currMenu = currentMenu()) {
88 if (closedMenu->isEmpty()) {
89 currMenu->removeAction(closedMenu->menuAction());
90 }
91 }
92 }
93 }
94 }
95
96 /// Gets the current menu (i.e. the top menu of the stack)
97 QMenu *currentMenu() const { return !m_Menus.isEmpty() ? m_Menus.top() : nullptr; }
98
99 /// Stack of all menus currently opened
100 QStack<QMenu *> m_Menus{};
101 };
102
103 } // namespace
104
105 struct GenerateVariableMenuOperation::GenerateVariableMenuOperationPrivate {
106 explicit GenerateVariableMenuOperationPrivate(QMenu *menu, std::shared_ptr<Variable> variable)
107 : m_Variable{variable}, m_MenuBuilder{menu}
108 {
109 }
110
111 void visitNodeEnter(const IVisualizationWidget &container)
112 {
113 // Opens a new menu associated to the node
114 m_MenuBuilder.addMenu(container.name());
115 }
116
117 template <typename ActionFun>
118 void visitNodeLeave(const IVisualizationWidget &container, const QString &actionName,
119 ActionFun actionFunction)
120 {
121 if (m_Variable && container.canDrop(*m_Variable)) {
122 m_MenuBuilder.addSeparator();
123 m_MenuBuilder.addAction(actionName, actionFunction);
124 }
125
126 // Closes the menu associated to the node
127 m_MenuBuilder.closeMenu();
128 }
129
130 template <typename ActionFun>
131 void visitLeaf(const IVisualizationWidget &container, const QString &actionName,
132 ActionFun actionFunction)
133 {
134 if (m_Variable && container.canDrop(*m_Variable)) {
135 m_MenuBuilder.addAction(actionName, actionFunction);
136 }
137 }
138
139 std::shared_ptr<Variable> m_Variable;
140 MenuBuilder m_MenuBuilder;
141 };
142
143 GenerateVariableMenuOperation::GenerateVariableMenuOperation(QMenu *menu,
144 std::shared_ptr<Variable> variable)
145 : impl{spimpl::make_unique_impl<GenerateVariableMenuOperationPrivate>(menu, variable)}
146 {
147 }
148
149 void GenerateVariableMenuOperation::visitEnter(VisualizationWidget *widget)
150 {
151 // VisualizationWidget is not intended to accommodate a variable
152 Q_UNUSED(widget)
153 }
154
155 void GenerateVariableMenuOperation::visitLeave(VisualizationWidget *widget)
156 {
157 // VisualizationWidget is not intended to accommodate a variable
158 Q_UNUSED(widget)
159 }
160
161 void GenerateVariableMenuOperation::visitEnter(VisualizationTabWidget *tabWidget)
162 {
163 if (tabWidget) {
164 impl->visitNodeEnter(*tabWidget);
165 }
166 }
167
168 void GenerateVariableMenuOperation::visitLeave(VisualizationTabWidget *tabWidget)
169 {
170 if (tabWidget) {
171 impl->visitNodeLeave(
172 *tabWidget, QObject::tr("Open in a new zone"),
173 [ var = impl->m_Variable, tabWidget ]() { tabWidget->createZone(var); });
174 }
175 }
176
177 void GenerateVariableMenuOperation::visitEnter(VisualizationZoneWidget *zoneWidget)
178 {
179 if (zoneWidget) {
180 impl->visitNodeEnter(*zoneWidget);
181 }
182 }
183
184 void GenerateVariableMenuOperation::visitLeave(VisualizationZoneWidget *zoneWidget)
185 {
186 if (zoneWidget) {
187 impl->visitNodeLeave(
188 *zoneWidget, QObject::tr("Open in a new graph"),
189 [ var = impl->m_Variable, zoneWidget ]() { zoneWidget->createGraph(var); });
190 }
191 }
192
193 void GenerateVariableMenuOperation::visit(VisualizationGraphWidget *graphWidget)
194 {
195 if (graphWidget) {
196 impl->visitLeaf(
197 *graphWidget, QObject::tr("Open in %1").arg(graphWidget->name()),
198 [ var = impl->m_Variable, graphWidget ]() { graphWidget->addVariable(var); });
199 }
200 }
@@ -1,12 +1,16
1 1 # On ignore toutes les règles vera++ pour le fichier spimpl
2 2
3 3 .*IPSIS_S04_METHOD.*found: Q_DECLARE_LOGGING_CATEGORY.*
4 4 .*IPSIS_S04_VARIABLE.*found: impl.*
5 5
6 6 # Ignore false positive relative to 'noexcept' keyword
7 7 .*IPSIS_S04_VARIABLE.*found: noexcept
8 8 .*IPSIS_S06.*found: noexcept
9 9
10 10 # Ignore false positive relative to 'override' keyword
11 11 .*IPSIS_S04_VARIABLE.*found: override
12 12 .*IPSIS_S06.*found: override
13
14 # Ignore false positive relative to 'final' keyword
15 .*IPSIS_S04_VARIABLE.*found: final
16 .*IPSIS_S06.*found: final
@@ -1,24 +1,26
1 1 #ifndef SCIQLOP_IVISUALIZATIONWIDGET_H
2 2 #define SCIQLOP_IVISUALIZATIONWIDGET_H
3 3
4 #include "Visualization/IVisualizationWidgetVisitor.h"
4 #include "Visualization/IVariableContainer.h"
5 5
6 6 #include <QString>
7 7 #include <memory>
8 8
9 class IVisualizationWidgetVisitor;
10
9 11 /**
10 12 * @brief The IVisualizationWidget handles the visualization widget.
11 13 */
12 class IVisualizationWidget {
14 class IVisualizationWidget : public IVariableContainer {
13 15
14 16 public:
15 17 virtual ~IVisualizationWidget() = default;
16 18
17 19 /// Initializes the plugin
18 virtual void accept(IVisualizationWidget *visitor) = 0;
20 virtual void accept(IVisualizationWidgetVisitor *visitor) = 0;
19 21 virtual void close() = 0;
20 22 virtual QString name() const = 0;
21 23 };
22 24
23 25
24 26 #endif // SCIQLOP_IVISUALIZATIONWIDGET_H
@@ -1,25 +1,28
1 1 #ifndef SCIQLOP_IVISUALIZATIONWIDGETVISITOR_H
2 2 #define SCIQLOP_IVISUALIZATIONWIDGETVISITOR_H
3 3
4 4
5 5 class VisualizationWidget;
6 6 class VisualizationTabWidget;
7 7 class VisualizationZoneWidget;
8 8 class VisualizationGraphWidget;
9 9
10 10 /**
11 11 * @brief The IVisualizationWidgetVisitor handles the visualization widget vistor pattern.
12 12 */
13 13 class IVisualizationWidgetVisitor {
14 14
15 15 public:
16 16 virtual ~IVisualizationWidgetVisitor() = default;
17 17
18 virtual void visit(VisualizationWidget *widget) = 0;
19 virtual void visit(VisualizationTabWidget *tabWidget) = 0;
20 virtual void visit(VisualizationZoneWidget *zoneWidget) = 0;
18 virtual void visitEnter(VisualizationWidget *widget) = 0;
19 virtual void visitLeave(VisualizationWidget *widget) = 0;
20 virtual void visitEnter(VisualizationTabWidget *tabWidget) = 0;
21 virtual void visitLeave(VisualizationTabWidget *tabWidget) = 0;
22 virtual void visitEnter(VisualizationZoneWidget *zoneWidget) = 0;
23 virtual void visitLeave(VisualizationZoneWidget *zoneWidget) = 0;
21 24 virtual void visit(VisualizationGraphWidget *graphWidget) = 0;
22 25 };
23 26
24 27
25 28 #endif // SCIQLOP_IVISUALIZATIONWIDGETVISITOR_H
@@ -1,43 +1,44
1 1 #ifndef SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
2 2 #define SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
3 3
4 4 #include "Visualization/IVisualizationWidget.h"
5 5
6 6 #include <QWidget>
7 7
8 8 #include <memory>
9 9
10 10 #include <Common/spimpl.h>
11 11
12 12 class Variable;
13 13
14 14 namespace Ui {
15 15 class VisualizationGraphWidget;
16 16 } // namespace Ui
17 17
18 18 class VisualizationGraphWidget : public QWidget, public IVisualizationWidget {
19 19 Q_OBJECT
20 20
21 21 public:
22 22 explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0);
23 23 virtual ~VisualizationGraphWidget();
24 24
25 25 void addVariable(std::shared_ptr<Variable> variable);
26 26
27 27 // IVisualizationWidget interface
28 void accept(IVisualizationWidget *visitor) override;
28 void accept(IVisualizationWidgetVisitor *visitor) override;
29 bool canDrop(const Variable &variable) const override;
29 30 void close() override;
30 31 QString name() const;
31 32
32 33 private:
33 34 Ui::VisualizationGraphWidget *ui;
34 35
35 36 class VisualizationGraphWidgetPrivate;
36 37 spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl;
37 38
38 39 private slots:
39 40 /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done
40 41 void onMouseWheel(QWheelEvent *event) noexcept;
41 42 };
42 43
43 44 #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
@@ -1,50 +1,51
1 1 #ifndef SCIQLOP_VISUALIZATIONTABWIDGET_H
2 2 #define SCIQLOP_VISUALIZATIONTABWIDGET_H
3 3
4 4 #include "Visualization/IVisualizationWidget.h"
5 5
6 6 #include <Common/spimpl.h>
7 7
8 8 #include <QWidget>
9 9
10 10 class Variable;
11 11 class VisualizationZoneWidget;
12 12
13 13 namespace Ui {
14 14 class VisualizationTabWidget;
15 15 } // namespace Ui
16 16
17 17 class VisualizationTabWidget : public QWidget, public IVisualizationWidget {
18 18 Q_OBJECT
19 19
20 20 public:
21 21 explicit VisualizationTabWidget(const QString &name = {}, QWidget *parent = 0);
22 22 virtual ~VisualizationTabWidget();
23 23
24 24 /// Add a zone widget
25 25 void addZone(VisualizationZoneWidget *zoneWidget);
26 26
27 27 /**
28 28 * Creates a zone using a variable. The variable will be displayed in a new graph of the new
29 29 * zone.
30 30 * @param variable the variable for which to create the zone
31 31 * @return the pointer to the created zone
32 32 */
33 33 VisualizationZoneWidget *createZone(std::shared_ptr<Variable> variable);
34 34
35 35 /// Remove a zone
36 36 void removeZone(VisualizationZoneWidget *zone);
37 37
38 38 // IVisualizationWidget interface
39 void accept(IVisualizationWidget *visitor) override;
39 void accept(IVisualizationWidgetVisitor *visitor) override;
40 bool canDrop(const Variable &variable) const override;
40 41 void close() override;
41 42 QString name() const override;
42 43
43 44 private:
44 45 Ui::VisualizationTabWidget *ui;
45 46
46 47 class VisualizationTabWidgetPrivate;
47 48 spimpl::unique_impl_ptr<VisualizationTabWidgetPrivate> impl;
48 49 };
49 50
50 51 #endif // SCIQLOP_VISUALIZATIONTABWIDGET_H
@@ -1,52 +1,53
1 1 #ifndef SCIQLOP_VISUALIZATIONWIDGET_H
2 2 #define SCIQLOP_VISUALIZATIONWIDGET_H
3 3
4 4 #include "Visualization/IVisualizationWidget.h"
5 5
6 6 #include <QLoggingCategory>
7 7 #include <QWidget>
8 8
9 9 class Variable;
10 10 class VisualizationTabWidget;
11 11
12 12 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationWidget)
13 13
14 14 namespace Ui {
15 15 class VisualizationWidget;
16 16 } // namespace Ui
17 17
18 18 class VisualizationWidget : public QWidget, public IVisualizationWidget {
19 19 Q_OBJECT
20 20
21 21 public:
22 22 explicit VisualizationWidget(QWidget *parent = 0);
23 23 virtual ~VisualizationWidget();
24 24
25 25 /// Add a zone widget
26 26 virtual void addTab(VisualizationTabWidget *tabWidget);
27 27
28 28 /// Create a tab using a Variable
29 29 VisualizationTabWidget *createTab();
30 30
31 31 /// Remove a tab
32 32 void removeTab(VisualizationTabWidget *tab);
33 33
34 34 // IVisualizationWidget interface
35 void accept(IVisualizationWidget *visitor) override;
35 void accept(IVisualizationWidgetVisitor *visitor) override;
36 bool canDrop(const Variable &variable) const override;
36 37 void close() override;
37 38 QString name() const;
38 39
39 40 public slots:
40 41 /**
41 42 * Displays a variable in a new graph of a new zone of the current tab
42 43 * @param variable the variable to display
43 44 * @todo this is a temporary method that will be replaced by own actions for each type of
44 45 * visualization widget
45 46 */
46 47 void displayVariable(std::shared_ptr<Variable> variable) noexcept;
47 48
48 49 private:
49 50 Ui::VisualizationWidget *ui;
50 51 };
51 52
52 53 #endif // VISUALIZATIONWIDGET_H
@@ -1,44 +1,45
1 1 #ifndef SCIQLOP_VISUALIZATIONZONEWIDGET_H
2 2 #define SCIQLOP_VISUALIZATIONZONEWIDGET_H
3 3
4 4 #include "Visualization/IVisualizationWidget.h"
5 5
6 6 #include <QWidget>
7 7
8 8 namespace Ui {
9 9 class VisualizationZoneWidget;
10 10 } // Ui
11 11
12 12 class Variable;
13 13 class VisualizationGraphWidget;
14 14
15 15 class VisualizationZoneWidget : public QWidget, public IVisualizationWidget {
16 16 Q_OBJECT
17 17
18 18 public:
19 19 explicit VisualizationZoneWidget(const QString &name = {}, QWidget *parent = 0);
20 20 virtual ~VisualizationZoneWidget();
21 21
22 22 /// Add a graph widget
23 23 void addGraph(VisualizationGraphWidget *graphWidget);
24 24
25 25 /**
26 26 * Creates a graph using a variable. The variable will be displayed in the new graph.
27 27 * @param variable the variable for which to create the graph
28 28 * @return the pointer to the created graph
29 29 */
30 30 VisualizationGraphWidget *createGraph(std::shared_ptr<Variable> variable);
31 31
32 32 /// Remove a graph
33 33 void removeGraph(VisualizationGraphWidget *graph);
34 34
35 35 // IVisualizationWidget interface
36 void accept(IVisualizationWidget *visitor) override;
36 void accept(IVisualizationWidgetVisitor *visitor) override;
37 bool canDrop(const Variable &variable) const override;
37 38 void close() override;
38 39 QString name() const override;
39 40
40 41 private:
41 42 Ui::VisualizationZoneWidget *ui;
42 43 };
43 44
44 45 #endif // SCIQLOP_VISUALIZATIONZONEWIDGET_H
@@ -1,95 +1,105
1 1 #include "Visualization/VisualizationGraphWidget.h"
2 2 #include "Visualization/GraphPlottablesFactory.h"
3 #include "Visualization/IVisualizationWidgetVisitor.h"
3 4 #include "ui_VisualizationGraphWidget.h"
4 5
5 6 #include <Variable/Variable.h>
6 7
7 8 #include <unordered_map>
8 9
9 10 namespace {
10 11
11 12 /// Key pressed to enable zoom on horizontal axis
12 13 const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier;
13 14
14 15 /// Key pressed to enable zoom on vertical axis
15 16 const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier;
16 17
17 18 } // namespace
18 19
19 20 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
20 21
21 22 // 1 variable -> n qcpplot
22 23 std::unordered_map<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMap;
23 24 };
24 25
25 26 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent)
26 27 : QWidget{parent},
27 28 ui{new Ui::VisualizationGraphWidget},
28 29 impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()}
29 30 {
30 31 ui->setupUi(this);
31 32
32 33 // qcpplot title
33 34 ui->widget->plotLayout()->insertRow(0);
34 35 ui->widget->plotLayout()->addElement(0, 0, new QCPTextElement{ui->widget, name});
35 36
36 37 // Set qcpplot properties :
37 38 // - Drag (on x-axis) and zoom are enabled
38 39 // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation
39 40 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
40 41 ui->widget->axisRect()->setRangeDrag(Qt::Horizontal);
41 42 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
42 43 }
43 44
44 45 VisualizationGraphWidget::~VisualizationGraphWidget()
45 46 {
46 47 delete ui;
47 48 }
48 49
49 50 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
50 51 {
51 52 // Uses delegate to create the qcpplot components according to the variable
52 53 auto createdPlottables = GraphPlottablesFactory::create(variable, *ui->widget);
53 54
54 55 for (auto createdPlottable : qAsConst(createdPlottables)) {
55 56 impl->m_VariableToPlotMap.insert({variable, createdPlottable});
56 57 }
57 58 }
58 59
59 void VisualizationGraphWidget::accept(IVisualizationWidget *visitor)
60 void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor)
60 61 {
61 // TODO: manage the visitor
62 if (visitor) {
63 visitor->visit(this);
64 }
65 }
66
67 bool VisualizationGraphWidget::canDrop(const Variable &variable) const
68 {
69 /// @todo : for the moment, a graph can always accomodate a variable
70 Q_UNUSED(variable);
71 return true;
62 72 }
63 73
64 74 void VisualizationGraphWidget::close()
65 75 {
66 76 // The main view cannot be directly closed.
67 77 return;
68 78 }
69 79
70 80 QString VisualizationGraphWidget::name() const
71 81 {
72 82 if (auto title = dynamic_cast<QCPTextElement *>(ui->widget->plotLayout()->elementAt(0))) {
73 83 return title->text();
74 84 }
75 85 else {
76 86 return QString{};
77 87 }
78 88 }
79 89
80 90 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
81 91 {
82 92 auto zoomOrientations = QFlags<Qt::Orientation>{};
83 93
84 94 // Lambda that enables a zoom orientation if the key modifier related to this orientation has
85 95 // been pressed
86 96 auto enableOrientation
87 97 = [&zoomOrientations, event](const auto &orientation, const auto &modifier) {
88 98 auto orientationEnabled = event->modifiers().testFlag(modifier);
89 99 zoomOrientations.setFlag(orientation, orientationEnabled);
90 100 };
91 101 enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER);
92 102 enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER);
93 103
94 104 ui->widget->axisRect()->setRangeZoom(zoomOrientations);
95 105 }
@@ -1,77 +1,99
1 1 #include "Visualization/VisualizationTabWidget.h"
2 #include "Visualization/IVisualizationWidgetVisitor.h"
2 3 #include "ui_VisualizationTabWidget.h"
3 4
4 5 #include "Visualization/VisualizationZoneWidget.h"
5 6
6 7 namespace {
7 8
8 9 /// Generates a default name for a new zone, according to the number of zones already displayed in
9 10 /// the tab
10 11 QString defaultZoneName(const QLayout &layout)
11 12 {
12 13 auto count = 0;
13 14 for (auto i = 0; i < layout.count(); ++i) {
14 15 if (dynamic_cast<VisualizationZoneWidget *>(layout.itemAt(i)->widget())) {
15 16 count++;
16 17 }
17 18 }
18 19
19 20 return QObject::tr("Zone %1").arg(count + 1);
20 21 }
21 22
22 23 } // namespace
23 24
24 25 struct VisualizationTabWidget::VisualizationTabWidgetPrivate {
25 26 explicit VisualizationTabWidgetPrivate(const QString &name) : m_Name{name} {}
26 27
27 28 QString m_Name;
28 29 };
29 30
30 31 VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *parent)
31 32 : QWidget{parent},
32 33 ui{new Ui::VisualizationTabWidget},
33 34 impl{spimpl::make_unique_impl<VisualizationTabWidgetPrivate>(name)}
34 35 {
35 36 ui->setupUi(this);
36 37 }
37 38
38 39 VisualizationTabWidget::~VisualizationTabWidget()
39 40 {
40 41 delete ui;
41 42 }
42 43
43 44 void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget)
44 45 {
45 46 this->layout()->addWidget(zoneWidget);
46 47 }
47 48
48 49 VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Variable> variable)
49 50 {
50 51 auto zoneWidget = new VisualizationZoneWidget{defaultZoneName(*layout()), this};
51 52 this->addZone(zoneWidget);
52 53
53 54 // Creates a new graph into the zone
54 55 zoneWidget->createGraph(variable);
55 56
56 57 return zoneWidget;
57 58 }
58 59
59 60 void VisualizationTabWidget::removeZone(VisualizationZoneWidget *zone)
60 61 {
61 62 }
62 63
63 void VisualizationTabWidget::accept(IVisualizationWidget *visitor)
64 void VisualizationTabWidget::accept(IVisualizationWidgetVisitor *visitor)
64 65 {
65 // TODO: manage the visitor
66 if (visitor) {
67 visitor->visitEnter(this);
68
69 // Apply visitor to zone children
70 for (auto i = 0; i < layout()->count(); ++i) {
71 if (auto item = layout()->itemAt(i)) {
72 if (auto visualizationZoneWidget
73 = dynamic_cast<VisualizationZoneWidget *>(item->widget())) {
74 visualizationZoneWidget->accept(visitor);
75 }
76 }
77 }
78
79 visitor->visitLeave(this);
80 }
81 }
82
83 bool VisualizationTabWidget::canDrop(const Variable &variable) const
84 {
85 // A tab can always accomodate a variable
86 Q_UNUSED(variable);
87 return true;
66 88 }
67 89
68 90 void VisualizationTabWidget::close()
69 91 {
70 92 // The main view cannot be directly closed.
71 93 return;
72 94 }
73 95
74 96 QString VisualizationTabWidget::name() const
75 97 {
76 98 return impl->m_Name;
77 99 }
@@ -1,112 +1,132
1 1 #include "Visualization/VisualizationWidget.h"
2 #include "Visualization/IVisualizationWidgetVisitor.h"
2 3 #include "Visualization/VisualizationGraphWidget.h"
3 4 #include "Visualization/VisualizationTabWidget.h"
4 5 #include "Visualization/VisualizationZoneWidget.h"
5 6 #include "Visualization/qcustomplot.h"
6 7
7 8 #include "ui_VisualizationWidget.h"
8 9
9 10 #include <QToolButton>
10 11
11 12 Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget")
12 13
13 14 VisualizationWidget::VisualizationWidget(QWidget *parent)
14 15 : QWidget{parent}, ui{new Ui::VisualizationWidget}
15 16 {
16 17 ui->setupUi(this);
17 18
18 19 auto addTabViewButton = new QToolButton{ui->tabWidget};
19 20 addTabViewButton->setText(tr("Add View"));
20 21 addTabViewButton->setCursor(Qt::ArrowCursor);
21 22 ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner);
22 23
23 24 auto enableMinimumCornerWidgetSize = [this](bool enable) {
24 25
25 26 auto tabViewCornerWidget = ui->tabWidget->cornerWidget();
26 27 auto width = enable ? tabViewCornerWidget->width() : 0;
27 28 auto height = enable ? tabViewCornerWidget->height() : 0;
28 29 tabViewCornerWidget->setMinimumHeight(height);
29 30 tabViewCornerWidget->setMinimumWidth(width);
30 31 ui->tabWidget->setMinimumHeight(height);
31 32 ui->tabWidget->setMinimumWidth(width);
32 33 };
33 34
34 35 auto addTabView = [this, enableMinimumCornerWidgetSize]() {
35 36 auto widget = new VisualizationTabWidget{QString{"View %1"}.arg(ui->tabWidget->count() + 1),
36 37 ui->tabWidget};
37 38 auto index = ui->tabWidget->addTab(widget, widget->name());
38 39 if (ui->tabWidget->count() > 0) {
39 40 enableMinimumCornerWidgetSize(false);
40 41 }
41 42 qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index);
42 43 };
43 44
44 45 auto removeTabView = [this, enableMinimumCornerWidgetSize](int index) {
45 46 if (ui->tabWidget->count() == 1) {
46 47 enableMinimumCornerWidgetSize(true);
47 48 }
48 49
49 50 ui->tabWidget->removeTab(index);
50 51 qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index);
51 52
52 53 };
53 54
54 55 ui->tabWidget->setTabsClosable(true);
55 56
56 57 connect(addTabViewButton, &QToolButton::clicked, addTabView);
57 58 connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView);
58 59
59 60 // Adds default tab
60 61 addTabView();
61 62 }
62 63
63 64 VisualizationWidget::~VisualizationWidget()
64 65 {
65 66 delete ui;
66 67 }
67 68
68 69 void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget)
69 70 {
70 71 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
71 72 // lambda function (in the constructor)
72 73 }
73 74
74 75 VisualizationTabWidget *VisualizationWidget::createTab()
75 76 {
76 77 }
77 78
78 79 void VisualizationWidget::removeTab(VisualizationTabWidget *tab)
79 80 {
80 81 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
81 82 // lambda function (in the constructor)
82 83 }
83 84
84 void VisualizationWidget::accept(IVisualizationWidget *visitor)
85 void VisualizationWidget::accept(IVisualizationWidgetVisitor *visitor)
85 86 {
86 // TODO: manage the visitor
87 if (visitor) {
88 visitor->visitEnter(this);
89
90 // Apply visitor for tab children
91 for (auto i = 0; i < ui->tabWidget->count(); ++i) {
92 if (auto visualizationTabWidget
93 = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->widget(i))) {
94 visualizationTabWidget->accept(visitor);
95 }
96 }
97
98 visitor->visitLeave(this);
99 }
100 }
101
102 bool VisualizationWidget::canDrop(const Variable &variable) const
103 {
104 // The main widget can never accomodate a variable
105 Q_UNUSED(variable);
106 return false;
87 107 }
88 108
89 109 void VisualizationWidget::close()
90 110 {
91 111 // The main view cannot be directly closed.
92 112 return;
93 113 }
94 114
95 115 QString VisualizationWidget::name() const
96 116 {
97 117 return QStringLiteral("MainView");
98 118 }
99 119
100 120 void VisualizationWidget::displayVariable(std::shared_ptr<Variable> variable) noexcept
101 121 {
102 122 if (auto currentTab = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->currentWidget())) {
103 123 if (!currentTab->createZone(variable)) {
104 124 qCCritical(LOG_VisualizationWidget())
105 125 << tr("Can't display the variable : can't create a new zone in the current tab");
106 126 }
107 127 }
108 128 else {
109 129 qCCritical(LOG_VisualizationWidget())
110 130 << tr("Can't display the variable : there is no current tab");
111 131 }
112 132 }
@@ -1,71 +1,94
1 1 #include "Visualization/VisualizationZoneWidget.h"
2 #include "Visualization/IVisualizationWidgetVisitor.h"
2 3 #include "ui_VisualizationZoneWidget.h"
3 4
4 5 #include "Visualization/VisualizationGraphWidget.h"
5 6
6 7 namespace {
7 8
8 9 /// Generates a default name for a new graph, according to the number of graphs already displayed in
9 10 /// the zone
10 11 QString defaultGraphName(const QLayout &layout)
11 12 {
12 13 auto count = 0;
13 14 for (auto i = 0; i < layout.count(); ++i) {
14 15 if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) {
15 16 count++;
16 17 }
17 18 }
18 19
19 20 return QObject::tr("Graph %1").arg(count + 1);
20 21 }
21 22
22 23 } // namespace
23 24
24 25 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent)
25 26 : QWidget{parent}, ui{new Ui::VisualizationZoneWidget}
26 27 {
27 28 ui->setupUi(this);
28 29
29 30 ui->zoneNameLabel->setText(name);
30 31 }
31 32
32 33 VisualizationZoneWidget::~VisualizationZoneWidget()
33 34 {
34 35 delete ui;
35 36 }
36 37
37 38 void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget)
38 39 {
39 40 ui->visualizationZoneFrame->layout()->addWidget(graphWidget);
40 41 }
41 42
42 43 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable)
43 44 {
44 45 auto graphWidget = new VisualizationGraphWidget{
45 46 defaultGraphName(*ui->visualizationZoneFrame->layout()), this};
46 47 this->addGraph(graphWidget);
47 48
48 49 graphWidget->addVariable(variable);
49 50
50 51 return graphWidget;
51 52 }
52 53
53 54 void VisualizationZoneWidget::removeGraph(VisualizationGraphWidget *graph)
54 55 {
55 56 }
56 57
57 void VisualizationZoneWidget::accept(IVisualizationWidget *visitor)
58 void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor)
58 59 {
59 // TODO: manage the visitor
60 if (visitor) {
61 visitor->visitEnter(this);
62
63 // Apply visitor to graph children
64 auto layout = ui->visualizationZoneFrame->layout();
65 for (auto i = 0; i < layout->count(); ++i) {
66 if (auto item = layout->itemAt(i)) {
67 if (auto visualizationGraphWidget
68 = dynamic_cast<VisualizationGraphWidget *>(item->widget())) {
69 visualizationGraphWidget->accept(visitor);
70 }
71 }
72 }
73
74 visitor->visitLeave(this);
75 }
76 }
77
78 bool VisualizationZoneWidget::canDrop(const Variable &variable) const
79 {
80 // A tab can always accomodate a variable
81 Q_UNUSED(variable);
82 return true;
60 83 }
61 84
62 85 void VisualizationZoneWidget::close()
63 86 {
64 87 // The main view cannot be directly closed.
65 88 return;
66 89 }
67 90
68 91 QString VisualizationZoneWidget::name() const
69 92 {
70 93 return ui->zoneNameLabel->text();
71 94 }
@@ -1,13 +1,14
1 1 \.h:\d+:.IPSIS_S04.*found: ui
2 2 qcustomplot\.h:\d+:.IPSIS
3 3 qcustomplot\.cpp:\d+:.IPSIS
4 4
5 5 # Ignore false positive relative to App macro
6 6 SqpApplication\.h:\d+:.IPSIS_S03.*found: sqpApp
7 7 SqpApplication\.h:\d+:.IPSIS_S04_VARIABLE.*found: sqpApp
8 8
9 9 # Ignore false positive relative to unnamed namespace
10 10 DataSourceTreeWidgetItem\.cpp:\d+:.*IPSIS_F13.*
11 GenerateVariableMenuOperation\.cpp:\d+:.*IPSIS_F13.*
11 12 VisualizationTabWidget\.cpp:\d+:.*IPSIS_F13.*
12 13 VisualizationZoneWidget\.cpp:\d+:.*IPSIS_F13.*
13 14
General Comments 0
You need to be logged in to leave comments. Login now