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

File last commit:

r184:0055ef23e3bb
r185:fa2e26651269 merge
Show More
VisualizationGraphWidget.cpp
86 lines | 2.7 KiB | text/x-c | CppLexer
/ gui / src / Visualization / VisualizationGraphWidget.cpp
mv visualization -> Visualization...
r95 #include "Visualization/VisualizationGraphWidget.h"
Alexandre Leroux
Uses factory in the VariableGraphWidget
r184 #include "Visualization/GraphPlottablesFactory.h"
Creation of VisualizationWidget, VizualizationTabWidget, VisualizationZoneWidget, VisualizationGraphWidget
r58 #include "ui_VisualizationGraphWidget.h"
Add the visualization gui classes
r118 #include <Variable/Variable.h>
#include <unordered_map>
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
Alexandre Leroux
Uses factory in the VariableGraphWidget
r184 std::unordered_map<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMap;
Add the visualization gui classes
r118 };
Creation of VisualizationWidget, VizualizationTabWidget, VisualizationZoneWidget, VisualizationGraphWidget
r58 VisualizationGraphWidget::VisualizationGraphWidget(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
// 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);
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
auto createdPlottables = GraphPlottablesFactory::create(variable.get(), *ui->widget);
for (auto createdPlottable : qAsConst(createdPlottables)) {
impl->m_VariableToPlotMap.insert({variable, createdPlottable});
}
Add the visualization gui classes
r118 }
void VisualizationGraphWidget::accept(IVisualizationWidget *visitor)
{
// TODO: manage the visitor
}
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 {
return QStringLiteral("MainView");
}
Alexandre Leroux
Handles key modifiers for zoom...
r179
void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
{
auto zoomOrientations = QFlags<Qt::Orientation>{};
// Lambda that enables a zoom orientation if the key modifier related to this orientation has
// 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);
}