Skip to content

Commit

Permalink
Qt6 migrations that are compatible with Qt5 (#598)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <mjcarroll@intrinsic.ai>
  • Loading branch information
mjcarroll authored Dec 8, 2023
1 parent 91b50b8 commit 4c86af8
Show file tree
Hide file tree
Showing 25 changed files with 247 additions and 355 deletions.
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,19 @@ set(GZ_TOOLS_VER 2)

#--------------------------------------
# Find QT
gz_find_package (Qt5
set(QT_MAJOR_VERSION 5)
set(QT_MINOR_VERSION 15)
gz_find_package (Qt${QT_MAJOR_VERSION}
VERSION ${QT_MAJOR_VERSION}.${QT_MINOR_VERSION}
COMPONENTS
Core
Quick
QuickControls2
Widgets
Test
REQUIRED
PKGCONFIG "Qt5Core Qt5Quick Qt5QuickControls2 Qt5Widgets"
)
PKGCONFIG "Qt${QT_MAJOR_VERSION}Core Qt${QT_MAJOR_VERSION}Quick Qt${QT_MAJOR_VERSION}QuickControls2 Qt${QT_MAJOR_VERSION}Widgets")
add_compile_definitions(QT_DISABLE_DEPRECATED_UP_TO=0x050F00)

set(GZ_GUI_PLUGIN_RELATIVE_INSTALL_DIR
${GZ_LIB_INSTALL_DIR}/gz-${GZ_DESIGNATION}-${PROJECT_VERSION_MAJOR}/plugins
Expand Down
10 changes: 2 additions & 8 deletions examples/plugin/custom_context_menu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ endif()
set (CMAKE_AUTOMOC ON)

# Find Qt5
find_package (Qt5
find_package (Qt5 5.15
COMPONENTS
Core
Quick
Expand All @@ -21,9 +21,7 @@ find_package (Qt5
find_package(gz-gui9 REQUIRED)
set(GZ_GUI_VER ${gz-gui9_VERSION_MAJOR})

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GZ-GUI_CXX_FLAGS}")

QT5_ADD_RESOURCES(resources_RCC CustomContext.qrc)
qt_add_resources(resources_RCC CustomContext.qrc)

# Generate examples
add_library(CustomContext SHARED ${headers_MOC}
Expand All @@ -32,8 +30,4 @@ add_library(CustomContext SHARED ${headers_MOC}
)
target_link_libraries(CustomContext
gz-gui${GZ_GUI_VER}::gz-gui${GZ_GUI_VER}
${Qt5Core_LIBRARIES}
${Qt5Qml_LIBRARIES}
${Qt5Quick_LIBRARIES}
${Qt5QuickControls2_LIBRARIES}
)
9 changes: 1 addition & 8 deletions examples/plugin/dialog_from_plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ endif()

set (CMAKE_AUTOMOC ON)

# Find Qt5
find_package (Qt5
COMPONENTS
Core
Expand All @@ -21,9 +20,7 @@ find_package (Qt5
find_package(gz-gui9 REQUIRED)
set(GZ_GUI_VER ${gz-gui9_VERSION_MAJOR})

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GZ-GUI_CXX_FLAGS}")

QT5_ADD_RESOURCES(resources_RCC DialogFromPlugin.qrc)
qt_add_resources(resources_RCC DialogFromPlugin.qrc)

# Generate examples
add_library(DialogFromPlugin SHARED ${headers_MOC}
Expand All @@ -32,8 +29,4 @@ add_library(DialogFromPlugin SHARED ${headers_MOC}
)
target_link_libraries(DialogFromPlugin
gz-gui${GZ_GUI_VER}::gz-gui${GZ_GUI_VER}
${Qt5Core_LIBRARIES}
${Qt5Qml_LIBRARIES}
${Qt5Quick_LIBRARIES}
${Qt5QuickControls2_LIBRARIES}
)
8 changes: 2 additions & 6 deletions examples/plugin/gz_components/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ endif()

set (CMAKE_AUTOMOC ON)

find_package (Qt5
find_package (Qt5 5.15
COMPONENTS
Core
Quick
Expand All @@ -21,7 +21,7 @@ set(GZ_GUI_VER ${gz-gui9_VERSION_MAJOR})

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GZ-GUI_CXX_FLAGS}")

QT5_ADD_RESOURCES(resources_RCC GzComponents.qrc)
qt_add_resources(resources_RCC GzComponents.qrc)

# Generate examples
add_library(GzComponents SHARED ${headers_MOC}
Expand All @@ -30,8 +30,4 @@ add_library(GzComponents SHARED ${headers_MOC}
)
target_link_libraries(GzComponents
gz-gui${GZ_GUI_VER}::gz-gui${GZ_GUI_VER}
${Qt5Core_LIBRARIES}
${Qt5Qml_LIBRARIES}
${Qt5Quick_LIBRARIES}
${Qt5QuickControls2_LIBRARIES}
)
11 changes: 2 additions & 9 deletions examples/plugin/hello_plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ endif()

set (CMAKE_AUTOMOC ON)

# Find Qt5
find_package (Qt5
find_package (Qt5 5.15
COMPONENTS
Core
Quick
Expand All @@ -21,9 +20,7 @@ find_package (Qt5
find_package(gz-gui9 REQUIRED)
set(GZ_GUI_VER ${gz-gui9_VERSION_MAJOR})

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GZ-GUI_CXX_FLAGS}")

QT5_ADD_RESOURCES(resources_RCC hello.qrc)
qt_add_resources(resources_RCC hello.qrc)

# Generate examples
add_library(HelloPlugin SHARED ${headers_MOC}
Expand All @@ -32,8 +29,4 @@ add_library(HelloPlugin SHARED ${headers_MOC}
)
target_link_libraries(HelloPlugin
gz-gui${GZ_GUI_VER}::gz-gui${GZ_GUI_VER}
${Qt5Core_LIBRARIES}
${Qt5Qml_LIBRARIES}
${Qt5Quick_LIBRARIES}
${Qt5QuickControls2_LIBRARIES}
)
7 changes: 1 addition & 6 deletions examples/plugin/multiple_qml/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ endif()

set (CMAKE_AUTOMOC ON)

# Find Qt5
find_package (Qt5
COMPONENTS
Core
Expand All @@ -23,7 +22,7 @@ set(GZ_GUI_VER ${gz-gui9_VERSION_MAJOR})

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GZ-GUI_CXX_FLAGS}")

QT5_ADD_RESOURCES(resources_RCC MultipleQml.qrc)
qt_add_resources(resources_RCC MultipleQml.qrc)

# Generate examples
add_library(MultipleQml SHARED ${headers_MOC}
Expand All @@ -32,8 +31,4 @@ add_library(MultipleQml SHARED ${headers_MOC}
)
target_link_libraries(MultipleQml
gz-gui${GZ_GUI_VER}::gz-gui${GZ_GUI_VER}
${Qt5Core_LIBRARIES}
${Qt5Qml_LIBRARIES}
${Qt5Quick_LIBRARIES}
${Qt5QuickControls2_LIBRARIES}
)
8 changes: 1 addition & 7 deletions examples/standalone/custom_drawer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ find_package (Qt5
find_package(gz-gui9 REQUIRED)
set(GZ_GUI_VER ${gz-gui9_VERSION_MAJOR})

QT5_ADD_RESOURCES(resources_RCC custom_drawer.qrc)

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GZ-GUI_CXX_FLAGS}")
qt_add_resources(resources_RCC custom_drawer.qrc)

# Generate example
add_executable(custom_drawer
Expand All @@ -32,8 +30,4 @@ add_executable(custom_drawer
)
target_link_libraries(custom_drawer
gz-gui${GZ_GUI_VER}::gz-gui${GZ_GUI_VER}
${Qt5Core_LIBRARIES}
${Qt5Qml_LIBRARIES}
${Qt5Quick_LIBRARIES}
${Qt5QuickControls2_LIBRARIES}
)
10 changes: 1 addition & 9 deletions examples/standalone/dialogs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ endif()

set (CMAKE_AUTOMOC ON)

# Find Qt5
find_package (Qt5
find_package (Qt5 5.15
COMPONENTS
Core
Quick
Expand All @@ -21,17 +20,10 @@ find_package (Qt5
find_package(gz-gui9 REQUIRED)
set(GZ_GUI_VER ${gz-gui9_VERSION_MAJOR})

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GZ-GUI_CXX_FLAGS}")

# Generate example
add_executable(dialogs
dialogs.cc
)
target_link_libraries(dialogs
gz-gui${GZ_GUI_VER}::gz-gui${GZ_GUI_VER}
${Qt5Core_LIBRARIES}
${Qt5Qml_LIBRARIES}
${Qt5Quick_LIBRARIES}
${Qt5QuickControls2_LIBRARIES}
)

7 changes: 1 addition & 6 deletions examples/standalone/window/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ endif()
set (CMAKE_AUTOMOC ON)

# Find Qt5
find_package (Qt5
find_package (Qt5 5.15
COMPONENTS
Core
Quick
Expand All @@ -29,9 +29,4 @@ add_executable(window
)
target_link_libraries(window
gz-gui${GZ_GUI_VER}::gz-gui${GZ_GUI_VER}
${Qt5Core_LIBRARIES}
${Qt5Qml_LIBRARIES}
${Qt5Quick_LIBRARIES}
${Qt5QuickControls2_LIBRARIES}
)

32 changes: 7 additions & 25 deletions include/gz/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,9 @@
include_directories(
${Qt5Core_INCLUDE_DIRS}
${tinyxml_INCLUDE_DIRS}
${Qt5Qml_INCLUDE_DIRS}
${Qt5Quick_INCLUDE_DIRS}
${Qt5QuickControls2_INCLUDE_DIRS}
${Qt5Widgets_INCLUDE_DIRS}
)

if(POLICY CMP0100)
cmake_policy(SET CMP0100 NEW)
endif()

set (CMAKE_AUTOMOC ON)

add_definitions(
${Qt5Core_DEFINITIONS}
${Qt5Qml_DEFINITIONS}
${Qt5Quick_DEFINITIONS}
${Qt5QuickControls2_DEFINITIONS}
${Qt5Widgets_DEFINITIONS}
)

set (qt_headers
Application.hh
Dialog.hh
Expand All @@ -42,8 +25,8 @@ set (headers

set (resources resources.qrc)

QT5_WRAP_CPP(headers_MOC ${qt_headers})
QT5_ADD_RESOURCES(resources_RCC ${resources})
qt_wrap_cpp(headers_MOC ${qt_headers})
qt_add_resources(resources_RCC ${resources})

gz_create_core_library(SOURCES
${sources}
Expand All @@ -67,13 +50,12 @@ target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME}
gz-msgs${GZ_MSGS_VER}::gz-msgs${GZ_MSGS_VER}
gz-plugin${GZ_PLUGIN_VER}::loader
gz-transport${GZ_TRANSPORT_VER}::gz-transport${GZ_TRANSPORT_VER}
${Qt5Core_LIBRARIES}
${Qt5Qml_LIBRARIES}
${Qt5Quick_LIBRARIES}
${Qt5QuickControls2_LIBRARIES}
${Qt5Widgets_LIBRARIES}
Qt::Core
Qt::Qml
Qt::Quick
Qt::QuickControls2
Qt::Widgets
TINYXML2::TINYXML2
)

gz_install_all_headers()

12 changes: 10 additions & 2 deletions src/Application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*
*/

#include <qsgrendererinterface.h>
#include <tinyxml2.h>
#include <queue>

Expand Down Expand Up @@ -126,7 +127,12 @@ Application::Application(int &_argc, char **_argv, const WindowType _type,
{
// Use the Metal graphics API on macOS.
gzdbg << "Qt using Metal graphics interface" << std::endl;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QQuickWindow::setGraphicsApi(QSGRendererInterface::MetalRhi);
#else
QQuickWindow::setSceneGraphBackend(QSGRendererInterface::MetalRhi);
#endif

}

// TODO(srmainwaring): implement facility for overriding the default
Expand Down Expand Up @@ -161,9 +167,11 @@ Application::Application(int &_argc, char **_argv, const WindowType _type,
# endif
);

# if QT_VERSION >= QT_VERSION_CHECK(5, 15, 2) && QT_CONFIG(vulkan)
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QQuickWindow::setGraphicsApi(QSGRendererInterface::VulkanRhi);
#else
QQuickWindow::setSceneGraphBackend(QSGRendererInterface::VulkanRhi);
# endif
#endif
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ gz_build_tests(TYPE UNIT
TINYXML2::TINYXML2
TEST_LIST
gtest_targets
ENVIRONMENT
ENVIRONMENT
GZ_GUI_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
)

Expand Down
4 changes: 0 additions & 4 deletions src/Conversions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,7 @@ gz::common::MouseEvent convert(const QWheelEvent &_e)
common::MouseEvent event;

event.SetType(common::MouseEvent::SCROLL);
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
event.SetPos(_e.x(), _e.y());
#else
event.SetPos(_e.position().x(), _e.position().y());
#endif
double scroll = (_e.angleDelta().y() > 0) ? -1.0 : 1.0;
event.SetScroll(scroll, scroll);

Expand Down
Loading

0 comments on commit 4c86af8

Please sign in to comment.