##// END OF EJS Templates
add Skeleton for displaying data which are already in cache
add Skeleton for displaying data which are already in cache

File last commit:

r571:ba71c0cdaccd
r571:ba71c0cdaccd
Show More
VisualizationGraphWidget.cpp
320 lines | 12.1 KiB | text/x-c | CppLexer
/ gui / src / Visualization / VisualizationGraphWidget.cpp
mv visualization -> Visualization...
r95 #include "Visualization/VisualizationGraphWidget.h"
Alexandre Leroux
Updates visitor interface...
r207 #include "Visualization/IVisualizationWidgetVisitor.h"
Correction for pull request
r243 #include "Visualization/VisualizationGraphHelper.h"
Alexandre Leroux
Creates a delegate offering methods for rendering a graph
r480 #include "Visualization/VisualizationGraphRenderingDelegate.h"
Creation of VisualizationWidget, VizualizationTabWidget, VisualizationZoneWidget, VisualizationGraphWidget
r58 #include "ui_VisualizationGraphWidget.h"
The mock plugin can now create data with view operation
r235 #include <Data/ArrayData.h>
#include <Data/IDataSeries.h>
Alexandre Leroux
Settings binding (5)...
r470 #include <Settings/SqpSettingsDefs.h>
The mock plugin can now create data with view operation
r235 #include <SqpApplication.h>
Add the visualization gui classes
r118 #include <Variable/Variable.h>
The mock plugin can now create data with view operation
r235 #include <Variable/VariableController.h>
Add the visualization gui classes
r118 #include <unordered_map>
Alexandre Leroux
Adds logs for null visitors
r219 Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget")
Alexandre Leroux
Handles key modifiers for zoom...
r179 namespace {
/// Key pressed to enable zoom on horizontal axis
const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier;
/// Key pressed to enable zoom on vertical axis
const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier;
} // namespace
Add the visualization gui classes
r118 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
Alexandre Leroux
Creates a delegate offering methods for rendering a graph
r480 explicit VisualizationGraphWidgetPrivate()
Implementation of V5 acquisition
r539 : m_DoAcquisition{true}, m_IsCalibration{false}, m_RenderingDelegate{nullptr}
Alexandre Leroux
Creates a delegate offering methods for rendering a graph
r480 {
}
Implementation of the calibration for the synchronization...
r445
Add the visualization gui classes
r118 // 1 variable -> n qcpplot
Alexandre Leroux
Remove variable from graph (2)...
r270 std::multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMultiMap;
Implementation of V5 acquisition
r539 bool m_DoAcquisition;
Implementation of the calibration for the synchronization...
r445 bool m_IsCalibration;
Alexandre Leroux
Creates a delegate offering methods for rendering a graph
r480 QCPItemTracer *m_TextTracer;
/// Delegate used to attach rendering features to the plot
std::unique_ptr<VisualizationGraphRenderingDelegate> m_RenderingDelegate;
Add the visualization gui classes
r118 };
Alexandre Leroux
Fixes reference
r205 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent)
add {} missing
r120 : QWidget{parent},
ui{new Ui::VisualizationGraphWidget},
Add the visualization gui classes
r118 impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()}
Creation of VisualizationWidget, VizualizationTabWidget, VisualizationZoneWidget, VisualizationGraphWidget
r58 {
ui->setupUi(this);
Alexandre Leroux
Sets plot properties in a graph
r178
Alexandre Leroux
Creates a delegate offering methods for rendering a graph
r480 // The delegate must be initialized after the ui as it uses the plot
impl->m_RenderingDelegate = std::make_unique<VisualizationGraphRenderingDelegate>(*ui->widget);
Alexandre Leroux
Adds a close button to a graph widget + calls close() method when clicked...
r266 ui->graphNameLabel->setText(name);
// 'Close' options : widget is deleted when closed
setAttribute(Qt::WA_DeleteOnClose);
connect(ui->closeButton, &QToolButton::clicked, this, &VisualizationGraphWidget::close);
ui->closeButton->setIcon(sqpApp->style()->standardIcon(QStyle::SP_TitleBarCloseButton));
Alexandre Leroux
Adds name to a graph...
r196
Alexandre Leroux
Sets plot properties in a graph
r178 // Set qcpplot properties :
Alexandre Leroux
Enables drag only for x-axis
r180 // - Drag (on x-axis) and zoom are enabled
Alexandre Leroux
Handles key modifiers for zoom...
r179 // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation
Alexandre Leroux
Sets plot properties in a graph
r178 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
Alexandre Leroux
Enables drag only for x-axis
r180 ui->widget->axisRect()->setRangeDrag(Qt::Horizontal);
Alexandre Leroux
Creates method that will display a tooltip and a tracer with data point information after a while
r481
Implementation of the calibration for the synchronization...
r445 connect(ui->widget, &QCustomPlot::mousePress, this, &VisualizationGraphWidget::onMousePress);
connect(ui->widget, &QCustomPlot::mouseRelease, this,
&VisualizationGraphWidget::onMouseRelease);
Alexandre Leroux
Creates method that will display a tooltip and a tracer with data point information after a while
r481 connect(ui->widget, &QCustomPlot::mouseMove, this, &VisualizationGraphWidget::onMouseMove);
Alexandre Leroux
Handles key modifiers for zoom...
r179 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
Add synchronization that keep delta
r444 connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>(
&QCPAxis::rangeChanged),
Implementation of the calibration for the synchronization...
r445 this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection);
Alexandre Leroux
Remove variable from graph (1)...
r269
// Activates menu when right clicking on the graph
ui->widget->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->widget, &QCustomPlot::customContextMenuRequested, this,
&VisualizationGraphWidget::onGraphMenuRequested);
Fix the cosinus bug....
r298
connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(),
&VariableController::onRequestDataLoading);
add Skeleton for displaying data which are already in cache
r571
connect(&sqpApp->variableController(), &VariableController::updateVarDisplaying, this,
&VisualizationGraphWidget::onUpdateVarDisplaying);
Creation of VisualizationWidget, VizualizationTabWidget, VisualizationZoneWidget, VisualizationGraphWidget
r58 }
Alexandre Leroux
QCustomPlot notify the graph widget when the xRange changed
r227
Creation of VisualizationWidget, VizualizationTabWidget, VisualizationZoneWidget, VisualizationGraphWidget
r58 VisualizationGraphWidget::~VisualizationGraphWidget()
{
delete ui;
}
Add the visualization gui classes
r118
Implementation of V5 acquisition
r539 void VisualizationGraphWidget::enableAcquisition(bool enable)
Add synchronization that keep delta
r444 {
Implementation of V5 acquisition
r539 impl->m_DoAcquisition = enable;
Add synchronization that keep delta
r444 }
Initialisation of the graph range at creation in a new graphe, or inside...
r548 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable, SqpRange range)
Add the visualization gui classes
r118 {
Alexandre Leroux
Uses factory in the VariableGraphWidget
r184 // Uses delegate to create the qcpplot components according to the variable
Initialisation of the graph range at creation in a new graphe, or inside...
r548 auto createdPlottables = VisualizationGraphHelper::createV2(variable, *ui->widget);
Alexandre Leroux
Uses factory in the VariableGraphWidget
r184
for (auto createdPlottable : qAsConst(createdPlottables)) {
The mock plugin can now create data with view operation
r235 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
Alexandre Leroux
Uses factory in the VariableGraphWidget
r184 }
The mock plugin can now create data with view operation
r235
Fix the cosinus bug....
r298 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
Add synchronization part of v5 acquisition
r540
Initialisation of the graph range at creation in a new graphe, or inside...
r548 auto varRange = variable->range();
variable time is now set to range graphe displayed when it is displayed...
r314
Initialisation of the graph range at creation in a new graphe, or inside...
r548 this->enableAcquisition(false);
this->setGraphRange(range);
this->enableAcquisition(true);
variable time is now set to range graphe displayed when it is displayed...
r314
Initialisation of the graph range at creation in a new graphe, or inside...
r548 emit requestDataLoading(QVector<std::shared_ptr<Variable> >() << variable, range, varRange,
false);
emit variableAdded(variable);
variable time is now set to range graphe displayed when it is displayed...
r314 }
Alexandre Leroux
Remove variable from graph (2)...
r270 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept
{
Alexandre Leroux
Remove variable from graph (3)...
r271 // Each component associated to the variable :
// - is removed from qcpplot (which deletes it)
// - is no longer referenced in the map
auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable);
for (auto it = componentsIt.first; it != componentsIt.second;) {
ui->widget->removePlottable(it->second);
it = impl->m_VariableToPlotMultiMap.erase(it);
}
// Updates graph
ui->widget->replot();
Alexandre Leroux
Remove variable from graph (2)...
r270 }
Change SqpRange for SqpDateTime
r512 void VisualizationGraphWidget::setRange(std::shared_ptr<Variable> variable, const SqpRange &range)
Add implementation for the range rescale. Variable is ignored here...
r438 {
Correction for MR
r447 // Note: in case of different axes that depends on variable, we could start with a code like
// that:
Add implementation for the range rescale. Variable is ignored here...
r438 // auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable);
// for (auto it = componentsIt.first; it != componentsIt.second;) {
// }
ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd);
Add synchronization that keep delta
r444 ui->widget->replot();
}
Initialisation of the graph range at creation in a new graphe, or inside...
r548 void VisualizationGraphWidget::setYRange(const SqpRange &range)
{
ui->widget->yAxis->setRange(range.m_TStart, range.m_TEnd);
}
Change SqpRange for SqpDateTime
r512 SqpRange VisualizationGraphWidget::graphRange() const noexcept
Add synchronization that keep delta
r444 {
change grapheRange to graphRange
r545 auto graphRange = ui->widget->xAxis->range();
return SqpRange{graphRange.lower, graphRange.upper};
Add synchronization that keep delta
r444 }
Change SqpRange for SqpDateTime
r512 void VisualizationGraphWidget::setGraphRange(const SqpRange &range)
Add synchronization that keep delta
r444 {
Implementation of the calibration for the synchronization...
r445 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange START");
Add synchronization that keep delta
r444 ui->widget->xAxis->setRange(range.m_TStart, range.m_TEnd);
ui->widget->replot();
qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END");
Add implementation for the range rescale. Variable is ignored here...
r438 }
Alexandre Leroux
Updates visitor interface...
r207 void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor)
Add the visualization gui classes
r118 {
Alexandre Leroux
Implements accept() method of visualization widgets
r208 if (visitor) {
visitor->visit(this);
}
Alexandre Leroux
Adds logs for null visitors
r219 else {
qCCritical(LOG_VisualizationGraphWidget())
<< tr("Can't visit widget : the visitor is null");
}
Add the visualization gui classes
r118 }
Alexandre Leroux
Creates a interface that defines a variable container...
r209 bool VisualizationGraphWidget::canDrop(const Variable &variable) const
{
/// @todo : for the moment, a graph can always accomodate a variable
Q_UNUSED(variable);
return true;
}
Alexandre Leroux
Unplot menu (5): adds contains() method to an IVariableContainer...
r327 bool VisualizationGraphWidget::contains(const Variable &variable) const
{
// Finds the variable among the keys of the map
auto variablePtr = &variable;
auto findVariable
= [variablePtr](const auto &entry) { return variablePtr == entry.first.get(); };
auto end = impl->m_VariableToPlotMultiMap.cend();
auto it = std::find_if(impl->m_VariableToPlotMultiMap.cbegin(), end, findVariable);
return it != end;
}
Add const and override
r119 QString VisualizationGraphWidget::name() const
Add the visualization gui classes
r118 {
Alexandre Leroux
Adds a close button to a graph widget + calls close() method when clicked...
r266 return ui->graphNameLabel->text();
Add the visualization gui classes
r118 }
Alexandre Leroux
Remove variable from graph (1)...
r269 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept
Add the visualization gui classes
r118 {
Alexandre Leroux
Remove variable from graph (1)...
r269 QMenu graphMenu{};
Alexandre Leroux
Remove variable from graph (2)...
r270 // Iterates on variables (unique keys)
for (auto it = impl->m_VariableToPlotMultiMap.cbegin(),
end = impl->m_VariableToPlotMultiMap.cend();
it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) {
// 'Remove variable' action
graphMenu.addAction(tr("Remove variable %1").arg(it->first->name()),
[ this, var = it->first ]() { removeVariable(var); });
Alexandre Leroux
Adds name to a graph...
r196 }
Alexandre Leroux
Remove variable from graph (1)...
r269
if (!graphMenu.isEmpty()) {
graphMenu.exec(mapToGlobal(pos));
Alexandre Leroux
Adds name to a graph...
r196 }
Add the visualization gui classes
r118 }
Alexandre Leroux
Handles key modifiers for zoom...
r179
Add synchronization that keep delta
r444 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2)
Alexandre Leroux
QCustomPlot notify the graph widget when the xRange changed
r227 {
Implementation of V5 acquisition
r539 qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: VisualizationGraphWidget::onRangeChanged")
<< QThread::currentThread()->objectName() << "DoAcqui"
<< impl->m_DoAcquisition;
Add synchronization that keep delta
r444
Implementation of V5 acquisition
r539 auto graphRange = SqpRange{t1.lower, t1.upper};
auto oldGraphRange = SqpRange{t2.lower, t2.upper};
The mock plugin can now create data with view operation
r235
Implementation of V5 acquisition
r539 if (impl->m_DoAcquisition) {
QVector<std::shared_ptr<Variable> > variableUnderGraphVector;
Add intersect méthode on variable and sqpDateTime...
r258
Implementation of V5 acquisition
r539 for (auto it = impl->m_VariableToPlotMultiMap.begin(),
end = impl->m_VariableToPlotMultiMap.end();
it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) {
variableUnderGraphVector.push_back(it->first);
The mock plugin can now create data with view operation
r235 }
Implementation of V5 acquisition
r539 emit requestDataLoading(std::move(variableUnderGraphVector), graphRange, oldGraphRange,
!impl->m_IsCalibration);
if (!impl->m_IsCalibration) {
The dataSeries of a variable is now shared istead of uniq to avoid...
r542 qCDebug(LOG_VisualizationGraphWidget())
Implementation of V5 acquisition
r539 << tr("TORM: VisualizationGraphWidget::Synchronize notify !!")
Add synchronization part of v5 acquisition
r540 << QThread::currentThread()->objectName() << graphRange << oldGraphRange;
Implementation of V5 acquisition
r539 emit synchronize(graphRange, oldGraphRange);
The cache is now updated only if date requested has been successfully...
r318 }
Alexandre Leroux
QCustomPlot notify the graph widget when the xRange changed
r227 }
}
Alexandre Leroux
Creates method that will display a tooltip and a tracer with data point information after a while
r481 void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept
{
// Handles plot rendering when mouse is moving
impl->m_RenderingDelegate->onMouseMove(event);
}
Alexandre Leroux
Handles key modifiers for zoom...
r179 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
{
auto zoomOrientations = QFlags<Qt::Orientation>{};
Implementation of the new Dela T computation strategy
r260 // Lambda that enables a zoom orientation if the key modifier related to this orientation
// has
Alexandre Leroux
Handles key modifiers for zoom...
r179 // been pressed
auto enableOrientation
= [&zoomOrientations, event](const auto &orientation, const auto &modifier) {
auto orientationEnabled = event->modifiers().testFlag(modifier);
zoomOrientations.setFlag(orientation, orientationEnabled);
};
enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER);
enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER);
ui->widget->axisRect()->setRangeZoom(zoomOrientations);
}
The mock plugin can now create data with view operation
r235
Implementation of the calibration for the synchronization...
r445 void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept
{
impl->m_IsCalibration = event->modifiers().testFlag(Qt::ControlModifier);
}
void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept
{
impl->m_IsCalibration = false;
}
The mock plugin can now create data with view operation
r235 void VisualizationGraphWidget::onDataCacheVariableUpdated()
{
Correction for pull request
r243 // NOTE:
Implementation of the new Dela T computation strategy
r260 // We don't want to call the method for each component of a variable unitarily, but for
// all
Correction for pull request
r243 // its components at once (eg its three components in the case of a vector).
// The unordered_multimap does not do this easily, so the question is whether to:
// - use an ordered_multimap and the algos of std to group the values by key
// - use a map (unique keys) and store as values directly the list of components
change grapheRange to graphRange
r545 auto graphRange = ui->widget->xAxis->range();
auto dateTime = SqpRange{graphRange.lower, graphRange.upper};
Implementation of the cache feature : download before display needs
r433
The mock plugin can now create data with view operation
r235 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
auto variable = it->first;
Downgrade dev log from info to debug
r441 qCDebug(LOG_VisualizationGraphWidget())
Implementation of V5 acquisition
r539 << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S" << variable->range();
Downgrade dev log from info to debug
r441 qCDebug(LOG_VisualizationGraphWidget())
Implementation of the cache feature : download before display needs
r433 << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime;
Implementation of V5 acquisition
r539 if (dateTime.contains(variable->range()) || dateTime.intersect(variable->range())) {
Implementation of the cache feature : download before display needs
r433
VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second,
Implementation of V5 acquisition
r539 variable->dataSeries(), variable->range());
Implementation of the cache feature : download before display needs
r433 }
The mock plugin can now create data with view operation
r235 }
}
add Skeleton for displaying data which are already in cache
r571
void VisualizationGraphWidget::onUpdateVarDisplaying(std::shared_ptr<Variable> variable,
const SqpRange &range)
{
auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable);
for (auto it = componentsIt.first; it != componentsIt.second;) {
VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second,
variable->dataSeries(), range);
}
}