##// END OF EJS Templates
Use std::shared_ptr in CosinusProvider
Alexandre Leroux -
r310:9a5cb57f1573
parent child
Show More
@@ -1,70 +1,93
1 #ifndef SCIQLOP_DATASERIES_H
1 #ifndef SCIQLOP_DATASERIES_H
2 #define SCIQLOP_DATASERIES_H
2 #define SCIQLOP_DATASERIES_H
3
3
4 #include <Data/ArrayData.h>
4 #include <Data/ArrayData.h>
5 #include <Data/IDataSeries.h>
5 #include <Data/IDataSeries.h>
6
6
7 #include <QLoggingCategory>
7 #include <QLoggingCategory>
8
8
9 #include <memory>
9 #include <memory>
10
10
11
11
12 Q_DECLARE_LOGGING_CATEGORY(LOG_DataSeries)
12 Q_DECLARE_LOGGING_CATEGORY(LOG_DataSeries)
13 Q_LOGGING_CATEGORY(LOG_DataSeries, "DataSeries")
13 Q_LOGGING_CATEGORY(LOG_DataSeries, "DataSeries")
14
14
15
15
16 /**
16 /**
17 * @brief The DataSeries class is the base (abstract) implementation of IDataSeries.
17 * @brief The DataSeries class is the base (abstract) implementation of IDataSeries.
18 *
18 *
19 * It proposes to set a dimension for the values ​​data
19 * It proposes to set a dimension for the values ​​data
20 *
20 *
21 * @tparam Dim The dimension of the values data
21 * @tparam Dim The dimension of the values data
22 *
22 *
23 */
23 */
24 template <int Dim>
24 template <int Dim>
25 class DataSeries : public IDataSeries {
25 class DataSeries : public IDataSeries {
26 public:
26 public:
27 /// @sa IDataSeries::xAxisData()
27 /// @sa IDataSeries::xAxisData()
28 std::shared_ptr<ArrayData<1> > xAxisData() override { return m_XAxisData; }
28 std::shared_ptr<ArrayData<1> > xAxisData() override { return m_XAxisData; }
29 const std::shared_ptr<ArrayData<1> > xAxisData() const { return m_XAxisData; }
29
30
30 /// @sa IDataSeries::xAxisUnit()
31 /// @sa IDataSeries::xAxisUnit()
31 Unit xAxisUnit() const override { return m_XAxisUnit; }
32 Unit xAxisUnit() const override { return m_XAxisUnit; }
32
33
33 /// @return the values dataset
34 /// @return the values dataset
34 std::shared_ptr<ArrayData<Dim> > valuesData() const { return m_ValuesData; }
35 std::shared_ptr<ArrayData<Dim> > valuesData() { return m_ValuesData; }
36 const std::shared_ptr<ArrayData<Dim> > valuesData() const { return m_ValuesData; }
35
37
36 /// @sa IDataSeries::valuesUnit()
38 /// @sa IDataSeries::valuesUnit()
37 Unit valuesUnit() const override { return m_ValuesUnit; }
39 Unit valuesUnit() const override { return m_ValuesUnit; }
38
40
39 /// @sa IDataSeries::merge()
41 /// @sa IDataSeries::merge()
40 void merge(IDataSeries *dataSeries) override
42 void merge(IDataSeries *dataSeries) override
41 {
43 {
42 if (auto dimDataSeries = dynamic_cast<DataSeries<Dim> *>(dataSeries)) {
44 if (auto dimDataSeries = dynamic_cast<DataSeries<Dim> *>(dataSeries)) {
43 m_XAxisData->merge(*dimDataSeries->xAxisData());
45 m_XAxisData->merge(*dimDataSeries->xAxisData());
44 m_ValuesData->merge(*dimDataSeries->valuesData());
46 m_ValuesData->merge(*dimDataSeries->valuesData());
45 }
47 }
46 else {
48 else {
47 qCWarning(LOG_DataSeries())
49 qCWarning(LOG_DataSeries())
48 << QObject::tr("Dection of a type of IDataSeries we cannot merge with !");
50 << QObject::tr("Dection of a type of IDataSeries we cannot merge with !");
49 }
51 }
50 }
52 }
51
53
52 protected:
54 protected:
53 /// Protected ctor (DataSeries is abstract)
55 /// Protected ctor (DataSeries is abstract)
54 explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, const Unit &xAxisUnit,
56 explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, const Unit &xAxisUnit,
55 std::shared_ptr<ArrayData<Dim> > valuesData, const Unit &valuesUnit)
57 std::shared_ptr<ArrayData<Dim> > valuesData, const Unit &valuesUnit)
56 : m_XAxisData{xAxisData},
58 : m_XAxisData{xAxisData},
57 m_XAxisUnit{xAxisUnit},
59 m_XAxisUnit{xAxisUnit},
58 m_ValuesData{valuesData},
60 m_ValuesData{valuesData},
59 m_ValuesUnit{valuesUnit}
61 m_ValuesUnit{valuesUnit}
60 {
62 {
61 }
63 }
62
64
65 /// Copy ctor
66 explicit DataSeries(const DataSeries<Dim> &other)
67 : m_XAxisData{std::make_shared<ArrayData<1> >(*other.m_XAxisData)},
68 m_XAxisUnit{other.m_XAxisUnit},
69 m_ValuesData{std::make_shared<ArrayData<Dim> >(*other.m_ValuesData)},
70 m_ValuesUnit{other.m_ValuesUnit}
71 {
72 }
73
74 /// Assignment operator
75 template <int D>
76 DataSeries &operator=(DataSeries<D> other)
77 {
78 std::swap(m_XAxisData, other.m_XAxisData);
79 std::swap(m_XAxisUnit, other.m_XAxisUnit);
80 std::swap(m_ValuesData, other.m_ValuesData);
81 std::swap(m_ValuesUnit, other.m_ValuesUnit);
82
83 return *this;
84 }
85
63 private:
86 private:
64 std::shared_ptr<ArrayData<1> > m_XAxisData;
87 std::shared_ptr<ArrayData<1> > m_XAxisData;
65 Unit m_XAxisUnit;
88 Unit m_XAxisUnit;
66 std::shared_ptr<ArrayData<Dim> > m_ValuesData;
89 std::shared_ptr<ArrayData<Dim> > m_ValuesData;
67 Unit m_ValuesUnit;
90 Unit m_ValuesUnit;
68 };
91 };
69
92
70 #endif // SCIQLOP_DATASERIES_H
93 #endif // SCIQLOP_DATASERIES_H
@@ -1,42 +1,42
1 #ifndef SCIQLOP_IDATAPROVIDER_H
1 #ifndef SCIQLOP_IDATAPROVIDER_H
2 #define SCIQLOP_IDATAPROVIDER_H
2 #define SCIQLOP_IDATAPROVIDER_H
3
3
4 #include <memory>
4 #include <memory>
5
5
6 #include <QObject>
6 #include <QObject>
7
7
8 #include <Common/MetaTypes.h>
8 #include <Common/MetaTypes.h>
9
9
10 #include <Data/SqpDateTime.h>
10 #include <Data/SqpDateTime.h>
11
11
12 class DataProviderParameters;
12 class DataProviderParameters;
13 class IDataSeries;
13 class IDataSeries;
14
14
15 /**
15 /**
16 * @brief The IDataProvider interface aims to declare a data provider.
16 * @brief The IDataProvider interface aims to declare a data provider.
17 *
17 *
18 * A data provider is an entity that generates data and returns it according to various parameters
18 * A data provider is an entity that generates data and returns it according to various parameters
19 * (time interval, product to retrieve the data, etc.)
19 * (time interval, product to retrieve the data, etc.)
20 *
20 *
21 * @sa IDataSeries
21 * @sa IDataSeries
22 */
22 */
23 class IDataProvider : public QObject {
23 class IDataProvider : public QObject {
24
24
25 Q_OBJECT
25 Q_OBJECT
26 public:
26 public:
27 virtual ~IDataProvider() noexcept = default;
27 virtual ~IDataProvider() noexcept = default;
28
28
29 virtual std::unique_ptr<IDataSeries>
29 virtual std::shared_ptr<IDataSeries>
30 retrieveData(const DataProviderParameters &parameters) const = 0;
30 retrieveData(const DataProviderParameters &parameters) const = 0;
31
31
32
32
33 virtual void requestDataLoading(const QVector<SqpDateTime> &dateTimeList) = 0;
33 virtual void requestDataLoading(const QVector<SqpDateTime> &dateTimeList) = 0;
34
34
35 signals:
35 signals:
36 void dataProvided(std::shared_ptr<IDataSeries> dateSerie, const SqpDateTime &dateTime);
36 void dataProvided(std::shared_ptr<IDataSeries> dateSerie, const SqpDateTime &dateTime);
37 };
37 };
38
38
39 // Required for using shared_ptr in signals/slots
39 // Required for using shared_ptr in signals/slots
40 SCIQLOP_REGISTER_META_TYPE(IDATAPROVIDER_PTR_REGISTRY, std::shared_ptr<IDataProvider>)
40 SCIQLOP_REGISTER_META_TYPE(IDATAPROVIDER_PTR_REGISTRY, std::shared_ptr<IDataProvider>)
41
41
42 #endif // SCIQLOP_IDATAPROVIDER_H
42 #endif // SCIQLOP_IDATAPROVIDER_H
@@ -1,54 +1,59
1 #ifndef SCIQLOP_IDATASERIES_H
1 #ifndef SCIQLOP_IDATASERIES_H
2 #define SCIQLOP_IDATASERIES_H
2 #define SCIQLOP_IDATASERIES_H
3
3
4 #include <Common/MetaTypes.h>
4 #include <Common/MetaTypes.h>
5
5
6 #include <memory>
6 #include <memory>
7
7
8 #include <QString>
8 #include <QString>
9
9
10 template <int Dim>
10 template <int Dim>
11 class ArrayData;
11 class ArrayData;
12
12
13 struct Unit {
13 struct Unit {
14 explicit Unit(const QString &name = {}, bool timeUnit = false)
14 explicit Unit(const QString &name = {}, bool timeUnit = false)
15 : m_Name{name}, m_TimeUnit{timeUnit}
15 : m_Name{name}, m_TimeUnit{timeUnit}
16 {
16 {
17 }
17 }
18
18
19 QString m_Name; ///< Unit name
19 QString m_Name; ///< Unit name
20 bool m_TimeUnit; ///< The unit is a unit of time
20 bool m_TimeUnit; ///< The unit is a unit of time
21 };
21 };
22
22
23 /**
23 /**
24 * @brief The IDataSeries aims to declare a data series.
24 * @brief The IDataSeries aims to declare a data series.
25 *
25 *
26 * A data series is an entity that contains at least :
26 * A data series is an entity that contains at least :
27 * - one dataset representing the x-axis
27 * - one dataset representing the x-axis
28 * - one dataset representing the values
28 * - one dataset representing the values
29 *
29 *
30 * Each dataset is represented by an ArrayData, and is associated with a unit.
30 * Each dataset is represented by an ArrayData, and is associated with a unit.
31 *
31 *
32 * An ArrayData can be unidimensional or two-dimensional, depending on the implementation of the
32 * An ArrayData can be unidimensional or two-dimensional, depending on the implementation of the
33 * IDataSeries. The x-axis dataset is always unidimensional.
33 * IDataSeries. The x-axis dataset is always unidimensional.
34 *
34 *
35 * @sa ArrayData
35 * @sa ArrayData
36 */
36 */
37 class IDataSeries {
37 class IDataSeries {
38 public:
38 public:
39 virtual ~IDataSeries() noexcept = default;
39 virtual ~IDataSeries() noexcept = default;
40
40
41 /// Returns the x-axis dataset
41 /// Returns the x-axis dataset
42 virtual std::shared_ptr<ArrayData<1> > xAxisData() = 0;
42 virtual std::shared_ptr<ArrayData<1> > xAxisData() = 0;
43
43
44 /// Returns the x-axis dataset (as const)
45 virtual const std::shared_ptr<ArrayData<1> > xAxisData() const = 0;
46
44 virtual Unit xAxisUnit() const = 0;
47 virtual Unit xAxisUnit() const = 0;
45
48
46 virtual Unit valuesUnit() const = 0;
49 virtual Unit valuesUnit() const = 0;
47
50
48 virtual void merge(IDataSeries *dataSeries) = 0;
51 virtual void merge(IDataSeries *dataSeries) = 0;
52
53 virtual std::unique_ptr<IDataSeries> clone() const = 0;
49 };
54 };
50
55
51 // Required for using shared_ptr in signals/slots
56 // Required for using shared_ptr in signals/slots
52 SCIQLOP_REGISTER_META_TYPE(IDATASERIES_PTR_REGISTRY, std::shared_ptr<IDataSeries>)
57 SCIQLOP_REGISTER_META_TYPE(IDATASERIES_PTR_REGISTRY, std::shared_ptr<IDataSeries>)
53
58
54 #endif // SCIQLOP_IDATASERIES_H
59 #endif // SCIQLOP_IDATASERIES_H
@@ -1,28 +1,30
1 #ifndef SCIQLOP_SCALARSERIES_H
1 #ifndef SCIQLOP_SCALARSERIES_H
2 #define SCIQLOP_SCALARSERIES_H
2 #define SCIQLOP_SCALARSERIES_H
3
3
4 #include <Data/DataSeries.h>
4 #include <Data/DataSeries.h>
5
5
6 /**
6 /**
7 * @brief The ScalarSeries class is the implementation for a data series representing a scalar.
7 * @brief The ScalarSeries class is the implementation for a data series representing a scalar.
8 */
8 */
9 class ScalarSeries : public DataSeries<1> {
9 class ScalarSeries : public DataSeries<1> {
10 public:
10 public:
11 /**
11 /**
12 * Ctor
12 * Ctor
13 * @param size the number of data the series will hold
13 * @param size the number of data the series will hold
14 * @param xAxisUnit x-axis unit
14 * @param xAxisUnit x-axis unit
15 * @param valuesUnit values unit
15 * @param valuesUnit values unit
16 */
16 */
17 explicit ScalarSeries(int size, const Unit &xAxisUnit, const Unit &valuesUnit);
17 explicit ScalarSeries(int size, const Unit &xAxisUnit, const Unit &valuesUnit);
18
18
19 /**
19 /**
20 * Sets data for a specific index. The index has to be valid to be effective
20 * Sets data for a specific index. The index has to be valid to be effective
21 * @param index the index to which the data will be set
21 * @param index the index to which the data will be set
22 * @param x the x-axis data
22 * @param x the x-axis data
23 * @param value the value data
23 * @param value the value data
24 */
24 */
25 void setData(int index, double x, double value) noexcept;
25 void setData(int index, double x, double value) noexcept;
26
27 std::unique_ptr<IDataSeries> clone() const;
26 };
28 };
27
29
28 #endif // SCIQLOP_SCALARSERIES_H
30 #endif // SCIQLOP_SCALARSERIES_H
@@ -1,55 +1,54
1 #ifndef SCIQLOP_VARIABLE_H
1 #ifndef SCIQLOP_VARIABLE_H
2 #define SCIQLOP_VARIABLE_H
2 #define SCIQLOP_VARIABLE_H
3
3
4 #include <Data/SqpDateTime.h>
4 #include <Data/SqpDateTime.h>
5
5
6 #include <QLoggingCategory>
6 #include <QLoggingCategory>
7 #include <QObject>
7 #include <QObject>
8
8
9 #include <Common/MetaTypes.h>
9 #include <Common/MetaTypes.h>
10 #include <Common/spimpl.h>
10 #include <Common/spimpl.h>
11
11
12 Q_DECLARE_LOGGING_CATEGORY(LOG_Variable)
12 Q_DECLARE_LOGGING_CATEGORY(LOG_Variable)
13
13
14 class IDataSeries;
14 class IDataSeries;
15 class QString;
15 class QString;
16
16
17 /**
17 /**
18 * @brief The Variable class represents a variable in SciQlop.
18 * @brief The Variable class represents a variable in SciQlop.
19 */
19 */
20 class Variable : public QObject {
20 class Variable : public QObject {
21
21
22 Q_OBJECT
22 Q_OBJECT
23
23
24 public:
24 public:
25 explicit Variable(const QString &name, const QString &unit, const QString &mission,
25 explicit Variable(const QString &name, const QString &unit, const QString &mission,
26 const SqpDateTime &dateTime);
26 const SqpDateTime &dateTime);
27
27
28 QString name() const noexcept;
28 QString name() const noexcept;
29 QString mission() const noexcept;
29 QString mission() const noexcept;
30 QString unit() const noexcept;
30 QString unit() const noexcept;
31 SqpDateTime dateTime() const noexcept;
31 SqpDateTime dateTime() const noexcept;
32 void setDateTime(const SqpDateTime &dateTime) noexcept;
32 void setDateTime(const SqpDateTime &dateTime) noexcept;
33
33
34 /// @return the data of the variable, nullptr if there is no data
34 /// @return the data of the variable, nullptr if there is no data
35 IDataSeries *dataSeries() const noexcept;
35 IDataSeries *dataSeries() const noexcept;
36
36
37 bool contains(const SqpDateTime &dateTime);
37 bool contains(const SqpDateTime &dateTime);
38 bool intersect(const SqpDateTime &dateTime);
38 bool intersect(const SqpDateTime &dateTime);
39 void setDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept;
40
39
41 public slots:
40 public slots:
42 void onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
41 void setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
43
42
44 signals:
43 signals:
45 void updated();
44 void updated();
46
45
47 private:
46 private:
48 class VariablePrivate;
47 class VariablePrivate;
49 spimpl::unique_impl_ptr<VariablePrivate> impl;
48 spimpl::unique_impl_ptr<VariablePrivate> impl;
50 };
49 };
51
50
52 // Required for using shared_ptr in signals/slots
51 // Required for using shared_ptr in signals/slots
53 SCIQLOP_REGISTER_META_TYPE(VARIABLE_PTR_REGISTRY, std::shared_ptr<Variable>)
52 SCIQLOP_REGISTER_META_TYPE(VARIABLE_PTR_REGISTRY, std::shared_ptr<Variable>)
54
53
55 #endif // SCIQLOP_VARIABLE_H
54 #endif // SCIQLOP_VARIABLE_H
@@ -1,51 +1,51
1 #ifndef SCIQLOP_VARIABLEMODEL_H
1 #ifndef SCIQLOP_VARIABLEMODEL_H
2 #define SCIQLOP_VARIABLEMODEL_H
2 #define SCIQLOP_VARIABLEMODEL_H
3
3
4
4
5 #include <Data/SqpDateTime.h>
5 #include <Data/SqpDateTime.h>
6
6
7 #include <QAbstractTableModel>
7 #include <QAbstractTableModel>
8 #include <QLoggingCategory>
8 #include <QLoggingCategory>
9
9
10 #include <Common/spimpl.h>
10 #include <Common/spimpl.h>
11
11
12 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel)
12 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel)
13
13
14 class IDataSeries;
14 class IDataSeries;
15 class Variable;
15 class Variable;
16
16
17 /**
17 /**
18 * @brief The VariableModel class aims to hold the variables that have been created in SciQlop
18 * @brief The VariableModel class aims to hold the variables that have been created in SciQlop
19 */
19 */
20 class VariableModel : public QAbstractTableModel {
20 class VariableModel : public QAbstractTableModel {
21 public:
21 public:
22 explicit VariableModel(QObject *parent = nullptr);
22 explicit VariableModel(QObject *parent = nullptr);
23
23
24 /**
24 /**
25 * Creates a new variable in the model
25 * Creates a new variable in the model
26 * @param name the name of the new variable
26 * @param name the name of the new variable
27 * @param dateTime the dateTime of the new variable
27 * @param dateTime the dateTime of the new variable
28 * @param defaultDataSeries the default data of the new variable
28 * @param defaultDataSeries the default data of the new variable
29 * @return the pointer to the new variable
29 * @return the pointer to the new variable
30 */
30 */
31 std::shared_ptr<Variable>
31 std::shared_ptr<Variable>
32 createVariable(const QString &name, const SqpDateTime &dateTime,
32 createVariable(const QString &name, const SqpDateTime &dateTime,
33 std::unique_ptr<IDataSeries> defaultDataSeries) noexcept;
33 std::shared_ptr<IDataSeries> defaultDataSeries) noexcept;
34
34
35 std::shared_ptr<Variable> variable(int index) const;
35 std::shared_ptr<Variable> variable(int index) const;
36
36
37 // /////////////////////////// //
37 // /////////////////////////// //
38 // QAbstractTableModel methods //
38 // QAbstractTableModel methods //
39 // /////////////////////////// //
39 // /////////////////////////// //
40 virtual int columnCount(const QModelIndex &parent = QModelIndex{}) const override;
40 virtual int columnCount(const QModelIndex &parent = QModelIndex{}) const override;
41 virtual int rowCount(const QModelIndex &parent = QModelIndex{}) const override;
41 virtual int rowCount(const QModelIndex &parent = QModelIndex{}) const override;
42 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
42 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
43 virtual QVariant headerData(int section, Qt::Orientation orientation,
43 virtual QVariant headerData(int section, Qt::Orientation orientation,
44 int role = Qt::DisplayRole) const override;
44 int role = Qt::DisplayRole) const override;
45
45
46 private:
46 private:
47 class VariableModelPrivate;
47 class VariableModelPrivate;
48 spimpl::unique_impl_ptr<VariableModelPrivate> impl;
48 spimpl::unique_impl_ptr<VariableModelPrivate> impl;
49 };
49 };
50
50
51 #endif // SCIQLOP_VARIABLEMODEL_H
51 #endif // SCIQLOP_VARIABLEMODEL_H
@@ -1,13 +1,18
1 #include <Data/ScalarSeries.h>
1 #include <Data/ScalarSeries.h>
2
2
3 ScalarSeries::ScalarSeries(int size, const Unit &xAxisUnit, const Unit &valuesUnit)
3 ScalarSeries::ScalarSeries(int size, const Unit &xAxisUnit, const Unit &valuesUnit)
4 : DataSeries{std::make_shared<ArrayData<1> >(size), xAxisUnit,
4 : DataSeries{std::make_shared<ArrayData<1> >(size), xAxisUnit,
5 std::make_shared<ArrayData<1> >(size), valuesUnit}
5 std::make_shared<ArrayData<1> >(size), valuesUnit}
6 {
6 {
7 }
7 }
8
8
9 void ScalarSeries::setData(int index, double x, double value) noexcept
9 void ScalarSeries::setData(int index, double x, double value) noexcept
10 {
10 {
11 xAxisData()->setData(index, x);
11 xAxisData()->setData(index, x);
12 valuesData()->setData(index, value);
12 valuesData()->setData(index, value);
13 }
13 }
14
15 std::unique_ptr<IDataSeries> ScalarSeries::clone() const
16 {
17 return std::make_unique<ScalarSeries>(*this);
18 }
@@ -1,87 +1,89
1 #include "Variable/Variable.h"
1 #include "Variable/Variable.h"
2
2
3 #include <Data/IDataSeries.h>
3 #include <Data/IDataSeries.h>
4 #include <Data/SqpDateTime.h>
4 #include <Data/SqpDateTime.h>
5
5
6 Q_LOGGING_CATEGORY(LOG_Variable, "Variable")
6 Q_LOGGING_CATEGORY(LOG_Variable, "Variable")
7
7
8 struct Variable::VariablePrivate {
8 struct Variable::VariablePrivate {
9 explicit VariablePrivate(const QString &name, const QString &unit, const QString &mission,
9 explicit VariablePrivate(const QString &name, const QString &unit, const QString &mission,
10 const SqpDateTime &dateTime)
10 const SqpDateTime &dateTime)
11 : m_Name{name},
11 : m_Name{name},
12 m_Unit{unit},
12 m_Unit{unit},
13 m_Mission{mission},
13 m_Mission{mission},
14 m_DateTime{dateTime},
14 m_DateTime{dateTime},
15 m_DataSeries{nullptr}
15 m_DataSeries{nullptr}
16 {
16 {
17 }
17 }
18
18
19 QString m_Name;
19 QString m_Name;
20 QString m_Unit;
20 QString m_Unit;
21 QString m_Mission;
21 QString m_Mission;
22
22
23 SqpDateTime m_DateTime; // The dateTime available in the view and loaded. not the cache.
23 SqpDateTime m_DateTime; // The dateTime available in the view and loaded. not the cache.
24 std::unique_ptr<IDataSeries> m_DataSeries;
24 std::unique_ptr<IDataSeries> m_DataSeries;
25 };
25 };
26
26
27 Variable::Variable(const QString &name, const QString &unit, const QString &mission,
27 Variable::Variable(const QString &name, const QString &unit, const QString &mission,
28 const SqpDateTime &dateTime)
28 const SqpDateTime &dateTime)
29 : impl{spimpl::make_unique_impl<VariablePrivate>(name, unit, mission, dateTime)}
29 : impl{spimpl::make_unique_impl<VariablePrivate>(name, unit, mission, dateTime)}
30 {
30 {
31 }
31 }
32
32
33 QString Variable::name() const noexcept
33 QString Variable::name() const noexcept
34 {
34 {
35 return impl->m_Name;
35 return impl->m_Name;
36 }
36 }
37
37
38 QString Variable::mission() const noexcept
38 QString Variable::mission() const noexcept
39 {
39 {
40 return impl->m_Mission;
40 return impl->m_Mission;
41 }
41 }
42
42
43 QString Variable::unit() const noexcept
43 QString Variable::unit() const noexcept
44 {
44 {
45 return impl->m_Unit;
45 return impl->m_Unit;
46 }
46 }
47
47
48 SqpDateTime Variable::dateTime() const noexcept
48 SqpDateTime Variable::dateTime() const noexcept
49 {
49 {
50 return impl->m_DateTime;
50 return impl->m_DateTime;
51 }
51 }
52
52
53 void Variable::setDateTime(const SqpDateTime &dateTime) noexcept
53 void Variable::setDateTime(const SqpDateTime &dateTime) noexcept
54 {
54 {
55 impl->m_DateTime = dateTime;
55 impl->m_DateTime = dateTime;
56 }
56 }
57
57
58 void Variable::setDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept
58 void Variable::setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
59 {
59 {
60 if (!impl->m_DataSeries) {
60 if (!dataSeries) {
61 impl->m_DataSeries = std::move(dataSeries);
61 /// @todo ALX : log
62 return;
62 }
63 }
63 }
64
64
65 void Variable::onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
65 // Inits the data series of the variable
66 {
66 if (!impl->m_DataSeries) {
67 if (impl->m_DataSeries) {
67 impl->m_DataSeries = dataSeries->clone();
68 }
69 else {
68 impl->m_DataSeries->merge(dataSeries.get());
70 impl->m_DataSeries->merge(dataSeries.get());
69
71
70 emit updated();
72 emit updated();
71 }
73 }
72 }
74 }
73
75
74 IDataSeries *Variable::dataSeries() const noexcept
76 IDataSeries *Variable::dataSeries() const noexcept
75 {
77 {
76 return impl->m_DataSeries.get();
78 return impl->m_DataSeries.get();
77 }
79 }
78
80
79 bool Variable::contains(const SqpDateTime &dateTime)
81 bool Variable::contains(const SqpDateTime &dateTime)
80 {
82 {
81 return impl->m_DateTime.contains(dateTime);
83 return impl->m_DateTime.contains(dateTime);
82 }
84 }
83
85
84 bool Variable::intersect(const SqpDateTime &dateTime)
86 bool Variable::intersect(const SqpDateTime &dateTime)
85 {
87 {
86 return impl->m_DateTime.intersect(dateTime);
88 return impl->m_DateTime.intersect(dateTime);
87 }
89 }
@@ -1,175 +1,175
1 #include <Variable/Variable.h>
1 #include <Variable/Variable.h>
2 #include <Variable/VariableCacheController.h>
2 #include <Variable/VariableCacheController.h>
3 #include <Variable/VariableController.h>
3 #include <Variable/VariableController.h>
4 #include <Variable/VariableModel.h>
4 #include <Variable/VariableModel.h>
5
5
6 #include <Data/DataProviderParameters.h>
6 #include <Data/DataProviderParameters.h>
7 #include <Data/IDataProvider.h>
7 #include <Data/IDataProvider.h>
8 #include <Data/IDataSeries.h>
8 #include <Data/IDataSeries.h>
9 #include <Time/TimeController.h>
9 #include <Time/TimeController.h>
10
10
11 #include <QDateTime>
11 #include <QDateTime>
12 #include <QMutex>
12 #include <QMutex>
13 #include <QThread>
13 #include <QThread>
14 #include <QtCore/QItemSelectionModel>
14 #include <QtCore/QItemSelectionModel>
15
15
16 #include <unordered_map>
16 #include <unordered_map>
17
17
18 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
18 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
19
19
20 namespace {
20 namespace {
21
21
22 /// @todo Generates default dataseries, according to the provider passed in parameter. This method
22 /// @todo Generates default dataseries, according to the provider passed in parameter. This method
23 /// will be deleted when the timerange is recovered from SciQlop
23 /// will be deleted when the timerange is recovered from SciQlop
24 std::unique_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider,
24 std::shared_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider,
25 const SqpDateTime &dateTime) noexcept
25 const SqpDateTime &dateTime) noexcept
26 {
26 {
27 auto parameters = DataProviderParameters{dateTime};
27 auto parameters = DataProviderParameters{dateTime};
28
28
29 return provider.retrieveData(parameters);
29 return provider.retrieveData(parameters);
30 }
30 }
31
31
32 } // namespace
32 } // namespace
33
33
34 struct VariableController::VariableControllerPrivate {
34 struct VariableController::VariableControllerPrivate {
35 explicit VariableControllerPrivate(VariableController *parent)
35 explicit VariableControllerPrivate(VariableController *parent)
36 : m_WorkingMutex{},
36 : m_WorkingMutex{},
37 m_VariableModel{new VariableModel{parent}},
37 m_VariableModel{new VariableModel{parent}},
38 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
38 m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}},
39 m_VariableCacheController{std::make_unique<VariableCacheController>()}
39 m_VariableCacheController{std::make_unique<VariableCacheController>()}
40 {
40 {
41 }
41 }
42
42
43 QMutex m_WorkingMutex;
43 QMutex m_WorkingMutex;
44 /// Variable model. The VariableController has the ownership
44 /// Variable model. The VariableController has the ownership
45 VariableModel *m_VariableModel;
45 VariableModel *m_VariableModel;
46 QItemSelectionModel *m_VariableSelectionModel;
46 QItemSelectionModel *m_VariableSelectionModel;
47
47
48
48
49 TimeController *m_TimeController{nullptr};
49 TimeController *m_TimeController{nullptr};
50 std::unique_ptr<VariableCacheController> m_VariableCacheController;
50 std::unique_ptr<VariableCacheController> m_VariableCacheController;
51
51
52 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
52 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
53 m_VariableToProviderMap;
53 m_VariableToProviderMap;
54 };
54 };
55
55
56 VariableController::VariableController(QObject *parent)
56 VariableController::VariableController(QObject *parent)
57 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
57 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
58 {
58 {
59 qCDebug(LOG_VariableController()) << tr("VariableController construction")
59 qCDebug(LOG_VariableController()) << tr("VariableController construction")
60 << QThread::currentThread();
60 << QThread::currentThread();
61 }
61 }
62
62
63 VariableController::~VariableController()
63 VariableController::~VariableController()
64 {
64 {
65 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
65 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
66 << QThread::currentThread();
66 << QThread::currentThread();
67 this->waitForFinish();
67 this->waitForFinish();
68 }
68 }
69
69
70 VariableModel *VariableController::variableModel() noexcept
70 VariableModel *VariableController::variableModel() noexcept
71 {
71 {
72 return impl->m_VariableModel;
72 return impl->m_VariableModel;
73 }
73 }
74
74
75 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
75 QItemSelectionModel *VariableController::variableSelectionModel() noexcept
76 {
76 {
77 return impl->m_VariableSelectionModel;
77 return impl->m_VariableSelectionModel;
78 }
78 }
79
79
80 void VariableController::setTimeController(TimeController *timeController) noexcept
80 void VariableController::setTimeController(TimeController *timeController) noexcept
81 {
81 {
82 impl->m_TimeController = timeController;
82 impl->m_TimeController = timeController;
83 }
83 }
84
84
85 void VariableController::createVariable(const QString &name,
85 void VariableController::createVariable(const QString &name,
86 std::shared_ptr<IDataProvider> provider) noexcept
86 std::shared_ptr<IDataProvider> provider) noexcept
87 {
87 {
88
88
89 if (!impl->m_TimeController) {
89 if (!impl->m_TimeController) {
90 qCCritical(LOG_VariableController())
90 qCCritical(LOG_VariableController())
91 << tr("Impossible to create variable: The time controller is null");
91 << tr("Impossible to create variable: The time controller is null");
92 return;
92 return;
93 }
93 }
94
94
95
95
96 /// @todo : for the moment :
96 /// @todo : for the moment :
97 /// - the provider is only used to retrieve data from the variable for its initialization, but
97 /// - the provider is only used to retrieve data from the variable for its initialization, but
98 /// it will be retained later
98 /// it will be retained later
99 /// - default data are generated for the variable, without taking into account the timerange set
99 /// - default data are generated for the variable, without taking into account the timerange set
100 /// in sciqlop
100 /// in sciqlop
101 auto dateTime = impl->m_TimeController->dateTime();
101 auto dateTime = impl->m_TimeController->dateTime();
102 if (auto newVariable = impl->m_VariableModel->createVariable(
102 if (auto newVariable = impl->m_VariableModel->createVariable(
103 name, dateTime, generateDefaultDataSeries(*provider, dateTime))) {
103 name, dateTime, generateDefaultDataSeries(*provider, dateTime))) {
104
104
105 // store the provider
105 // store the provider
106 impl->m_VariableToProviderMap[newVariable] = provider;
106 impl->m_VariableToProviderMap[newVariable] = provider;
107 connect(provider.get(), &IDataProvider::dataProvided, newVariable.get(),
107 connect(provider.get(), &IDataProvider::dataProvided, newVariable.get(),
108 &Variable::onAddDataSeries);
108 &Variable::setDataSeries);
109
109
110
110
111 // store in cache
111 // store in cache
112 impl->m_VariableCacheController->addDateTime(newVariable, dateTime);
112 impl->m_VariableCacheController->addDateTime(newVariable, dateTime);
113
113
114 // notify the creation
114 // notify the creation
115 emit variableCreated(newVariable);
115 emit variableCreated(newVariable);
116 }
116 }
117 }
117 }
118
118
119 void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime)
119 void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime)
120 {
120 {
121 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
121 auto selectedRows = impl->m_VariableSelectionModel->selectedRows();
122
122
123 for (const auto &selectedRow : qAsConst(selectedRows)) {
123 for (const auto &selectedRow : qAsConst(selectedRows)) {
124 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
124 if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) {
125 selectedVariable->setDateTime(dateTime);
125 selectedVariable->setDateTime(dateTime);
126 this->onRequestDataLoading(selectedVariable, dateTime);
126 this->onRequestDataLoading(selectedVariable, dateTime);
127 }
127 }
128 }
128 }
129 }
129 }
130
130
131
131
132 void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable,
132 void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable,
133 const SqpDateTime &dateTime)
133 const SqpDateTime &dateTime)
134 {
134 {
135 // we want to load data of the variable for the dateTime.
135 // we want to load data of the variable for the dateTime.
136 // First we check if the cache contains some of them.
136 // First we check if the cache contains some of them.
137 // For the other, we ask the provider to give them.
137 // For the other, we ask the provider to give them.
138 if (variable) {
138 if (variable) {
139
139
140 auto dateTimeListNotInCache
140 auto dateTimeListNotInCache
141 = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime);
141 = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime);
142
142
143 if (!dateTimeListNotInCache.empty()) {
143 if (!dateTimeListNotInCache.empty()) {
144 // Ask the provider for each data on the dateTimeListNotInCache
144 // Ask the provider for each data on the dateTimeListNotInCache
145 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
145 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
146 std::move(dateTimeListNotInCache));
146 std::move(dateTimeListNotInCache));
147 // store in cache
147 // store in cache
148 impl->m_VariableCacheController->addDateTime(variable, dateTime);
148 impl->m_VariableCacheController->addDateTime(variable, dateTime);
149 }
149 }
150 else {
150 else {
151 emit variable->updated();
151 emit variable->updated();
152 }
152 }
153 }
153 }
154 else {
154 else {
155 qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null");
155 qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null");
156 }
156 }
157 }
157 }
158
158
159
159
160 void VariableController::initialize()
160 void VariableController::initialize()
161 {
161 {
162 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
162 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
163 impl->m_WorkingMutex.lock();
163 impl->m_WorkingMutex.lock();
164 qCDebug(LOG_VariableController()) << tr("VariableController init END");
164 qCDebug(LOG_VariableController()) << tr("VariableController init END");
165 }
165 }
166
166
167 void VariableController::finalize()
167 void VariableController::finalize()
168 {
168 {
169 impl->m_WorkingMutex.unlock();
169 impl->m_WorkingMutex.unlock();
170 }
170 }
171
171
172 void VariableController::waitForFinish()
172 void VariableController::waitForFinish()
173 {
173 {
174 QMutexLocker locker{&impl->m_WorkingMutex};
174 QMutexLocker locker{&impl->m_WorkingMutex};
175 }
175 }
@@ -1,155 +1,155
1 #include <Variable/Variable.h>
1 #include <Variable/Variable.h>
2 #include <Variable/VariableModel.h>
2 #include <Variable/VariableModel.h>
3
3
4 #include <Data/IDataSeries.h>
4 #include <Data/IDataSeries.h>
5
5
6 #include <QDateTime>
6 #include <QDateTime>
7 #include <QSize>
7 #include <QSize>
8
8
9 Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
9 Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
10
10
11 namespace {
11 namespace {
12
12
13 // Column indexes
13 // Column indexes
14 const auto NAME_COLUMN = 0;
14 const auto NAME_COLUMN = 0;
15 const auto TSTART_COLUMN = 1;
15 const auto TSTART_COLUMN = 1;
16 const auto TEND_COLUMN = 2;
16 const auto TEND_COLUMN = 2;
17 const auto NB_COLUMNS = 3;
17 const auto NB_COLUMNS = 3;
18
18
19 // Column properties
19 // Column properties
20 const auto DEFAULT_HEIGHT = 25;
20 const auto DEFAULT_HEIGHT = 25;
21 const auto DEFAULT_WIDTH = 100;
21 const auto DEFAULT_WIDTH = 100;
22
22
23 struct ColumnProperties {
23 struct ColumnProperties {
24 ColumnProperties(const QString &name = {}, int width = DEFAULT_WIDTH,
24 ColumnProperties(const QString &name = {}, int width = DEFAULT_WIDTH,
25 int height = DEFAULT_HEIGHT)
25 int height = DEFAULT_HEIGHT)
26 : m_Name{name}, m_Width{width}, m_Height{height}
26 : m_Name{name}, m_Width{width}, m_Height{height}
27 {
27 {
28 }
28 }
29
29
30 QString m_Name;
30 QString m_Name;
31 int m_Width;
31 int m_Width;
32 int m_Height;
32 int m_Height;
33 };
33 };
34
34
35 const auto COLUMN_PROPERTIES
35 const auto COLUMN_PROPERTIES
36 = QHash<int, ColumnProperties>{{NAME_COLUMN, {QObject::tr("Name")}},
36 = QHash<int, ColumnProperties>{{NAME_COLUMN, {QObject::tr("Name")}},
37 {TSTART_COLUMN, {QObject::tr("tStart"), 180}},
37 {TSTART_COLUMN, {QObject::tr("tStart"), 180}},
38 {TEND_COLUMN, {QObject::tr("tEnd"), 180}}};
38 {TEND_COLUMN, {QObject::tr("tEnd"), 180}}};
39
39
40 /// Format for datetimes
40 /// Format for datetimes
41 const auto DATETIME_FORMAT = QStringLiteral("dd/MM/yyyy \nhh:mm:ss:zzz");
41 const auto DATETIME_FORMAT = QStringLiteral("dd/MM/yyyy \nhh:mm:ss:zzz");
42
42
43 } // namespace
43 } // namespace
44
44
45 struct VariableModel::VariableModelPrivate {
45 struct VariableModel::VariableModelPrivate {
46 /// Variables created in SciQlop
46 /// Variables created in SciQlop
47 std::vector<std::shared_ptr<Variable> > m_Variables;
47 std::vector<std::shared_ptr<Variable> > m_Variables;
48 };
48 };
49
49
50 VariableModel::VariableModel(QObject *parent)
50 VariableModel::VariableModel(QObject *parent)
51 : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()}
51 : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()}
52 {
52 {
53 }
53 }
54
54
55 std::shared_ptr<Variable>
55 std::shared_ptr<Variable>
56 VariableModel::createVariable(const QString &name, const SqpDateTime &dateTime,
56 VariableModel::createVariable(const QString &name, const SqpDateTime &dateTime,
57 std::unique_ptr<IDataSeries> defaultDataSeries) noexcept
57 std::shared_ptr<IDataSeries> defaultDataSeries) noexcept
58 {
58 {
59 auto insertIndex = rowCount();
59 auto insertIndex = rowCount();
60 beginInsertRows({}, insertIndex, insertIndex);
60 beginInsertRows({}, insertIndex, insertIndex);
61
61
62 /// @todo For the moment, the other data of the variable is initialized with default values
62 /// @todo For the moment, the other data of the variable is initialized with default values
63 auto variable = std::make_shared<Variable>(name, QStringLiteral("unit"),
63 auto variable = std::make_shared<Variable>(name, QStringLiteral("unit"),
64 QStringLiteral("mission"), dateTime);
64 QStringLiteral("mission"), dateTime);
65 variable->setDataSeries(std::move(defaultDataSeries));
65 variable->setDataSeries(std::move(defaultDataSeries));
66
66
67 impl->m_Variables.push_back(variable);
67 impl->m_Variables.push_back(variable);
68
68
69 endInsertRows();
69 endInsertRows();
70
70
71 return variable;
71 return variable;
72 }
72 }
73
73
74 std::shared_ptr<Variable> VariableModel::variable(int index) const
74 std::shared_ptr<Variable> VariableModel::variable(int index) const
75 {
75 {
76 return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables[index] : nullptr;
76 return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables[index] : nullptr;
77 }
77 }
78
78
79 int VariableModel::columnCount(const QModelIndex &parent) const
79 int VariableModel::columnCount(const QModelIndex &parent) const
80 {
80 {
81 Q_UNUSED(parent);
81 Q_UNUSED(parent);
82
82
83 return NB_COLUMNS;
83 return NB_COLUMNS;
84 }
84 }
85
85
86 int VariableModel::rowCount(const QModelIndex &parent) const
86 int VariableModel::rowCount(const QModelIndex &parent) const
87 {
87 {
88 Q_UNUSED(parent);
88 Q_UNUSED(parent);
89
89
90 return impl->m_Variables.size();
90 return impl->m_Variables.size();
91 }
91 }
92
92
93 QVariant VariableModel::data(const QModelIndex &index, int role) const
93 QVariant VariableModel::data(const QModelIndex &index, int role) const
94 {
94 {
95 if (!index.isValid()) {
95 if (!index.isValid()) {
96 return QVariant{};
96 return QVariant{};
97 }
97 }
98
98
99 if (index.row() < 0 || index.row() >= rowCount()) {
99 if (index.row() < 0 || index.row() >= rowCount()) {
100 return QVariant{};
100 return QVariant{};
101 }
101 }
102
102
103 if (role == Qt::DisplayRole) {
103 if (role == Qt::DisplayRole) {
104 if (auto variable = impl->m_Variables.at(index.row()).get()) {
104 if (auto variable = impl->m_Variables.at(index.row()).get()) {
105 /// Lambda function that builds the variant to return for a time value
105 /// Lambda function that builds the variant to return for a time value
106 auto dateTimeVariant = [](double time) {
106 auto dateTimeVariant = [](double time) {
107 auto dateTime = QDateTime::fromMSecsSinceEpoch(time * 1000.);
107 auto dateTime = QDateTime::fromMSecsSinceEpoch(time * 1000.);
108 return dateTime.toString(DATETIME_FORMAT);
108 return dateTime.toString(DATETIME_FORMAT);
109 };
109 };
110
110
111 switch (index.column()) {
111 switch (index.column()) {
112 case NAME_COLUMN:
112 case NAME_COLUMN:
113 return variable->name();
113 return variable->name();
114 case TSTART_COLUMN:
114 case TSTART_COLUMN:
115 return dateTimeVariant(variable->dateTime().m_TStart);
115 return dateTimeVariant(variable->dateTime().m_TStart);
116 case TEND_COLUMN:
116 case TEND_COLUMN:
117 return dateTimeVariant(variable->dateTime().m_TEnd);
117 return dateTimeVariant(variable->dateTime().m_TEnd);
118 default:
118 default:
119 // No action
119 // No action
120 break;
120 break;
121 }
121 }
122
122
123 qWarning(LOG_VariableModel())
123 qWarning(LOG_VariableModel())
124 << tr("Can't get data (unknown column %1)").arg(index.column());
124 << tr("Can't get data (unknown column %1)").arg(index.column());
125 }
125 }
126 else {
126 else {
127 qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)");
127 qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)");
128 }
128 }
129 }
129 }
130
130
131 return QVariant{};
131 return QVariant{};
132 }
132 }
133
133
134 QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const
134 QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const
135 {
135 {
136 if (role != Qt::DisplayRole && role != Qt::SizeHintRole) {
136 if (role != Qt::DisplayRole && role != Qt::SizeHintRole) {
137 return QVariant{};
137 return QVariant{};
138 }
138 }
139
139
140 if (orientation == Qt::Horizontal) {
140 if (orientation == Qt::Horizontal) {
141 auto propertiesIt = COLUMN_PROPERTIES.find(section);
141 auto propertiesIt = COLUMN_PROPERTIES.find(section);
142 if (propertiesIt != COLUMN_PROPERTIES.cend()) {
142 if (propertiesIt != COLUMN_PROPERTIES.cend()) {
143 // Role is either DisplayRole or SizeHintRole
143 // Role is either DisplayRole or SizeHintRole
144 return (role == Qt::DisplayRole)
144 return (role == Qt::DisplayRole)
145 ? QVariant{propertiesIt->m_Name}
145 ? QVariant{propertiesIt->m_Name}
146 : QVariant{QSize{propertiesIt->m_Width, propertiesIt->m_Height}};
146 : QVariant{QSize{propertiesIt->m_Width, propertiesIt->m_Height}};
147 }
147 }
148 else {
148 else {
149 qWarning(LOG_VariableModel())
149 qWarning(LOG_VariableModel())
150 << tr("Can't get header data (unknown column %1)").arg(section);
150 << tr("Can't get header data (unknown column %1)").arg(section);
151 }
151 }
152 }
152 }
153
153
154 return QVariant{};
154 return QVariant{};
155 }
155 }
@@ -1,26 +1,26
1 #ifndef SCIQLOP_COSINUSPROVIDER_H
1 #ifndef SCIQLOP_COSINUSPROVIDER_H
2 #define SCIQLOP_COSINUSPROVIDER_H
2 #define SCIQLOP_COSINUSPROVIDER_H
3
3
4 #include <Data/IDataProvider.h>
4 #include <Data/IDataProvider.h>
5
5
6 #include <QLoggingCategory>
6 #include <QLoggingCategory>
7
7
8 Q_DECLARE_LOGGING_CATEGORY(LOG_CosinusProvider)
8 Q_DECLARE_LOGGING_CATEGORY(LOG_CosinusProvider)
9
9
10 /**
10 /**
11 * @brief The CosinusProvider class is an example of how a data provider can generate data
11 * @brief The CosinusProvider class is an example of how a data provider can generate data
12 */
12 */
13 class CosinusProvider : public IDataProvider {
13 class CosinusProvider : public IDataProvider {
14 public:
14 public:
15 /// @sa IDataProvider::retrieveData()
15 /// @sa IDataProvider::retrieveData()
16 std::unique_ptr<IDataSeries>
16 std::shared_ptr<IDataSeries>
17 retrieveData(const DataProviderParameters &parameters) const override;
17 retrieveData(const DataProviderParameters &parameters) const override;
18
18
19 void requestDataLoading(const QVector<SqpDateTime> &dateTimeList) override;
19 void requestDataLoading(const QVector<SqpDateTime> &dateTimeList) override;
20
20
21
21
22 private:
22 private:
23 std::shared_ptr<IDataSeries> retrieveDataSeries(const SqpDateTime &dateTime);
23 std::shared_ptr<IDataSeries> retrieveDataSeries(const SqpDateTime &dateTime);
24 };
24 };
25
25
26 #endif // SCIQLOP_COSINUSPROVIDER_H
26 #endif // SCIQLOP_COSINUSPROVIDER_H
@@ -1,74 +1,47
1 #include "CosinusProvider.h"
1 #include "CosinusProvider.h"
2
2
3 #include <Data/DataProviderParameters.h>
3 #include <Data/DataProviderParameters.h>
4 #include <Data/ScalarSeries.h>
4 #include <Data/ScalarSeries.h>
5
5
6 #include <cmath>
6 #include <cmath>
7
7
8 #include <QDateTime>
8 #include <QDateTime>
9
9
10 Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider")
10 Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider")
11
11
12 std::unique_ptr<IDataSeries>
12 std::shared_ptr<IDataSeries>
13 CosinusProvider::retrieveData(const DataProviderParameters &parameters) const
13 CosinusProvider::retrieveData(const DataProviderParameters &parameters) const
14 {
14 {
15 auto dateTime = parameters.m_Time;
15 auto dateTime = parameters.m_Time;
16
16
17 // Gets the timerange from the parameters
18 auto start = dateTime.m_TStart;
19 auto end = dateTime.m_TEnd;
20
21
22 // We assure that timerange is valid
23 if (end < start) {
24 std::swap(start, end);
25 }
26
27 // Generates scalar series containing cosinus values (one value per second)
28 auto scalarSeries
29 = std::make_unique<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{});
30
31 auto dataIndex = 0;
32 for (auto time = start; time < end; ++time, ++dataIndex) {
33 scalarSeries->setData(dataIndex, time, std::cos(time));
34 }
35
36 return scalarSeries;
37 }
38
39 void CosinusProvider::requestDataLoading(const QVector<SqpDateTime> &dateTimeList)
40 {
41 // NOTE: Try to use multithread if possible
42 for (const auto &dateTime : dateTimeList) {
43
44 auto scalarSeries = this->retrieveDataSeries(dateTime);
45
46 emit dataProvided(scalarSeries, dateTime);
47 }
48 }
49
50
51 std::shared_ptr<IDataSeries> CosinusProvider::retrieveDataSeries(const SqpDateTime &dateTime)
52 {
53 auto dataIndex = 0;
17 auto dataIndex = 0;
54
18
55 // Gets the timerange from the parameters
19 // Gets the timerange from the parameters
56 double freq = 100.0;
20 double freq = 100.0;
57 double start = dateTime.m_TStart * freq; // 100 htz
21 double start = dateTime.m_TStart * freq; // 100 htz
58 double end = dateTime.m_TEnd * freq; // 100 htz
22 double end = dateTime.m_TEnd * freq; // 100 htz
59
23
60 // We assure that timerange is valid
24 // We assure that timerange is valid
61 if (end < start) {
25 if (end < start) {
62 std::swap(start, end);
26 std::swap(start, end);
63 }
27 }
64
28
65 // Generates scalar series containing cosinus values (one value per second)
29 // Generates scalar series containing cosinus values (one value per second)
66 auto scalarSeries
30 auto scalarSeries
67 = std::make_shared<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{});
31 = std::make_shared<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{});
68
32
69 for (auto time = start; time < end; ++time, ++dataIndex) {
33 for (auto time = start; time < end; ++time, ++dataIndex) {
70 const auto timeOnFreq = time / freq;
34 const auto timeOnFreq = time / freq;
71 scalarSeries->setData(dataIndex, timeOnFreq, std::cos(timeOnFreq));
35 scalarSeries->setData(dataIndex, timeOnFreq, std::cos(timeOnFreq));
72 }
36 }
73 return scalarSeries;
37 return scalarSeries;
74 }
38 }
39
40 void CosinusProvider::requestDataLoading(const QVector<SqpDateTime> &dateTimeList)
41 {
42 // NOTE: Try to use multithread if possible
43 for (const auto &dateTime : dateTimeList) {
44 auto scalarSeries = this->retrieveData(DataProviderParameters{dateTime});
45 emit dataProvided(scalarSeries, dateTime);
46 }
47 }
General Comments 0
You need to be logged in to leave comments. Login now