Skip to content

Commit

Permalink
Fix build with qwt 6.2, deprecation warning (#3047)
Browse files Browse the repository at this point in the history
* IncrementalPlot.cc: include qwt_scale_map.h
* Use Qt::MiddleButton to fix deprecation warning
* PlotCurve: add private helper for renamed members

In qwt 6.2, they have renamed all member variables,
so create helper functions to minimize the ifdefs we will need
to support both versions.

* PlotCurve: add ifdefs to support qwt 6.2.0

Signed-off-by: Steven Peters <scpeters@openrobotics.org>
  • Loading branch information
scpeters committed Aug 11, 2021
1 parent 8ce1215 commit c343565
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 26 deletions.
4 changes: 2 additions & 2 deletions gazebo/gui/GLWidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ void GLWidget::SetMouseEventButtons(const Qt::MouseButtons &_buttons)
this->dataPtr->mouseEvent.Buttons() | 0x0);
}

if (_buttons & Qt::MidButton)
if (_buttons & Qt::MiddleButton)
{
this->dataPtr->mouseEvent.SetButtons(
this->dataPtr->mouseEvent.Buttons() | common::MouseEvent::MIDDLE);
Expand All @@ -1388,6 +1388,6 @@ void GLWidget::SetMouseEventButton(const Qt::MouseButton &_button)
this->dataPtr->mouseEvent.SetButton(common::MouseEvent::LEFT);
else if (_button == Qt::RightButton)
this->dataPtr->mouseEvent.SetButton(common::MouseEvent::RIGHT);
else if (_button == Qt::MidButton)
else if (_button == Qt::MiddleButton)
this->dataPtr->mouseEvent.SetButton(common::MouseEvent::MIDDLE);
}
2 changes: 1 addition & 1 deletion gazebo/gui/plot/IncrementalPlot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ IncrementalPlot::IncrementalPlot(QWidget *_parent)
// box zoom
this->dataPtr->zoomer = new QwtPlotZoomer(this->canvas());
this->dataPtr->zoomer->setMousePattern(QwtEventPattern::MouseSelect1,
Qt::MidButton);
Qt::MiddleButton);
this->dataPtr->zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
Qt::RightButton, Qt::ControlModifier);
this->dataPtr->zoomer->setMousePattern(QwtEventPattern::MouseSelect3,
Expand Down
99 changes: 76 additions & 23 deletions gazebo/gui/plot/PlotCurve.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
#include "gazebo/gui/plot/IncrementalPlot.hh"
#include "gazebo/gui/plot/PlotCurve.hh"

// member variables in qwt_series_data were renamed in 6.2.0
#if QWT_VERSION < 0x060200
#define QWT_VERSION_LT_620
#endif

using namespace gazebo;
using namespace gui;

Expand Down Expand Up @@ -51,75 +56,123 @@ namespace gazebo
public: CurveData()
{}

/// \brief Add a point to the sample.
private: inline const QRectF& BoundingRect() const
{
#ifdef QWT_VERSION_LT_620
return this->d_boundingRect;
#else
return this->cachedBoundingRect;
#endif
}

private: inline QRectF& BoundingRect()
{
#ifdef QWT_VERSION_LT_620
return this->d_boundingRect;
#else
return this->cachedBoundingRect;
#endif
}

private: inline const QVector<QPointF>& SamplesRef() const
{
#ifdef QWT_VERSION_LT_620
return this->d_samples;
#else
return this->m_samples;
#endif
}

private: inline QVector<QPointF>& SamplesRef()
{
#ifdef QWT_VERSION_LT_620
return this->d_samples;
#else
return this->m_samples;
#endif
}

/// \brief Bounding rectangle accessor. This create the object
/// if it does not already exist or is too small.
/// \return Bounding box of the sample.
public: virtual QRectF boundingRect() const
{
if (this->d_boundingRect.width() < 0.0)
if (this->BoundingRect().width() < 0.0)
{
#ifdef QWT_VERSION_LT_620
this->d_boundingRect = qwtBoundingRect(*this);
#else
this->cachedBoundingRect = qwtBoundingRect(*this);
#endif
}

// set a minimum bounding box height
// this prevents plot's auto scale to zoom in on near-zero
// floating point noise.
double minHeight = 1e-3;
double absHeight = std::fabs(this->d_boundingRect.height());
double absHeight = std::fabs(this->BoundingRect().height());
if (absHeight < minHeight)
{
double halfMinHeight = minHeight * 0.5;
double mid = this->d_boundingRect.top() +
double mid = this->BoundingRect().top() +
(absHeight * 0.5);
#ifdef QWT_VERSION_LT_620
this->d_boundingRect.setTop(mid - halfMinHeight);
this->d_boundingRect.setBottom(mid + halfMinHeight);
#else
this->cachedBoundingRect.setTop(mid - halfMinHeight);
this->cachedBoundingRect.setBottom(mid + halfMinHeight);
#endif
}

return this->d_boundingRect;
return this->BoundingRect();
}

/// \brief Add a point to the sample.
/// \param[in] _point Point to add.
public: inline void Add(const QPointF &_point)
{
this->d_samples += _point;
this->SamplesRef() += _point;

if (this->d_samples.size() > maxSampleSize)
if (this->SamplesRef().size() > maxSampleSize)
{
// remove sample window
// update bounding rect?
this->d_samples.remove(0, windowSize);
this->SamplesRef().remove(0, windowSize);
}

if (this->d_samples.size() == 1)
if (this->SamplesRef().size() == 1)
{
// init bounding rect
this->d_boundingRect.setTopLeft(_point);
this->d_boundingRect.setBottomRight(_point);
this->BoundingRect().setTopLeft(_point);
this->BoundingRect().setBottomRight(_point);
return;
}

// expand bounding rect
if (_point.x() < this->d_boundingRect.left())
this->d_boundingRect.setLeft(_point.x());
else if (_point.x() > this->d_boundingRect.right())
this->d_boundingRect.setRight(_point.x());
if (_point.y() < this->d_boundingRect.top())
this->d_boundingRect.setTop(_point.y());
else if (_point.y() > this->d_boundingRect.bottom())
this->d_boundingRect.setBottom(_point.y());
if (_point.x() < this->BoundingRect().left())
this->BoundingRect().setLeft(_point.x());
else if (_point.x() > this->BoundingRect().right())
this->BoundingRect().setRight(_point.x());
if (_point.y() < this->BoundingRect().top())
this->BoundingRect().setTop(_point.y());
else if (_point.y() > this->BoundingRect().bottom())
this->BoundingRect().setBottom(_point.y());
}

/// \brief Clear the sample data.
public: void Clear()
{
this->d_samples.clear();
this->d_samples.squeeze();
this->d_boundingRect = QRectF(0.0, 0.0, -1.0, -1.0);
this->SamplesRef().clear();
this->SamplesRef().squeeze();
this->BoundingRect() = QRectF(0.0, 0.0, -1.0, -1.0);
}

/// \brief Get the sample data.
/// \return A vector of same points.
public: QVector<QPointF> Samples() const
{
return this->d_samples;
return this->SamplesRef();
}

/// \brief maxium sample size of this curve.
Expand Down
2 changes: 2 additions & 0 deletions gazebo/gui/plot/qwt_gazebo.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#pragma clang diagnostic ignored "-Wfloat-equal"

#include <qwt/qwt_curve_fitter.h>
#include <qwt/qwt_global.h>
#include <qwt/qwt_legend.h>
#include <qwt/qwt_painter.h>
#include <qwt/qwt_picker_machine.h>
Expand All @@ -38,6 +39,7 @@
#include <qwt/qwt_plot_panner.h>
#include <qwt/qwt_plot_zoomer.h>
#include <qwt/qwt_scale_engine.h>
#include <qwt/qwt_scale_map.h>
#include <qwt/qwt_scale_widget.h>
#include <qwt/qwt_symbol.h>
#include <qwt/qwt_plot_renderer.h>
Expand Down

0 comments on commit c343565

Please sign in to comment.