##// END OF EJS Templates
Creates a delegate offering methods for rendering a graph
Creates a delegate offering methods for rendering a graph

File last commit:

r435:9ca55d63290e
r442:b604fc4c3d10
Show More
VisualizationGraphHelper.cpp
161 lines | 5.6 KiB | text/x-c | CppLexer
/ gui / src / Visualization / VisualizationGraphHelper.cpp
Correction for pull request
r227 #include "Visualization/VisualizationGraphHelper.h"
Alexandre Leroux
Creates factory that is responsible of creation of QCustomPlot components relative to a variable
r168 #include "Visualization/qcustomplot.h"
Alexandre Leroux
Handles creations for scalar series
r169 #include <Data/ScalarSeries.h>
Alexandre Leroux
Creates factory that is responsible of creation of QCustomPlot components relative to a variable
r168 #include <Variable/Variable.h>
Correction for pull request
r227 Q_LOGGING_CATEGORY(LOG_VisualizationGraphHelper, "VisualizationGraphHelper")
Alexandre Leroux
Creates factory that is responsible of creation of QCustomPlot components relative to a variable
r168
Alexandre Leroux
Handles creations for scalar series
r169 namespace {
Add current progression for thread fix
r336 class SqpDataContainer : public QCPGraphDataContainer {
public:
Alexandre Leroux
Updates UI to not call the sort method when update graphs, as data series are already sorted
r419 void appendGraphData(const QCPGraphData &data) { mData.append(data); }
Add current progression for thread fix
r336 };
Alexandre Leroux
Handles axes properties
r170 /// Format for datetimes on a axis
const auto DATETIME_TICKER_FORMAT = QStringLiteral("yyyy/MM/dd \nhh:mm:ss");
/// Generates the appropriate ticker for an axis, depending on whether the axis displays time or
/// non-time data
QSharedPointer<QCPAxisTicker> axisTicker(bool isTimeAxis)
{
if (isTimeAxis) {
auto dateTicker = QSharedPointer<QCPAxisTickerDateTime>::create();
dateTicker->setDateTimeFormat(DATETIME_TICKER_FORMAT);
return dateTicker;
}
else {
// default ticker
return QSharedPointer<QCPAxisTicker>::create();
}
}
Alexandre Leroux
Handles creations for scalar series
r169
The mock plugin can now create data with view operation
r219 void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSeries,
const SqpDateTime &dateTime)
{
Change info to debug on thread display log
r339 qCDebug(LOG_VisualizationGraphHelper()) << "TORM: updateScalarData"
<< QThread::currentThread()->objectName();
The mock plugin can now create data with view operation
r219 if (auto qcpGraph = dynamic_cast<QCPGraph *>(component)) {
Add current progression for thread fix
r336 scalarSeries.lockRead();
{
Alexandre Leroux
Updates UI to not call the sort method when update graphs, as data series are already sorted
r419 const auto &xData = scalarSeries.xAxisData()->cdata();
const auto &valuesData = scalarSeries.valuesData()->cdata();
auto xDataBegin = xData.cbegin();
auto xDataEnd = xData.cend();
Add clang format for linux
r435 qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points in cache"
<< xData.count();
Alexandre Leroux
Updates UI to not call the sort method when update graphs, as data series are already sorted
r419
Add current progression for thread fix
r336 auto sqpDataContainer = QSharedPointer<SqpDataContainer>::create();
qcpGraph->setData(sqpDataContainer);
Alexandre Leroux
Updates UI to not call the sort method when update graphs, as data series are already sorted
r419 auto lowerIt = std::lower_bound(xDataBegin, xDataEnd, dateTime.m_TStart);
auto upperIt = std::upper_bound(xDataBegin, xDataEnd, dateTime.m_TEnd);
auto distance = std::distance(xDataBegin, lowerIt);
auto valuesDataIt = valuesData.cbegin() + distance;
for (auto xAxisDataIt = lowerIt; xAxisDataIt != upperIt;
++xAxisDataIt, ++valuesDataIt) {
sqpDataContainer->appendGraphData(QCPGraphData(*xAxisDataIt, *valuesDataIt));
The mock plugin can now create data with view operation
r219 }
Alexandre Leroux
Updates UI to not call the sort method when update graphs, as data series are already sorted
r419
Add clang format for linux
r435 qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points displayed"
<< sqpDataContainer->size();
The mock plugin can now create data with view operation
r219 }
Add current progression for thread fix
r336 scalarSeries.unlock();
The mock plugin can now create data with view operation
r219
onRangeChanged is now based on the good range (the new one)...
r290
// Display all data
component->parentPlot()->replot();
The mock plugin can now create data with view operation
r219 }
else {
/// @todo DEBUG
}
}
QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QCustomPlot &plot,
const SqpDateTime &dateTime)
Alexandre Leroux
Handles creations for scalar series
r169 {
auto component = plot.addGraph();
if (component) {
The mock plugin can now create data with view operation
r219 // // Graph data
Alexandre Leroux
Handles creations for scalar series
r169 component->setData(scalarSeries.xAxisData()->data(), scalarSeries.valuesData()->data(),
true);
The mock plugin can now create data with view operation
r219 updateScalarData(component, scalarSeries, dateTime);
Alexandre Leroux
Handles axes properties
r170 // Axes properties
/// @todo : for the moment, no control is performed on the axes: the units and the tickers
/// are fixed for the default x-axis and y-axis of the plot, and according to the new graph
auto setAxisProperties = [](auto axis, const auto &unit) {
// label (unit name)
axis->setLabel(unit.m_Name);
// ticker (depending on the type of unit)
axis->setTicker(axisTicker(unit.m_TimeUnit));
};
setAxisProperties(plot.xAxis, scalarSeries.xAxisUnit());
setAxisProperties(plot.yAxis, scalarSeries.valuesUnit());
Alexandre Leroux
Handles creations for scalar series
r169 // Display all data
component->rescaleAxes();
plot.replot();
}
else {
Correction for pull request
r227 qCDebug(LOG_VisualizationGraphHelper())
Alexandre Leroux
Handles creations for scalar series
r169 << QObject::tr("Can't create graph for the scalar series");
}
return component;
}
} // namespace
Correction for pull request
r227 QVector<QCPAbstractPlottable *> VisualizationGraphHelper::create(std::shared_ptr<Variable> variable,
QCustomPlot &plot) noexcept
Alexandre Leroux
Creates factory that is responsible of creation of QCustomPlot components relative to a variable
r168 {
auto result = QVector<QCPAbstractPlottable *>{};
if (variable) {
Alexandre Leroux
Handles creations for scalar series
r169 // Gets the data series of the variable to call the creation of the right components
// according to its type
if (auto scalarSeries = dynamic_cast<ScalarSeries *>(variable->dataSeries())) {
The mock plugin can now create data with view operation
r219 result.append(createScalarSeriesComponent(*scalarSeries, plot, variable->dateTime()));
Alexandre Leroux
Handles creations for scalar series
r169 }
else {
Correction for pull request
r227 qCDebug(LOG_VisualizationGraphHelper())
Alexandre Leroux
Handles creations for scalar series
r169 << QObject::tr("Can't create graph plottables : unmanaged data series type");
}
Alexandre Leroux
Creates factory that is responsible of creation of QCustomPlot components relative to a variable
r168 }
else {
Correction for pull request
r227 qCDebug(LOG_VisualizationGraphHelper())
Alexandre Leroux
Creates factory that is responsible of creation of QCustomPlot components relative to a variable
r168 << QObject::tr("Can't create graph plottables : the variable is null");
}
return result;
}
The mock plugin can now create data with view operation
r219
Correction for pull request
r227 void VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *> plotableVect,
IDataSeries *dataSeries, const SqpDateTime &dateTime)
The mock plugin can now create data with view operation
r219 {
if (auto scalarSeries = dynamic_cast<ScalarSeries *>(dataSeries)) {
if (plotableVect.size() == 1) {
updateScalarData(plotableVect.at(0), *scalarSeries, dateTime);
}
else {
Correction for pull request
r227 qCCritical(LOG_VisualizationGraphHelper()) << QObject::tr(
The mock plugin can now create data with view operation
r219 "Can't update Data of a scalarSeries because there is not only one component "
"associated");
}
}
else {
/// @todo DEBUG
}
}