##// END OF EJS Templates
Reads variable's metadata to retrieve the type of data series (scalar, vector, spectrogram)
Alexandre Leroux -
r1279:88939ef97b8f
parent child
Show More
@@ -4,6 +4,7
4 4 #include "CoreGlobal.h"
5 5
6 6 #include <Data/DataSeriesIterator.h>
7 #include <Data/DataSeriesType.h>
7 8 #include <Data/SqpRange.h>
8 9
9 10 #include <QLoggingCategory>
@@ -54,6 +55,9 public:
54 55 /// @return the data of the variable, nullptr if there is no data
55 56 std::shared_ptr<IDataSeries> dataSeries() const noexcept;
56 57
58 /// @return the type of data that the variable holds
59 DataSeriesType type() const noexcept;
60
57 61 QVariantHash metadata() const noexcept;
58 62
59 63 bool contains(const SqpRange &range) const noexcept;
@@ -9,6 +9,29
9 9
10 10 Q_LOGGING_CATEGORY(LOG_Variable, "Variable")
11 11
12 namespace {
13
14 /**
15 * Searches in metadata for a value that can be converted to DataSeriesType
16 * @param metadata the metadata where to search
17 * @return the value converted to a DataSeriesType if it was found, UNKNOWN type otherwise
18 * @sa DataSeriesType
19 */
20 DataSeriesType findDataSeriesType(const QVariantHash &metadata)
21 {
22 auto dataSeriesType = DataSeriesType::UNKNOWN;
23
24 // 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 it != end && dataSeriesType == DataSeriesType::UNKNOWN; ++it) {
27 dataSeriesType = DataSeriesTypeUtils::fromString(it.value().toString());
28 }
29
30 return dataSeriesType;
31 }
32
33 } // namespace
34
12 35 struct Variable::VariablePrivate {
13 36 explicit VariablePrivate(const QString &name, const QVariantHash &metadata)
14 37 : m_Name{name},
@@ -17,7 +40,8 struct Variable::VariablePrivate {
17 40 m_Metadata{metadata},
18 41 m_DataSeries{nullptr},
19 42 m_RealRange{INVALID_RANGE},
20 m_NbPoints{0}
43 m_NbPoints{0},
44 m_Type{findDataSeriesType(m_Metadata)}
21 45 {
22 46 }
23 47
@@ -28,7 +52,8 struct Variable::VariablePrivate {
28 52 m_Metadata{other.m_Metadata},
29 53 m_DataSeries{other.m_DataSeries != nullptr ? other.m_DataSeries->clone() : nullptr},
30 54 m_RealRange{other.m_RealRange},
31 m_NbPoints{other.m_NbPoints}
55 m_NbPoints{other.m_NbPoints},
56 m_Type{findDataSeriesType(m_Metadata)}
32 57 {
33 58 }
34 59
@@ -75,6 +100,7 struct Variable::VariablePrivate {
75 100 std::shared_ptr<IDataSeries> m_DataSeries;
76 101 SqpRange m_RealRange;
77 102 int m_NbPoints;
103 DataSeriesType m_Type;
78 104
79 105 QReadWriteLock m_Lock;
80 106 };
@@ -183,6 +209,15 std::shared_ptr<IDataSeries> Variable::dataSeries() const noexcept
183 209 return dataSeries;
184 210 }
185 211
212 DataSeriesType Variable::type() const noexcept
213 {
214 impl->lockRead();
215 auto type = impl->m_Type;
216 impl->unlock();
217
218 return type;
219 }
220
186 221 QVariantHash Variable::metadata() const noexcept
187 222 {
188 223 impl->lockRead();
General Comments 0
You need to be logged in to leave comments. Login now