@@ -1,30 +1,32 | |||||
1 | #ifndef SCIQLOP_GRAPHPLOTTABLESFACTORY_H |
|
1 | #ifndef SCIQLOP_GRAPHPLOTTABLESFACTORY_H | |
2 | #define SCIQLOP_GRAPHPLOTTABLESFACTORY_H |
|
2 | #define SCIQLOP_GRAPHPLOTTABLESFACTORY_H | |
3 |
|
3 | |||
4 | #include <QLoggingCategory> |
|
4 | #include <QLoggingCategory> | |
5 | #include <QVector> |
|
5 | #include <QVector> | |
6 |
|
6 | |||
|
7 | #include <memory> | |||
|
8 | ||||
7 | Q_DECLARE_LOGGING_CATEGORY(LOG_GraphPlottablesFactory) |
|
9 | Q_DECLARE_LOGGING_CATEGORY(LOG_GraphPlottablesFactory) | |
8 |
|
10 | |||
9 | class QCPAbstractPlottable; |
|
11 | class QCPAbstractPlottable; | |
10 | class QCustomPlot; |
|
12 | class QCustomPlot; | |
11 | class Variable; |
|
13 | class Variable; | |
12 |
|
14 | |||
13 | /** |
|
15 | /** | |
14 | * @brief The GraphPlottablesFactory class aims to create the QCustomPlot components relative to a |
|
16 | * @brief The GraphPlottablesFactory class aims to create the QCustomPlot components relative to a | |
15 | * variable, depending on the data series of this variable |
|
17 | * variable, depending on the data series of this variable | |
16 | */ |
|
18 | */ | |
17 | struct GraphPlottablesFactory { |
|
19 | struct GraphPlottablesFactory { | |
18 | /** |
|
20 | /** | |
19 | * Creates (if possible) the QCustomPlot components relative to the variable passed in |
|
21 | * Creates (if possible) the QCustomPlot components relative to the variable passed in | |
20 | * parameter, and adds these to the plot passed in parameter. |
|
22 | * parameter, and adds these to the plot passed in parameter. | |
21 | * @param variable the variable for which to create the components |
|
23 | * @param variable the variable for which to create the components | |
22 | * @param plot the plot in which to add the created components. It takes ownership of these |
|
24 | * @param plot the plot in which to add the created components. It takes ownership of these | |
23 | * components. |
|
25 | * components. | |
24 | * @return the list of the components created |
|
26 | * @return the list of the components created | |
25 | */ |
|
27 | */ | |
26 |
static QVector<QCPAbstractPlottable *> create( |
|
28 | static QVector<QCPAbstractPlottable *> create(std::shared_ptr<Variable> variable, | |
27 | QCustomPlot &plot) noexcept; |
|
29 | QCustomPlot &plot) noexcept; | |
28 | }; |
|
30 | }; | |
29 |
|
31 | |||
30 | #endif // SCIQLOP_GRAPHPLOTTABLESFACTORY_H |
|
32 | #endif // SCIQLOP_GRAPHPLOTTABLESFACTORY_H |
@@ -1,91 +1,91 | |||||
1 | #include "Visualization/GraphPlottablesFactory.h" |
|
1 | #include "Visualization/GraphPlottablesFactory.h" | |
2 | #include "Visualization/qcustomplot.h" |
|
2 | #include "Visualization/qcustomplot.h" | |
3 |
|
3 | |||
4 | #include <Data/ScalarSeries.h> |
|
4 | #include <Data/ScalarSeries.h> | |
5 |
|
5 | |||
6 | #include <Variable/Variable.h> |
|
6 | #include <Variable/Variable.h> | |
7 |
|
7 | |||
8 | Q_LOGGING_CATEGORY(LOG_GraphPlottablesFactory, "GraphPlottablesFactory") |
|
8 | Q_LOGGING_CATEGORY(LOG_GraphPlottablesFactory, "GraphPlottablesFactory") | |
9 |
|
9 | |||
10 | namespace { |
|
10 | namespace { | |
11 |
|
11 | |||
12 | /// Format for datetimes on a axis |
|
12 | /// Format for datetimes on a axis | |
13 | const auto DATETIME_TICKER_FORMAT = QStringLiteral("yyyy/MM/dd \nhh:mm:ss"); |
|
13 | const auto DATETIME_TICKER_FORMAT = QStringLiteral("yyyy/MM/dd \nhh:mm:ss"); | |
14 |
|
14 | |||
15 | /// Generates the appropriate ticker for an axis, depending on whether the axis displays time or |
|
15 | /// Generates the appropriate ticker for an axis, depending on whether the axis displays time or | |
16 | /// non-time data |
|
16 | /// non-time data | |
17 | QSharedPointer<QCPAxisTicker> axisTicker(bool isTimeAxis) |
|
17 | QSharedPointer<QCPAxisTicker> axisTicker(bool isTimeAxis) | |
18 | { |
|
18 | { | |
19 | if (isTimeAxis) { |
|
19 | if (isTimeAxis) { | |
20 | auto dateTicker = QSharedPointer<QCPAxisTickerDateTime>::create(); |
|
20 | auto dateTicker = QSharedPointer<QCPAxisTickerDateTime>::create(); | |
21 | dateTicker->setDateTimeFormat(DATETIME_TICKER_FORMAT); |
|
21 | dateTicker->setDateTimeFormat(DATETIME_TICKER_FORMAT); | |
22 |
|
22 | |||
23 | return dateTicker; |
|
23 | return dateTicker; | |
24 | } |
|
24 | } | |
25 | else { |
|
25 | else { | |
26 | // default ticker |
|
26 | // default ticker | |
27 | return QSharedPointer<QCPAxisTicker>::create(); |
|
27 | return QSharedPointer<QCPAxisTicker>::create(); | |
28 | } |
|
28 | } | |
29 | } |
|
29 | } | |
30 |
|
30 | |||
31 | QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QCustomPlot &plot) |
|
31 | QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QCustomPlot &plot) | |
32 | { |
|
32 | { | |
33 | auto component = plot.addGraph(); |
|
33 | auto component = plot.addGraph(); | |
34 |
|
34 | |||
35 | if (component) { |
|
35 | if (component) { | |
36 | // Graph data |
|
36 | // Graph data | |
37 | component->setData(scalarSeries.xAxisData()->data(), scalarSeries.valuesData()->data(), |
|
37 | component->setData(scalarSeries.xAxisData()->data(), scalarSeries.valuesData()->data(), | |
38 | true); |
|
38 | true); | |
39 |
|
39 | |||
40 | // Axes properties |
|
40 | // Axes properties | |
41 | /// @todo : for the moment, no control is performed on the axes: the units and the tickers |
|
41 | /// @todo : for the moment, no control is performed on the axes: the units and the tickers | |
42 | /// are fixed for the default x-axis and y-axis of the plot, and according to the new graph |
|
42 | /// are fixed for the default x-axis and y-axis of the plot, and according to the new graph | |
43 |
|
43 | |||
44 | auto setAxisProperties = [](auto axis, const auto &unit) { |
|
44 | auto setAxisProperties = [](auto axis, const auto &unit) { | |
45 | // label (unit name) |
|
45 | // label (unit name) | |
46 | axis->setLabel(unit.m_Name); |
|
46 | axis->setLabel(unit.m_Name); | |
47 |
|
47 | |||
48 | // ticker (depending on the type of unit) |
|
48 | // ticker (depending on the type of unit) | |
49 | axis->setTicker(axisTicker(unit.m_TimeUnit)); |
|
49 | axis->setTicker(axisTicker(unit.m_TimeUnit)); | |
50 | }; |
|
50 | }; | |
51 | setAxisProperties(plot.xAxis, scalarSeries.xAxisUnit()); |
|
51 | setAxisProperties(plot.xAxis, scalarSeries.xAxisUnit()); | |
52 | setAxisProperties(plot.yAxis, scalarSeries.valuesUnit()); |
|
52 | setAxisProperties(plot.yAxis, scalarSeries.valuesUnit()); | |
53 |
|
53 | |||
54 | // Display all data |
|
54 | // Display all data | |
55 | component->rescaleAxes(); |
|
55 | component->rescaleAxes(); | |
56 |
|
56 | |||
57 | plot.replot(); |
|
57 | plot.replot(); | |
58 | } |
|
58 | } | |
59 | else { |
|
59 | else { | |
60 | qCDebug(LOG_GraphPlottablesFactory()) |
|
60 | qCDebug(LOG_GraphPlottablesFactory()) | |
61 | << QObject::tr("Can't create graph for the scalar series"); |
|
61 | << QObject::tr("Can't create graph for the scalar series"); | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | return component; |
|
64 | return component; | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | } // namespace |
|
67 | } // namespace | |
68 |
|
68 | |||
69 |
QVector<QCPAbstractPlottable *> GraphPlottablesFactory::create( |
|
69 | QVector<QCPAbstractPlottable *> GraphPlottablesFactory::create(std::shared_ptr<Variable> variable, | |
70 | QCustomPlot &plot) noexcept |
|
70 | QCustomPlot &plot) noexcept | |
71 | { |
|
71 | { | |
72 | auto result = QVector<QCPAbstractPlottable *>{}; |
|
72 | auto result = QVector<QCPAbstractPlottable *>{}; | |
73 |
|
73 | |||
74 | if (variable) { |
|
74 | if (variable) { | |
75 | // Gets the data series of the variable to call the creation of the right components |
|
75 | // Gets the data series of the variable to call the creation of the right components | |
76 | // according to its type |
|
76 | // according to its type | |
77 | if (auto scalarSeries = dynamic_cast<ScalarSeries *>(variable->dataSeries())) { |
|
77 | if (auto scalarSeries = dynamic_cast<ScalarSeries *>(variable->dataSeries())) { | |
78 | result.append(createScalarSeriesComponent(*scalarSeries, plot)); |
|
78 | result.append(createScalarSeriesComponent(*scalarSeries, plot)); | |
79 | } |
|
79 | } | |
80 | else { |
|
80 | else { | |
81 | qCDebug(LOG_GraphPlottablesFactory()) |
|
81 | qCDebug(LOG_GraphPlottablesFactory()) | |
82 | << QObject::tr("Can't create graph plottables : unmanaged data series type"); |
|
82 | << QObject::tr("Can't create graph plottables : unmanaged data series type"); | |
83 | } |
|
83 | } | |
84 | } |
|
84 | } | |
85 | else { |
|
85 | else { | |
86 | qCDebug(LOG_GraphPlottablesFactory()) |
|
86 | qCDebug(LOG_GraphPlottablesFactory()) | |
87 | << QObject::tr("Can't create graph plottables : the variable is null"); |
|
87 | << QObject::tr("Can't create graph plottables : the variable is null"); | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | return result; |
|
90 | return result; | |
91 | } |
|
91 | } |
@@ -1,86 +1,86 | |||||
1 | #include "Visualization/VisualizationGraphWidget.h" |
|
1 | #include "Visualization/VisualizationGraphWidget.h" | |
2 | #include "Visualization/GraphPlottablesFactory.h" |
|
2 | #include "Visualization/GraphPlottablesFactory.h" | |
3 | #include "ui_VisualizationGraphWidget.h" |
|
3 | #include "ui_VisualizationGraphWidget.h" | |
4 |
|
4 | |||
5 | #include <Variable/Variable.h> |
|
5 | #include <Variable/Variable.h> | |
6 |
|
6 | |||
7 | #include <unordered_map> |
|
7 | #include <unordered_map> | |
8 |
|
8 | |||
9 | namespace { |
|
9 | namespace { | |
10 |
|
10 | |||
11 | /// Key pressed to enable zoom on horizontal axis |
|
11 | /// Key pressed to enable zoom on horizontal axis | |
12 | const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier; |
|
12 | const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier; | |
13 |
|
13 | |||
14 | /// Key pressed to enable zoom on vertical axis |
|
14 | /// Key pressed to enable zoom on vertical axis | |
15 | const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier; |
|
15 | const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier; | |
16 |
|
16 | |||
17 | } // namespace |
|
17 | } // namespace | |
18 |
|
18 | |||
19 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { |
|
19 | struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { | |
20 |
|
20 | |||
21 | // 1 variable -> n qcpplot |
|
21 | // 1 variable -> n qcpplot | |
22 | std::unordered_map<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMap; |
|
22 | std::unordered_map<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMap; | |
23 | }; |
|
23 | }; | |
24 |
|
24 | |||
25 | VisualizationGraphWidget::VisualizationGraphWidget(QWidget *parent) |
|
25 | VisualizationGraphWidget::VisualizationGraphWidget(QWidget *parent) | |
26 | : QWidget{parent}, |
|
26 | : QWidget{parent}, | |
27 | ui{new Ui::VisualizationGraphWidget}, |
|
27 | ui{new Ui::VisualizationGraphWidget}, | |
28 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()} |
|
28 | impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()} | |
29 | { |
|
29 | { | |
30 | ui->setupUi(this); |
|
30 | ui->setupUi(this); | |
31 |
|
31 | |||
32 | // Set qcpplot properties : |
|
32 | // Set qcpplot properties : | |
33 | // - Drag (on x-axis) and zoom are enabled |
|
33 | // - Drag (on x-axis) and zoom are enabled | |
34 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation |
|
34 | // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation | |
35 | ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); |
|
35 | ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); | |
36 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal); |
|
36 | ui->widget->axisRect()->setRangeDrag(Qt::Horizontal); | |
37 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); |
|
37 | connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel); | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | VisualizationGraphWidget::~VisualizationGraphWidget() |
|
40 | VisualizationGraphWidget::~VisualizationGraphWidget() | |
41 | { |
|
41 | { | |
42 | delete ui; |
|
42 | delete ui; | |
43 | } |
|
43 | } | |
44 |
|
44 | |||
45 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable) |
|
45 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable) | |
46 | { |
|
46 | { | |
47 | // Uses delegate to create the qcpplot components according to the variable |
|
47 | // Uses delegate to create the qcpplot components according to the variable | |
48 |
auto createdPlottables = GraphPlottablesFactory::create(variable |
|
48 | auto createdPlottables = GraphPlottablesFactory::create(variable, *ui->widget); | |
49 |
|
49 | |||
50 | for (auto createdPlottable : qAsConst(createdPlottables)) { |
|
50 | for (auto createdPlottable : qAsConst(createdPlottables)) { | |
51 | impl->m_VariableToPlotMap.insert({variable, createdPlottable}); |
|
51 | impl->m_VariableToPlotMap.insert({variable, createdPlottable}); | |
52 | } |
|
52 | } | |
53 | } |
|
53 | } | |
54 |
|
54 | |||
55 | void VisualizationGraphWidget::accept(IVisualizationWidget *visitor) |
|
55 | void VisualizationGraphWidget::accept(IVisualizationWidget *visitor) | |
56 | { |
|
56 | { | |
57 | // TODO: manage the visitor |
|
57 | // TODO: manage the visitor | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | void VisualizationGraphWidget::close() |
|
60 | void VisualizationGraphWidget::close() | |
61 | { |
|
61 | { | |
62 | // The main view cannot be directly closed. |
|
62 | // The main view cannot be directly closed. | |
63 | return; |
|
63 | return; | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | QString VisualizationGraphWidget::name() const |
|
66 | QString VisualizationGraphWidget::name() const | |
67 | { |
|
67 | { | |
68 | return QStringLiteral("MainView"); |
|
68 | return QStringLiteral("MainView"); | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept |
|
71 | void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept | |
72 | { |
|
72 | { | |
73 | auto zoomOrientations = QFlags<Qt::Orientation>{}; |
|
73 | auto zoomOrientations = QFlags<Qt::Orientation>{}; | |
74 |
|
74 | |||
75 | // Lambda that enables a zoom orientation if the key modifier related to this orientation has |
|
75 | // Lambda that enables a zoom orientation if the key modifier related to this orientation has | |
76 | // been pressed |
|
76 | // been pressed | |
77 | auto enableOrientation |
|
77 | auto enableOrientation | |
78 | = [&zoomOrientations, event](const auto &orientation, const auto &modifier) { |
|
78 | = [&zoomOrientations, event](const auto &orientation, const auto &modifier) { | |
79 | auto orientationEnabled = event->modifiers().testFlag(modifier); |
|
79 | auto orientationEnabled = event->modifiers().testFlag(modifier); | |
80 | zoomOrientations.setFlag(orientation, orientationEnabled); |
|
80 | zoomOrientations.setFlag(orientation, orientationEnabled); | |
81 | }; |
|
81 | }; | |
82 | enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER); |
|
82 | enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER); | |
83 | enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER); |
|
83 | enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER); | |
84 |
|
84 | |||
85 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); |
|
85 | ui->widget->axisRect()->setRangeZoom(zoomOrientations); | |
86 | } |
|
86 | } |
General Comments 0
You need to be logged in to leave comments.
Login now