From 4f6deb054427042a8b3850872414ef8e4750c56a 2017-09-14 07:14:22 From: Alexandre Leroux Date: 2017-09-14 07:14:22 Subject: [PATCH] Prohibits the plot of a variable in several graphs (1) Creates operation that find a variable in the visualization tree --- diff --git a/gui/include/Visualization/operations/FindVariableOperation.h b/gui/include/Visualization/operations/FindVariableOperation.h new file mode 100644 index 0000000..afad39e --- /dev/null +++ b/gui/include/Visualization/operations/FindVariableOperation.h @@ -0,0 +1,42 @@ +#ifndef SCIQLOP_FINDVARIABLEOPERATION_H +#define SCIQLOP_FINDVARIABLEOPERATION_H + +#include "Visualization/IVisualizationWidgetVisitor.h" + +#include + +#include + +class IVisualizationWidget; +class Variable; + +/** + * @brief The FindVariableOperation class defines an operation that traverses all of visualization + * widgets to determine which ones contain the variable passed as parameter. The result of the + * operation is the list of widgets that contain the variable. + */ +class FindVariableOperation : public IVisualizationWidgetVisitor { +public: + /** + * Ctor + * @param variable the variable to find + */ + explicit FindVariableOperation(std::shared_ptr variable); + + void visitEnter(VisualizationWidget *widget) override final; + void visitLeave(VisualizationWidget *widget) override final; + void visitEnter(VisualizationTabWidget *tabWidget) override final; + void visitLeave(VisualizationTabWidget *tabWidget) override final; + void visitEnter(VisualizationZoneWidget *zoneWidget) override final; + void visitLeave(VisualizationZoneWidget *zoneWidget) override final; + void visit(VisualizationGraphWidget *graphWidget) override final; + + /// @return the widgets that contain the variable + std::set result() const noexcept; + +private: + class FindVariableOperationPrivate; + spimpl::unique_impl_ptr impl; +}; + +#endif // SCIQLOP_FINDVARIABLEOPERATION_H diff --git a/gui/meson.build b/gui/meson.build index a8ece56..903a518 100644 --- a/gui/meson.build +++ b/gui/meson.build @@ -54,6 +54,7 @@ gui_sources = [ 'src/Visualization/VisualizationZoneWidget.cpp', 'src/Visualization/qcustomplot.cpp', 'src/Visualization/QCustomPlotSynchronizer.cpp', + 'src/Visualization/operations/FindVariableOperation.cpp', 'src/Visualization/operations/GenerateVariableMenuOperation.cpp', 'src/Visualization/operations/MenuBuilder.cpp', 'src/Visualization/operations/RemoveVariableOperation.cpp', diff --git a/gui/src/Visualization/operations/FindVariableOperation.cpp b/gui/src/Visualization/operations/FindVariableOperation.cpp new file mode 100644 index 0000000..eeb4f69 --- /dev/null +++ b/gui/src/Visualization/operations/FindVariableOperation.cpp @@ -0,0 +1,72 @@ +#include "Visualization/operations/FindVariableOperation.h" + +#include "Visualization/VisualizationGraphWidget.h" +#include "Visualization/VisualizationTabWidget.h" +#include "Visualization/VisualizationWidget.h" +#include "Visualization/VisualizationZoneWidget.h" + +#include + +struct FindVariableOperation::FindVariableOperationPrivate { + explicit FindVariableOperationPrivate(std::shared_ptr variable) : m_Variable{variable} + { + } + + void visit(IVisualizationWidget *widget) + { + if (m_Variable && widget && widget->contains(*m_Variable)) { + m_Containers.insert(widget); + } + } + + std::shared_ptr m_Variable; ///< Variable to find + std::set m_Containers; ///< Containers found for the variable +}; + +FindVariableOperation::FindVariableOperation(std::shared_ptr variable) + : impl{spimpl::make_unique_impl(variable)} +{ +} + +void FindVariableOperation::visitEnter(VisualizationWidget *widget) +{ + impl->visit(widget); +} + +void FindVariableOperation::visitLeave(VisualizationWidget *widget) +{ + // Does nothing + Q_UNUSED(widget); +} + +void FindVariableOperation::visitEnter(VisualizationTabWidget *tabWidget) +{ + impl->visit(tabWidget); +} + +void FindVariableOperation::visitLeave(VisualizationTabWidget *tabWidget) +{ + // Does nothing + Q_UNUSED(tabWidget); +} + +void FindVariableOperation::visitEnter(VisualizationZoneWidget *zoneWidget) +{ + impl->visit(zoneWidget); +} + +void FindVariableOperation::visitLeave(VisualizationZoneWidget *zoneWidget) +{ + // Does nothing + Q_UNUSED(zoneWidget); +} + +void FindVariableOperation::visit(VisualizationGraphWidget *graphWidget) +{ + impl->visit(graphWidget); +} + +std::set FindVariableOperation::result() const noexcept +{ + return impl->m_Containers; +}