##// END OF EJS Templates
Merge branch 'feature/VariableModel3' into develop
Alexandre Leroux -
r173:030b888e93aa merge
parent child
Show More
@@ -0,0 +1,43
1 #include "Variable/Variable.h"
2
3 #include <Data/IDataSeries.h>
4
5 struct Variable::VariablePrivate {
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}
8 {
9 }
10
11 QString m_Name;
12 QString m_Unit;
13 QString m_Mission;
14 std::unique_ptr<IDataSeries> m_DataSeries;
15 };
16
17 Variable::Variable(const QString &name, const QString &unit, const QString &mission)
18 : impl{spimpl::make_unique_impl<VariablePrivate>(name, unit, mission)}
19 {
20 }
21
22 QString Variable::name() const noexcept
23 {
24 return impl->m_Name;
25 }
26
27 QString Variable::mission() const noexcept
28 {
29 return impl->m_Mission;
30 }
31
32 QString Variable::unit() const noexcept
33 {
34 return impl->m_Unit;
35 }
36
37 void Variable::addDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept
38 {
39 if (!impl->m_DataSeries) {
40 impl->m_DataSeries = std::move(dataSeries);
41 }
42 /// @todo : else, merge the two data series (if possible)
43 }
@@ -1,25 +1,30
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>
7
6 class DataProviderParameters;
8 class DataProviderParameters;
7 class IDataSeries;
9 class IDataSeries;
8
10
9 /**
11 /**
10 * @brief The IDataProvider interface aims to declare a data provider.
12 * @brief The IDataProvider interface aims to declare a data provider.
11 *
13 *
12 * A data provider is an entity that generates data and returns it according to various parameters
14 * A data provider is an entity that generates data and returns it according to various parameters
13 * (time interval, product to retrieve the data, etc.)
15 * (time interval, product to retrieve the data, etc.)
14 *
16 *
15 * @sa IDataSeries
17 * @sa IDataSeries
16 */
18 */
17 class IDataProvider {
19 class IDataProvider {
18 public:
20 public:
19 virtual ~IDataProvider() noexcept = default;
21 virtual ~IDataProvider() noexcept = default;
20
22
21 virtual std::unique_ptr<IDataSeries>
23 virtual std::unique_ptr<IDataSeries>
22 retrieveData(const DataProviderParameters &parameters) const = 0;
24 retrieveData(const DataProviderParameters &parameters) const = 0;
23 };
25 };
24
26
27 // Required for using shared_ptr in signals/slots
28 Q_DECLARE_METATYPE(std::shared_ptr<IDataProvider>)
29
25 #endif // SCIQLOP_IDATAPROVIDER_H
30 #endif // SCIQLOP_IDATAPROVIDER_H
@@ -1,79 +1,90
1 #ifndef SCIQLOP_DATASOURCECONTROLLER_H
1 #ifndef SCIQLOP_DATASOURCECONTROLLER_H
2 #define SCIQLOP_DATASOURCECONTROLLER_H
2 #define SCIQLOP_DATASOURCECONTROLLER_H
3
3
4 #include <QLoggingCategory>
4 #include <QLoggingCategory>
5 #include <QObject>
5 #include <QObject>
6 #include <QUuid>
6 #include <QUuid>
7
7
8 #include <Common/spimpl.h>
8 #include <Common/spimpl.h>
9
9
10 Q_DECLARE_LOGGING_CATEGORY(LOG_DataSourceController)
10 Q_DECLARE_LOGGING_CATEGORY(LOG_DataSourceController)
11
11
12 class DataSourceItem;
12 class DataSourceItem;
13 class IDataProvider;
13 class IDataProvider;
14
14
15 /**
15 /**
16 * @brief The DataSourceController class aims to make the link between SciQlop and its plugins. This
16 * @brief The DataSourceController class aims to make the link between SciQlop and its plugins. This
17 * is the intermediate class that SciQlop has to use in the way to connect a data source. Please
17 * is the intermediate class that SciQlop has to use in the way to connect a data source. Please
18 * first use register method to initialize a plugin specified by its metadata name (JSON plugin
18 * first use register method to initialize a plugin specified by its metadata name (JSON plugin
19 * source) then others specifics method will be able to access it. You can load a data source driver
19 * source) then others specifics method will be able to access it. You can load a data source driver
20 * plugin then create a data source.
20 * plugin then create a data source.
21 */
21 */
22 class DataSourceController : public QObject {
22 class DataSourceController : public QObject {
23 Q_OBJECT
23 Q_OBJECT
24 public:
24 public:
25 explicit DataSourceController(QObject *parent = 0);
25 explicit DataSourceController(QObject *parent = 0);
26 virtual ~DataSourceController();
26 virtual ~DataSourceController();
27
27
28 /**
28 /**
29 * Registers a data source. The method delivers a unique id that can be used afterwards to
29 * Registers a data source. The method delivers a unique id that can be used afterwards to
30 * access to the data source properties (structure, connection parameters, data provider, etc.)
30 * access to the data source properties (structure, connection parameters, data provider, etc.)
31 * @param dataSourceName the name of the data source
31 * @param dataSourceName the name of the data source
32 * @return the unique id with which the data source has been registered
32 * @return the unique id with which the data source has been registered
33 */
33 */
34 QUuid registerDataSource(const QString &dataSourceName) noexcept;
34 QUuid registerDataSource(const QString &dataSourceName) noexcept;
35
35
36 /**
36 /**
37 * Sets the structure of a data source. The controller takes ownership of the structure.
37 * Sets the structure of a data source. The controller takes ownership of the structure.
38 * @param dataSourceUid the unique id with which the data source has been registered into the
38 * @param dataSourceUid the unique id with which the data source has been registered into the
39 * controller. If it is invalid, the method has no effect.
39 * controller. If it is invalid, the method has no effect.
40 * @param dataSourceItem the structure of the data source
40 * @param dataSourceItem the structure of the data source
41 * @sa registerDataSource()
41 * @sa registerDataSource()
42 */
42 */
43 void setDataSourceItem(const QUuid &dataSourceUid,
43 void setDataSourceItem(const QUuid &dataSourceUid,
44 std::unique_ptr<DataSourceItem> dataSourceItem) noexcept;
44 std::unique_ptr<DataSourceItem> dataSourceItem) noexcept;
45
45
46 /**
46 /**
47 * Sets the data provider used to retrieve data from of a data source. The controller takes
47 * Sets the data provider used to retrieve data from of a data source. The controller takes
48 * ownership of the provider.
48 * ownership of the provider.
49 * @param dataSourceUid the unique id with which the data source has been registered into the
49 * @param dataSourceUid the unique id with which the data source has been registered into the
50 * controller. If it is invalid, the method has no effect.
50 * controller. If it is invalid, the method has no effect.
51 * @param dataProvider the provider of the data source
51 * @param dataProvider the provider of the data source
52 * @sa registerDataSource()
52 * @sa registerDataSource()
53 */
53 */
54 void setDataProvider(const QUuid &dataSourceUid,
54 void setDataProvider(const QUuid &dataSourceUid,
55 std::unique_ptr<IDataProvider> dataProvider) noexcept;
55 std::unique_ptr<IDataProvider> dataProvider) noexcept;
56
56
57 /**
57 /**
58 * Loads an item (product) as a variable in SciQlop
58 * Loads an item (product) as a variable in SciQlop
59 * @param dataSourceUid the unique id of the data source containing the item. It is used to get
60 * the data provider associated to the data source, and pass it to for the variable creation
59 * @param productItem the item to load
61 * @param productItem the item to load
60 */
62 */
61 void loadProductItem(const DataSourceItem &productItem) noexcept;
63 void loadProductItem(const QUuid &dataSourceUid, const DataSourceItem &productItem) noexcept;
62
64
63 public slots:
65 public slots:
64 /// Manage init/end of the controller
66 /// Manage init/end of the controller
65 void initialize();
67 void initialize();
66 void finalize();
68 void finalize();
67
69
68 signals:
70 signals:
69 /// Signal emitted when a structure has been set for a data source
71 /// Signal emitted when a structure has been set for a data source
70 void dataSourceItemSet(DataSourceItem *dataSourceItem);
72 void dataSourceItemSet(DataSourceItem *dataSourceItem);
71
73
74 /**
75 * Signal emitted when a variable creation is asked for a product
76 * @param variableName the name of the variable
77 * @param variableProvider the provider that will be used to retrieve the data of the variable
78 * (can be null)
79 */
80 void variableCreationRequested(const QString &variableName,
81 std::shared_ptr<IDataProvider> variableProvider);
82
72 private:
83 private:
73 void waitForFinish();
84 void waitForFinish();
74
85
75 class DataSourceControllerPrivate;
86 class DataSourceControllerPrivate;
76 spimpl::unique_impl_ptr<DataSourceControllerPrivate> impl;
87 spimpl::unique_impl_ptr<DataSourceControllerPrivate> impl;
77 };
88 };
78
89
79 #endif // SCIQLOP_DATASOURCECONTROLLER_H
90 #endif // SCIQLOP_DATASOURCECONTROLLER_H
@@ -1,20 +1,32
1 #ifndef SCIQLOP_VARIABLE_H
1 #ifndef SCIQLOP_VARIABLE_H
2 #define SCIQLOP_VARIABLE_H
2 #define SCIQLOP_VARIABLE_H
3
3
4 #include <QString>
4 #include <Common/spimpl.h>
5
6 #include <QObject>
7
8 class IDataSeries;
9 class QString;
5
10
6 /**
11 /**
7 * @brief The Variable struct represents a variable in SciQlop.
12 * @brief The Variable class represents a variable in SciQlop.
8 */
13 */
9 struct Variable {
14 class Variable {
10 explicit Variable(const QString &name, const QString &unit, const QString &mission)
15 public:
11 : m_Name{name}, m_Unit{unit}, m_Mission{mission}
16 explicit Variable(const QString &name, const QString &unit, const QString &mission);
12 {
17
13 }
18 QString name() const noexcept;
14
19 QString mission() const noexcept;
15 QString m_Name;
20 QString unit() const noexcept;
16 QString m_Unit;
21
17 QString m_Mission;
22 void addDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept;
23
24 private:
25 class VariablePrivate;
26 spimpl::unique_impl_ptr<VariablePrivate> impl;
18 };
27 };
19
28
29 // Required for using shared_ptr in signals/slots
30 Q_DECLARE_METATYPE(std::shared_ptr<Variable>)
31
20 #endif // SCIQLOP_VARIABLE_H
32 #endif // SCIQLOP_VARIABLE_H
@@ -1,43 +1,48
1 #ifndef SCIQLOP_VARIABLECONTROLLER_H
1 #ifndef SCIQLOP_VARIABLECONTROLLER_H
2 #define SCIQLOP_VARIABLECONTROLLER_H
2 #define SCIQLOP_VARIABLECONTROLLER_H
3
3
4 #include <QLoggingCategory>
4 #include <QLoggingCategory>
5 #include <QObject>
5 #include <QObject>
6
6
7 #include <Common/spimpl.h>
7 #include <Common/spimpl.h>
8
8
9 class IDataProvider;
9 class Variable;
10 class Variable;
10 class VariableModel;
11 class VariableModel;
11
12
12 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController)
13 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController)
13
14
14 /**
15 /**
15 * @brief The VariableController class aims to handle the variables in SciQlop.
16 * @brief The VariableController class aims to handle the variables in SciQlop.
16 */
17 */
17 class VariableController : public QObject {
18 class VariableController : public QObject {
18 Q_OBJECT
19 Q_OBJECT
19 public:
20 public:
20 explicit VariableController(QObject *parent = 0);
21 explicit VariableController(QObject *parent = 0);
21 virtual ~VariableController();
22 virtual ~VariableController();
22
23
24 VariableModel *variableModel() noexcept;
25
26 signals:
27 /// Signal emitted when a variable has been created
28 void variableCreated(std::shared_ptr<Variable> variable);
29
30 public slots:
23 /**
31 /**
24 * Creates a new variable
32 * Creates a new variable and adds it to the model
25 * @param name the name of the new variable
33 * @param name the name of the new variable
26 * @return the variable if it was created successfully, nullptr otherwise
34 * @param provider the data provider for the new variable
27 */
35 */
28 Variable *createVariable(const QString &name) noexcept;
36 void createVariable(const QString &name, std::shared_ptr<IDataProvider> provider) noexcept;
29
37
30 VariableModel *variableModel() noexcept;
31
32 public slots:
33 void initialize();
38 void initialize();
34 void finalize();
39 void finalize();
35
40
36 private:
41 private:
37 void waitForFinish();
42 void waitForFinish();
38
43
39 class VariableControllerPrivate;
44 class VariableControllerPrivate;
40 spimpl::unique_impl_ptr<VariableControllerPrivate> impl;
45 spimpl::unique_impl_ptr<VariableControllerPrivate> impl;
41 };
46 };
42
47
43 #endif // SCIQLOP_VARIABLECONTROLLER_H
48 #endif // SCIQLOP_VARIABLECONTROLLER_H
@@ -1,41 +1,44
1 #ifndef SCIQLOP_VARIABLEMODEL_H
1 #ifndef SCIQLOP_VARIABLEMODEL_H
2 #define SCIQLOP_VARIABLEMODEL_H
2 #define SCIQLOP_VARIABLEMODEL_H
3
3
4 #include <Common/spimpl.h>
4 #include <Common/spimpl.h>
5
5
6 #include <QAbstractTableModel>
6 #include <QAbstractTableModel>
7 #include <QLoggingCategory>
7 #include <QLoggingCategory>
8
8
9 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel)
9 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel)
10
10
11 class IDataSeries;
11 class Variable;
12 class Variable;
12
13
13 /**
14 /**
14 * @brief The VariableModel class aims to hold the variables that have been created in SciQlop
15 * @brief The VariableModel class aims to hold the variables that have been created in SciQlop
15 */
16 */
16 class VariableModel : public QAbstractTableModel {
17 class VariableModel : public QAbstractTableModel {
17 public:
18 public:
18 explicit VariableModel(QObject *parent = nullptr);
19 explicit VariableModel(QObject *parent = nullptr);
19
20
20 /**
21 /**
21 * Creates a new variable in the model
22 * Creates a new variable in the model
22 * @param name the name of the new variable
23 * @param name the name of the new variable
23 * @return the variable if it was created successfully, nullptr otherwise
24 * @param defaultDataSeries the default data of the new variable
25 * @return the pointer to the new variable
24 */
26 */
25 Variable *createVariable(const QString &name) noexcept;
27 std::shared_ptr<Variable>
28 createVariable(const QString &name, std::unique_ptr<IDataSeries> defaultDataSeries) noexcept;
26
29
27 // /////////////////////////// //
30 // /////////////////////////// //
28 // QAbstractTableModel methods //
31 // QAbstractTableModel methods //
29 // /////////////////////////// //
32 // /////////////////////////// //
30 virtual int columnCount(const QModelIndex &parent = QModelIndex{}) const override;
33 virtual int columnCount(const QModelIndex &parent = QModelIndex{}) const override;
31 virtual int rowCount(const QModelIndex &parent = QModelIndex{}) const override;
34 virtual int rowCount(const QModelIndex &parent = QModelIndex{}) const override;
32 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
35 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
33 virtual QVariant headerData(int section, Qt::Orientation orientation,
36 virtual QVariant headerData(int section, Qt::Orientation orientation,
34 int role = Qt::DisplayRole) const override;
37 int role = Qt::DisplayRole) const override;
35
38
36 private:
39 private:
37 class VariableModelPrivate;
40 class VariableModelPrivate;
38 spimpl::unique_impl_ptr<VariableModelPrivate> impl;
41 spimpl::unique_impl_ptr<VariableModelPrivate> impl;
39 };
42 };
40
43
41 #endif // SCIQLOP_VARIABLEMODEL_H
44 #endif // SCIQLOP_VARIABLEMODEL_H
@@ -1,39 +1,43
1 #ifndef SCIQLOP_VISUALIZATIONCONTROLLER_H
1 #ifndef SCIQLOP_VISUALIZATIONCONTROLLER_H
2 #define SCIQLOP_VISUALIZATIONCONTROLLER_H
2 #define SCIQLOP_VISUALIZATIONCONTROLLER_H
3
3
4 #include <QLoggingCategory>
4 #include <QLoggingCategory>
5 #include <QObject>
5 #include <QObject>
6 #include <QUuid>
6 #include <QUuid>
7
7
8 #include <Common/spimpl.h>
8 #include <Common/spimpl.h>
9
9
10 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationController)
10 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationController)
11
11
12 class DataSourceItem;
12 class DataSourceItem;
13 class Variable;
13
14
14 /**
15 /**
15 * @brief The VisualizationController class aims to make the link between SciQlop and its plugins.
16 * @brief The VisualizationController class aims to make the link between SciQlop and its plugins.
16 * This is the intermediate class that SciQlop has to use in the way to connect a data source.
17 * This is the intermediate class that SciQlop has to use in the way to connect a data source.
17 * Please first use register method to initialize a plugin specified by its metadata name (JSON
18 * Please first use register method to initialize a plugin specified by its metadata name (JSON
18 * plugin source) then others specifics method will be able to access it. You can load a data source
19 * plugin source) then others specifics method will be able to access it. You can load a data source
19 * driver plugin then create a data source.
20 * driver plugin then create a data source.
20 */
21 */
21 class VisualizationController : public QObject {
22 class VisualizationController : public QObject {
22 Q_OBJECT
23 Q_OBJECT
23 public:
24 public:
24 explicit VisualizationController(QObject *parent = 0);
25 explicit VisualizationController(QObject *parent = 0);
25 virtual ~VisualizationController();
26 virtual ~VisualizationController();
26
27
27 public slots:
28 public slots:
29 /// Slot called when a variable has been created in SciQlop
30 void onVariableCreated(std::shared_ptr<Variable> variable) noexcept;
31
28 /// Manage init/end of the controller
32 /// Manage init/end of the controller
29 void initialize();
33 void initialize();
30 void finalize();
34 void finalize();
31
35
32 private:
36 private:
33 void waitForFinish();
37 void waitForFinish();
34
38
35 class VisualizationControllerPrivate;
39 class VisualizationControllerPrivate;
36 spimpl::unique_impl_ptr<VisualizationControllerPrivate> impl;
40 spimpl::unique_impl_ptr<VisualizationControllerPrivate> impl;
37 };
41 };
38
42
39 #endif // SCIQLOP_VISUALIZATIONCONTROLLER_H
43 #endif // SCIQLOP_VISUALIZATIONCONTROLLER_H
@@ -1,100 +1,114
1 #include <DataSource/DataSourceController.h>
1 #include "DataSource/DataSourceController.h"
2 #include <DataSource/DataSourceItem.h>
2 #include "DataSource/DataSourceItem.h"
3
3
4 #include <Data/IDataProvider.h>
4 #include <Data/IDataProvider.h>
5
5
6 #include <QMutex>
6 #include <QMutex>
7 #include <QThread>
7 #include <QThread>
8
8
9 #include <QDir>
9 #include <QDir>
10 #include <QStandardPaths>
10 #include <QStandardPaths>
11
11
12 Q_LOGGING_CATEGORY(LOG_DataSourceController, "DataSourceController")
12 Q_LOGGING_CATEGORY(LOG_DataSourceController, "DataSourceController")
13
13
14 class DataSourceController::DataSourceControllerPrivate {
14 class DataSourceController::DataSourceControllerPrivate {
15 public:
15 public:
16 QMutex m_WorkingMutex;
16 QMutex m_WorkingMutex;
17 /// Data sources registered
17 /// Data sources registered
18 QHash<QUuid, QString> m_DataSources;
18 QHash<QUuid, QString> m_DataSources;
19 /// Data sources structures
19 /// Data sources structures
20 std::map<QUuid, std::unique_ptr<DataSourceItem> > m_DataSourceItems;
20 std::map<QUuid, std::unique_ptr<DataSourceItem> > m_DataSourceItems;
21 /// Data providers registered
21 /// Data providers registered
22 std::map<QUuid, std::unique_ptr<IDataProvider> > m_DataProviders;
22 /// @remarks Data providers are stored as shared_ptr as they can be sent to a variable and
23 /// continue to live without necessarily the data source controller
24 std::map<QUuid, std::shared_ptr<IDataProvider> > m_DataProviders;
23 };
25 };
24
26
25 DataSourceController::DataSourceController(QObject *parent)
27 DataSourceController::DataSourceController(QObject *parent)
26 : impl{spimpl::make_unique_impl<DataSourceControllerPrivate>()}
28 : impl{spimpl::make_unique_impl<DataSourceControllerPrivate>()}
27 {
29 {
28 qCDebug(LOG_DataSourceController()) << tr("DataSourceController construction")
30 qCDebug(LOG_DataSourceController()) << tr("DataSourceController construction")
29 << QThread::currentThread();
31 << QThread::currentThread();
30 }
32 }
31
33
32 DataSourceController::~DataSourceController()
34 DataSourceController::~DataSourceController()
33 {
35 {
34 qCDebug(LOG_DataSourceController()) << tr("DataSourceController destruction")
36 qCDebug(LOG_DataSourceController()) << tr("DataSourceController destruction")
35 << QThread::currentThread();
37 << QThread::currentThread();
36 this->waitForFinish();
38 this->waitForFinish();
37 }
39 }
38
40
39 QUuid DataSourceController::registerDataSource(const QString &dataSourceName) noexcept
41 QUuid DataSourceController::registerDataSource(const QString &dataSourceName) noexcept
40 {
42 {
41 auto dataSourceUid = QUuid::createUuid();
43 auto dataSourceUid = QUuid::createUuid();
42 impl->m_DataSources.insert(dataSourceUid, dataSourceName);
44 impl->m_DataSources.insert(dataSourceUid, dataSourceName);
43
45
44 return dataSourceUid;
46 return dataSourceUid;
45 }
47 }
46
48
47 void DataSourceController::setDataSourceItem(
49 void DataSourceController::setDataSourceItem(
48 const QUuid &dataSourceUid, std::unique_ptr<DataSourceItem> dataSourceItem) noexcept
50 const QUuid &dataSourceUid, std::unique_ptr<DataSourceItem> dataSourceItem) noexcept
49 {
51 {
50 if (impl->m_DataSources.contains(dataSourceUid)) {
52 if (impl->m_DataSources.contains(dataSourceUid)) {
53 // The data provider is implicitly converted to a shared_ptr
51 impl->m_DataSourceItems.insert(std::make_pair(dataSourceUid, std::move(dataSourceItem)));
54 impl->m_DataSourceItems.insert(std::make_pair(dataSourceUid, std::move(dataSourceItem)));
52
55
53 // Retrieves the data source item to emit the signal with it
56 // Retrieves the data source item to emit the signal with it
54 auto it = impl->m_DataSourceItems.find(dataSourceUid);
57 auto it = impl->m_DataSourceItems.find(dataSourceUid);
55 if (it != impl->m_DataSourceItems.end()) {
58 if (it != impl->m_DataSourceItems.end()) {
56 emit dataSourceItemSet(it->second.get());
59 emit dataSourceItemSet(it->second.get());
57 }
60 }
58 }
61 }
59 else {
62 else {
60 qCWarning(LOG_DataSourceController()) << tr("Can't set data source item for uid %1 : no "
63 qCWarning(LOG_DataSourceController()) << tr("Can't set data source item for uid %1 : no "
61 "data source has been registered with the uid")
64 "data source has been registered with the uid")
62 .arg(dataSourceUid.toString());
65 .arg(dataSourceUid.toString());
63 }
66 }
64 }
67 }
65
68
66 void DataSourceController::setDataProvider(const QUuid &dataSourceUid,
69 void DataSourceController::setDataProvider(const QUuid &dataSourceUid,
67 std::unique_ptr<IDataProvider> dataProvider) noexcept
70 std::unique_ptr<IDataProvider> dataProvider) noexcept
68 {
71 {
69 if (impl->m_DataSources.contains(dataSourceUid)) {
72 if (impl->m_DataSources.contains(dataSourceUid)) {
70 impl->m_DataProviders.insert(std::make_pair(dataSourceUid, std::move(dataProvider)));
73 impl->m_DataProviders.insert(std::make_pair(dataSourceUid, std::move(dataProvider)));
71 }
74 }
72 else {
75 else {
73 qCWarning(LOG_DataSourceController()) << tr("Can't set data provider for uid %1 : no data "
76 qCWarning(LOG_DataSourceController()) << tr("Can't set data provider for uid %1 : no data "
74 "source has been registered with the uid")
77 "source has been registered with the uid")
75 .arg(dataSourceUid.toString());
78 .arg(dataSourceUid.toString());
76 }
79 }
77 }
80 }
78
81
79 void DataSourceController::loadProductItem(const DataSourceItem &productItem) noexcept
82 void DataSourceController::loadProductItem(const QUuid &dataSourceUid,
83 const DataSourceItem &productItem) noexcept
80 {
84 {
81 /// @todo ALX
85 if (productItem.type() == DataSourceItemType::PRODUCT) {
86 /// Retrieves the data provider of the data source (if any)
87 auto it = impl->m_DataProviders.find(dataSourceUid);
88 auto dataProvider = (it != impl->m_DataProviders.end()) ? it->second : nullptr;
89
90 /// @todo retrieve timerange, and pass it to the signal
91 emit variableCreationRequested(productItem.name(), dataProvider);
92 }
93 else {
94 qCWarning(LOG_DataSourceController()) << tr("Can't load an item that is not a product");
95 }
82 }
96 }
83
97
84 void DataSourceController::initialize()
98 void DataSourceController::initialize()
85 {
99 {
86 qCDebug(LOG_DataSourceController()) << tr("DataSourceController init")
100 qCDebug(LOG_DataSourceController()) << tr("DataSourceController init")
87 << QThread::currentThread();
101 << QThread::currentThread();
88 impl->m_WorkingMutex.lock();
102 impl->m_WorkingMutex.lock();
89 qCDebug(LOG_DataSourceController()) << tr("DataSourceController init END");
103 qCDebug(LOG_DataSourceController()) << tr("DataSourceController init END");
90 }
104 }
91
105
92 void DataSourceController::finalize()
106 void DataSourceController::finalize()
93 {
107 {
94 impl->m_WorkingMutex.unlock();
108 impl->m_WorkingMutex.unlock();
95 }
109 }
96
110
97 void DataSourceController::waitForFinish()
111 void DataSourceController::waitForFinish()
98 {
112 {
99 QMutexLocker locker{&impl->m_WorkingMutex};
113 QMutexLocker locker{&impl->m_WorkingMutex};
100 }
114 }
@@ -1,86 +1,86
1 #include <DataSource/DataSourceItem.h>
1 #include <DataSource/DataSourceItem.h>
2 #include <DataSource/DataSourceItemAction.h>
2 #include <DataSource/DataSourceItemAction.h>
3
3
4 #include <QVector>
4 #include <QVector>
5
5
6 namespace {
6 namespace {
7
7
8 /// Index of the 'name' value in the item
8 /// Index of the 'name' value in the item
9 const auto NAME_INDEX = 0;
9 const auto NAME_INDEX = 0;
10
10
11 } // namespace
11 } // namespace
12
12
13 struct DataSourceItem::DataSourceItemPrivate {
13 struct DataSourceItem::DataSourceItemPrivate {
14 explicit DataSourceItemPrivate(DataSourceItemType type, QVector<QVariant> data)
14 explicit DataSourceItemPrivate(DataSourceItemType type, QVector<QVariant> data)
15 : m_Parent{nullptr}, m_Children{}, m_Type{type}, m_Data{std::move(data)}, m_Actions{}
15 : m_Parent{nullptr}, m_Children{}, m_Type{type}, m_Data{std::move(data)}, m_Actions{}
16 {
16 {
17 }
17 }
18
18
19 DataSourceItem *m_Parent;
19 DataSourceItem *m_Parent;
20 std::vector<std::unique_ptr<DataSourceItem> > m_Children;
20 std::vector<std::unique_ptr<DataSourceItem> > m_Children;
21 DataSourceItemType m_Type;
21 DataSourceItemType m_Type;
22 QVector<QVariant> m_Data;
22 QVector<QVariant> m_Data;
23 std::vector<std::unique_ptr<DataSourceItemAction> > m_Actions;
23 std::vector<std::unique_ptr<DataSourceItemAction> > m_Actions;
24 };
24 };
25
25
26 DataSourceItem::DataSourceItem(DataSourceItemType type, QVector<QVariant> data)
26 DataSourceItem::DataSourceItem(DataSourceItemType type, QVector<QVariant> data)
27 : impl{spimpl::make_unique_impl<DataSourceItemPrivate>(type, std::move(data))}
27 : impl{spimpl::make_unique_impl<DataSourceItemPrivate>(type, std::move(data))}
28 {
28 {
29 }
29 }
30
30
31 QVector<DataSourceItemAction *> DataSourceItem::actions() const noexcept
31 QVector<DataSourceItemAction *> DataSourceItem::actions() const noexcept
32 {
32 {
33 QVector<DataSourceItemAction *> result{};
33 auto result = QVector<DataSourceItemAction *>{};
34
34
35 std::transform(std::cbegin(impl->m_Actions), std::cend(impl->m_Actions),
35 std::transform(std::cbegin(impl->m_Actions), std::cend(impl->m_Actions),
36 std::back_inserter(result), [](const auto &action) { return action.get(); });
36 std::back_inserter(result), [](const auto &action) { return action.get(); });
37
37
38 return result;
38 return result;
39 }
39 }
40
40
41 void DataSourceItem::addAction(std::unique_ptr<DataSourceItemAction> action) noexcept
41 void DataSourceItem::addAction(std::unique_ptr<DataSourceItemAction> action) noexcept
42 {
42 {
43 action->setDataSourceItem(this);
43 action->setDataSourceItem(this);
44 impl->m_Actions.push_back(std::move(action));
44 impl->m_Actions.push_back(std::move(action));
45 }
45 }
46
46
47 void DataSourceItem::appendChild(std::unique_ptr<DataSourceItem> child) noexcept
47 void DataSourceItem::appendChild(std::unique_ptr<DataSourceItem> child) noexcept
48 {
48 {
49 child->impl->m_Parent = this;
49 child->impl->m_Parent = this;
50 impl->m_Children.push_back(std::move(child));
50 impl->m_Children.push_back(std::move(child));
51 }
51 }
52
52
53 DataSourceItem *DataSourceItem::child(int childIndex) const noexcept
53 DataSourceItem *DataSourceItem::child(int childIndex) const noexcept
54 {
54 {
55 if (childIndex < 0 || childIndex >= childCount()) {
55 if (childIndex < 0 || childIndex >= childCount()) {
56 return nullptr;
56 return nullptr;
57 }
57 }
58 else {
58 else {
59 return impl->m_Children.at(childIndex).get();
59 return impl->m_Children.at(childIndex).get();
60 }
60 }
61 }
61 }
62
62
63 int DataSourceItem::childCount() const noexcept
63 int DataSourceItem::childCount() const noexcept
64 {
64 {
65 return impl->m_Children.size();
65 return impl->m_Children.size();
66 }
66 }
67
67
68 QVariant DataSourceItem::data(int dataIndex) const noexcept
68 QVariant DataSourceItem::data(int dataIndex) const noexcept
69 {
69 {
70 return impl->m_Data.value(dataIndex);
70 return impl->m_Data.value(dataIndex);
71 }
71 }
72
72
73 QString DataSourceItem::name() const noexcept
73 QString DataSourceItem::name() const noexcept
74 {
74 {
75 return data(NAME_INDEX).toString();
75 return data(NAME_INDEX).toString();
76 }
76 }
77
77
78 DataSourceItem *DataSourceItem::parentItem() const noexcept
78 DataSourceItem *DataSourceItem::parentItem() const noexcept
79 {
79 {
80 return impl->m_Parent;
80 return impl->m_Parent;
81 }
81 }
82
82
83 DataSourceItemType DataSourceItem::type() const noexcept
83 DataSourceItemType DataSourceItem::type() const noexcept
84 {
84 {
85 return impl->m_Type;
85 return impl->m_Type;
86 }
86 }
@@ -1,59 +1,91
1 #include <Variable/VariableController.h>
1 #include <Variable/VariableController.h>
2 #include <Variable/VariableModel.h>
2 #include <Variable/VariableModel.h>
3
3
4 #include <Data/DataProviderParameters.h>
5 #include <Data/IDataProvider.h>
6 #include <Data/IDataSeries.h>
7
8 #include <QDateTime>
4 #include <QMutex>
9 #include <QMutex>
5 #include <QThread>
10 #include <QThread>
6
11
7 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
12 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
8
13
14 namespace {
15
16 /// @todo Generates default dataseries, according to the provider passed in parameter. This method
17 /// will be deleted when the timerange is recovered from SciQlop
18 std::unique_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider) noexcept
19 {
20 auto parameters = DataProviderParameters{
21 // Remarks : we don't use toSecsSinceEpoch() here (method is for Qt 5.8 or above)
22 static_cast<double>(QDateTime{QDate{2017, 01, 01}, QTime{12, 00}}.toMSecsSinceEpoch()
23 / 1000.),
24 static_cast<double>(QDateTime{QDate{2017, 01, 01}, QTime{12, 01}}.toMSecsSinceEpoch())
25 / 1000.};
26
27 return provider.retrieveData(parameters);
28 }
29
30 } // namespace
31
9 struct VariableController::VariableControllerPrivate {
32 struct VariableController::VariableControllerPrivate {
10 explicit VariableControllerPrivate(VariableController *parent)
33 explicit VariableControllerPrivate(VariableController *parent)
11 : m_WorkingMutex{}, m_VariableModel{new VariableModel{parent}}
34 : m_WorkingMutex{}, m_VariableModel{new VariableModel{parent}}
12 {
35 {
13 }
36 }
14
37
15 QMutex m_WorkingMutex;
38 QMutex m_WorkingMutex;
16 /// Variable model. The VariableController has the ownership
39 /// Variable model. The VariableController has the ownership
17 VariableModel *m_VariableModel;
40 VariableModel *m_VariableModel;
18 };
41 };
19
42
20 VariableController::VariableController(QObject *parent)
43 VariableController::VariableController(QObject *parent)
21 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
44 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
22 {
45 {
23 qCDebug(LOG_VariableController()) << tr("VariableController construction")
46 qCDebug(LOG_VariableController()) << tr("VariableController construction")
24 << QThread::currentThread();
47 << QThread::currentThread();
25 }
48 }
26
49
27 VariableController::~VariableController()
50 VariableController::~VariableController()
28 {
51 {
29 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
52 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
30 << QThread::currentThread();
53 << QThread::currentThread();
31 this->waitForFinish();
54 this->waitForFinish();
32 }
55 }
33
56
34 Variable *VariableController::createVariable(const QString &name) noexcept
57 VariableModel *VariableController::variableModel() noexcept
35 {
58 {
36 return impl->m_VariableModel->createVariable(name);
59 return impl->m_VariableModel;
37 }
60 }
38
61
39 VariableModel *VariableController::variableModel() noexcept
62 void VariableController::createVariable(const QString &name,
63 std::shared_ptr<IDataProvider> provider) noexcept
40 {
64 {
41 return impl->m_VariableModel;
65 /// @todo : for the moment :
66 /// - the provider is only used to retrieve data from the variable for its initialization, but
67 /// it will be retained later
68 /// - default data are generated for the variable, without taking into account the timerange set
69 /// in sciqlop
70 if (auto newVariable
71 = impl->m_VariableModel->createVariable(name, generateDefaultDataSeries(*provider))) {
72 emit variableCreated(newVariable);
73 }
42 }
74 }
43
75
44 void VariableController::initialize()
76 void VariableController::initialize()
45 {
77 {
46 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
78 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
47 impl->m_WorkingMutex.lock();
79 impl->m_WorkingMutex.lock();
48 qCDebug(LOG_VariableController()) << tr("VariableController init END");
80 qCDebug(LOG_VariableController()) << tr("VariableController init END");
49 }
81 }
50
82
51 void VariableController::finalize()
83 void VariableController::finalize()
52 {
84 {
53 impl->m_WorkingMutex.unlock();
85 impl->m_WorkingMutex.unlock();
54 }
86 }
55
87
56 void VariableController::waitForFinish()
88 void VariableController::waitForFinish()
57 {
89 {
58 QMutexLocker locker{&impl->m_WorkingMutex};
90 QMutexLocker locker{&impl->m_WorkingMutex};
59 }
91 }
@@ -1,115 +1,120
1 #include <Variable/Variable.h>
1 #include <Variable/VariableModel.h>
2 #include <Variable/VariableModel.h>
2
3
3 #include <Variable/Variable.h>
4 #include <Data/IDataSeries.h>
4
5
5 Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
6 Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
6
7
7 namespace {
8 namespace {
8
9
9 // Column indexes
10 // Column indexes
10 const auto NAME_COLUMN = 0;
11 const auto NAME_COLUMN = 0;
11 const auto UNIT_COLUMN = 1;
12 const auto UNIT_COLUMN = 1;
12 const auto MISSION_COLUMN = 2;
13 const auto MISSION_COLUMN = 2;
13 const auto NB_COLUMNS = 3;
14 const auto NB_COLUMNS = 3;
14
15
15 } // namespace
16 } // namespace
16
17
17 struct VariableModel::VariableModelPrivate {
18 struct VariableModel::VariableModelPrivate {
18 /// Variables created in SciQlop
19 /// Variables created in SciQlop
19 std::vector<std::unique_ptr<Variable> > m_Variables;
20 std::vector<std::shared_ptr<Variable> > m_Variables;
20 };
21 };
21
22
22 VariableModel::VariableModel(QObject *parent)
23 VariableModel::VariableModel(QObject *parent)
23 : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()}
24 : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()}
24 {
25 {
25 }
26 }
26
27
27 Variable *VariableModel::createVariable(const QString &name) noexcept
28 std::shared_ptr<Variable>
29 VariableModel::createVariable(const QString &name,
30 std::unique_ptr<IDataSeries> defaultDataSeries) noexcept
28 {
31 {
29 auto insertIndex = rowCount();
32 auto insertIndex = rowCount();
30 beginInsertRows({}, insertIndex, insertIndex);
33 beginInsertRows({}, insertIndex, insertIndex);
31
34
32 /// @todo For the moment, the other data of the variable is initialized with default values
35 /// @todo For the moment, the other data of the variable is initialized with default values
33 auto variable
36 auto variable
34 = std::make_unique<Variable>(name, QStringLiteral("unit"), QStringLiteral("mission"));
37 = std::make_shared<Variable>(name, QStringLiteral("unit"), QStringLiteral("mission"));
35 impl->m_Variables.push_back(std::move(variable));
38 variable->addDataSeries(std::move(defaultDataSeries));
39
40 impl->m_Variables.push_back(variable);
36
41
37 endInsertRows();
42 endInsertRows();
38
43
39 return impl->m_Variables.at(insertIndex).get();
44 return variable;
40 }
45 }
41
46
42 int VariableModel::columnCount(const QModelIndex &parent) const
47 int VariableModel::columnCount(const QModelIndex &parent) const
43 {
48 {
44 Q_UNUSED(parent);
49 Q_UNUSED(parent);
45
50
46 return NB_COLUMNS;
51 return NB_COLUMNS;
47 }
52 }
48
53
49 int VariableModel::rowCount(const QModelIndex &parent) const
54 int VariableModel::rowCount(const QModelIndex &parent) const
50 {
55 {
51 Q_UNUSED(parent);
56 Q_UNUSED(parent);
52
57
53 return impl->m_Variables.size();
58 return impl->m_Variables.size();
54 }
59 }
55
60
56 QVariant VariableModel::data(const QModelIndex &index, int role) const
61 QVariant VariableModel::data(const QModelIndex &index, int role) const
57 {
62 {
58 if (!index.isValid()) {
63 if (!index.isValid()) {
59 return QVariant{};
64 return QVariant{};
60 }
65 }
61
66
62 if (index.row() < 0 || index.row() >= rowCount()) {
67 if (index.row() < 0 || index.row() >= rowCount()) {
63 return QVariant{};
68 return QVariant{};
64 }
69 }
65
70
66 if (role == Qt::DisplayRole) {
71 if (role == Qt::DisplayRole) {
67 if (auto variable = impl->m_Variables.at(index.row()).get()) {
72 if (auto variable = impl->m_Variables.at(index.row()).get()) {
68 switch (index.column()) {
73 switch (index.column()) {
69 case NAME_COLUMN:
74 case NAME_COLUMN:
70 return variable->m_Name;
75 return variable->name();
71 case UNIT_COLUMN:
76 case UNIT_COLUMN:
72 return variable->m_Unit;
77 return variable->unit();
73 case MISSION_COLUMN:
78 case MISSION_COLUMN:
74 return variable->m_Mission;
79 return variable->mission();
75 default:
80 default:
76 // No action
81 // No action
77 break;
82 break;
78 }
83 }
79
84
80 qWarning(LOG_VariableModel())
85 qWarning(LOG_VariableModel())
81 << tr("Can't get data (unknown column %1)").arg(index.column());
86 << tr("Can't get data (unknown column %1)").arg(index.column());
82 }
87 }
83 else {
88 else {
84 qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)");
89 qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)");
85 }
90 }
86 }
91 }
87
92
88 return QVariant{};
93 return QVariant{};
89 }
94 }
90
95
91 QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const
96 QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const
92 {
97 {
93 if (role != Qt::DisplayRole) {
98 if (role != Qt::DisplayRole) {
94 return QVariant{};
99 return QVariant{};
95 }
100 }
96
101
97 if (orientation == Qt::Horizontal) {
102 if (orientation == Qt::Horizontal) {
98 switch (section) {
103 switch (section) {
99 case NAME_COLUMN:
104 case NAME_COLUMN:
100 return tr("Name");
105 return tr("Name");
101 case UNIT_COLUMN:
106 case UNIT_COLUMN:
102 return tr("Unit");
107 return tr("Unit");
103 case MISSION_COLUMN:
108 case MISSION_COLUMN:
104 return tr("Mission");
109 return tr("Mission");
105 default:
110 default:
106 // No action
111 // No action
107 break;
112 break;
108 }
113 }
109
114
110 qWarning(LOG_VariableModel())
115 qWarning(LOG_VariableModel())
111 << tr("Can't get header data (unknown column %1)").arg(section);
116 << tr("Can't get header data (unknown column %1)").arg(section);
112 }
117 }
113
118
114 return QVariant{};
119 return QVariant{};
115 }
120 }
@@ -1,46 +1,54
1 #include <Visualization/VisualizationController.h>
1 #include <Visualization/VisualizationController.h>
2
2
3 #include <Variable/Variable.h>
4
3 #include <QMutex>
5 #include <QMutex>
4 #include <QThread>
6 #include <QThread>
5
7
6 #include <QDir>
8 #include <QDir>
7 #include <QStandardPaths>
9 #include <QStandardPaths>
8
10
9 Q_LOGGING_CATEGORY(LOG_VisualizationController, "VisualizationController")
11 Q_LOGGING_CATEGORY(LOG_VisualizationController, "VisualizationController")
10
12
11 class VisualizationController::VisualizationControllerPrivate {
13 class VisualizationController::VisualizationControllerPrivate {
12 public:
14 public:
13 QMutex m_WorkingMutex;
15 QMutex m_WorkingMutex;
14 };
16 };
15
17
16 VisualizationController::VisualizationController(QObject *parent)
18 VisualizationController::VisualizationController(QObject *parent)
17 : impl{spimpl::make_unique_impl<VisualizationControllerPrivate>()}
19 : impl{spimpl::make_unique_impl<VisualizationControllerPrivate>()}
18 {
20 {
19 qCDebug(LOG_VisualizationController()) << tr("VisualizationController construction")
21 qCDebug(LOG_VisualizationController()) << tr("VisualizationController construction")
20 << QThread::currentThread();
22 << QThread::currentThread();
21 }
23 }
22
24
23 VisualizationController::~VisualizationController()
25 VisualizationController::~VisualizationController()
24 {
26 {
25 qCDebug(LOG_VisualizationController()) << tr("VisualizationController destruction")
27 qCDebug(LOG_VisualizationController()) << tr("VisualizationController destruction")
26 << QThread::currentThread();
28 << QThread::currentThread();
27 this->waitForFinish();
29 this->waitForFinish();
28 }
30 }
29
31
32 void VisualizationController::onVariableCreated(std::shared_ptr<Variable> variable) noexcept
33 {
34 /// @todo ALX : make new graph for the variable
35 qCDebug(LOG_VisualizationController()) << "new variable to display";
36 }
37
30 void VisualizationController::initialize()
38 void VisualizationController::initialize()
31 {
39 {
32 qCDebug(LOG_VisualizationController()) << tr("VisualizationController init")
40 qCDebug(LOG_VisualizationController()) << tr("VisualizationController init")
33 << QThread::currentThread();
41 << QThread::currentThread();
34 impl->m_WorkingMutex.lock();
42 impl->m_WorkingMutex.lock();
35 qCDebug(LOG_VisualizationController()) << tr("VisualizationController init END");
43 qCDebug(LOG_VisualizationController()) << tr("VisualizationController init END");
36 }
44 }
37
45
38 void VisualizationController::finalize()
46 void VisualizationController::finalize()
39 {
47 {
40 impl->m_WorkingMutex.unlock();
48 impl->m_WorkingMutex.unlock();
41 }
49 }
42
50
43 void VisualizationController::waitForFinish()
51 void VisualizationController::waitForFinish()
44 {
52 {
45 QMutexLocker locker{&impl->m_WorkingMutex};
53 QMutexLocker locker{&impl->m_WorkingMutex};
46 }
54 }
@@ -1,13 +1,16
1 # On ignore toutes les règles vera++ pour le fichier spimpl
1 # On ignore toutes les règles vera++ pour le fichier spimpl
2 Common/spimpl\.h:\d+:.*
2 Common/spimpl\.h:\d+:.*
3
3
4 # Ignore false positive relative to two class definitions in a same file
4 # Ignore false positive relative to two class definitions in a same file
5 DataSourceItem\.h:\d+:.*IPSIS_S01.*
5 DataSourceItem\.h:\d+:.*IPSIS_S01.*
6
6
7 # Ignore false positive relative to a template class
7 # Ignore false positive relative to a template class
8 ArrayData\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (D)
8 ArrayData\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (D)
9 ArrayData\.h:\d+:.*IPSIS_S06.*found: (D)
9 ArrayData\.h:\d+:.*IPSIS_S06.*found: (D)
10 ArrayData\.h:\d+:.*IPSIS_S06.*found: (Dim)
10 ArrayData\.h:\d+:.*IPSIS_S06.*found: (Dim)
11
11
12 # Ignore false positive relative to an alias
12 # Ignore false positive relative to an alias
13 DataSourceItemAction\.h:\d+:.*IPSIS_S06.*found: (ExecuteFunction)
13 DataSourceItemAction\.h:\d+:.*IPSIS_S06.*found: (ExecuteFunction)
14
15 # Ignore false positive relative to unnamed namespace
16 VariableController\.cpp:\d+:.*IPSIS_F13.*
@@ -1,91 +1,109
1 #include "SqpApplication.h"
1 #include "SqpApplication.h"
2
2
3 #include <Data/IDataProvider.h>
3 #include <DataSource/DataSourceController.h>
4 #include <DataSource/DataSourceController.h>
4 #include <QThread>
5 #include <QThread>
6 #include <Variable/Variable.h>
5 #include <Variable/VariableController.h>
7 #include <Variable/VariableController.h>
6 #include <Visualization/VisualizationController.h>
8 #include <Visualization/VisualizationController.h>
7
9
8 Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication")
10 Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication")
9
11
10 class SqpApplication::SqpApplicationPrivate {
12 class SqpApplication::SqpApplicationPrivate {
11 public:
13 public:
12 SqpApplicationPrivate()
14 SqpApplicationPrivate()
13 : m_DataSourceController{std::make_unique<DataSourceController>()},
15 : m_DataSourceController{std::make_unique<DataSourceController>()},
14 m_VariableController{std::make_unique<VariableController>()},
16 m_VariableController{std::make_unique<VariableController>()},
15 m_VisualizationController{std::make_unique<VisualizationController>()}
17 m_VisualizationController{std::make_unique<VisualizationController>()}
16 {
18 {
19 // /////////////////////////////// //
20 // Connections between controllers //
21 // /////////////////////////////// //
22
23 // VariableController <-> DataSourceController
24 qRegisterMetaType<std::shared_ptr<IDataProvider> >();
25 connect(m_DataSourceController.get(),
26 SIGNAL(variableCreationRequested(const QString &, std::shared_ptr<IDataProvider>)),
27 m_VariableController.get(),
28 SLOT(createVariable(const QString &, std::shared_ptr<IDataProvider>)));
29
30 // VariableController <-> VisualizationController
31 qRegisterMetaType<std::shared_ptr<Variable> >();
32 connect(m_VariableController.get(), SIGNAL(variableCreated(std::shared_ptr<Variable>)),
33 m_VisualizationController.get(),
34 SLOT(onVariableCreated(std::shared_ptr<Variable>)));
35
17 m_DataSourceController->moveToThread(&m_DataSourceControllerThread);
36 m_DataSourceController->moveToThread(&m_DataSourceControllerThread);
18 m_VariableController->moveToThread(&m_VariableControllerThread);
37 m_VariableController->moveToThread(&m_VariableControllerThread);
19 m_VisualizationController->moveToThread(&m_VisualizationControllerThread);
38 m_VisualizationController->moveToThread(&m_VisualizationControllerThread);
20 }
39 }
21
40
22 virtual ~SqpApplicationPrivate()
41 virtual ~SqpApplicationPrivate()
23 {
42 {
24 qCInfo(LOG_SqpApplication()) << tr("SqpApplicationPrivate destruction");
43 qCInfo(LOG_SqpApplication()) << tr("SqpApplicationPrivate destruction");
25 m_DataSourceControllerThread.quit();
44 m_DataSourceControllerThread.quit();
26 m_DataSourceControllerThread.wait();
45 m_DataSourceControllerThread.wait();
27
46
28 m_VariableControllerThread.quit();
47 m_VariableControllerThread.quit();
29 m_VariableControllerThread.wait();
48 m_VariableControllerThread.wait();
30
49
31 m_VisualizationControllerThread.quit();
50 m_VisualizationControllerThread.quit();
32 m_VisualizationControllerThread.wait();
51 m_VisualizationControllerThread.wait();
33 }
52 }
34
53
35 std::unique_ptr<DataSourceController> m_DataSourceController;
54 std::unique_ptr<DataSourceController> m_DataSourceController;
36 std::unique_ptr<VariableController> m_VariableController;
55 std::unique_ptr<VariableController> m_VariableController;
37 std::unique_ptr<VisualizationController> m_VisualizationController;
56 std::unique_ptr<VisualizationController> m_VisualizationController;
38 QThread m_DataSourceControllerThread;
57 QThread m_DataSourceControllerThread;
39 QThread m_VariableControllerThread;
58 QThread m_VariableControllerThread;
40 QThread m_VisualizationControllerThread;
59 QThread m_VisualizationControllerThread;
41 };
60 };
42
61
43
62
44 SqpApplication::SqpApplication(int &argc, char **argv)
63 SqpApplication::SqpApplication(int &argc, char **argv)
45 : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()}
64 : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()}
46 {
65 {
47 qCInfo(LOG_SqpApplication()) << tr("SqpApplication construction");
66 qCInfo(LOG_SqpApplication()) << tr("SqpApplication construction");
48
67
49 connect(&impl->m_DataSourceControllerThread, &QThread::started,
68 connect(&impl->m_DataSourceControllerThread, &QThread::started,
50 impl->m_DataSourceController.get(), &DataSourceController::initialize);
69 impl->m_DataSourceController.get(), &DataSourceController::initialize);
51 connect(&impl->m_DataSourceControllerThread, &QThread::finished,
70 connect(&impl->m_DataSourceControllerThread, &QThread::finished,
52 impl->m_DataSourceController.get(), &DataSourceController::finalize);
71 impl->m_DataSourceController.get(), &DataSourceController::finalize);
53
72
54 connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(),
73 connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(),
55 &VariableController::initialize);
74 &VariableController::initialize);
56 connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(),
75 connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(),
57 &VariableController::finalize);
76 &VariableController::finalize);
58
77
59 connect(&impl->m_VisualizationControllerThread, &QThread::started,
78 connect(&impl->m_VisualizationControllerThread, &QThread::started,
60 impl->m_VisualizationController.get(), &VisualizationController::initialize);
79 impl->m_VisualizationController.get(), &VisualizationController::initialize);
61 connect(&impl->m_VisualizationControllerThread, &QThread::finished,
80 connect(&impl->m_VisualizationControllerThread, &QThread::finished,
62 impl->m_VisualizationController.get(), &VisualizationController::finalize);
81 impl->m_VisualizationController.get(), &VisualizationController::finalize);
63
82
64
65 impl->m_DataSourceControllerThread.start();
83 impl->m_DataSourceControllerThread.start();
66 impl->m_VariableControllerThread.start();
84 impl->m_VariableControllerThread.start();
67 impl->m_VisualizationControllerThread.start();
85 impl->m_VisualizationControllerThread.start();
68 }
86 }
69
87
70 SqpApplication::~SqpApplication()
88 SqpApplication::~SqpApplication()
71 {
89 {
72 }
90 }
73
91
74 void SqpApplication::initialize()
92 void SqpApplication::initialize()
75 {
93 {
76 }
94 }
77
95
78 DataSourceController &SqpApplication::dataSourceController() noexcept
96 DataSourceController &SqpApplication::dataSourceController() noexcept
79 {
97 {
80 return *impl->m_DataSourceController;
98 return *impl->m_DataSourceController;
81 }
99 }
82
100
83 VariableController &SqpApplication::variableController() noexcept
101 VariableController &SqpApplication::variableController() noexcept
84 {
102 {
85 return *impl->m_VariableController;
103 return *impl->m_VariableController;
86 }
104 }
87
105
88 VisualizationController &SqpApplication::visualizationController() noexcept
106 VisualizationController &SqpApplication::visualizationController() noexcept
89 {
107 {
90 return *impl->m_VisualizationController;
108 return *impl->m_VisualizationController;
91 }
109 }
@@ -1,79 +1,81
1 #include "MockPlugin.h"
1 #include "MockPlugin.h"
2 #include "CosinusProvider.h"
2 #include "CosinusProvider.h"
3
3
4 #include <DataSource/DataSourceController.h>
4 #include <DataSource/DataSourceController.h>
5 #include <DataSource/DataSourceItem.h>
5 #include <DataSource/DataSourceItem.h>
6 #include <DataSource/DataSourceItemAction.h>
6 #include <DataSource/DataSourceItemAction.h>
7
7
8 #include <SqpApplication.h>
8 #include <SqpApplication.h>
9
9
10 Q_LOGGING_CATEGORY(LOG_MockPlugin, "MockPlugin")
10 Q_LOGGING_CATEGORY(LOG_MockPlugin, "MockPlugin")
11
11
12 namespace {
12 namespace {
13
13
14 /// Name of the data source
14 /// Name of the data source
15 const auto DATA_SOURCE_NAME = QStringLiteral("MMS");
15 const auto DATA_SOURCE_NAME = QStringLiteral("MMS");
16
16
17 /// Creates the data provider relative to the plugin
17 /// Creates the data provider relative to the plugin
18 std::unique_ptr<IDataProvider> createDataProvider() noexcept
18 std::unique_ptr<IDataProvider> createDataProvider() noexcept
19 {
19 {
20 return std::make_unique<CosinusProvider>();
20 return std::make_unique<CosinusProvider>();
21 }
21 }
22
22
23 std::unique_ptr<DataSourceItem> createProductItem(const QString &productName)
23 std::unique_ptr<DataSourceItem> createProductItem(const QString &productName,
24 const QUuid &dataSourceUid)
24 {
25 {
25 auto result = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT,
26 auto result = std::make_unique<DataSourceItem>(DataSourceItemType::PRODUCT,
26 QVector<QVariant>{productName});
27 QVector<QVariant>{productName});
27
28
28 // Add action to load product from DataSourceController
29 // Add action to load product from DataSourceController
29 result->addAction(std::make_unique<DataSourceItemAction>(
30 result->addAction(std::make_unique<DataSourceItemAction>(
30 QObject::tr("Load %1 product").arg(productName), [productName](DataSourceItem &item) {
31 QObject::tr("Load %1 product").arg(productName),
32 [productName, dataSourceUid](DataSourceItem &item) {
31 if (auto app = sqpApp) {
33 if (auto app = sqpApp) {
32 app->dataSourceController().loadProductItem(item);
34 app->dataSourceController().loadProductItem(dataSourceUid, item);
33 }
35 }
34 }));
36 }));
35
37
36 return result;
38 return result;
37 }
39 }
38
40
39 /// Creates the data source item relative to the plugin
41 /// Creates the data source item relative to the plugin
40 std::unique_ptr<DataSourceItem> createDataSourceItem() noexcept
42 std::unique_ptr<DataSourceItem> createDataSourceItem(const QUuid &dataSourceUid) noexcept
41 {
43 {
42 // Magnetic field products
44 // Magnetic field products
43 auto magneticFieldFolder = std::make_unique<DataSourceItem>(
45 auto magneticFieldFolder = std::make_unique<DataSourceItem>(
44 DataSourceItemType::NODE, QVector<QVariant>{QStringLiteral("Magnetic field")});
46 DataSourceItemType::NODE, QVector<QVariant>{QStringLiteral("Magnetic field")});
45 magneticFieldFolder->appendChild(createProductItem(QStringLiteral("FGM")));
47 magneticFieldFolder->appendChild(createProductItem(QStringLiteral("FGM"), dataSourceUid));
46 magneticFieldFolder->appendChild(createProductItem(QStringLiteral("SC")));
48 magneticFieldFolder->appendChild(createProductItem(QStringLiteral("SC"), dataSourceUid));
47
49
48 // Electric field products
50 // Electric field products
49 auto electricFieldFolder = std::make_unique<DataSourceItem>(
51 auto electricFieldFolder = std::make_unique<DataSourceItem>(
50 DataSourceItemType::NODE, QVector<QVariant>{QStringLiteral("Electric field")});
52 DataSourceItemType::NODE, QVector<QVariant>{QStringLiteral("Electric field")});
51
53
52 // Root
54 // Root
53 auto root = std::make_unique<DataSourceItem>(DataSourceItemType::NODE,
55 auto root = std::make_unique<DataSourceItem>(DataSourceItemType::NODE,
54 QVector<QVariant>{DATA_SOURCE_NAME});
56 QVector<QVariant>{DATA_SOURCE_NAME});
55 root->appendChild(std::move(magneticFieldFolder));
57 root->appendChild(std::move(magneticFieldFolder));
56 root->appendChild(std::move(electricFieldFolder));
58 root->appendChild(std::move(electricFieldFolder));
57
59
58 return root;
60 return root;
59 }
61 }
60
62
61 } // namespace
63 } // namespace
62
64
63 void MockPlugin::initialize()
65 void MockPlugin::initialize()
64 {
66 {
65 if (auto app = sqpApp) {
67 if (auto app = sqpApp) {
66 // Registers to the data source controller
68 // Registers to the data source controller
67 auto &dataSourceController = app->dataSourceController();
69 auto &dataSourceController = app->dataSourceController();
68 auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME);
70 auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME);
69
71
70 // Sets data source tree
72 // Sets data source tree
71 dataSourceController.setDataSourceItem(dataSourceUid, createDataSourceItem());
73 dataSourceController.setDataSourceItem(dataSourceUid, createDataSourceItem(dataSourceUid));
72
74
73 // Sets data provider
75 // Sets data provider
74 dataSourceController.setDataProvider(dataSourceUid, createDataProvider());
76 dataSourceController.setDataProvider(dataSourceUid, createDataProvider());
75 }
77 }
76 else {
78 else {
77 qCWarning(LOG_MockPlugin()) << tr("Can't access to SciQlop application");
79 qCWarning(LOG_MockPlugin()) << tr("Can't access to SciQlop application");
78 }
80 }
79 }
81 }
General Comments 0
You need to be logged in to leave comments. Login now