Skip to content

Commit

Permalink
Support Qt6
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Hernández Cordero <[email protected]>
  • Loading branch information
ahcorde committed Jul 3, 2024
1 parent 9a3e552 commit 978dce2
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 37 deletions.
28 changes: 21 additions & 7 deletions qt_gui_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ endif()

find_package(ament_cmake REQUIRED)

# set(CMAKE_SKIP_BUILD_RPATH FALSE)
# set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
# set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

if(WIN32)
message(STATUS "${PROJECT_NAME} is not yet supported on Windows. Package will not be built.")
ament_package()
Expand All @@ -20,7 +28,8 @@ if(WIN32)
endif()

find_package(pluginlib REQUIRED)
find_package(Qt5 REQUIRED COMPONENTS Widgets)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Core)
find_package(tinyxml2_vendor REQUIRED)
find_package(TinyXML2 REQUIRED)

Expand All @@ -44,7 +53,12 @@ set(qt_gui_cpp_HDRS
include/qt_gui_cpp/plugin_context.h
)

qt5_wrap_cpp(qt_gui_cpp_MOCS ${qt_gui_cpp_HDRS})
if (${QT_VERSION_MAJOR} GREATER "5")
qt_standard_project_setup()
qt_wrap_cpp(turtlesim_node_MOCS ${qt_gui_cpp_HDRS})
else()
qt5_wrap_cpp(turtlesim_node_MOCS ${qt_gui_cpp_HDRS})
endif()

add_library(${PROJECT_NAME} SHARED ${qt_gui_cpp_SRCS} ${qt_gui_cpp_MOCS})
target_include_directories(${PROJECT_NAME} PUBLIC
Expand All @@ -54,17 +68,17 @@ target_include_directories(${PROJECT_NAME} PUBLIC
target_link_libraries(${PROJECT_NAME}
${QT_QTCORE_LIBRARY}
${QT_QTGUI_LIBRARY}
Qt5::Widgets
Qt${QT_VERSION_MAJOR}::Widgets
pluginlib::pluginlib
tinyxml2::tinyxml2)

add_subdirectory(src/qt_gui_cpp_shiboken)
add_subdirectory(src/qt_gui_cpp_sip)

message(STATUS "Python binding generators: ${qt_gui_cpp_BINDINGS}")
if(NOT qt_gui_cpp_BINDINGS)
message(FATAL_ERROR "No Python binding generator found.")
endif()
# message(STATUS "Python binding generators: ${qt_gui_cpp_BINDINGS}")
# if(NOT qt_gui_cpp_BINDINGS)
# message(FATAL_ERROR "No Python binding generator found.")
# endif()

install(FILES plugin.xml
DESTINATION share/${PROJECT_NAME})
Expand Down
4 changes: 2 additions & 2 deletions qt_gui_cpp/include/qt_gui_cpp/plugin_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include "plugin_descriptor.h"

#include <QList>
#include <QMap>
#include <QMultiMap>
#include <QString>

namespace qt_gui_cpp
Expand All @@ -53,7 +53,7 @@ class PluginProvider

virtual ~PluginProvider();

virtual QMap<QString, QString> discover(QObject* discovery_data);
virtual QMultiMap<QString, QString> discover(QObject* discovery_data);

/**
* @attention Ownership of returned PluginDescriptor's is transfered to the caller
Expand Down
2 changes: 1 addition & 1 deletion qt_gui_cpp/include/qt_gui_cpp/recursive_plugin_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class RecursivePluginProvider

virtual ~RecursivePluginProvider();

virtual QMap<QString, QString> discover(QObject* discovery_data);
virtual QMultiMap<QString, QString> discover(QObject* discovery_data);

virtual void shutdown();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class RosPluginlibPluginProvider
}
}

virtual QMap<QString, QString> discover(QObject* discovery_data)
virtual QMultiMap<QString, QString> discover(QObject* discovery_data)
{
return PluginProvider::discover(discovery_data);
}
Expand Down
8 changes: 4 additions & 4 deletions qt_gui_cpp/src/qt_gui_cpp/plugin_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,25 @@ const QStringList& PluginContext::argv() const

void PluginContext::addWidget(QWidget* widget)
{
bool rc = proxy_.invokeMethod("add_widget", Q_ARG(QWidget*, widget));
bool rc = QMetaObject::invokeMethod(proxy_.proxiedObject(), "add_widget", Qt::DirectConnection, Q_ARG(QWidget*, widget));
if (!rc) throw std::runtime_error("PluginContext::addWidget() invoke method failed");
}

void PluginContext::removeWidget(QWidget* widget)
{
bool rc = proxy_.invokeMethod("remove_widget", Q_ARG(QWidget*, widget));
bool rc = QMetaObject::invokeMethod(proxy_.proxiedObject(), "remove_widget", Qt::DirectConnection, Q_ARG(QWidget*, widget));
if (!rc) throw std::runtime_error("PluginContext::removeWidget() invoke method failed");
}

void PluginContext::closePlugin()
{
bool rc = proxy_.invokeMethod("close_plugin");
bool rc = QMetaObject::invokeMethod(proxy_.proxiedObject(), "close_plugin", Qt::DirectConnection);
if (!rc) throw std::runtime_error("PluginContext::closePlugin() invoke method failed");
}

void PluginContext::reloadPlugin()
{
bool rc = proxy_.invokeMethod("reload_plugin");
bool rc = QMetaObject::invokeMethod(proxy_.proxiedObject(), "reload_plugin", Qt::DirectConnection);
if (!rc) throw std::runtime_error("PluginContext::reloadPlugin() invoke method failed");
}

Expand Down
9 changes: 6 additions & 3 deletions qt_gui_cpp/src/qt_gui_cpp/plugin_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,19 @@ PluginProvider::PluginProvider()
PluginProvider::~PluginProvider()
{}

QMap<QString, QString> PluginProvider::discover(QObject* discovery_data)
QMultiMap<QString, QString> PluginProvider::discover(QObject* discovery_data)
{
QMultiMap<QString, QString> plugins;
QList<PluginDescriptor*> descriptors = discover_descriptors(discovery_data);
for (QList<PluginDescriptor*>::iterator it = descriptors.begin(); it != descriptors.end(); it++)
{
// extract plugin descriptor dictionary
PluginDescriptor* descriptor = *it;
QMap<QString, QString> plugin = descriptor->toDictionary();
plugins.unite(plugin);
QMap descriptorValue = descriptor->toDictionary();
QMultiMap<QString, QString> plugin;
for (auto i = descriptorValue.cbegin(), end = descriptorValue.cend(); i != end; ++i) {
plugin.insert(i.key(), i.value());
}
delete descriptor;
}
return plugins;
Expand Down
2 changes: 1 addition & 1 deletion qt_gui_cpp/src/qt_gui_cpp/recursive_plugin_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ RecursivePluginProvider::~RecursivePluginProvider()
delete plugin_provider_;
}

QMap<QString, QString> RecursivePluginProvider::discover(QObject* discovery_data)
QMultiMap<QString, QString> RecursivePluginProvider::discover(QObject* discovery_data)
{
// discover plugins, which are providers themselves
QList<PluginDescriptor*> descriptors = plugin_provider_->discover_descriptors(discovery_data);
Expand Down
28 changes: 20 additions & 8 deletions qt_gui_cpp/src/qt_gui_cpp/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,59 +43,71 @@ Settings::Settings(QObject* obj)
Settings Settings::getSettings(const QString& prefix)
{
Settings settings(proxy_.proxiedObject());
bool rc = proxy_.invokeMethodWithReturn("get_settings", Q_RETURN_ARG(Settings, settings), Q_ARG(QString, prefix));
bool rc = QMetaObject::invokeMethod(proxy_.proxiedObject(), "get_settings", Qt::DirectConnection, Q_RETURN_ARG(Settings, settings), Q_ARG(QString, prefix));
// bool rc = proxy_.invokeMethodWithReturn("get_settings", Q_RETURN_ARG(Settings, settings), Q_ARG(QString, prefix));
if (!rc) throw std::runtime_error("Settings::get_settings() invoke method failed");
return settings;
}

QStringList Settings::allKeys() const
{
QStringList list;
bool rc = const_cast<Settings*>(this)->proxy_.invokeMethodWithReturn("all_keys", Q_RETURN_ARG(QStringList, list));
bool rc;

// bool rc = QMetaObject::invokeMethod(proxy_.proxiedObject(), "all_keys", Qt::DirectConnection, Q_RETURN_ARG(QStringList, list));
// bool rc = const_cast<Settings*>(this)->proxy_.invokeMethodWithReturn("all_keys", Q_RETURN_ARG(QStringList, list));
if (!rc) throw std::runtime_error("Settings::all_keys() invoke method failed");
return list;
}

QStringList Settings::childGroups() const
{
QStringList list;
bool rc = const_cast<Settings*>(this)->proxy_.invokeMethodWithReturn("child_groups", Q_RETURN_ARG(QStringList, list));
bool rc;
// bool rc = const_cast<Settings*>(this)->proxy_.invokeMethodWithReturn("child_groups", Q_RETURN_ARG(QStringList, list));
if (!rc) throw std::runtime_error("Settings::child_groups() invoke method failed");
return list;
}

QStringList Settings::childKeys() const
{
QStringList list;
bool rc = const_cast<Settings*>(this)->proxy_.invokeMethodWithReturn("child_keys", Q_RETURN_ARG(QStringList, list));
bool rc;
// bool rc = const_cast<Settings*>(this)->proxy_.invokeMethodWithReturn("child_keys", Q_RETURN_ARG(QStringList, list));
if (!rc) throw std::runtime_error("Settings::child_keys() invoke method failed");
return list;
}

bool Settings::contains(const QString& key) const
{
bool flag = false;
bool rc = const_cast<Settings*>(this)->proxy_.invokeMethodWithReturn("contains", Q_RETURN_ARG(bool, flag), Q_ARG(QString, key));
bool rc;
// bool rc = const_cast<Settings*>(this)->proxy_.invokeMethodWithReturn("contains", Q_RETURN_ARG(bool, flag), Q_ARG(QString, key));
if (!rc) throw std::runtime_error("Settings::contains() invoke method failed");
return flag;
}

void Settings::remove(const QString& key)
{
bool rc = proxy_.invokeMethod("remove", Q_ARG(QString, key));
bool rc;
// bool rc = proxy_.invokeMethod("remove", Q_ARG(QString, key));
if (!rc) throw std::runtime_error("Settings::remove() invoke method failed");
}

void Settings::setValue(const QString& key, const QVariant& value)
{
bool rc = proxy_.invokeMethod("set_value", Q_ARG(QString, key), Q_ARG(QVariant, value));
bool rc;

// bool rc = proxy_.invokeMethod("set_value", Q_ARG(QString, key), Q_ARG(QVariant, value));
if (!rc) throw std::runtime_error("Settings::set_value() invoke method failed");
}

QVariant Settings::value(const QString& key, const QVariant& defaultValue) const
{
QVariant val;
bool rc = const_cast<Settings*>(this)->proxy_.invokeMethodWithReturn("value", Q_RETURN_ARG(QVariant, val), Q_ARG(QString, key), Q_ARG(QVariant, defaultValue));
bool rc;
// bool rc = QMetaObject::invokeMethod(proxy_.proxiedObject(), "value", Qt::DirectConnection, Q_RETURN_ARG(QVariant, val), Q_ARG(QString, key), Q_ARG(QVariant, defaultValue));
// bool rc = const_cast<Settings*>(this)->proxy_.invokeMethodWithReturn("value", Q_RETURN_ARG(QVariant, val), Q_ARG(QString, key), Q_ARG(QVariant, defaultValue));
if (!rc) throw std::runtime_error("Settings::value() invoke method failed");
return val;
}
Expand Down
19 changes: 13 additions & 6 deletions qt_gui_cpp/src/qt_gui_cpp_shiboken/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
find_package(Qt5Widgets REQUIRED)
find_package(QTWidgets NAMES Qt5Widgets Qt6Widgets)
find_package(Qt${QTWidgets_VERSION_MAJOR}Widgets REQUIRED)

set(qt_gui_cpp_shiboken_QT_COMPONENTS
QtCore
QtGui
Expand Down Expand Up @@ -50,18 +52,23 @@ if(shiboken_helper_FOUND)
list(APPEND qt_gui_cpp_BINDINGS "shiboken")
set(qt_gui_cpp_BINDINGS "${qt_gui_cpp_BINDINGS}" PARENT_SCOPE)

set(QT_INCLUDE_DIR "${Qt5Widgets_INCLUDE_DIRS}")
shiboken_generator(libqt_gui_cpp global.h typesystem.xml ${PROJECT_SOURCE_DIR}/src/qt_gui_cpp_shiboken "${qt_gui_cpp_shiboken_SRCS}" "${qt_gui_cpp_HDRS}" "${qt_gui_cpp_INCLUDE_PATH}" "${CMAKE_CURRENT_BINARY_DIR}")
set(QT_INCLUDE_DIR "${Qt${QT_VERSION_MAJOR}Widgets_INCLUDE_DIRS}")
if(${QTWidgets_VERSION_MAJOR} GREATER "5")
shiboken_generator6(libqt_gui_cpp global.h typesystem.xml ${PROJECT_SOURCE_DIR}/src/qt_gui_cpp_shiboken "${qt_gui_cpp_shiboken_SRCS}" "${qt_gui_cpp_HDRS}" "${qt_gui_cpp_INCLUDE_PATH}" "${CMAKE_CURRENT_BINARY_DIR}")
else()
shiboken_generator(libqt_gui_cpp global.h typesystem.xml ${PROJECT_SOURCE_DIR}/src/qt_gui_cpp_shiboken "${qt_gui_cpp_shiboken_SRCS}" "${qt_gui_cpp_HDRS}" "${qt_gui_cpp_INCLUDE_PATH}" "${CMAKE_CURRENT_BINARY_DIR}")
endif()

shiboken_include_directories(qt_gui_cpp_shiboken "${qt_gui_cpp_shiboken_QT_COMPONENTS}")

add_library(qt_gui_cpp_shiboken SHARED ${qt_gui_cpp_shiboken_SRCS})
set_property(TARGET qt_gui_cpp_shiboken PROPERTY PREFIX "")
target_compile_definitions(qt_gui_cpp_shiboken PRIVATE BINDINGS_BUILD)
target_include_directories(qt_gui_cpp_shiboken PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../include)
target_link_libraries(qt_gui_cpp_shiboken ${PROJECT_NAME})
ament_target_dependencies(qt_gui_cpp_shiboken pluginlib TinyXML2)
target_link_libraries(qt_gui_cpp_shiboken ${PROJECT_NAME} pluginlib::pluginlib tinyxml2::tinyxml2)
shiboken_target_link_libraries(qt_gui_cpp_shiboken "${qt_gui_cpp_shiboken_QT_COMPONENTS}")

install(TARGETS qt_gui_cpp_shiboken
DESTINATION ${PYTHON_INSTALL_DIR}/${PROJECT_NAME})
endif()
endif()
endif()
2 changes: 1 addition & 1 deletion qt_gui_cpp/src/qt_gui_cpp_sip/plugin_provider.sip
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public:

virtual ~PluginProvider();

virtual QMap<QString, QString> discover(QObject* discovery_data);
virtual QMultiMap<QString, QString> discover(QObject* discovery_data);

/**
* @attention Ownership of returned PluginDescriptor's is transfered to the caller
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public:

virtual ~RecursivePluginProvider();

virtual QMap<QString, QString> discover(QObject* discovery_data);
virtual QMultiMap<QString, QString> discover(QObject* discovery_data);

virtual void shutdown();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public:

virtual ~RosPluginlibPluginProvider_ForPluginProviders();

virtual QMap<QString, QString> discover(QObject* discovery_data);
virtual QMultiMap<QString, QString> discover(QObject* discovery_data);

virtual QList<qt_gui_cpp::PluginDescriptor*> discover_descriptors(QObject* discovery_data);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public:

virtual ~RosPluginlibPluginProvider_ForPlugins();

virtual QMap<QString, QString> discover(QObject* discovery_data);
virtual QMultiMap<QString, QString> discover(QObject* discovery_data);

virtual QList<qt_gui_cpp::PluginDescriptor*> discover_descriptors(QObject* discovery_data);

Expand Down

0 comments on commit 978dce2

Please sign in to comment.