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

Support qt6 #293

Draft
wants to merge 2 commits into
base: rolling
Choose a base branch
from
Draft
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
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.hpp
)

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.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include "plugin_descriptor.hpp"

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

namespace qt_gui_cpp
Expand All @@ -51,7 +51,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
4 changes: 2 additions & 2 deletions qt_gui_cpp/include/qt_gui_cpp/recursive_plugin_provider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#define QT_GUI_CPP__RECURSIVE_PLUGIN_PROVIDER_HPP_

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

#include "composite_plugin_provider.hpp"
Expand All @@ -51,7 +51,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 @@ -87,7 +87,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
11 changes: 7 additions & 4 deletions qt_gui_cpp/src/qt_gui_cpp/plugin_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,20 @@ 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);
PluginDescriptor* descriptor = *it;
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 @@ -48,7 +48,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
66 changes: 28 additions & 38 deletions qt_gui_cpp/src/qt_gui_cpp/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,82 +44,72 @@ 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));
if (!rc) {
throw std::runtime_error("Settings::get_settings() invoke method failed");
}
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));
if (!rc) {
throw std::runtime_error("Settings::all_keys() invoke method failed");
}
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));
if (!rc) {
throw std::runtime_error("Settings::child_groups() invoke method failed");
}
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));
if (!rc) {
throw std::runtime_error("Settings::child_keys() invoke method failed");
}
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));
if (!rc) {
throw std::runtime_error("Settings::contains() invoke method failed");
}
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));
if (!rc) {
throw std::runtime_error("Settings::remove() invoke method failed");
}
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));
if (!rc) {
throw std::runtime_error("Settings::set_value() invoke method failed");
}
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));
if (!rc) {
throw std::runtime_error("Settings::value() invoke method failed");
}
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;
}
} // namespace qt_gui_cpp
27 changes: 13 additions & 14 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 @@ -52,26 +54,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