##// END OF EJS Templates
Fixes Windows compilation
Fixes Windows compilation

File last commit:

r221:4aa09749c958
r221:4aa09749c958
Show More
VisualizationGraphWidget.cpp
165 lines | 5.7 KiB | text/x-c | CppLexer
/ gui / src / Visualization / VisualizationGraphWidget.cpp
mv visualization -> Visualization...
r93 #include "Visualization/VisualizationGraphWidget.h"
Alexandre Leroux
Uses factory in the VariableGraphWidget
r171 #include "Visualization/GraphPlottablesFactory.h"
Alexandre Leroux
Updates visitor interface...
r192 #include "Visualization/IVisualizationWidgetVisitor.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
The mock plugin can now create data with view operation
r219 std::unordered_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 name to a graph...
r182 // 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
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);
Alexandre Leroux
QCustomPlot notify the graph widget when the xRange changed
r211 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
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
Alexandre Leroux
Pass Variable as shared_ptr
r174 auto createdPlottables = GraphPlottablesFactory::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
Alexandre Leroux
Fixes Windows compilation
r221 connect(variable.get(), SIGNAL(dataCacheUpdated()), this, SLOT(onDataCacheVariableUpdated()));
Add the visualization gui classes
r111 }
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;
}
Add the visualization gui classes
r111 void VisualizationGraphWidget::close()
{
// The main view cannot be directly closed.
return;
}
Add const and override
r112 QString VisualizationGraphWidget::name() const
Add the visualization gui classes
r111 {
Alexandre Leroux
Adds name to a graph...
r182 if (auto title = dynamic_cast<QCPTextElement *>(ui->widget->plotLayout()->elementAt(0))) {
return title->text();
}
else {
return QString{};
}
Add the visualization gui classes
r111 }
Alexandre Leroux
Handles key modifiers for zoom...
r166
Alexandre Leroux
QCustomPlot notify the graph widget when the xRange changed
r211 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2)
{
The mock plugin can now create data with view operation
r219
qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged");
for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
auto variable = it->first;
auto tolerance = 0.1 * (t2.upper - t2.lower);
auto dateTime = SqpDateTime{t2.lower - tolerance, t2.upper + tolerance};
qCInfo(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged")
<< variable->dataSeries()->xAxisData()->size();
if (!variable->contains(dateTime)) {
sqpApp->variableController().requestDataLoading(variable, dateTime);
}
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>{};
// 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);
}
The mock plugin can now create data with view operation
r219
void VisualizationGraphWidget::onDataCacheVariableUpdated()
{
for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
auto variable = it->first;
GraphPlottablesFactory::updateData(QVector<QCPAbstractPlottable *>{} << it->second,
variable->dataSeries(), variable->dateTime());
}
}
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);
}
GraphPlottablesFactory::updateData(abstractPlotableVect, variable->dataSeries(),
variable->dateTime());
}