@@ -0,0 +1,41 | |||
|
1 | #ifndef SCIQLOP_REMOVEVARIABLEOPERATION_H | |
|
2 | #define SCIQLOP_REMOVEVARIABLEOPERATION_H | |
|
3 | ||
|
4 | #include "Visualization/IVisualizationWidgetVisitor.h" | |
|
5 | ||
|
6 | #include <Common/spimpl.h> | |
|
7 | ||
|
8 | #include <QLoggingCategory> | |
|
9 | ||
|
10 | #include <memory> | |
|
11 | ||
|
12 | class Variable; | |
|
13 | ||
|
14 | Q_DECLARE_LOGGING_CATEGORY(LOG_RemoveVariableOperation) | |
|
15 | ||
|
16 | /** | |
|
17 | * @brief The RemoveVariableOperation class defines an operation that traverses all of visualization | |
|
18 | * widgets to remove a variable if they contain it | |
|
19 | */ | |
|
20 | class RemoveVariableOperation : public IVisualizationWidgetVisitor { | |
|
21 | public: | |
|
22 | /** | |
|
23 | * Ctor | |
|
24 | * @param variable the variable to remove from widgets | |
|
25 | */ | |
|
26 | explicit RemoveVariableOperation(std::shared_ptr<Variable> variable); | |
|
27 | ||
|
28 | void visitEnter(VisualizationWidget *widget) override final; | |
|
29 | void visitLeave(VisualizationWidget *widget) override final; | |
|
30 | void visitEnter(VisualizationTabWidget *tabWidget) override final; | |
|
31 | void visitLeave(VisualizationTabWidget *tabWidget) override final; | |
|
32 | void visitEnter(VisualizationZoneWidget *zoneWidget) override final; | |
|
33 | void visitLeave(VisualizationZoneWidget *zoneWidget) override final; | |
|
34 | void visit(VisualizationGraphWidget *graphWidget) override final; | |
|
35 | ||
|
36 | private: | |
|
37 | class RemoveVariableOperationPrivate; | |
|
38 | spimpl::unique_impl_ptr<RemoveVariableOperationPrivate> impl; | |
|
39 | }; | |
|
40 | ||
|
41 | #endif // SCIQLOP_REMOVEVARIABLEOPERATION_H |
@@ -0,0 +1,70 | |||
|
1 | #include "Visualization/operations/RemoveVariableOperation.h" | |
|
2 | #include "Visualization/VisualizationGraphWidget.h" | |
|
3 | ||
|
4 | #include <Variable/Variable.h> | |
|
5 | ||
|
6 | Q_LOGGING_CATEGORY(LOG_RemoveVariableOperation, "RemoveVariableOperation") | |
|
7 | ||
|
8 | struct RemoveVariableOperation::RemoveVariableOperationPrivate { | |
|
9 | explicit RemoveVariableOperationPrivate(std::shared_ptr<Variable> variable) | |
|
10 | : m_Variable(variable) | |
|
11 | { | |
|
12 | } | |
|
13 | ||
|
14 | std::shared_ptr<Variable> m_Variable; | |
|
15 | }; | |
|
16 | ||
|
17 | RemoveVariableOperation::RemoveVariableOperation(std::shared_ptr<Variable> variable) | |
|
18 | : impl{spimpl::make_unique_impl<RemoveVariableOperationPrivate>(variable)} | |
|
19 | { | |
|
20 | } | |
|
21 | ||
|
22 | void RemoveVariableOperation::visitEnter(VisualizationWidget *widget) | |
|
23 | { | |
|
24 | // VisualizationWidget is not intended to contain a variable | |
|
25 | Q_UNUSED(widget) | |
|
26 | } | |
|
27 | ||
|
28 | void RemoveVariableOperation::visitLeave(VisualizationWidget *widget) | |
|
29 | { | |
|
30 | // VisualizationWidget is not intended to contain a variable | |
|
31 | Q_UNUSED(widget) | |
|
32 | } | |
|
33 | ||
|
34 | void RemoveVariableOperation::visitEnter(VisualizationTabWidget *tabWidget) | |
|
35 | { | |
|
36 | // VisualizationTabWidget is not intended to contain a variable | |
|
37 | Q_UNUSED(tabWidget) | |
|
38 | } | |
|
39 | ||
|
40 | void RemoveVariableOperation::visitLeave(VisualizationTabWidget *tabWidget) | |
|
41 | { | |
|
42 | // VisualizationTabWidget is not intended to contain a variable | |
|
43 | Q_UNUSED(tabWidget) | |
|
44 | } | |
|
45 | ||
|
46 | void RemoveVariableOperation::visitEnter(VisualizationZoneWidget *zoneWidget) | |
|
47 | { | |
|
48 | // VisualizationZoneWidget is not intended to contain a variable | |
|
49 | Q_UNUSED(zoneWidget) | |
|
50 | } | |
|
51 | ||
|
52 | void RemoveVariableOperation::visitLeave(VisualizationZoneWidget *zoneWidget) | |
|
53 | { | |
|
54 | // VisualizationZoneWidget is not intended to contain a variable | |
|
55 | Q_UNUSED(zoneWidget) | |
|
56 | } | |
|
57 | ||
|
58 | void RemoveVariableOperation::visit(VisualizationGraphWidget *graphWidget) | |
|
59 | { | |
|
60 | if (graphWidget) { | |
|
61 | // If the widget contains the variable, removes it | |
|
62 | if (impl->m_Variable && graphWidget->contains(*impl->m_Variable)) { | |
|
63 | graphWidget->removeVariable(impl->m_Variable); | |
|
64 | } | |
|
65 | } | |
|
66 | else { | |
|
67 | qCCritical(LOG_RemoveVariableOperation(), | |
|
68 | "Can't visit VisualizationGraphWidget : the widget is null"); | |
|
69 | } | |
|
70 | } |
General Comments 0
You need to be logged in to leave comments.
Login now