Skip to content

Commit

Permalink
Enable Qt6 compatibility (#1813)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
simonschmeisser and rhaschke authored Feb 2, 2024
1 parent b466cb9 commit fc75912
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
#
Expand Down
11 changes: 9 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,31 @@ 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
CACHE_PREFIX: ${{ matrix.distro }}
# 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
Expand Down
20 changes: 16 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,29 @@ 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()
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
Expand Down
4 changes: 3 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
7 changes: 3 additions & 4 deletions src/rviz/default_plugin/depth_cloud_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <QObject>
#include <QRegularExpression>

#include "depth_cloud_display.h"
#include <rviz/visualization_manager.h>
Expand Down Expand Up @@ -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,
Expand All @@ -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", "",
Expand Down
11 changes: 6 additions & 5 deletions src/rviz/default_plugin/depth_cloud_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#endif

#include <QMap>
#include <QtCore/QRegularExpression>

using namespace message_filters::sync_policies;

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -124,7 +125,7 @@ class RosFilteredTopicProperty : public RosTopicProperty
fillTopicList();
}

QRegExp filter() const
QRegularExpression filter() const
{
return filter_;
}
Expand All @@ -142,7 +143,7 @@ protected Q_SLOTS:
}

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

Expand Down
1 change: 1 addition & 0 deletions src/rviz/properties/property_tree_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include <stdio.h>

#include <QIODevice>
#include <QStringList>
#include <QMimeData>

Expand Down
4 changes: 2 additions & 2 deletions src/rviz/tool_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/

#include <QKeyEvent>
#include <QRegExp>
#include <QRegularExpression>

#include <ros/assert.h>

Expand All @@ -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();
}
Expand Down
5 changes: 5 additions & 0 deletions src/rviz/viewport_mouse_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
3 changes: 2 additions & 1 deletion src/rviz/visualization_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <memory>

#include <QAction>
#include <QActionGroup>
#include <QShortcut>
#include <QApplication>
#include <QCoreApplication>
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit fc75912

Please sign in to comment.