diff --git a/qt_gui_cpp/CMakeLists.txt b/qt_gui_cpp/CMakeLists.txt index f424ae4d..9617c35d 100644 --- a/qt_gui_cpp/CMakeLists.txt +++ b/qt_gui_cpp/CMakeLists.txt @@ -84,6 +84,9 @@ install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin) if(BUILD_TESTING) + find_package(ament_lint_auto REQUIRED) + ament_lint_auto_find_test_dependencies() + find_package(ament_cmake_pytest REQUIRED) if(TARGET qt_gui_cpp_shiboken) diff --git a/qt_gui_cpp/cmake/qt_gui_cpp-extras.cmake b/qt_gui_cpp/cmake/qt_gui_cpp-extras.cmake index e5d13da9..37cf66a7 100644 --- a/qt_gui_cpp/cmake/qt_gui_cpp-extras.cmake +++ b/qt_gui_cpp/cmake/qt_gui_cpp-extras.cmake @@ -1 +1,29 @@ +# Copyright (c) 2024, Open Source Robotics Foundation, Inc. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + set(qt_gui_cpp_USE_QT_MAJOR_VERSION 5) diff --git a/qt_gui_cpp/include/qt_gui_cpp/composite_plugin_provider.h b/qt_gui_cpp/include/qt_gui_cpp/composite_plugin_provider.h index b43b5f28..472859af 100644 --- a/qt_gui_cpp/include/qt_gui_cpp/composite_plugin_provider.h +++ b/qt_gui_cpp/include/qt_gui_cpp/composite_plugin_provider.h @@ -30,8 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef qt_gui_cpp__CompositePluginProvider_H -#define qt_gui_cpp__CompositePluginProvider_H +#ifndef QT_GUI_CPP__COMPOSITE_PLUGIN_PROVIDER_H_ +#define QT_GUI_CPP__COMPOSITE_PLUGIN_PROVIDER_H_ // *INDENT-OFF* (prevent uncrustify from adding indention below) #warning Including header is deprecated, \ @@ -39,4 +39,4 @@ include instead. // *INDENT-ON* #include "./composite_plugin_provider.hpp" -#endif // qt_gui_cpp__CompositePluginProvider_H +#endif // QT_GUI_CPP__COMPOSITE_PLUGIN_PROVIDER_H_ diff --git a/qt_gui_cpp/include/qt_gui_cpp/composite_plugin_provider.hpp b/qt_gui_cpp/include/qt_gui_cpp/composite_plugin_provider.hpp index 1f8e40ed..82670f50 100644 --- a/qt_gui_cpp/include/qt_gui_cpp/composite_plugin_provider.hpp +++ b/qt_gui_cpp/include/qt_gui_cpp/composite_plugin_provider.hpp @@ -30,55 +30,52 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef qt_gui_cpp__CompositePluginProvider_HPP -#define qt_gui_cpp__CompositePluginProvider_HPP - -#include "plugin_descriptor.hpp" -#include "plugin_provider.hpp" +#ifndef QT_GUI_CPP__COMPOSITE_PLUGIN_PROVIDER_HPP_ +#define QT_GUI_CPP__COMPOSITE_PLUGIN_PROVIDER_HPP_ #include #include #include #include +#include "plugin_descriptor.hpp" +#include "plugin_provider.hpp" + namespace qt_gui_cpp { class CompositePluginProvider : public PluginProvider { - public: - - CompositePluginProvider(const QList& plugin_providers = QList()); + CompositePluginProvider( + const QList & plugin_providers = QList()); virtual ~CompositePluginProvider(); /** * @note The ownership of the plugin providers is transferred to the callee. */ - virtual void set_plugin_providers(const QList& plugin_providers); + virtual void set_plugin_providers(const QList & plugin_providers); - virtual QList discover_descriptors(QObject* discovery_data); + virtual QList discover_descriptors(QObject * discovery_data); - virtual void* load(const QString& plugin_id, PluginContext* plugin_context); + virtual void * load(const QString & plugin_id, PluginContext * plugin_context); - virtual Plugin* load_plugin(const QString& plugin_id, PluginContext* plugin_context); + virtual Plugin * load_plugin(const QString & plugin_id, PluginContext * plugin_context); - virtual void unload(void* plugin_instance); + virtual void unload(void * plugin_instance); virtual void shutdown(); private: + QList plugin_providers_; - QList plugin_providers_; - - QMap > discovered_plugins_; - - QMap running_plugins_; + QMap> discovered_plugins_; + QMap running_plugins_; }; -} // namespace +} // namespace qt_gui_cpp -#endif // qt_gui_cpp__CompositePluginProvider_HPP +#endif // QT_GUI_CPP__COMPOSITE_PLUGIN_PROVIDER_HPP_ diff --git a/qt_gui_cpp/include/qt_gui_cpp/generic_proxy.h b/qt_gui_cpp/include/qt_gui_cpp/generic_proxy.h index 3d2a8bef..d2da16d2 100644 --- a/qt_gui_cpp/include/qt_gui_cpp/generic_proxy.h +++ b/qt_gui_cpp/include/qt_gui_cpp/generic_proxy.h @@ -30,8 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef qt_gui_cpp__GenericProxy_H -#define qt_gui_cpp__GenericProxy_H +#ifndef QT_GUI_CPP__GENERIC_PROXY_H_ +#define QT_GUI_CPP__GENERIC_PROXY_H_ // *INDENT-OFF* (prevent uncrustify from adding indention below) #warning Including header is deprecated, \ @@ -40,4 +40,4 @@ include instead. #include "./generic_proxy.hpp" -#endif // qt_gui_cpp__GenericProxy_H +#endif // QT_GUI_CPP__GENERIC_PROXY_H_ diff --git a/qt_gui_cpp/include/qt_gui_cpp/generic_proxy.hpp b/qt_gui_cpp/include/qt_gui_cpp/generic_proxy.hpp index c75f4840..26981571 100644 --- a/qt_gui_cpp/include/qt_gui_cpp/generic_proxy.hpp +++ b/qt_gui_cpp/include/qt_gui_cpp/generic_proxy.hpp @@ -30,8 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef qt_gui_cpp__GenericProxy_HPP -#define qt_gui_cpp__GenericProxy_HPP +#ifndef QT_GUI_CPP__GENERIC_PROXY_HPP_ +#define QT_GUI_CPP__GENERIC_PROXY_HPP_ #include @@ -40,25 +40,33 @@ namespace qt_gui_cpp class GenericProxy { - public: + explicit GenericProxy(QObject * obj = 0); - GenericProxy(QObject* obj = 0); - - QObject* proxiedObject(); + QObject * proxiedObject(); - void setProxiedObject(QObject* obj); + void setProxiedObject(QObject * obj); - bool invokeMethod(const char* member, QGenericArgument val0 = QGenericArgument(), QGenericArgument val1 = QGenericArgument(), QGenericArgument val2 = QGenericArgument(), QGenericArgument val3 = QGenericArgument(), QGenericArgument val4 = QGenericArgument(), QGenericArgument val5 = QGenericArgument(), QGenericArgument val6 = QGenericArgument(), QGenericArgument val7 = QGenericArgument(), QGenericArgument val8 = QGenericArgument(), QGenericArgument val9 = QGenericArgument()); + bool invokeMethod( + const char * member, QGenericArgument val0 = QGenericArgument(), + QGenericArgument val1 = QGenericArgument(), QGenericArgument val2 = QGenericArgument(), + QGenericArgument val3 = QGenericArgument(), QGenericArgument val4 = QGenericArgument(), + QGenericArgument val5 = QGenericArgument(), QGenericArgument val6 = QGenericArgument(), + QGenericArgument val7 = QGenericArgument(), QGenericArgument val8 = QGenericArgument(), + QGenericArgument val9 = QGenericArgument()); - bool invokeMethodWithReturn(const char* member, QGenericReturnArgument ret = QGenericReturnArgument(0, 0), QGenericArgument val0 = QGenericArgument(), QGenericArgument val1 = QGenericArgument(), QGenericArgument val2 = QGenericArgument(), QGenericArgument val3 = QGenericArgument(), QGenericArgument val4 = QGenericArgument(), QGenericArgument val5 = QGenericArgument(), QGenericArgument val6 = QGenericArgument(), QGenericArgument val7 = QGenericArgument(), QGenericArgument val8 = QGenericArgument(), QGenericArgument val9 = QGenericArgument()); + bool invokeMethodWithReturn( + const char * member, + QGenericReturnArgument ret = QGenericReturnArgument(0, 0), + QGenericArgument val0 = QGenericArgument(), QGenericArgument val1 = QGenericArgument(), + QGenericArgument val2 = QGenericArgument(), QGenericArgument val3 = QGenericArgument(), + QGenericArgument val4 = QGenericArgument(), QGenericArgument val5 = QGenericArgument(), + QGenericArgument val6 = QGenericArgument(), QGenericArgument val7 = QGenericArgument(), + QGenericArgument val8 = QGenericArgument(), QGenericArgument val9 = QGenericArgument()); private: - - QObject* object_; - + QObject * object_; }; +} // namespace qt_gui_cpp -} // namespace - -#endif // qt_gui_cpp__GenericProxy_HPP +#endif // QT_GUI_CPP__GENERIC_PROXY_HPP_ diff --git a/qt_gui_cpp/include/qt_gui_cpp/plugin.h b/qt_gui_cpp/include/qt_gui_cpp/plugin.h index ab71180a..12f8548d 100644 --- a/qt_gui_cpp/include/qt_gui_cpp/plugin.h +++ b/qt_gui_cpp/include/qt_gui_cpp/plugin.h @@ -30,8 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef qt_gui_cpp__Plugin_H -#define qt_gui_cpp__Plugin_H +#ifndef QT_GUI_CPP__PLUGIN_H_ +#define QT_GUI_CPP__PLUGIN_H_ // *INDENT-OFF* (prevent uncrustify from adding indention below) #warning Including header is deprecated, \ @@ -40,4 +40,4 @@ include instead. #include "./plugin.hpp" -#endif // qt_gui_cpp__Plugin_H +#endif // QT_GUI_CPP__PLUGIN_H_ diff --git a/qt_gui_cpp/include/qt_gui_cpp/plugin.hpp b/qt_gui_cpp/include/qt_gui_cpp/plugin.hpp index 0656ae36..0cf9a2c4 100644 --- a/qt_gui_cpp/include/qt_gui_cpp/plugin.hpp +++ b/qt_gui_cpp/include/qt_gui_cpp/plugin.hpp @@ -30,15 +30,15 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef qt_gui_cpp__Plugin_HPP -#define qt_gui_cpp__Plugin_HPP +#ifndef QT_GUI_CPP__PLUGIN_HPP_ +#define QT_GUI_CPP__PLUGIN_HPP_ + +#include #include "plugin_bridge.hpp" #include "plugin_context.hpp" #include "settings.hpp" -#include - namespace qt_gui_cpp { @@ -48,24 +48,22 @@ namespace qt_gui_cpp class Plugin : public QObject { - Q_OBJECT public: - /** * Construct the plugin. * All initialization should be performed in initPlugin(). */ Plugin() - : QObject() + : QObject() {} /** * Instantiate the plugin. * @param the plugin context */ - virtual void initPlugin(PluginContext& /*context*/) + virtual void initPlugin(PluginContext & /*context*/) {} /** @@ -79,7 +77,7 @@ class Plugin * @param the plugin-specific settings * @param the instance-specific settings */ - virtual void saveSettings(Settings& /*plugin_settings*/, Settings& /*instance_settings*/) const + virtual void saveSettings(Settings & /*plugin_settings*/, Settings & /*instance_settings*/) const {} /** @@ -87,7 +85,9 @@ class Plugin * @param the plugin-specific settings * @param the instance-specific settings */ - virtual void restoreSettings(const Settings& /*plugin_settings*/, const Settings& /*instance_settings*/) + virtual void restoreSettings( + const Settings & /*plugin_settings*/, + const Settings & /*instance_settings*/) {} /** @@ -105,9 +105,7 @@ class Plugin */ virtual void triggerConfiguration() {} - }; +} // namespace qt_gui_cpp -} // namespace - -#endif // qt_gui_cpp__Plugin_HPP +#endif // QT_GUI_CPP__PLUGIN_HPP_ diff --git a/qt_gui_cpp/include/qt_gui_cpp/plugin_bridge.h b/qt_gui_cpp/include/qt_gui_cpp/plugin_bridge.h index 3c66a7cc..01595996 100644 --- a/qt_gui_cpp/include/qt_gui_cpp/plugin_bridge.h +++ b/qt_gui_cpp/include/qt_gui_cpp/plugin_bridge.h @@ -30,8 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef qt_gui_cpp__PluginBridge_H -#define qt_gui_cpp__PluginBridge_H +#ifndef QT_GUI_CPP__PLUGIN_BRIDGE_H_ +#define QT_GUI_CPP__PLUGIN_BRIDGE_H_ // *INDENT-OFF* (prevent uncrustify from adding indention below) #warning Including header is deprecated, \ @@ -40,4 +40,4 @@ include instead. #include "./plugin_bridge.hpp" -#endif // qt_gui_cpp__PluginBridge_H +#endif // QT_GUI_CPP__PLUGIN_BRIDGE_H_ diff --git a/qt_gui_cpp/include/qt_gui_cpp/plugin_bridge.hpp b/qt_gui_cpp/include/qt_gui_cpp/plugin_bridge.hpp index 21d321a2..5c76409b 100644 --- a/qt_gui_cpp/include/qt_gui_cpp/plugin_bridge.hpp +++ b/qt_gui_cpp/include/qt_gui_cpp/plugin_bridge.hpp @@ -30,8 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef qt_gui_cpp__PluginBridge_HPP -#define qt_gui_cpp__PluginBridge_HPP +#ifndef QT_GUI_CPP__PLUGIN_BRIDGE_HPP_ +#define QT_GUI_CPP__PLUGIN_BRIDGE_HPP_ #include @@ -45,14 +45,14 @@ class PluginProvider; class PluginBridge : public QObject { - Q_OBJECT public: - PluginBridge(); - virtual bool load_plugin(PluginProvider* provider, const QString& plugin_id, PluginContext* plugin_context); + virtual bool load_plugin( + PluginProvider * provider, const QString & plugin_id, + PluginContext * plugin_context); virtual void unload_plugin(); @@ -61,21 +61,17 @@ class PluginBridge virtual void trigger_configuration(); public slots: - virtual void shutdown_plugin(); - virtual void save_settings(QObject* plugin_settings, QObject* instance_settings); + virtual void save_settings(QObject * plugin_settings, QObject * instance_settings); - virtual void restore_settings(QObject* plugin_settings, QObject* instance_settings); + virtual void restore_settings(QObject * plugin_settings, QObject * instance_settings); private: + PluginProvider * provider_; - PluginProvider* provider_; - - Plugin* plugin_; - + Plugin * plugin_; }; +} // namespace qt_gui_cpp -} // namespace - -#endif // qt_gui_cpp__PluginBridge_HPP +#endif // QT_GUI_CPP__PLUGIN_BRIDGE_HPP_ diff --git a/qt_gui_cpp/include/qt_gui_cpp/plugin_context.h b/qt_gui_cpp/include/qt_gui_cpp/plugin_context.h index 78ce1f78..57a441c4 100644 --- a/qt_gui_cpp/include/qt_gui_cpp/plugin_context.h +++ b/qt_gui_cpp/include/qt_gui_cpp/plugin_context.h @@ -30,8 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef qt_gui_cpp__PluginContext_H -#define qt_gui_cpp__PluginContext_H +#ifndef QT_GUI_CPP__PLUGIN_CONTEXT_H_ +#define QT_GUI_CPP__PLUGIN_CONTEXT_H_ // *INDENT-OFF* (prevent uncrustify from adding indention below) #warning Including header is deprecated, \ @@ -40,5 +40,4 @@ include instead. #include "./plugin_context.hpp" - -#endif // qt_gui_cpp__PluginContext_H +#endif // QT_GUI_CPP__PLUGIN_CONTEXT_H_ diff --git a/qt_gui_cpp/include/qt_gui_cpp/plugin_context.hpp b/qt_gui_cpp/include/qt_gui_cpp/plugin_context.hpp index 6046289f..85ffff4d 100644 --- a/qt_gui_cpp/include/qt_gui_cpp/plugin_context.hpp +++ b/qt_gui_cpp/include/qt_gui_cpp/plugin_context.hpp @@ -30,10 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef qt_gui_cpp__PluginContext_HPP -#define qt_gui_cpp__PluginContext_HPP - -#include "generic_proxy.hpp" +#ifndef QT_GUI_CPP__PLUGIN_CONTEXT_HPP_ +#define QT_GUI_CPP__PLUGIN_CONTEXT_HPP_ #include #include @@ -50,6 +48,8 @@ #endif #include +#include "generic_proxy.hpp" + namespace qt_gui_cpp { @@ -60,14 +60,12 @@ namespace qt_gui_cpp class PluginContext : public QObject { - Q_OBJECT public: + PluginContext(QObject * obj, int serial_number, const QStringList & argv); - PluginContext(QObject* obj, int serial_number, const QStringList& argv); - - PluginContext(const PluginContext& other); + PluginContext(const PluginContext & other); /** * Return the serial number of the plugin. @@ -80,7 +78,7 @@ class PluginContext * Return the command line arguments of the plugin. * @return The arguments without a program name at the beginning */ - const QStringList& argv() const; + const QStringList & argv() const; /** * Add a widget to the UI. @@ -89,14 +87,14 @@ class PluginContext * @note The ownership of the widget pointer is transferred to the callee which will delete it when the plugin is shut down. * @param widget The widget to add */ - void addWidget(QWidget* widget); + void addWidget(QWidget * widget); /** * Remove a previously added widget from the UI. * @note The ownership of the widget pointer is transferred back to the caller which is responsible of deleting it. * @param widget The widget to remove */ - void removeWidget(QWidget* widget); + void removeWidget(QWidget * widget); /** * Close the plugin. @@ -110,15 +108,11 @@ class PluginContext void reloadPlugin(); protected: - GenericProxy proxy_; int serial_number_; QStringList argv_; - }; - -} // namespace - -#endif // qt_gui_cpp__PluginContext_HPP +} // namespace qt_gui_cpp +#endif // QT_GUI_CPP__PLUGIN_CONTEXT_HPP_ diff --git a/qt_gui_cpp/include/qt_gui_cpp/plugin_descriptor.h b/qt_gui_cpp/include/qt_gui_cpp/plugin_descriptor.h index 909fd33f..dd9d6cae 100644 --- a/qt_gui_cpp/include/qt_gui_cpp/plugin_descriptor.h +++ b/qt_gui_cpp/include/qt_gui_cpp/plugin_descriptor.h @@ -30,8 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef qt_gui_cpp__PluginDescriptor_H -#define qt_gui_cpp__PluginDescriptor_H +#ifndef QT_GUI_CPP__PLUGIN_DESCRIPTOR_H_ +#define QT_GUI_CPP__PLUGIN_DESCRIPTOR_H_ // *INDENT-OFF* (prevent uncrustify from adding indention below) #warning Including header is deprecated, \ @@ -40,4 +40,4 @@ include instead. #include "./plugin_descriptor.hpp" -#endif // qt_gui_cpp__PluginDescriptor_H +#endif // QT_GUI_CPP__PLUGIN_DESCRIPTOR_H_ diff --git a/qt_gui_cpp/include/qt_gui_cpp/plugin_descriptor.hpp b/qt_gui_cpp/include/qt_gui_cpp/plugin_descriptor.hpp index 07684139..aae756ac 100644 --- a/qt_gui_cpp/include/qt_gui_cpp/plugin_descriptor.hpp +++ b/qt_gui_cpp/include/qt_gui_cpp/plugin_descriptor.hpp @@ -30,8 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef qt_gui_cpp__PluginDescriptor_HPP -#define qt_gui_cpp__PluginDescriptor_HPP +#ifndef QT_GUI_CPP__PLUGIN_DESCRIPTOR_HPP_ +#define QT_GUI_CPP__PLUGIN_DESCRIPTOR_HPP_ #include #include @@ -42,41 +42,42 @@ namespace qt_gui_cpp class PluginDescriptor { - public: + PluginDescriptor( + const QString & plugin_id, + const QMap & attributes = (QMap())); - PluginDescriptor(const QString& plugin_id, const QMap& attributes = (QMap())); - - const QString& pluginId() const; + const QString & pluginId() const; - const QMap& attributes() const; + const QMap & attributes() const; - QMap& attributes(); + QMap & attributes(); - const QMap& actionAttributes() const; + const QMap & actionAttributes() const; - void setActionAttributes(const QString& label, const QString& statustip = QString(), const QString& icon = QString(), const QString& icontype = QString()); + void setActionAttributes( + const QString & label, const QString & statustip = QString(), + const QString & icon = QString(), const QString & icontype = QString()); int countGroups() const; QMap group(int index) const; - void addGroupAttributes(const QString& label, const QString& statustip = QString(), const QString& icon = QString(), const QString& icontype = QString()); + void addGroupAttributes( + const QString & label, const QString & statustip = QString(), + const QString & icon = QString(), const QString & icontype = QString()); QMap toDictionary() const; protected: - QString plugin_id_; QMap attributes_; QMap action_attributes_; - QVector > groups_; - + QVector> groups_; }; +} // namespace qt_gui_cpp -} // namespace - -#endif // qt_gui_cpp__PluginDescriptor_HPP +#endif // QT_GUI_CPP__PLUGIN_DESCRIPTOR_HPP_ diff --git a/qt_gui_cpp/include/qt_gui_cpp/plugin_provider.h b/qt_gui_cpp/include/qt_gui_cpp/plugin_provider.h index 6a5d898d..2de63d3e 100644 --- a/qt_gui_cpp/include/qt_gui_cpp/plugin_provider.h +++ b/qt_gui_cpp/include/qt_gui_cpp/plugin_provider.h @@ -30,8 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef qt_gui_cpp__PluginProvider_H -#define qt_gui_cpp__PluginProvider_H +#ifndef QT_GUI_CPP__PLUGIN_PROVIDER_H_ +#define QT_GUI_CPP__PLUGIN_PROVIDER_H_ // *INDENT-OFF* (prevent uncrustify from adding indention below) #warning Including header is deprecated, \ @@ -40,4 +40,4 @@ include instead. #include "./plugin_provider.hpp" -#endif // qt_gui_cpp__PluginProvider_H +#endif // QT_GUI_CPP__PLUGIN_PROVIDER_H_ diff --git a/qt_gui_cpp/include/qt_gui_cpp/plugin_provider.hpp b/qt_gui_cpp/include/qt_gui_cpp/plugin_provider.hpp index 5dbb076a..a703e7e1 100644 --- a/qt_gui_cpp/include/qt_gui_cpp/plugin_provider.hpp +++ b/qt_gui_cpp/include/qt_gui_cpp/plugin_provider.hpp @@ -30,8 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef qt_gui_cpp__PluginProvider_HPP -#define qt_gui_cpp__PluginProvider_HPP +#ifndef QT_GUI_CPP__PLUGIN_PROVIDER_HPP_ +#define QT_GUI_CPP__PLUGIN_PROVIDER_HPP_ #include "plugin.hpp" #include "plugin_context.hpp" @@ -46,32 +46,28 @@ namespace qt_gui_cpp class PluginProvider { - public: - PluginProvider(); virtual ~PluginProvider(); - virtual QMap discover(QObject* discovery_data); + virtual QMap discover(QObject * discovery_data); /** * @attention Ownership of returned PluginDescriptor's is transfered to the caller */ - virtual QList discover_descriptors(QObject* discovery_data); + virtual QList discover_descriptors(QObject * discovery_data); - virtual void* load(const QString& plugin_id, PluginContext* plugin_context); + virtual void * load(const QString & plugin_id, PluginContext * plugin_context); - virtual Plugin* load_plugin(const QString& plugin_id, PluginContext* plugin_context); + virtual Plugin * load_plugin(const QString & plugin_id, PluginContext * plugin_context); - virtual void unload(void* plugin_instance); + virtual void unload(void * plugin_instance); - virtual void unload_plugin(Plugin* plugin_instance); + virtual void unload_plugin(Plugin * plugin_instance); virtual void shutdown(); - }; +} // namespace qt_gui_cpp -} // namespace - -#endif // qt_gui_cpp__PluginProvider_HPP +#endif // QT_GUI_CPP__PLUGIN_PROVIDER_HPP_ diff --git a/qt_gui_cpp/include/qt_gui_cpp/recursive_plugin_provider.h b/qt_gui_cpp/include/qt_gui_cpp/recursive_plugin_provider.h index 43437bb0..4171d9fa 100644 --- a/qt_gui_cpp/include/qt_gui_cpp/recursive_plugin_provider.h +++ b/qt_gui_cpp/include/qt_gui_cpp/recursive_plugin_provider.h @@ -30,8 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef qt_gui_cpp__RecursivePluginProvider_H -#define qt_gui_cpp__RecursivePluginProvider_H +#ifndef QT_GUI_CPP__RECURSIVE_PLUGIN_PROVIDER_H_ +#define QT_GUI_CPP__RECURSIVE_PLUGIN_PROVIDER_H_ // *INDENT-OFF* (prevent uncrustify from adding indention below) #warning Including header is deprecated, \ @@ -40,4 +40,4 @@ include instead. #include "./recursive_plugin_provider.hpp" -#endif // qt_gui_cpp__RecursivePluginProvider_H +#endif // QT_GUI_CPP__RECURSIVE_PLUGIN_PROVIDER_H_ diff --git a/qt_gui_cpp/include/qt_gui_cpp/recursive_plugin_provider.hpp b/qt_gui_cpp/include/qt_gui_cpp/recursive_plugin_provider.hpp index 427377c7..2fd3758f 100644 --- a/qt_gui_cpp/include/qt_gui_cpp/recursive_plugin_provider.hpp +++ b/qt_gui_cpp/include/qt_gui_cpp/recursive_plugin_provider.hpp @@ -30,40 +30,34 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef qt_gui_cpp__RecursivePluginProvider_HPP -#define qt_gui_cpp__RecursivePluginProvider_HPP - -#include "composite_plugin_provider.hpp" -#include "ros_pluginlib_plugin_provider_for_plugin_providers.hpp" +#ifndef QT_GUI_CPP__RECURSIVE_PLUGIN_PROVIDER_HPP_ +#define QT_GUI_CPP__RECURSIVE_PLUGIN_PROVIDER_HPP_ #include #include #include +#include "composite_plugin_provider.hpp" +#include "ros_pluginlib_plugin_provider_for_plugin_providers.hpp" + namespace qt_gui_cpp { class RecursivePluginProvider : public CompositePluginProvider { - public: - - RecursivePluginProvider(RosPluginlibPluginProvider_ForPluginProviders* plugin_provider); + explicit RecursivePluginProvider(RosPluginlibPluginProvider_ForPluginProviders * plugin_provider); virtual ~RecursivePluginProvider(); - virtual QMap discover(QObject* discovery_data); + virtual QMap discover(QObject * discovery_data); virtual void shutdown(); private: - - RosPluginlibPluginProvider_ForPluginProviders* plugin_provider_; - QList providers_; - + RosPluginlibPluginProvider_ForPluginProviders * plugin_provider_; + QList providers_; }; - -} // namespace - -#endif // qt_gui_cpp__RecursivePluginProvider_HPP +} // namespace qt_gui_cpp +#endif // QT_GUI_CPP__RECURSIVE_PLUGIN_PROVIDER_HPP_ diff --git a/qt_gui_cpp/include/qt_gui_cpp/ros_pluginlib_plugin_provider.h b/qt_gui_cpp/include/qt_gui_cpp/ros_pluginlib_plugin_provider.h index 78f74f4b..fe55a821 100644 --- a/qt_gui_cpp/include/qt_gui_cpp/ros_pluginlib_plugin_provider.h +++ b/qt_gui_cpp/include/qt_gui_cpp/ros_pluginlib_plugin_provider.h @@ -30,8 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef qt_gui_cpp__RosPluginlibPluginProvider_H -#define qt_gui_cpp__RosPluginlibPluginProvider_H +#ifndef QT_GUI_CPP__ROS_PLUGINLIB_PLUGIN_PROVIDER_H_ +#define QT_GUI_CPP__ROS_PLUGINLIB_PLUGIN_PROVIDER_H_ // *INDENT-OFF* (prevent uncrustify from adding indention below) #warning Including header is deprecated, \ @@ -40,4 +40,4 @@ include instead. #include "./ros_pluginlib_plugin_provider.hpp" -#endif // qt_gui_cpp__RosPluginlibPluginProvider_H +#endif // QT_GUI_CPP__ROS_PLUGINLIB_PLUGIN_PROVIDER_H_ diff --git a/qt_gui_cpp/include/qt_gui_cpp/ros_pluginlib_plugin_provider.hpp b/qt_gui_cpp/include/qt_gui_cpp/ros_pluginlib_plugin_provider.hpp index a83ea8ac..cd89e5d8 100644 --- a/qt_gui_cpp/include/qt_gui_cpp/ros_pluginlib_plugin_provider.hpp +++ b/qt_gui_cpp/include/qt_gui_cpp/ros_pluginlib_plugin_provider.hpp @@ -30,21 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef qt_gui_cpp__RosPluginlibPluginProvider_HPP -#define qt_gui_cpp__RosPluginlibPluginProvider_HPP - -// Pluginlib has an optional dependency on boost::shared_ptr, which is not required here -// On machines without boost, including pluginlib/class_loader.hpp requires defining this flag to -// disable that dependency. Mosty notably these are the machines configured on ci.ros2.org -#define PLUGINLIB__DISABLE_BOOST_FUNCTIONS - -#include "plugin.hpp" -#include "plugin_context.hpp" -#include "plugin_descriptor.hpp" -#include "plugin_provider.hpp" - -#include -#include +#ifndef QT_GUI_CPP__ROS_PLUGINLIB_PLUGIN_PROVIDER_HPP_ +#define QT_GUI_CPP__ROS_PLUGINLIB_PLUGIN_PROVIDER_HPP_ #include #include @@ -53,29 +40,38 @@ #include #include +#include + #include #include +#include #include #include +#include "plugin.hpp" +#include "plugin_context.hpp" +#include "plugin_descriptor.hpp" +#include "plugin_provider.hpp" + +#include + namespace qt_gui_cpp { - template class RosPluginlibPluginProvider - : public QObject - , public PluginProvider + : public QObject, + public PluginProvider { - public: - - static RosPluginlibPluginProvider* create_instance(const QString& export_tag, const QString& base_class_type) + static RosPluginlibPluginProvider * create_instance( + const QString & export_tag, + const QString & base_class_type) { return new RosPluginlibPluginProvider(export_tag, base_class_type); } - RosPluginlibPluginProvider(const QString& export_tag, const QString& base_class_type) - : QObject() + RosPluginlibPluginProvider(const QString & export_tag, const QString & base_class_type) + : QObject() , PluginProvider() , export_tag_(export_tag) , base_class_type_(base_class_type) @@ -86,21 +82,19 @@ class RosPluginlibPluginProvider virtual ~RosPluginlibPluginProvider() { - if (class_loader_) - { + if (class_loader_) { delete class_loader_; } } - virtual QMap discover(QObject* discovery_data) + virtual QMap discover(QObject * discovery_data) { return PluginProvider::discover(discovery_data); } - virtual QList discover_descriptors(QObject* discovery_data) + virtual QList discover_descriptors(QObject * discovery_data) { - if (class_loader_) - { + if (class_loader_) { delete class_loader_; } @@ -110,37 +104,34 @@ class RosPluginlibPluginProvider std::vector plugin_xml_paths; // reuse plugin paths from cache if available - if (is_cached) - { + if (is_cached) { QStringList paths = discovery_settings.value(key).toStringList(); - for (QStringList::const_iterator it = paths.begin(); it != paths.end(); it++) - { + for (QStringList::const_iterator it = paths.begin(); it != paths.end(); it++) { plugin_xml_paths.push_back(it->toStdString()); } + } else { + qDebug( + "RosPluginlibPluginProvider::discover_descriptors() crawling for plugins of type '%s' " + "and base class '%s'", + export_tag_.toStdString().c_str(), base_class_type_.toStdString().c_str()); } - else - { - qDebug("RosPluginlibPluginProvider::discover_descriptors() crawling for plugins of type '%s' and base class '%s'", export_tag_.toStdString().c_str(), base_class_type_.toStdString().c_str()); - } - class_loader_ = new pluginlib::ClassLoader(export_tag_.toStdString(), base_class_type_.toStdString(), std::string("plugin"), plugin_xml_paths); + class_loader_ = new pluginlib::ClassLoader(export_tag_.toStdString(), + base_class_type_.toStdString(), std::string("plugin"), plugin_xml_paths); - if (!is_cached) - { + if (!is_cached) { // save discovered paths std::vector paths = class_loader_->getPluginXmlPaths(); QStringList qpaths; - for (std::vector::const_iterator it = paths.begin(); it != paths.end(); it++) - { + for (std::vector::const_iterator it = paths.begin(); it != paths.end(); it++) { qpaths.push_back(it->c_str()); } discovery_settings.setValue(key, qpaths); } - QList descriptors; + QList descriptors; std::vector classes = class_loader_->getDeclaredClasses(); - for (std::vector::iterator it = classes.begin(); it != classes.end(); it++) - { + for (std::vector::iterator it = classes.begin(); it != classes.end(); it++) { std::string lookup_name = *it; std::string name = class_loader_->getName(lookup_name); @@ -156,11 +147,14 @@ class RosPluginlibPluginProvider attributes["plugin_path"] = plugin_path.c_str(); // check if plugin is available - //std::string library_path = class_loader_->getClassLibraryPath(lookup_name); - //attributes["not_available"] = !std::ifstream(library_path.c_str()) ? QString("library ").append(lookup_name.c_str()).append(" not found (may be it must be built?)") : ""; + // std::string library_path = class_loader_->getClassLibraryPath(lookup_name); + // attributes["not_available"] = + // !std::ifstream(library_path.c_str()) ? + // QString("library ").append(lookup_name.c_str()).append( + // " not found (may be it must be built?)") : ""; attributes["not_available"] = ""; - PluginDescriptor* plugin_descriptor = new PluginDescriptor(lookup_name.c_str(), attributes); + PluginDescriptor * plugin_descriptor = new PluginDescriptor(lookup_name.c_str(), attributes); QString label = name.c_str(); QString statustip = class_loader_->getClassDescription(lookup_name).c_str(); QString icon; @@ -174,86 +168,78 @@ class RosPluginlibPluginProvider return descriptors; } - virtual void* load(const QString& plugin_id, PluginContext* plugin_context) + virtual void * load(const QString & plugin_id, PluginContext * plugin_context) { return load_explicit_type(plugin_id, plugin_context); } - virtual Plugin* load_plugin(const QString& plugin_id, PluginContext* plugin_context) + virtual Plugin * load_plugin(const QString & plugin_id, PluginContext * plugin_context) { - T* instance = load_explicit_type(plugin_id, plugin_context); - if (instance == 0) - { + T * instance = load_explicit_type(plugin_id, plugin_context); + if (instance == 0) { return 0; } - Plugin* plugin = dynamic_cast(instance); - if (plugin == 0) - { - // TODO: garbage instance + Plugin * plugin = dynamic_cast(instance); + if (plugin == 0) { + // TODO(someone): garbage instance qWarning("RosPluginlibPluginProvider::load_plugin() called on non-plugin plugin provider"); return 0; } return plugin; } - virtual T* load_explicit_type(const QString& plugin_id, PluginContext* plugin_context) + virtual T * load_explicit_type(const QString & plugin_id, PluginContext * plugin_context) { std::string lookup_name = plugin_id.toStdString(); - if (!class_loader_->isClassAvailable(lookup_name)) - { - qWarning("RosPluginlibPluginProvider::load_explicit_type(%s) class not available", lookup_name.c_str()); + if (!class_loader_->isClassAvailable(lookup_name)) { + qWarning("RosPluginlibPluginProvider::load_explicit_type(%s) class not available", + lookup_name.c_str()); return 0; } std::shared_ptr instance; - try - { + try { instance = create_plugin(lookup_name, plugin_context); - } - catch (pluginlib::LibraryLoadException& e) - { - qWarning("RosPluginlibPluginProvider::load_explicit_type(%s) could not load library (%s)", lookup_name.c_str(), e.what()); + } catch (pluginlib::LibraryLoadException & e) { + qWarning("RosPluginlibPluginProvider::load_explicit_type(%s) could not load library (%s)", + lookup_name.c_str(), e.what()); return 0; - } - catch (pluginlib::PluginlibException& e) - { - qWarning("RosPluginlibPluginProvider::load_explicit_type(%s) failed creating instance (%s)", lookup_name.c_str(), e.what()); + } catch (pluginlib::PluginlibException & e) { + qWarning("RosPluginlibPluginProvider::load_explicit_type(%s) failed creating instance (%s)", + lookup_name.c_str(), e.what()); return 0; } - if (!instance) - { - qWarning("RosPluginlibPluginProvider::load_explicit_type(%s) failed creating instance", lookup_name.c_str()); + if (!instance) { + qWarning("RosPluginlibPluginProvider::load_explicit_type(%s) failed creating instance", + lookup_name.c_str()); return 0; } // pass context to plugin - Plugin* plugin = dynamic_cast(&*instance); - if (plugin) - { - try - { + Plugin * plugin = dynamic_cast(&*instance); + if (plugin) { + try { init_plugin(plugin_id, plugin_context, plugin); - } - catch (std::exception& e) - { - // TODO: garbage instance - qWarning("RosPluginlibPluginProvider::load_explicit_type(%s) failed initializing plugin (%s)", lookup_name.c_str(), e.what()); + } catch (std::exception & e) { + // TODO(someone): garbage instance + qWarning( + "RosPluginlibPluginProvider::load_explicit_type(%s) failed initializing plugin (%s)", + lookup_name.c_str(), e.what()); return 0; } } - //qDebug("RosPluginlibPluginProvider::load_explicit_type(%s) succeeded", lookup_name.c_str()); + // qDebug("RosPluginlibPluginProvider::load_explicit_type(%s) succeeded", lookup_name.c_str()); instances_[&*instance] = instance; return &*instance; } - virtual void unload(void* instance) + virtual void unload(void * instance) { - if (!instances_.contains(instance)) - { + if (!instances_.contains(instance)) { qCritical("RosPluginlibPluginProvider::unload() instance not found"); return; } @@ -261,13 +247,13 @@ class RosPluginlibPluginProvider std::shared_ptr pointer = instances_.take(instance); libraries_to_unload_.append(pointer); - QCoreApplication::postEvent(this, new QEvent(static_cast(unload_libraries_event_))); + QCoreApplication::postEvent(this, + new QEvent(static_cast(unload_libraries_event_))); } - bool event(QEvent* e) + bool event(QEvent * e) { - if (e->type() == unload_libraries_event_) - { + if (e->type() == unload_libraries_event_) { libraries_to_unload_.clear(); return true; } @@ -275,19 +261,21 @@ class RosPluginlibPluginProvider } protected: - - virtual std::shared_ptr create_plugin(const std::string& lookup_name, PluginContext* /*plugin_context*/ = 0) + virtual std::shared_ptr create_plugin( + const std::string & lookup_name, + PluginContext * /*plugin_context*/ = 0) { return class_loader_->createSharedInstance(lookup_name); } - virtual void init_plugin(const QString& /*plugin_id*/, PluginContext* plugin_context, Plugin* plugin) + virtual void init_plugin( + const QString & /*plugin_id*/, PluginContext * plugin_context, + Plugin * plugin) { plugin->initPlugin(*plugin_context); } private: - template struct TinyXMLAPIChoice { @@ -299,103 +287,110 @@ class RosPluginlibPluginProvider // only enable for TinyXML versions >= 6 typename = typename std::enable_if::value>::type > - static void warningWithErrorStr(const std::string & manifest_path, const TDoc & doc, std::true_type * = nullptr) + static void warningWithErrorStr( + const std::string & manifest_path, const TDoc & doc, + std::true_type * = nullptr) { - qWarning("RosPluginlibPluginProvider::parseManifest() could not load manifest \"%s\" (%s)", manifest_path.c_str(), doc.ErrorStr()); + qWarning("RosPluginlibPluginProvider::parseManifest() could not load manifest \"%s\" (%s)", + manifest_path.c_str(), doc.ErrorStr()); } template< typename TDoc, typename TType = TVersion, typename = typename std::enable_if::value>::type > - static void warningWithErrorStr(const std::string & manifest_path, const TDoc & doc, std::false_type * = nullptr) + static void warningWithErrorStr( + const std::string & manifest_path, const TDoc & doc, + std::false_type * = nullptr) { - qWarning("RosPluginlibPluginProvider::parseManifest() could not load manifest \"%s\" (%s, %s)", manifest_path.c_str(), doc.GetErrorStr1(), doc.GetErrorStr2()); + qWarning( + "RosPluginlibPluginProvider::parseManifest() could not load manifest \"%s\" (%s, %s)", + manifest_path.c_str(), doc.GetErrorStr1(), doc.GetErrorStr2()); } }; - bool parseManifest(const std::string& lookup_name, const std::string& plugin_path, QString& label, QString& statustip, QString& icon, QString& icontype, PluginDescriptor* plugin_descriptor) + bool parseManifest( + const std::string & lookup_name, const std::string & plugin_path, + QString & label, QString & statustip, QString & icon, QString & icontype, + PluginDescriptor * plugin_descriptor) { - //qDebug("RosPluginlibPluginProvider::parseManifest()"); + // qDebug("RosPluginlibPluginProvider::parseManifest()"); std::string manifest_path = class_loader_->getPluginManifestPath(lookup_name); - //qDebug("RosPluginlibPluginProvider::parseManifest() manifest_path \"%s\"", manifest_path.c_str()); + // qDebug("RosPluginlibPluginProvider::parseManifest() manifest_path \"%s\"", + // manifest_path.c_str()); tinyxml2::XMLDocument doc; tinyxml2::XMLError result = doc.LoadFile(manifest_path.c_str()); - if (result != tinyxml2::XML_SUCCESS) - { - TinyXMLAPIChoice= 6)>>::warningWithErrorStr(manifest_path, doc); + if (result != tinyxml2::XML_SUCCESS) { + TinyXMLAPIChoice= 6)>>::warningWithErrorStr(manifest_path, doc); return false; } // search library-tag with specific path-attribute std::string class_type = class_loader_->getClassType(lookup_name); - tinyxml2::XMLElement* library_element = doc.FirstChildElement("library"); - while (library_element) - { - // search class-tag with specific type- and base_class_type-attribute - tinyxml2::XMLElement* class_element = library_element->FirstChildElement("class"); - while (class_element) + tinyxml2::XMLElement * library_element = doc.FirstChildElement("library"); + while (library_element) { + // search class-tag with specific type- and base_class_type-attribute + tinyxml2::XMLElement * class_element = library_element->FirstChildElement("class"); + while (class_element) { + if (class_type.compare(class_element->Attribute("type")) == 0 && + base_class_type_.compare(class_element->Attribute("base_class_type")) == 0) { - if (class_type.compare(class_element->Attribute("type")) == 0 && base_class_type_.compare(class_element->Attribute("base_class_type")) == 0) - { - tinyxml2::XMLElement* qtgui_element = class_element->FirstChildElement("qtgui"); - if (qtgui_element) - { - // extract meta information - parseActionAttributes(qtgui_element, plugin_path, label, statustip, icon, icontype); - - // extract grouping information - tinyxml2::XMLElement* group_element = qtgui_element->FirstChildElement("group"); - while (group_element) - { - QString group_label; - QString group_statustip; - QString group_icon; - QString group_icontype; - parseActionAttributes(group_element, plugin_path, group_label, group_statustip, group_icon, group_icontype); - plugin_descriptor->addGroupAttributes(group_label, group_statustip, group_icon, group_icontype); - - group_element = group_element->NextSiblingElement("group"); - } + tinyxml2::XMLElement * qtgui_element = class_element->FirstChildElement("qtgui"); + if (qtgui_element) { + // extract meta information + parseActionAttributes(qtgui_element, plugin_path, label, statustip, icon, icontype); + + // extract grouping information + tinyxml2::XMLElement * group_element = qtgui_element->FirstChildElement("group"); + while (group_element) { + QString group_label; + QString group_statustip; + QString group_icon; + QString group_icontype; + parseActionAttributes(group_element, plugin_path, group_label, group_statustip, + group_icon, group_icontype); + plugin_descriptor->addGroupAttributes(group_label, group_statustip, group_icon, + group_icontype); + + group_element = group_element->NextSiblingElement("group"); } - return true; } - class_element = class_element->NextSiblingElement("class"); + return true; } - break; + class_element = class_element->NextSiblingElement("class"); + } + break; library_element = library_element->NextSiblingElement("library"); } - qWarning("RosPluginlibPluginProvider::parseManifest() could not handle manifest \"%s\"", manifest_path.c_str()); + qWarning("RosPluginlibPluginProvider::parseManifest() could not handle manifest \"%s\"", + manifest_path.c_str()); return false; } - void parseActionAttributes(tinyxml2::XMLElement* element, const std::string& plugin_path, QString& label, QString& statustip, QString& icon, QString& icontype) + void parseActionAttributes( + tinyxml2::XMLElement * element, const std::string & plugin_path, + QString & label, QString & statustip, QString & icon, QString & icontype) { - tinyxml2::XMLElement* child_element; - if ((child_element = element->FirstChildElement("label")) != 0) - { + tinyxml2::XMLElement * child_element; + if ((child_element = element->FirstChildElement("label")) != 0) { label = child_element->GetText(); } - if ((child_element = element->FirstChildElement("icon")) != 0) - { + if ((child_element = element->FirstChildElement("icon")) != 0) { icontype = child_element->Attribute("type"); - if (icontype == "file") - { + if (icontype == "file") { // prepend base path icon = plugin_path.c_str(); icon += "/"; icon += child_element->GetText(); - } - else - { + } else { icon = child_element->GetText(); } } - if ((child_element = element->FirstChildElement("statustip")) != 0) - { + if ((child_element = element->FirstChildElement("statustip")) != 0) { statustip = child_element->GetText(); } } @@ -410,14 +405,12 @@ class RosPluginlibPluginProvider int unload_libraries_event_; - pluginlib::ClassLoader* class_loader_; - - QMap > instances_; + pluginlib::ClassLoader * class_loader_; - QList > libraries_to_unload_; + QMap> instances_; + QList> libraries_to_unload_; }; +} // namespace qt_gui_cpp -} // namespace - -#endif // qt_gui_cpp__RosPluginlibPluginProvider_HPP +#endif // QT_GUI_CPP__ROS_PLUGINLIB_PLUGIN_PROVIDER_HPP_ diff --git a/qt_gui_cpp/include/qt_gui_cpp/ros_pluginlib_plugin_provider_for_plugin_providers.h b/qt_gui_cpp/include/qt_gui_cpp/ros_pluginlib_plugin_provider_for_plugin_providers.h index a270c504..7dce7654 100644 --- a/qt_gui_cpp/include/qt_gui_cpp/ros_pluginlib_plugin_provider_for_plugin_providers.h +++ b/qt_gui_cpp/include/qt_gui_cpp/ros_pluginlib_plugin_provider_for_plugin_providers.h @@ -30,8 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef qt_gui_cpp__RosPluginlibPluginProvider_ForPluginProviders_H -#define qt_gui_cpp__RosPluginlibPluginProvider_ForPluginProviders_H +#ifndef QT_GUI_CPP__ROS_PLUGINLIB_PLUGIN_PROVIDER_FOR_PLUGIN_PROVIDERS_H_ +#define QT_GUI_CPP__ROS_PLUGINLIB_PLUGIN_PROVIDER_FOR_PLUGIN_PROVIDERS_H_ // *INDENT-OFF* (prevent uncrustify from adding indention below) #warning Including header \ @@ -41,4 +41,4 @@ instead. #include "./ros_pluginlib_plugin_provider_for_plugin_providers.hpp" -#endif // qt_gui_cpp__RosPluginlibPluginProvider_ForPluginProviders_H +#endif // QT_GUI_CPP__ROS_PLUGINLIB_PLUGIN_PROVIDER_FOR_PLUGIN_PROVIDERS_H_ diff --git a/qt_gui_cpp/include/qt_gui_cpp/ros_pluginlib_plugin_provider_for_plugin_providers.hpp b/qt_gui_cpp/include/qt_gui_cpp/ros_pluginlib_plugin_provider_for_plugin_providers.hpp index 8be2b2df..4d71bd20 100644 --- a/qt_gui_cpp/include/qt_gui_cpp/ros_pluginlib_plugin_provider_for_plugin_providers.hpp +++ b/qt_gui_cpp/include/qt_gui_cpp/ros_pluginlib_plugin_provider_for_plugin_providers.hpp @@ -30,8 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef qt_gui_cpp__RosPluginlibPluginProvider_ForPluginProviders_HPP -#define qt_gui_cpp__RosPluginlibPluginProvider_ForPluginProviders_HPP +#ifndef QT_GUI_CPP__ROS_PLUGINLIB_PLUGIN_PROVIDER_FOR_PLUGIN_PROVIDERS_HPP_ +#define QT_GUI_CPP__ROS_PLUGINLIB_PLUGIN_PROVIDER_FOR_PLUGIN_PROVIDERS_HPP_ #include "plugin_provider.hpp" #include "ros_pluginlib_plugin_provider.hpp" @@ -41,6 +41,6 @@ namespace qt_gui_cpp typedef RosPluginlibPluginProvider RosPluginlibPluginProvider_ForPluginProviders; -} // namespace +} // namespace qt_gui_cpp -#endif // qt_gui_cpp__RosPluginlibPluginProvider_ForPluginProviders_HPP +#endif // QT_GUI_CPP__ROS_PLUGINLIB_PLUGIN_PROVIDER_FOR_PLUGIN_PROVIDERS_HPP_ diff --git a/qt_gui_cpp/include/qt_gui_cpp/ros_pluginlib_plugin_provider_for_plugins.h b/qt_gui_cpp/include/qt_gui_cpp/ros_pluginlib_plugin_provider_for_plugins.h index d87e6bd3..260a5d14 100644 --- a/qt_gui_cpp/include/qt_gui_cpp/ros_pluginlib_plugin_provider_for_plugins.h +++ b/qt_gui_cpp/include/qt_gui_cpp/ros_pluginlib_plugin_provider_for_plugins.h @@ -30,8 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef qt_gui_cpp__RosPluginlibPluginProvider_ForPlugins_H -#define qt_gui_cpp__RosPluginlibPluginProvider_ForPlugins_H +#ifndef QT_GUI_CPP__ROS_PLUGINLIB_PLUGIN_PROVIDER_FOR_PLUGINS_H_ +#define QT_GUI_CPP__ROS_PLUGINLIB_PLUGIN_PROVIDER_FOR_PLUGINS_H_ // *INDENT-OFF* (prevent uncrustify from adding indention below) #warning Including header is deprecated, \ @@ -40,4 +40,4 @@ include instead. #include "./ros_pluginlib_plugin_provider_for_plugins.hpp" -#endif // qt_gui_cpp__RosPluginlibPluginProvider_ForPlugins_H +#endif // QT_GUI_CPP__ROS_PLUGINLIB_PLUGIN_PROVIDER_FOR_PLUGINS_H_ diff --git a/qt_gui_cpp/include/qt_gui_cpp/ros_pluginlib_plugin_provider_for_plugins.hpp b/qt_gui_cpp/include/qt_gui_cpp/ros_pluginlib_plugin_provider_for_plugins.hpp index 09f96ea2..f07d8842 100644 --- a/qt_gui_cpp/include/qt_gui_cpp/ros_pluginlib_plugin_provider_for_plugins.hpp +++ b/qt_gui_cpp/include/qt_gui_cpp/ros_pluginlib_plugin_provider_for_plugins.hpp @@ -30,8 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef qt_gui_cpp__RosPluginlibPluginProvider_ForPlugins_HPP -#define qt_gui_cpp__RosPluginlibPluginProvider_ForPlugins_HPP +#ifndef QT_GUI_CPP__ROS_PLUGINLIB_PLUGIN_PROVIDER_FOR_PLUGINS_HPP_ +#define QT_GUI_CPP__ROS_PLUGINLIB_PLUGIN_PROVIDER_FOR_PLUGINS_HPP_ #include "plugin.hpp" #include "ros_pluginlib_plugin_provider.hpp" @@ -41,6 +41,6 @@ namespace qt_gui_cpp typedef RosPluginlibPluginProvider RosPluginlibPluginProvider_ForPlugins; -} // namespace +} // namespace qt_gui_cpp -#endif // qt_gui_cpp__RosPluginlibPluginProvider_ForPlugins_HPP +#endif // QT_GUI_CPP__ROS_PLUGINLIB_PLUGIN_PROVIDER_FOR_PLUGINS_HPP_ diff --git a/qt_gui_cpp/include/qt_gui_cpp/settings.h b/qt_gui_cpp/include/qt_gui_cpp/settings.h index b7397afd..6f939d0e 100644 --- a/qt_gui_cpp/include/qt_gui_cpp/settings.h +++ b/qt_gui_cpp/include/qt_gui_cpp/settings.h @@ -30,8 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef qt_gui_cpp__Settings_H -#define qt_gui_cpp__Settings_H +#ifndef QT_GUI_CPP__SETTINGS_H_ +#define QT_GUI_CPP__SETTINGS_H_ // *INDENT-OFF* (prevent uncrustify from adding indention below) #warning Including header is deprecated, \ @@ -40,4 +40,4 @@ include instead. #include "./settings.hpp" -#endif // qt_gui_cpp__Settings_H +#endif // QT_GUI_CPP__SETTINGS_H_ diff --git a/qt_gui_cpp/include/qt_gui_cpp/settings.hpp b/qt_gui_cpp/include/qt_gui_cpp/settings.hpp index d819e5d2..5dee140a 100644 --- a/qt_gui_cpp/include/qt_gui_cpp/settings.hpp +++ b/qt_gui_cpp/include/qt_gui_cpp/settings.hpp @@ -30,10 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef qt_gui_cpp__Settings_HPP -#define qt_gui_cpp__Settings_HPP - -#include "generic_proxy.hpp" +#ifndef QT_GUI_CPP__SETTINGS_HPP_ +#define QT_GUI_CPP__SETTINGS_HPP_ #include #include @@ -46,18 +44,17 @@ #if __GNUC__ >= 9 # pragma GCC diagnostic pop #endif +#include "generic_proxy.hpp" namespace qt_gui_cpp { class Settings { - public: + explicit Settings(QObject * obj); - Settings(QObject* obj); - - Settings getSettings(const QString& prefix); + Settings getSettings(const QString & prefix); QStringList allKeys() const; @@ -69,24 +66,21 @@ class Settings QStringList childKeys() const; - bool contains(const QString& key) const; + bool contains(const QString & key) const; // void endArray(); - void remove(const QString& key); + void remove(const QString & key); // void setArrayIndex(int i); - void setValue(const QString& key, const QVariant& value); + void setValue(const QString & key, const QVariant & value); - QVariant value(const QString& key, const QVariant& defaultValue = QVariant()) const; + QVariant value(const QString & key, const QVariant & defaultValue = QVariant()) const; protected: - GenericProxy proxy_; - }; +} // namespace qt_gui_cpp -} // namespace - -#endif // qt_gui_cpp__Settings_HPP +#endif // QT_GUI_CPP__SETTINGS_HPP_ diff --git a/qt_gui_cpp/package.xml b/qt_gui_cpp/package.xml index 41d16cd3..f1e5ff13 100644 --- a/qt_gui_cpp/package.xml +++ b/qt_gui_cpp/package.xml @@ -27,6 +27,8 @@ tinyxml2_vendor ament_cmake_pytest + ament_lint_auto + ament_lint_common ament_cmake diff --git a/qt_gui_cpp/src/qt_gui_cpp/composite_plugin_provider.cpp b/qt_gui_cpp/src/qt_gui_cpp/composite_plugin_provider.cpp index b4d9274c..6c571e9d 100644 --- a/qt_gui_cpp/src/qt_gui_cpp/composite_plugin_provider.cpp +++ b/qt_gui_cpp/src/qt_gui_cpp/composite_plugin_provider.cpp @@ -34,59 +34,62 @@ #include -namespace qt_gui_cpp { +namespace qt_gui_cpp +{ -CompositePluginProvider::CompositePluginProvider(const QList& plugin_providers) - : PluginProvider() +CompositePluginProvider::CompositePluginProvider(const QList & plugin_providers) +: PluginProvider() , plugin_providers_(plugin_providers) {} CompositePluginProvider::~CompositePluginProvider() { - for (QList::iterator it = plugin_providers_.begin(); it != plugin_providers_.end(); it++) + for (QList::iterator it = plugin_providers_.begin(); + it != plugin_providers_.end(); it++) { delete *it; } } -void CompositePluginProvider::set_plugin_providers(const QList& plugin_providers) +void CompositePluginProvider::set_plugin_providers(const QList & plugin_providers) { // garbage old plugin providers - for (QList::iterator it = plugin_providers_.begin(); it != plugin_providers_.end(); it++) + for (QList::iterator it = plugin_providers_.begin(); + it != plugin_providers_.end(); it++) { delete *it; } plugin_providers_ = plugin_providers; } -QList CompositePluginProvider::discover_descriptors(QObject* discovery_data) +QList CompositePluginProvider::discover_descriptors(QObject * discovery_data) { // discover plugins from all providers - QList descriptors; - for (QList::iterator it = plugin_providers_.begin(); it != plugin_providers_.end(); it++) + QList descriptors; + for (QList::iterator it = plugin_providers_.begin(); + it != plugin_providers_.end(); it++) { - QList sub_descriptors; - try - { + QList sub_descriptors; + try { sub_descriptors = (*it)->discover_descriptors(discovery_data); - } - catch (std::runtime_error e) - { - // TODO: add name of plugin provider to error message - qCritical("CompositePluginProvider::discover() could not discover plugins from provider - runtime_error:\n%s", e.what()); + } catch (std::runtime_error e) { + // TODO(someone): add name of plugin provider to error message + qCritical( + "CompositePluginProvider::discover() could not discover plugins from provider - " + "runtime_error:\n%s", + e.what()); continue; - } - catch (...) - { - // TODO: add name of plugin provider to error message + } catch (...) { + // TODO(someone): add name of plugin provider to error message qCritical("CompositePluginProvider::discover() could not discover plugins from provider"); continue; } QSet plugin_ids; - for (QList::iterator jt = sub_descriptors.begin(); jt != sub_descriptors.end(); jt++) + for (QList::iterator jt = sub_descriptors.begin(); + jt != sub_descriptors.end(); jt++) { - PluginDescriptor* descriptor = *jt; + PluginDescriptor * descriptor = *jt; descriptors.append(descriptor); plugin_ids.insert(descriptor->pluginId()); } @@ -95,23 +98,21 @@ QList CompositePluginProvider::discover_descriptors(QObject* return descriptors; } -void* CompositePluginProvider::load(const QString& plugin_id, PluginContext* plugin_context) +void * CompositePluginProvider::load(const QString & plugin_id, PluginContext * plugin_context) { // dispatch load to appropriate provider - for (QMap >::iterator it = discovered_plugins_.begin(); it != discovered_plugins_.end(); it++) + for (QMap>::iterator it = discovered_plugins_.begin(); + it != discovered_plugins_.end(); it++) { - if (it.value().contains(plugin_id)) - { - PluginProvider* plugin_provider = it.key(); - try - { - void* instance = plugin_provider->load(plugin_id, plugin_context); + if (it.value().contains(plugin_id)) { + PluginProvider * plugin_provider = it.key(); + try { + void * instance = plugin_provider->load(plugin_id, plugin_context); running_plugins_[instance] = plugin_provider; return instance; - } - catch (std::exception& e) - { - qWarning("CompositePluginProvider::load(%s) failed loading plugin (%s)", plugin_id.toStdString().c_str(), e.what()); + } catch (std::exception & e) { + qWarning("CompositePluginProvider::load(%s) failed loading plugin (%s)", + plugin_id.toStdString().c_str(), e.what()); return 0; } } @@ -119,22 +120,21 @@ void* CompositePluginProvider::load(const QString& plugin_id, PluginContext* plu return 0; } -Plugin* CompositePluginProvider::load_plugin(const QString& plugin_id, PluginContext* plugin_context) +Plugin * CompositePluginProvider::load_plugin( + const QString & plugin_id, + PluginContext * plugin_context) { // dispatch load to appropriate provider - for (QMap >::iterator it = discovered_plugins_.begin(); it != discovered_plugins_.end(); it++) + for (QMap>::iterator it = discovered_plugins_.begin(); + it != discovered_plugins_.end(); it++) { - if (it.value().contains(plugin_id)) - { - PluginProvider* plugin_provider = it.key(); - try - { - Plugin* instance = plugin_provider->load_plugin(plugin_id, plugin_context); + if (it.value().contains(plugin_id)) { + PluginProvider * plugin_provider = it.key(); + try { + Plugin * instance = plugin_provider->load_plugin(plugin_id, plugin_context); running_plugins_[instance] = plugin_provider; return instance; - } - catch (std::exception& e) - { + } catch (std::exception & e) { // error message will be generated by python } } @@ -142,12 +142,11 @@ Plugin* CompositePluginProvider::load_plugin(const QString& plugin_id, PluginCon return 0; } -void CompositePluginProvider::unload(void* plugin_instance) +void CompositePluginProvider::unload(void * plugin_instance) { // dispatch unload to appropriate provider - QMap::iterator it = running_plugins_.find(plugin_instance); - if (it != running_plugins_.end()) - { + QMap::iterator it = running_plugins_.find(plugin_instance); + if (it != running_plugins_.end()) { (*it)->unload(plugin_instance); running_plugins_.remove(it.key()); return; @@ -157,10 +156,10 @@ void CompositePluginProvider::unload(void* plugin_instance) void CompositePluginProvider::shutdown() { - for (QList::iterator it = plugin_providers_.begin(); it != plugin_providers_.end(); it++) + for (QList::iterator it = plugin_providers_.begin(); + it != plugin_providers_.end(); it++) { (*it)->shutdown(); } } - -} // namespace +} // namespace qt_gui_cpp diff --git a/qt_gui_cpp/src/qt_gui_cpp/generic_proxy.cpp b/qt_gui_cpp/src/qt_gui_cpp/generic_proxy.cpp index cd9b95f9..336c7f0f 100644 --- a/qt_gui_cpp/src/qt_gui_cpp/generic_proxy.cpp +++ b/qt_gui_cpp/src/qt_gui_cpp/generic_proxy.cpp @@ -34,34 +34,45 @@ #include -namespace qt_gui_cpp { +namespace qt_gui_cpp +{ -GenericProxy::GenericProxy(QObject* obj) - : object_(obj) +GenericProxy::GenericProxy(QObject * obj) +: object_(obj) {} -QObject* GenericProxy::proxiedObject() +QObject * GenericProxy::proxiedObject() { return object_; } -void GenericProxy::setProxiedObject(QObject* obj) +void GenericProxy::setProxiedObject(QObject * obj) { object_ = obj; } -bool GenericProxy::invokeMethod(const char* member, QGenericArgument val0, QGenericArgument val1, QGenericArgument val2, QGenericArgument val3, QGenericArgument val4, QGenericArgument val5, QGenericArgument val6, QGenericArgument val7, QGenericArgument val8, QGenericArgument val9) +bool GenericProxy::invokeMethod( + const char * member, QGenericArgument val0, QGenericArgument val1, + QGenericArgument val2, QGenericArgument val3, QGenericArgument val4, QGenericArgument val5, + QGenericArgument val6, QGenericArgument val7, QGenericArgument val8, QGenericArgument val9) { - if (!object_) return false; - //qDebug("GenericProxy::invokeMethod(%s, %s)", object_->objectName().toStdString().c_str(), member); - return QMetaObject::invokeMethod(object_, member, Qt::DirectConnection, val0, val1, val2, val3, val4, val5, val6, val7, val8, val9); + if (!object_) {return false;} + // qDebug("GenericProxy::invokeMethod(%s, %s)", + // object_->objectName().toStdString().c_str(), member); + return QMetaObject::invokeMethod(object_, member, Qt::DirectConnection, val0, val1, val2, val3, + val4, val5, val6, val7, val8, val9); } -bool GenericProxy::invokeMethodWithReturn(const char* member, QGenericReturnArgument ret, QGenericArgument val0, QGenericArgument val1, QGenericArgument val2, QGenericArgument val3, QGenericArgument val4, QGenericArgument val5, QGenericArgument val6, QGenericArgument val7, QGenericArgument val8, QGenericArgument val9) +bool GenericProxy::invokeMethodWithReturn( + const char * member, QGenericReturnArgument ret, + QGenericArgument val0, QGenericArgument val1, QGenericArgument val2, QGenericArgument val3, + QGenericArgument val4, QGenericArgument val5, QGenericArgument val6, QGenericArgument val7, + QGenericArgument val8, QGenericArgument val9) { - if (!object_) return false; - //qDebug("GenericProxy::invokeMethodWithReturn(%s, %s)", object_->objectName().toStdString().c_str(), member); - return QMetaObject::invokeMethod(object_, member, Qt::DirectConnection, ret, val0, val1, val2, val3, val4, val5, val6, val7, val8, val9); + if (!object_) {return false;} + // qDebug("GenericProxy::invokeMethodWithReturn(%s, %s)", + // object_->objectName().toStdString().c_str(), member); + return QMetaObject::invokeMethod(object_, member, Qt::DirectConnection, ret, val0, val1, val2, + val3, val4, val5, val6, val7, val8, val9); } - -} // namespace +} // namespace qt_gui_cpp diff --git a/qt_gui_cpp/src/qt_gui_cpp/plugin_bridge.cpp b/qt_gui_cpp/src/qt_gui_cpp/plugin_bridge.cpp index a8df5456..553b292b 100644 --- a/qt_gui_cpp/src/qt_gui_cpp/plugin_bridge.cpp +++ b/qt_gui_cpp/src/qt_gui_cpp/plugin_bridge.cpp @@ -37,23 +37,25 @@ #include -namespace qt_gui_cpp { +namespace qt_gui_cpp +{ PluginBridge::PluginBridge() - : QObject() +: QObject() , provider_(0) , plugin_(0) { setObjectName("PluginBridge"); } -bool PluginBridge::load_plugin(PluginProvider* provider, const QString& plugin_id, PluginContext* plugin_context) +bool PluginBridge::load_plugin( + PluginProvider * provider, const QString & plugin_id, + PluginContext * plugin_context) { qDebug("PluginBridge::load_plugin() %s", plugin_id.toStdString().c_str()); provider_ = provider; plugin_ = provider_->load_plugin(plugin_id, plugin_context); - if (plugin_) - { + if (plugin_) { plugin_->installEventFilter(this); } return plugin_ != 0; @@ -68,8 +70,7 @@ void PluginBridge::unload_plugin() bool PluginBridge::has_configuration() const { - if (plugin_) - { + if (plugin_) { return plugin_->hasConfiguration(); } return false; @@ -77,39 +78,34 @@ bool PluginBridge::has_configuration() const void PluginBridge::trigger_configuration() { - if (plugin_) - { + if (plugin_) { plugin_->triggerConfiguration(); } } void PluginBridge::shutdown_plugin() { - if (plugin_) - { + if (plugin_) { plugin_->removeEventFilter(this); plugin_->shutdownPlugin(); } } -void PluginBridge::save_settings(QObject* plugin_settings, QObject* instance_settings) +void PluginBridge::save_settings(QObject * plugin_settings, QObject * instance_settings) { - if (plugin_) - { + if (plugin_) { Settings plugin(plugin_settings); Settings instance(instance_settings); plugin_->saveSettings(plugin, instance); } } -void PluginBridge::restore_settings(QObject* plugin_settings, QObject* instance_settings) +void PluginBridge::restore_settings(QObject * plugin_settings, QObject * instance_settings) { - if (plugin_) - { + if (plugin_) { Settings plugin(plugin_settings); Settings instance(instance_settings); plugin_->restoreSettings(plugin, instance); } } - -} // namespace +} // namespace qt_gui_cpp diff --git a/qt_gui_cpp/src/qt_gui_cpp/plugin_context.cpp b/qt_gui_cpp/src/qt_gui_cpp/plugin_context.cpp index 28986e4c..998004a4 100644 --- a/qt_gui_cpp/src/qt_gui_cpp/plugin_context.cpp +++ b/qt_gui_cpp/src/qt_gui_cpp/plugin_context.cpp @@ -34,17 +34,18 @@ #include -namespace qt_gui_cpp { +namespace qt_gui_cpp +{ -PluginContext::PluginContext(QObject* obj, int serial_number, const QStringList& argv) - : QObject(obj) +PluginContext::PluginContext(QObject * obj, int serial_number, const QStringList & argv) +: QObject(obj) , proxy_(obj) , serial_number_(serial_number) , argv_(argv) {} -PluginContext::PluginContext(const PluginContext& other) - : QObject(other.parent()) +PluginContext::PluginContext(const PluginContext & other) +: QObject(other.parent()) , proxy_(other.parent()) , serial_number_(other.serial_number_) , argv_(other.argv_) @@ -55,33 +56,40 @@ int PluginContext::serialNumber() const return serial_number_; } -const QStringList& PluginContext::argv() const +const QStringList & PluginContext::argv() const { return argv_; } -void PluginContext::addWidget(QWidget* widget) +void PluginContext::addWidget(QWidget * widget) { - bool rc = proxy_.invokeMethod("add_widget", Q_ARG(QWidget*, widget)); - if (!rc) throw std::runtime_error("PluginContext::addWidget() invoke method failed"); + bool rc = proxy_.invokeMethod("add_widget", Q_ARG(QWidget *, widget)); + if (!rc) { + throw std::runtime_error("PluginContext::addWidget() invoke method failed"); + } } -void PluginContext::removeWidget(QWidget* widget) +void PluginContext::removeWidget(QWidget * widget) { - bool rc = proxy_.invokeMethod("remove_widget", Q_ARG(QWidget*, widget)); - if (!rc) throw std::runtime_error("PluginContext::removeWidget() invoke method failed"); + bool rc = proxy_.invokeMethod("remove_widget", Q_ARG(QWidget *, widget)); + if (!rc) { + throw std::runtime_error("PluginContext::removeWidget() invoke method failed"); + } } void PluginContext::closePlugin() { bool rc = proxy_.invokeMethod("close_plugin"); - if (!rc) throw std::runtime_error("PluginContext::closePlugin() invoke method failed"); + if (!rc) { + throw std::runtime_error("PluginContext::closePlugin() invoke method failed"); + } } void PluginContext::reloadPlugin() { bool rc = proxy_.invokeMethod("reload_plugin"); - if (!rc) throw std::runtime_error("PluginContext::reloadPlugin() invoke method failed"); + if (!rc) { + throw std::runtime_error("PluginContext::reloadPlugin() invoke method failed"); + } } - -} // namespace +} // namespace qt_gui_cpp diff --git a/qt_gui_cpp/src/qt_gui_cpp/plugin_descriptor.cpp b/qt_gui_cpp/src/qt_gui_cpp/plugin_descriptor.cpp index d8834a8b..ab94c29f 100644 --- a/qt_gui_cpp/src/qt_gui_cpp/plugin_descriptor.cpp +++ b/qt_gui_cpp/src/qt_gui_cpp/plugin_descriptor.cpp @@ -32,35 +32,40 @@ #include -namespace qt_gui_cpp { +namespace qt_gui_cpp +{ -PluginDescriptor::PluginDescriptor(const QString& plugin_id, const QMap& attributes) +PluginDescriptor::PluginDescriptor( + const QString & plugin_id, + const QMap & attributes) { plugin_id_ = plugin_id; attributes_ = attributes; } -const QString& PluginDescriptor::pluginId() const +const QString & PluginDescriptor::pluginId() const { return plugin_id_; } -const QMap& PluginDescriptor::attributes() const +const QMap & PluginDescriptor::attributes() const { return attributes_; } -QMap& PluginDescriptor::attributes() +QMap & PluginDescriptor::attributes() { return attributes_; } -const QMap& PluginDescriptor::actionAttributes() const +const QMap & PluginDescriptor::actionAttributes() const { return action_attributes_; } -void PluginDescriptor::setActionAttributes(const QString& label, const QString& statustip, const QString& icon, const QString& icontype) +void PluginDescriptor::setActionAttributes( + const QString & label, const QString & statustip, + const QString & icon, const QString & icontype) { action_attributes_["label"] = label; action_attributes_["statustip"] = statustip; @@ -78,7 +83,9 @@ QMap PluginDescriptor::group(int index) const return groups_[index]; } -void PluginDescriptor::addGroupAttributes(const QString& label, const QString& statustip, const QString& icon, const QString& icontype) +void PluginDescriptor::addGroupAttributes( + const QString & label, const QString & statustip, + const QString & icon, const QString & icontype) { QMap attributes; attributes["label"] = label; @@ -93,25 +100,26 @@ QMap PluginDescriptor::toDictionary() const QMap dict; QString plugin_prefix = plugin_id_ + "."; dict[plugin_prefix + "plugin_id"] = plugin_id_; - for (QMap::const_iterator it = attributes_.constBegin(); it != attributes_.constEnd(); it++) + for (QMap::const_iterator it = attributes_.constBegin(); + it != attributes_.constEnd(); it++) { dict[plugin_prefix + QString("attributes.") + it.key()] = it.value(); } - for (QMap::const_iterator it = action_attributes_.constBegin(); it != action_attributes_.constEnd(); it++) + for (QMap::const_iterator it = action_attributes_.constBegin(); + it != action_attributes_.constEnd(); it++) { dict[plugin_prefix + QString("action.") + it.key()] = it.value(); } int group_index = 1; - for (QVector >::const_iterator it = groups_.constBegin(); it != groups_.constEnd(); it++) + for (QVector>::const_iterator it = groups_.constBegin(); + it != groups_.constEnd(); it++) { QString prefix = QString("groups.") + QString::number(group_index) + QString("."); - for (QMap::const_iterator jt = it->constBegin(); jt != it->constEnd(); jt++) - { + for (QMap::const_iterator jt = it->constBegin(); jt != it->constEnd(); jt++) { dict[plugin_prefix + prefix + jt.key()] = jt.value(); } group_index++; } return dict; } - -} // namespace +} // namespace qt_gui_cpp diff --git a/qt_gui_cpp/src/qt_gui_cpp/plugin_provider.cpp b/qt_gui_cpp/src/qt_gui_cpp/plugin_provider.cpp index c4e76305..0bc61a95 100644 --- a/qt_gui_cpp/src/qt_gui_cpp/plugin_provider.cpp +++ b/qt_gui_cpp/src/qt_gui_cpp/plugin_provider.cpp @@ -32,7 +32,8 @@ #include -namespace qt_gui_cpp { +namespace qt_gui_cpp +{ PluginProvider::PluginProvider() {} @@ -40,14 +41,15 @@ PluginProvider::PluginProvider() PluginProvider::~PluginProvider() {} -QMap PluginProvider::discover(QObject* discovery_data) +QMap PluginProvider::discover(QObject * discovery_data) { QMultiMap plugins; - QList descriptors = discover_descriptors(discovery_data); - for (QList::iterator it = descriptors.begin(); it != descriptors.end(); it++) + QList descriptors = discover_descriptors(discovery_data); + for (QList::iterator it = descriptors.begin(); it != descriptors.end(); + it++) { // extract plugin descriptor dictionary - PluginDescriptor* descriptor = *it; + PluginDescriptor * descriptor = *it; QMap plugin = descriptor->toDictionary(); plugins.unite(plugin); delete descriptor; @@ -55,30 +57,29 @@ QMap PluginProvider::discover(QObject* discovery_data) return plugins; } -QList PluginProvider::discover_descriptors(QObject* discovery_data) +QList PluginProvider::discover_descriptors(QObject * discovery_data) { - return QList(); + return QList(); } -void* PluginProvider::load(const QString& plugin_id, PluginContext* plugin_context) +void * PluginProvider::load(const QString & plugin_id, PluginContext * plugin_context) { return load_plugin(plugin_id, plugin_context); } -Plugin* PluginProvider::load_plugin(const QString& plugin_id, PluginContext* plugin_context) +Plugin * PluginProvider::load_plugin(const QString & plugin_id, PluginContext * plugin_context) { return 0; } -void PluginProvider::unload(void* plugin_instance) +void PluginProvider::unload(void * plugin_instance) {} -void PluginProvider::unload_plugin(Plugin* plugin_instance) +void PluginProvider::unload_plugin(Plugin * plugin_instance) { unload(plugin_instance); } void PluginProvider::shutdown() {} - -} // namespace +} // namespace qt_gui_cpp diff --git a/qt_gui_cpp/src/qt_gui_cpp/recursive_plugin_provider.cpp b/qt_gui_cpp/src/qt_gui_cpp/recursive_plugin_provider.cpp index 55734f56..94c98f63 100644 --- a/qt_gui_cpp/src/qt_gui_cpp/recursive_plugin_provider.cpp +++ b/qt_gui_cpp/src/qt_gui_cpp/recursive_plugin_provider.cpp @@ -34,10 +34,12 @@ #include -namespace qt_gui_cpp { +namespace qt_gui_cpp +{ -RecursivePluginProvider::RecursivePluginProvider(RosPluginlibPluginProvider_ForPluginProviders* plugin_provider) - : CompositePluginProvider() +RecursivePluginProvider::RecursivePluginProvider( + RosPluginlibPluginProvider_ForPluginProviders * plugin_provider) +: CompositePluginProvider() , plugin_provider_(plugin_provider) {} @@ -46,34 +48,31 @@ RecursivePluginProvider::~RecursivePluginProvider() delete plugin_provider_; } -QMap RecursivePluginProvider::discover(QObject* discovery_data) +QMap RecursivePluginProvider::discover(QObject * discovery_data) { // discover plugins, which are providers themselves - QList descriptors = plugin_provider_->discover_descriptors(discovery_data); + QList descriptors = plugin_provider_->discover_descriptors(discovery_data); QList plugin_ids; - for (QList::iterator it = descriptors.begin(); it != descriptors.end(); it++) + for (QList::iterator it = descriptors.begin(); it != descriptors.end(); + it++) { - PluginDescriptor* descriptor = *it; + PluginDescriptor * descriptor = *it; plugin_ids.append(descriptor->pluginId()); delete descriptor; } // instantiate plugins - for (QList::iterator it = plugin_ids.begin(); it != plugin_ids.end(); it++) - { - try - { + for (QList::iterator it = plugin_ids.begin(); it != plugin_ids.end(); it++) { + try { // pass NULL as PluginContext for PluginProviders - PluginProvider* instance = plugin_provider_->load_explicit_type(*it, 0); - if (instance == 0) - { + PluginProvider * instance = plugin_provider_->load_explicit_type(*it, 0); + if (instance == 0) { throw std::runtime_error("load returned None"); } providers_.append(instance); - } - catch (...) - { - qCritical("RecursivePluginProvider.discover() loading plugin '%s' failed", it->toStdString().c_str()); + } catch (...) { + qCritical("RecursivePluginProvider.discover() loading plugin '%s' failed", + it->toStdString().c_str()); } } @@ -84,11 +83,9 @@ QMap RecursivePluginProvider::discover(QObject* discovery_data void RecursivePluginProvider::shutdown() { - for (QList::iterator it = providers_.begin(); it != providers_.end(); it++) - { + for (QList::iterator it = providers_.begin(); it != providers_.end(); it++) { plugin_provider_->unload(*it); } CompositePluginProvider::shutdown(); } - -} // namespace +} // namespace qt_gui_cpp diff --git a/qt_gui_cpp/src/qt_gui_cpp/settings.cpp b/qt_gui_cpp/src/qt_gui_cpp/settings.cpp index ea89d0b7..7a0473a4 100644 --- a/qt_gui_cpp/src/qt_gui_cpp/settings.cpp +++ b/qt_gui_cpp/src/qt_gui_cpp/settings.cpp @@ -34,70 +34,92 @@ #include -namespace qt_gui_cpp { +namespace qt_gui_cpp +{ -Settings::Settings(QObject* obj) - : proxy_(obj) +Settings::Settings(QObject * obj) +: proxy_(obj) {} -Settings Settings::getSettings(const QString& prefix) +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 = 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(this)->proxy_.invokeMethodWithReturn("all_keys", Q_RETURN_ARG(QStringList, list)); - if (!rc) throw std::runtime_error("Settings::all_keys() invoke method failed"); + bool rc = const_cast(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(this)->proxy_.invokeMethodWithReturn("child_groups", Q_RETURN_ARG(QStringList, list)); - if (!rc) throw std::runtime_error("Settings::child_groups() invoke method failed"); + bool rc = const_cast(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(this)->proxy_.invokeMethodWithReturn("child_keys", Q_RETURN_ARG(QStringList, list)); - if (!rc) throw std::runtime_error("Settings::child_keys() invoke method failed"); + bool rc = const_cast(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 Settings::contains(const QString & key) const { bool flag = false; - bool rc = const_cast(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 = const_cast(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) +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"); + if (!rc) { + throw std::runtime_error("Settings::remove() invoke method failed"); + } } -void Settings::setValue(const QString& key, const QVariant& value) +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"); + if (!rc) { + throw std::runtime_error("Settings::set_value() invoke method failed"); + } } -QVariant Settings::value(const QString& key, const QVariant& defaultValue) const +QVariant Settings::value(const QString & key, const QVariant & defaultValue) const { QVariant val; - bool rc = const_cast(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 = const_cast(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 +} // namespace qt_gui_cpp diff --git a/qt_gui_cpp/src/qt_gui_cpp_shiboken/CMakeLists.txt b/qt_gui_cpp/src/qt_gui_cpp_shiboken/CMakeLists.txt index e19e12fb..4742615b 100644 --- a/qt_gui_cpp/src/qt_gui_cpp_shiboken/CMakeLists.txt +++ b/qt_gui_cpp/src/qt_gui_cpp_shiboken/CMakeLists.txt @@ -45,13 +45,23 @@ ament_export_dependencies(pluginlib) if(shiboken_helper_FOUND) if(Shiboken_VERSION VERSION_GREATER "1.1.1") # shiboken 1.1.2 and higher will segfault until https://bugreports.qt-project.org/browse/PYSIDE-218 is fixed - message(WARNING "Shiboken version ${Shiboken_VERSION} would segfault when trying to process qt_gui_cpp (see https://bugreports.qt-project.org/browse/PYSIDE-218). Therefore shiboken bindings are being skipped.") + message(WARNING "Shiboken version ${Shiboken_VERSION} would segfault when trying to process qt_gui_cpp " + "(see https://bugreports.qt-project.org/browse/PYSIDE-218)" + " Therefore shiboken bindings are being skipped.") else() 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}") + 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}") shiboken_include_directories(qt_gui_cpp_shiboken "${qt_gui_cpp_shiboken_QT_COMPONENTS}") diff --git a/qt_gui_cpp/src/qt_gui_cpp_shiboken/global.h b/qt_gui_cpp/src/qt_gui_cpp_shiboken/global.h index 655e5786..fb6be93e 100644 --- a/qt_gui_cpp/src/qt_gui_cpp_shiboken/global.h +++ b/qt_gui_cpp/src/qt_gui_cpp_shiboken/global.h @@ -30,6 +30,9 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#ifndef QT_GUI_CPP_SHIBOKEN__GLOBAL_H_ +#define QT_GUI_CPP_SHIBOKEN__GLOBAL_H_ + #ifndef NULL #define NULL 0 #endif @@ -50,3 +53,5 @@ #include #include #include + +#endif // QT_GUI_CPP_SHIBOKEN__GLOBAL_H_