Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support both qt5 and qt6 #1187

Open
wants to merge 10 commits into
base: rolling
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions rviz2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,25 @@ find_package(rviz_common REQUIRED)

find_package(rviz_ogre_vendor REQUIRED)

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

execute_process(
COMMAND "${_qt5_qmake_location}" -query QT_INSTALL_PREFIX
COMMAND "${_qt_qmake_location}" -query QT${QT_VERSION_MAJOR}_INSTALL_PREFIX
RESULT_VARIABLE return_code
OUTPUT_VARIABLE qt5_install_prefix
OUTPUT_VARIABLE qt_install_prefix
OUTPUT_STRIP_TRAILING_WHITESPACE
)

set(imported_location "${qt5_install_prefix}/bin/windeployqt.exe")
set(imported_location "${qt_install_prefix}/bin/windeployqt.exe")

if(EXISTS ${imported_location})
add_executable(Qt5::windeployqt IMPORTED)
add_executable(Qt${QT_VERSION_MAJOR}::windeployqt IMPORTED)

set_target_properties(Qt5::windeployqt PROPERTIES
set_target_properties(Qt${QT_VERSION_MAJOR}::windeployqt PROPERTIES
IMPORTED_LOCATION ${imported_location}
)
endif()
Expand All @@ -48,21 +49,21 @@ target_link_libraries(${PROJECT_NAME}
rviz_common::rviz_common
rviz_ogre_vendor::OgreMain
rviz_ogre_vendor::OgreOverlay
Qt5::Widgets
Qt${QT_VERSION_MAJOR}::Widgets
)

# TODO(wjwwood): find a way to make this optional or to run without "deploying" the
# necessary dlls and stuff to the bin folder.
# see:
# https://stackoverflow.com/questions/41193584/deploy-all-qt-dependencies-when-building#41199492
if(TARGET Qt5::windeployqt)
if(TARGET Qt${QT_VERSION_MAJOR}::windeployqt)
# execute windeployqt in a tmp directory after build
add_custom_command(TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E remove_directory "${CMAKE_CURRENT_BINARY_DIR}/windeployqt"
COMMAND set PATH=%PATH%$<SEMICOLON>${qt5_install_prefix}/bin
COMMAND set PATH=%PATH%$<SEMICOLON>${qt_install_prefix}/bin
COMMAND
Qt5::windeployqt
Qt${QT_VERSION_MAJOR}::windeployqt
--dir "${CMAKE_CURRENT_BINARY_DIR}/windeployqt"
"$<TARGET_FILE_DIR:${PROJECT_NAME}>/$<TARGET_FILE_NAME:${PROJECT_NAME}>"
)
Expand Down
25 changes: 16 additions & 9 deletions rviz_common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ find_package(ament_cmake REQUIRED)
# do find_package(rviz_ogre_vendor) first to make sure the custom OGRE is found
find_package(rviz_ogre_vendor REQUIRED)

find_package(Qt5 REQUIRED COMPONENTS Widgets)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
if(${QT_VERSION} VERSION_LESS 5.15.0)
function(qt_wrap_cpp out)
qt5_wrap_cpp(_sources ${ARGN})
set("${out}" ${_sources} PARENT_SCOPE)
endfunction()
endif()

find_package(geometry_msgs REQUIRED)
find_package(pluginlib REQUIRED)
Expand Down Expand Up @@ -131,7 +138,7 @@ set(rviz_common_headers_to_moc
)

foreach(header "${rviz_common_headers_to_moc}")
qt5_wrap_cpp(rviz_common_moc_files "${header}")
qt_wrap_cpp(rviz_common_moc_files "${header}")
endforeach()

set(rviz_common_source_files
Expand Down Expand Up @@ -239,7 +246,7 @@ target_link_libraries(rviz_common PUBLIC
${geometry_msgs_TARGETS}
message_filters::message_filters
pluginlib::pluginlib
Qt5::Widgets
Qt${QT_VERSION_MAJOR}::Widgets
rclcpp::rclcpp
rviz_ogre_vendor::OgreMain
rviz_ogre_vendor::OgreOverlay
Expand All @@ -265,7 +272,7 @@ ament_export_dependencies(
geometry_msgs
message_filters
pluginlib
Qt5
Qt${QT_VERSION_MAJOR}
rclcpp
rviz_ogre_vendor
rviz_rendering
Expand Down Expand Up @@ -324,10 +331,10 @@ if(BUILD_TESTING)
find_package(ament_cmake_gmock REQUIRED)
find_package(ament_cmake_gtest REQUIRED)

qt5_wrap_cpp(rviz_common_test_moc_files test/mock_display.hpp)
qt5_wrap_cpp(rviz_common_test_moc_files test/mock_property_change_receiver.hpp)
qt_wrap_cpp(rviz_common_test_moc_files test/mock_display.hpp)
qt_wrap_cpp(rviz_common_test_moc_files test/mock_property_change_receiver.hpp)

qt5_wrap_cpp(rviz_common_test_frame_manager_moc src/rviz_common/frame_manager.hpp)
qt_wrap_cpp(rviz_common_test_frame_manager_moc src/rviz_common/frame_manager.hpp)

ament_add_gmock(display_factory_test
test/display_factory_test.cpp
Expand All @@ -336,7 +343,7 @@ if(BUILD_TESTING)
if(TARGET display_factory_test)
target_compile_definitions(display_factory_test PUBLIC
-D_TEST_PLUGIN_DESCRIPTIONS="${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(display_factory_test rviz_common Qt5::Widgets)
target_link_libraries(display_factory_test rviz_common Qt${QT_VERSION_MAJOR}::Widgets)
endif()

ament_add_gmock(frame_manager_test
Expand Down Expand Up @@ -445,7 +452,7 @@ if(BUILD_TESTING)
test/mock_property_change_receiver.cpp
${SKIP_DISPLAY_TESTS})
if(TARGET rviz_common_display_test)
target_link_libraries(rviz_common_display_test rviz_common Qt5::Widgets yaml-cpp::yaml-cpp)
target_link_libraries(rviz_common_display_test rviz_common Qt${QT_VERSION_MAJOR}::Widgets yaml-cpp::yaml-cpp)
endif()
endif()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

#include <string>

#include <QRegularExpression> // NOLINT: cpplint is unable to handle the include order here

#include "rviz_common/properties/editable_enum_property.hpp"
#include "rviz_common/ros_integration/ros_node_abstraction_iface.hpp"
#include "rviz_common/visibility_control.hpp"
Expand Down Expand Up @@ -89,20 +91,20 @@ class RVIZ_COMMON_PUBLIC RosFilteredTopicProperty
const QString & default_value = QString(),
const QString & message_type = QString(),
const QString & description = QString(),
const QRegExp & filter = QRegExp(),
const QRegularExpression & filter = QRegularExpression(),
Property * parent = 0,
const char * changed_slot = 0,
QObject * receiver = 0);

void enableFilter(bool enabled);

QRegExp filter() const;
QRegularExpression filter() const;

protected Q_SLOTS:
void fillTopicList() override;

private:
QRegExp filter_;
QRegularExpression filter_;
bool filter_enabled_;
};

Expand Down
3 changes: 2 additions & 1 deletion rviz_common/rviz_common-extras.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@

# find package Qt5 because otherwise using the rviz_common::rviz_common
# exported target will complain that the Qt5::Widgets target does not exist
find_package(Qt5 REQUIRED QUIET COMPONENTS Widgets)
find_package(QT NAMES Qt6 Qt5 QUIET COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} QUIET COMPONENTS Widgets)
3 changes: 2 additions & 1 deletion rviz_common/src/rviz_common/add_display_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <QLabel> // NOLINT: cpplint is unable to handle the include order here
#include <QLineEdit> // NOLINT: cpplint is unable to handle the include order here
#include <QPushButton> // NOLINT: cpplint is unable to handle the include order here
#include <QRegularExpression> // NOLINT: cpplint is unable to handle the include order here
#include <QTabWidget> // NOLINT: cpplint is unable to handle the include order here
#include <QTextBrowser> // NOLINT: cpplint is unable to handle the include order here
#include <QVBoxLayout> // NOLINT: cpplint is unable to handle the include order here
Expand Down Expand Up @@ -590,7 +591,7 @@ void TopicDisplayWidget::findPlugins(DisplayFactory * factory)
// For now, we assume that all types supported by plugins have the form
// "<pkg_name>/msg/<type_name>", though in the future zero or more namespaces may be
// permitted.
QRegExp delim("/");
QRegularExpression delim("/");
QStringList topic_type_parts = topic_type.split(delim);
if (topic_type_parts.size() == 2) {
topic_type = topic_type_parts.at(0) + "/msg/" + topic_type_parts.at(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include <cstdio>

#include <QIODevice> // NOLINT: cpplint is unable to handle the include order here
#include <QMimeData> // NOLINT: cpplint is unable to handle the include order here
#include <QStringList> // NOLINT: cpplint is unable to handle the include order here

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ RosFilteredTopicProperty::RosFilteredTopicProperty(
const QString & default_value,
const QString & message_type,
const QString & description,
const QRegExp & filter,
const QRegularExpression & filter,
Property * parent,
const char * changed_slot,
QObject * receiver)
Expand All @@ -110,7 +110,7 @@ void RosFilteredTopicProperty::enableFilter(bool enabled)
fillTopicList();
}

QRegExp RosFilteredTopicProperty::filter() const
QRegularExpression RosFilteredTopicProperty::filter() const
{
return filter_;
}
Expand Down
4 changes: 2 additions & 2 deletions rviz_common/src/rviz_common/tool_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

#include <QKeyEvent> // NOLINT: cpplint is unable to handle the include order here
#include <QKeySequence> // NOLINT: cpplint is unable to handle the include order here
#include <QRegExp> // NOLINT: cpplint is unable to handle the include order here
#include <QRegularExpression> // NOLINT: cpplint is unable to handle the include order here

#include "rviz_common/logging.hpp"

Expand All @@ -52,7 +52,7 @@ using rviz_common::properties::PropertyTreeModel;

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();
}
Expand Down
3 changes: 2 additions & 1 deletion rviz_common/src/rviz_common/visualization_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <OgreMeshManager.h>
#include <OgreMaterialManager.h>

#include <QActionGroup> // NOLINT cpplint cannot handle include order here
#include <QApplication> // NOLINT cpplint cannot handle include order here
#include <QCloseEvent> // NOLINT cpplint cannot handle include order here
#include <QDesktopServices> // NOLINT cpplint cannot handle include order here
Expand Down Expand Up @@ -262,7 +263,7 @@ void VisualizationFrame::initialize(
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);

Expand Down
Loading