Skip to content

Commit 4330161

Browse files
authored
feat: support both qt5 and qt6 (#1187)
Signed-off-by: wep21 <[email protected]> Signed-off-by: Daisuke Nishimatsu <[email protected]>
1 parent 5722e51 commit 4330161

File tree

16 files changed

+172
-105
lines changed

16 files changed

+172
-105
lines changed

rviz2/CMakeLists.txt

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,25 @@ find_package(rviz_common REQUIRED)
1818

1919
find_package(rviz_ogre_vendor REQUIRED)
2020

21-
find_package(Qt5 REQUIRED COMPONENTS Widgets)
21+
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
22+
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
2223
# TODO(wjwwood): this block is to setup the windeployqt tool, could be removed later.
23-
if(Qt5_FOUND AND WIN32 AND TARGET Qt5::qmake AND NOT TARGET Qt5::windeployqt)
24-
get_target_property(_qt5_qmake_location Qt5::qmake IMPORTED_LOCATION)
24+
if(Qt${QT_VERSION_MAJOR}_FOUND AND WIN32 AND TARGET Qt${QT_VERSION_MAJOR}::qmake AND NOT TARGET Qt${QT_VERSION_MAJOR}::windeployqt)
25+
get_target_property(_qt_qmake_location Qt${QT_VERSION_MAJOR}::qmake IMPORTED_LOCATION)
2526

2627
execute_process(
27-
COMMAND "${_qt5_qmake_location}" -query QT_INSTALL_PREFIX
28+
COMMAND "${_qt_qmake_location}" -query QT${QT_VERSION_MAJOR}_INSTALL_PREFIX
2829
RESULT_VARIABLE return_code
29-
OUTPUT_VARIABLE qt5_install_prefix
30+
OUTPUT_VARIABLE qt_install_prefix
3031
OUTPUT_STRIP_TRAILING_WHITESPACE
3132
)
3233

33-
set(imported_location "${qt5_install_prefix}/bin/windeployqt.exe")
34+
set(imported_location "${qt_install_prefix}/bin/windeployqt.exe")
3435

3536
if(EXISTS ${imported_location})
36-
add_executable(Qt5::windeployqt IMPORTED)
37+
add_executable(Qt${QT_VERSION_MAJOR}::windeployqt IMPORTED)
3738

38-
set_target_properties(Qt5::windeployqt PROPERTIES
39+
set_target_properties(Qt${QT_VERSION_MAJOR}::windeployqt PROPERTIES
3940
IMPORTED_LOCATION ${imported_location}
4041
)
4142
endif()
@@ -48,21 +49,21 @@ target_link_libraries(${PROJECT_NAME}
4849
rviz_common::rviz_common
4950
rviz_ogre_vendor::OgreMain
5051
rviz_ogre_vendor::OgreOverlay
51-
Qt5::Widgets
52+
Qt${QT_VERSION_MAJOR}::Widgets
5253
)
5354

5455
# TODO(wjwwood): find a way to make this optional or to run without "deploying" the
5556
# necessary dlls and stuff to the bin folder.
5657
# see:
5758
# https://stackoverflow.com/questions/41193584/deploy-all-qt-dependencies-when-building#41199492
58-
if(TARGET Qt5::windeployqt)
59+
if(TARGET Qt${QT_VERSION_MAJOR}::windeployqt)
5960
# execute windeployqt in a tmp directory after build
6061
add_custom_command(TARGET ${PROJECT_NAME}
6162
POST_BUILD
6263
COMMAND ${CMAKE_COMMAND} -E remove_directory "${CMAKE_CURRENT_BINARY_DIR}/windeployqt"
63-
COMMAND set PATH=%PATH%$<SEMICOLON>${qt5_install_prefix}/bin
64+
COMMAND set PATH=%PATH%$<SEMICOLON>${qt_install_prefix}/bin
6465
COMMAND
65-
Qt5::windeployqt
66+
Qt${QT_VERSION_MAJOR}::windeployqt
6667
--dir "${CMAKE_CURRENT_BINARY_DIR}/windeployqt"
6768
"$<TARGET_FILE_DIR:${PROJECT_NAME}>/$<TARGET_FILE_NAME:${PROJECT_NAME}>"
6869
)

rviz_common/CMakeLists.txt

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,14 @@ find_package(ament_cmake REQUIRED)
3131
# do find_package(rviz_ogre_vendor) first to make sure the custom OGRE is found
3232
find_package(rviz_ogre_vendor REQUIRED)
3333

34-
find_package(Qt5 REQUIRED COMPONENTS Widgets)
34+
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
35+
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
36+
if(${QT_VERSION} VERSION_LESS 5.15.0)
37+
function(qt_wrap_cpp out)
38+
qt5_wrap_cpp(_sources ${ARGN})
39+
set("${out}" ${_sources} PARENT_SCOPE)
40+
endfunction()
41+
endif()
3542

3643
find_package(geometry_msgs REQUIRED)
3744
find_package(pluginlib REQUIRED)
@@ -132,7 +139,7 @@ set(rviz_common_headers_to_moc
132139
)
133140

134141
foreach(header "${rviz_common_headers_to_moc}")
135-
qt5_wrap_cpp(rviz_common_moc_files "${header}")
142+
qt_wrap_cpp(rviz_common_moc_files "${header}")
136143
endforeach()
137144

138145
set(rviz_common_source_files
@@ -240,7 +247,7 @@ target_link_libraries(rviz_common PUBLIC
240247
${geometry_msgs_TARGETS}
241248
message_filters::message_filters
242249
pluginlib::pluginlib
243-
Qt5::Widgets
250+
Qt${QT_VERSION_MAJOR}::Widgets
244251
rclcpp::rclcpp
245252
rviz_ogre_vendor::OgreMain
246253
rviz_ogre_vendor::OgreOverlay
@@ -266,7 +273,7 @@ ament_export_dependencies(
266273
geometry_msgs
267274
message_filters
268275
pluginlib
269-
Qt5
276+
Qt${QT_VERSION_MAJOR}
270277
rclcpp
271278
rviz_ogre_vendor
272279
rviz_rendering
@@ -325,10 +332,10 @@ if(BUILD_TESTING)
325332
find_package(ament_cmake_gmock REQUIRED)
326333
find_package(ament_cmake_gtest REQUIRED)
327334

328-
qt5_wrap_cpp(rviz_common_test_moc_files test/mock_display.hpp)
329-
qt5_wrap_cpp(rviz_common_test_moc_files test/mock_property_change_receiver.hpp)
335+
qt_wrap_cpp(rviz_common_test_moc_files test/mock_display.hpp)
336+
qt_wrap_cpp(rviz_common_test_moc_files test/mock_property_change_receiver.hpp)
330337

331-
qt5_wrap_cpp(rviz_common_test_frame_manager_moc src/rviz_common/frame_manager.hpp)
338+
qt_wrap_cpp(rviz_common_test_frame_manager_moc src/rviz_common/frame_manager.hpp)
332339

333340
ament_add_gmock(display_factory_test
334341
test/display_factory_test.cpp
@@ -337,7 +344,7 @@ if(BUILD_TESTING)
337344
if(TARGET display_factory_test)
338345
target_compile_definitions(display_factory_test PUBLIC
339346
-D_TEST_PLUGIN_DESCRIPTIONS="${CMAKE_CURRENT_SOURCE_DIR}")
340-
target_link_libraries(display_factory_test rviz_common Qt5::Widgets)
347+
target_link_libraries(display_factory_test rviz_common Qt${QT_VERSION_MAJOR}::Widgets)
341348
endif()
342349

343350
ament_add_gmock(frame_manager_test
@@ -446,7 +453,7 @@ if(BUILD_TESTING)
446453
test/mock_property_change_receiver.cpp
447454
${SKIP_DISPLAY_TESTS})
448455
if(TARGET rviz_common_display_test)
449-
target_link_libraries(rviz_common_display_test rviz_common Qt5::Widgets yaml-cpp::yaml-cpp)
456+
target_link_libraries(rviz_common_display_test rviz_common Qt${QT_VERSION_MAJOR}::Widgets yaml-cpp::yaml-cpp)
450457
endif()
451458
endif()
452459

rviz_common/include/rviz_common/properties/ros_topic_property.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include <string>
3434

35+
#include <QRegularExpression> // NOLINT: cpplint is unable to handle the include order here
3536
#include <QString> // NOLINT: cpplint is unable to handle the include order here
3637

3738
#include "rviz_common/properties/editable_enum_property.hpp"
@@ -92,20 +93,20 @@ class RVIZ_COMMON_PUBLIC RosFilteredTopicProperty
9293
const QString & default_value = QString(),
9394
const QString & message_type = QString(),
9495
const QString & description = QString(),
95-
const QRegExp & filter = QRegExp(),
96+
const QRegularExpression & filter = QRegularExpression(),
9697
Property * parent = 0,
9798
const char * changed_slot = 0,
9899
QObject * receiver = 0);
99100

100101
void enableFilter(bool enabled);
101102

102-
QRegExp filter() const;
103+
QRegularExpression filter() const;
103104

104105
protected Q_SLOTS:
105106
void fillTopicList() override;
106107

107108
private:
108-
QRegExp filter_;
109+
QRegularExpression filter_;
109110
bool filter_enabled_;
110111
};
111112

rviz_common/rviz_common-extras.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@
3030

3131
# find package Qt5 because otherwise using the rviz_common::rviz_common
3232
# exported target will complain that the Qt5::Widgets target does not exist
33-
find_package(Qt5 REQUIRED QUIET COMPONENTS Widgets)
33+
find_package(QT NAMES Qt6 Qt5 QUIET COMPONENTS Widgets)
34+
find_package(Qt${QT_VERSION_MAJOR} QUIET COMPONENTS Widgets)

rviz_common/src/rviz_common/add_display_dialog.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include <QLabel> // NOLINT: cpplint is unable to handle the include order here
4848
#include <QLineEdit> // NOLINT: cpplint is unable to handle the include order here
4949
#include <QPushButton> // NOLINT: cpplint is unable to handle the include order here
50+
#include <QRegularExpression> // NOLINT: cpplint is unable to handle the include order here
5051
#include <QString> // NOLINT: cpplint is unable to handle the include order here
5152
#include <QTabWidget> // NOLINT: cpplint is unable to handle the include order here
5253
#include <QTextBrowser> // NOLINT: cpplint is unable to handle the include order here
@@ -592,7 +593,7 @@ void TopicDisplayWidget::findPlugins(DisplayFactory * factory)
592593
// For now, we assume that all types supported by plugins have the form
593594
// "<pkg_name>/msg/<type_name>", though in the future zero or more namespaces may be
594595
// permitted.
595-
QRegExp delim("/");
596+
QRegularExpression delim("/");
596597
QStringList topic_type_parts = topic_type.split(delim);
597598
if (topic_type_parts.size() == 2) {
598599
topic_type = topic_type_parts.at(0) + "/msg/" + topic_type_parts.at(1);

rviz_common/src/rviz_common/properties/property_tree_model.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
#include <cstdio>
3535

36+
#include <QIODevice> // NOLINT: cpplint is unable to handle the include order here
3637
#include <QMimeData> // NOLINT: cpplint is unable to handle the include order here
3738
#include <QString> // NOLINT: cpplint is unable to handle the include order here
3839
#include <QStringList> // NOLINT: cpplint is unable to handle the include order here

rviz_common/src/rviz_common/properties/ros_topic_property.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ RosFilteredTopicProperty::RosFilteredTopicProperty(
9696
const QString & default_value,
9797
const QString & message_type,
9898
const QString & description,
99-
const QRegExp & filter,
99+
const QRegularExpression & filter,
100100
Property * parent,
101101
const char * changed_slot,
102102
QObject * receiver)
@@ -112,7 +112,7 @@ void RosFilteredTopicProperty::enableFilter(bool enabled)
112112
fillTopicList();
113113
}
114114

115-
QRegExp RosFilteredTopicProperty::filter() const
115+
QRegularExpression RosFilteredTopicProperty::filter() const
116116
{
117117
return filter_;
118118
}

rviz_common/src/rviz_common/tool_manager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
#include <QKeyEvent> // NOLINT: cpplint is unable to handle the include order here
3838
#include <QKeySequence> // NOLINT: cpplint is unable to handle the include order here
39-
#include <QRegExp> // NOLINT: cpplint is unable to handle the include order here
39+
#include <QRegularExpression> // NOLINT: cpplint is unable to handle the include order here
4040
#include <QString> // NOLINT: cpplint is unable to handle the include order here
4141

4242
#include "rviz_common/logging.hpp"
@@ -54,7 +54,7 @@ using rviz_common::properties::PropertyTreeModel;
5454

5555
QString addSpaceToCamelCase(QString input)
5656
{
57-
QRegExp re = QRegExp("([A-Z])([a-z]*)");
57+
QRegularExpression re = QRegularExpression("([A-Z])([a-z]*)");
5858
input.replace(re, " \\1\\2");
5959
return input.trimmed();
6060
}

rviz_common/src/rviz_common/visualization_frame.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <OgreMeshManager.h>
4444
#include <OgreMaterialManager.h>
4545

46+
#include <QActionGroup> // NOLINT cpplint cannot handle include order here
4647
#include <QApplication> // NOLINT cpplint cannot handle include order here
4748
#include <QCloseEvent> // NOLINT cpplint cannot handle include order here
4849
#include <QDesktopServices> // NOLINT cpplint cannot handle include order here
@@ -264,7 +265,7 @@ void VisualizationFrame::initialize(
264265
QWidget * central_widget = new QWidget(this);
265266
QHBoxLayout * central_layout = new QHBoxLayout;
266267
central_layout->setSpacing(0);
267-
central_layout->setMargin(0);
268+
central_layout->setContentsMargins(0, 0, 0, 0);
268269

269270
render_panel_ = new RenderPanel(central_widget);
270271

0 commit comments

Comments
 (0)