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