@@ -0,0 +1,36 | |||||
|
1 | #ifndef SCIQLOP_AMDAPROVIDER_H | |||
|
2 | #define SCIQLOP_AMDAPROVIDER_H | |||
|
3 | ||||
|
4 | #include "AmdaGlobal.h" | |||
|
5 | ||||
|
6 | #include <Common/spimpl.h> | |||
|
7 | ||||
|
8 | #include <Data/IDataProvider.h> | |||
|
9 | ||||
|
10 | #include <QLoggingCategory> | |||
|
11 | ||||
|
12 | ||||
|
13 | Q_DECLARE_LOGGING_CATEGORY(LOG_AmdaProvider) | |||
|
14 | ||||
|
15 | /** | |||
|
16 | * @brief The AmdaProvider class is an example of how a data provider can generate data | |||
|
17 | */ | |||
|
18 | class SCIQLOP_AMDA_EXPORT AmdaProvider : public IDataProvider { | |||
|
19 | public: | |||
|
20 | explicit AmdaProvider(); | |||
|
21 | ||||
|
22 | void requestDataLoading(QUuid token, const QVector<SqpDateTime> &dateTimeList) override; | |||
|
23 | ||||
|
24 | private: | |||
|
25 | void retrieveData(QUuid token, const DataProviderParameters ¶meters) const; | |||
|
26 | ||||
|
27 | class AmdaProviderPrivate; | |||
|
28 | spimpl::unique_impl_ptr<AmdaProviderPrivate> impl; | |||
|
29 | ||||
|
30 | private slots: | |||
|
31 | void httpFinished() noexcept; | |||
|
32 | void httpDownloadFinished() noexcept; | |||
|
33 | void httpDownloadReadyRead() noexcept; | |||
|
34 | }; | |||
|
35 | ||||
|
36 | #endif // SCIQLOP_AMDAPROVIDER_H |
@@ -0,0 +1,19 | |||||
|
1 | #ifndef SCIQLOP_AMDARESULTPARSER_H | |||
|
2 | #define SCIQLOP_AMDARESULTPARSER_H | |||
|
3 | ||||
|
4 | #include "AmdaGlobal.h" | |||
|
5 | ||||
|
6 | #include <QLoggingCategory> | |||
|
7 | ||||
|
8 | #include <memory> | |||
|
9 | ||||
|
10 | class IDataSeries; | |||
|
11 | ||||
|
12 | Q_DECLARE_LOGGING_CATEGORY(LOG_AmdaResultParser) | |||
|
13 | ||||
|
14 | struct SCIQLOP_AMDA_EXPORT AmdaResultParser { | |||
|
15 | ||||
|
16 | static std::shared_ptr<IDataSeries> readTxt(const QString &filePath) noexcept; | |||
|
17 | }; | |||
|
18 | ||||
|
19 | #endif // SCIQLOP_AMDARESULTPARSER_H |
@@ -0,0 +1,134 | |||||
|
1 | #include "AmdaProvider.h" | |||
|
2 | #include "AmdaResultParser.h" | |||
|
3 | ||||
|
4 | #include <Data/DataProviderParameters.h> | |||
|
5 | ||||
|
6 | #include <QNetworkAccessManager> | |||
|
7 | #include <QNetworkReply> | |||
|
8 | #include <QTemporaryFile> | |||
|
9 | ||||
|
10 | Q_LOGGING_CATEGORY(LOG_AmdaProvider, "AmdaProvider") | |||
|
11 | ||||
|
12 | namespace { | |||
|
13 | ||||
|
14 | /// URL format for a request on AMDA server. The parameters are as follows: | |||
|
15 | /// - %1: start date | |||
|
16 | /// - %2: end date | |||
|
17 | /// - %3: parameter id | |||
|
18 | const auto AMDA_URL_FORMAT = QStringLiteral( | |||
|
19 | "http://amda.irap.omp.eu/php/rest/" | |||
|
20 | "getParameter.php?startTime=%1&stopTime=%2¶meterID=%3&sampling=60&outputFormat=ASCII&" | |||
|
21 | "timeFormat=ISO8601&gzip=0"); | |||
|
22 | ||||
|
23 | /// Dates format passed in the URL (e.g 2013-09-23T09:00) | |||
|
24 | const auto AMDA_TIME_FORMAT = QStringLiteral("yyyy-MM-ddThh:ss"); | |||
|
25 | ||||
|
26 | /// Formats a time to a date that can be passed in URL | |||
|
27 | QString dateFormat(double sqpDateTime) noexcept | |||
|
28 | { | |||
|
29 | auto dateTime = QDateTime::fromMSecsSinceEpoch(sqpDateTime * 1000.); | |||
|
30 | return dateTime.toString(AMDA_TIME_FORMAT); | |||
|
31 | } | |||
|
32 | ||||
|
33 | } // namespace | |||
|
34 | ||||
|
35 | struct AmdaProvider::AmdaProviderPrivate { | |||
|
36 | DataProviderParameters m_Params{}; | |||
|
37 | std::unique_ptr<QNetworkAccessManager> m_AccessManager{nullptr}; | |||
|
38 | QNetworkReply *m_Reply{nullptr}; | |||
|
39 | std::unique_ptr<QTemporaryFile> m_File{nullptr}; | |||
|
40 | QUuid m_Token; | |||
|
41 | }; | |||
|
42 | ||||
|
43 | AmdaProvider::AmdaProvider() : impl{spimpl::make_unique_impl<AmdaProviderPrivate>()} | |||
|
44 | { | |||
|
45 | } | |||
|
46 | ||||
|
47 | void AmdaProvider::requestDataLoading(QUuid token, const QVector<SqpDateTime> &dateTimeList) | |||
|
48 | { | |||
|
49 | // NOTE: Try to use multithread if possible | |||
|
50 | for (const auto &dateTime : dateTimeList) { | |||
|
51 | retrieveData(token, DataProviderParameters{dateTime}); | |||
|
52 | } | |||
|
53 | } | |||
|
54 | ||||
|
55 | void AmdaProvider::retrieveData(QUuid token, const DataProviderParameters ¶meters) const | |||
|
56 | { | |||
|
57 | // /////////// // | |||
|
58 | // Creates URL // | |||
|
59 | // /////////// // | |||
|
60 | ||||
|
61 | auto startDate = dateFormat(parameters.m_Time.m_TStart); | |||
|
62 | auto endDate = dateFormat(parameters.m_Time.m_TEnd); | |||
|
63 | auto productId = QStringLiteral("imf(0)"); | |||
|
64 | ||||
|
65 | auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(startDate, endDate, productId)}; | |||
|
66 | ||||
|
67 | // //////////////// // | |||
|
68 | // Executes request // | |||
|
69 | // //////////////// // | |||
|
70 | ||||
|
71 | impl->m_Token = token; | |||
|
72 | impl->m_Params = parameters; | |||
|
73 | impl->m_AccessManager = std::make_unique<QNetworkAccessManager>(); | |||
|
74 | impl->m_Reply = impl->m_AccessManager->get(QNetworkRequest{url}); | |||
|
75 | connect(impl->m_Reply, &QNetworkReply::finished, this, &AmdaProvider::httpFinished); | |||
|
76 | } | |||
|
77 | ||||
|
78 | void AmdaProvider::httpFinished() noexcept | |||
|
79 | { | |||
|
80 | // ////////////////////// // | |||
|
81 | // Gets download file url // | |||
|
82 | // ////////////////////// // | |||
|
83 | ||||
|
84 | auto downloadFileUrl = QUrl{QString{impl->m_Reply->readAll()}}; | |||
|
85 | ||||
|
86 | // ///////////////////////////////////// // | |||
|
87 | // Executes request for downloading file // | |||
|
88 | // ///////////////////////////////////// // | |||
|
89 | ||||
|
90 | // Deletes old reply | |||
|
91 | impl->m_Reply->deleteLater(); | |||
|
92 | impl->m_Reply = nullptr; | |||
|
93 | ||||
|
94 | // Creates destination file | |||
|
95 | impl->m_File = std::make_unique<QTemporaryFile>(); | |||
|
96 | if (impl->m_File->open()) { | |||
|
97 | qCDebug(LOG_AmdaProvider()) << "Temp file: " << impl->m_File->fileName(); | |||
|
98 | ||||
|
99 | // Executes request | |||
|
100 | impl->m_AccessManager = std::make_unique<QNetworkAccessManager>(); | |||
|
101 | impl->m_Reply = impl->m_AccessManager->get(QNetworkRequest{downloadFileUrl}); | |||
|
102 | connect(impl->m_Reply, &QNetworkReply::finished, this, | |||
|
103 | &AmdaProvider::httpDownloadReadyRead); | |||
|
104 | connect(impl->m_Reply, &QNetworkReply::finished, this, &AmdaProvider::httpDownloadFinished); | |||
|
105 | } | |||
|
106 | } | |||
|
107 | ||||
|
108 | void AmdaProvider::httpDownloadFinished() noexcept | |||
|
109 | { | |||
|
110 | if (impl->m_File) { | |||
|
111 | impl->m_File->close(); | |||
|
112 | ||||
|
113 | // Parse results file | |||
|
114 | if (auto dataSeries = AmdaResultParser::readTxt(impl->m_File->fileName())) { | |||
|
115 | emit dataProvided(impl->m_Token, dataSeries, impl->m_Params.m_Time); | |||
|
116 | } | |||
|
117 | else { | |||
|
118 | /// @todo ALX : debug | |||
|
119 | } | |||
|
120 | ||||
|
121 | impl->m_File = nullptr; | |||
|
122 | } | |||
|
123 | ||||
|
124 | // Deletes reply | |||
|
125 | impl->m_Reply->deleteLater(); | |||
|
126 | impl->m_Reply = nullptr; | |||
|
127 | } | |||
|
128 | ||||
|
129 | void AmdaProvider::httpDownloadReadyRead() noexcept | |||
|
130 | { | |||
|
131 | if (impl->m_File) { | |||
|
132 | impl->m_File->write(impl->m_Reply->readAll()); | |||
|
133 | } | |||
|
134 | } |
@@ -0,0 +1,70 | |||||
|
1 | #include "AmdaResultParser.h" | |||
|
2 | ||||
|
3 | #include <Data/ScalarSeries.h> | |||
|
4 | ||||
|
5 | #include <QDateTime> | |||
|
6 | #include <QFile> | |||
|
7 | ||||
|
8 | Q_LOGGING_CATEGORY(LOG_AmdaResultParser, "AmdaResultParser") | |||
|
9 | ||||
|
10 | namespace { | |||
|
11 | ||||
|
12 | /// Format for dates in result files | |||
|
13 | const auto DATE_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss.zzz"); | |||
|
14 | ||||
|
15 | /// @todo ALX | |||
|
16 | double doubleDate(const QString &stringDate) noexcept | |||
|
17 | { | |||
|
18 | auto dateTime = QDateTime::fromString(stringDate, DATE_FORMAT); | |||
|
19 | return dateTime.toMSecsSinceEpoch() / 1000.; | |||
|
20 | } | |||
|
21 | ||||
|
22 | } // namespace | |||
|
23 | ||||
|
24 | std::shared_ptr<IDataSeries> AmdaResultParser::readTxt(const QString &filePath) noexcept | |||
|
25 | { | |||
|
26 | QFile file{filePath}; | |||
|
27 | ||||
|
28 | if (!file.open(QFile::ReadOnly | QIODevice::Text)) { | |||
|
29 | qCCritical(LOG_AmdaResultParser()) | |||
|
30 | << QObject::tr("Can't retrieve AMDA data from file %1: %2") | |||
|
31 | .arg(filePath, file.errorString()); | |||
|
32 | return nullptr; | |||
|
33 | } | |||
|
34 | ||||
|
35 | auto xData = QVector<double>{}; | |||
|
36 | auto valuesData = QVector<double>{}; | |||
|
37 | ||||
|
38 | QTextStream stream{&file}; | |||
|
39 | ||||
|
40 | // Ignore comment lines (3 lines) | |||
|
41 | stream.readLine(); | |||
|
42 | stream.readLine(); | |||
|
43 | stream.readLine(); | |||
|
44 | ||||
|
45 | QString line{}; | |||
|
46 | auto lineRegex = QRegExp{QStringLiteral("\\s+")}; | |||
|
47 | while (stream.readLineInto(&line)) { | |||
|
48 | auto lineData = line.split(lineRegex, QString::SkipEmptyParts); | |||
|
49 | if (lineData.size() == 2) { | |||
|
50 | // X : the data is converted from date to double (in secs) | |||
|
51 | xData.push_back(doubleDate(lineData.at(0))); | |||
|
52 | ||||
|
53 | // Value | |||
|
54 | valuesData.push_back(lineData.at(1).toDouble()); | |||
|
55 | } | |||
|
56 | else { | |||
|
57 | /// @todo ALX : log | |||
|
58 | } | |||
|
59 | } | |||
|
60 | ||||
|
61 | /// @todo ALX : handle units | |||
|
62 | auto scalarSeries = std::make_shared<ScalarSeries>(xData.size(), Unit{"nT", true}, Unit{}); | |||
|
63 | ||||
|
64 | const auto count = xData.size(); | |||
|
65 | for (auto i = 0; i < count; ++i) { | |||
|
66 | scalarSeries->setData(i, xData.at(i), valuesData.at(i)); | |||
|
67 | } | |||
|
68 | ||||
|
69 | return scalarSeries; | |||
|
70 | } |
@@ -1,164 +1,164 | |||||
1 | <?xml version="1.0" encoding="UTF-8"?> |
|
1 | <?xml version="1.0" encoding="UTF-8"?> | |
2 | <ui version="4.0"> |
|
2 | <ui version="4.0"> | |
3 | <class>MainWindow</class> |
|
3 | <class>MainWindow</class> | |
4 | <widget class="QMainWindow" name="MainWindow"> |
|
4 | <widget class="QMainWindow" name="MainWindow"> | |
5 | <property name="geometry"> |
|
5 | <property name="geometry"> | |
6 | <rect> |
|
6 | <rect> | |
7 | <x>0</x> |
|
7 | <x>0</x> | |
8 | <y>0</y> |
|
8 | <y>0</y> | |
9 | <width>800</width> |
|
9 | <width>800</width> | |
10 | <height>600</height> |
|
10 | <height>600</height> | |
11 | </rect> |
|
11 | </rect> | |
12 | </property> |
|
12 | </property> | |
13 | <property name="windowTitle"> |
|
13 | <property name="windowTitle"> | |
14 |
<string> |
|
14 | <string>SciQlop v0.0.1</string> | |
15 | </property> |
|
15 | </property> | |
16 | <property name="dockNestingEnabled"> |
|
16 | <property name="dockNestingEnabled"> | |
17 | <bool>true</bool> |
|
17 | <bool>true</bool> | |
18 | </property> |
|
18 | </property> | |
19 | <widget class="QWidget" name="centralWidget"> |
|
19 | <widget class="QWidget" name="centralWidget"> | |
20 | <property name="enabled"> |
|
20 | <property name="enabled"> | |
21 | <bool>true</bool> |
|
21 | <bool>true</bool> | |
22 | </property> |
|
22 | </property> | |
23 | <property name="sizePolicy"> |
|
23 | <property name="sizePolicy"> | |
24 | <sizepolicy hsizetype="Minimum" vsizetype="Minimum"> |
|
24 | <sizepolicy hsizetype="Minimum" vsizetype="Minimum"> | |
25 | <horstretch>0</horstretch> |
|
25 | <horstretch>0</horstretch> | |
26 | <verstretch>0</verstretch> |
|
26 | <verstretch>0</verstretch> | |
27 | </sizepolicy> |
|
27 | </sizepolicy> | |
28 | </property> |
|
28 | </property> | |
29 | <property name="maximumSize"> |
|
29 | <property name="maximumSize"> | |
30 | <size> |
|
30 | <size> | |
31 | <width>16777215</width> |
|
31 | <width>16777215</width> | |
32 | <height>16777215</height> |
|
32 | <height>16777215</height> | |
33 | </size> |
|
33 | </size> | |
34 | </property> |
|
34 | </property> | |
35 | <layout class="QHBoxLayout" name="horizontalLayout"> |
|
35 | <layout class="QHBoxLayout" name="horizontalLayout"> | |
36 | <property name="spacing"> |
|
36 | <property name="spacing"> | |
37 | <number>0</number> |
|
37 | <number>0</number> | |
38 | </property> |
|
38 | </property> | |
39 | <property name="leftMargin"> |
|
39 | <property name="leftMargin"> | |
40 | <number>0</number> |
|
40 | <number>0</number> | |
41 | </property> |
|
41 | </property> | |
42 | <property name="topMargin"> |
|
42 | <property name="topMargin"> | |
43 | <number>0</number> |
|
43 | <number>0</number> | |
44 | </property> |
|
44 | </property> | |
45 | <property name="rightMargin"> |
|
45 | <property name="rightMargin"> | |
46 | <number>0</number> |
|
46 | <number>0</number> | |
47 | </property> |
|
47 | </property> | |
48 | <property name="bottomMargin"> |
|
48 | <property name="bottomMargin"> | |
49 | <number>0</number> |
|
49 | <number>0</number> | |
50 | </property> |
|
50 | </property> | |
51 | <item> |
|
51 | <item> | |
52 | <widget class="QSplitter" name="splitter"> |
|
52 | <widget class="QSplitter" name="splitter"> | |
53 | <property name="orientation"> |
|
53 | <property name="orientation"> | |
54 | <enum>Qt::Horizontal</enum> |
|
54 | <enum>Qt::Horizontal</enum> | |
55 | </property> |
|
55 | </property> | |
56 | <widget class="QWidget" name="leftMainInspectorWidget" native="true"> |
|
56 | <widget class="QWidget" name="leftMainInspectorWidget" native="true"> | |
57 | <layout class="QVBoxLayout" name="verticalLayout"> |
|
57 | <layout class="QVBoxLayout" name="verticalLayout"> | |
58 | <property name="spacing"> |
|
58 | <property name="spacing"> | |
59 | <number>0</number> |
|
59 | <number>0</number> | |
60 | </property> |
|
60 | </property> | |
61 | <property name="leftMargin"> |
|
61 | <property name="leftMargin"> | |
62 | <number>0</number> |
|
62 | <number>0</number> | |
63 | </property> |
|
63 | </property> | |
64 | <property name="topMargin"> |
|
64 | <property name="topMargin"> | |
65 | <number>0</number> |
|
65 | <number>0</number> | |
66 | </property> |
|
66 | </property> | |
67 | <property name="rightMargin"> |
|
67 | <property name="rightMargin"> | |
68 | <number>0</number> |
|
68 | <number>0</number> | |
69 | </property> |
|
69 | </property> | |
70 | <property name="bottomMargin"> |
|
70 | <property name="bottomMargin"> | |
71 | <number>0</number> |
|
71 | <number>0</number> | |
72 | </property> |
|
72 | </property> | |
73 | <item> |
|
73 | <item> | |
74 | <widget class="DataSourceWidget" name="dataSourceWidget" native="true"/> |
|
74 | <widget class="DataSourceWidget" name="dataSourceWidget" native="true"/> | |
75 | </item> |
|
75 | </item> | |
76 | <item> |
|
76 | <item> | |
77 | <widget class="QWidget" name="dateTimeWidget" native="true"/> |
|
77 | <widget class="QWidget" name="dateTimeWidget" native="true"/> | |
78 | </item> |
|
78 | </item> | |
79 | <item> |
|
79 | <item> | |
80 | <widget class="VariableInspectorWidget" name="variableInspectorWidget" native="true"/> |
|
80 | <widget class="VariableInspectorWidget" name="variableInspectorWidget" native="true"/> | |
81 | </item> |
|
81 | </item> | |
82 | </layout> |
|
82 | </layout> | |
83 | </widget> |
|
83 | </widget> | |
84 | <widget class="SqpSidePane" name="leftInspectorSidePane" native="true"/> |
|
84 | <widget class="SqpSidePane" name="leftInspectorSidePane" native="true"/> | |
85 | <widget class="VisualizationWidget" name="view" native="true"> |
|
85 | <widget class="VisualizationWidget" name="view" native="true"> | |
86 | <property name="sizePolicy"> |
|
86 | <property name="sizePolicy"> | |
87 | <sizepolicy hsizetype="Expanding" vsizetype="Preferred"> |
|
87 | <sizepolicy hsizetype="Expanding" vsizetype="Preferred"> | |
88 | <horstretch>0</horstretch> |
|
88 | <horstretch>0</horstretch> | |
89 | <verstretch>0</verstretch> |
|
89 | <verstretch>0</verstretch> | |
90 | </sizepolicy> |
|
90 | </sizepolicy> | |
91 | </property> |
|
91 | </property> | |
92 | </widget> |
|
92 | </widget> | |
93 | <widget class="SqpSidePane" name="rightInspectorSidePane" native="true"/> |
|
93 | <widget class="SqpSidePane" name="rightInspectorSidePane" native="true"/> | |
94 | <widget class="QWidget" name="rightMainInspectorWidget" native="true"> |
|
94 | <widget class="QWidget" name="rightMainInspectorWidget" native="true"> | |
95 | <layout class="QVBoxLayout" name="verticalLayout_3"> |
|
95 | <layout class="QVBoxLayout" name="verticalLayout_3"> | |
96 | <property name="spacing"> |
|
96 | <property name="spacing"> | |
97 | <number>0</number> |
|
97 | <number>0</number> | |
98 | </property> |
|
98 | </property> | |
99 | <property name="leftMargin"> |
|
99 | <property name="leftMargin"> | |
100 | <number>0</number> |
|
100 | <number>0</number> | |
101 | </property> |
|
101 | </property> | |
102 | <property name="topMargin"> |
|
102 | <property name="topMargin"> | |
103 | <number>0</number> |
|
103 | <number>0</number> | |
104 | </property> |
|
104 | </property> | |
105 | <property name="rightMargin"> |
|
105 | <property name="rightMargin"> | |
106 | <number>0</number> |
|
106 | <number>0</number> | |
107 | </property> |
|
107 | </property> | |
108 | <property name="bottomMargin"> |
|
108 | <property name="bottomMargin"> | |
109 | <number>0</number> |
|
109 | <number>0</number> | |
110 | </property> |
|
110 | </property> | |
111 | <item> |
|
111 | <item> | |
112 | <widget class="QWidget" name="commonPropertyInspectorWidget" native="true"/> |
|
112 | <widget class="QWidget" name="commonPropertyInspectorWidget" native="true"/> | |
113 | </item> |
|
113 | </item> | |
114 | <item> |
|
114 | <item> | |
115 | <widget class="DataSourceWidget" name="catalogWidget" native="true"/> |
|
115 | <widget class="DataSourceWidget" name="catalogWidget" native="true"/> | |
116 | </item> |
|
116 | </item> | |
117 | </layout> |
|
117 | </layout> | |
118 | </widget> |
|
118 | </widget> | |
119 | </widget> |
|
119 | </widget> | |
120 | </item> |
|
120 | </item> | |
121 | </layout> |
|
121 | </layout> | |
122 | </widget> |
|
122 | </widget> | |
123 | <widget class="QMenuBar" name="menuBar"> |
|
123 | <widget class="QMenuBar" name="menuBar"> | |
124 | <property name="geometry"> |
|
124 | <property name="geometry"> | |
125 | <rect> |
|
125 | <rect> | |
126 | <x>0</x> |
|
126 | <x>0</x> | |
127 | <y>0</y> |
|
127 | <y>0</y> | |
128 | <width>800</width> |
|
128 | <width>800</width> | |
129 |
<height>2 |
|
129 | <height>28</height> | |
130 | </rect> |
|
130 | </rect> | |
131 | </property> |
|
131 | </property> | |
132 | </widget> |
|
132 | </widget> | |
133 | <widget class="QStatusBar" name="statusBar"/> |
|
133 | <widget class="QStatusBar" name="statusBar"/> | |
134 | </widget> |
|
134 | </widget> | |
135 | <layoutdefault spacing="6" margin="11"/> |
|
135 | <layoutdefault spacing="6" margin="11"/> | |
136 | <customwidgets> |
|
136 | <customwidgets> | |
137 | <customwidget> |
|
137 | <customwidget> | |
138 | <class>VisualizationWidget</class> |
|
138 | <class>VisualizationWidget</class> | |
139 | <extends>QWidget</extends> |
|
139 | <extends>QWidget</extends> | |
140 | <header location="global">Visualization/VisualizationWidget.h</header> |
|
140 | <header location="global">Visualization/VisualizationWidget.h</header> | |
141 | <container>1</container> |
|
141 | <container>1</container> | |
142 | </customwidget> |
|
142 | </customwidget> | |
143 | <customwidget> |
|
143 | <customwidget> | |
144 | <class>SqpSidePane</class> |
|
144 | <class>SqpSidePane</class> | |
145 | <extends>QWidget</extends> |
|
145 | <extends>QWidget</extends> | |
146 | <header location="global">SidePane/SqpSidePane.h</header> |
|
146 | <header location="global">SidePane/SqpSidePane.h</header> | |
147 | <container>1</container> |
|
147 | <container>1</container> | |
148 | </customwidget> |
|
148 | </customwidget> | |
149 | <customwidget> |
|
149 | <customwidget> | |
150 | <class>DataSourceWidget</class> |
|
150 | <class>DataSourceWidget</class> | |
151 | <extends>QWidget</extends> |
|
151 | <extends>QWidget</extends> | |
152 | <header location="global">DataSource/DataSourceWidget.h</header> |
|
152 | <header location="global">DataSource/DataSourceWidget.h</header> | |
153 | <container>1</container> |
|
153 | <container>1</container> | |
154 | </customwidget> |
|
154 | </customwidget> | |
155 | <customwidget> |
|
155 | <customwidget> | |
156 | <class>VariableInspectorWidget</class> |
|
156 | <class>VariableInspectorWidget</class> | |
157 | <extends>QWidget</extends> |
|
157 | <extends>QWidget</extends> | |
158 | <header location="global">Variable/VariableInspectorWidget.h</header> |
|
158 | <header location="global">Variable/VariableInspectorWidget.h</header> | |
159 | <container>1</container> |
|
159 | <container>1</container> | |
160 | </customwidget> |
|
160 | </customwidget> | |
161 | </customwidgets> |
|
161 | </customwidgets> | |
162 | <resources/> |
|
162 | <resources/> | |
163 | <connections/> |
|
163 | <connections/> | |
164 | </ui> |
|
164 | </ui> |
@@ -1,38 +1,40 | |||||
1 | #ifndef SCIQLOP_IDATAPROVIDER_H |
|
1 | #ifndef SCIQLOP_IDATAPROVIDER_H | |
2 | #define SCIQLOP_IDATAPROVIDER_H |
|
2 | #define SCIQLOP_IDATAPROVIDER_H | |
3 |
|
3 | |||
4 | #include <memory> |
|
4 | #include <memory> | |
5 |
|
5 | |||
6 | #include <QObject> |
|
6 | #include <QObject> | |
|
7 | #include <QUuid> | |||
7 |
|
8 | |||
8 | #include <Common/MetaTypes.h> |
|
9 | #include <Common/MetaTypes.h> | |
9 |
|
10 | |||
10 | #include <Data/SqpDateTime.h> |
|
11 | #include <Data/SqpDateTime.h> | |
11 |
|
12 | |||
12 | class DataProviderParameters; |
|
13 | class DataProviderParameters; | |
13 | class IDataSeries; |
|
14 | class IDataSeries; | |
14 |
|
15 | |||
15 | /** |
|
16 | /** | |
16 | * @brief The IDataProvider interface aims to declare a data provider. |
|
17 | * @brief The IDataProvider interface aims to declare a data provider. | |
17 | * |
|
18 | * | |
18 | * A data provider is an entity that generates data and returns it according to various parameters |
|
19 | * A data provider is an entity that generates data and returns it according to various parameters | |
19 | * (time interval, product to retrieve the data, etc.) |
|
20 | * (time interval, product to retrieve the data, etc.) | |
20 | * |
|
21 | * | |
21 | * @sa IDataSeries |
|
22 | * @sa IDataSeries | |
22 | */ |
|
23 | */ | |
23 | class IDataProvider : public QObject { |
|
24 | class IDataProvider : public QObject { | |
24 |
|
25 | |||
25 | Q_OBJECT |
|
26 | Q_OBJECT | |
26 | public: |
|
27 | public: | |
27 | virtual ~IDataProvider() noexcept = default; |
|
28 | virtual ~IDataProvider() noexcept = default; | |
28 |
|
29 | |||
29 | virtual void requestDataLoading(const QVector<SqpDateTime> &dateTimeList) = 0; |
|
30 | virtual void requestDataLoading(QUuid token, const QVector<SqpDateTime> &dateTimeList) = 0; | |
30 |
|
31 | |||
31 | signals: |
|
32 | signals: | |
32 |
void dataProvided(std::shared_ptr<IDataSeries> dateSerie, |
|
33 | void dataProvided(QUuid token, std::shared_ptr<IDataSeries> dateSerie, | |
|
34 | const SqpDateTime &dateTime); | |||
33 | }; |
|
35 | }; | |
34 |
|
36 | |||
35 | // Required for using shared_ptr in signals/slots |
|
37 | // Required for using shared_ptr in signals/slots | |
36 | SCIQLOP_REGISTER_META_TYPE(IDATAPROVIDER_PTR_REGISTRY, std::shared_ptr<IDataProvider>) |
|
38 | SCIQLOP_REGISTER_META_TYPE(IDATAPROVIDER_PTR_REGISTRY, std::shared_ptr<IDataProvider>) | |
37 |
|
39 | |||
38 | #endif // SCIQLOP_IDATAPROVIDER_H |
|
40 | #endif // SCIQLOP_IDATAPROVIDER_H |
@@ -1,197 +1,205 | |||||
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 <QtCore/QItemSelectionModel> |
|
15 | #include <QtCore/QItemSelectionModel> | |
15 |
|
16 | |||
16 | #include <unordered_map> |
|
17 | #include <unordered_map> | |
17 |
|
18 | |||
18 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") |
|
19 | Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController") | |
19 |
|
20 | |||
20 | struct VariableController::VariableControllerPrivate { |
|
21 | struct VariableController::VariableControllerPrivate { | |
21 | explicit VariableControllerPrivate(VariableController *parent) |
|
22 | explicit VariableControllerPrivate(VariableController *parent) | |
22 | : m_WorkingMutex{}, |
|
23 | : m_WorkingMutex{}, | |
23 | m_VariableModel{new VariableModel{parent}}, |
|
24 | m_VariableModel{new VariableModel{parent}}, | |
24 | m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}}, |
|
25 | m_VariableSelectionModel{new QItemSelectionModel{m_VariableModel, parent}}, | |
25 | m_VariableCacheController{std::make_unique<VariableCacheController>()} |
|
26 | m_VariableCacheController{std::make_unique<VariableCacheController>()} | |
26 | { |
|
27 | { | |
27 | } |
|
28 | } | |
28 |
|
29 | |||
29 | QMutex m_WorkingMutex; |
|
30 | QMutex m_WorkingMutex; | |
30 | /// Variable model. The VariableController has the ownership |
|
31 | /// Variable model. The VariableController has the ownership | |
31 | VariableModel *m_VariableModel; |
|
32 | VariableModel *m_VariableModel; | |
32 | QItemSelectionModel *m_VariableSelectionModel; |
|
33 | QItemSelectionModel *m_VariableSelectionModel; | |
33 |
|
34 | |||
34 |
|
35 | |||
35 | TimeController *m_TimeController{nullptr}; |
|
36 | TimeController *m_TimeController{nullptr}; | |
36 | std::unique_ptr<VariableCacheController> m_VariableCacheController; |
|
37 | std::unique_ptr<VariableCacheController> m_VariableCacheController; | |
37 |
|
38 | |||
38 | std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > |
|
39 | std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> > | |
39 | m_VariableToProviderMap; |
|
40 | m_VariableToProviderMap; | |
|
41 | std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToToken; | |||
40 | }; |
|
42 | }; | |
41 |
|
43 | |||
42 | VariableController::VariableController(QObject *parent) |
|
44 | VariableController::VariableController(QObject *parent) | |
43 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} |
|
45 | : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)} | |
44 | { |
|
46 | { | |
45 | qCDebug(LOG_VariableController()) << tr("VariableController construction") |
|
47 | qCDebug(LOG_VariableController()) << tr("VariableController construction") | |
46 | << QThread::currentThread(); |
|
48 | << QThread::currentThread(); | |
47 | } |
|
49 | } | |
48 |
|
50 | |||
49 | VariableController::~VariableController() |
|
51 | VariableController::~VariableController() | |
50 | { |
|
52 | { | |
51 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") |
|
53 | qCDebug(LOG_VariableController()) << tr("VariableController destruction") | |
52 | << QThread::currentThread(); |
|
54 | << QThread::currentThread(); | |
53 | this->waitForFinish(); |
|
55 | this->waitForFinish(); | |
54 | } |
|
56 | } | |
55 |
|
57 | |||
56 | VariableModel *VariableController::variableModel() noexcept |
|
58 | VariableModel *VariableController::variableModel() noexcept | |
57 | { |
|
59 | { | |
58 | return impl->m_VariableModel; |
|
60 | return impl->m_VariableModel; | |
59 | } |
|
61 | } | |
60 |
|
62 | |||
61 | QItemSelectionModel *VariableController::variableSelectionModel() noexcept |
|
63 | QItemSelectionModel *VariableController::variableSelectionModel() noexcept | |
62 | { |
|
64 | { | |
63 | return impl->m_VariableSelectionModel; |
|
65 | return impl->m_VariableSelectionModel; | |
64 | } |
|
66 | } | |
65 |
|
67 | |||
66 | void VariableController::setTimeController(TimeController *timeController) noexcept |
|
68 | void VariableController::setTimeController(TimeController *timeController) noexcept | |
67 | { |
|
69 | { | |
68 | impl->m_TimeController = timeController; |
|
70 | impl->m_TimeController = timeController; | |
69 | } |
|
71 | } | |
70 |
|
72 | |||
71 | void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept |
|
73 | void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept | |
72 | { |
|
74 | { | |
73 | if (!variable) { |
|
75 | if (!variable) { | |
74 | qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null"; |
|
76 | qCCritical(LOG_VariableController()) << "Can't delete variable: variable is null"; | |
75 | return; |
|
77 | return; | |
76 | } |
|
78 | } | |
77 |
|
79 | |||
78 | // 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 | |
79 | // make some treatments before the deletion |
|
81 | // make some treatments before the deletion | |
80 | emit variableAboutToBeDeleted(variable); |
|
82 | emit variableAboutToBeDeleted(variable); | |
81 |
|
83 | |||
82 | // Deletes provider |
|
84 | // Deletes provider | |
83 | auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable); |
|
85 | auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable); | |
84 | qCDebug(LOG_VariableController()) |
|
86 | qCDebug(LOG_VariableController()) | |
85 | << tr("Number of providers deleted for variable %1: %2") |
|
87 | << tr("Number of providers deleted for variable %1: %2") | |
86 | .arg(variable->name(), QString::number(nbProvidersDeleted)); |
|
88 | .arg(variable->name(), QString::number(nbProvidersDeleted)); | |
87 |
|
89 | |||
88 | // Clears cache |
|
90 | // Clears cache | |
89 | impl->m_VariableCacheController->clear(variable); |
|
91 | impl->m_VariableCacheController->clear(variable); | |
90 |
|
92 | |||
91 | // Deletes from model |
|
93 | // Deletes from model | |
92 | impl->m_VariableModel->deleteVariable(variable); |
|
94 | impl->m_VariableModel->deleteVariable(variable); | |
93 | } |
|
95 | } | |
94 |
|
96 | |||
95 | void VariableController::deleteVariables( |
|
97 | void VariableController::deleteVariables( | |
96 | const QVector<std::shared_ptr<Variable> > &variables) noexcept |
|
98 | const QVector<std::shared_ptr<Variable> > &variables) noexcept | |
97 | { |
|
99 | { | |
98 | for (auto variable : qAsConst(variables)) { |
|
100 | for (auto variable : qAsConst(variables)) { | |
99 | deleteVariable(variable); |
|
101 | deleteVariable(variable); | |
100 | } |
|
102 | } | |
101 | } |
|
103 | } | |
102 |
|
104 | |||
103 | void VariableController::createVariable(const QString &name, |
|
105 | void VariableController::createVariable(const QString &name, | |
104 | std::shared_ptr<IDataProvider> provider) noexcept |
|
106 | std::shared_ptr<IDataProvider> provider) noexcept | |
105 | { |
|
107 | { | |
106 |
|
108 | |||
107 | if (!impl->m_TimeController) { |
|
109 | if (!impl->m_TimeController) { | |
108 | qCCritical(LOG_VariableController()) |
|
110 | qCCritical(LOG_VariableController()) | |
109 | << tr("Impossible to create variable: The time controller is null"); |
|
111 | << tr("Impossible to create variable: The time controller is null"); | |
110 | return; |
|
112 | return; | |
111 | } |
|
113 | } | |
112 |
|
114 | |||
113 |
|
115 | |||
114 | /// @todo : for the moment : |
|
116 | /// @todo : for the moment : | |
115 | /// - 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 | |
116 | /// it will be retained later |
|
118 | /// it will be retained later | |
117 | /// - 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 | |
118 | /// in sciqlop |
|
120 | /// in sciqlop | |
119 | auto dateTime = impl->m_TimeController->dateTime(); |
|
121 | auto dateTime = impl->m_TimeController->dateTime(); | |
120 | if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime)) { |
|
122 | if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime)) { | |
|
123 | auto token = QUuid::createUuid(); | |||
121 |
|
124 | |||
122 | // store the provider |
|
125 | // store the provider | |
123 | impl->m_VariableToProviderMap[newVariable] = provider; |
|
126 | impl->m_VariableToProviderMap[newVariable] = provider; | |
|
127 | impl->m_VariableToToken[newVariable] = token; | |||
124 |
|
128 | |||
125 | auto addDateTimeAcquired = [ this, varW = std::weak_ptr<Variable>{newVariable} ]( |
|
129 | auto addDateTimeAcquired = [ this, varW = std::weak_ptr<Variable>{newVariable} ]( | |
126 | auto dataSeriesAcquired, auto dateTimeToPutInCache) |
|
130 | QUuid token, auto dataSeriesAcquired, auto dateTimeToPutInCache) | |
127 | { |
|
131 | { | |
128 | if (auto variable = varW.lock()) { |
|
132 | if (auto variable = varW.lock()) { | |
129 | impl->m_VariableCacheController->addDateTime(variable, dateTimeToPutInCache); |
|
133 | auto varToken = impl->m_VariableToToken.at(variable); | |
130 | variable->setDataSeries(dataSeriesAcquired); |
|
134 | if (varToken == token) { | |
|
135 | impl->m_VariableCacheController->addDateTime(variable, dateTimeToPutInCache); | |||
|
136 | variable->setDataSeries(dataSeriesAcquired); | |||
|
137 | } | |||
131 | } |
|
138 | } | |
132 | }; |
|
139 | }; | |
133 |
|
140 | |||
134 | connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired); |
|
141 | connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired); | |
135 | this->onRequestDataLoading(newVariable, dateTime); |
|
142 | this->onRequestDataLoading(newVariable, dateTime); | |
136 | } |
|
143 | } | |
137 | } |
|
144 | } | |
138 |
|
145 | |||
139 | void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime) |
|
146 | void VariableController::onDateTimeOnSelection(const SqpDateTime &dateTime) | |
140 | { |
|
147 | { | |
141 | qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection" |
|
148 | qCDebug(LOG_VariableController()) << "VariableController::onDateTimeOnSelection" | |
142 | << QThread::currentThread()->objectName(); |
|
149 | << QThread::currentThread()->objectName(); | |
143 | auto selectedRows = impl->m_VariableSelectionModel->selectedRows(); |
|
150 | auto selectedRows = impl->m_VariableSelectionModel->selectedRows(); | |
144 |
|
151 | |||
145 | for (const auto &selectedRow : qAsConst(selectedRows)) { |
|
152 | for (const auto &selectedRow : qAsConst(selectedRows)) { | |
146 | if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) { |
|
153 | if (auto selectedVariable = impl->m_VariableModel->variable(selectedRow.row())) { | |
147 | selectedVariable->setDateTime(dateTime); |
|
154 | selectedVariable->setDateTime(dateTime); | |
148 | this->onRequestDataLoading(selectedVariable, dateTime); |
|
155 | this->onRequestDataLoading(selectedVariable, dateTime); | |
149 | } |
|
156 | } | |
150 | } |
|
157 | } | |
151 | } |
|
158 | } | |
152 |
|
159 | |||
153 |
|
160 | |||
154 | void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable, |
|
161 | void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable, | |
155 | const SqpDateTime &dateTime) |
|
162 | const SqpDateTime &dateTime) | |
156 | { |
|
163 | { | |
157 | qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading" |
|
164 | qCDebug(LOG_VariableController()) << "VariableController::onRequestDataLoading" | |
158 | << QThread::currentThread()->objectName(); |
|
165 | << QThread::currentThread()->objectName(); | |
159 | // we want to load data of the variable for the dateTime. |
|
166 | // we want to load data of the variable for the dateTime. | |
160 | // First we check if the cache contains some of them. |
|
167 | // First we check if the cache contains some of them. | |
161 | // For the other, we ask the provider to give them. |
|
168 | // For the other, we ask the provider to give them. | |
162 | if (variable) { |
|
169 | if (variable) { | |
163 |
|
170 | |||
164 | auto dateTimeListNotInCache |
|
171 | auto dateTimeListNotInCache | |
165 | = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime); |
|
172 | = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime); | |
166 |
|
173 | |||
167 | if (!dateTimeListNotInCache.empty()) { |
|
174 | if (!dateTimeListNotInCache.empty()) { | |
168 | // Ask the provider for each data on the dateTimeListNotInCache |
|
175 | // Ask the provider for each data on the dateTimeListNotInCache | |
|
176 | auto token = impl->m_VariableToToken.at(variable); | |||
169 | impl->m_VariableToProviderMap.at(variable)->requestDataLoading( |
|
177 | impl->m_VariableToProviderMap.at(variable)->requestDataLoading( | |
170 | std::move(dateTimeListNotInCache)); |
|
178 | token, std::move(dateTimeListNotInCache)); | |
171 | } |
|
179 | } | |
172 | else { |
|
180 | else { | |
173 | emit variable->updated(); |
|
181 | emit variable->updated(); | |
174 | } |
|
182 | } | |
175 | } |
|
183 | } | |
176 | else { |
|
184 | else { | |
177 | qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null"); |
|
185 | qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null"); | |
178 | } |
|
186 | } | |
179 | } |
|
187 | } | |
180 |
|
188 | |||
181 |
|
189 | |||
182 | void VariableController::initialize() |
|
190 | void VariableController::initialize() | |
183 | { |
|
191 | { | |
184 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); |
|
192 | qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread(); | |
185 | impl->m_WorkingMutex.lock(); |
|
193 | impl->m_WorkingMutex.lock(); | |
186 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); |
|
194 | qCDebug(LOG_VariableController()) << tr("VariableController init END"); | |
187 | } |
|
195 | } | |
188 |
|
196 | |||
189 | void VariableController::finalize() |
|
197 | void VariableController::finalize() | |
190 | { |
|
198 | { | |
191 | impl->m_WorkingMutex.unlock(); |
|
199 | impl->m_WorkingMutex.unlock(); | |
192 | } |
|
200 | } | |
193 |
|
201 | |||
194 | void VariableController::waitForFinish() |
|
202 | void VariableController::waitForFinish() | |
195 | { |
|
203 | { | |
196 | QMutexLocker locker{&impl->m_WorkingMutex}; |
|
204 | QMutexLocker locker{&impl->m_WorkingMutex}; | |
197 | } |
|
205 | } |
@@ -1,167 +1,167 | |||||
1 | ## amda - CMakeLists.txt |
|
1 | ## amda - CMakeLists.txt | |
2 | STRING(TOLOWER ${CMAKE_PROJECT_NAME} LIBRARY_PREFFIX) |
|
2 | STRING(TOLOWER ${CMAKE_PROJECT_NAME} LIBRARY_PREFFIX) | |
3 | SET(SQPAMDA_LIBRARY_NAME "${LIBRARY_PREFFIX}_amda${DEBUG_SUFFIX}") |
|
3 | SET(SQPAMDA_LIBRARY_NAME "${LIBRARY_PREFFIX}_amda${DEBUG_SUFFIX}") | |
4 | SET(SOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src") |
|
4 | SET(SOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src") | |
5 | SET(INCLUDES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include") |
|
5 | SET(INCLUDES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include") | |
6 | SET(RESOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/resources") |
|
6 | SET(RESOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/resources") | |
7 | SET(TESTS_RESOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests-resources") |
|
7 | SET(TESTS_RESOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests-resources") | |
8 |
|
8 | |||
9 | # Include amda directory |
|
9 | # Include amda directory | |
10 | INCLUDE_DIRECTORIES(${INCLUDES_DIR}) |
|
10 | INCLUDE_DIRECTORIES(${INCLUDES_DIR}) | |
11 | INCLUDE_DIRECTORIES(${RESOURCES_DIR}) |
|
11 | INCLUDE_DIRECTORIES(${RESOURCES_DIR}) | |
12 |
|
12 | |||
13 | # |
|
13 | # | |
14 | # Find Qt modules |
|
14 | # Find Qt modules | |
15 | # |
|
15 | # | |
16 | SCIQLOP_FIND_QT(Core Widgets) |
|
16 | SCIQLOP_FIND_QT(Core Widgets Network) | |
17 |
|
17 | |||
18 | # |
|
18 | # | |
19 | # Find dependent libraries |
|
19 | # Find dependent libraries | |
20 | # ======================== |
|
20 | # ======================== | |
21 |
|
21 | |||
22 | # sciqlop plugin |
|
22 | # sciqlop plugin | |
23 | find_package(sciqlop-plugin) |
|
23 | find_package(sciqlop-plugin) | |
24 | INCLUDE_DIRECTORIES(${SCIQLOP-PLUGIN_INCLUDE_DIR}) |
|
24 | INCLUDE_DIRECTORIES(${SCIQLOP-PLUGIN_INCLUDE_DIR}) | |
25 |
|
25 | |||
26 | # sciqlop core |
|
26 | # sciqlop core | |
27 | find_package(sciqlop-core) |
|
27 | find_package(sciqlop-core) | |
28 | INCLUDE_DIRECTORIES(${SCIQLOP-CORE_INCLUDE_DIR}) |
|
28 | INCLUDE_DIRECTORIES(${SCIQLOP-CORE_INCLUDE_DIR}) | |
29 | list(APPEND LIBRARIES ${SCIQLOP-CORE_LIBRARIES}) |
|
29 | list(APPEND LIBRARIES ${SCIQLOP-CORE_LIBRARIES}) | |
30 |
|
30 | |||
31 | # sciqlop gui |
|
31 | # sciqlop gui | |
32 | find_package(sciqlop-gui) |
|
32 | find_package(sciqlop-gui) | |
33 | INCLUDE_DIRECTORIES(${SCIQLOP-GUI_INCLUDE_DIR}) |
|
33 | INCLUDE_DIRECTORIES(${SCIQLOP-GUI_INCLUDE_DIR}) | |
34 | list(APPEND LIBRARIES ${SCIQLOP-GUI_LIBRARIES}) |
|
34 | list(APPEND LIBRARIES ${SCIQLOP-GUI_LIBRARIES}) | |
35 |
|
35 | |||
36 | # Description file |
|
36 | # Description file | |
37 | FILE (GLOB_RECURSE PLUGIN_FILE ${RESOURCES_DIR}/amda.json) |
|
37 | FILE (GLOB_RECURSE PLUGIN_FILE ${RESOURCES_DIR}/amda.json) | |
38 |
|
38 | |||
39 | # Resources files |
|
39 | # Resources files | |
40 | FILE (GLOB_RECURSE PROJECT_RESOURCES ${RESOURCES_DIR}/*.qrc) |
|
40 | FILE (GLOB_RECURSE PROJECT_RESOURCES ${RESOURCES_DIR}/*.qrc) | |
41 |
|
41 | |||
42 | # |
|
42 | # | |
43 | # Compile the library |
|
43 | # Compile the library | |
44 | # |
|
44 | # | |
45 |
|
45 | |||
46 | ADD_DEFINITIONS(-DAMDA_LIB) |
|
46 | ADD_DEFINITIONS(-DAMDA_LIB) | |
47 |
|
47 | |||
48 | FILE (GLOB_RECURSE MODULE_SOURCES |
|
48 | FILE (GLOB_RECURSE MODULE_SOURCES | |
49 | ${INCLUDES_DIR}/*.h |
|
49 | ${INCLUDES_DIR}/*.h | |
50 | ${SOURCES_DIR}/*.c |
|
50 | ${SOURCES_DIR}/*.c | |
51 | ${SOURCES_DIR}/*.cpp |
|
51 | ${SOURCES_DIR}/*.cpp | |
52 | ${SOURCES_DIR}/*.h |
|
52 | ${SOURCES_DIR}/*.h | |
53 | ${PLUGIN_FILE}) |
|
53 | ${PLUGIN_FILE}) | |
54 |
|
54 | |||
55 | QT5_ADD_RESOURCES(RCC_AMDA |
|
55 | QT5_ADD_RESOURCES(RCC_AMDA | |
56 | ${PROJECT_RESOURCES} |
|
56 | ${PROJECT_RESOURCES} | |
57 | ) |
|
57 | ) | |
58 |
|
58 | |||
59 | ADD_LIBRARY(${SQPAMDA_LIBRARY_NAME} ${MODULE_SOURCES} ${RCC_AMDA}) |
|
59 | ADD_LIBRARY(${SQPAMDA_LIBRARY_NAME} ${MODULE_SOURCES} ${RCC_AMDA}) | |
60 | set_property(TARGET ${SQPAMDA_LIBRARY_NAME} PROPERTY CXX_STANDARD 14) |
|
60 | set_property(TARGET ${SQPAMDA_LIBRARY_NAME} PROPERTY CXX_STANDARD 14) | |
61 | set_property(TARGET ${SQPAMDA_LIBRARY_NAME} PROPERTY CXX_STANDARD_REQUIRED ON) |
|
61 | set_property(TARGET ${SQPAMDA_LIBRARY_NAME} PROPERTY CXX_STANDARD_REQUIRED ON) | |
62 |
|
62 | |||
63 | INSTALL(TARGETS ${SQPAMDA_LIBRARY_NAME} |
|
63 | INSTALL(TARGETS ${SQPAMDA_LIBRARY_NAME} | |
64 | RUNTIME DESTINATION ${INSTALL_BINARY_DIR} |
|
64 | RUNTIME DESTINATION ${INSTALL_BINARY_DIR} | |
65 | LIBRARY DESTINATION ${INSTALL_PLUGINS_LIBRARY_DIR} |
|
65 | LIBRARY DESTINATION ${INSTALL_PLUGINS_LIBRARY_DIR} | |
66 | ARCHIVE DESTINATION ${INSTALL_PLUGINS_LIBRARY_DIR} |
|
66 | ARCHIVE DESTINATION ${INSTALL_PLUGINS_LIBRARY_DIR} | |
67 | ) |
|
67 | ) | |
68 |
|
68 | |||
69 |
|
69 | |||
70 | TARGET_LINK_LIBRARIES(${SQPAMDA_LIBRARY_NAME} ${LIBRARIES}) |
|
70 | TARGET_LINK_LIBRARIES(${SQPAMDA_LIBRARY_NAME} ${LIBRARIES}) | |
71 | qt5_use_modules(${SQPAMDA_LIBRARY_NAME} Core Widgets) |
|
71 | qt5_use_modules(${SQPAMDA_LIBRARY_NAME} Core Widgets Network) | |
72 |
|
72 | |||
73 | add_dependencies(${SQPAMDA_LIBRARY_NAME} ${SQPPLUGIN_LIBRARY_NAME} ${SQPGUI_LIBRARY_NAME} ${SQPCORE_LIBRARY_NAME}) |
|
73 | add_dependencies(${SQPAMDA_LIBRARY_NAME} ${SQPPLUGIN_LIBRARY_NAME} ${SQPGUI_LIBRARY_NAME} ${SQPCORE_LIBRARY_NAME}) | |
74 |
|
74 | |||
75 | # From cmake documentation: http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html |
|
75 | # From cmake documentation: http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html | |
76 | # Entries in the COMPILE_DEFINITIONS are prefixed with -D or /D and added to the compile line in an unspecified order. |
|
76 | # Entries in the COMPILE_DEFINITIONS are prefixed with -D or /D and added to the compile line in an unspecified order. | |
77 | # The DEFINE_SYMBOL target property is also added as a compile definition as a special convenience case for SHARED and MODULE library targets |
|
77 | # The DEFINE_SYMBOL target property is also added as a compile definition as a special convenience case for SHARED and MODULE library targets | |
78 | IF(BUILD_SHARED_LIBS) |
|
78 | IF(BUILD_SHARED_LIBS) | |
79 | SET_TARGET_PROPERTIES(${SQPAMDA_LIBRARY_NAME} PROPERTIES COMPILE_DEFINITIONS "SCIQLOP_EXPORT") |
|
79 | SET_TARGET_PROPERTIES(${SQPAMDA_LIBRARY_NAME} PROPERTIES COMPILE_DEFINITIONS "SCIQLOP_EXPORT") | |
80 | ELSE() |
|
80 | ELSE() | |
81 | TARGET_COMPILE_DEFINITIONS(${SQPAMDA_LIBRARY_NAME} PUBLIC "SCIQLOP_STATIC_LIBRARIES") |
|
81 | TARGET_COMPILE_DEFINITIONS(${SQPAMDA_LIBRARY_NAME} PUBLIC "SCIQLOP_STATIC_LIBRARIES") | |
82 | ENDIF() |
|
82 | ENDIF() | |
83 |
|
83 | |||
84 | # Set the variable to parent scope so that the other projects can copy the |
|
84 | # Set the variable to parent scope so that the other projects can copy the | |
85 | # dependent shared libraries |
|
85 | # dependent shared libraries | |
86 | SCIQLOP_SET_TO_PARENT_SCOPE(SQPAMDA_LIBRARY_NAME) |
|
86 | SCIQLOP_SET_TO_PARENT_SCOPE(SQPAMDA_LIBRARY_NAME) | |
87 |
|
87 | |||
88 | # Copy extern shared libraries to the lib folder |
|
88 | # Copy extern shared libraries to the lib folder | |
89 | SCIQLOP_COPY_TO_TARGET(LIBRARY ${SQPAMDA_LIBRARY_NAME} ${EXTERN_SHARED_LIBRARIES}) |
|
89 | SCIQLOP_COPY_TO_TARGET(LIBRARY ${SQPAMDA_LIBRARY_NAME} ${EXTERN_SHARED_LIBRARIES}) | |
90 |
|
90 | |||
91 | # Add the files to the list of files to be analyzed |
|
91 | # Add the files to the list of files to be analyzed | |
92 | LIST(APPEND CHECKSTYLE_INPUT_FILES ${MODULE_SOURCES}) |
|
92 | LIST(APPEND CHECKSTYLE_INPUT_FILES ${MODULE_SOURCES}) | |
93 | SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_INPUT_FILES) |
|
93 | SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_INPUT_FILES) | |
94 | # Vera++ exclusion files |
|
94 | # Vera++ exclusion files | |
95 | #LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/vera-exclusions/exclusions.txt) |
|
95 | #LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/vera-exclusions/exclusions.txt) | |
96 | SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES) |
|
96 | SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES) | |
97 |
|
97 | |||
98 | # |
|
98 | # | |
99 | # Compile the tests |
|
99 | # Compile the tests | |
100 | # |
|
100 | # | |
101 | IF(BUILD_TESTS) |
|
101 | IF(BUILD_TESTS) | |
102 | INCLUDE_DIRECTORIES(${SOURCES_DIR}) |
|
102 | INCLUDE_DIRECTORIES(${SOURCES_DIR}) | |
103 | FILE (GLOB_RECURSE TESTS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Test*.cpp) |
|
103 | FILE (GLOB_RECURSE TESTS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Test*.cpp) | |
104 | FILE (GLOB_RECURSE TESTS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/Test*.h) |
|
104 | FILE (GLOB_RECURSE TESTS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/Test*.h) | |
105 | SET( TEST_LIBRARIES ${SQPAMDA_LIBRARY_NAME}) |
|
105 | SET( TEST_LIBRARIES ${SQPAMDA_LIBRARY_NAME}) | |
106 |
|
106 | |||
107 | FOREACH( testFile ${TESTS_SOURCES} ) |
|
107 | FOREACH( testFile ${TESTS_SOURCES} ) | |
108 | GET_FILENAME_COMPONENT( testDirectory ${testFile} DIRECTORY ) |
|
108 | GET_FILENAME_COMPONENT( testDirectory ${testFile} DIRECTORY ) | |
109 | GET_FILENAME_COMPONENT( testName ${testFile} NAME_WE ) |
|
109 | GET_FILENAME_COMPONENT( testName ${testFile} NAME_WE ) | |
110 |
|
110 | |||
111 | # Add to the list of sources files all the sources in the same |
|
111 | # Add to the list of sources files all the sources in the same | |
112 | # directory that aren't another test |
|
112 | # directory that aren't another test | |
113 | FILE (GLOB currentTestSources |
|
113 | FILE (GLOB currentTestSources | |
114 | ${testDirectory}/*.c |
|
114 | ${testDirectory}/*.c | |
115 | ${testDirectory}/*.cpp |
|
115 | ${testDirectory}/*.cpp | |
116 | ${testDirectory}/*.h) |
|
116 | ${testDirectory}/*.h) | |
117 | LIST (REMOVE_ITEM currentTestSources ${TESTS_SOURCES}) |
|
117 | LIST (REMOVE_ITEM currentTestSources ${TESTS_SOURCES}) | |
118 | # LIST (REMOVE_ITEM currentTestSources ${TESTS_HEADERS}) |
|
118 | # LIST (REMOVE_ITEM currentTestSources ${TESTS_HEADERS}) | |
119 |
|
119 | |||
120 | ADD_EXECUTABLE(${testName} ${testFile} ${currentTestSources}) |
|
120 | ADD_EXECUTABLE(${testName} ${testFile} ${currentTestSources}) | |
121 | set_property(TARGET ${testName} PROPERTY CXX_STANDARD 14) |
|
121 | set_property(TARGET ${testName} PROPERTY CXX_STANDARD 14) | |
122 | set_property(TARGET ${testName} PROPERTY CXX_STANDARD_REQUIRED ON) |
|
122 | set_property(TARGET ${testName} PROPERTY CXX_STANDARD_REQUIRED ON) | |
123 | TARGET_LINK_LIBRARIES( ${testName} ${TEST_LIBRARIES} ) |
|
123 | TARGET_LINK_LIBRARIES( ${testName} ${TEST_LIBRARIES} ) | |
124 | qt5_use_modules(${testName} Test) |
|
124 | qt5_use_modules(${testName} Test) | |
125 |
|
125 | |||
126 | ADD_TEST( NAME ${testName} COMMAND ${testName} ) |
|
126 | ADD_TEST( NAME ${testName} COMMAND ${testName} ) | |
127 |
|
127 | |||
128 | SCIQLOP_COPY_TO_TARGET(RUNTIME ${testName} ${EXTERN_SHARED_LIBRARIES}) |
|
128 | SCIQLOP_COPY_TO_TARGET(RUNTIME ${testName} ${EXTERN_SHARED_LIBRARIES}) | |
129 | ENDFOREACH( testFile ) |
|
129 | ENDFOREACH( testFile ) | |
130 |
|
130 | |||
131 | LIST(APPEND testFilesToFormat ${TESTS_SOURCES}) |
|
131 | LIST(APPEND testFilesToFormat ${TESTS_SOURCES}) | |
132 | LIST(APPEND testFilesToFormat ${TESTS_HEADERS}) |
|
132 | LIST(APPEND testFilesToFormat ${TESTS_HEADERS}) | |
133 | LIST(APPEND FORMATTING_INPUT_FILES ${testFilesToFormat}) |
|
133 | LIST(APPEND FORMATTING_INPUT_FILES ${testFilesToFormat}) | |
134 | SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES) |
|
134 | SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES) | |
135 |
|
135 | |||
136 | ADD_DEFINITIONS(-DAMDA_TESTS_RESOURCES_DIR="${TESTS_RESOURCES_DIR}") |
|
136 | ADD_DEFINITIONS(-DAMDA_TESTS_RESOURCES_DIR="${TESTS_RESOURCES_DIR}") | |
137 | ENDIF(BUILD_TESTS) |
|
137 | ENDIF(BUILD_TESTS) | |
138 |
|
138 | |||
139 | # |
|
139 | # | |
140 | # Set the files that must be formatted by clang-format. |
|
140 | # Set the files that must be formatted by clang-format. | |
141 | # |
|
141 | # | |
142 | LIST (APPEND FORMATTING_INPUT_FILES ${MODULE_SOURCES}) |
|
142 | LIST (APPEND FORMATTING_INPUT_FILES ${MODULE_SOURCES}) | |
143 | SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES) |
|
143 | SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES) | |
144 |
|
144 | |||
145 | # |
|
145 | # | |
146 | # Set the directories that doxygen must browse to generate the |
|
146 | # Set the directories that doxygen must browse to generate the | |
147 | # documentation. |
|
147 | # documentation. | |
148 | # |
|
148 | # | |
149 | # Source directories: |
|
149 | # Source directories: | |
150 | LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/docs") |
|
150 | LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/docs") | |
151 | LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src") |
|
151 | LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src") | |
152 | SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_INPUT_DIRS) |
|
152 | SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_INPUT_DIRS) | |
153 | # Source directories to exclude from the documentation generation |
|
153 | # Source directories to exclude from the documentation generation | |
154 | #LIST (APPEND DOXYGEN_EXCLUDE_PATTERNS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir/*") |
|
154 | #LIST (APPEND DOXYGEN_EXCLUDE_PATTERNS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir/*") | |
155 | SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_EXCLUDE_PATTERNS) |
|
155 | SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_EXCLUDE_PATTERNS) | |
156 |
|
156 | |||
157 | # |
|
157 | # | |
158 | # Set the directories with the sources to analyze and propagate the |
|
158 | # Set the directories with the sources to analyze and propagate the | |
159 | # modification to the parent scope |
|
159 | # modification to the parent scope | |
160 | # |
|
160 | # | |
161 | # Source directories to analyze: |
|
161 | # Source directories to analyze: | |
162 | LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src") |
|
162 | LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src") | |
163 | LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/tests") |
|
163 | LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/tests") | |
164 | SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_INPUT_DIRS) |
|
164 | SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_INPUT_DIRS) | |
165 | # Source directories to exclude from the analysis |
|
165 | # Source directories to exclude from the analysis | |
166 | #LIST (APPEND ANALYSIS_EXCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir") |
|
166 | #LIST (APPEND ANALYSIS_EXCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir") | |
167 | SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_EXCLUDE_DIRS) |
|
167 | SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_EXCLUDE_DIRS) |
@@ -1,39 +1,68 | |||||
1 | #include "AmdaPlugin.h" |
|
1 | #include "AmdaPlugin.h" | |
2 | #include "AmdaParser.h" |
|
2 | #include "AmdaParser.h" | |
|
3 | #include "AmdaProvider.h" | |||
3 |
|
4 | |||
4 | #include <DataSource/DataSourceController.h> |
|
5 | #include <DataSource/DataSourceController.h> | |
5 | #include <DataSource/DataSourceItem.h> |
|
6 | #include <DataSource/DataSourceItem.h> | |
|
7 | #include <DataSource/DataSourceItemAction.h> | |||
6 |
|
8 | |||
7 | #include <SqpApplication.h> |
|
9 | #include <SqpApplication.h> | |
8 |
|
10 | |||
9 | Q_LOGGING_CATEGORY(LOG_AmdaPlugin, "AmdaPlugin") |
|
11 | Q_LOGGING_CATEGORY(LOG_AmdaPlugin, "AmdaPlugin") | |
10 |
|
12 | |||
11 | namespace { |
|
13 | namespace { | |
12 |
|
14 | |||
13 | /// Name of the data source |
|
15 | /// Name of the data source | |
14 | const auto DATA_SOURCE_NAME = QStringLiteral("AMDA"); |
|
16 | const auto DATA_SOURCE_NAME = QStringLiteral("AMDA"); | |
15 |
|
17 | |||
16 | /// Path of the file used to generate the data source item for AMDA |
|
18 | /// Path of the file used to generate the data source item for AMDA | |
17 | const auto JSON_FILE_PATH = QStringLiteral(":/samples/AmdaSample.json"); |
|
19 | const auto JSON_FILE_PATH = QStringLiteral(":/samples/AmdaSample.json"); | |
18 |
|
20 | |||
|
21 | void associateActions(DataSourceItem &item, const QUuid &dataSourceUid) | |||
|
22 | { | |||
|
23 | if (item.type() == DataSourceItemType::PRODUCT) { | |||
|
24 | auto itemName = item.name(); | |||
|
25 | ||||
|
26 | item.addAction(std::make_unique<DataSourceItemAction>( | |||
|
27 | QObject::tr("Load %1 product").arg(itemName), | |||
|
28 | [itemName, dataSourceUid](DataSourceItem &item) { | |||
|
29 | if (auto app = sqpApp) { | |||
|
30 | app->dataSourceController().loadProductItem(dataSourceUid, item); | |||
|
31 | } | |||
|
32 | })); | |||
|
33 | } | |||
|
34 | ||||
|
35 | auto count = item.childCount(); | |||
|
36 | for (auto i = 0; i < count; ++i) { | |||
|
37 | if (auto child = item.child(i)) { | |||
|
38 | associateActions(*child, dataSourceUid); | |||
|
39 | } | |||
|
40 | } | |||
|
41 | } | |||
|
42 | ||||
19 | } // namespace |
|
43 | } // namespace | |
20 |
|
44 | |||
21 | void AmdaPlugin::initialize() |
|
45 | void AmdaPlugin::initialize() | |
22 | { |
|
46 | { | |
23 | if (auto app = sqpApp) { |
|
47 | if (auto app = sqpApp) { | |
24 | // Registers to the data source controller |
|
48 | // Registers to the data source controller | |
25 | auto &dataSourceController = app->dataSourceController(); |
|
49 | auto &dataSourceController = app->dataSourceController(); | |
26 | auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME); |
|
50 | auto dataSourceUid = dataSourceController.registerDataSource(DATA_SOURCE_NAME); | |
27 |
|
51 | |||
28 | // Sets data source tree |
|
52 | // Sets data source tree | |
29 | if (auto dataSourceItem = AmdaParser::readJson(JSON_FILE_PATH)) { |
|
53 | if (auto dataSourceItem = AmdaParser::readJson(JSON_FILE_PATH)) { | |
|
54 | associateActions(*dataSourceItem, dataSourceUid); | |||
|
55 | ||||
30 | dataSourceController.setDataSourceItem(dataSourceUid, std::move(dataSourceItem)); |
|
56 | dataSourceController.setDataSourceItem(dataSourceUid, std::move(dataSourceItem)); | |
31 | } |
|
57 | } | |
32 | else { |
|
58 | else { | |
33 | qCCritical(LOG_AmdaPlugin()) << tr("No data source item could be generated for AMDA"); |
|
59 | qCCritical(LOG_AmdaPlugin()) << tr("No data source item could be generated for AMDA"); | |
34 | } |
|
60 | } | |
|
61 | ||||
|
62 | // Sets data provider | |||
|
63 | dataSourceController.setDataProvider(dataSourceUid, std::make_unique<AmdaProvider>()); | |||
35 | } |
|
64 | } | |
36 | else { |
|
65 | else { | |
37 | qCWarning(LOG_AmdaPlugin()) << tr("Can't access to SciQlop application"); |
|
66 | qCWarning(LOG_AmdaPlugin()) << tr("Can't access to SciQlop application"); | |
38 | } |
|
67 | } | |
39 | } |
|
68 | } |
@@ -1,26 +1,26 | |||||
1 | #ifndef SCIQLOP_COSINUSPROVIDER_H |
|
1 | #ifndef SCIQLOP_COSINUSPROVIDER_H | |
2 | #define SCIQLOP_COSINUSPROVIDER_H |
|
2 | #define SCIQLOP_COSINUSPROVIDER_H | |
3 |
|
3 | |||
4 | #include "MockPluginGlobal.h" |
|
4 | #include "MockPluginGlobal.h" | |
5 |
|
5 | |||
6 | #include <Data/IDataProvider.h> |
|
6 | #include <Data/IDataProvider.h> | |
7 |
|
7 | |||
8 | #include <QLoggingCategory> |
|
8 | #include <QLoggingCategory> | |
9 |
|
9 | |||
10 | Q_DECLARE_LOGGING_CATEGORY(LOG_CosinusProvider) |
|
10 | Q_DECLARE_LOGGING_CATEGORY(LOG_CosinusProvider) | |
11 |
|
11 | |||
12 | /** |
|
12 | /** | |
13 | * @brief The CosinusProvider class is an example of how a data provider can generate data |
|
13 | * @brief The CosinusProvider class is an example of how a data provider can generate data | |
14 | */ |
|
14 | */ | |
15 | class SCIQLOP_MOCKPLUGIN_EXPORT CosinusProvider : public IDataProvider { |
|
15 | class SCIQLOP_MOCKPLUGIN_EXPORT CosinusProvider : public IDataProvider { | |
16 | public: |
|
16 | public: | |
17 | void requestDataLoading(const QVector<SqpDateTime> &dateTimeList) override; |
|
17 | void requestDataLoading(QUuid token, const QVector<SqpDateTime> &dateTimeList) override; | |
18 |
|
18 | |||
19 |
|
19 | |||
20 | private: |
|
20 | private: | |
21 | /// @sa IDataProvider::retrieveData() |
|
21 | /// @sa IDataProvider::retrieveData() | |
22 | std::shared_ptr<IDataSeries> retrieveData(const DataProviderParameters ¶meters) const; |
|
22 | std::shared_ptr<IDataSeries> retrieveData(const DataProviderParameters ¶meters) const; | |
23 | std::shared_ptr<IDataSeries> retrieveDataSeries(const SqpDateTime &dateTime); |
|
23 | std::shared_ptr<IDataSeries> retrieveDataSeries(const SqpDateTime &dateTime); | |
24 | }; |
|
24 | }; | |
25 |
|
25 | |||
26 | #endif // SCIQLOP_COSINUSPROVIDER_H |
|
26 | #endif // SCIQLOP_COSINUSPROVIDER_H |
@@ -1,50 +1,50 | |||||
1 | #include "CosinusProvider.h" |
|
1 | #include "CosinusProvider.h" | |
2 |
|
2 | |||
3 | #include <Data/DataProviderParameters.h> |
|
3 | #include <Data/DataProviderParameters.h> | |
4 | #include <Data/ScalarSeries.h> |
|
4 | #include <Data/ScalarSeries.h> | |
5 |
|
5 | |||
6 | #include <cmath> |
|
6 | #include <cmath> | |
7 |
|
7 | |||
8 | #include <QDateTime> |
|
8 | #include <QDateTime> | |
9 | #include <QThread> |
|
9 | #include <QThread> | |
10 |
|
10 | |||
11 | Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider") |
|
11 | Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider") | |
12 |
|
12 | |||
13 | std::shared_ptr<IDataSeries> |
|
13 | std::shared_ptr<IDataSeries> | |
14 | CosinusProvider::retrieveData(const DataProviderParameters ¶meters) const |
|
14 | CosinusProvider::retrieveData(const DataProviderParameters ¶meters) const | |
15 | { |
|
15 | { | |
16 | auto dateTime = parameters.m_Time; |
|
16 | auto dateTime = parameters.m_Time; | |
17 |
|
17 | |||
18 | auto dataIndex = 0; |
|
18 | auto dataIndex = 0; | |
19 |
|
19 | |||
20 | // Gets the timerange from the parameters |
|
20 | // Gets the timerange from the parameters | |
21 | double freq = 100.0; |
|
21 | double freq = 100.0; | |
22 | double start = dateTime.m_TStart * freq; // 100 htz |
|
22 | double start = dateTime.m_TStart * freq; // 100 htz | |
23 | double end = dateTime.m_TEnd * freq; // 100 htz |
|
23 | double end = dateTime.m_TEnd * freq; // 100 htz | |
24 |
|
24 | |||
25 | // We assure that timerange is valid |
|
25 | // We assure that timerange is valid | |
26 | if (end < start) { |
|
26 | if (end < start) { | |
27 | std::swap(start, end); |
|
27 | std::swap(start, end); | |
28 | } |
|
28 | } | |
29 |
|
29 | |||
30 | // Generates scalar series containing cosinus values (one value per second) |
|
30 | // Generates scalar series containing cosinus values (one value per second) | |
31 | auto scalarSeries |
|
31 | auto scalarSeries | |
32 | = std::make_shared<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{}); |
|
32 | = std::make_shared<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{}); | |
33 |
|
33 | |||
34 | for (auto time = start; time < end; ++time, ++dataIndex) { |
|
34 | for (auto time = start; time < end; ++time, ++dataIndex) { | |
35 | const auto timeOnFreq = time / freq; |
|
35 | const auto timeOnFreq = time / freq; | |
36 | scalarSeries->setData(dataIndex, timeOnFreq, std::cos(timeOnFreq)); |
|
36 | scalarSeries->setData(dataIndex, timeOnFreq, std::cos(timeOnFreq)); | |
37 | } |
|
37 | } | |
38 | return scalarSeries; |
|
38 | return scalarSeries; | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | void CosinusProvider::requestDataLoading(const QVector<SqpDateTime> &dateTimeList) |
|
41 | void CosinusProvider::requestDataLoading(QUuid token, const QVector<SqpDateTime> &dateTimeList) | |
42 | { |
|
42 | { | |
43 | qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataLoading" |
|
43 | qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataLoading" | |
44 | << QThread::currentThread()->objectName(); |
|
44 | << QThread::currentThread()->objectName(); | |
45 | // NOTE: Try to use multithread if possible |
|
45 | // NOTE: Try to use multithread if possible | |
46 | for (const auto &dateTime : dateTimeList) { |
|
46 | for (const auto &dateTime : dateTimeList) { | |
47 | auto scalarSeries = this->retrieveData(DataProviderParameters{dateTime}); |
|
47 | auto scalarSeries = this->retrieveData(DataProviderParameters{dateTime}); | |
48 | emit dataProvided(scalarSeries, dateTime); |
|
48 | emit dataProvided(token, scalarSeries, dateTime); | |
49 | } |
|
49 | } | |
50 | } |
|
50 | } |
General Comments 0
You need to be logged in to leave comments.
Login now