##// END OF EJS Templates
Implementation of the new Dela T computation strategy
Implementation of the new Dela T computation strategy

File last commit:

r260:1a61ee1f7b08
r260:1a61ee1f7b08
Show More
VisualizationGraphWidget.cpp
205 lines | 7.6 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"
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>
#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 {
// 1 variable -> n qcpplot
The mock plugin can now create data with view operation
r235 std::unordered_multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *>
m_VariableToPlotMultiMap;
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
Adds name to a graph...
r196 // qcpplot title
ui->widget->plotLayout()->insertRow(0);
ui->widget->plotLayout()->addElement(0, 0, new QCPTextElement{ui->widget, name});
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
Handles key modifiers for zoom...
r179 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
Alexandre Leroux
QCustomPlot notify the graph widget when the xRange changed
r227 connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>(
&QCPAxis::rangeChanged),
this, &VisualizationGraphWidget::onRangeChanged);
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
void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
{
Alexandre Leroux
Uses factory in the VariableGraphWidget
r184 // Uses delegate to create the qcpplot components according to the variable
Correction for pull request
r243 auto createdPlottables = VisualizationGraphHelper::create(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
Alexandre Leroux
Fixes Windows compilation
r237 connect(variable.get(), SIGNAL(dataCacheUpdated()), this, SLOT(onDataCacheVariableUpdated()));
Add the visualization gui classes
r118 }
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;
}
Add the visualization gui classes
r118 void VisualizationGraphWidget::close()
{
// The main view cannot be directly closed.
return;
}
Add const and override
r119 QString VisualizationGraphWidget::name() const
Add the visualization gui classes
r118 {
Alexandre Leroux
Adds name to a graph...
r196 if (auto title = dynamic_cast<QCPTextElement *>(ui->widget->plotLayout()->elementAt(0))) {
return title->text();
}
else {
return QString{};
}
Add the visualization gui classes
r118 }
Alexandre Leroux
Handles key modifiers for zoom...
r179
Alexandre Leroux
QCustomPlot notify the graph widget when the xRange changed
r227 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2)
{
The mock plugin can now create data with view operation
r235
qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged");
for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
Add intersect méthode on variable and sqpDateTime...
r258
The mock plugin can now create data with view operation
r235 auto variable = it->first;
Add intersect méthode on variable and sqpDateTime...
r258 qCInfo(LOG_VisualizationGraphWidget())
<< tr("TORM: VisualizationGraphWidget::onRangeChanged")
<< variable->dataSeries()->xAxisData()->size();
auto dateTime = SqpDateTime{t2.lower, t2.upper};
The mock plugin can now create data with view operation
r235
if (!variable->contains(dateTime)) {
Add intersect méthode on variable and sqpDateTime...
r258
Implementation of the new Dela T computation strategy
r260 auto variableDateTimeWithTolerance = dateTime;
Add intersect méthode on variable and sqpDateTime...
r258 if (variable->intersect(dateTime)) {
auto variableDateTime = variable->dateTime();
if (variableDateTime.m_TStart < dateTime.m_TStart) {
dateTime.m_TStart = variableDateTime.m_TStart;
Implementation of the new Dela T computation strategy
r260 // START is set to the old one. tolerance have to be added to the right
// 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...
r258 }
if (variableDateTime.m_TEnd > dateTime.m_TEnd) {
dateTime.m_TEnd = variableDateTime.m_TEnd;
Implementation of the new Dela T computation strategy
r260 // END is set to the old one. tolerance have to be added to the left
// 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...
r258 }
}
else {
// add 10% tolerance for each side
auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
Implementation of the new Dela T computation strategy
r260 variableDateTimeWithTolerance.m_TStart -= tolerance;
variableDateTimeWithTolerance.m_TEnd += tolerance;
Add intersect méthode on variable and sqpDateTime...
r258 }
Implementation of the new Dela T computation strategy
r260 variable->setDateTime(dateTime);
// CHangement detected, we need to ask controller to request data loading
sqpApp->variableController().requestDataLoading(variable,
variableDateTimeWithTolerance);
The mock plugin can now create data with view operation
r235 }
Alexandre Leroux
QCustomPlot notify the graph widget when the xRange changed
r227 }
}
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
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
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;
Correction for pull request
r243 VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second,
variable->dataSeries(), variable->dateTime());
The mock plugin can now create data with view operation
r235 }
}
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
r243 VisualizationGraphHelper::updateData(abstractPlotableVect, variable->dataSeries(),
variable->dateTime());
The mock plugin can now create data with view operation
r235 }