##// END OF EJS Templates
Handles creations for scalar series
Alexandre Leroux -
r169:cc2257464c26
parent child
Show More
@@ -1,32 +1,35
1 1 #ifndef SCIQLOP_VARIABLE_H
2 2 #define SCIQLOP_VARIABLE_H
3 3
4 4 #include <Common/spimpl.h>
5 5
6 6 #include <QObject>
7 7
8 8 class IDataSeries;
9 9 class QString;
10 10
11 11 /**
12 12 * @brief The Variable class represents a variable in SciQlop.
13 13 */
14 14 class Variable {
15 15 public:
16 16 explicit Variable(const QString &name, const QString &unit, const QString &mission);
17 17
18 18 QString name() const noexcept;
19 19 QString mission() const noexcept;
20 20 QString unit() const noexcept;
21 21
22 22 void addDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept;
23 23
24 /// @return the data of the variable, nullptr if there is no data
25 IDataSeries *dataSeries() const noexcept;
26
24 27 private:
25 28 class VariablePrivate;
26 29 spimpl::unique_impl_ptr<VariablePrivate> impl;
27 30 };
28 31
29 32 // Required for using shared_ptr in signals/slots
30 33 Q_DECLARE_METATYPE(std::shared_ptr<Variable>)
31 34
32 35 #endif // SCIQLOP_VARIABLE_H
@@ -1,43 +1,48
1 1 #include "Variable/Variable.h"
2 2
3 3 #include <Data/IDataSeries.h>
4 4
5 5 struct Variable::VariablePrivate {
6 6 explicit VariablePrivate(const QString &name, const QString &unit, const QString &mission)
7 7 : m_Name{name}, m_Unit{unit}, m_Mission{mission}, m_DataSeries{nullptr}
8 8 {
9 9 }
10 10
11 11 QString m_Name;
12 12 QString m_Unit;
13 13 QString m_Mission;
14 14 std::unique_ptr<IDataSeries> m_DataSeries;
15 15 };
16 16
17 17 Variable::Variable(const QString &name, const QString &unit, const QString &mission)
18 18 : impl{spimpl::make_unique_impl<VariablePrivate>(name, unit, mission)}
19 19 {
20 20 }
21 21
22 22 QString Variable::name() const noexcept
23 23 {
24 24 return impl->m_Name;
25 25 }
26 26
27 27 QString Variable::mission() const noexcept
28 28 {
29 29 return impl->m_Mission;
30 30 }
31 31
32 32 QString Variable::unit() const noexcept
33 33 {
34 34 return impl->m_Unit;
35 35 }
36 36
37 37 void Variable::addDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept
38 38 {
39 39 if (!impl->m_DataSeries) {
40 40 impl->m_DataSeries = std::move(dataSeries);
41 41 }
42 42 /// @todo : else, merge the two data series (if possible)
43 43 }
44
45 IDataSeries *Variable::dataSeries() const noexcept
46 {
47 return impl->m_DataSeries.get();
48 }
@@ -1,22 +1,59
1 1 #include "Visualization/GraphPlottablesFactory.h"
2 2 #include "Visualization/qcustomplot.h"
3 3
4 #include <Data/ScalarSeries.h>
5
4 6 #include <Variable/Variable.h>
5 7
6 8 Q_LOGGING_CATEGORY(LOG_GraphPlottablesFactory, "GraphPlottablesFactory")
7 9
10 namespace {
11
12
13 QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QCustomPlot &plot)
14 {
15 auto component = plot.addGraph();
16
17 if (component) {
18 // Graph data
19 component->setData(scalarSeries.xAxisData()->data(), scalarSeries.valuesData()->data(),
20 true);
21
22 // Display all data
23 component->rescaleAxes();
24
25 plot.replot();
26 }
27 else {
28 qCDebug(LOG_GraphPlottablesFactory())
29 << QObject::tr("Can't create graph for the scalar series");
30 }
31
32 return component;
33 }
34
35 } // namespace
36
8 37 QVector<QCPAbstractPlottable *> GraphPlottablesFactory::create(const Variable *variable,
9 38 QCustomPlot &plot) noexcept
10 39 {
11 40 auto result = QVector<QCPAbstractPlottable *>{};
12 41
13 42 if (variable) {
14 /// @todo ALX
43 // Gets the data series of the variable to call the creation of the right components
44 // according to its type
45 if (auto scalarSeries = dynamic_cast<ScalarSeries *>(variable->dataSeries())) {
46 result.append(createScalarSeriesComponent(*scalarSeries, plot));
47 }
48 else {
49 qCDebug(LOG_GraphPlottablesFactory())
50 << QObject::tr("Can't create graph plottables : unmanaged data series type");
51 }
15 52 }
16 53 else {
17 54 qCDebug(LOG_GraphPlottablesFactory())
18 55 << QObject::tr("Can't create graph plottables : the variable is null");
19 56 }
20 57
21 58 return result;
22 59 }
General Comments 0
You need to be logged in to leave comments. Login now