diff --git a/core/include/Data/ArrayData.h b/core/include/Data/ArrayData.h index 5da5d72..f390d71 100644 --- a/core/include/Data/ArrayData.h +++ b/core/include/Data/ArrayData.h @@ -11,7 +11,8 @@ * @brief The ArrayData class represents a dataset for a data series. * * A dataset can be unidimensional or two-dimensional. This property is determined by the Dim - * template-parameter. + * template-parameter. In a case of a two-dimensional dataset, each dataset component has the same + * number of values * * @tparam Dim the dimension of the ArrayData (one or two) * @sa IDataSeries @@ -29,6 +30,35 @@ public: m_Data[0] = std::move(data); } + /** + * Ctor for a two-dimensional ArrayData. The number of components (number of vectors) must be + * greater than 2 and each component must have the same number of values + * @param data the data the ArrayData will hold + * @throws std::invalid_argument if the number of components is less than 2 + * @remarks if the number of values is not the same for each component, no value is set + */ + template > + explicit ArrayData(QVector > data) + { + auto nbComponents = data.size(); + if (nbComponents < 2) { + throw std::invalid_argument{ + QString{"A multidimensional ArrayData must have at least 2 components (found: %1"} + .arg(data.size()) + .toStdString()}; + } + + auto nbValues = data.front().size(); + if (std::all_of(data.cbegin(), data.cend(), [nbValues](const auto &component) { + return component.size() == nbValues; + })) { + m_Data = std::move(data); + } + else { + m_Data = QVector >{nbComponents, QVector{}}; + } + } + /// Copy ctor explicit ArrayData(const ArrayData &other) {