diff --git a/core/include/Variable/Variable.h b/core/include/Variable/Variable.h index d67e115..228202c 100644 --- a/core/include/Variable/Variable.h +++ b/core/include/Variable/Variable.h @@ -21,6 +21,9 @@ public: void addDataSeries(std::unique_ptr dataSeries) noexcept; + /// @return the data of the variable, nullptr if there is no data + IDataSeries *dataSeries() const noexcept; + private: class VariablePrivate; spimpl::unique_impl_ptr impl; diff --git a/core/src/Variable/Variable.cpp b/core/src/Variable/Variable.cpp index 02a2713..544d73d 100644 --- a/core/src/Variable/Variable.cpp +++ b/core/src/Variable/Variable.cpp @@ -41,3 +41,8 @@ void Variable::addDataSeries(std::unique_ptr dataSeries) noexcept } /// @todo : else, merge the two data series (if possible) } + +IDataSeries *Variable::dataSeries() const noexcept +{ + return impl->m_DataSeries.get(); +} diff --git a/gui/src/Visualization/GraphPlottablesFactory.cpp b/gui/src/Visualization/GraphPlottablesFactory.cpp index bbf5c97..90af5a5 100644 --- a/gui/src/Visualization/GraphPlottablesFactory.cpp +++ b/gui/src/Visualization/GraphPlottablesFactory.cpp @@ -1,17 +1,54 @@ #include "Visualization/GraphPlottablesFactory.h" #include "Visualization/qcustomplot.h" +#include + #include Q_LOGGING_CATEGORY(LOG_GraphPlottablesFactory, "GraphPlottablesFactory") +namespace { + + +QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QCustomPlot &plot) +{ + auto component = plot.addGraph(); + + if (component) { + // Graph data + component->setData(scalarSeries.xAxisData()->data(), scalarSeries.valuesData()->data(), + true); + + // Display all data + component->rescaleAxes(); + + plot.replot(); + } + else { + qCDebug(LOG_GraphPlottablesFactory()) + << QObject::tr("Can't create graph for the scalar series"); + } + + return component; +} + +} // namespace + QVector GraphPlottablesFactory::create(const Variable *variable, QCustomPlot &plot) noexcept { auto result = QVector{}; if (variable) { - /// @todo ALX + // Gets the data series of the variable to call the creation of the right components + // according to its type + if (auto scalarSeries = dynamic_cast(variable->dataSeries())) { + result.append(createScalarSeriesComponent(*scalarSeries, plot)); + } + else { + qCDebug(LOG_GraphPlottablesFactory()) + << QObject::tr("Can't create graph plottables : unmanaged data series type"); + } } else { qCDebug(LOG_GraphPlottablesFactory())