diff --git a/core/include/Data/ArrayData.h b/core/include/Data/ArrayData.h index a1aad29..ab14657 100644 --- a/core/include/Data/ArrayData.h +++ b/core/include/Data/ArrayData.h @@ -273,6 +273,13 @@ public: return m_Data.size() / m_NbComponents; } + /// @return the total size (i.e. number of values) of the array data + int totalSize() const + { + QReadLocker locker{&m_Lock}; + return m_Data.size(); + } + std::shared_ptr > sort(const std::vector &sortPermutation) { QReadLocker locker{&m_Lock}; diff --git a/core/include/Data/DataSeries.h b/core/include/Data/DataSeries.h index 63684ea..1669c91 100644 --- a/core/include/Data/DataSeries.h +++ b/core/include/Data/DataSeries.h @@ -146,6 +146,7 @@ public: /// @sa IDataSeries::valuesUnit() Unit valuesUnit() const override { return m_ValuesUnit; } + int nbPoints() const override { return m_XAxisData->totalSize() + m_ValuesData->totalSize(); } SqpRange range() const override { diff --git a/core/include/Data/IDataSeries.h b/core/include/Data/IDataSeries.h index aea7206..f7c2aa1 100644 --- a/core/include/Data/IDataSeries.h +++ b/core/include/Data/IDataSeries.h @@ -64,6 +64,10 @@ public: virtual std::shared_ptr subDataSeries(const SqpRange &range) = 0; virtual std::unique_ptr clone() const = 0; + + /// @return the total number of points contained in the data series + virtual int nbPoints() const = 0; + virtual SqpRange range() const = 0; // ///////// // diff --git a/core/include/Variable/Variable.h b/core/include/Variable/Variable.h index 5b731ab..eb9b144 100644 --- a/core/include/Variable/Variable.h +++ b/core/include/Variable/Variable.h @@ -40,6 +40,10 @@ public: SqpRange cacheRange() const noexcept; void setCacheRange(const SqpRange &cacheRange) noexcept; + /// @return the number of points hold by the variable. The number of points is updated each time + /// the data series changes + int nbPoints() const noexcept; + /// Returns the real range of the variable, i.e. the min and max x-axis values of the data /// series between the range of the variable. The real range is updated each time the variable /// range or the data series changed diff --git a/core/src/Variable/Variable.cpp b/core/src/Variable/Variable.cpp index 64874ba..ed9c248 100644 --- a/core/src/Variable/Variable.cpp +++ b/core/src/Variable/Variable.cpp @@ -16,7 +16,8 @@ struct Variable::VariablePrivate { m_Range{dateTime}, m_Metadata{metadata}, m_DataSeries{nullptr}, - m_RealRange{INVALID_RANGE} + m_RealRange{INVALID_RANGE}, + m_NbPoints{0} { } @@ -25,7 +26,8 @@ struct Variable::VariablePrivate { m_Range{other.m_Range}, m_Metadata{other.m_Metadata}, m_DataSeries{other.m_DataSeries != nullptr ? other.m_DataSeries->clone() : nullptr}, - m_RealRange{other.m_RealRange} + m_RealRange{other.m_RealRange}, + m_NbPoints{other.m_NbPoints} { } @@ -39,8 +41,11 @@ struct Variable::VariablePrivate { m_DataSeries->purge(m_CacheRange.m_TStart, m_CacheRange.m_TEnd); } updateRealRange(); + updateNbPoints(); } + void updateNbPoints() { m_NbPoints = m_DataSeries ? m_DataSeries->nbPoints() : 0; } + /// Updates real range according to current variable range and data series void updateRealRange() { @@ -67,6 +72,7 @@ struct Variable::VariablePrivate { QVariantHash m_Metadata; std::shared_ptr m_DataSeries; SqpRange m_RealRange; + int m_NbPoints; QReadWriteLock m_Lock; }; @@ -135,6 +141,11 @@ void Variable::setCacheRange(const SqpRange &cacheRange) noexcept impl->unlock(); } +int Variable::nbPoints() const noexcept +{ + return impl->m_NbPoints; +} + SqpRange Variable::realRange() const noexcept { return impl->m_RealRange; diff --git a/core/src/Variable/VariableModel.cpp b/core/src/Variable/VariableModel.cpp index ad88e27..13e4d70 100644 --- a/core/src/Variable/VariableModel.cpp +++ b/core/src/Variable/VariableModel.cpp @@ -17,10 +17,11 @@ namespace { const auto NAME_COLUMN = 0; const auto TSTART_COLUMN = 1; const auto TEND_COLUMN = 2; -const auto UNIT_COLUMN = 3; -const auto MISSION_COLUMN = 4; -const auto PLUGIN_COLUMN = 5; -const auto NB_COLUMNS = 6; +const auto NBPOINTS_COLUMN = 3; +const auto UNIT_COLUMN = 4; +const auto MISSION_COLUMN = 5; +const auto PLUGIN_COLUMN = 6; +const auto NB_COLUMNS = 7; // Column properties const auto DEFAULT_HEIGHT = 25; @@ -39,9 +40,10 @@ struct ColumnProperties { }; const auto COLUMN_PROPERTIES = QHash{ - {NAME_COLUMN, {QObject::tr("Name")}}, {TSTART_COLUMN, {QObject::tr("tStart"), 180}}, - {TEND_COLUMN, {QObject::tr("tEnd"), 180}}, {UNIT_COLUMN, {QObject::tr("Unit")}}, - {MISSION_COLUMN, {QObject::tr("Mission")}}, {PLUGIN_COLUMN, {QObject::tr("Plugin")}}}; + {NAME_COLUMN, {QObject::tr("Name")}}, {TSTART_COLUMN, {QObject::tr("tStart"), 180}}, + {TEND_COLUMN, {QObject::tr("tEnd"), 180}}, {NBPOINTS_COLUMN, {QObject::tr("Nb points")}}, + {UNIT_COLUMN, {QObject::tr("Unit")}}, {MISSION_COLUMN, {QObject::tr("Mission")}}, + {PLUGIN_COLUMN, {QObject::tr("Plugin")}}}; /// Format for datetimes const auto DATETIME_FORMAT = QStringLiteral("dd/MM/yyyy \nhh:mm:ss:zzz"); @@ -198,6 +200,8 @@ QVariant VariableModel::data(const QModelIndex &index, int role) const ? DateUtils::dateTime(range.m_TEnd).toString(DATETIME_FORMAT) : QVariant{}; } + case NBPOINTS_COLUMN: + return variable->nbPoints(); case UNIT_COLUMN: return variable->metadata().value(QStringLiteral("units")); case MISSION_COLUMN: