From 2eb3d2aeabcaeeebcc9d40ed0b9d6def03328afd Mon Sep 17 00:00:00 2001 From: Jacob Perron Date: Tue, 2 Jun 2020 13:04:01 -0700 Subject: [PATCH] Fix deprecated Qt usage (#555) * 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 * Update function signature and fix usage of QMultiMap Signed-off-by: Jacob Perron * Stay compatible with Qt versions less than 5.14 Signed-off-by: Jacob Perron * Use QT_VERSION_CHECK Signed-off-by: Jacob Perron * Round from floating point to integer Signed-off-by: Jacob Perron * Use QT_VERSION_CHECK Signed-off-by: Jacob Perron * Add missing parentheses Signed-off-by: Jacob Perron * Replace obsolete QWheelEvent constructor Signed-off-by: Jacob Perron * Use QPoint for angle delta Signed-off-by: Jacob Perron * Undo whitespace changes Signed-off-by: Jacob Perron --- .../include/rviz_common/viewport_mouse_event.hpp | 1 + rviz_common/src/rviz_common/add_display_dialog.cpp | 4 ++-- rviz_common/src/rviz_common/add_display_dialog.hpp | 3 ++- rviz_common/src/rviz_common/render_panel.cpp | 6 ++++++ rviz_common/src/rviz_common/viewport_mouse_event.cpp | 7 ++++++- .../view_controller_test_fixture.hpp | 12 +++++++++++- 6 files changed, 28 insertions(+), 5 deletions(-) diff --git a/rviz_common/include/rviz_common/viewport_mouse_event.hpp b/rviz_common/include/rviz_common/viewport_mouse_event.hpp index b766a26be..703defb89 100644 --- a/rviz_common/include/rviz_common/viewport_mouse_event.hpp +++ b/rviz_common/include/rviz_common/viewport_mouse_event.hpp @@ -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; diff --git a/rviz_common/src/rviz_common/add_display_dialog.cpp b/rviz_common/src/rviz_common/add_display_dialog.cpp index 494c87d4e..5ec60796f 100644 --- a/rviz_common/src/rviz_common/add_display_dialog.cpp +++ b/rviz_common/src/rviz_common/add_display_dialog.cpp @@ -140,7 +140,7 @@ struct PluginGroup }; void getPluginGroups( - const QMap & datatype_plugins, + const QMultiMap & datatype_plugins, QList * groups, std::vector * unvisualizable, ros_integration::RosNodeAbstractionIface::WeakPtr rviz_ros_node) @@ -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); } } } diff --git a/rviz_common/src/rviz_common/add_display_dialog.hpp b/rviz_common/src/rviz_common/add_display_dialog.hpp index 3c7e06c08..2f4816579 100644 --- a/rviz_common/src/rviz_common/add_display_dialog.hpp +++ b/rviz_common/src/rviz_common/add_display_dialog.hpp @@ -37,6 +37,7 @@ #include // NOLINT: cpplint is unable to handle the include order here #include // NOLINT: cpplint is unable to handle the include order here +#include // NOLINT: cpplint is unable to handle the include order here #include // NOLINT: cpplint is unable to handle the include order here #include "rviz_common/factory/factory.hpp" @@ -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 datatype_plugins_; + QMultiMap datatype_plugins_; ros_integration::RosNodeAbstractionIface::WeakPtr rviz_ros_node_; }; diff --git a/rviz_common/src/rviz_common/render_panel.cpp b/rviz_common/src/rviz_common/render_panel.cpp index 00d61b8a2..e83f3b8d4 100644 --- a/rviz_common/src/rviz_common/render_panel.cpp +++ b/rviz_common/src/rviz_common/render_panel.cpp @@ -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); diff --git a/rviz_common/src/rviz_common/viewport_mouse_event.cpp b/rviz_common/src/rviz_common/viewport_mouse_event.cpp index 6dbae9f7c..e528d9863 100644 --- a/rviz_common/src/rviz_common/viewport_mouse_event.cpp +++ b/rviz_common/src/rviz_common/viewport_mouse_event.cpp @@ -57,9 +57,14 @@ ViewportMouseEvent::ViewportMouseEvent(RenderPanel * p, QWheelEvent * e, int lx, : panel(p), type(e->type()), device_pixel_ratio(static_cast(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()), diff --git a/rviz_default_plugins/test/rviz_default_plugins/view_controllers/view_controller_test_fixture.hpp b/rviz_default_plugins/test/rviz_default_plugins/view_controllers/view_controller_test_fixture.hpp index 9b88e1c4e..1b2a0b4bc 100644 --- a/rviz_default_plugins/test/rviz_default_plugins/view_controllers/view_controller_test_fixture.hpp +++ b/rviz_default_plugins/test/rviz_default_plugins/view_controllers/view_controller_test_fixture.hpp @@ -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}; }