##// END OF EJS Templates
Basic serial variable creation and update...
jeandet -
r2:c7f53bda4647
parent child
Show More
@@ -0,0 +1,9
1 #ifndef DEBUG_H
2 #define DEBUG_H
3
4 #ifdef SCIQLOP_CRASH_ON_ERROR
5 #define SCIQLOP_ERROR(x) assert(false)
6 #else
7 #define SCIQLOP_ERROR(x)
8 #endif
9 #endif
@@ -1,187 +1,188
1 cmake_minimum_required(VERSION 3.6)
1 cmake_minimum_required(VERSION 3.6)
2 project(SciQLOPCore CXX)
2 project(SciQLOPCore CXX)
3
3
4 OPTION (CPPCHECK "Analyzes the source code with cppcheck" OFF)
4 OPTION (CPPCHECK "Analyzes the source code with cppcheck" OFF)
5 OPTION (CLANG_TIDY "Analyzes the source code with Clang Tidy" OFF)
5 OPTION (CLANG_TIDY "Analyzes the source code with Clang Tidy" OFF)
6 OPTION (IWYU "Analyzes the source code with Include What You Use" OFF)
6 OPTION (IWYU "Analyzes the source code with Include What You Use" OFF)
7
7
8 OPTION (Catalog "builds catalog API" OFF)
8 OPTION (Catalog "builds catalog API" OFF)
9
9
10 set(CMAKE_CXX_STANDARD 17)
10 set(CMAKE_CXX_STANDARD 17)
11
11
12 set(CMAKE_AUTOMOC ON)
12 set(CMAKE_AUTOMOC ON)
13 #https://gitlab.kitware.com/cmake/cmake/issues/15227
13 #https://gitlab.kitware.com/cmake/cmake/issues/15227
14 #set(CMAKE_AUTOUIC ON)
14 #set(CMAKE_AUTOUIC ON)
15 if(POLICY CMP0071)
15 if(POLICY CMP0071)
16 cmake_policy(SET CMP0071 OLD)
16 cmake_policy(SET CMP0071 OLD)
17 endif()
17 endif()
18 set(CMAKE_AUTORCC ON)
18 set(CMAKE_AUTORCC ON)
19 set(CMAKE_INCLUDE_CURRENT_DIR ON)
19 set(CMAKE_INCLUDE_CURRENT_DIR ON)
20
20
21 find_package(Qt5 COMPONENTS Core Widgets Network PrintSupport Svg Test REQUIRED)
21 find_package(Qt5 COMPONENTS Core Widgets Network PrintSupport Svg Test REQUIRED)
22
22
23 find_package(pybind11 CONFIG QUIET)
23 find_package(pybind11 CONFIG QUIET)
24 if (NOT pybind11_FOUND)
24 if (NOT pybind11_FOUND)
25 execute_process(COMMAND git submodule init external/pybind11 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
25 execute_process(COMMAND git submodule init external/pybind11 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
26 execute_process(COMMAND git submodule update external/pybind11 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
26 execute_process(COMMAND git submodule update external/pybind11 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
27 add_subdirectory(external/pybind11)
27 add_subdirectory(external/pybind11)
28 endif()
28 endif()
29
29
30 macro(declare_test testname testexe sources libraries)
30 macro(declare_test testname testexe sources libraries)
31 add_executable(${testexe} ${sources})
31 add_executable(${testexe} ${sources})
32 target_link_libraries(${testexe} ${libraries})
32 target_link_libraries(${testexe} ${libraries})
33 add_test(NAME ${testname} COMMAND ${testexe})
33 add_test(NAME ${testname} COMMAND ${testexe})
34 endmacro(declare_test)
34 endmacro(declare_test)
35
35
36 enable_testing()
36 enable_testing()
37
37
38 FILE (GLOB_RECURSE core_SRCS
38 FILE (GLOB_RECURSE core_SRCS
39 ./include/DataSource/DataSourceItemMergeHelper.h
39 ./include/DataSource/DataSourceItemMergeHelper.h
40 ./include/DataSource/DataSourceItemAction.h
40 ./include/DataSource/DataSourceItemAction.h
41 ./include/DataSource/DataSourceItem.h
41 ./include/DataSource/DataSourceItem.h
42 ./include/DataSource/DataSourceController.h
42 ./include/DataSource/DataSourceController.h
43 ./include/Common/SortUtils.h
43 ./include/Common/SortUtils.h
44 ./include/Common/spimpl.h
44 ./include/Common/spimpl.h
45 ./include/Common/MimeTypesDef.h
45 ./include/Common/MimeTypesDef.h
46 ./include/Common/MetaTypes.h
46 ./include/Common/MetaTypes.h
47 ./include/Common/StringUtils.h
47 ./include/Common/StringUtils.h
48 ./include/Common/SignalWaiter.h
48 ./include/Common/SignalWaiter.h
49 ./include/Common/DateUtils.h
49 ./include/Common/DateUtils.h
50 ./include/Common/Numeric.h
50 ./include/Common/Numeric.h
51 ./include/Common/deprecate.h
51 ./include/Common/deprecate.h
52 ./include/Common/containers.h
52 ./include/Common/containers.h
53 ./include/Common/debug.h
53 ./include/Plugin/IPlugin.h
54 ./include/Plugin/IPlugin.h
54 ./include/Data/ArrayDataIterator.h
55 ./include/Data/ArrayDataIterator.h
55 ./include/Data/VariableRequest.h
56 ./include/Data/VariableRequest.h
56 ./include/Data/VectorSeries.h
57 ./include/Data/VectorSeries.h
57 ./include/Data/DateTimeRange.h
58 ./include/Data/DateTimeRange.h
58 ./include/Data/ScalarSeries.h
59 ./include/Data/ScalarSeries.h
59 ./include/Data/DataSeriesMergeHelper.h
60 ./include/Data/DataSeriesMergeHelper.h
60 ./include/Data/DataSeries.h
61 ./include/Data/DataSeries.h
61 ./include/Data/AcquisitionDataPacket.h
62 ./include/Data/AcquisitionDataPacket.h
62 ./include/Data/DataSeriesType.h
63 ./include/Data/DataSeriesType.h
63 ./include/Data/AcquisitionRequest.h
64 ./include/Data/AcquisitionRequest.h
64 ./include/Data/SqpIterator.h
65 ./include/Data/SqpIterator.h
65 ./include/Data/ArrayData.h
66 ./include/Data/ArrayData.h
66 ./include/Data/DataSeriesIterator.h
67 ./include/Data/DataSeriesIterator.h
67 ./include/Data/DataSeriesUtils.h
68 ./include/Data/DataSeriesUtils.h
68 ./include/Data/SpectrogramSeries.h
69 ./include/Data/SpectrogramSeries.h
69 ./include/Data/Unit.h
70 ./include/Data/Unit.h
70 ./include/Data/DataProviderParameters.h
71 ./include/Data/DataProviderParameters.h
71 ./include/Data/OptionalAxis.h
72 ./include/Data/OptionalAxis.h
72 ./include/Data/IDataProvider.h
73 ./include/Data/IDataProvider.h
73 ./include/Data/IDataSeries.h
74 ./include/Data/IDataSeries.h
74 ./include/Network/NetworkController.h
75 ./include/Network/NetworkController.h
75 ./include/Network/Downloader.h
76 ./include/Network/Downloader.h
76 ./include/Version.h
77 ./include/Version.h
77 ./include/CoreGlobal.h
78 ./include/CoreGlobal.h
78 ./include/Visualization/VisualizationController.h
79 ./include/Visualization/VisualizationController.h
79 ./include/PluginManager/PluginManager.h
80 ./include/PluginManager/PluginManager.h
80 ./include/Variable/VariableModel.h
81 ./include/Variable/VariableModel.h
81 ./include/Variable/VariableAcquisitionWorker.h
82 ./include/Variable/VariableAcquisitionWorker.h
82 ./include/Variable/VariableCacheStrategy.h
83 ./include/Variable/VariableCacheStrategy.h
83 ./include/Variable/VariableSynchronizationGroup.h
84 ./include/Variable/VariableSynchronizationGroup.h
84 ./include/Variable/VariableSynchronizationGroup2.h
85 ./include/Variable/VariableSynchronizationGroup2.h
85 ./include/Variable/VariableSingleThresholdCacheStrategy.h
86 ./include/Variable/VariableSingleThresholdCacheStrategy.h
86 ./include/Variable/VariableCacheStrategyFactory.h
87 ./include/Variable/VariableCacheStrategyFactory.h
87 ./include/Variable/Variable.h
88 ./include/Variable/Variable.h
88 ./include/Variable/VariableCacheController.h
89 ./include/Variable/VariableCacheController.h
89 ./include/Variable/VariableController.h
90 ./include/Variable/VariableController.h
90 ./include/Variable/VariableController2.h
91 ./include/Variable/VariableController2.h
91 ./include/Time/TimeController.h
92 ./include/Time/TimeController.h
92 ./include/Settings/ISqpSettingsBindable.h
93 ./include/Settings/ISqpSettingsBindable.h
93 ./include/Settings/SqpSettingsDefs.h
94 ./include/Settings/SqpSettingsDefs.h
94
95
95 ./src/DataSource/DataSourceItem.cpp
96 ./src/DataSource/DataSourceItem.cpp
96 ./src/DataSource/DataSourceItemAction.cpp
97 ./src/DataSource/DataSourceItemAction.cpp
97 ./src/DataSource/DataSourceItemMergeHelper.cpp
98 ./src/DataSource/DataSourceItemMergeHelper.cpp
98 ./src/DataSource/DataSourceController.cpp
99 ./src/DataSource/DataSourceController.cpp
99 ./src/Common/DateUtils.cpp
100 ./src/Common/DateUtils.cpp
100 ./src/Common/MimeTypesDef.cpp
101 ./src/Common/MimeTypesDef.cpp
101 ./src/Common/StringUtils.cpp
102 ./src/Common/StringUtils.cpp
102 ./src/Common/SignalWaiter.cpp
103 ./src/Common/SignalWaiter.cpp
103 ./src/Data/ScalarSeries.cpp
104 ./src/Data/ScalarSeries.cpp
104 ./src/Data/DataSeriesIterator.cpp
105 ./src/Data/DataSeriesIterator.cpp
105 ./src/Data/OptionalAxis.cpp
106 ./src/Data/OptionalAxis.cpp
106 ./src/Data/ArrayDataIterator.cpp
107 ./src/Data/ArrayDataIterator.cpp
107 ./src/Data/SpectrogramSeries.cpp
108 ./src/Data/SpectrogramSeries.cpp
108 ./src/Data/DataSeriesUtils.cpp
109 ./src/Data/DataSeriesUtils.cpp
109 ./src/Data/VectorSeries.cpp
110 ./src/Data/VectorSeries.cpp
110 ./src/Network/NetworkController.cpp
111 ./src/Network/NetworkController.cpp
111 ./src/Network/Downloader.cpp
112 ./src/Network/Downloader.cpp
112 ./src/Visualization/VisualizationController.cpp
113 ./src/Visualization/VisualizationController.cpp
113 ./src/PluginManager/PluginManager.cpp
114 ./src/PluginManager/PluginManager.cpp
114 ./src/Variable/VariableController.cpp
115 ./src/Variable/VariableController.cpp
115 ./src/Variable/VariableController2.cpp
116 ./src/Variable/VariableController2.cpp
116 ./src/Variable/VariableModel.cpp
117 ./src/Variable/VariableModel.cpp
117 ./src/Variable/VariableCacheController.cpp
118 ./src/Variable/VariableCacheController.cpp
118 ./src/Variable/VariableSynchronizationGroup.cpp
119 ./src/Variable/VariableSynchronizationGroup.cpp
119 ./src/Variable/VariableSynchronizationGroup2.cpp
120 ./src/Variable/VariableSynchronizationGroup2.cpp
120 ./src/Variable/Variable.cpp
121 ./src/Variable/Variable.cpp
121 ./src/Variable/VariableAcquisitionWorker.cpp
122 ./src/Variable/VariableAcquisitionWorker.cpp
122 ./src/Version.cpp
123 ./src/Version.cpp
123 ./src/Time/TimeController.cpp
124 ./src/Time/TimeController.cpp
124 ./src/Settings/SqpSettingsDefs.cpp
125 ./src/Settings/SqpSettingsDefs.cpp
125
126
126 )
127 )
127
128
128
129
129 IF(Catalog)
130 IF(Catalog)
130 FILE (GLOB_RECURSE core_catalog_SRCS
131 FILE (GLOB_RECURSE core_catalog_SRCS
131 ./src/Catalogue/CatalogueController.cpp
132 ./src/Catalogue/CatalogueController.cpp
132 ./include/Catalogue/CatalogueController.h
133 ./include/Catalogue/CatalogueController.h
133 )
134 )
134 ELSE()
135 ELSE()
135 FILE (GLOB_RECURSE core_catalog_SRCS
136 FILE (GLOB_RECURSE core_catalog_SRCS
136 )
137 )
137 ENDIF(Catalog)
138 ENDIF(Catalog)
138
139
139 add_definitions(-DCORE_STATIC)
140 add_definitions(-DCORE_STATIC)
140 #add_definitions(-DHIDE_DEPRECATED)
141 #add_definitions(-DHIDE_DEPRECATED)
141
142
142 add_library(sciqlopcore ${core_SRCS} ${core_catalog_SRCS})
143 add_library(sciqlopcore ${core_SRCS} ${core_catalog_SRCS})
143 SET_TARGET_PROPERTIES(sciqlopcore PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
144 SET_TARGET_PROPERTIES(sciqlopcore PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
144
145
145 target_include_directories(sciqlopcore PUBLIC
146 target_include_directories(sciqlopcore PUBLIC
146 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
147 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
147 $<INSTALL_INTERFACE:include/SciQLOP>
148 $<INSTALL_INTERFACE:include/SciQLOP>
148 )
149 )
149
150
150 target_link_libraries(sciqlopcore PUBLIC
151 target_link_libraries(sciqlopcore PUBLIC
151 Qt5::Core
152 Qt5::Core
152 Qt5::Network
153 Qt5::Network
153 )
154 )
154
155
155 if(Catalog)
156 if(Catalog)
156 target_link_libraries(sciqlopcore PUBLIC
157 target_link_libraries(sciqlopcore PUBLIC
157 catalogs
158 catalogs
158 )
159 )
159 endif()
160 endif()
160
161
161
162
162 pybind11_add_module(sciqlopqt src/pybind11_wrappers/QtWrappers.cpp)
163 pybind11_add_module(sciqlopqt src/pybind11_wrappers/QtWrappers.cpp)
163 target_link_libraries(sciqlopqt PUBLIC Qt5::Core)
164 target_link_libraries(sciqlopqt PUBLIC Qt5::Core)
164
165
165 pybind11_add_module(pysciqlopcore src/pybind11_wrappers/CoreWrappers.cpp)
166 pybind11_add_module(pysciqlopcore src/pybind11_wrappers/CoreWrappers.cpp)
166 target_link_libraries(pysciqlopcore PUBLIC sciqlopcore)
167 target_link_libraries(pysciqlopcore PUBLIC sciqlopcore)
167
168
168 add_library(pysciqlop src/pybind11_wrappers/pywrappers_common.h)
169 add_library(pysciqlop src/pybind11_wrappers/pywrappers_common.h)
169 target_link_libraries(pysciqlop PUBLIC Qt5::Core)
170 target_link_libraries(pysciqlop PUBLIC Qt5::Core)
170 target_include_directories(pysciqlop PUBLIC
171 target_include_directories(pysciqlop PUBLIC
171 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/pybind11_wrappers/>
172 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/pybind11_wrappers/>
172 $<INSTALL_INTERFACE:include/SciQLOP/py_wrappers>
173 $<INSTALL_INTERFACE:include/SciQLOP/py_wrappers>
173 )
174 )
174
175
175 SET_PROPERTY(GLOBAL PROPERTY CORE_PYTHON_PATH ${CMAKE_CURRENT_BINARY_DIR})
176 SET_PROPERTY(GLOBAL PROPERTY CORE_PYTHON_PATH ${CMAKE_CURRENT_BINARY_DIR})
176
177
177
178
178 install(TARGETS sciqlopcore EXPORT SciQLOPCoreConfig
179 install(TARGETS sciqlopcore EXPORT SciQLOPCoreConfig
179 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
180 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
180 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
181 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
181 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
182 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
182
183
183 install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/SciQLOP)
184 install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/SciQLOP)
184 install(EXPORT SciQLOPCoreConfig DESTINATION share/SciQLOPCore/cmake)
185 install(EXPORT SciQLOPCoreConfig DESTINATION share/SciQLOPCore/cmake)
185 export(TARGETS sciqlopcore FILE SciQLOPCoreConfig.cmake)
186 export(TARGETS sciqlopcore FILE SciQLOPCoreConfig.cmake)
186
187
187 add_subdirectory(tests)
188 add_subdirectory(tests)
@@ -1,107 +1,112
1 #ifndef SCIQLOP_IDATAPROVIDER_H
1 #ifndef SCIQLOP_IDATAPROVIDER_H
2 #define SCIQLOP_IDATAPROVIDER_H
2 #define SCIQLOP_IDATAPROVIDER_H
3
3
4 #include "CoreGlobal.h"
4 #include "CoreGlobal.h"
5 #include <Common/deprecate.h>
5 #include <Common/deprecate.h>
6
6
7 #include <memory>
7 #include <memory>
8
8
9 #include <QObject>
9 #include <QObject>
10 #include <QUuid>
10 #include <QUuid>
11
11
12 #include <Common/MetaTypes.h>
12 #include <Common/MetaTypes.h>
13
13
14 #include <Data/DateTimeRange.h>
14 #include <Data/DateTimeRange.h>
15
15
16 #include <functional>
16 #include <functional>
17
17
18 class DataProviderParameters;
18 class DataProviderParameters;
19 class IDataSeries;
19 class IDataSeries;
20 DEPRECATE(
20 DEPRECATE(
21 class QNetworkReply;
21 class QNetworkReply;
22 class QNetworkRequest;
22 class QNetworkRequest;
23 )
23 )
24
24
25 /**
25 /**
26 * @brief The IDataProvider interface aims to declare a data provider.
26 * @brief The IDataProvider interface aims to declare a data provider.
27 *
27 *
28 * A data provider is an entity that generates data and returns it according to various parameters
28 * A data provider is an entity that generates data and returns it according to various parameters
29 * (time interval, product to retrieve the data, etc.)
29 * (time interval, product to retrieve the data, etc.)
30 *
30 *
31 * @sa IDataSeries
31 * @sa IDataSeries
32 */
32 */
33 class SCIQLOP_CORE_EXPORT IDataProvider : public QObject {
33 class SCIQLOP_CORE_EXPORT IDataProvider : public QObject {
34
34
35 Q_OBJECT
35 Q_OBJECT
36 public:
36 public:
37 virtual ~IDataProvider() noexcept = default;
37 virtual ~IDataProvider() noexcept = default;
38 virtual std::shared_ptr<IDataProvider> clone() const = 0;
38 virtual std::shared_ptr<IDataProvider> clone() const = 0;
39
39
40 DEPRECATE(
40 DEPRECATE(
41 /**
41 /**
42 * @brief requestDataLoading provide datas for the data identified by acqIdentifier and
42 * @brief requestDataLoading provide datas for the data identified by acqIdentifier and
43 * parameters
43 * parameters
44 */
44 */
45 virtual void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters &parameters)
45 virtual void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters &parameters)
46 = 0;
46 = 0;
47 )
47 )
48
48
49 virtual QUuid getData(const DataProviderParameters &parameters){return QUuid::createUuid();}
49 // Synchronous call -> asyncGetData may be written for asynchronous get
50 virtual IDataSeries* getData(const DataProviderParameters &parameters)
51 {
52 Q_UNUSED(parameters);
53 return nullptr;
54 }
50
55
51
56
52 DEPRECATE(
57 DEPRECATE(
53 /**
58 /**
54 * @brief requestDataAborting stop data loading of the data identified by acqIdentifier
59 * @brief requestDataAborting stop data loading of the data identified by acqIdentifier
55 */
60 */
56 virtual void requestDataAborting(QUuid acqIdentifier) = 0;
61 virtual void requestDataAborting(QUuid acqIdentifier) = 0;
57 )
62 )
58
63
59 virtual void abort(QUuid requestID){}
64 virtual void abort(QUuid requestID){Q_UNUSED(requestID);}
60
65
61 signals:
66 signals:
62 DEPRECATE(
67 DEPRECATE(
63 /**
68 /**
64 * @brief dataProvided send dataSeries under dateTime and that corresponds of the data
69 * @brief dataProvided send dataSeries under dateTime and that corresponds of the data
65 * identified by acqIdentifier
70 * identified by acqIdentifier
66 */
71 */
67 void dataProvided(QUuid acqIdentifier, std::shared_ptr<IDataSeries> dateSeriesAcquired,
72 void dataProvided(QUuid acqIdentifier, std::shared_ptr<IDataSeries> dateSeriesAcquired,
68 const DateTimeRange &dataRangeAcquired);
73 const DateTimeRange &dataRangeAcquired);
69 )
74 )
70
75
71 void finished(QUuid requestID, std::shared_ptr<IDataSeries> dataSerie,
76 void finished(QUuid requestID, std::shared_ptr<IDataSeries> dataSerie,
72 const DateTimeRange &range);
77 const DateTimeRange &range);
73
78
74 DEPRECATE(
79 DEPRECATE(
75 /**
80 /**
76 * @brief dataProvidedProgress notify the progression of the data identifier by acqIdentifier
81 * @brief dataProvidedProgress notify the progression of the data identifier by acqIdentifier
77 */
82 */
78 void dataProvidedProgress(QUuid acqIdentifier, double progress);
83 void dataProvidedProgress(QUuid acqIdentifier, double progress);
79 )
84 )
80
85
81 void progress(QUuid requestID, double progress);
86 void progress(QUuid requestID, double progress);
82
87
83 DEPRECATE(
88 DEPRECATE(
84 /**
89 /**
85 * @brief dataProvidedFailed notify that data acquisition has failed
90 * @brief dataProvidedFailed notify that data acquisition has failed
86 */
91 */
87 void dataProvidedFailed(QUuid acqIdentifier);
92 void dataProvidedFailed(QUuid acqIdentifier);
88 )
93 )
89
94
90 void failed(QUuid requestID);
95 void failed(QUuid requestID);
91
96
92 /**
97 /**
93 * @brief requestConstructed send a request for the data identified by acqIdentifier
98 * @brief requestConstructed send a request for the data identified by acqIdentifier
94 * @callback is the methode call by the reply of the request when it is finished.
99 * @callback is the methode call by the reply of the request when it is finished.
95 */
100 */
96 DEPRECATE(
101 DEPRECATE(
97 void requestConstructed(std::shared_ptr<QNetworkRequest> request, QUuid acqIdentifier,
102 void requestConstructed(std::shared_ptr<QNetworkRequest> request, QUuid acqIdentifier,
98 std::function<void(QNetworkReply *, QUuid)> callback);
103 std::function<void(QNetworkReply *, QUuid)> callback);
99 )
104 )
100 };
105 };
101
106
102 // Required for using shared_ptr in signals/slots
107 // Required for using shared_ptr in signals/slots
103 SCIQLOP_REGISTER_META_TYPE(IDATAPROVIDER_PTR_REGISTRY, std::shared_ptr<IDataProvider>)
108 SCIQLOP_REGISTER_META_TYPE(IDATAPROVIDER_PTR_REGISTRY, std::shared_ptr<IDataProvider>)
104 SCIQLOP_REGISTER_META_TYPE(IDATAPROVIDER_FUNCTION_REGISTRY,
109 SCIQLOP_REGISTER_META_TYPE(IDATAPROVIDER_FUNCTION_REGISTRY,
105 std::function<void(QNetworkReply *, QUuid)>)
110 std::function<void(QNetworkReply *, QUuid)>)
106
111
107 #endif // SCIQLOP_IDATAPROVIDER_H
112 #endif // SCIQLOP_IDATAPROVIDER_H
@@ -1,95 +1,102
1 #ifndef SCIQLOP_VARIABLE_H
1 #ifndef SCIQLOP_VARIABLE_H
2 #define SCIQLOP_VARIABLE_H
2 #define SCIQLOP_VARIABLE_H
3
3
4 #include "CoreGlobal.h"
4 #include "CoreGlobal.h"
5
5
6 #include <Data/DataSeriesIterator.h>
6 #include <Data/DataSeriesIterator.h>
7 #include <Data/DataSeriesType.h>
7 #include <Data/DataSeriesType.h>
8 #include <Data/DateTimeRange.h>
8 #include <Data/DateTimeRange.h>
9
9
10 #include <QLoggingCategory>
10 #include <QLoggingCategory>
11 #include <QObject>
11 #include <QObject>
12 #include <QUuid>
12
13
14 #include <Common/deprecate.h>
13 #include <Common/MetaTypes.h>
15 #include <Common/MetaTypes.h>
14 #include <Common/spimpl.h>
16 #include <Common/spimpl.h>
15
17
16 Q_DECLARE_LOGGING_CATEGORY(LOG_Variable)
18 Q_DECLARE_LOGGING_CATEGORY(LOG_Variable)
17
19
18 class IDataSeries;
20 class IDataSeries;
19 class QString;
21 class QString;
20
22
21 /**
23 /**
22 * @brief The Variable class represents a variable in SciQlop.
24 * @brief The Variable class represents a variable in SciQlop.
23 */
25 */
24 class SCIQLOP_CORE_EXPORT Variable : public QObject {
26 class SCIQLOP_CORE_EXPORT Variable : public QObject {
25
27
26 Q_OBJECT
28 Q_OBJECT
27
29
28 public:
30 public:
29 explicit Variable(const QString &name, const QVariantHash &metadata = {});
31 explicit Variable(const QString &name, const QVariantHash &metadata = {});
30
32
31 /// Copy ctor
33 /// Copy ctor
32 explicit Variable(const Variable &other);
34 explicit Variable(const Variable &other);
33
35
34 std::shared_ptr<Variable> clone() const;
36 std::shared_ptr<Variable> clone() const;
35
37
36 QString name() const noexcept;
38 QString name() const noexcept;
37 void setName(const QString &name) noexcept;
39 void setName(const QString &name) noexcept;
38 DateTimeRange range() const noexcept;
40 DateTimeRange range() const noexcept;
39 void setRange(const DateTimeRange &range) noexcept;
41 void setRange(const DateTimeRange &range) noexcept;
40 DateTimeRange cacheRange() const noexcept;
42 DateTimeRange cacheRange() const noexcept;
41 void setCacheRange(const DateTimeRange &cacheRange) noexcept;
43 void setCacheRange(const DateTimeRange &cacheRange) noexcept;
42
44
43 /// @return the number of points hold by the variable. The number of points is updated each time
45 /// @return the number of points hold by the variable. The number of points is updated each time
44 /// the data series changes
46 /// the data series changes
45 int nbPoints() const noexcept;
47 int nbPoints() const noexcept;
46
48
47 /// Returns the real range of the variable, i.e. the min and max x-axis values of the data
49 /// Returns the real range of the variable, i.e. the min and max x-axis values of the data
48 /// series between the range of the variable. The real range is updated each time the variable
50 /// series between the range of the variable. The real range is updated each time the variable
49 /// range or the data series changed
51 /// range or the data series changed
50 /// @return the real range, invalid range if the data series is null or empty
52 /// @return the real range, invalid range if the data series is null or empty
51 /// @sa setDataSeries()
53 /// @sa setDataSeries()
52 /// @sa setRange()
54 /// @sa setRange()
53 DateTimeRange realRange() const noexcept;
55 DateTimeRange realRange() const noexcept;
54
56
55 /// @return the data of the variable, nullptr if there is no data
57 /// @return the data of the variable, nullptr if there is no data
56 std::shared_ptr<IDataSeries> dataSeries() const noexcept;
58 std::shared_ptr<IDataSeries> dataSeries() const noexcept;
57
59
58 /// @return the type of data that the variable holds
60 /// @return the type of data that the variable holds
59 DataSeriesType type() const noexcept;
61 DataSeriesType type() const noexcept;
60
62
61 QVariantHash metadata() const noexcept;
63 QVariantHash metadata() const noexcept;
62
64
63 bool contains(const DateTimeRange &range) const noexcept;
65 bool contains(const DateTimeRange &range) const noexcept;
64 bool intersect(const DateTimeRange &range) const noexcept;
66 bool intersect(const DateTimeRange &range) const noexcept;
65 bool isInside(const DateTimeRange &range) const noexcept;
67 bool isInside(const DateTimeRange &range) const noexcept;
66
68
67 bool cacheContains(const DateTimeRange &range) const noexcept;
69 bool cacheContains(const DateTimeRange &range) const noexcept;
68 bool cacheIntersect(const DateTimeRange &range) const noexcept;
70 bool cacheIntersect(const DateTimeRange &range) const noexcept;
69 bool cacheIsInside(const DateTimeRange &range) const noexcept;
71 bool cacheIsInside(const DateTimeRange &range) const noexcept;
70
72
71 QVector<DateTimeRange> provideNotInCacheRangeList(const DateTimeRange &range) const noexcept;
73 QVector<DateTimeRange> provideNotInCacheRangeList(const DateTimeRange &range) const noexcept;
72 QVector<DateTimeRange> provideInCacheRangeList(const DateTimeRange &range) const noexcept;
74 QVector<DateTimeRange> provideInCacheRangeList(const DateTimeRange &range) const noexcept;
75 DEPRECATE(
73 void mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
76 void mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
77 )
78 void mergeDataSeries(IDataSeries* dataSeries) noexcept;
74
79
75 static QVector<DateTimeRange> provideNotInCacheRangeList(const DateTimeRange &oldRange,
80 static QVector<DateTimeRange> provideNotInCacheRangeList(const DateTimeRange &oldRange,
76 const DateTimeRange &nextRange);
81 const DateTimeRange &nextRange);
77
82
78 static QVector<DateTimeRange> provideInCacheRangeList(const DateTimeRange &oldRange,
83 static QVector<DateTimeRange> provideInCacheRangeList(const DateTimeRange &oldRange,
79 const DateTimeRange &nextRange);
84 const DateTimeRange &nextRange);
80
85
86 QUuid ID(){return _uuid;}
81 signals:
87 signals:
82 void updated();
88 void updated();
83 /// Signal emitted when when the data series of the variable is loaded for the first time
89 /// Signal emitted when when the data series of the variable is loaded for the first time
84 void dataInitialized();
90 void dataInitialized();
85
91
86 private:
92 private:
87 class VariablePrivate;
93 class VariablePrivate;
88 spimpl::unique_impl_ptr<VariablePrivate> impl;
94 spimpl::unique_impl_ptr<VariablePrivate> impl;
95 QUuid _uuid;
89 };
96 };
90
97
91 // Required for using shared_ptr in signals/slots
98 // Required for using shared_ptr in signals/slots
92 SCIQLOP_REGISTER_META_TYPE(VARIABLE_PTR_REGISTRY, std::shared_ptr<Variable>)
99 SCIQLOP_REGISTER_META_TYPE(VARIABLE_PTR_REGISTRY, std::shared_ptr<Variable>)
93 SCIQLOP_REGISTER_META_TYPE(VARIABLE_PTR_VECTOR_REGISTRY, QVector<std::shared_ptr<Variable> >)
100 SCIQLOP_REGISTER_META_TYPE(VARIABLE_PTR_VECTOR_REGISTRY, QVector<std::shared_ptr<Variable> >)
94
101
95 #endif // SCIQLOP_VARIABLE_H
102 #endif // SCIQLOP_VARIABLE_H
@@ -1,26 +1,36
1 #include <Common/spimpl.h>
2 #include <memory>
1 #include <memory>
3 #include <vector>
2 #include <vector>
4 #include <QHash>
3 #include <QHash>
4 #include <QObject>
5 #include <QMutexLocker>
6 #include <QUuid>
7 #include <QItemSelectionModel>
8 #include <Common/spimpl.h>
5 #include <Variable/Variable.h>
9 #include <Variable/Variable.h>
6 #include <Variable/VariableSynchronizationGroup.h>
10 #include <Variable/VariableSynchronizationGroup.h>
7 #include <Variable/VariableModel.h>
11 #include <Variable/VariableModel.h>
8 #include <Data/IDataProvider.h>
12 #include <Data/IDataProvider.h>
9 #include "Data/DateTimeRange.h"
13 #include "Data/DateTimeRange.h"
10 #include <QMutexLocker>
11 #include <QUuid>
12 #include <QItemSelectionModel>
13
14
14 class VariableController2Private;
15 class VariableController2: public QObject
15 class VariableController2
16 {
16 {
17 class VariableController2Private;
18 Q_OBJECT
19
17 spimpl::unique_impl_ptr<VariableController2Private> impl;
20 spimpl::unique_impl_ptr<VariableController2Private> impl;
18
21
19 public:
22 public:
20 explicit VariableController2();
23 explicit VariableController2();
21 std::shared_ptr<Variable> createVariable(const QString &name, const QVariantHash &metadata,
24 std::shared_ptr<Variable> createVariable(const QString &name, const QVariantHash &metadata,
22 std::shared_ptr<IDataProvider> provider, const DateTimeRange &range);
25 std::shared_ptr<IDataProvider> provider, const DateTimeRange &range);
23 void changeRange(QUuid variable, DateTimeRange r);
26
24 void asyncChangeRange(QUuid variable, DateTimeRange r);
27 void deleteVariable(std::shared_ptr<Variable> variable);
28 void changeRange(std::shared_ptr<Variable> variable, DateTimeRange r);
29 void asyncChangeRange(std::shared_ptr<Variable> variable, DateTimeRange r);
30 const std::set<std::shared_ptr<Variable> > &variables();
31
32 signals:
33 void variableAdded(std::shared_ptr<Variable>);
34 void variableDeleted(std::shared_ptr<Variable>);
25
35
26 };
36 };
@@ -1,430 +1,461
1 #include "Variable/Variable.h"
1 #include "Variable/Variable.h"
2
2
3 #include <Data/IDataSeries.h>
3 #include <Data/IDataSeries.h>
4 #include <Data/DateTimeRange.h>
4 #include <Data/DateTimeRange.h>
5
5
6 #include <QMutex>
6 #include <QMutex>
7 #include <QReadWriteLock>
7 #include <QReadWriteLock>
8 #include <QThread>
8 #include <QThread>
9 #include <Common/debug.h>
9
10
10 Q_LOGGING_CATEGORY(LOG_Variable, "Variable")
11 Q_LOGGING_CATEGORY(LOG_Variable, "Variable")
11
12
12 namespace {
13 namespace {
13
14
14 /**
15 /**
15 * Searches in metadata for a value that can be converted to DataSeriesType
16 * Searches in metadata for a value that can be converted to DataSeriesType
16 * @param metadata the metadata where to search
17 * @param metadata the metadata where to search
17 * @return the value converted to a DataSeriesType if it was found, UNKNOWN type otherwise
18 * @return the value converted to a DataSeriesType if it was found, UNKNOWN type otherwise
18 * @sa DataSeriesType
19 * @sa DataSeriesType
19 */
20 */
20 DataSeriesType findDataSeriesType(const QVariantHash &metadata)
21 DataSeriesType findDataSeriesType(const QVariantHash &metadata)
21 {
22 {
22 auto dataSeriesType = DataSeriesType::UNKNOWN;
23 auto dataSeriesType = DataSeriesType::UNKNOWN;
23
24
24 // Go through the metadata and stop at the first value that could be converted to DataSeriesType
25 // Go through the metadata and stop at the first value that could be converted to DataSeriesType
25 for (auto it = metadata.cbegin(), end = metadata.cend();
26 for (auto it = metadata.cbegin(), end = metadata.cend();
26 it != end && dataSeriesType == DataSeriesType::UNKNOWN; ++it) {
27 it != end && dataSeriesType == DataSeriesType::UNKNOWN; ++it) {
27 dataSeriesType = DataSeriesTypeUtils::fromString(it.value().toString());
28 dataSeriesType = DataSeriesTypeUtils::fromString(it.value().toString());
28 }
29 }
29
30
30 return dataSeriesType;
31 return dataSeriesType;
31 }
32 }
32
33
33 } // namespace
34 } // namespace
34
35
35 struct Variable::VariablePrivate {
36 struct Variable::VariablePrivate {
36 explicit VariablePrivate(const QString &name, const QVariantHash &metadata)
37 explicit VariablePrivate(const QString &name, const QVariantHash &metadata)
37 : m_Name{name},
38 : m_Name{name},
38 m_Range{INVALID_RANGE},
39 m_Range{INVALID_RANGE},
39 m_CacheRange{INVALID_RANGE},
40 m_CacheRange{INVALID_RANGE},
40 m_Metadata{metadata},
41 m_Metadata{metadata},
41 m_DataSeries{nullptr},
42 m_DataSeries{nullptr},
42 m_RealRange{INVALID_RANGE},
43 m_RealRange{INVALID_RANGE},
43 m_NbPoints{0},
44 m_NbPoints{0},
44 m_Type{findDataSeriesType(m_Metadata)}
45 m_Type{findDataSeriesType(m_Metadata)}
45 {
46 {
46 }
47 }
47
48
48 VariablePrivate(const VariablePrivate &other)
49 VariablePrivate(const VariablePrivate &other)
49 : m_Name{other.m_Name},
50 : m_Name{other.m_Name},
50 m_Range{other.m_Range},
51 m_Range{other.m_Range},
51 m_CacheRange{other.m_CacheRange},
52 m_CacheRange{other.m_CacheRange},
52 m_Metadata{other.m_Metadata},
53 m_Metadata{other.m_Metadata},
53 m_DataSeries{other.m_DataSeries != nullptr ? other.m_DataSeries->clone() : nullptr},
54 m_DataSeries{other.m_DataSeries != nullptr ? other.m_DataSeries->clone() : nullptr},
54 m_RealRange{other.m_RealRange},
55 m_RealRange{other.m_RealRange},
55 m_NbPoints{other.m_NbPoints},
56 m_NbPoints{other.m_NbPoints},
56 m_Type{findDataSeriesType(m_Metadata)}
57 m_Type{findDataSeriesType(m_Metadata)}
57 {
58 {
58 }
59 }
59
60
60 void lockRead() { m_Lock.lockForRead(); }
61 void lockRead() { m_Lock.lockForRead(); }
61 void lockWrite() { m_Lock.lockForWrite(); }
62 void lockWrite() { m_Lock.lockForWrite(); }
62 void unlock() { m_Lock.unlock(); }
63 void unlock() { m_Lock.unlock(); }
63
64
64 void purgeDataSeries()
65 void purgeDataSeries()
65 {
66 {
66 if (m_DataSeries) {
67 if (m_DataSeries) {
67 m_DataSeries->purge(m_CacheRange.m_TStart, m_CacheRange.m_TEnd);
68 m_DataSeries->purge(m_CacheRange.m_TStart, m_CacheRange.m_TEnd);
68 }
69 }
69 updateRealRange();
70 updateRealRange();
70 updateNbPoints();
71 updateNbPoints();
71 }
72 }
72
73
73 void updateNbPoints() { m_NbPoints = m_DataSeries ? m_DataSeries->nbPoints() : 0; }
74 void updateNbPoints() { m_NbPoints = m_DataSeries ? m_DataSeries->nbPoints() : 0; }
74
75
75 /// Updates real range according to current variable range and data series
76 /// Updates real range according to current variable range and data series
76 void updateRealRange()
77 void updateRealRange()
77 {
78 {
78 if (m_DataSeries) {
79 if (m_DataSeries) {
79 m_DataSeries->lockRead();
80 m_DataSeries->lockRead();
80 auto end = m_DataSeries->cend();
81 auto end = m_DataSeries->cend();
81 auto minXAxisIt = m_DataSeries->minXAxisData(m_Range.m_TStart);
82 auto minXAxisIt = m_DataSeries->minXAxisData(m_Range.m_TStart);
82 auto maxXAxisIt = m_DataSeries->maxXAxisData(m_Range.m_TEnd);
83 auto maxXAxisIt = m_DataSeries->maxXAxisData(m_Range.m_TEnd);
83
84
84 m_RealRange
85 m_RealRange
85 = (minXAxisIt != end && maxXAxisIt != end && minXAxisIt->x() <= maxXAxisIt->x())
86 = (minXAxisIt != end && maxXAxisIt != end && minXAxisIt->x() <= maxXAxisIt->x())
86 ? DateTimeRange{minXAxisIt->x(), maxXAxisIt->x()}
87 ? DateTimeRange{minXAxisIt->x(), maxXAxisIt->x()}
87 : INVALID_RANGE;
88 : INVALID_RANGE;
88 m_DataSeries->unlock();
89 m_DataSeries->unlock();
89 }
90 }
90 else {
91 else {
91 m_RealRange = INVALID_RANGE;
92 m_RealRange = INVALID_RANGE;
92 }
93 }
93 }
94 }
94
95
95 QString m_Name;
96 QString m_Name;
96
97
97 DateTimeRange m_Range;
98 DateTimeRange m_Range;
98 DateTimeRange m_CacheRange;
99 DateTimeRange m_CacheRange;
99 QVariantHash m_Metadata;
100 QVariantHash m_Metadata;
100 std::shared_ptr<IDataSeries> m_DataSeries;
101 std::shared_ptr<IDataSeries> m_DataSeries;
101 DateTimeRange m_RealRange;
102 DateTimeRange m_RealRange;
102 int m_NbPoints;
103 int m_NbPoints;
103 DataSeriesType m_Type;
104 DataSeriesType m_Type;
104
105
105 QReadWriteLock m_Lock;
106 QReadWriteLock m_Lock;
106 };
107 };
107
108
108 Variable::Variable(const QString &name, const QVariantHash &metadata)
109 Variable::Variable(const QString &name, const QVariantHash &metadata)
109 : impl{spimpl::make_unique_impl<VariablePrivate>(name, metadata)}
110 : impl{spimpl::make_unique_impl<VariablePrivate>(name, metadata)},
111 _uuid{QUuid::createUuid()}
110 {
112 {
111 }
113 }
112
114
113 Variable::Variable(const Variable &other)
115 Variable::Variable(const Variable &other)
114 : impl{spimpl::make_unique_impl<VariablePrivate>(*other.impl)}
116 : impl{spimpl::make_unique_impl<VariablePrivate>(*other.impl)},
117 _uuid{QUuid::createUuid()} //is a clone but must have a != uuid
115 {
118 {
116 }
119 }
117
120
118 std::shared_ptr<Variable> Variable::clone() const
121 std::shared_ptr<Variable> Variable::clone() const
119 {
122 {
120 return std::make_shared<Variable>(*this);
123 return std::make_shared<Variable>(*this);
121 }
124 }
122
125
123 QString Variable::name() const noexcept
126 QString Variable::name() const noexcept
124 {
127 {
125 impl->lockRead();
128 impl->lockRead();
126 auto name = impl->m_Name;
129 auto name = impl->m_Name;
127 impl->unlock();
130 impl->unlock();
128 return name;
131 return name;
129 }
132 }
130
133
131 void Variable::setName(const QString &name) noexcept
134 void Variable::setName(const QString &name) noexcept
132 {
135 {
133 impl->lockWrite();
136 impl->lockWrite();
134 impl->m_Name = name;
137 impl->m_Name = name;
135 impl->unlock();
138 impl->unlock();
136 }
139 }
137
140
138 DateTimeRange Variable::range() const noexcept
141 DateTimeRange Variable::range() const noexcept
139 {
142 {
140 impl->lockRead();
143 impl->lockRead();
141 auto range = impl->m_Range;
144 auto range = impl->m_Range;
142 impl->unlock();
145 impl->unlock();
143 return range;
146 return range;
144 }
147 }
145
148
146 void Variable::setRange(const DateTimeRange &range) noexcept
149 void Variable::setRange(const DateTimeRange &range) noexcept
147 {
150 {
148 impl->lockWrite();
151 impl->lockWrite();
149 impl->m_Range = range;
152 impl->m_Range = range;
150 impl->updateRealRange();
153 impl->updateRealRange();
151 impl->unlock();
154 impl->unlock();
152 }
155 }
153
156
154 DateTimeRange Variable::cacheRange() const noexcept
157 DateTimeRange Variable::cacheRange() const noexcept
155 {
158 {
156 impl->lockRead();
159 impl->lockRead();
157 auto cacheRange = impl->m_CacheRange;
160 auto cacheRange = impl->m_CacheRange;
158 impl->unlock();
161 impl->unlock();
159 return cacheRange;
162 return cacheRange;
160 }
163 }
161
164
162 void Variable::setCacheRange(const DateTimeRange &cacheRange) noexcept
165 void Variable::setCacheRange(const DateTimeRange &cacheRange) noexcept
163 {
166 {
164 impl->lockWrite();
167 impl->lockWrite();
165 if (cacheRange != impl->m_CacheRange) {
168 if (cacheRange != impl->m_CacheRange) {
166 impl->m_CacheRange = cacheRange;
169 impl->m_CacheRange = cacheRange;
167 }
170 }
168 impl->unlock();
171 impl->unlock();
169 }
172 }
170
173
171 int Variable::nbPoints() const noexcept
174 int Variable::nbPoints() const noexcept
172 {
175 {
173 return impl->m_NbPoints;
176 return impl->m_NbPoints;
174 }
177 }
175
178
176 DateTimeRange Variable::realRange() const noexcept
179 DateTimeRange Variable::realRange() const noexcept
177 {
180 {
178 return impl->m_RealRange;
181 return impl->m_RealRange;
179 }
182 }
180
183
181 void Variable::mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
184 void Variable::mergeDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
182 {
185 {
183 qCDebug(LOG_Variable()) << "TORM Variable::mergeDataSeries"
186 qCDebug(LOG_Variable()) << "TORM Variable::mergeDataSeries"
184 << QThread::currentThread()->objectName();
187 << QThread::currentThread()->objectName();
185 if (!dataSeries) {
188 if (!dataSeries) {
186 /// @todo ALX : log
189 /// @todo ALX : log
187 return;
190 return;
188 }
191 }
189
192
190 auto dataInit = false;
193 auto dataInit = false;
191
194
192 // Add or merge the data
195 // Add or merge the data
193 impl->lockWrite();
196 impl->lockWrite();
194 if (!impl->m_DataSeries) {
197 if (!impl->m_DataSeries) {
195 impl->m_DataSeries = dataSeries->clone();
198 impl->m_DataSeries = dataSeries->clone();
196 dataInit = true;
199 dataInit = true;
197 }
200 }
198 else {
201 else {
199 impl->m_DataSeries->merge(dataSeries.get());
202 impl->m_DataSeries->merge(dataSeries.get());
200 }
203 }
201 impl->purgeDataSeries();
204 impl->purgeDataSeries();
202 impl->unlock();
205 impl->unlock();
203
206
204 if (dataInit) {
207 if (dataInit) {
205 emit dataInitialized();
208 emit dataInitialized();
206 }
209 }
207 }
210 }
208
211
212 void Variable::mergeDataSeries(IDataSeries *dataSeries) noexcept
213 {
214 if (dataSeries==nullptr) {
215 SCIQLOP_ERROR("Given IDataSeries is nullptr");
216 return;
217 }
218
219 auto dataInit = false;
220 // @TODO move to impl to Pimpl this is what it stands for...
221 // Add or merge the data
222 impl->lockWrite();
223 if (!impl->m_DataSeries) {
224 //@TODO find a better way
225 impl->m_DataSeries = dataSeries->clone();
226 dataInit = true;
227 delete dataSeries;
228 }
229 else {
230 impl->m_DataSeries->merge(dataSeries);
231 }
232 impl->purgeDataSeries();
233 impl->unlock();
234
235 if (dataInit) {
236 emit dataInitialized();
237 }
238 }
239
209
240
210 std::shared_ptr<IDataSeries> Variable::dataSeries() const noexcept
241 std::shared_ptr<IDataSeries> Variable::dataSeries() const noexcept
211 {
242 {
212 impl->lockRead();
243 impl->lockRead();
213 auto dataSeries = impl->m_DataSeries;
244 auto dataSeries = impl->m_DataSeries;
214 impl->unlock();
245 impl->unlock();
215
246
216 return dataSeries;
247 return dataSeries;
217 }
248 }
218
249
219 DataSeriesType Variable::type() const noexcept
250 DataSeriesType Variable::type() const noexcept
220 {
251 {
221 impl->lockRead();
252 impl->lockRead();
222 auto type = impl->m_Type;
253 auto type = impl->m_Type;
223 impl->unlock();
254 impl->unlock();
224
255
225 return type;
256 return type;
226 }
257 }
227
258
228 QVariantHash Variable::metadata() const noexcept
259 QVariantHash Variable::metadata() const noexcept
229 {
260 {
230 impl->lockRead();
261 impl->lockRead();
231 auto metadata = impl->m_Metadata;
262 auto metadata = impl->m_Metadata;
232 impl->unlock();
263 impl->unlock();
233 return metadata;
264 return metadata;
234 }
265 }
235
266
236 bool Variable::contains(const DateTimeRange &range) const noexcept
267 bool Variable::contains(const DateTimeRange &range) const noexcept
237 {
268 {
238 impl->lockRead();
269 impl->lockRead();
239 auto res = impl->m_Range.contains(range);
270 auto res = impl->m_Range.contains(range);
240 impl->unlock();
271 impl->unlock();
241 return res;
272 return res;
242 }
273 }
243
274
244 bool Variable::intersect(const DateTimeRange &range) const noexcept
275 bool Variable::intersect(const DateTimeRange &range) const noexcept
245 {
276 {
246
277
247 impl->lockRead();
278 impl->lockRead();
248 auto res = impl->m_Range.intersect(range);
279 auto res = impl->m_Range.intersect(range);
249 impl->unlock();
280 impl->unlock();
250 return res;
281 return res;
251 }
282 }
252
283
253 bool Variable::isInside(const DateTimeRange &range) const noexcept
284 bool Variable::isInside(const DateTimeRange &range) const noexcept
254 {
285 {
255 impl->lockRead();
286 impl->lockRead();
256 auto res = range.contains(DateTimeRange{impl->m_Range.m_TStart, impl->m_Range.m_TEnd});
287 auto res = range.contains(DateTimeRange{impl->m_Range.m_TStart, impl->m_Range.m_TEnd});
257 impl->unlock();
288 impl->unlock();
258 return res;
289 return res;
259 }
290 }
260
291
261 bool Variable::cacheContains(const DateTimeRange &range) const noexcept
292 bool Variable::cacheContains(const DateTimeRange &range) const noexcept
262 {
293 {
263 impl->lockRead();
294 impl->lockRead();
264 auto res = impl->m_CacheRange.contains(range);
295 auto res = impl->m_CacheRange.contains(range);
265 impl->unlock();
296 impl->unlock();
266 return res;
297 return res;
267 }
298 }
268
299
269 bool Variable::cacheIntersect(const DateTimeRange &range) const noexcept
300 bool Variable::cacheIntersect(const DateTimeRange &range) const noexcept
270 {
301 {
271 impl->lockRead();
302 impl->lockRead();
272 auto res = impl->m_CacheRange.intersect(range);
303 auto res = impl->m_CacheRange.intersect(range);
273 impl->unlock();
304 impl->unlock();
274 return res;
305 return res;
275 }
306 }
276
307
277 bool Variable::cacheIsInside(const DateTimeRange &range) const noexcept
308 bool Variable::cacheIsInside(const DateTimeRange &range) const noexcept
278 {
309 {
279 impl->lockRead();
310 impl->lockRead();
280 auto res = range.contains(DateTimeRange{impl->m_CacheRange.m_TStart, impl->m_CacheRange.m_TEnd});
311 auto res = range.contains(DateTimeRange{impl->m_CacheRange.m_TStart, impl->m_CacheRange.m_TEnd});
281 impl->unlock();
312 impl->unlock();
282 return res;
313 return res;
283 }
314 }
284
315
285
316
286 QVector<DateTimeRange> Variable::provideNotInCacheRangeList(const DateTimeRange &range) const noexcept
317 QVector<DateTimeRange> Variable::provideNotInCacheRangeList(const DateTimeRange &range) const noexcept
287 {
318 {
288 // This code assume that cach in contigue. Can return 0, 1 or 2 SqpRange
319 // This code assume that cach in contigue. Can return 0, 1 or 2 SqpRange
289 auto notInCache = QVector<DateTimeRange>{};
320 auto notInCache = QVector<DateTimeRange>{};
290 if (impl->m_CacheRange != INVALID_RANGE) {
321 if (impl->m_CacheRange != INVALID_RANGE) {
291
322
292 if (!this->cacheContains(range)) {
323 if (!this->cacheContains(range)) {
293 if (range.m_TEnd <= impl->m_CacheRange.m_TStart
324 if (range.m_TEnd <= impl->m_CacheRange.m_TStart
294 || range.m_TStart >= impl->m_CacheRange.m_TEnd) {
325 || range.m_TStart >= impl->m_CacheRange.m_TEnd) {
295 notInCache << range;
326 notInCache << range;
296 }
327 }
297 else if (range.m_TStart < impl->m_CacheRange.m_TStart
328 else if (range.m_TStart < impl->m_CacheRange.m_TStart
298 && range.m_TEnd <= impl->m_CacheRange.m_TEnd) {
329 && range.m_TEnd <= impl->m_CacheRange.m_TEnd) {
299 notInCache << DateTimeRange{range.m_TStart, impl->m_CacheRange.m_TStart};
330 notInCache << DateTimeRange{range.m_TStart, impl->m_CacheRange.m_TStart};
300 }
331 }
301 else if (range.m_TStart < impl->m_CacheRange.m_TStart
332 else if (range.m_TStart < impl->m_CacheRange.m_TStart
302 && range.m_TEnd > impl->m_CacheRange.m_TEnd) {
333 && range.m_TEnd > impl->m_CacheRange.m_TEnd) {
303 notInCache << DateTimeRange{range.m_TStart, impl->m_CacheRange.m_TStart}
334 notInCache << DateTimeRange{range.m_TStart, impl->m_CacheRange.m_TStart}
304 << DateTimeRange{impl->m_CacheRange.m_TEnd, range.m_TEnd};
335 << DateTimeRange{impl->m_CacheRange.m_TEnd, range.m_TEnd};
305 }
336 }
306 else if (range.m_TStart < impl->m_CacheRange.m_TEnd) {
337 else if (range.m_TStart < impl->m_CacheRange.m_TEnd) {
307 notInCache << DateTimeRange{impl->m_CacheRange.m_TEnd, range.m_TEnd};
338 notInCache << DateTimeRange{impl->m_CacheRange.m_TEnd, range.m_TEnd};
308 }
339 }
309 else {
340 else {
310 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
341 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
311 << QThread::currentThread();
342 << QThread::currentThread();
312 }
343 }
313 }
344 }
314 }
345 }
315 else {
346 else {
316 notInCache << range;
347 notInCache << range;
317 }
348 }
318
349
319 return notInCache;
350 return notInCache;
320 }
351 }
321
352
322 QVector<DateTimeRange> Variable::provideInCacheRangeList(const DateTimeRange &range) const noexcept
353 QVector<DateTimeRange> Variable::provideInCacheRangeList(const DateTimeRange &range) const noexcept
323 {
354 {
324 // This code assume that cach in contigue. Can return 0 or 1 SqpRange
355 // This code assume that cach in contigue. Can return 0 or 1 SqpRange
325
356
326 auto inCache = QVector<DateTimeRange>{};
357 auto inCache = QVector<DateTimeRange>{};
327
358
328 if (impl->m_CacheRange != INVALID_RANGE) {
359 if (impl->m_CacheRange != INVALID_RANGE) {
329
360
330 if (this->cacheIntersect(range)) {
361 if (this->cacheIntersect(range)) {
331 if (range.m_TStart <= impl->m_CacheRange.m_TStart
362 if (range.m_TStart <= impl->m_CacheRange.m_TStart
332 && range.m_TEnd >= impl->m_CacheRange.m_TStart
363 && range.m_TEnd >= impl->m_CacheRange.m_TStart
333 && range.m_TEnd < impl->m_CacheRange.m_TEnd) {
364 && range.m_TEnd < impl->m_CacheRange.m_TEnd) {
334 inCache << DateTimeRange{impl->m_CacheRange.m_TStart, range.m_TEnd};
365 inCache << DateTimeRange{impl->m_CacheRange.m_TStart, range.m_TEnd};
335 }
366 }
336
367
337 else if (range.m_TStart >= impl->m_CacheRange.m_TStart
368 else if (range.m_TStart >= impl->m_CacheRange.m_TStart
338 && range.m_TEnd <= impl->m_CacheRange.m_TEnd) {
369 && range.m_TEnd <= impl->m_CacheRange.m_TEnd) {
339 inCache << range;
370 inCache << range;
340 }
371 }
341 else if (range.m_TStart > impl->m_CacheRange.m_TStart
372 else if (range.m_TStart > impl->m_CacheRange.m_TStart
342 && range.m_TEnd > impl->m_CacheRange.m_TEnd) {
373 && range.m_TEnd > impl->m_CacheRange.m_TEnd) {
343 inCache << DateTimeRange{range.m_TStart, impl->m_CacheRange.m_TEnd};
374 inCache << DateTimeRange{range.m_TStart, impl->m_CacheRange.m_TEnd};
344 }
375 }
345 else if (range.m_TStart <= impl->m_CacheRange.m_TStart
376 else if (range.m_TStart <= impl->m_CacheRange.m_TStart
346 && range.m_TEnd >= impl->m_CacheRange.m_TEnd) {
377 && range.m_TEnd >= impl->m_CacheRange.m_TEnd) {
347 inCache << impl->m_CacheRange;
378 inCache << impl->m_CacheRange;
348 }
379 }
349 else {
380 else {
350 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
381 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
351 << QThread::currentThread();
382 << QThread::currentThread();
352 }
383 }
353 }
384 }
354 }
385 }
355
386
356 return inCache;
387 return inCache;
357 }
388 }
358
389
359
390
360 QVector<DateTimeRange> Variable::provideNotInCacheRangeList(const DateTimeRange &oldRange,
391 QVector<DateTimeRange> Variable::provideNotInCacheRangeList(const DateTimeRange &oldRange,
361 const DateTimeRange &nextRange)
392 const DateTimeRange &nextRange)
362 {
393 {
363
394
364 // This code assume that cach in contigue. Can return 0, 1 or 2 SqpRange
395 // This code assume that cach in contigue. Can return 0, 1 or 2 SqpRange
365 auto notInCache = QVector<DateTimeRange>{};
396 auto notInCache = QVector<DateTimeRange>{};
366 if (oldRange != INVALID_RANGE) {
397 if (oldRange != INVALID_RANGE) {
367
398
368 if (!oldRange.contains(nextRange)) {
399 if (!oldRange.contains(nextRange)) {
369 if (nextRange.m_TEnd <= oldRange.m_TStart || nextRange.m_TStart >= oldRange.m_TEnd) {
400 if (nextRange.m_TEnd <= oldRange.m_TStart || nextRange.m_TStart >= oldRange.m_TEnd) {
370 notInCache << nextRange;
401 notInCache << nextRange;
371 }
402 }
372 else if (nextRange.m_TStart < oldRange.m_TStart
403 else if (nextRange.m_TStart < oldRange.m_TStart
373 && nextRange.m_TEnd <= oldRange.m_TEnd) {
404 && nextRange.m_TEnd <= oldRange.m_TEnd) {
374 notInCache << DateTimeRange{nextRange.m_TStart, oldRange.m_TStart};
405 notInCache << DateTimeRange{nextRange.m_TStart, oldRange.m_TStart};
375 }
406 }
376 else if (nextRange.m_TStart < oldRange.m_TStart && nextRange.m_TEnd > oldRange.m_TEnd) {
407 else if (nextRange.m_TStart < oldRange.m_TStart && nextRange.m_TEnd > oldRange.m_TEnd) {
377 notInCache << DateTimeRange{nextRange.m_TStart, oldRange.m_TStart}
408 notInCache << DateTimeRange{nextRange.m_TStart, oldRange.m_TStart}
378 << DateTimeRange{oldRange.m_TEnd, nextRange.m_TEnd};
409 << DateTimeRange{oldRange.m_TEnd, nextRange.m_TEnd};
379 }
410 }
380 else if (nextRange.m_TStart < oldRange.m_TEnd) {
411 else if (nextRange.m_TStart < oldRange.m_TEnd) {
381 notInCache << DateTimeRange{oldRange.m_TEnd, nextRange.m_TEnd};
412 notInCache << DateTimeRange{oldRange.m_TEnd, nextRange.m_TEnd};
382 }
413 }
383 else {
414 else {
384 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
415 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
385 << QThread::currentThread();
416 << QThread::currentThread();
386 }
417 }
387 }
418 }
388 }
419 }
389 else {
420 else {
390 notInCache << nextRange;
421 notInCache << nextRange;
391 }
422 }
392
423
393 return notInCache;
424 return notInCache;
394 }
425 }
395
426
396 QVector<DateTimeRange> Variable::provideInCacheRangeList(const DateTimeRange &oldRange,
427 QVector<DateTimeRange> Variable::provideInCacheRangeList(const DateTimeRange &oldRange,
397 const DateTimeRange &nextRange)
428 const DateTimeRange &nextRange)
398 {
429 {
399 // This code assume that cach is contigue. Can return 0 or 1 SqpRange
430 // This code assume that cach is contigue. Can return 0 or 1 SqpRange
400
431
401 auto inCache = QVector<DateTimeRange>{};
432 auto inCache = QVector<DateTimeRange>{};
402
433
403 if (oldRange != INVALID_RANGE) {
434 if (oldRange != INVALID_RANGE) {
404
435
405 if (oldRange.intersect(nextRange)) {
436 if (oldRange.intersect(nextRange)) {
406 if (nextRange.m_TStart <= oldRange.m_TStart && nextRange.m_TEnd >= oldRange.m_TStart
437 if (nextRange.m_TStart <= oldRange.m_TStart && nextRange.m_TEnd >= oldRange.m_TStart
407 && nextRange.m_TEnd < oldRange.m_TEnd) {
438 && nextRange.m_TEnd < oldRange.m_TEnd) {
408 inCache << DateTimeRange{oldRange.m_TStart, nextRange.m_TEnd};
439 inCache << DateTimeRange{oldRange.m_TStart, nextRange.m_TEnd};
409 }
440 }
410
441
411 else if (nextRange.m_TStart >= oldRange.m_TStart
442 else if (nextRange.m_TStart >= oldRange.m_TStart
412 && nextRange.m_TEnd <= oldRange.m_TEnd) {
443 && nextRange.m_TEnd <= oldRange.m_TEnd) {
413 inCache << nextRange;
444 inCache << nextRange;
414 }
445 }
415 else if (nextRange.m_TStart > oldRange.m_TStart && nextRange.m_TEnd > oldRange.m_TEnd) {
446 else if (nextRange.m_TStart > oldRange.m_TStart && nextRange.m_TEnd > oldRange.m_TEnd) {
416 inCache << DateTimeRange{nextRange.m_TStart, oldRange.m_TEnd};
447 inCache << DateTimeRange{nextRange.m_TStart, oldRange.m_TEnd};
417 }
448 }
418 else if (nextRange.m_TStart <= oldRange.m_TStart
449 else if (nextRange.m_TStart <= oldRange.m_TStart
419 && nextRange.m_TEnd >= oldRange.m_TEnd) {
450 && nextRange.m_TEnd >= oldRange.m_TEnd) {
420 inCache << oldRange;
451 inCache << oldRange;
421 }
452 }
422 else {
453 else {
423 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
454 qCCritical(LOG_Variable()) << tr("Detection of unknown case.")
424 << QThread::currentThread();
455 << QThread::currentThread();
425 }
456 }
426 }
457 }
427 }
458 }
428
459
429 return inCache;
460 return inCache;
430 }
461 }
@@ -1,25 +1,83
1 #include "Variable/VariableController2.h"
1 #include "Variable/VariableController2.h"
2 #include <Common/containers.h>
3 #include <Common/debug.h>
4 #include <Data/DataProviderParameters.h>
2
5
3
6 class VariableController2::VariableController2Private
4 class VariableController2Private
5 {
7 {
6
8 std::set<std::shared_ptr<Variable>> _variables;
9 QMap<QUuid,std::shared_ptr<IDataProvider>> _providers;
7 public:
10 public:
8 VariableController2Private(QObject* parent=Q_NULLPTR)
11 VariableController2Private(QObject* parent=Q_NULLPTR)
9 {}
12 {
13 Q_UNUSED(parent);
14 }
15
10 ~VariableController2Private() = default;
16 ~VariableController2Private() = default;
17
11 std::shared_ptr<Variable> createVariable(const QString &name, const QVariantHash &metadata, std::shared_ptr<IDataProvider> provider, const DateTimeRange &range)
18 std::shared_ptr<Variable> createVariable(const QString &name, const QVariantHash &metadata, std::shared_ptr<IDataProvider> provider, const DateTimeRange &range)
12 {
19 {
13 return std::make_shared<Variable>(name,metadata);
20 auto newVar = std::make_shared<Variable>(name,metadata);
21 this->_variables.insert(newVar);
22 this->_providers[newVar->ID()] = provider;
23 return newVar;
24 }
25
26 void deleteVariable(std::shared_ptr<Variable> variable)
27 {
28 if(this->_providers.contains(variable->ID()))
29 this->_providers.remove(variable->ID());
30 if(SciQLop::containers::contains(this->_variables, variable))
31 this->_variables.erase(variable);
32 }
33
34 void changeRange(std::shared_ptr<Variable> variable, DateTimeRange r)
35 {
36 if(_providers.contains(variable->ID()))
37 {
38 auto provider = _providers[variable->ID()];
39 auto data = provider->getData(DataProviderParameters{{r},variable->metadata()});
40 variable->mergeDataSeries(data);
41 }
42 else
43 {
44 SCIQLOP_ERROR("No provider found for given variable");
45 }
46 }
47
48
49 const std::set<std::shared_ptr<Variable>>& variables()
50 {
51 return _variables;
14 }
52 }
53
15 };
54 };
16
55
17 VariableController2::VariableController2()
56 VariableController2::VariableController2()
18 :impl{spimpl::make_unique_impl<VariableController2Private>()}
57 :impl{spimpl::make_unique_impl<VariableController2Private>()}
19 {}
58 {}
20
59
21 std::shared_ptr<Variable> VariableController2::createVariable(const QString &name, const QVariantHash &metadata, std::shared_ptr<IDataProvider> provider, const DateTimeRange &range)
60 std::shared_ptr<Variable> VariableController2::createVariable(const QString &name, const QVariantHash &metadata, std::shared_ptr<IDataProvider> provider, const DateTimeRange &range)
22 {
61 {
23 return impl->createVariable(name, metadata, provider, range);
62 auto var = impl->createVariable(name, metadata, provider, range);
63 emit variableAdded(var);
64 impl->changeRange(var,range);
65 return var;
66 }
67
68 void VariableController2::deleteVariable(std::shared_ptr<Variable> variable)
69 {
70 impl->deleteVariable(variable);
71 emit variableDeleted(variable);
72 }
73
74 void VariableController2::changeRange(std::shared_ptr<Variable> variable, DateTimeRange r)
75 {
76 impl->changeRange(variable, r);
77 }
78
79 const std::set<std::shared_ptr<Variable> > &VariableController2::variables()
80 {
81 return impl->variables();
24 }
82 }
25
83
@@ -1,30 +1,108
1 #include <cmath>
1 #include <QtTest>
2 #include <QtTest>
2 #include <QObject>
3 #include <QObject>
4 #include <Variable/VariableController2.h>
5 #include <Data/DateTimeRange.h>
6 #include <Data/IDataProvider.h>
7 #include <Data/ScalarSeries.h>
8 #include <Data/DataProviderParameters.h>
9 #include <Common/containers.h>
3
10
11 class FakeProvider: public IDataProvider
12 {
13 public:
14 FakeProvider() = default;
4
15
5 class TestVariableController2 : public QObject
16 std::shared_ptr<IDataProvider> clone() const override{ return std::make_shared<FakeProvider>(); }
17
18 IDataSeries* getData(const DataProviderParameters &parameters) override
19 {
20 auto tstart = parameters.m_Times[0].m_TStart;
21 auto tend = parameters.m_Times[0].m_TEnd;
22 std::vector<double> x;
23 std::vector<double> y;
24 for(auto i = tstart;i<tend;i+=1.) //1 seconde data resolution
25 {
26 x.push_back(i);
27 y.push_back(i);
28 }
29 auto serie = new ScalarSeries(std::move(x),std::move(y),Unit("Secondes",true),Unit("Volts",false));
30 return serie;
31 }
32
33
34
35 void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters &parameters) override
36 {
37 Q_UNUSED(acqIdentifier)
38 Q_UNUSED(parameters)
39 }
40
41 void requestDataAborting(QUuid acqIdentifier) override
42 {
43 Q_UNUSED(acqIdentifier)
44 }
45
46 };
6
47
48 class TestVariableController2 : public QObject
7 {
49 {
8 Q_OBJECT
50 Q_OBJECT
9 public:
51 public:
10 explicit TestVariableController2(QObject *parent = nullptr) : QObject(parent){}
52 explicit TestVariableController2(QObject *parent = nullptr) : QObject(parent){}
11 signals:
53 signals:
12
54
13 private slots:
55 private slots:
14 void initTestCase(){}
56 void initTestCase(){}
15 void cleanupTestCase(){}
57 void cleanupTestCase(){}
16
58
17 void test1()
59 void testCreateVariable()
60 {
61 VariableController2 vc;
62 bool callbackCalled = false;
63 connect(&vc,&VariableController2::variableAdded, [&callbackCalled](std::shared_ptr<Variable>){callbackCalled=true;});
64 auto provider = std::make_shared<FakeProvider>();
65 QVERIFY(!callbackCalled);
66 auto var1 = vc.createVariable("var1",{},provider,DateTimeRange());
67 QVERIFY(SciQLop::containers::contains(vc.variables(), var1));
68 QVERIFY(callbackCalled);
69 }
70
71 void testDeleteVariable()
72 {
73 VariableController2 vc;
74 bool callbackCalled = false;
75 connect(&vc,&VariableController2::variableDeleted, [&callbackCalled](std::shared_ptr<Variable>){callbackCalled=true;});
76 auto provider = std::make_shared<FakeProvider>();
77 auto var1 = vc.createVariable("var1",{},provider,DateTimeRange());
78 QVERIFY(SciQLop::containers::contains(vc.variables(), var1));
79 QVERIFY(!callbackCalled);
80 vc.deleteVariable(var1);
81 QVERIFY(!SciQLop::containers::contains(vc.variables(), var1));
82 QVERIFY(callbackCalled);
83 }
84
85 void testGetData()
18 {
86 {
19 QCOMPARE(1+1, 2);
87 VariableController2 vc;
88 auto provider = std::make_shared<FakeProvider>();
89 auto range1 = DateTimeRange::fromDateTime(QDate(2018,8,7),QTime(14,00),
90 QDate(2018,8,7),QTime(16,00));
91 auto range2 = DateTimeRange::fromDateTime(QDate(2018,8,7),QTime(12,00),
92 QDate(2018,8,7),QTime(18,00));
93 auto var1 = vc.createVariable("var1", {}, provider, range1);
94 QCOMPARE(var1->nbPoints(), int(range1.delta()));
95 vc.changeRange(var1, range2);
96 QCOMPARE(var1->nbPoints(), int(range2.delta()));
97
20 }
98 }
21
99
22 private:
100 private:
23
101
24 };
102 };
25
103
26
104
27 QTEST_MAIN(TestVariableController2)
105 QTEST_MAIN(TestVariableController2)
28
106
29 #include "TestVariableController2.moc"
107 #include "TestVariableController2.moc"
30
108
General Comments 0
You need to be logged in to leave comments. Login now