Skip to content

Commit

Permalink
Fix deprecated Qt usage (#555)
Browse files Browse the repository at this point in the history
* Fix Qt 5 deprecation warnings

* Replace obsoleted QWheelEvent functions
* Use QMultiMap for maps storing multiple values with the same key

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Update function signature and fix usage of QMultiMap

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Stay compatible with Qt versions less than 5.14

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Use QT_VERSION_CHECK

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Round from floating point to integer

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Use QT_VERSION_CHECK

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Add missing parentheses

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Replace obsolete QWheelEvent constructor

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Use QPoint for angle delta

Signed-off-by: Jacob Perron <jacob@openrobotics.org>

* Undo whitespace changes

Signed-off-by: Jacob Perron <jacob@openrobotics.org>
  • Loading branch information
jacobperron committed Jun 2, 2020
1 parent c5e6803 commit 2eb3d2a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions rviz_common/include/rviz_common/viewport_mouse_event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class RVIZ_COMMON_PUBLIC ViewportMouseEvent
int device_pixel_ratio;
int x;
int y;
/// Angle that the common vertical mouse wheel was rotated
int wheel_delta;
// The button which caused the event. Can be Qt::NoButton (move or wheel events).
Qt::MouseButton acting_button;
Expand Down
4 changes: 2 additions & 2 deletions rviz_common/src/rviz_common/add_display_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ struct PluginGroup
};

void getPluginGroups(
const QMap<QString, QString> & datatype_plugins,
const QMultiMap<QString, QString> & datatype_plugins,
QList<PluginGroup> * groups,
std::vector<std::string> * unvisualizable,
ros_integration::RosNodeAbstractionIface::WeakPtr rviz_ros_node)
Expand Down Expand Up @@ -607,7 +607,7 @@ void TopicDisplayWidget::findPlugins(DisplayFactory * factory)
"future release."
);
}
datatype_plugins_.insertMulti(topic_type, plugin.id);
datatype_plugins_.insert(topic_type, plugin.id);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion rviz_common/src/rviz_common/add_display_dialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#include <QComboBox> // NOLINT: cpplint is unable to handle the include order here
#include <QDialog> // NOLINT: cpplint is unable to handle the include order here
#include <QMultiMap> // NOLINT: cpplint is unable to handle the include order here
#include <QTreeWidget> // NOLINT: cpplint is unable to handle the include order here

#include "rviz_common/factory/factory.hpp"
Expand Down Expand Up @@ -205,7 +206,7 @@ private Q_SLOTS:

// Map from ROS topic type to all displays that can visualize it.
// One key may have multiple values.
QMap<QString, QString> datatype_plugins_;
QMultiMap<QString, QString> datatype_plugins_;
ros_integration::RosNodeAbstractionIface::WeakPtr rviz_ros_node_;
};

Expand Down
6 changes: 6 additions & 0 deletions rviz_common/src/rviz_common/render_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,14 @@ void RenderPanel::wheelEvent(QWheelEvent * event)
int last_x = mouse_x_;
int last_y = mouse_y_;

#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
const QPoint rounded_position = event->position().toPoint();
mouse_x_ = rounded_position.x();
mouse_y_ = rounded_position.y();
#else
mouse_x_ = event->x();
mouse_y_ = event->y();
#endif

if (context_) {
setFocus(Qt::MouseFocusReason);
Expand Down
7 changes: 6 additions & 1 deletion rviz_common/src/rviz_common/viewport_mouse_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@ ViewportMouseEvent::ViewportMouseEvent(RenderPanel * p, QWheelEvent * e, int lx,
: panel(p),
type(e->type()),
device_pixel_ratio(static_cast<int>(panel->getRenderWindow()->devicePixelRatio())),
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
x(e->position().x() * device_pixel_ratio),
y(e->position().y() * device_pixel_ratio),
#else
x(e->x() * device_pixel_ratio),
y(e->y() * device_pixel_ratio),
wheel_delta(e->delta()),
#endif
wheel_delta(e->angleDelta().x()),
acting_button(Qt::NoButton),
buttons_down(e->buttons()),
modifiers(e->modifiers()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,18 @@ class ViewControllerTestFixture : public DisplayTestFixture
rviz_common::ViewportMouseEvent generateMouseWheelEvent(int delta)
{
auto point = QPointF();
auto global_point = QPointF();
auto pixel_delta = QPoint();
auto angle_delta = QPoint(delta, 0);
auto mouseEvent = new QWheelEvent(
point, delta, Qt::NoButton, Qt::NoModifier, Qt::Orientation::Horizontal);
point,
global_point,
pixel_delta,
angle_delta,
Qt::NoButton,
Qt::NoModifier,
Qt::NoScrollPhase,
false);
return {render_panel_.get(), mouseEvent, 0, 0};
}

Expand Down

0 comments on commit 2eb3d2a

Please sign in to comment.