##// END OF EJS Templates
Handles creations for scalar series
Alexandre Leroux -
r169:cc2257464c26
parent child
Show More
@@ -1,32 +1,35
1 #ifndef SCIQLOP_VARIABLE_H
1 #ifndef SCIQLOP_VARIABLE_H
2 #define SCIQLOP_VARIABLE_H
2 #define SCIQLOP_VARIABLE_H
3
3
4 #include <Common/spimpl.h>
4 #include <Common/spimpl.h>
5
5
6 #include <QObject>
6 #include <QObject>
7
7
8 class IDataSeries;
8 class IDataSeries;
9 class QString;
9 class QString;
10
10
11 /**
11 /**
12 * @brief The Variable class represents a variable in SciQlop.
12 * @brief The Variable class represents a variable in SciQlop.
13 */
13 */
14 class Variable {
14 class Variable {
15 public:
15 public:
16 explicit Variable(const QString &name, const QString &unit, const QString &mission);
16 explicit Variable(const QString &name, const QString &unit, const QString &mission);
17
17
18 QString name() const noexcept;
18 QString name() const noexcept;
19 QString mission() const noexcept;
19 QString mission() const noexcept;
20 QString unit() const noexcept;
20 QString unit() const noexcept;
21
21
22 void addDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept;
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 private:
27 private:
25 class VariablePrivate;
28 class VariablePrivate;
26 spimpl::unique_impl_ptr<VariablePrivate> impl;
29 spimpl::unique_impl_ptr<VariablePrivate> impl;
27 };
30 };
28
31
29 // Required for using shared_ptr in signals/slots
32 // Required for using shared_ptr in signals/slots
30 Q_DECLARE_METATYPE(std::shared_ptr<Variable>)
33 Q_DECLARE_METATYPE(std::shared_ptr<Variable>)
31
34
32 #endif // SCIQLOP_VARIABLE_H
35 #endif // SCIQLOP_VARIABLE_H
@@ -1,43 +1,48
1 #include "Variable/Variable.h"
1 #include "Variable/Variable.h"
2
2
3 #include <Data/IDataSeries.h>
3 #include <Data/IDataSeries.h>
4
4
5 struct Variable::VariablePrivate {
5 struct Variable::VariablePrivate {
6 explicit VariablePrivate(const QString &name, const QString &unit, const QString &mission)
6 explicit VariablePrivate(const QString &name, const QString &unit, const QString &mission)
7 : m_Name{name}, m_Unit{unit}, m_Mission{mission}, m_DataSeries{nullptr}
7 : m_Name{name}, m_Unit{unit}, m_Mission{mission}, m_DataSeries{nullptr}
8 {
8 {
9 }
9 }
10
10
11 QString m_Name;
11 QString m_Name;
12 QString m_Unit;
12 QString m_Unit;
13 QString m_Mission;
13 QString m_Mission;
14 std::unique_ptr<IDataSeries> m_DataSeries;
14 std::unique_ptr<IDataSeries> m_DataSeries;
15 };
15 };
16
16
17 Variable::Variable(const QString &name, const QString &unit, const QString &mission)
17 Variable::Variable(const QString &name, const QString &unit, const QString &mission)
18 : impl{spimpl::make_unique_impl<VariablePrivate>(name, unit, mission)}
18 : impl{spimpl::make_unique_impl<VariablePrivate>(name, unit, mission)}
19 {
19 {
20 }
20 }
21
21
22 QString Variable::name() const noexcept
22 QString Variable::name() const noexcept
23 {
23 {
24 return impl->m_Name;
24 return impl->m_Name;
25 }
25 }
26
26
27 QString Variable::mission() const noexcept
27 QString Variable::mission() const noexcept
28 {
28 {
29 return impl->m_Mission;
29 return impl->m_Mission;
30 }
30 }
31
31
32 QString Variable::unit() const noexcept
32 QString Variable::unit() const noexcept
33 {
33 {
34 return impl->m_Unit;
34 return impl->m_Unit;
35 }
35 }
36
36
37 void Variable::addDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept
37 void Variable::addDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept
38 {
38 {
39 if (!impl->m_DataSeries) {
39 if (!impl->m_DataSeries) {
40 impl->m_DataSeries = std::move(dataSeries);
40 impl->m_DataSeries = std::move(dataSeries);
41 }
41 }
42 /// @todo : else, merge the two data series (if possible)
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 #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>
5
4 #include <Variable/Variable.h>
6 #include <Variable/Variable.h>
5
7
6 Q_LOGGING_CATEGORY(LOG_GraphPlottablesFactory, "GraphPlottablesFactory")
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 QVector<QCPAbstractPlottable *> GraphPlottablesFactory::create(const Variable *variable,
37 QVector<QCPAbstractPlottable *> GraphPlottablesFactory::create(const Variable *variable,
9 QCustomPlot &plot) noexcept
38 QCustomPlot &plot) noexcept
10 {
39 {
11 auto result = QVector<QCPAbstractPlottable *>{};
40 auto result = QVector<QCPAbstractPlottable *>{};
12
41
13 if (variable) {
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 else {
53 else {
17 qCDebug(LOG_GraphPlottablesFactory())
54 qCDebug(LOG_GraphPlottablesFactory())
18 << QObject::tr("Can't create graph plottables : the variable is null");
55 << QObject::tr("Can't create graph plottables : the variable is null");
19 }
56 }
20
57
21 return result;
58 return result;
22 }
59 }
General Comments 0
You need to be logged in to leave comments. Login now