##// END OF EJS Templates
Merge branch 'feature/DownloadProgressRefactoring' into develop
Merge branch 'feature/DownloadProgressRefactoring' into develop

File last commit:

r337:557d1cdcb95a
r393:7dfa9848e171 merge
Show More
VisualizationGraphWidget.cpp
285 lines | 11.1 KiB | text/x-c | CppLexer
/ gui / src / Visualization / VisualizationGraphWidget.cpp
mv visualization -> Visualization...
r93 #include "Visualization/VisualizationGraphWidget.h"
Alexandre Leroux
Updates visitor interface...
r192 #include "Visualization/IVisualizationWidgetVisitor.h"
Correction for pull request
r227 #include "Visualization/VisualizationGraphHelper.h"
Creation of VisualizationWidget, VizualizationTabWidget, VisualizationZoneWidget, VisualizationGraphWidget
r58 #include "ui_VisualizationGraphWidget.h"
The mock plugin can now create data with view operation
r219 #include <Data/ArrayData.h>
#include <Data/IDataSeries.h>
#include <SqpApplication.h>
Add the visualization gui classes
r111 #include <Variable/Variable.h>
The mock plugin can now create data with view operation
r219 #include <Variable/VariableController.h>
Add the visualization gui classes
r111 #include <unordered_map>
Alexandre Leroux
Adds logs for null visitors
r204 Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget")
Alexandre Leroux
Handles key modifiers for zoom...
r166 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
r111 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
// 1 variable -> n qcpplot
Alexandre Leroux
Remove variable from graph (2)...
r250 std::multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMultiMap;
Add the visualization gui classes
r111 };
Alexandre Leroux
Fixes reference
r191 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent)
add {} missing
r113 : QWidget{parent},
ui{new Ui::VisualizationGraphWidget},
Add the visualization gui classes
r111 impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()}
Creation of VisualizationWidget, VizualizationTabWidget, VisualizationZoneWidget, VisualizationGraphWidget
r58 {
ui->setupUi(this);
Alexandre Leroux
Sets plot properties in a graph
r165
Alexandre Leroux
Adds a close button to a graph widget + calls close() method when clicked...
r246 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...
r182
Alexandre Leroux
Sets plot properties in a graph
r165 // Set qcpplot properties :
Alexandre Leroux
Enables drag only for x-axis
r167 // - Drag (on x-axis) and zoom are enabled
Alexandre Leroux
Handles key modifiers for zoom...
r166 // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation
Alexandre Leroux
Sets plot properties in a graph
r165 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
Alexandre Leroux
Enables drag only for x-axis
r167 ui->widget->axisRect()->setRangeDrag(Qt::Horizontal);
Alexandre Leroux
Handles key modifiers for zoom...
r166 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
onRangeChanged is now based on the good range (the new one)...
r290 connect(ui->widget->xAxis,
static_cast<void (QCPAxis::*)(const QCPRange &)>(&QCPAxis::rangeChanged), this,
&VisualizationGraphWidget::onRangeChanged);
Alexandre Leroux
Remove variable from graph (1)...
r249
// 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....
r276
connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(),
&VariableController::onRequestDataLoading);
Creation of VisualizationWidget, VizualizationTabWidget, VisualizationZoneWidget, VisualizationGraphWidget
r58 }
Alexandre Leroux
QCustomPlot notify the graph widget when the xRange changed
r211
Creation of VisualizationWidget, VizualizationTabWidget, VisualizationZoneWidget, VisualizationGraphWidget
r58 VisualizationGraphWidget::~VisualizationGraphWidget()
{
delete ui;
}
Add the visualization gui classes
r111
void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
{
Alexandre Leroux
Uses factory in the VariableGraphWidget
r171 // Uses delegate to create the qcpplot components according to the variable
Correction for pull request
r227 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
Alexandre Leroux
Uses factory in the VariableGraphWidget
r171
for (auto createdPlottable : qAsConst(createdPlottables)) {
The mock plugin can now create data with view operation
r219 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
Alexandre Leroux
Uses factory in the VariableGraphWidget
r171 }
The mock plugin can now create data with view operation
r219
Fix the cosinus bug....
r276 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
Add the visualization gui classes
r111 }
variable time is now set to range graphe displayed when it is displayed...
r289 void VisualizationGraphWidget::addVariableUsingGraph(std::shared_ptr<Variable> variable)
{
// when adding a variable, we need to set its time range to the current graph range
auto grapheRange = ui->widget->xAxis->range();
auto dateTime = SqpDateTime{grapheRange.lower, grapheRange.upper};
variable->setDateTime(dateTime);
auto variableDateTimeWithTolerance = dateTime;
// add 10% tolerance for each side
auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
variableDateTimeWithTolerance.m_TStart -= tolerance;
variableDateTimeWithTolerance.m_TEnd += tolerance;
// Uses delegate to create the qcpplot components according to the variable
auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
for (auto createdPlottable : qAsConst(createdPlottables)) {
impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
}
connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
// CHangement detected, we need to ask controller to request data loading
emit requestDataLoading(variable, variableDateTimeWithTolerance);
}
Alexandre Leroux
Remove variable from graph (2)...
r250 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept
{
Alexandre Leroux
Remove variable from graph (3)...
r251 // 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)...
r250 }
Alexandre Leroux
Updates visitor interface...
r192 void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor)
Add the visualization gui classes
r111 {
Alexandre Leroux
Implements accept() method of visualization widgets
r193 if (visitor) {
visitor->visit(this);
}
Alexandre Leroux
Adds logs for null visitors
r204 else {
qCCritical(LOG_VisualizationGraphWidget())
<< tr("Can't visit widget : the visitor is null");
}
Add the visualization gui classes
r111 }
Alexandre Leroux
Creates a interface that defines a variable container...
r194 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...
r301 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
r112 QString VisualizationGraphWidget::name() const
Add the visualization gui classes
r111 {
Alexandre Leroux
Adds a close button to a graph widget + calls close() method when clicked...
r246 return ui->graphNameLabel->text();
Add the visualization gui classes
r111 }
Alexandre Leroux
Remove variable from graph (1)...
r249 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept
Add the visualization gui classes
r111 {
Alexandre Leroux
Remove variable from graph (1)...
r249 QMenu graphMenu{};
Alexandre Leroux
Remove variable from graph (2)...
r250 // 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...
r182 }
Alexandre Leroux
Remove variable from graph (1)...
r249
if (!graphMenu.isEmpty()) {
graphMenu.exec(mapToGlobal(pos));
Alexandre Leroux
Adds name to a graph...
r182 }
Add the visualization gui classes
r111 }
Alexandre Leroux
Handles key modifiers for zoom...
r166
onRangeChanged is now based on the good range (the new one)...
r290 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1)
Alexandre Leroux
QCustomPlot notify the graph widget when the xRange changed
r211 {
Correction clang format
r337 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged")
<< QThread::currentThread()->objectName();
The mock plugin can now create data with view operation
r219
for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
Add intersect méthode on variable and sqpDateTime...
r240
The mock plugin can now create data with view operation
r219 auto variable = it->first;
onRangeChanged is now based on the good range (the new one)...
r290 auto dateTime = SqpDateTime{t1.lower, t1.upper};
The mock plugin can now create data with view operation
r219
if (!variable->contains(dateTime)) {
Add intersect méthode on variable and sqpDateTime...
r240
Implementation of the new Dela T computation strategy
r241 auto variableDateTimeWithTolerance = dateTime;
The cache is now updated only if date requested has been successfully...
r293 if (!variable->isInside(dateTime)) {
Add intersect méthode on variable and sqpDateTime...
r240 auto variableDateTime = variable->dateTime();
if (variableDateTime.m_TStart < dateTime.m_TStart) {
The cache is now updated only if date requested has been successfully...
r293 qCDebug(LOG_VisualizationGraphWidget()) << tr("TDetection pan to right:");
Add correction for delta T
r243
auto diffEndToKeepDelta = dateTime.m_TEnd - variableDateTime.m_TEnd;
dateTime.m_TStart = variableDateTime.m_TStart + diffEndToKeepDelta;
// Tolerance have to be added to the right
Implementation of the new Dela T computation strategy
r241 // add 10% tolerance for right (end) side
auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
variableDateTimeWithTolerance.m_TEnd += tolerance;
Add intersect méthode on variable and sqpDateTime...
r240 }
The cache is now updated only if date requested has been successfully...
r293 else if (variableDateTime.m_TEnd > dateTime.m_TEnd) {
qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection pan to left: ");
Correction delat T on start
r259 auto diffStartToKeepDelta = variableDateTime.m_TStart - dateTime.m_TStart;
Add correction for delta T
r243 dateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta;
// Tolerance have to be added to the left
Implementation of the new Dela T computation strategy
r241 // add 10% tolerance for left (start) side
auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
variableDateTimeWithTolerance.m_TStart -= tolerance;
Add intersect méthode on variable and sqpDateTime...
r240 }
The cache is now updated only if date requested has been successfully...
r293 else {
qCWarning(LOG_VisualizationGraphWidget())
<< tr("Detection anormal zoom detection: ");
}
Add intersect méthode on variable and sqpDateTime...
r240 }
else {
The cache is now updated only if date requested has been successfully...
r293 qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection zoom out: ");
Add intersect méthode on variable and sqpDateTime...
r240 // add 10% tolerance for each side
auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
Implementation of the new Dela T computation strategy
r241 variableDateTimeWithTolerance.m_TStart -= tolerance;
variableDateTimeWithTolerance.m_TEnd += tolerance;
Add intersect méthode on variable and sqpDateTime...
r240 }
Implementation of the new Dela T computation strategy
r241 variable->setDateTime(dateTime);
// CHangement detected, we need to ask controller to request data loading
Fix the cosinus bug....
r276 emit requestDataLoading(variable, variableDateTimeWithTolerance);
The mock plugin can now create data with view operation
r219 }
The cache is now updated only if date requested has been successfully...
r293 else {
qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection zoom in: ");
}
Alexandre Leroux
QCustomPlot notify the graph widget when the xRange changed
r211 }
}
Alexandre Leroux
Handles key modifiers for zoom...
r166 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
{
auto zoomOrientations = QFlags<Qt::Orientation>{};
Implementation of the new Dela T computation strategy
r241 // Lambda that enables a zoom orientation if the key modifier related to this orientation
// has
Alexandre Leroux
Handles key modifiers for zoom...
r166 // 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
r219
void VisualizationGraphWidget::onDataCacheVariableUpdated()
{
Correction for pull request
r227 // NOTE:
Implementation of the new Dela T computation strategy
r241 // We don't want to call the method for each component of a variable unitarily, but for
// all
Correction for pull request
r227 // 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
The mock plugin can now create data with view operation
r219 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
auto variable = it->first;
Correction for pull request
r227 VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second,
variable->dataSeries(), variable->dateTime());
The mock plugin can now create data with view operation
r219 }
}
void VisualizationGraphWidget::updateDisplay(std::shared_ptr<Variable> variable)
{
auto abstractPlotableItPair = impl->m_VariableToPlotMultiMap.equal_range(variable);
auto abstractPlotableVect = QVector<QCPAbstractPlottable *>{};
for (auto it = abstractPlotableItPair.first; it != abstractPlotableItPair.second; ++it) {
abstractPlotableVect.push_back(it->second);
}
Correction for pull request
r227 VisualizationGraphHelper::updateData(abstractPlotableVect, variable->dataSeries(),
variable->dateTime());
The mock plugin can now create data with view operation
r219 }