Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build with qwt 6.2, deprecation warning #3047

Merged
merged 6 commits into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gazebo/gui/GLWidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,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 @@ -1397,6 +1397,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
4 changes: 4 additions & 0 deletions gazebo/gui/plot/qwt_gazebo.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#if defined __has_include
#if __has_include (<qwt.h>)
#include <qwt_curve_fitter.h>
#include <qwt_global.h>
#include <qwt_legend.h>
#include <qwt_painter.h>
#include <qwt_picker_machine.h>
Expand All @@ -40,6 +41,7 @@
#include <qwt_plot_panner.h>
#include <qwt_plot_zoomer.h>
#include <qwt_scale_engine.h>
#include <qwt_scale_map.h>
#include <qwt_scale_widget.h>
#include <qwt_symbol.h>
#include <qwt_plot_renderer.h>
Expand All @@ -49,6 +51,7 @@

#ifndef GAZEBO_GUI_QWT_IS_INCLUDED
#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 @@ -63,6 +66,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