Skip to content

Commit fc75912

Browse files
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 <[email protected]>
1 parent b466cb9 commit fc75912

10 files changed

+49
-19
lines changed

.github/workflows/Dockerfile

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ RUN --mount=type=bind,target=/tmp/rviz \
2121
apt-get -q install --no-install-recommends -y \
2222
# Some basic requirements
2323
wget git sudo \
24+
# Qt6 packages for Jammy
25+
$(test "$ROS_DISTRO" = "one" && echo "qt6-base-dev qt6-base-dev-tools libqt6opengl6-dev") \
2426
# Preferred build tools
2527
clang clang-format-12 clang-tidy clang-tools ccache && \
2628
#

.github/workflows/ci.yaml

+9-2
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,31 @@ jobs:
1616
distro: [noetic, jammy]
1717
ogre: ["1.9", "1.12"]
1818
include:
19+
- qt: 5
20+
cxxflags: -Werror
1921
- distro: noetic
2022
ogre: 1.9
2123
env:
2224
CLANG_TIDY: true
25+
- distro: jammy
26+
ogre: 1.12
27+
qt: 6
28+
cxxflags: -Wno-deprecated-declarations -Werror
2329

2430
env:
25-
CXXFLAGS: "-DRVIZ_DEPRECATE_QT4_SLOTS -Werror -Wall -Wextra -Wwrite-strings -Wunreachable-code -Wpointer-arith -Wredundant-decls -Wno-strict-aliasing -Wno-sign-compare"
31+
CXXFLAGS: "-DRVIZ_DEPRECATE_QT4_SLOTS -Wall -Wextra -Wwrite-strings -Wunreachable-code -Wpointer-arith -Wredundant-decls -Wno-strict-aliasing -Wno-sign-compare ${{ matrix.cxxflags}}"
2632
UPSTREAM_WORKSPACE: ${{ matrix.distro != 'jammy' && 'github:rhaschke/python_qt_binding#silent-external-warnings' || '' }}
2733
AFTER_INSTALL_TARGET_DEPENDENCIES: apt install -qq -y libogre-${{ matrix.ogre }}-dev
2834
CATKIN_LINT: true
35+
CMAKE_ARGS: -DRVIZ_QT_VERSIONS="${{ matrix.qt }}"
2936
CCACHE_DIR: ${{ github.workspace }}/.ccache
3037
BASEDIR: /home/runner/work
3138
DOCKER_IMAGE: rhaschke/ici:rviz-${{ matrix.distro }}-ros
3239
CACHE_PREFIX: ${{ matrix.distro }}
3340
# perform full clang-tidy check only on manual trigger (workflow_dispatch), PRs do check changed files, otherwise nothing
3441
CLANG_TIDY_BASE_REF: ${{ github.event_name != 'workflow_dispatch' && (github.base_ref || github.ref) || '' }}
3542

36-
name: "${{ matrix.distro }} • ogre ${{ matrix.ogre }}${{ matrix.env.CLANG_TIDY && (github.event_name != 'workflow_dispatch' && ' • clang-tidy (delta)' || ' • clang-tidy (all)') || '' }}"
43+
name: "${{ matrix.distro }} • ogre ${{ matrix.ogre }} • Qt ${{ matrix.qt }}${{ matrix.env.CLANG_TIDY && (github.event_name != 'workflow_dispatch' && ' • clang-tidy (delta)' || ' • clang-tidy (all)') || '' }}"
3744
runs-on: ubuntu-latest
3845
steps:
3946
- uses: actions/checkout@v3

CMakeLists.txt

+16-4
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,29 @@ if(APPLE)
9797
add_definitions(-D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES=0)
9898
endif()
9999

100-
# Prefer newer vender-specific OpenGL library
100+
# Prefer newer vendor-specific OpenGL library
101101
if (POLICY CMP0072)
102102
cmake_policy(SET CMP0072 NEW)
103103
endif()
104104
find_package(OpenGL REQUIRED)
105105

106106
set(CMAKE_AUTOMOC ON)
107107

108-
find_package(Qt5 REQUIRED COMPONENTS Core Widgets OpenGL)
109-
set(QT_LIBRARIES Qt5::Widgets)
110-
set(QTVERSION ${Qt5Widgets_VERSION})
108+
set(RVIZ_QT_VERSIONS "5;6" CACHE STRING "List of Qt versions to consider (in order)")
109+
foreach(_current_version ${RVIZ_QT_VERSIONS})
110+
find_package(Qt${_current_version} QUIET COMPONENTS Core Widgets OpenGL)
111+
if (Qt${_current_version}_FOUND)
112+
set(QTVERSION ${Qt${_current_version}_VERSION})
113+
set(QT_LIBRARIES Qt${_current_version}::Widgets)
114+
break() # early break from loop
115+
else()
116+
message(WARNING "Qt${_current_version} not found.")
117+
endif()
118+
endforeach()
119+
if(NOT QTVERSION)
120+
message(FATAL_ERROR "Failed to find a suitable Qt version.")
121+
endif()
122+
message(STATUS "Found Qt ${QTVERSION}")
111123
add_definitions(-DQT_NO_KEYWORDS)
112124

113125
find_package(catkin REQUIRED

src/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ add_subdirectory(image_view)
33
if (CATKIN_ENABLE_TESTING)
44
add_subdirectory(test)
55
endif()
6-
add_subdirectory(python_bindings)
6+
if (QT_VERSION_MAJOR EQUAL 5)
7+
add_subdirectory(python_bindings)
8+
endif()

src/rviz/default_plugin/depth_cloud_display.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
* POSSIBILITY OF SUCH DAMAGE.
2828
*/
2929
#include <QObject>
30+
#include <QRegularExpression>
3031

3132
#include "depth_cloud_display.h"
3233
#include <rviz/visualization_manager.h>
@@ -78,8 +79,7 @@ DepthCloudDisplay::DepthCloudDisplay()
7879

7980
{
8081
// Depth map properties
81-
QRegExp depth_filter("depth");
82-
depth_filter.setCaseSensitivity(Qt::CaseInsensitive);
82+
QRegularExpression depth_filter("depth", QRegularExpression::CaseInsensitiveOption);
8383

8484
topic_filter_property_ =
8585
new Property("Topic Filter", true,
@@ -100,8 +100,7 @@ DepthCloudDisplay::DepthCloudDisplay()
100100
depth_transport_property_->setStdString("raw");
101101

102102
// color image properties
103-
QRegExp color_filter("color|rgb|bgr|gray|mono");
104-
color_filter.setCaseSensitivity(Qt::CaseInsensitive);
103+
QRegularExpression color_filter("color|rgb|bgr|gray|mono", QRegularExpression::CaseInsensitiveOption);
105104

106105
color_topic_property_ = new RosFilteredTopicProperty(
107106
"Color Image Topic", "",

src/rviz/default_plugin/depth_cloud_display.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#endif
5555

5656
#include <QMap>
57+
#include <QtCore/QRegularExpression>
5758

5859
using namespace message_filters::sync_policies;
5960

@@ -81,7 +82,7 @@ class RosFilteredTopicProperty : public RosTopicProperty
8182
const QString& default_value = QString(),
8283
const QString& message_type = QString(),
8384
const QString& description = QString(),
84-
const QRegExp& filter = QRegExp(),
85+
const QRegularExpression& filter = QRegularExpression(),
8586
Property* parent = nullptr)
8687
: RosTopicProperty(name, default_value, message_type, description, parent)
8788
, filter_(filter)
@@ -94,7 +95,7 @@ class RosFilteredTopicProperty : public RosTopicProperty
9495
const QString& default_value,
9596
const QString& message_type,
9697
const QString& description,
97-
const QRegExp& filter,
98+
const QRegularExpression& filter,
9899
Property* parent,
99100
Func&& changed_slot,
100101
const R* receiver)
@@ -109,7 +110,7 @@ class RosFilteredTopicProperty : public RosTopicProperty
109110
const QString& default_value,
110111
const QString& message_type,
111112
const QString& description,
112-
const QRegExp& filter,
113+
const QRegularExpression& filter,
113114
P* parent,
114115
Func&& changed_slot)
115116
: RosFilteredTopicProperty(name, default_value, message_type, description, filter, parent)
@@ -124,7 +125,7 @@ class RosFilteredTopicProperty : public RosTopicProperty
124125
fillTopicList();
125126
}
126127

127-
QRegExp filter() const
128+
QRegularExpression filter() const
128129
{
129130
return filter_;
130131
}
@@ -142,7 +143,7 @@ protected Q_SLOTS:
142143
}
143144

144145
private:
145-
QRegExp filter_;
146+
QRegularExpression filter_;
146147
bool filter_enabled_;
147148
};
148149

src/rviz/properties/property_tree_model.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include <stdio.h>
3131

32+
#include <QIODevice>
3233
#include <QStringList>
3334
#include <QMimeData>
3435

src/rviz/tool_manager.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929

3030
#include <QKeyEvent>
31-
#include <QRegExp>
31+
#include <QRegularExpression>
3232

3333
#include <ros/assert.h>
3434

@@ -42,7 +42,7 @@ namespace rviz
4242
{
4343
QString addSpaceToCamelCase(QString input)
4444
{
45-
QRegExp re = QRegExp("([A-Z])([a-z]*)");
45+
QRegularExpression re = QRegularExpression("([A-Z])([a-z]*)");
4646
input.replace(re, " \\1\\2");
4747
return input.trimmed();
4848
}

src/rviz/viewport_mouse_event.h

+5
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,13 @@ class ViewportMouseEvent
5454
: panel(p)
5555
, viewport(vp)
5656
, type(e->type())
57+
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
58+
, x(e->position().x())
59+
, y(e->position().y())
60+
#else
5761
, x(e->x())
5862
, y(e->y())
63+
#endif
5964
, wheel_delta(0)
6065
, acting_button(e->button())
6166
, buttons_down(e->buttons())

src/rviz/visualization_frame.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <memory>
3232

3333
#include <QAction>
34+
#include <QActionGroup>
3435
#include <QShortcut>
3536
#include <QApplication>
3637
#include <QCoreApplication>
@@ -274,7 +275,7 @@ void VisualizationFrame::initialize(const QString& display_config_file)
274275
QWidget* central_widget = new QWidget(this);
275276
QHBoxLayout* central_layout = new QHBoxLayout;
276277
central_layout->setSpacing(0);
277-
central_layout->setMargin(0);
278+
central_layout->setContentsMargins(0, 0, 0, 0);
278279

279280
render_panel_ = new RenderPanel(central_widget);
280281

0 commit comments

Comments
 (0)