##// END OF EJS Templates
Minor fixes
Alexandre Leroux -
r159:d6ec0a8c7ca0
parent child
Show More
@@ -1,114 +1,114
1 #include <DataSource/DataSourceController.h>
1 #include "DataSource/DataSourceController.h"
2 #include <DataSource/DataSourceItem.h>
2 #include "DataSource/DataSourceItem.h"
3
3
4 #include <Data/IDataProvider.h>
4 #include <Data/IDataProvider.h>
5
5
6 #include <QMutex>
6 #include <QMutex>
7 #include <QThread>
7 #include <QThread>
8
8
9 #include <QDir>
9 #include <QDir>
10 #include <QStandardPaths>
10 #include <QStandardPaths>
11
11
12 Q_LOGGING_CATEGORY(LOG_DataSourceController, "DataSourceController")
12 Q_LOGGING_CATEGORY(LOG_DataSourceController, "DataSourceController")
13
13
14 class DataSourceController::DataSourceControllerPrivate {
14 class DataSourceController::DataSourceControllerPrivate {
15 public:
15 public:
16 QMutex m_WorkingMutex;
16 QMutex m_WorkingMutex;
17 /// Data sources registered
17 /// Data sources registered
18 QHash<QUuid, QString> m_DataSources;
18 QHash<QUuid, QString> m_DataSources;
19 /// Data sources structures
19 /// Data sources structures
20 std::map<QUuid, std::unique_ptr<DataSourceItem> > m_DataSourceItems;
20 std::map<QUuid, std::unique_ptr<DataSourceItem> > m_DataSourceItems;
21 /// Data providers registered
21 /// Data providers registered
22 /// @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 (impl->m_DataSources.contains(dataSourceUid)) {
52 if (impl->m_DataSources.contains(dataSourceUid)) {
53 // The data provider is implicitly converted to a shared_ptr
53 // The data provider is implicitly converted to a shared_ptr
54 impl->m_DataSourceItems.insert(std::make_pair(dataSourceUid, std::move(dataSourceItem)));
54 impl->m_DataSourceItems.insert(std::make_pair(dataSourceUid, std::move(dataSourceItem)));
55
55
56 // Retrieves the data source item to emit the signal with it
56 // Retrieves the data source item to emit the signal with it
57 auto it = impl->m_DataSourceItems.find(dataSourceUid);
57 auto it = impl->m_DataSourceItems.find(dataSourceUid);
58 if (it != impl->m_DataSourceItems.end()) {
58 if (it != impl->m_DataSourceItems.end()) {
59 emit dataSourceItemSet(it->second.get());
59 emit dataSourceItemSet(it->second.get());
60 }
60 }
61 }
61 }
62 else {
62 else {
63 qCWarning(LOG_DataSourceController()) << tr("Can't set data source item for uid %1 : no "
63 qCWarning(LOG_DataSourceController()) << tr("Can't set data source item for uid %1 : no "
64 "data source has been registered with the uid")
64 "data source has been registered with the uid")
65 .arg(dataSourceUid.toString());
65 .arg(dataSourceUid.toString());
66 }
66 }
67 }
67 }
68
68
69 void DataSourceController::setDataProvider(const QUuid &dataSourceUid,
69 void DataSourceController::setDataProvider(const QUuid &dataSourceUid,
70 std::unique_ptr<IDataProvider> dataProvider) noexcept
70 std::unique_ptr<IDataProvider> dataProvider) noexcept
71 {
71 {
72 if (impl->m_DataSources.contains(dataSourceUid)) {
72 if (impl->m_DataSources.contains(dataSourceUid)) {
73 impl->m_DataProviders.insert(std::make_pair(dataSourceUid, std::move(dataProvider)));
73 impl->m_DataProviders.insert(std::make_pair(dataSourceUid, std::move(dataProvider)));
74 }
74 }
75 else {
75 else {
76 qCWarning(LOG_DataSourceController()) << tr("Can't set data provider for uid %1 : no data "
76 qCWarning(LOG_DataSourceController()) << tr("Can't set data provider for uid %1 : no data "
77 "source has been registered with the uid")
77 "source has been registered with the uid")
78 .arg(dataSourceUid.toString());
78 .arg(dataSourceUid.toString());
79 }
79 }
80 }
80 }
81
81
82 void DataSourceController::loadProductItem(const QUuid &dataSourceUid,
82 void DataSourceController::loadProductItem(const QUuid &dataSourceUid,
83 const DataSourceItem &productItem) noexcept
83 const DataSourceItem &productItem) noexcept
84 {
84 {
85 if (productItem.type() == DataSourceItemType::PRODUCT) {
85 if (productItem.type() == DataSourceItemType::PRODUCT) {
86 /// Retrieves the data provider of the data source (if any)
86 /// Retrieves the data provider of the data source (if any)
87 auto it = impl->m_DataProviders.find(dataSourceUid);
87 auto it = impl->m_DataProviders.find(dataSourceUid);
88 auto dataProvider = (it != impl->m_DataProviders.end()) ? it->second : nullptr;
88 auto dataProvider = (it != impl->m_DataProviders.end()) ? it->second : nullptr;
89
89
90 /// @todo retrieve timerange, and pass it to the signal
90 /// @todo retrieve timerange, and pass it to the signal
91 emit variableCreationRequested(productItem.name(), dataProvider);
91 emit variableCreationRequested(productItem.name(), dataProvider);
92 }
92 }
93 else {
93 else {
94 qCWarning(LOG_DataSourceController()) << tr("Can't load an item that is not a product");
94 qCWarning(LOG_DataSourceController()) << tr("Can't load an item that is not a product");
95 }
95 }
96 }
96 }
97
97
98 void DataSourceController::initialize()
98 void DataSourceController::initialize()
99 {
99 {
100 qCDebug(LOG_DataSourceController()) << tr("DataSourceController init")
100 qCDebug(LOG_DataSourceController()) << tr("DataSourceController init")
101 << QThread::currentThread();
101 << QThread::currentThread();
102 impl->m_WorkingMutex.lock();
102 impl->m_WorkingMutex.lock();
103 qCDebug(LOG_DataSourceController()) << tr("DataSourceController init END");
103 qCDebug(LOG_DataSourceController()) << tr("DataSourceController init END");
104 }
104 }
105
105
106 void DataSourceController::finalize()
106 void DataSourceController::finalize()
107 {
107 {
108 impl->m_WorkingMutex.unlock();
108 impl->m_WorkingMutex.unlock();
109 }
109 }
110
110
111 void DataSourceController::waitForFinish()
111 void DataSourceController::waitForFinish()
112 {
112 {
113 QMutexLocker locker{&impl->m_WorkingMutex};
113 QMutexLocker locker{&impl->m_WorkingMutex};
114 }
114 }
@@ -1,86 +1,86
1 #include <DataSource/DataSourceItem.h>
1 #include <DataSource/DataSourceItem.h>
2 #include <DataSource/DataSourceItemAction.h>
2 #include <DataSource/DataSourceItemAction.h>
3
3
4 #include <QVector>
4 #include <QVector>
5
5
6 namespace {
6 namespace {
7
7
8 /// Index of the 'name' value in the item
8 /// Index of the 'name' value in the item
9 const auto NAME_INDEX = 0;
9 const auto NAME_INDEX = 0;
10
10
11 } // namespace
11 } // namespace
12
12
13 struct DataSourceItem::DataSourceItemPrivate {
13 struct DataSourceItem::DataSourceItemPrivate {
14 explicit DataSourceItemPrivate(DataSourceItemType type, QVector<QVariant> data)
14 explicit DataSourceItemPrivate(DataSourceItemType type, QVector<QVariant> data)
15 : m_Parent{nullptr}, m_Children{}, m_Type{type}, m_Data{std::move(data)}, m_Actions{}
15 : m_Parent{nullptr}, m_Children{}, m_Type{type}, m_Data{std::move(data)}, m_Actions{}
16 {
16 {
17 }
17 }
18
18
19 DataSourceItem *m_Parent;
19 DataSourceItem *m_Parent;
20 std::vector<std::unique_ptr<DataSourceItem> > m_Children;
20 std::vector<std::unique_ptr<DataSourceItem> > m_Children;
21 DataSourceItemType m_Type;
21 DataSourceItemType m_Type;
22 QVector<QVariant> m_Data;
22 QVector<QVariant> m_Data;
23 std::vector<std::unique_ptr<DataSourceItemAction> > m_Actions;
23 std::vector<std::unique_ptr<DataSourceItemAction> > m_Actions;
24 };
24 };
25
25
26 DataSourceItem::DataSourceItem(DataSourceItemType type, QVector<QVariant> data)
26 DataSourceItem::DataSourceItem(DataSourceItemType type, QVector<QVariant> data)
27 : impl{spimpl::make_unique_impl<DataSourceItemPrivate>(type, std::move(data))}
27 : impl{spimpl::make_unique_impl<DataSourceItemPrivate>(type, std::move(data))}
28 {
28 {
29 }
29 }
30
30
31 QVector<DataSourceItemAction *> DataSourceItem::actions() const noexcept
31 QVector<DataSourceItemAction *> DataSourceItem::actions() const noexcept
32 {
32 {
33 QVector<DataSourceItemAction *> result{};
33 auto result = QVector<DataSourceItemAction *>{};
34
34
35 std::transform(std::cbegin(impl->m_Actions), std::cend(impl->m_Actions),
35 std::transform(std::cbegin(impl->m_Actions), std::cend(impl->m_Actions),
36 std::back_inserter(result), [](const auto &action) { return action.get(); });
36 std::back_inserter(result), [](const auto &action) { return action.get(); });
37
37
38 return result;
38 return result;
39 }
39 }
40
40
41 void DataSourceItem::addAction(std::unique_ptr<DataSourceItemAction> action) noexcept
41 void DataSourceItem::addAction(std::unique_ptr<DataSourceItemAction> action) noexcept
42 {
42 {
43 action->setDataSourceItem(this);
43 action->setDataSourceItem(this);
44 impl->m_Actions.push_back(std::move(action));
44 impl->m_Actions.push_back(std::move(action));
45 }
45 }
46
46
47 void DataSourceItem::appendChild(std::unique_ptr<DataSourceItem> child) noexcept
47 void DataSourceItem::appendChild(std::unique_ptr<DataSourceItem> child) noexcept
48 {
48 {
49 child->impl->m_Parent = this;
49 child->impl->m_Parent = this;
50 impl->m_Children.push_back(std::move(child));
50 impl->m_Children.push_back(std::move(child));
51 }
51 }
52
52
53 DataSourceItem *DataSourceItem::child(int childIndex) const noexcept
53 DataSourceItem *DataSourceItem::child(int childIndex) const noexcept
54 {
54 {
55 if (childIndex < 0 || childIndex >= childCount()) {
55 if (childIndex < 0 || childIndex >= childCount()) {
56 return nullptr;
56 return nullptr;
57 }
57 }
58 else {
58 else {
59 return impl->m_Children.at(childIndex).get();
59 return impl->m_Children.at(childIndex).get();
60 }
60 }
61 }
61 }
62
62
63 int DataSourceItem::childCount() const noexcept
63 int DataSourceItem::childCount() const noexcept
64 {
64 {
65 return impl->m_Children.size();
65 return impl->m_Children.size();
66 }
66 }
67
67
68 QVariant DataSourceItem::data(int dataIndex) const noexcept
68 QVariant DataSourceItem::data(int dataIndex) const noexcept
69 {
69 {
70 return impl->m_Data.value(dataIndex);
70 return impl->m_Data.value(dataIndex);
71 }
71 }
72
72
73 QString DataSourceItem::name() const noexcept
73 QString DataSourceItem::name() const noexcept
74 {
74 {
75 return data(NAME_INDEX).toString();
75 return data(NAME_INDEX).toString();
76 }
76 }
77
77
78 DataSourceItem *DataSourceItem::parentItem() const noexcept
78 DataSourceItem *DataSourceItem::parentItem() const noexcept
79 {
79 {
80 return impl->m_Parent;
80 return impl->m_Parent;
81 }
81 }
82
82
83 DataSourceItemType DataSourceItem::type() const noexcept
83 DataSourceItemType DataSourceItem::type() const noexcept
84 {
84 {
85 return impl->m_Type;
85 return impl->m_Type;
86 }
86 }
@@ -1,88 +1,91
1 #include <Variable/VariableController.h>
1 #include <Variable/VariableController.h>
2 #include <Variable/VariableModel.h>
2 #include <Variable/VariableModel.h>
3
3
4 #include <Data/DataProviderParameters.h>
4 #include <Data/DataProviderParameters.h>
5 #include <Data/IDataProvider.h>
5 #include <Data/IDataProvider.h>
6 #include <Data/IDataSeries.h>
6 #include <Data/IDataSeries.h>
7
7
8 #include <QDateTime>
8 #include <QDateTime>
9 #include <QMutex>
9 #include <QMutex>
10 #include <QThread>
10 #include <QThread>
11
11
12 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
12 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
13
13
14 namespace {
14 namespace {
15
15
16 /// @todo Generates default dataseries, according to the provider passed in parameter. This method
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
17 /// will be deleted when the timerange is recovered from SciQlop
18 std::unique_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider) noexcept
18 std::unique_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider) noexcept
19 {
19 {
20 auto parameters = DataProviderParameters{
20 auto parameters = DataProviderParameters{
21 static_cast<double>(QDateTime{QDate{2017, 01, 01}}.toSecsSinceEpoch()),
21 // Remarks : we don't use toSecsSinceEpoch() here (method is for Qt 5.8 or above)
22 static_cast<double>(QDateTime{QDate{2017, 01, 03}}.toSecsSinceEpoch())};
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 return provider.retrieveData(parameters);
27 return provider.retrieveData(parameters);
25 }
28 }
26
29
27 } // namespace
30 } // namespace
28
31
29 struct VariableController::VariableControllerPrivate {
32 struct VariableController::VariableControllerPrivate {
30 explicit VariableControllerPrivate(VariableController *parent)
33 explicit VariableControllerPrivate(VariableController *parent)
31 : m_WorkingMutex{}, m_VariableModel{new VariableModel{parent}}
34 : m_WorkingMutex{}, m_VariableModel{new VariableModel{parent}}
32 {
35 {
33 }
36 }
34
37
35 QMutex m_WorkingMutex;
38 QMutex m_WorkingMutex;
36 /// Variable model. The VariableController has the ownership
39 /// Variable model. The VariableController has the ownership
37 VariableModel *m_VariableModel;
40 VariableModel *m_VariableModel;
38 };
41 };
39
42
40 VariableController::VariableController(QObject *parent)
43 VariableController::VariableController(QObject *parent)
41 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
44 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
42 {
45 {
43 qCDebug(LOG_VariableController()) << tr("VariableController construction")
46 qCDebug(LOG_VariableController()) << tr("VariableController construction")
44 << QThread::currentThread();
47 << QThread::currentThread();
45 }
48 }
46
49
47 VariableController::~VariableController()
50 VariableController::~VariableController()
48 {
51 {
49 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
52 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
50 << QThread::currentThread();
53 << QThread::currentThread();
51 this->waitForFinish();
54 this->waitForFinish();
52 }
55 }
53
56
54 VariableModel *VariableController::variableModel() noexcept
57 VariableModel *VariableController::variableModel() noexcept
55 {
58 {
56 return impl->m_VariableModel;
59 return impl->m_VariableModel;
57 }
60 }
58
61
59 void VariableController::createVariable(const QString &name,
62 void VariableController::createVariable(const QString &name,
60 std::shared_ptr<IDataProvider> provider) noexcept
63 std::shared_ptr<IDataProvider> provider) noexcept
61 {
64 {
62 /// @todo : for the moment :
65 /// @todo : for the moment :
63 /// - the provider is only used to retrieve data from the variable for its initialization, but
66 /// - the provider is only used to retrieve data from the variable for its initialization, but
64 /// it will be retained later
67 /// it will be retained later
65 /// - default data are generated for the variable, without taking into account the timerange set
68 /// - default data are generated for the variable, without taking into account the timerange set
66 /// in sciqlop
69 /// in sciqlop
67 if (auto newVariable
70 if (auto newVariable
68 = impl->m_VariableModel->createVariable(name, generateDefaultDataSeries(*provider))) {
71 = impl->m_VariableModel->createVariable(name, generateDefaultDataSeries(*provider))) {
69 emit variableCreated(newVariable);
72 emit variableCreated(newVariable);
70 }
73 }
71 }
74 }
72
75
73 void VariableController::initialize()
76 void VariableController::initialize()
74 {
77 {
75 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
78 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
76 impl->m_WorkingMutex.lock();
79 impl->m_WorkingMutex.lock();
77 qCDebug(LOG_VariableController()) << tr("VariableController init END");
80 qCDebug(LOG_VariableController()) << tr("VariableController init END");
78 }
81 }
79
82
80 void VariableController::finalize()
83 void VariableController::finalize()
81 {
84 {
82 impl->m_WorkingMutex.unlock();
85 impl->m_WorkingMutex.unlock();
83 }
86 }
84
87
85 void VariableController::waitForFinish()
88 void VariableController::waitForFinish()
86 {
89 {
87 QMutexLocker locker{&impl->m_WorkingMutex};
90 QMutexLocker locker{&impl->m_WorkingMutex};
88 }
91 }
@@ -1,13 +1,16
1 # On ignore toutes les règles vera++ pour le fichier spimpl
1 # On ignore toutes les règles vera++ pour le fichier spimpl
2 Common/spimpl\.h:\d+:.*
2 Common/spimpl\.h:\d+:.*
3
3
4 # Ignore false positive relative to two class definitions in a same file
4 # Ignore false positive relative to two class definitions in a same file
5 DataSourceItem\.h:\d+:.*IPSIS_S01.*
5 DataSourceItem\.h:\d+:.*IPSIS_S01.*
6
6
7 # Ignore false positive relative to a template class
7 # Ignore false positive relative to a template class
8 ArrayData\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (D)
8 ArrayData\.h:\d+:.*IPSIS_S04_VARIABLE.*found: (D)
9 ArrayData\.h:\d+:.*IPSIS_S06.*found: (D)
9 ArrayData\.h:\d+:.*IPSIS_S06.*found: (D)
10 ArrayData\.h:\d+:.*IPSIS_S06.*found: (Dim)
10 ArrayData\.h:\d+:.*IPSIS_S06.*found: (Dim)
11
11
12 # Ignore false positive relative to an alias
12 # Ignore false positive relative to an alias
13 DataSourceItemAction\.h:\d+:.*IPSIS_S06.*found: (ExecuteFunction)
13 DataSourceItemAction\.h:\d+:.*IPSIS_S06.*found: (ExecuteFunction)
14
15 # Ignore false positive relative to unnamed namespace
16 VariableController\.cpp:\d+:.*IPSIS_F13.*
General Comments 1
Approved

Status change > Approved

You need to be logged in to leave comments. Login now