From fc75912a40a961be6d9c7472571bcc20a6ae77ce Mon Sep 17 00:00:00 2001 From: Simon Schmeisser Date: Fri, 2 Feb 2024 22:01:46 +0100 Subject: [PATCH] Enable Qt6 compatibility (#1813) * QLayout::setMargin(int) -> setContentsMargins(...) * QRegExp -> QRegularExpression * QMouseEvent::[x|y]() -> position().[x|y]() * Allow specifying an order of Qt versions to consider * CI: Build against Qt 6 Co-authored-by: Robert Haschke --- .github/workflows/Dockerfile | 2 ++ .github/workflows/ci.yaml | 11 ++++++++-- CMakeLists.txt | 20 +++++++++++++++---- src/CMakeLists.txt | 4 +++- .../default_plugin/depth_cloud_display.cpp | 7 +++---- src/rviz/default_plugin/depth_cloud_display.h | 11 +++++----- src/rviz/properties/property_tree_model.cpp | 1 + src/rviz/tool_manager.cpp | 4 ++-- src/rviz/viewport_mouse_event.h | 5 +++++ src/rviz/visualization_frame.cpp | 3 ++- 10 files changed, 49 insertions(+), 19 deletions(-) diff --git a/.github/workflows/Dockerfile b/.github/workflows/Dockerfile index 5097b1c465..ab6a31d5fd 100644 --- a/.github/workflows/Dockerfile +++ b/.github/workflows/Dockerfile @@ -21,6 +21,8 @@ RUN --mount=type=bind,target=/tmp/rviz \ apt-get -q install --no-install-recommends -y \ # Some basic requirements wget git sudo \ + # Qt6 packages for Jammy + $(test "$ROS_DISTRO" = "one" && echo "qt6-base-dev qt6-base-dev-tools libqt6opengl6-dev") \ # Preferred build tools clang clang-format-12 clang-tidy clang-tools ccache && \ # diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b649be74f0..022ced9699 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -16,16 +16,23 @@ jobs: distro: [noetic, jammy] ogre: ["1.9", "1.12"] include: + - qt: 5 + cxxflags: -Werror - distro: noetic ogre: 1.9 env: CLANG_TIDY: true + - distro: jammy + ogre: 1.12 + qt: 6 + cxxflags: -Wno-deprecated-declarations -Werror env: - CXXFLAGS: "-DRVIZ_DEPRECATE_QT4_SLOTS -Werror -Wall -Wextra -Wwrite-strings -Wunreachable-code -Wpointer-arith -Wredundant-decls -Wno-strict-aliasing -Wno-sign-compare" + CXXFLAGS: "-DRVIZ_DEPRECATE_QT4_SLOTS -Wall -Wextra -Wwrite-strings -Wunreachable-code -Wpointer-arith -Wredundant-decls -Wno-strict-aliasing -Wno-sign-compare ${{ matrix.cxxflags}}" UPSTREAM_WORKSPACE: ${{ matrix.distro != 'jammy' && 'github:rhaschke/python_qt_binding#silent-external-warnings' || '' }} AFTER_INSTALL_TARGET_DEPENDENCIES: apt install -qq -y libogre-${{ matrix.ogre }}-dev CATKIN_LINT: true + CMAKE_ARGS: -DRVIZ_QT_VERSIONS="${{ matrix.qt }}" CCACHE_DIR: ${{ github.workspace }}/.ccache BASEDIR: /home/runner/work DOCKER_IMAGE: rhaschke/ici:rviz-${{ matrix.distro }}-ros @@ -33,7 +40,7 @@ jobs: # perform full clang-tidy check only on manual trigger (workflow_dispatch), PRs do check changed files, otherwise nothing CLANG_TIDY_BASE_REF: ${{ github.event_name != 'workflow_dispatch' && (github.base_ref || github.ref) || '' }} - name: "${{ matrix.distro }} • ogre ${{ matrix.ogre }}${{ matrix.env.CLANG_TIDY && (github.event_name != 'workflow_dispatch' && ' • clang-tidy (delta)' || ' • clang-tidy (all)') || '' }}" + name: "${{ matrix.distro }} • ogre ${{ matrix.ogre }} • Qt ${{ matrix.qt }}${{ matrix.env.CLANG_TIDY && (github.event_name != 'workflow_dispatch' && ' • clang-tidy (delta)' || ' • clang-tidy (all)') || '' }}" runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/CMakeLists.txt b/CMakeLists.txt index d623dd4e7c..f212ca6d6c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,7 +97,7 @@ if(APPLE) add_definitions(-D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES=0) endif() -# Prefer newer vender-specific OpenGL library +# Prefer newer vendor-specific OpenGL library if (POLICY CMP0072) cmake_policy(SET CMP0072 NEW) endif() @@ -105,9 +105,21 @@ find_package(OpenGL REQUIRED) set(CMAKE_AUTOMOC ON) -find_package(Qt5 REQUIRED COMPONENTS Core Widgets OpenGL) -set(QT_LIBRARIES Qt5::Widgets) -set(QTVERSION ${Qt5Widgets_VERSION}) +set(RVIZ_QT_VERSIONS "5;6" CACHE STRING "List of Qt versions to consider (in order)") +foreach(_current_version ${RVIZ_QT_VERSIONS}) + find_package(Qt${_current_version} QUIET COMPONENTS Core Widgets OpenGL) + if (Qt${_current_version}_FOUND) + set(QTVERSION ${Qt${_current_version}_VERSION}) + set(QT_LIBRARIES Qt${_current_version}::Widgets) + break() # early break from loop + else() + message(WARNING "Qt${_current_version} not found.") + endif() +endforeach() +if(NOT QTVERSION) + message(FATAL_ERROR "Failed to find a suitable Qt version.") +endif() +message(STATUS "Found Qt ${QTVERSION}") add_definitions(-DQT_NO_KEYWORDS) find_package(catkin REQUIRED diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bf61488585..b8f7d06c21 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,4 +3,6 @@ add_subdirectory(image_view) if (CATKIN_ENABLE_TESTING) add_subdirectory(test) endif() -add_subdirectory(python_bindings) +if (QT_VERSION_MAJOR EQUAL 5) + add_subdirectory(python_bindings) +endif() diff --git a/src/rviz/default_plugin/depth_cloud_display.cpp b/src/rviz/default_plugin/depth_cloud_display.cpp index 7b98d73dcb..3e863e85b6 100644 --- a/src/rviz/default_plugin/depth_cloud_display.cpp +++ b/src/rviz/default_plugin/depth_cloud_display.cpp @@ -27,6 +27,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include +#include #include "depth_cloud_display.h" #include @@ -78,8 +79,7 @@ DepthCloudDisplay::DepthCloudDisplay() { // Depth map properties - QRegExp depth_filter("depth"); - depth_filter.setCaseSensitivity(Qt::CaseInsensitive); + QRegularExpression depth_filter("depth", QRegularExpression::CaseInsensitiveOption); topic_filter_property_ = new Property("Topic Filter", true, @@ -100,8 +100,7 @@ DepthCloudDisplay::DepthCloudDisplay() depth_transport_property_->setStdString("raw"); // color image properties - QRegExp color_filter("color|rgb|bgr|gray|mono"); - color_filter.setCaseSensitivity(Qt::CaseInsensitive); + QRegularExpression color_filter("color|rgb|bgr|gray|mono", QRegularExpression::CaseInsensitiveOption); color_topic_property_ = new RosFilteredTopicProperty( "Color Image Topic", "", diff --git a/src/rviz/default_plugin/depth_cloud_display.h b/src/rviz/default_plugin/depth_cloud_display.h index 6a3ce750b9..4ba129637e 100644 --- a/src/rviz/default_plugin/depth_cloud_display.h +++ b/src/rviz/default_plugin/depth_cloud_display.h @@ -54,6 +54,7 @@ #endif #include +#include using namespace message_filters::sync_policies; @@ -81,7 +82,7 @@ class RosFilteredTopicProperty : public RosTopicProperty const QString& default_value = QString(), const QString& message_type = QString(), const QString& description = QString(), - const QRegExp& filter = QRegExp(), + const QRegularExpression& filter = QRegularExpression(), Property* parent = nullptr) : RosTopicProperty(name, default_value, message_type, description, parent) , filter_(filter) @@ -94,7 +95,7 @@ class RosFilteredTopicProperty : public RosTopicProperty const QString& default_value, const QString& message_type, const QString& description, - const QRegExp& filter, + const QRegularExpression& filter, Property* parent, Func&& changed_slot, const R* receiver) @@ -109,7 +110,7 @@ class RosFilteredTopicProperty : public RosTopicProperty const QString& default_value, const QString& message_type, const QString& description, - const QRegExp& filter, + const QRegularExpression& filter, P* parent, Func&& changed_slot) : RosFilteredTopicProperty(name, default_value, message_type, description, filter, parent) @@ -124,7 +125,7 @@ class RosFilteredTopicProperty : public RosTopicProperty fillTopicList(); } - QRegExp filter() const + QRegularExpression filter() const { return filter_; } @@ -142,7 +143,7 @@ protected Q_SLOTS: } private: - QRegExp filter_; + QRegularExpression filter_; bool filter_enabled_; }; diff --git a/src/rviz/properties/property_tree_model.cpp b/src/rviz/properties/property_tree_model.cpp index 6c5b737775..5b8aa36229 100644 --- a/src/rviz/properties/property_tree_model.cpp +++ b/src/rviz/properties/property_tree_model.cpp @@ -29,6 +29,7 @@ #include +#include #include #include diff --git a/src/rviz/tool_manager.cpp b/src/rviz/tool_manager.cpp index 5c48804602..31f674a754 100644 --- a/src/rviz/tool_manager.cpp +++ b/src/rviz/tool_manager.cpp @@ -28,7 +28,7 @@ */ #include -#include +#include #include @@ -42,7 +42,7 @@ namespace rviz { QString addSpaceToCamelCase(QString input) { - QRegExp re = QRegExp("([A-Z])([a-z]*)"); + QRegularExpression re = QRegularExpression("([A-Z])([a-z]*)"); input.replace(re, " \\1\\2"); return input.trimmed(); } diff --git a/src/rviz/viewport_mouse_event.h b/src/rviz/viewport_mouse_event.h index 849386fbed..00f3e883e7 100644 --- a/src/rviz/viewport_mouse_event.h +++ b/src/rviz/viewport_mouse_event.h @@ -54,8 +54,13 @@ class ViewportMouseEvent : panel(p) , viewport(vp) , type(e->type()) +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + , x(e->position().x()) + , y(e->position().y()) +#else , x(e->x()) , y(e->y()) +#endif , wheel_delta(0) , acting_button(e->button()) , buttons_down(e->buttons()) diff --git a/src/rviz/visualization_frame.cpp b/src/rviz/visualization_frame.cpp index 9c1028c7ea..e6572ec198 100644 --- a/src/rviz/visualization_frame.cpp +++ b/src/rviz/visualization_frame.cpp @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -274,7 +275,7 @@ void VisualizationFrame::initialize(const QString& display_config_file) QWidget* central_widget = new QWidget(this); QHBoxLayout* central_layout = new QHBoxLayout; central_layout->setSpacing(0); - central_layout->setMargin(0); + central_layout->setContentsMargins(0, 0, 0, 0); render_panel_ = new RenderPanel(central_widget);