##// END OF EJS Templates
Sets sames margin sides for graphs in a same zone
Alexandre Leroux -
r671:2d96f9af06b9
parent child
Show More
@@ -0,0 +1,24
1 #ifndef SCIQLOP_IGRAPHSYNCHRONIZER_H
2 #define SCIQLOP_IGRAPHSYNCHRONIZER_H
3
4 class VisualizationGraphWidget;
5
6 /**
7 * @brief The IVisualizationSynchronizer interface represents a delegate used to manage the
8 * synchronization between graphs, applying them processes or properties to ensure their
9 * synchronization
10 */
11 class IGraphSynchronizer {
12
13 public:
14 virtual ~IGraphSynchronizer() = default;
15
16 /**
17 * Adds a graph as a new synchronized element, and sets its properties so that its
18 * synchronization is maintained with all other graphs managed by the synchonizer
19 * @param graph the graph to add in the synchronization
20 */
21 virtual void addGraph(VisualizationGraphWidget &graph) const = 0;
22 };
23
24 #endif // SCIQLOP_IGRAPHSYNCHRONIZER_H
@@ -0,0 +1,26
1 #ifndef SCIQLOP_QCUSTOMPLOTSYNCHRONIZER_H
2 #define SCIQLOP_QCUSTOMPLOTSYNCHRONIZER_H
3
4 #include "Visualization/IGraphSynchronizer.h"
5
6 #include <Common/spimpl.h>
7
8 /**
9 * @brief The QCustomPlotSynchronizer class is an implementation of IGraphSynchronizer that handles
10 * graphs using QCustomPlot elements
11 * @sa IGraphSynchronizer
12 * @sa QCustomPlot
13 */
14 class QCustomPlotSynchronizer : public IGraphSynchronizer {
15 public:
16 explicit QCustomPlotSynchronizer();
17
18 /// @sa IGraphSynchronizer::addGraph()
19 virtual void addGraph(VisualizationGraphWidget &graph) const override;
20
21 private:
22 class QCustomPlotSynchronizerPrivate;
23 spimpl::unique_impl_ptr<QCustomPlotSynchronizerPrivate> impl;
24 };
25
26 #endif // SCIQLOP_QCUSTOMPLOTSYNCHRONIZER_H
@@ -0,0 +1,30
1 #include "Visualization/QCustomPlotSynchronizer.h"
2
3 #include "Visualization/VisualizationGraphWidget.h"
4 #include "Visualization/qcustomplot.h"
5
6 struct QCustomPlotSynchronizer::QCustomPlotSynchronizerPrivate {
7 explicit QCustomPlotSynchronizerPrivate()
8 : m_MarginGroup{std::make_unique<QCPMarginGroup>(nullptr)}
9 {
10 }
11
12 /// Sets the same margin sides for all added plot elements
13 std::unique_ptr<QCPMarginGroup> m_MarginGroup;
14 };
15
16 QCustomPlotSynchronizer::QCustomPlotSynchronizer()
17 : impl{spimpl::make_unique_impl<QCustomPlotSynchronizerPrivate>()}
18 {
19 }
20
21 void QCustomPlotSynchronizer::addGraph(VisualizationGraphWidget &graph) const
22 {
23 // Adds all plot elements of the graph to the margin group: all these elements will then have
24 // the same margin sides
25 auto &plot = graph.plot();
26 for (auto axisRect : plot.axisRects()) {
27 // Sames margin sides at left and right
28 axisRect->setMarginGroup(QCP::msLeft | QCP::msRight, impl->m_MarginGroup.get());
29 }
30 }
@@ -24,6 +24,7 class VisualizationGraphWidget;
24 class VisualizationGraphWidget : public QWidget, public IVisualizationWidget {
24 class VisualizationGraphWidget : public QWidget, public IVisualizationWidget {
25 Q_OBJECT
25 Q_OBJECT
26
26
27 friend class QCustomPlotSynchronizer;
27 friend class VisualizationGraphRenderingDelegate;
28 friend class VisualizationGraphRenderingDelegate;
28
29
29 public:
30 public:
@@ -53,6 +53,7 gui_sources = [
53 'src/Visualization/VisualizationWidget.cpp',
53 'src/Visualization/VisualizationWidget.cpp',
54 'src/Visualization/VisualizationZoneWidget.cpp',
54 'src/Visualization/VisualizationZoneWidget.cpp',
55 'src/Visualization/qcustomplot.cpp',
55 'src/Visualization/qcustomplot.cpp',
56 'src/Visualization/QCustomPlotSynchronizer.cpp',
56 'src/Visualization/operations/GenerateVariableMenuOperation.cpp',
57 'src/Visualization/operations/GenerateVariableMenuOperation.cpp',
57 'src/Visualization/operations/MenuBuilder.cpp',
58 'src/Visualization/operations/MenuBuilder.cpp',
58 'src/Visualization/operations/RemoveVariableOperation.cpp',
59 'src/Visualization/operations/RemoveVariableOperation.cpp',
@@ -1,7 +1,7
1 #include "Visualization/VisualizationZoneWidget.h"
1 #include "Visualization/VisualizationZoneWidget.h"
2
2
3
4 #include "Visualization/IVisualizationWidgetVisitor.h"
3 #include "Visualization/IVisualizationWidgetVisitor.h"
4 #include "Visualization/QCustomPlotSynchronizer.h"
5 #include "Visualization/VisualizationGraphWidget.h"
5 #include "Visualization/VisualizationGraphWidget.h"
6 #include "ui_VisualizationZoneWidget.h"
6 #include "ui_VisualizationZoneWidget.h"
7
7
@@ -38,8 +38,13 QString defaultGraphName(const QLayout &layout)
38
38
39 struct VisualizationZoneWidget::VisualizationZoneWidgetPrivate {
39 struct VisualizationZoneWidget::VisualizationZoneWidgetPrivate {
40
40
41 explicit VisualizationZoneWidgetPrivate() : m_SynchronisationGroupId{QUuid::createUuid()} {}
41 explicit VisualizationZoneWidgetPrivate()
42 : m_SynchronisationGroupId{QUuid::createUuid()},
43 m_Synchronizer{std::make_unique<QCustomPlotSynchronizer>()}
44 {
45 }
42 QUuid m_SynchronisationGroupId;
46 QUuid m_SynchronisationGroupId;
47 std::unique_ptr<IGraphSynchronizer> m_Synchronizer;
43 };
48 };
44
49
45 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent)
50 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent)
@@ -68,6 +73,9 VisualizationZoneWidget::~VisualizationZoneWidget()
68
73
69 void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget)
74 void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget)
70 {
75 {
76 // Synchronize new graph with others in the zone
77 impl->m_Synchronizer->addGraph(*graphWidget);
78
71 ui->visualizationZoneFrame->layout()->addWidget(graphWidget);
79 ui->visualizationZoneFrame->layout()->addWidget(graphWidget);
72 }
80 }
73
81
General Comments 0
You need to be logged in to leave comments. Login now