Status change > Approved
@@ -1,114 +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 | 22 | /// @remarks Data providers are stored as shared_ptr as they can be sent to a variable and |
|
23 | 23 | /// continue to live without necessarily the data source controller |
|
24 | 24 | std::map<QUuid, std::shared_ptr<IDataProvider> > m_DataProviders; |
|
25 | 25 | }; |
|
26 | 26 | |
|
27 | 27 | DataSourceController::DataSourceController(QObject *parent) |
|
28 | 28 | : impl{spimpl::make_unique_impl<DataSourceControllerPrivate>()} |
|
29 | 29 | { |
|
30 | 30 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController construction") |
|
31 | 31 | << QThread::currentThread(); |
|
32 | 32 | } |
|
33 | 33 | |
|
34 | 34 | DataSourceController::~DataSourceController() |
|
35 | 35 | { |
|
36 | 36 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController destruction") |
|
37 | 37 | << QThread::currentThread(); |
|
38 | 38 | this->waitForFinish(); |
|
39 | 39 | } |
|
40 | 40 | |
|
41 | 41 | QUuid DataSourceController::registerDataSource(const QString &dataSourceName) noexcept |
|
42 | 42 | { |
|
43 | 43 | auto dataSourceUid = QUuid::createUuid(); |
|
44 | 44 | impl->m_DataSources.insert(dataSourceUid, dataSourceName); |
|
45 | 45 | |
|
46 | 46 | return dataSourceUid; |
|
47 | 47 | } |
|
48 | 48 | |
|
49 | 49 | void DataSourceController::setDataSourceItem( |
|
50 | 50 | const QUuid &dataSourceUid, std::unique_ptr<DataSourceItem> dataSourceItem) noexcept |
|
51 | 51 | { |
|
52 | 52 | if (impl->m_DataSources.contains(dataSourceUid)) { |
|
53 | 53 | // The data provider is implicitly converted to a shared_ptr |
|
54 | 54 | impl->m_DataSourceItems.insert(std::make_pair(dataSourceUid, std::move(dataSourceItem))); |
|
55 | 55 | |
|
56 | 56 | // Retrieves the data source item to emit the signal with it |
|
57 | 57 | auto it = impl->m_DataSourceItems.find(dataSourceUid); |
|
58 | 58 | if (it != impl->m_DataSourceItems.end()) { |
|
59 | 59 | emit dataSourceItemSet(it->second.get()); |
|
60 | 60 | } |
|
61 | 61 | } |
|
62 | 62 | else { |
|
63 | 63 | qCWarning(LOG_DataSourceController()) << tr("Can't set data source item for uid %1 : no " |
|
64 | 64 | "data source has been registered with the uid") |
|
65 | 65 | .arg(dataSourceUid.toString()); |
|
66 | 66 | } |
|
67 | 67 | } |
|
68 | 68 | |
|
69 | 69 | void DataSourceController::setDataProvider(const QUuid &dataSourceUid, |
|
70 | 70 | std::unique_ptr<IDataProvider> dataProvider) noexcept |
|
71 | 71 | { |
|
72 | 72 | if (impl->m_DataSources.contains(dataSourceUid)) { |
|
73 | 73 | impl->m_DataProviders.insert(std::make_pair(dataSourceUid, std::move(dataProvider))); |
|
74 | 74 | } |
|
75 | 75 | else { |
|
76 | 76 | qCWarning(LOG_DataSourceController()) << tr("Can't set data provider for uid %1 : no data " |
|
77 | 77 | "source has been registered with the uid") |
|
78 | 78 | .arg(dataSourceUid.toString()); |
|
79 | 79 | } |
|
80 | 80 | } |
|
81 | 81 | |
|
82 | 82 | void DataSourceController::loadProductItem(const QUuid &dataSourceUid, |
|
83 | 83 | const DataSourceItem &productItem) noexcept |
|
84 | 84 | { |
|
85 | 85 | if (productItem.type() == DataSourceItemType::PRODUCT) { |
|
86 | 86 | /// Retrieves the data provider of the data source (if any) |
|
87 | 87 | auto it = impl->m_DataProviders.find(dataSourceUid); |
|
88 | 88 | auto dataProvider = (it != impl->m_DataProviders.end()) ? it->second : nullptr; |
|
89 | 89 | |
|
90 | 90 | /// @todo retrieve timerange, and pass it to the signal |
|
91 | 91 | emit variableCreationRequested(productItem.name(), dataProvider); |
|
92 | 92 | } |
|
93 | 93 | else { |
|
94 | 94 | qCWarning(LOG_DataSourceController()) << tr("Can't load an item that is not a product"); |
|
95 | 95 | } |
|
96 | 96 | } |
|
97 | 97 | |
|
98 | 98 | void DataSourceController::initialize() |
|
99 | 99 | { |
|
100 | 100 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController init") |
|
101 | 101 | << QThread::currentThread(); |
|
102 | 102 | impl->m_WorkingMutex.lock(); |
|
103 | 103 | qCDebug(LOG_DataSourceController()) << tr("DataSourceController init END"); |
|
104 | 104 | } |
|
105 | 105 | |
|
106 | 106 | void DataSourceController::finalize() |
|
107 | 107 | { |
|
108 | 108 | impl->m_WorkingMutex.unlock(); |
|
109 | 109 | } |
|
110 | 110 | |
|
111 | 111 | void DataSourceController::waitForFinish() |
|
112 | 112 | { |
|
113 | 113 | QMutexLocker locker{&impl->m_WorkingMutex}; |
|
114 | 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,88 +1,91 | |||
|
1 | 1 | #include <Variable/VariableController.h> |
|
2 | 2 | #include <Variable/VariableModel.h> |
|
3 | 3 | |
|
4 | 4 | #include <Data/DataProviderParameters.h> |
|
5 | 5 | #include <Data/IDataProvider.h> |
|
6 | 6 | #include <Data/IDataSeries.h> |
|
7 | 7 | |
|
8 | 8 | #include <QDateTime> |
|
9 | 9 | #include <QMutex> |
|
10 | 10 | #include <QThread> |
|
11 | 11 | |
|
12 | 12 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") |
|
13 | 13 | |
|
14 | 14 | namespace { |
|
15 | 15 | |
|
16 | 16 | /// @todo Generates default dataseries, according to the provider passed in parameter. This method |
|
17 | 17 | /// will be deleted when the timerange is recovered from SciQlop |
|
18 | 18 | std::unique_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider) noexcept |
|
19 | 19 | { |
|
20 | 20 | auto parameters = DataProviderParameters{ |
|
21 | static_cast<double>(QDateTime{QDate{2017, 01, 01}}.toSecsSinceEpoch()), | |
|
22 |
static_cast<double>(QDateTime{QDate{2017, 01, 0 |
|
|
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.}; | |
|
23 | 26 | |
|
24 | 27 | return provider.retrieveData(parameters); |
|
25 | 28 | } |
|
26 | 29 | |
|
27 | 30 | } // namespace |
|
28 | 31 | |
|
29 | 32 | struct VariableController::VariableControllerPrivate { |
|
30 | 33 | explicit VariableControllerPrivate(VariableController *parent) |
|
31 | 34 | : m_WorkingMutex{}, m_VariableModel{new VariableModel{parent}} |
|
32 | 35 | { |
|
33 | 36 | } |
|
34 | 37 | |
|
35 | 38 | QMutex m_WorkingMutex; |
|
36 | 39 | /// Variable model. The VariableController has the ownership |
|
37 | 40 | VariableModel *m_VariableModel; |
|
38 | 41 | }; |
|
39 | 42 | |
|
40 | 43 | VariableController::VariableController(QObject *parent) |
|
41 | 44 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} |
|
42 | 45 | { |
|
43 | 46 | qCDebug(LOG_VariableController()) << tr("VariableController construction") |
|
44 | 47 | << QThread::currentThread(); |
|
45 | 48 | } |
|
46 | 49 | |
|
47 | 50 | VariableController::~VariableController() |
|
48 | 51 | { |
|
49 | 52 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") |
|
50 | 53 | << QThread::currentThread(); |
|
51 | 54 | this->waitForFinish(); |
|
52 | 55 | } |
|
53 | 56 | |
|
54 | 57 | VariableModel *VariableController::variableModel() noexcept |
|
55 | 58 | { |
|
56 | 59 | return impl->m_VariableModel; |
|
57 | 60 | } |
|
58 | 61 | |
|
59 | 62 | void VariableController::createVariable(const QString &name, |
|
60 | 63 | std::shared_ptr<IDataProvider> provider) noexcept |
|
61 | 64 | { |
|
62 | 65 | /// @todo : for the moment : |
|
63 | 66 | /// - the provider is only used to retrieve data from the variable for its initialization, but |
|
64 | 67 | /// it will be retained later |
|
65 | 68 | /// - default data are generated for the variable, without taking into account the timerange set |
|
66 | 69 | /// in sciqlop |
|
67 | 70 | if (auto newVariable |
|
68 | 71 | = impl->m_VariableModel->createVariable(name, generateDefaultDataSeries(*provider))) { |
|
69 | 72 | emit variableCreated(newVariable); |
|
70 | 73 | } |
|
71 | 74 | } |
|
72 | 75 | |
|
73 | 76 | void VariableController::initialize() |
|
74 | 77 | { |
|
75 | 78 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); |
|
76 | 79 | impl->m_WorkingMutex.lock(); |
|
77 | 80 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); |
|
78 | 81 | } |
|
79 | 82 | |
|
80 | 83 | void VariableController::finalize() |
|
81 | 84 | { |
|
82 | 85 | impl->m_WorkingMutex.unlock(); |
|
83 | 86 | } |
|
84 | 87 | |
|
85 | 88 | void VariableController::waitForFinish() |
|
86 | 89 | { |
|
87 | 90 | QMutexLocker locker{&impl->m_WorkingMutex}; |
|
88 | 91 | } |
@@ -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.* |
General Comments 1
You need to be logged in to leave comments.
Login now