##// END OF EJS Templates
Replaces "Plus" cursor by "Circle" cursor
Replaces "Plus" cursor by "Circle" cursor

File last commit:

r573:575eda7156d0
r577:3b933383848f
Show More
VisualizationGraphHelper.cpp
195 lines | 6.8 KiB | text/x-c | CppLexer
/ gui / src / Visualization / VisualizationGraphHelper.cpp
Correction for pull request
r243 #include "Visualization/VisualizationGraphHelper.h"
Alexandre Leroux
Creates factory that is responsible of creation of QCustomPlot components relative to a variable
r181 #include "Visualization/qcustomplot.h"
Alexandre Leroux
Handles creations for scalar series
r182 #include <Data/ScalarSeries.h>
Alexandre Leroux
Creates factory that is responsible of creation of QCustomPlot components relative to a variable
r181 #include <Variable/Variable.h>
Correction for pull request
r243 Q_LOGGING_CATEGORY(LOG_VisualizationGraphHelper, "VisualizationGraphHelper")
Alexandre Leroux
Creates factory that is responsible of creation of QCustomPlot components relative to a variable
r181
Alexandre Leroux
Handles creations for scalar series
r182 namespace {
Add current progression for thread fix
r364 class SqpDataContainer : public QCPGraphDataContainer {
public:
Alexandre Leroux
Updates UI to not call the sort method when update graphs, as data series are already sorted
r453 void appendGraphData(const QCPGraphData &data) { mData.append(data); }
Add current progression for thread fix
r364 };
Alexandre Leroux
Handles axes properties
r183 /// 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);
Alexandre Leroux
Uses the same time spec (UTC) as axis for tooltips on graph
r490 dateTicker->setDateTimeSpec(Qt::UTC);
Alexandre Leroux
Handles axes properties
r183
return dateTicker;
}
else {
// default ticker
return QSharedPointer<QCPAxisTicker>::create();
}
}
Alexandre Leroux
Handles creations for scalar series
r182
The dataSeries of a variable is now shared istead of uniq to avoid...
r542 void updateScalarData(QCPAbstractPlottable *component, std::shared_ptr<ScalarSeries> scalarSeries,
Add impletation for displaying data that are already in cache when...
r573 const SqpRange &range)
The mock plugin can now create data with view operation
r235 {
Change info to debug on thread display log
r367 qCDebug(LOG_VisualizationGraphHelper()) << "TORM: updateScalarData"
<< QThread::currentThread()->objectName();
The mock plugin can now create data with view operation
r235 if (auto qcpGraph = dynamic_cast<QCPGraph *>(component)) {
The dataSeries of a variable is now shared istead of uniq to avoid...
r542 scalarSeries->lockRead();
Add current progression for thread fix
r364 {
Add impletation for displaying data that are already in cache when...
r573 auto sqpDataContainer = QSharedPointer<SqpDataContainer>::create();
qcpGraph->setData(sqpDataContainer);
auto bounds = scalarSeries->subData(range.m_TStart, range.m_TEnd);
for (auto it = bounds.first; it != bounds.second; ++it) {
sqpDataContainer->appendGraphData(QCPGraphData(it->x(), it->value()));
}
Alexandre Leroux
Updates UI to not call the sort method when update graphs, as data series are already sorted
r453
The dataSeries of a variable is now shared istead of uniq to avoid...
r542 qCInfo(LOG_VisualizationGraphHelper()) << "TODEBUG: Current points displayed"
Add clang format for linux
r471 << sqpDataContainer->size();
The mock plugin can now create data with view operation
r235 }
The dataSeries of a variable is now shared istead of uniq to avoid...
r542 scalarSeries->unlock();
The mock plugin can now create data with view operation
r235
onRangeChanged is now based on the good range (the new one)...
r315
// Display all data
component->parentPlot()->replot();
The mock plugin can now create data with view operation
r235 }
else {
/// @todo DEBUG
}
}
Initialisation of the graph range at creation in a new graphe, or inside...
r548 QCPAbstractPlottable *createScalarSeriesComponentV2(std::shared_ptr<ScalarSeries> scalarSeries,
QCustomPlot &plot)
{
auto component = plot.addGraph();
if (component) {
// 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());
}
return component;
}
The dataSeries of a variable is now shared istead of uniq to avoid...
r542 QCPAbstractPlottable *createScalarSeriesComponent(std::shared_ptr<ScalarSeries> scalarSeries,
QCustomPlot &plot, const SqpRange &dateTime)
Alexandre Leroux
Handles creations for scalar series
r182 {
auto component = plot.addGraph();
if (component) {
The mock plugin can now create data with view operation
r235 // // Graph data
The dataSeries of a variable is now shared istead of uniq to avoid...
r542 component->setData(scalarSeries->xAxisData()->data(), scalarSeries->valuesData()->data(),
Alexandre Leroux
Handles creations for scalar series
r182 true);
The mock plugin can now create data with view operation
r235 updateScalarData(component, scalarSeries, dateTime);
Alexandre Leroux
Handles axes properties
r183 // 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));
};
The dataSeries of a variable is now shared istead of uniq to avoid...
r542 setAxisProperties(plot.xAxis, scalarSeries->xAxisUnit());
setAxisProperties(plot.yAxis, scalarSeries->valuesUnit());
Alexandre Leroux
Handles axes properties
r183
Alexandre Leroux
Handles creations for scalar series
r182 // Display all data
component->rescaleAxes();
plot.replot();
}
else {
Correction for pull request
r243 qCDebug(LOG_VisualizationGraphHelper())
Alexandre Leroux
Handles creations for scalar series
r182 << QObject::tr("Can't create graph for the scalar series");
}
return component;
}
} // namespace
Initialisation of the graph range at creation in a new graphe, or inside...
r548 QVector<QCPAbstractPlottable *>
VisualizationGraphHelper::createV2(std::shared_ptr<Variable> variable, QCustomPlot &plot) noexcept
{
auto result = QVector<QCPAbstractPlottable *>{};
if (variable) {
// Gets the data series of the variable to call the creation of the right components
// according to its type
if (auto scalarSeries = std::dynamic_pointer_cast<ScalarSeries>(variable->dataSeries())) {
result.append(createScalarSeriesComponentV2(scalarSeries, plot));
}
else {
qCDebug(LOG_VisualizationGraphHelper())
<< QObject::tr("Can't create graph plottables : unmanaged data series type");
}
}
else {
qCDebug(LOG_VisualizationGraphHelper())
<< QObject::tr("Can't create graph plottables : the variable is null");
}
return result;
}
Correction for pull request
r243 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
r181 {
auto result = QVector<QCPAbstractPlottable *>{};
if (variable) {
Alexandre Leroux
Handles creations for scalar series
r182 // Gets the data series of the variable to call the creation of the right components
// according to its type
The dataSeries of a variable is now shared istead of uniq to avoid...
r542 if (auto scalarSeries = std::dynamic_pointer_cast<ScalarSeries>(variable->dataSeries())) {
result.append(createScalarSeriesComponent(scalarSeries, plot, variable->range()));
Alexandre Leroux
Handles creations for scalar series
r182 }
else {
Correction for pull request
r243 qCDebug(LOG_VisualizationGraphHelper())
Alexandre Leroux
Handles creations for scalar series
r182 << 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
r181 }
else {
Correction for pull request
r243 qCDebug(LOG_VisualizationGraphHelper())
Alexandre Leroux
Creates factory that is responsible of creation of QCustomPlot components relative to a variable
r181 << QObject::tr("Can't create graph plottables : the variable is null");
}
return result;
}
The mock plugin can now create data with view operation
r235
Correction for pull request
r243 void VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *> plotableVect,
The dataSeries of a variable is now shared istead of uniq to avoid...
r542 std::shared_ptr<IDataSeries> dataSeries,
const SqpRange &dateTime)
The mock plugin can now create data with view operation
r235 {
The dataSeries of a variable is now shared istead of uniq to avoid...
r542 if (auto scalarSeries = std::dynamic_pointer_cast<ScalarSeries>(dataSeries)) {
The mock plugin can now create data with view operation
r235 if (plotableVect.size() == 1) {
The dataSeries of a variable is now shared istead of uniq to avoid...
r542 updateScalarData(plotableVect.at(0), scalarSeries, dateTime);
The mock plugin can now create data with view operation
r235 }
else {
Correction for pull request
r243 qCCritical(LOG_VisualizationGraphHelper()) << QObject::tr(
The mock plugin can now create data with view operation
r235 "Can't update Data of a scalarSeries because there is not only one component "
"associated");
}
}
else {
/// @todo DEBUG
}
}