@@ -1,90 +1,92 | |||||
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. It must be not null to be registered |
|
40 | * @param dataSourceItem the structure of the data source. It must be not null to be registered | |
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 |
|
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 |
|
60 | * the data provider associated to the data source, and pass it to for the variable creation | |
61 | * @param productItem the item to load |
|
61 | * @param productItem the item to load | |
62 | */ |
|
62 | */ | |
63 | void loadProductItem(const QUuid &dataSourceUid, const DataSourceItem &productItem) noexcept; |
|
63 | void loadProductItem(const QUuid &dataSourceUid, const DataSourceItem &productItem) noexcept; | |
64 |
|
64 | |||
65 | public slots: |
|
65 | public slots: | |
66 | /// Manage init/end of the controller |
|
66 | /// Manage init/end of the controller | |
67 | void initialize(); |
|
67 | void initialize(); | |
68 | void finalize(); |
|
68 | void finalize(); | |
69 |
|
69 | |||
70 | signals: |
|
70 | signals: | |
71 | /// 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 | |
72 | void dataSourceItemSet(DataSourceItem *dataSourceItem); |
|
72 | void dataSourceItemSet(DataSourceItem *dataSourceItem); | |
73 |
|
73 | |||
74 | /** |
|
74 | /** | |
75 | * Signal emitted when a variable creation is asked for a product |
|
75 | * Signal emitted when a variable creation is asked for a product | |
76 | * @param variableName the name of the variable |
|
76 | * @param variableName the name of the variable | |
|
77 | * @param variableMetadata the metadata of the variable | |||
77 | * @param variableProvider the provider that will be used to retrieve the data of the variable |
|
78 | * @param variableProvider the provider that will be used to retrieve the data of the variable | |
78 | * (can be null) |
|
79 | * (can be null) | |
79 | */ |
|
80 | */ | |
80 | void variableCreationRequested(const QString &variableName, |
|
81 | void variableCreationRequested(const QString &variableName, | |
|
82 | const QVariantHash &variableMetadata, | |||
81 | std::shared_ptr<IDataProvider> variableProvider); |
|
83 | std::shared_ptr<IDataProvider> variableProvider); | |
82 |
|
84 | |||
83 | private: |
|
85 | private: | |
84 | void waitForFinish(); |
|
86 | void waitForFinish(); | |
85 |
|
87 | |||
86 | class DataSourceControllerPrivate; |
|
88 | class DataSourceControllerPrivate; | |
87 | spimpl::unique_impl_ptr<DataSourceControllerPrivate> impl; |
|
89 | spimpl::unique_impl_ptr<DataSourceControllerPrivate> impl; | |
88 | }; |
|
90 | }; | |
89 |
|
91 | |||
90 | #endif // SCIQLOP_DATASOURCECONTROLLER_H |
|
92 | #endif // SCIQLOP_DATASOURCECONTROLLER_H |
@@ -1,83 +1,85 | |||||
1 | #ifndef SCIQLOP_VARIABLECONTROLLER_H |
|
1 | #ifndef SCIQLOP_VARIABLECONTROLLER_H | |
2 | #define SCIQLOP_VARIABLECONTROLLER_H |
|
2 | #define SCIQLOP_VARIABLECONTROLLER_H | |
3 |
|
3 | |||
4 | #include <Data/SqpDateTime.h> |
|
4 | #include <Data/SqpDateTime.h> | |
5 |
|
5 | |||
6 | #include <QLoggingCategory> |
|
6 | #include <QLoggingCategory> | |
7 | #include <QObject> |
|
7 | #include <QObject> | |
8 |
|
8 | |||
9 | #include <Common/spimpl.h> |
|
9 | #include <Common/spimpl.h> | |
10 |
|
10 | |||
11 | class IDataProvider; |
|
11 | class IDataProvider; | |
12 | class QItemSelectionModel; |
|
12 | class QItemSelectionModel; | |
13 | class TimeController; |
|
13 | class TimeController; | |
14 | class Variable; |
|
14 | class Variable; | |
15 | class VariableModel; |
|
15 | class VariableModel; | |
16 |
|
16 | |||
17 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController) |
|
17 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController) | |
18 |
|
18 | |||
19 | /** |
|
19 | /** | |
20 | * @brief The VariableController class aims to handle the variables in SciQlop. |
|
20 | * @brief The VariableController class aims to handle the variables in SciQlop. | |
21 | */ |
|
21 | */ | |
22 | class VariableController : public QObject { |
|
22 | class VariableController : public QObject { | |
23 | Q_OBJECT |
|
23 | Q_OBJECT | |
24 | public: |
|
24 | public: | |
25 | explicit VariableController(QObject *parent = 0); |
|
25 | explicit VariableController(QObject *parent = 0); | |
26 | virtual ~VariableController(); |
|
26 | virtual ~VariableController(); | |
27 |
|
27 | |||
28 | VariableModel *variableModel() noexcept; |
|
28 | VariableModel *variableModel() noexcept; | |
29 | QItemSelectionModel *variableSelectionModel() noexcept; |
|
29 | QItemSelectionModel *variableSelectionModel() noexcept; | |
30 |
|
30 | |||
31 | void setTimeController(TimeController *timeController) noexcept; |
|
31 | void setTimeController(TimeController *timeController) noexcept; | |
32 |
|
32 | |||
33 | /** |
|
33 | /** | |
34 | * Deletes from the controller the variable passed in parameter. |
|
34 | * Deletes from the controller the variable passed in parameter. | |
35 | * |
|
35 | * | |
36 | * Delete a variable includes: |
|
36 | * Delete a variable includes: | |
37 | * - the deletion of the various references to the variable in SciQlop |
|
37 | * - the deletion of the various references to the variable in SciQlop | |
38 | * - the deletion of the model variable |
|
38 | * - the deletion of the model variable | |
39 | * - the deletion of the provider associated with the variable |
|
39 | * - the deletion of the provider associated with the variable | |
40 | * - removing the cache associated with the variable |
|
40 | * - removing the cache associated with the variable | |
41 | * |
|
41 | * | |
42 | * @param variable the variable to delete from the controller. |
|
42 | * @param variable the variable to delete from the controller. | |
43 | */ |
|
43 | */ | |
44 | void deleteVariable(std::shared_ptr<Variable> variable) noexcept; |
|
44 | void deleteVariable(std::shared_ptr<Variable> variable) noexcept; | |
45 |
|
45 | |||
46 | /** |
|
46 | /** | |
47 | * Deletes from the controller the variables passed in parameter. |
|
47 | * Deletes from the controller the variables passed in parameter. | |
48 | * @param variables the variables to delete from the controller. |
|
48 | * @param variables the variables to delete from the controller. | |
49 | * @sa deleteVariable() |
|
49 | * @sa deleteVariable() | |
50 | */ |
|
50 | */ | |
51 | void deleteVariables(const QVector<std::shared_ptr<Variable> > &variables) noexcept; |
|
51 | void deleteVariables(const QVector<std::shared_ptr<Variable> > &variables) noexcept; | |
52 |
|
52 | |||
53 | signals: |
|
53 | signals: | |
54 | /// Signal emitted when a variable is about to be deleted from the controller |
|
54 | /// Signal emitted when a variable is about to be deleted from the controller | |
55 | void variableAboutToBeDeleted(std::shared_ptr<Variable> variable); |
|
55 | void variableAboutToBeDeleted(std::shared_ptr<Variable> variable); | |
56 |
|
56 | |||
57 | public slots: |
|
57 | public slots: | |
58 | /// Request the data loading of the variable whithin dateTime |
|
58 | /// Request the data loading of the variable whithin dateTime | |
59 | void onRequestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime); |
|
59 | void onRequestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime); | |
60 | /** |
|
60 | /** | |
61 | * Creates a new variable and adds it to the model |
|
61 | * Creates a new variable and adds it to the model | |
62 | * @param name the name of the new variable |
|
62 | * @param name the name of the new variable | |
|
63 | * @param metadata the metadata of the new variable | |||
63 | * @param provider the data provider for the new variable |
|
64 | * @param provider the data provider for the new variable | |
64 | */ |
|
65 | */ | |
65 |
void createVariable(const QString &name, st |
|
66 | void createVariable(const QString &name, const QVariantHash &metadata, | |
|
67 | std::shared_ptr<IDataProvider> provider) noexcept; | |||
66 |
|
68 | |||
67 | /// Update the temporal parameters of every selected variable to dateTime |
|
69 | /// Update the temporal parameters of every selected variable to dateTime | |
68 | void onDateTimeOnSelection(const SqpDateTime &dateTime); |
|
70 | void onDateTimeOnSelection(const SqpDateTime &dateTime); | |
69 |
|
71 | |||
70 |
|
72 | |||
71 | void onVariableRetrieveDataInProgress(QUuid identifier, double progress); |
|
73 | void onVariableRetrieveDataInProgress(QUuid identifier, double progress); | |
72 |
|
74 | |||
73 | void initialize(); |
|
75 | void initialize(); | |
74 | void finalize(); |
|
76 | void finalize(); | |
75 |
|
77 | |||
76 | private: |
|
78 | private: | |
77 | void waitForFinish(); |
|
79 | void waitForFinish(); | |
78 |
|
80 | |||
79 | class VariableControllerPrivate; |
|
81 | class VariableControllerPrivate; | |
80 | spimpl::unique_impl_ptr<VariableControllerPrivate> impl; |
|
82 | spimpl::unique_impl_ptr<VariableControllerPrivate> impl; | |
81 | }; |
|
83 | }; | |
82 |
|
84 | |||
83 | #endif // SCIQLOP_VARIABLECONTROLLER_H |
|
85 | #endif // SCIQLOP_VARIABLECONTROLLER_H |
@@ -1,70 +1,71 | |||||
1 | #ifndef SCIQLOP_VARIABLEMODEL_H |
|
1 | #ifndef SCIQLOP_VARIABLEMODEL_H | |
2 | #define SCIQLOP_VARIABLEMODEL_H |
|
2 | #define SCIQLOP_VARIABLEMODEL_H | |
3 |
|
3 | |||
4 |
|
4 | |||
5 | #include <Data/SqpDateTime.h> |
|
5 | #include <Data/SqpDateTime.h> | |
6 |
|
6 | |||
7 | #include <QAbstractTableModel> |
|
7 | #include <QAbstractTableModel> | |
8 | #include <QLoggingCategory> |
|
8 | #include <QLoggingCategory> | |
9 |
|
9 | |||
10 | #include <Common/MetaTypes.h> |
|
10 | #include <Common/MetaTypes.h> | |
11 | #include <Common/spimpl.h> |
|
11 | #include <Common/spimpl.h> | |
12 |
|
12 | |||
13 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel) |
|
13 | Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel) | |
14 |
|
14 | |||
15 | enum VariableRoles { ProgressRole = Qt::UserRole }; |
|
15 | enum VariableRoles { ProgressRole = Qt::UserRole }; | |
16 |
|
16 | |||
17 |
|
17 | |||
18 | class IDataSeries; |
|
18 | class IDataSeries; | |
19 | class Variable; |
|
19 | class Variable; | |
20 |
|
20 | |||
21 | /** |
|
21 | /** | |
22 | * @brief The VariableModel class aims to hold the variables that have been created in SciQlop |
|
22 | * @brief The VariableModel class aims to hold the variables that have been created in SciQlop | |
23 | */ |
|
23 | */ | |
24 | class VariableModel : public QAbstractTableModel { |
|
24 | class VariableModel : public QAbstractTableModel { | |
25 | public: |
|
25 | public: | |
26 | explicit VariableModel(QObject *parent = nullptr); |
|
26 | explicit VariableModel(QObject *parent = nullptr); | |
27 |
|
27 | |||
28 | /** |
|
28 | /** | |
29 | * Creates a new variable in the model |
|
29 | * Creates a new variable in the model | |
30 | * @param name the name of the new variable |
|
30 | * @param name the name of the new variable | |
31 | * @param dateTime the dateTime of the new variable |
|
31 | * @param dateTime the dateTime of the new variable | |
|
32 | * @param metadata the metadata associated to the new variable | |||
32 | * @return the pointer to the new variable |
|
33 | * @return the pointer to the new variable | |
33 | */ |
|
34 | */ | |
34 | std::shared_ptr<Variable> createVariable(const QString &name, |
|
35 | std::shared_ptr<Variable> createVariable(const QString &name, const SqpDateTime &dateTime, | |
35 |
const |
|
36 | const QVariantHash &metadata) noexcept; | |
36 |
|
37 | |||
37 | /** |
|
38 | /** | |
38 | * Deletes a variable from the model, if it exists |
|
39 | * Deletes a variable from the model, if it exists | |
39 | * @param variable the variable to delete |
|
40 | * @param variable the variable to delete | |
40 | */ |
|
41 | */ | |
41 | void deleteVariable(std::shared_ptr<Variable> variable) noexcept; |
|
42 | void deleteVariable(std::shared_ptr<Variable> variable) noexcept; | |
42 |
|
43 | |||
43 |
|
44 | |||
44 | std::shared_ptr<Variable> variable(int index) const; |
|
45 | std::shared_ptr<Variable> variable(int index) const; | |
45 |
|
46 | |||
46 | void setDataProgress(std::shared_ptr<Variable> variable, double progress); |
|
47 | void setDataProgress(std::shared_ptr<Variable> variable, double progress); | |
47 |
|
48 | |||
48 | // /////////////////////////// // |
|
49 | // /////////////////////////// // | |
49 | // QAbstractTableModel methods // |
|
50 | // QAbstractTableModel methods // | |
50 | // /////////////////////////// // |
|
51 | // /////////////////////////// // | |
51 |
|
52 | |||
52 | virtual int columnCount(const QModelIndex &parent = QModelIndex{}) const override; |
|
53 | virtual int columnCount(const QModelIndex &parent = QModelIndex{}) const override; | |
53 | virtual int rowCount(const QModelIndex &parent = QModelIndex{}) const override; |
|
54 | virtual int rowCount(const QModelIndex &parent = QModelIndex{}) const override; | |
54 | virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
|
55 | virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; | |
55 | virtual QVariant headerData(int section, Qt::Orientation orientation, |
|
56 | virtual QVariant headerData(int section, Qt::Orientation orientation, | |
56 | int role = Qt::DisplayRole) const override; |
|
57 | int role = Qt::DisplayRole) const override; | |
57 |
|
58 | |||
58 | private: |
|
59 | private: | |
59 | class VariableModelPrivate; |
|
60 | class VariableModelPrivate; | |
60 | spimpl::unique_impl_ptr<VariableModelPrivate> impl; |
|
61 | spimpl::unique_impl_ptr<VariableModelPrivate> impl; | |
61 |
|
62 | |||
62 | private slots: |
|
63 | private slots: | |
63 | /// Slot called when data of a variable has been updated |
|
64 | /// Slot called when data of a variable has been updated | |
64 | void onVariableUpdated() noexcept; |
|
65 | void onVariableUpdated() noexcept; | |
65 | }; |
|
66 | }; | |
66 |
|
67 | |||
67 | // Registers QVector<int> metatype so it can be used in VariableModel::dataChanged() signal |
|
68 | // Registers QVector<int> metatype so it can be used in VariableModel::dataChanged() signal | |
68 | SCIQLOP_REGISTER_META_TYPE(QVECTOR_INT_REGISTRY, QVector<int>) |
|
69 | SCIQLOP_REGISTER_META_TYPE(QVECTOR_INT_REGISTRY, QVector<int>) | |
69 |
|
70 | |||
70 | #endif // SCIQLOP_VARIABLEMODEL_H |
|
71 | #endif // SCIQLOP_VARIABLEMODEL_H |
@@ -1,120 +1,120 | |||||
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 | /// @remarks Data providers are stored as shared_ptr as they can be sent to a variable and |
|
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 |
|
23 | /// continue to live without necessarily the data source controller | |
24 | std::map<QUuid, std::shared_ptr<IDataProvider> > m_DataProviders; |
|
24 | std::map<QUuid, std::shared_ptr<IDataProvider> > m_DataProviders; | |
25 | }; |
|
25 | }; | |
26 |
|
26 | |||
27 | DataSourceController::DataSourceController(QObject *parent) |
|
27 | DataSourceController::DataSourceController(QObject *parent) | |
28 | : impl{spimpl::make_unique_impl<DataSourceControllerPrivate>()} |
|
28 | : impl{spimpl::make_unique_impl<DataSourceControllerPrivate>()} | |
29 | { |
|
29 | { | |
30 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController construction") |
|
30 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController construction") | |
31 | << QThread::currentThread(); |
|
31 | << QThread::currentThread(); | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | DataSourceController::~DataSourceController() |
|
34 | DataSourceController::~DataSourceController() | |
35 | { |
|
35 | { | |
36 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController destruction") |
|
36 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController destruction") | |
37 | << QThread::currentThread(); |
|
37 | << QThread::currentThread(); | |
38 | this->waitForFinish(); |
|
38 | this->waitForFinish(); | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | QUuid DataSourceController::registerDataSource(const QString &dataSourceName) noexcept |
|
41 | QUuid DataSourceController::registerDataSource(const QString &dataSourceName) noexcept | |
42 | { |
|
42 | { | |
43 | auto dataSourceUid = QUuid::createUuid(); |
|
43 | auto dataSourceUid = QUuid::createUuid(); | |
44 | impl->m_DataSources.insert(dataSourceUid, dataSourceName); |
|
44 | impl->m_DataSources.insert(dataSourceUid, dataSourceName); | |
45 |
|
45 | |||
46 | return dataSourceUid; |
|
46 | return dataSourceUid; | |
47 | } |
|
47 | } | |
48 |
|
48 | |||
49 | void DataSourceController::setDataSourceItem( |
|
49 | void DataSourceController::setDataSourceItem( | |
50 | const QUuid &dataSourceUid, std::unique_ptr<DataSourceItem> dataSourceItem) noexcept |
|
50 | const QUuid &dataSourceUid, std::unique_ptr<DataSourceItem> dataSourceItem) noexcept | |
51 | { |
|
51 | { | |
52 | if (!dataSourceItem) { |
|
52 | if (!dataSourceItem) { | |
53 | qCWarning(LOG_DataSourceController()) |
|
53 | qCWarning(LOG_DataSourceController()) | |
54 | << tr("Data source item can't be registered (null item)"); |
|
54 | << tr("Data source item can't be registered (null item)"); | |
55 | return; |
|
55 | return; | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | if (impl->m_DataSources.contains(dataSourceUid)) { |
|
58 | if (impl->m_DataSources.contains(dataSourceUid)) { | |
59 | // The data provider is implicitly converted to a shared_ptr |
|
59 | // The data provider is implicitly converted to a shared_ptr | |
60 | impl->m_DataSourceItems.insert(std::make_pair(dataSourceUid, std::move(dataSourceItem))); |
|
60 | impl->m_DataSourceItems.insert(std::make_pair(dataSourceUid, std::move(dataSourceItem))); | |
61 |
|
61 | |||
62 | // Retrieves the data source item to emit the signal with it |
|
62 | // Retrieves the data source item to emit the signal with it | |
63 | auto it = impl->m_DataSourceItems.find(dataSourceUid); |
|
63 | auto it = impl->m_DataSourceItems.find(dataSourceUid); | |
64 | if (it != impl->m_DataSourceItems.end()) { |
|
64 | if (it != impl->m_DataSourceItems.end()) { | |
65 | emit dataSourceItemSet(it->second.get()); |
|
65 | emit dataSourceItemSet(it->second.get()); | |
66 | } |
|
66 | } | |
67 | } |
|
67 | } | |
68 | else { |
|
68 | else { | |
69 | qCWarning(LOG_DataSourceController()) << tr("Can't set data source item for uid %1 : no " |
|
69 | qCWarning(LOG_DataSourceController()) << tr("Can't set data source item for uid %1 : no " | |
70 | "data source has been registered with the uid") |
|
70 | "data source has been registered with the uid") | |
71 | .arg(dataSourceUid.toString()); |
|
71 | .arg(dataSourceUid.toString()); | |
72 | } |
|
72 | } | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | void DataSourceController::setDataProvider(const QUuid &dataSourceUid, |
|
75 | void DataSourceController::setDataProvider(const QUuid &dataSourceUid, | |
76 | std::unique_ptr<IDataProvider> dataProvider) noexcept |
|
76 | std::unique_ptr<IDataProvider> dataProvider) noexcept | |
77 | { |
|
77 | { | |
78 | if (impl->m_DataSources.contains(dataSourceUid)) { |
|
78 | if (impl->m_DataSources.contains(dataSourceUid)) { | |
79 | impl->m_DataProviders.insert(std::make_pair(dataSourceUid, std::move(dataProvider))); |
|
79 | impl->m_DataProviders.insert(std::make_pair(dataSourceUid, std::move(dataProvider))); | |
80 | } |
|
80 | } | |
81 | else { |
|
81 | else { | |
82 | qCWarning(LOG_DataSourceController()) << tr("Can't set data provider for uid %1 : no data " |
|
82 | qCWarning(LOG_DataSourceController()) << tr("Can't set data provider for uid %1 : no data " | |
83 | "source has been registered with the uid") |
|
83 | "source has been registered with the uid") | |
84 | .arg(dataSourceUid.toString()); |
|
84 | .arg(dataSourceUid.toString()); | |
85 | } |
|
85 | } | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | void DataSourceController::loadProductItem(const QUuid &dataSourceUid, |
|
88 | void DataSourceController::loadProductItem(const QUuid &dataSourceUid, | |
89 | const DataSourceItem &productItem) noexcept |
|
89 | const DataSourceItem &productItem) noexcept | |
90 | { |
|
90 | { | |
91 | if (productItem.type() == DataSourceItemType::PRODUCT) { |
|
91 | if (productItem.type() == DataSourceItemType::PRODUCT) { | |
92 | /// Retrieves the data provider of the data source (if any) |
|
92 | /// Retrieves the data provider of the data source (if any) | |
93 | auto it = impl->m_DataProviders.find(dataSourceUid); |
|
93 | auto it = impl->m_DataProviders.find(dataSourceUid); | |
94 | auto dataProvider = (it != impl->m_DataProviders.end()) ? it->second : nullptr; |
|
94 | auto dataProvider = (it != impl->m_DataProviders.end()) ? it->second : nullptr; | |
95 |
|
95 | |||
96 | /// @todo retrieve timerange, and pass it to the signal |
|
96 | /// @todo retrieve timerange, and pass it to the signal | |
97 | emit variableCreationRequested(productItem.name(), dataProvider); |
|
97 | emit variableCreationRequested(productItem.name(), productItem.data(), dataProvider); | |
98 | } |
|
98 | } | |
99 | else { |
|
99 | else { | |
100 | qCWarning(LOG_DataSourceController()) << tr("Can't load an item that is not a product"); |
|
100 | qCWarning(LOG_DataSourceController()) << tr("Can't load an item that is not a product"); | |
101 | } |
|
101 | } | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | void DataSourceController::initialize() |
|
104 | void DataSourceController::initialize() | |
105 | { |
|
105 | { | |
106 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController init") |
|
106 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController init") | |
107 | << QThread::currentThread(); |
|
107 | << QThread::currentThread(); | |
108 | impl->m_WorkingMutex.lock(); |
|
108 | impl->m_WorkingMutex.lock(); | |
109 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController init END"); |
|
109 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController init END"); | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | void DataSourceController::finalize() |
|
112 | void DataSourceController::finalize() | |
113 | { |
|
113 | { | |
114 | impl->m_WorkingMutex.unlock(); |
|
114 | impl->m_WorkingMutex.unlock(); | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | void DataSourceController::waitForFinish() |
|
117 | void DataSourceController::waitForFinish() | |
118 | { |
|
118 | { | |
119 | QMutexLocker locker{&impl->m_WorkingMutex}; |
|
119 | QMutexLocker locker{&impl->m_WorkingMutex}; | |
120 | } |
|
120 | } |
@@ -1,216 +1,217 | |||||
1 | #include <Variable/Variable.h> |
|
1 | #include <Variable/Variable.h> | |
2 | #include <Variable/VariableCacheController.h> |
|
2 | #include <Variable/VariableCacheController.h> | |
3 | #include <Variable/VariableController.h> |
|
3 | #include <Variable/VariableController.h> | |
4 | #include <Variable/VariableModel.h> |
|
4 | #include <Variable/VariableModel.h> | |
5 |
|
5 | |||
6 | #include <Data/DataProviderParameters.h> |
|
6 | #include <Data/DataProviderParameters.h> | |
7 | #include <Data/IDataProvider.h> |
|
7 | #include <Data/IDataProvider.h> | |
8 | #include <Data/IDataSeries.h> |
|
8 | #include <Data/IDataSeries.h> | |
9 | #include <Time/TimeController.h> |
|
9 | #include <Time/TimeController.h> | |
10 |
|
10 | |||
11 | #include <QDateTime> |
|
11 | #include <QDateTime> | |
12 | #include <QMutex> |
|
12 | #include <QMutex> | |
13 | #include <QThread> |
|
13 | #include <QThread> | |
14 | #include <QUuid> |
|
14 | #include <QUuid> | |
15 | #include <QtCore/QItemSelectionModel> |
|
15 | #include <QtCore/QItemSelectionModel> | |
16 |
|
16 | |||
17 | #include <unordered_map> |
|
17 | #include <unordered_map> | |
18 |
|
18 | |||
19 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") |
|
19 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") | |
20 |
|
20 | |||
21 | struct VariableController::VariableControllerPrivate { |
|
21 | struct VariableController::VariableControllerPrivate { | |
22 | explicit VariableControllerPrivate(VariableController *parent) |
|
22 | explicit VariableControllerPrivate(VariableController *parent) | |
23 | : m_WorkingMutex{}, |
|
23 | : m_WorkingMutex{}, | |
24 | m_VariableModel{new VariableModel{parent}}, |
|
24 | m_VariableModel{new VariableModel{parent}}, | |
25 | m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}}, |
|
25 | m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}}, | |
26 | m_VariableCacheController{std::make_unique<VariableCacheController>()} |
|
26 | m_VariableCacheController{std::make_unique<VariableCacheController>()} | |
27 | { |
|
27 | { | |
28 | } |
|
28 | } | |
29 |
|
29 | |||
30 | QMutex m_WorkingMutex; |
|
30 | QMutex m_WorkingMutex; | |
31 | /// Variable model. The VariableController has the ownership |
|
31 | /// Variable model. The VariableController has the ownership | |
32 | VariableModel *m_VariableModel; |
|
32 | VariableModel *m_VariableModel; | |
33 | QItemSelectionModel *m_VariableSelectionModel; |
|
33 | QItemSelectionModel *m_VariableSelectionModel; | |
34 |
|
34 | |||
35 |
|
35 | |||
36 | TimeController *m_TimeController{nullptr}; |
|
36 | TimeController *m_TimeController{nullptr}; | |
37 | std::unique_ptr<VariableCacheController> m_VariableCacheController; |
|
37 | std::unique_ptr<VariableCacheController> m_VariableCacheController; | |
38 |
|
38 | |||
39 | std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > |
|
39 | std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > | |
40 | m_VariableToProviderMap; |
|
40 | m_VariableToProviderMap; | |
41 | std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifier; |
|
41 | std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifier; | |
42 | }; |
|
42 | }; | |
43 |
|
43 | |||
44 | VariableController::VariableController(QObject *parent) |
|
44 | VariableController::VariableController(QObject *parent) | |
45 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} |
|
45 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} | |
46 | { |
|
46 | { | |
47 | qCDebug(LOG_VariableController()) << tr("VariableController construction") |
|
47 | qCDebug(LOG_VariableController()) << tr("VariableController construction") | |
48 | << QThread::currentThread(); |
|
48 | << QThread::currentThread(); | |
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 | VariableController::~VariableController() |
|
51 | VariableController::~VariableController() | |
52 | { |
|
52 | { | |
53 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") |
|
53 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") | |
54 | << QThread::currentThread(); |
|
54 | << QThread::currentThread(); | |
55 | this->waitForFinish(); |
|
55 | this->waitForFinish(); | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | VariableModel *VariableController::variableModel() noexcept |
|
58 | VariableModel *VariableController::variableModel() noexcept | |
59 | { |
|
59 | { | |
60 | return impl->m_VariableModel; |
|
60 | return impl->m_VariableModel; | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | QItemSelectionModel *VariableController::variableSelectionModel() noexcept |
|
63 | QItemSelectionModel *VariableController::variableSelectionModel() noexcept | |
64 | { |
|
64 | { | |
65 | return impl->m_VariableSelectionModel; |
|
65 | return impl->m_VariableSelectionModel; | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | void VariableController::setTimeController(TimeController *timeController) noexcept |
|
68 | void VariableController::setTimeController(TimeController *timeController) noexcept | |
69 | { |
|
69 | { | |
70 | impl->m_TimeController = timeController; |
|
70 | impl->m_TimeController = timeController; | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept |
|
73 | void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept | |
74 | { |
|
74 | { | |
75 | if (!variable) { |
|
75 | if (!variable) { | |
76 | qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null"; |
|
76 | qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null"; | |
77 | return; |
|
77 | return; | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | // Spreads in SciQlop that the variable will be deleted, so that potential receivers can |
|
80 | // Spreads in SciQlop that the variable will be deleted, so that potential receivers can | |
81 | // make some treatments before the deletion |
|
81 | // make some treatments before the deletion | |
82 | emit variableAboutToBeDeleted(variable); |
|
82 | emit variableAboutToBeDeleted(variable); | |
83 |
|
83 | |||
84 | // Deletes provider |
|
84 | // Deletes provider | |
85 | auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable); |
|
85 | auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable); | |
86 | qCDebug(LOG_VariableController()) |
|
86 | qCDebug(LOG_VariableController()) | |
87 | << tr("Number of providers deleted for variable %1: %2") |
|
87 | << tr("Number of providers deleted for variable %1: %2") | |
88 | .arg(variable->name(), QString::number(nbProvidersDeleted)); |
|
88 | .arg(variable->name(), QString::number(nbProvidersDeleted)); | |
89 |
|
89 | |||
90 | // Clears cache |
|
90 | // Clears cache | |
91 | impl->m_VariableCacheController->clear(variable); |
|
91 | impl->m_VariableCacheController->clear(variable); | |
92 |
|
92 | |||
93 | // Deletes from model |
|
93 | // Deletes from model | |
94 | impl->m_VariableModel->deleteVariable(variable); |
|
94 | impl->m_VariableModel->deleteVariable(variable); | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | void VariableController::deleteVariables( |
|
97 | void VariableController::deleteVariables( | |
98 | const QVector<std::shared_ptr<Variable> > &variables) noexcept |
|
98 | const QVector<std::shared_ptr<Variable> > &variables) noexcept | |
99 | { |
|
99 | { | |
100 | for (auto variable : qAsConst(variables)) { |
|
100 | for (auto variable : qAsConst(variables)) { | |
101 | deleteVariable(variable); |
|
101 | deleteVariable(variable); | |
102 | } |
|
102 | } | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | void VariableController::createVariable(const QString &name, |
|
105 | void VariableController::createVariable(const QString &name, const QVariantHash &metadata, | |
106 | std::shared_ptr<IDataProvider> provider) noexcept |
|
106 | std::shared_ptr<IDataProvider> provider) noexcept | |
107 | { |
|
107 | { | |
108 |
|
108 | |||
109 | if (!impl->m_TimeController) { |
|
109 | if (!impl->m_TimeController) { | |
110 | qCCritical(LOG_VariableController()) |
|
110 | qCCritical(LOG_VariableController()) | |
111 | << tr("Impossible to create variable: The time controller is null"); |
|
111 | << tr("Impossible to create variable: The time controller is null"); | |
112 | return; |
|
112 | return; | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 |
|
115 | |||
116 | /// @todo : for the moment : |
|
116 | /// @todo : for the moment : | |
117 | /// - the provider is only used to retrieve data from the variable for its initialization, but |
|
117 | /// - the provider is only used to retrieve data from the variable for its initialization, but | |
118 | /// it will be retained later |
|
118 | /// it will be retained later | |
119 | /// - default data are generated for the variable, without taking into account the timerange set |
|
119 | /// - default data are generated for the variable, without taking into account the timerange set | |
120 | /// in sciqlop |
|
120 | /// in sciqlop | |
121 | auto dateTime = impl->m_TimeController->dateTime(); |
|
121 | auto dateTime = impl->m_TimeController->dateTime(); | |
122 | if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime)) { |
|
122 | ||
|
123 | if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime, metadata)) { | |||
123 | auto identifier = QUuid::createUuid(); |
|
124 | auto identifier = QUuid::createUuid(); | |
124 |
|
125 | |||
125 | // store the provider |
|
126 | // store the provider | |
126 | impl->m_VariableToProviderMap[newVariable] = provider; |
|
127 | impl->m_VariableToProviderMap[newVariable] = provider; | |
127 | impl->m_VariableToIdentifier[newVariable] = identifier; |
|
128 | impl->m_VariableToIdentifier[newVariable] = identifier; | |
128 |
|
129 | |||
129 | auto addDateTimeAcquired = [ this, varW = std::weak_ptr<Variable>{newVariable} ]( |
|
130 | auto addDateTimeAcquired = [ this, varW = std::weak_ptr<Variable>{newVariable} ]( | |
130 | QUuid identifier, auto dataSeriesAcquired, auto dateTimeToPutInCache) |
|
131 | QUuid identifier, auto dataSeriesAcquired, auto dateTimeToPutInCache) | |
131 | { |
|
132 | { | |
132 | if (auto variable = varW.lock()) { |
|
133 | if (auto variable = varW.lock()) { | |
133 | auto varIdentifier = impl->m_VariableToIdentifier.at(variable); |
|
134 | auto varIdentifier = impl->m_VariableToIdentifier.at(variable); | |
134 | if (varIdentifier == identifier) { |
|
135 | if (varIdentifier == identifier) { | |
135 | impl->m_VariableCacheController->addDateTime(variable, dateTimeToPutInCache); |
|
136 | impl->m_VariableCacheController->addDateTime(variable, dateTimeToPutInCache); | |
136 | variable->setDataSeries(dataSeriesAcquired); |
|
137 | variable->setDataSeries(dataSeriesAcquired); | |
137 | } |
|
138 | } | |
138 | } |
|
139 | } | |
139 | }; |
|
140 | }; | |
140 |
|
141 | |||
141 | connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired); |
|
142 | connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired); | |
142 | this->onRequestDataLoading(newVariable, dateTime); |
|
143 | this->onRequestDataLoading(newVariable, dateTime); | |
143 | } |
|
144 | } | |
144 | } |
|
145 | } | |
145 |
|
146 | |||
146 | void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime) |
|
147 | void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime) | |
147 | { |
|
148 | { | |
148 | qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection" |
|
149 | qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection" | |
149 | << QThread::currentThread()->objectName(); |
|
150 | << QThread::currentThread()->objectName(); | |
150 | auto selectedRows = impl->m_VariableSelectionModel->selectedRows(); |
|
151 | auto selectedRows = impl->m_VariableSelectionModel->selectedRows(); | |
151 |
|
152 | |||
152 | for (const auto &selectedRow : qAsConst(selectedRows)) { |
|
153 | for (const auto &selectedRow : qAsConst(selectedRows)) { | |
153 | if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) { |
|
154 | if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) { | |
154 | selectedVariable->setDateTime(dateTime); |
|
155 | selectedVariable->setDateTime(dateTime); | |
155 | this->onRequestDataLoading(selectedVariable, dateTime); |
|
156 | this->onRequestDataLoading(selectedVariable, dateTime); | |
156 | } |
|
157 | } | |
157 | } |
|
158 | } | |
158 | } |
|
159 | } | |
159 |
|
160 | |||
160 | void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress) |
|
161 | void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, double progress) | |
161 | { |
|
162 | { | |
162 | auto findReply = [identifier](const auto &entry) { return identifier == entry.second; }; |
|
163 | auto findReply = [identifier](const auto &entry) { return identifier == entry.second; }; | |
163 |
|
164 | |||
164 | auto end = impl->m_VariableToIdentifier.cend(); |
|
165 | auto end = impl->m_VariableToIdentifier.cend(); | |
165 | auto it = std::find_if(impl->m_VariableToIdentifier.cbegin(), end, findReply); |
|
166 | auto it = std::find_if(impl->m_VariableToIdentifier.cbegin(), end, findReply); | |
166 | if (it != end) { |
|
167 | if (it != end) { | |
167 | impl->m_VariableModel->setDataProgress(it->first, progress); |
|
168 | impl->m_VariableModel->setDataProgress(it->first, progress); | |
168 | } |
|
169 | } | |
169 | } |
|
170 | } | |
170 |
|
171 | |||
171 |
|
172 | |||
172 | void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable, |
|
173 | void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable, | |
173 | const SqpDateTime &dateTime) |
|
174 | const SqpDateTime &dateTime) | |
174 | { |
|
175 | { | |
175 | qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading" |
|
176 | qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading" | |
176 | << QThread::currentThread()->objectName(); |
|
177 | << QThread::currentThread()->objectName(); | |
177 | // we want to load data of the variable for the dateTime. |
|
178 | // we want to load data of the variable for the dateTime. | |
178 | // First we check if the cache contains some of them. |
|
179 | // First we check if the cache contains some of them. | |
179 | // For the other, we ask the provider to give them. |
|
180 | // For the other, we ask the provider to give them. | |
180 | if (variable) { |
|
181 | if (variable) { | |
181 |
|
182 | |||
182 | auto dateTimeListNotInCache |
|
183 | auto dateTimeListNotInCache | |
183 | = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime); |
|
184 | = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime); | |
184 |
|
185 | |||
185 | if (!dateTimeListNotInCache.empty()) { |
|
186 | if (!dateTimeListNotInCache.empty()) { | |
186 | // Ask the provider for each data on the dateTimeListNotInCache |
|
187 | // Ask the provider for each data on the dateTimeListNotInCache | |
187 | auto identifier = impl->m_VariableToIdentifier.at(variable); |
|
188 | auto identifier = impl->m_VariableToIdentifier.at(variable); | |
188 | impl->m_VariableToProviderMap.at(variable)->requestDataLoading( |
|
189 | impl->m_VariableToProviderMap.at(variable)->requestDataLoading( | |
189 | identifier, DataProviderParameters{std::move(dateTimeListNotInCache)}); |
|
190 | identifier, DataProviderParameters{std::move(dateTimeListNotInCache)}); | |
190 | } |
|
191 | } | |
191 | else { |
|
192 | else { | |
192 | emit variable->updated(); |
|
193 | emit variable->updated(); | |
193 | } |
|
194 | } | |
194 | } |
|
195 | } | |
195 | else { |
|
196 | else { | |
196 | qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null"); |
|
197 | qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null"); | |
197 | } |
|
198 | } | |
198 | } |
|
199 | } | |
199 |
|
200 | |||
200 |
|
201 | |||
201 | void VariableController::initialize() |
|
202 | void VariableController::initialize() | |
202 | { |
|
203 | { | |
203 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); |
|
204 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); | |
204 | impl->m_WorkingMutex.lock(); |
|
205 | impl->m_WorkingMutex.lock(); | |
205 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); |
|
206 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); | |
206 | } |
|
207 | } | |
207 |
|
208 | |||
208 | void VariableController::finalize() |
|
209 | void VariableController::finalize() | |
209 | { |
|
210 | { | |
210 | impl->m_WorkingMutex.unlock(); |
|
211 | impl->m_WorkingMutex.unlock(); | |
211 | } |
|
212 | } | |
212 |
|
213 | |||
213 | void VariableController::waitForFinish() |
|
214 | void VariableController::waitForFinish() | |
214 | { |
|
215 | { | |
215 | QMutexLocker locker{&impl->m_WorkingMutex}; |
|
216 | QMutexLocker locker{&impl->m_WorkingMutex}; | |
216 | } |
|
217 | } |
@@ -1,234 +1,235 | |||||
1 | #include <Variable/Variable.h> |
|
1 | #include <Variable/Variable.h> | |
2 | #include <Variable/VariableModel.h> |
|
2 | #include <Variable/VariableModel.h> | |
3 |
|
3 | |||
4 | #include <Data/IDataSeries.h> |
|
4 | #include <Data/IDataSeries.h> | |
5 |
|
5 | |||
6 | #include <QDateTime> |
|
6 | #include <QDateTime> | |
7 | #include <QSize> |
|
7 | #include <QSize> | |
8 | #include <unordered_map> |
|
8 | #include <unordered_map> | |
9 |
|
9 | |||
10 | Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel") |
|
10 | Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel") | |
11 |
|
11 | |||
12 | namespace { |
|
12 | namespace { | |
13 |
|
13 | |||
14 | // Column indexes |
|
14 | // Column indexes | |
15 | const auto NAME_COLUMN = 0; |
|
15 | const auto NAME_COLUMN = 0; | |
16 | const auto TSTART_COLUMN = 1; |
|
16 | const auto TSTART_COLUMN = 1; | |
17 | const auto TEND_COLUMN = 2; |
|
17 | const auto TEND_COLUMN = 2; | |
18 | const auto NB_COLUMNS = 3; |
|
18 | const auto NB_COLUMNS = 3; | |
19 |
|
19 | |||
20 | // Column properties |
|
20 | // Column properties | |
21 | const auto DEFAULT_HEIGHT = 25; |
|
21 | const auto DEFAULT_HEIGHT = 25; | |
22 | const auto DEFAULT_WIDTH = 100; |
|
22 | const auto DEFAULT_WIDTH = 100; | |
23 |
|
23 | |||
24 | struct ColumnProperties { |
|
24 | struct ColumnProperties { | |
25 | ColumnProperties(const QString &name = {}, int width = DEFAULT_WIDTH, |
|
25 | ColumnProperties(const QString &name = {}, int width = DEFAULT_WIDTH, | |
26 | int height = DEFAULT_HEIGHT) |
|
26 | int height = DEFAULT_HEIGHT) | |
27 | : m_Name{name}, m_Width{width}, m_Height{height} |
|
27 | : m_Name{name}, m_Width{width}, m_Height{height} | |
28 | { |
|
28 | { | |
29 | } |
|
29 | } | |
30 |
|
30 | |||
31 | QString m_Name; |
|
31 | QString m_Name; | |
32 | int m_Width; |
|
32 | int m_Width; | |
33 | int m_Height; |
|
33 | int m_Height; | |
34 | }; |
|
34 | }; | |
35 |
|
35 | |||
36 | const auto COLUMN_PROPERTIES |
|
36 | const auto COLUMN_PROPERTIES | |
37 | = QHash<int, ColumnProperties>{{NAME_COLUMN, {QObject::tr("Name")}}, |
|
37 | = QHash<int, ColumnProperties>{{NAME_COLUMN, {QObject::tr("Name")}}, | |
38 | {TSTART_COLUMN, {QObject::tr("tStart"), 180}}, |
|
38 | {TSTART_COLUMN, {QObject::tr("tStart"), 180}}, | |
39 | {TEND_COLUMN, {QObject::tr("tEnd"), 180}}}; |
|
39 | {TEND_COLUMN, {QObject::tr("tEnd"), 180}}}; | |
40 |
|
40 | |||
41 | /// Format for datetimes |
|
41 | /// Format for datetimes | |
42 | const auto DATETIME_FORMAT = QStringLiteral("dd/MM/yyyy \nhh:mm:ss:zzz"); |
|
42 | const auto DATETIME_FORMAT = QStringLiteral("dd/MM/yyyy \nhh:mm:ss:zzz"); | |
43 |
|
43 | |||
44 |
|
44 | |||
45 | } // namespace |
|
45 | } // namespace | |
46 |
|
46 | |||
47 | struct VariableModel::VariableModelPrivate { |
|
47 | struct VariableModel::VariableModelPrivate { | |
48 | /// Variables created in SciQlop |
|
48 | /// Variables created in SciQlop | |
49 | std::vector<std::shared_ptr<Variable> > m_Variables; |
|
49 | std::vector<std::shared_ptr<Variable> > m_Variables; | |
50 | std::unordered_map<std::shared_ptr<Variable>, double> m_VariableToProgress; |
|
50 | std::unordered_map<std::shared_ptr<Variable>, double> m_VariableToProgress; | |
51 |
|
51 | |||
52 |
|
52 | |||
53 | /// Return the row index of the variable. -1 if it's not found |
|
53 | /// Return the row index of the variable. -1 if it's not found | |
54 | int indexOfVariable(Variable *variable) const noexcept; |
|
54 | int indexOfVariable(Variable *variable) const noexcept; | |
55 | }; |
|
55 | }; | |
56 |
|
56 | |||
57 | VariableModel::VariableModel(QObject *parent) |
|
57 | VariableModel::VariableModel(QObject *parent) | |
58 | : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()} |
|
58 | : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()} | |
59 | { |
|
59 | { | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | std::shared_ptr<Variable> VariableModel::createVariable(const QString &name, |
|
62 | std::shared_ptr<Variable> VariableModel::createVariable(const QString &name, | |
63 |
const SqpDateTime &dateTime |
|
63 | const SqpDateTime &dateTime, | |
|
64 | const QVariantHash &metadata) noexcept | |||
64 | { |
|
65 | { | |
65 | auto insertIndex = rowCount(); |
|
66 | auto insertIndex = rowCount(); | |
66 | beginInsertRows({}, insertIndex, insertIndex); |
|
67 | beginInsertRows({}, insertIndex, insertIndex); | |
67 |
|
68 | |||
68 | auto variable = std::make_shared<Variable>(name, dateTime); |
|
69 | auto variable = std::make_shared<Variable>(name, dateTime, metadata); | |
69 |
|
70 | |||
70 | impl->m_Variables.push_back(variable); |
|
71 | impl->m_Variables.push_back(variable); | |
71 | connect(variable.get(), &Variable::updated, this, &VariableModel::onVariableUpdated); |
|
72 | connect(variable.get(), &Variable::updated, this, &VariableModel::onVariableUpdated); | |
72 |
|
73 | |||
73 | endInsertRows(); |
|
74 | endInsertRows(); | |
74 |
|
75 | |||
75 | return variable; |
|
76 | return variable; | |
76 | } |
|
77 | } | |
77 |
|
78 | |||
78 | void VariableModel::deleteVariable(std::shared_ptr<Variable> variable) noexcept |
|
79 | void VariableModel::deleteVariable(std::shared_ptr<Variable> variable) noexcept | |
79 | { |
|
80 | { | |
80 | if (!variable) { |
|
81 | if (!variable) { | |
81 | qCCritical(LOG_Variable()) << "Can't delete a null variable from the model"; |
|
82 | qCCritical(LOG_Variable()) << "Can't delete a null variable from the model"; | |
82 | return; |
|
83 | return; | |
83 | } |
|
84 | } | |
84 |
|
85 | |||
85 | // Finds variable in the model |
|
86 | // Finds variable in the model | |
86 | auto begin = impl->m_Variables.cbegin(); |
|
87 | auto begin = impl->m_Variables.cbegin(); | |
87 | auto end = impl->m_Variables.cend(); |
|
88 | auto end = impl->m_Variables.cend(); | |
88 | auto it = std::find(begin, end, variable); |
|
89 | auto it = std::find(begin, end, variable); | |
89 | if (it != end) { |
|
90 | if (it != end) { | |
90 | auto removeIndex = std::distance(begin, it); |
|
91 | auto removeIndex = std::distance(begin, it); | |
91 |
|
92 | |||
92 | // Deletes variable |
|
93 | // Deletes variable | |
93 | beginRemoveRows({}, removeIndex, removeIndex); |
|
94 | beginRemoveRows({}, removeIndex, removeIndex); | |
94 | impl->m_Variables.erase(it); |
|
95 | impl->m_Variables.erase(it); | |
95 | endRemoveRows(); |
|
96 | endRemoveRows(); | |
96 | } |
|
97 | } | |
97 | else { |
|
98 | else { | |
98 | qCritical(LOG_VariableModel()) |
|
99 | qCritical(LOG_VariableModel()) | |
99 | << tr("Can't delete variable %1 from the model: the variable is not in the model") |
|
100 | << tr("Can't delete variable %1 from the model: the variable is not in the model") | |
100 | .arg(variable->name()); |
|
101 | .arg(variable->name()); | |
101 | } |
|
102 | } | |
102 | } |
|
103 | } | |
103 |
|
104 | |||
104 |
|
105 | |||
105 | std::shared_ptr<Variable> VariableModel::variable(int index) const |
|
106 | std::shared_ptr<Variable> VariableModel::variable(int index) const | |
106 | { |
|
107 | { | |
107 | return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables[index] : nullptr; |
|
108 | return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables[index] : nullptr; | |
108 | } |
|
109 | } | |
109 |
|
110 | |||
110 | void VariableModel::setDataProgress(std::shared_ptr<Variable> variable, double progress) |
|
111 | void VariableModel::setDataProgress(std::shared_ptr<Variable> variable, double progress) | |
111 | { |
|
112 | { | |
112 |
|
113 | |||
113 | impl->m_VariableToProgress[variable] = progress; |
|
114 | impl->m_VariableToProgress[variable] = progress; | |
114 | auto modelIndex = createIndex(impl->indexOfVariable(variable.get()), NAME_COLUMN); |
|
115 | auto modelIndex = createIndex(impl->indexOfVariable(variable.get()), NAME_COLUMN); | |
115 |
|
116 | |||
116 | emit dataChanged(modelIndex, modelIndex); |
|
117 | emit dataChanged(modelIndex, modelIndex); | |
117 | } |
|
118 | } | |
118 |
|
119 | |||
119 | int VariableModel::columnCount(const QModelIndex &parent) const |
|
120 | int VariableModel::columnCount(const QModelIndex &parent) const | |
120 | { |
|
121 | { | |
121 | Q_UNUSED(parent); |
|
122 | Q_UNUSED(parent); | |
122 |
|
123 | |||
123 | return NB_COLUMNS; |
|
124 | return NB_COLUMNS; | |
124 | } |
|
125 | } | |
125 |
|
126 | |||
126 | int VariableModel::rowCount(const QModelIndex &parent) const |
|
127 | int VariableModel::rowCount(const QModelIndex &parent) const | |
127 | { |
|
128 | { | |
128 | Q_UNUSED(parent); |
|
129 | Q_UNUSED(parent); | |
129 |
|
130 | |||
130 | return impl->m_Variables.size(); |
|
131 | return impl->m_Variables.size(); | |
131 | } |
|
132 | } | |
132 |
|
133 | |||
133 | QVariant VariableModel::data(const QModelIndex &index, int role) const |
|
134 | QVariant VariableModel::data(const QModelIndex &index, int role) const | |
134 | { |
|
135 | { | |
135 | if (!index.isValid()) { |
|
136 | if (!index.isValid()) { | |
136 | return QVariant{}; |
|
137 | return QVariant{}; | |
137 | } |
|
138 | } | |
138 |
|
139 | |||
139 | if (index.row() < 0 || index.row() >= rowCount()) { |
|
140 | if (index.row() < 0 || index.row() >= rowCount()) { | |
140 | return QVariant{}; |
|
141 | return QVariant{}; | |
141 | } |
|
142 | } | |
142 |
|
143 | |||
143 | if (role == Qt::DisplayRole) { |
|
144 | if (role == Qt::DisplayRole) { | |
144 | if (auto variable = impl->m_Variables.at(index.row()).get()) { |
|
145 | if (auto variable = impl->m_Variables.at(index.row()).get()) { | |
145 | /// Lambda function that builds the variant to return for a time value |
|
146 | /// Lambda function that builds the variant to return for a time value | |
146 | auto dateTimeVariant = [](double time) { |
|
147 | auto dateTimeVariant = [](double time) { | |
147 | auto dateTime = QDateTime::fromMSecsSinceEpoch(time * 1000.); |
|
148 | auto dateTime = QDateTime::fromMSecsSinceEpoch(time * 1000.); | |
148 | return dateTime.toString(DATETIME_FORMAT); |
|
149 | return dateTime.toString(DATETIME_FORMAT); | |
149 | }; |
|
150 | }; | |
150 |
|
151 | |||
151 | switch (index.column()) { |
|
152 | switch (index.column()) { | |
152 | case NAME_COLUMN: |
|
153 | case NAME_COLUMN: | |
153 | return variable->name(); |
|
154 | return variable->name(); | |
154 | case TSTART_COLUMN: |
|
155 | case TSTART_COLUMN: | |
155 | return dateTimeVariant(variable->dateTime().m_TStart); |
|
156 | return dateTimeVariant(variable->dateTime().m_TStart); | |
156 | case TEND_COLUMN: |
|
157 | case TEND_COLUMN: | |
157 | return dateTimeVariant(variable->dateTime().m_TEnd); |
|
158 | return dateTimeVariant(variable->dateTime().m_TEnd); | |
158 | default: |
|
159 | default: | |
159 | // No action |
|
160 | // No action | |
160 | break; |
|
161 | break; | |
161 | } |
|
162 | } | |
162 |
|
163 | |||
163 | qWarning(LOG_VariableModel()) |
|
164 | qWarning(LOG_VariableModel()) | |
164 | << tr("Can't get data (unknown column %1)").arg(index.column()); |
|
165 | << tr("Can't get data (unknown column %1)").arg(index.column()); | |
165 | } |
|
166 | } | |
166 | else { |
|
167 | else { | |
167 | qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)"); |
|
168 | qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)"); | |
168 | } |
|
169 | } | |
169 | } |
|
170 | } | |
170 | else if (role == VariableRoles::ProgressRole) { |
|
171 | else if (role == VariableRoles::ProgressRole) { | |
171 | if (auto variable = impl->m_Variables.at(index.row())) { |
|
172 | if (auto variable = impl->m_Variables.at(index.row())) { | |
172 |
|
173 | |||
173 | auto it = impl->m_VariableToProgress.find(variable); |
|
174 | auto it = impl->m_VariableToProgress.find(variable); | |
174 | if (it != impl->m_VariableToProgress.cend()) { |
|
175 | if (it != impl->m_VariableToProgress.cend()) { | |
175 | return it->second; |
|
176 | return it->second; | |
176 | } |
|
177 | } | |
177 | } |
|
178 | } | |
178 | } |
|
179 | } | |
179 |
|
180 | |||
180 | return QVariant{}; |
|
181 | return QVariant{}; | |
181 | } |
|
182 | } | |
182 |
|
183 | |||
183 | QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const |
|
184 | QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const | |
184 | { |
|
185 | { | |
185 | if (role != Qt::DisplayRole && role != Qt::SizeHintRole) { |
|
186 | if (role != Qt::DisplayRole && role != Qt::SizeHintRole) { | |
186 | return QVariant{}; |
|
187 | return QVariant{}; | |
187 | } |
|
188 | } | |
188 |
|
189 | |||
189 | if (orientation == Qt::Horizontal) { |
|
190 | if (orientation == Qt::Horizontal) { | |
190 | auto propertiesIt = COLUMN_PROPERTIES.find(section); |
|
191 | auto propertiesIt = COLUMN_PROPERTIES.find(section); | |
191 | if (propertiesIt != COLUMN_PROPERTIES.cend()) { |
|
192 | if (propertiesIt != COLUMN_PROPERTIES.cend()) { | |
192 | // Role is either DisplayRole or SizeHintRole |
|
193 | // Role is either DisplayRole or SizeHintRole | |
193 | return (role == Qt::DisplayRole) |
|
194 | return (role == Qt::DisplayRole) | |
194 | ? QVariant{propertiesIt->m_Name} |
|
195 | ? QVariant{propertiesIt->m_Name} | |
195 | : QVariant{QSize{propertiesIt->m_Width, propertiesIt->m_Height}}; |
|
196 | : QVariant{QSize{propertiesIt->m_Width, propertiesIt->m_Height}}; | |
196 | } |
|
197 | } | |
197 | else { |
|
198 | else { | |
198 | qWarning(LOG_VariableModel()) |
|
199 | qWarning(LOG_VariableModel()) | |
199 | << tr("Can't get header data (unknown column %1)").arg(section); |
|
200 | << tr("Can't get header data (unknown column %1)").arg(section); | |
200 | } |
|
201 | } | |
201 | } |
|
202 | } | |
202 |
|
203 | |||
203 | return QVariant{}; |
|
204 | return QVariant{}; | |
204 | } |
|
205 | } | |
205 |
|
206 | |||
206 | void VariableModel::onVariableUpdated() noexcept |
|
207 | void VariableModel::onVariableUpdated() noexcept | |
207 | { |
|
208 | { | |
208 | // Finds variable that has been updated in the model |
|
209 | // Finds variable that has been updated in the model | |
209 | if (auto updatedVariable = dynamic_cast<Variable *>(sender())) { |
|
210 | if (auto updatedVariable = dynamic_cast<Variable *>(sender())) { | |
210 | auto updatedVariableIndex = impl->indexOfVariable(updatedVariable); |
|
211 | auto updatedVariableIndex = impl->indexOfVariable(updatedVariable); | |
211 |
|
212 | |||
212 | if (updatedVariableIndex > -1) { |
|
213 | if (updatedVariableIndex > -1) { | |
213 | emit dataChanged(createIndex(updatedVariableIndex, 0), |
|
214 | emit dataChanged(createIndex(updatedVariableIndex, 0), | |
214 | createIndex(updatedVariableIndex, columnCount() - 1)); |
|
215 | createIndex(updatedVariableIndex, columnCount() - 1)); | |
215 | } |
|
216 | } | |
216 | } |
|
217 | } | |
217 | } |
|
218 | } | |
218 |
|
219 | |||
219 | int VariableModel::VariableModelPrivate::indexOfVariable(Variable *variable) const noexcept |
|
220 | int VariableModel::VariableModelPrivate::indexOfVariable(Variable *variable) const noexcept | |
220 | { |
|
221 | { | |
221 | auto begin = std::cbegin(m_Variables); |
|
222 | auto begin = std::cbegin(m_Variables); | |
222 | auto end = std::cend(m_Variables); |
|
223 | auto end = std::cend(m_Variables); | |
223 | auto it |
|
224 | auto it | |
224 | = std::find_if(begin, end, [variable](const auto &var) { return var.get() == variable; }); |
|
225 | = std::find_if(begin, end, [variable](const auto &var) { return var.get() == variable; }); | |
225 |
|
226 | |||
226 | if (it != end) { |
|
227 | if (it != end) { | |
227 | // Gets the index of the variable in the model: we assume here that views have the same |
|
228 | // Gets the index of the variable in the model: we assume here that views have the same | |
228 | // order as the model |
|
229 | // order as the model | |
229 | return std::distance(begin, it); |
|
230 | return std::distance(begin, it); | |
230 | } |
|
231 | } | |
231 | else { |
|
232 | else { | |
232 | return -1; |
|
233 | return -1; | |
233 | } |
|
234 | } | |
234 | } |
|
235 | } |
@@ -1,145 +1,147 | |||||
1 | #include "SqpApplication.h" |
|
1 | #include "SqpApplication.h" | |
2 |
|
2 | |||
3 | #include <Data/IDataProvider.h> |
|
3 | #include <Data/IDataProvider.h> | |
4 | #include <DataSource/DataSourceController.h> |
|
4 | #include <DataSource/DataSourceController.h> | |
5 | #include <Network/NetworkController.h> |
|
5 | #include <Network/NetworkController.h> | |
6 | #include <QThread> |
|
6 | #include <QThread> | |
7 | #include <Time/TimeController.h> |
|
7 | #include <Time/TimeController.h> | |
8 | #include <Variable/Variable.h> |
|
8 | #include <Variable/Variable.h> | |
9 | #include <Variable/VariableController.h> |
|
9 | #include <Variable/VariableController.h> | |
10 | #include <Visualization/VisualizationController.h> |
|
10 | #include <Visualization/VisualizationController.h> | |
11 |
|
11 | |||
12 | Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication") |
|
12 | Q_LOGGING_CATEGORY(LOG_SqpApplication, "SqpApplication") | |
13 |
|
13 | |||
14 | class SqpApplication::SqpApplicationPrivate { |
|
14 | class SqpApplication::SqpApplicationPrivate { | |
15 | public: |
|
15 | public: | |
16 | SqpApplicationPrivate() |
|
16 | SqpApplicationPrivate() | |
17 | : m_DataSourceController{std::make_unique<DataSourceController>()}, |
|
17 | : m_DataSourceController{std::make_unique<DataSourceController>()}, | |
18 | m_NetworkController{std::make_unique<NetworkController>()}, |
|
18 | m_NetworkController{std::make_unique<NetworkController>()}, | |
19 | m_TimeController{std::make_unique<TimeController>()}, |
|
19 | m_TimeController{std::make_unique<TimeController>()}, | |
20 | m_VariableController{std::make_unique<VariableController>()}, |
|
20 | m_VariableController{std::make_unique<VariableController>()}, | |
21 | m_VisualizationController{std::make_unique<VisualizationController>()} |
|
21 | m_VisualizationController{std::make_unique<VisualizationController>()} | |
22 | { |
|
22 | { | |
23 | // /////////////////////////////// // |
|
23 | // /////////////////////////////// // | |
24 | // Connections between controllers // |
|
24 | // Connections between controllers // | |
25 | // /////////////////////////////// // |
|
25 | // /////////////////////////////// // | |
26 |
|
26 | |||
27 | // VariableController <-> DataSourceController |
|
27 | // VariableController <-> DataSourceController | |
28 | connect(m_DataSourceController.get(), |
|
28 | connect(m_DataSourceController.get(), | |
29 |
SIGNAL(variableCreationRequested(const QString &, |
|
29 | SIGNAL(variableCreationRequested(const QString &, const QVariantHash &, | |
|
30 | std::shared_ptr<IDataProvider>)), | |||
30 | m_VariableController.get(), |
|
31 | m_VariableController.get(), | |
31 |
SLOT(createVariable(const QString &, |
|
32 | SLOT(createVariable(const QString &, const QVariantHash &, | |
|
33 | std::shared_ptr<IDataProvider>))); | |||
32 |
|
34 | |||
33 | // VariableController <-> VisualizationController |
|
35 | // VariableController <-> VisualizationController | |
34 | connect(m_VariableController.get(), |
|
36 | connect(m_VariableController.get(), | |
35 | SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), |
|
37 | SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), | |
36 | m_VisualizationController.get(), |
|
38 | m_VisualizationController.get(), | |
37 | SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), Qt::DirectConnection); |
|
39 | SIGNAL(variableAboutToBeDeleted(std::shared_ptr<Variable>)), Qt::DirectConnection); | |
38 |
|
40 | |||
39 |
|
41 | |||
40 | m_DataSourceController->moveToThread(&m_DataSourceControllerThread); |
|
42 | m_DataSourceController->moveToThread(&m_DataSourceControllerThread); | |
41 | m_NetworkController->moveToThread(&m_NetworkControllerThread); |
|
43 | m_NetworkController->moveToThread(&m_NetworkControllerThread); | |
42 | m_VariableController->moveToThread(&m_VariableControllerThread); |
|
44 | m_VariableController->moveToThread(&m_VariableControllerThread); | |
43 | m_VisualizationController->moveToThread(&m_VisualizationControllerThread); |
|
45 | m_VisualizationController->moveToThread(&m_VisualizationControllerThread); | |
44 |
|
46 | |||
45 |
|
47 | |||
46 | // Additionnal init |
|
48 | // Additionnal init | |
47 | m_VariableController->setTimeController(m_TimeController.get()); |
|
49 | m_VariableController->setTimeController(m_TimeController.get()); | |
48 | } |
|
50 | } | |
49 |
|
51 | |||
50 | virtual ~SqpApplicationPrivate() |
|
52 | virtual ~SqpApplicationPrivate() | |
51 | { |
|
53 | { | |
52 | qCInfo(LOG_SqpApplication()) << tr("SqpApplicationPrivate destruction"); |
|
54 | qCInfo(LOG_SqpApplication()) << tr("SqpApplicationPrivate destruction"); | |
53 | m_DataSourceControllerThread.quit(); |
|
55 | m_DataSourceControllerThread.quit(); | |
54 | m_DataSourceControllerThread.wait(); |
|
56 | m_DataSourceControllerThread.wait(); | |
55 |
|
57 | |||
56 | m_NetworkControllerThread.quit(); |
|
58 | m_NetworkControllerThread.quit(); | |
57 | m_NetworkControllerThread.wait(); |
|
59 | m_NetworkControllerThread.wait(); | |
58 |
|
60 | |||
59 | m_VariableControllerThread.quit(); |
|
61 | m_VariableControllerThread.quit(); | |
60 | m_VariableControllerThread.wait(); |
|
62 | m_VariableControllerThread.wait(); | |
61 |
|
63 | |||
62 | m_VisualizationControllerThread.quit(); |
|
64 | m_VisualizationControllerThread.quit(); | |
63 | m_VisualizationControllerThread.wait(); |
|
65 | m_VisualizationControllerThread.wait(); | |
64 | } |
|
66 | } | |
65 |
|
67 | |||
66 | std::unique_ptr<DataSourceController> m_DataSourceController; |
|
68 | std::unique_ptr<DataSourceController> m_DataSourceController; | |
67 | std::unique_ptr<VariableController> m_VariableController; |
|
69 | std::unique_ptr<VariableController> m_VariableController; | |
68 | std::unique_ptr<TimeController> m_TimeController; |
|
70 | std::unique_ptr<TimeController> m_TimeController; | |
69 | std::unique_ptr<NetworkController> m_NetworkController; |
|
71 | std::unique_ptr<NetworkController> m_NetworkController; | |
70 | std::unique_ptr<VisualizationController> m_VisualizationController; |
|
72 | std::unique_ptr<VisualizationController> m_VisualizationController; | |
71 | QThread m_DataSourceControllerThread; |
|
73 | QThread m_DataSourceControllerThread; | |
72 | QThread m_NetworkControllerThread; |
|
74 | QThread m_NetworkControllerThread; | |
73 | QThread m_VariableControllerThread; |
|
75 | QThread m_VariableControllerThread; | |
74 | QThread m_VisualizationControllerThread; |
|
76 | QThread m_VisualizationControllerThread; | |
75 | }; |
|
77 | }; | |
76 |
|
78 | |||
77 |
|
79 | |||
78 | SqpApplication::SqpApplication(int &argc, char **argv) |
|
80 | SqpApplication::SqpApplication(int &argc, char **argv) | |
79 | : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()} |
|
81 | : QApplication{argc, argv}, impl{spimpl::make_unique_impl<SqpApplicationPrivate>()} | |
80 | { |
|
82 | { | |
81 | qCDebug(LOG_SqpApplication()) << tr("SqpApplication construction") << QThread::currentThread(); |
|
83 | qCDebug(LOG_SqpApplication()) << tr("SqpApplication construction") << QThread::currentThread(); | |
82 |
|
84 | |||
83 | connect(&impl->m_DataSourceControllerThread, &QThread::started, |
|
85 | connect(&impl->m_DataSourceControllerThread, &QThread::started, | |
84 | impl->m_DataSourceController.get(), &DataSourceController::initialize); |
|
86 | impl->m_DataSourceController.get(), &DataSourceController::initialize); | |
85 | connect(&impl->m_DataSourceControllerThread, &QThread::finished, |
|
87 | connect(&impl->m_DataSourceControllerThread, &QThread::finished, | |
86 | impl->m_DataSourceController.get(), &DataSourceController::finalize); |
|
88 | impl->m_DataSourceController.get(), &DataSourceController::finalize); | |
87 |
|
89 | |||
88 | connect(&impl->m_NetworkControllerThread, &QThread::started, impl->m_NetworkController.get(), |
|
90 | connect(&impl->m_NetworkControllerThread, &QThread::started, impl->m_NetworkController.get(), | |
89 | &NetworkController::initialize); |
|
91 | &NetworkController::initialize); | |
90 | connect(&impl->m_NetworkControllerThread, &QThread::finished, impl->m_NetworkController.get(), |
|
92 | connect(&impl->m_NetworkControllerThread, &QThread::finished, impl->m_NetworkController.get(), | |
91 | &NetworkController::finalize); |
|
93 | &NetworkController::finalize); | |
92 |
|
94 | |||
93 | connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(), |
|
95 | connect(&impl->m_VariableControllerThread, &QThread::started, impl->m_VariableController.get(), | |
94 | &VariableController::initialize); |
|
96 | &VariableController::initialize); | |
95 | connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(), |
|
97 | connect(&impl->m_VariableControllerThread, &QThread::finished, impl->m_VariableController.get(), | |
96 | &VariableController::finalize); |
|
98 | &VariableController::finalize); | |
97 |
|
99 | |||
98 | connect(&impl->m_VisualizationControllerThread, &QThread::started, |
|
100 | connect(&impl->m_VisualizationControllerThread, &QThread::started, | |
99 | impl->m_VisualizationController.get(), &VisualizationController::initialize); |
|
101 | impl->m_VisualizationController.get(), &VisualizationController::initialize); | |
100 | connect(&impl->m_VisualizationControllerThread, &QThread::finished, |
|
102 | connect(&impl->m_VisualizationControllerThread, &QThread::finished, | |
101 | impl->m_VisualizationController.get(), &VisualizationController::finalize); |
|
103 | impl->m_VisualizationController.get(), &VisualizationController::finalize); | |
102 |
|
104 | |||
103 | impl->m_DataSourceControllerThread.start(); |
|
105 | impl->m_DataSourceControllerThread.start(); | |
104 | impl->m_NetworkControllerThread.start(); |
|
106 | impl->m_NetworkControllerThread.start(); | |
105 | impl->m_VariableControllerThread.start(); |
|
107 | impl->m_VariableControllerThread.start(); | |
106 | impl->m_VisualizationControllerThread.start(); |
|
108 | impl->m_VisualizationControllerThread.start(); | |
107 |
|
109 | |||
108 | // Core connections: |
|
110 | // Core connections: | |
109 | // NetworkController <-> VariableController |
|
111 | // NetworkController <-> VariableController | |
110 | connect(&sqpApp->networkController(), &NetworkController::replyDownloadProgress, |
|
112 | connect(&sqpApp->networkController(), &NetworkController::replyDownloadProgress, | |
111 | &sqpApp->variableController(), &VariableController::onVariableRetrieveDataInProgress); |
|
113 | &sqpApp->variableController(), &VariableController::onVariableRetrieveDataInProgress); | |
112 | } |
|
114 | } | |
113 |
|
115 | |||
114 | SqpApplication::~SqpApplication() |
|
116 | SqpApplication::~SqpApplication() | |
115 | { |
|
117 | { | |
116 | } |
|
118 | } | |
117 |
|
119 | |||
118 | void SqpApplication::initialize() |
|
120 | void SqpApplication::initialize() | |
119 | { |
|
121 | { | |
120 | } |
|
122 | } | |
121 |
|
123 | |||
122 | DataSourceController &SqpApplication::dataSourceController() noexcept |
|
124 | DataSourceController &SqpApplication::dataSourceController() noexcept | |
123 | { |
|
125 | { | |
124 | return *impl->m_DataSourceController; |
|
126 | return *impl->m_DataSourceController; | |
125 | } |
|
127 | } | |
126 |
|
128 | |||
127 | NetworkController &SqpApplication::networkController() noexcept |
|
129 | NetworkController &SqpApplication::networkController() noexcept | |
128 | { |
|
130 | { | |
129 | return *impl->m_NetworkController; |
|
131 | return *impl->m_NetworkController; | |
130 | } |
|
132 | } | |
131 |
|
133 | |||
132 | TimeController &SqpApplication::timeController() noexcept |
|
134 | TimeController &SqpApplication::timeController() noexcept | |
133 | { |
|
135 | { | |
134 | return *impl->m_TimeController; |
|
136 | return *impl->m_TimeController; | |
135 | } |
|
137 | } | |
136 |
|
138 | |||
137 | VariableController &SqpApplication::variableController() noexcept |
|
139 | VariableController &SqpApplication::variableController() noexcept | |
138 | { |
|
140 | { | |
139 | return *impl->m_VariableController; |
|
141 | return *impl->m_VariableController; | |
140 | } |
|
142 | } | |
141 |
|
143 | |||
142 | VisualizationController &SqpApplication::visualizationController() noexcept |
|
144 | VisualizationController &SqpApplication::visualizationController() noexcept | |
143 | { |
|
145 | { | |
144 | return *impl->m_VisualizationController; |
|
146 | return *impl->m_VisualizationController; | |
145 | } |
|
147 | } |
General Comments 0
You need to be logged in to leave comments.
Login now