diff --git a/src/plugins/image_display/ImageDisplay.cc b/src/plugins/image_display/ImageDisplay.cc index 404c48a7b..d70122754 100644 --- a/src/plugins/image_display/ImageDisplay.cc +++ b/src/plugins/image_display/ImageDisplay.cc @@ -51,19 +51,33 @@ class ImageDisplay::Implementation /// \brief To provide images for QML. public: ImageProvider *provider{nullptr}; + + /// \brief Holds the provider name unique to this plugin instance + public: QString providerName; }; ///////////////////////////////////////////////// ImageDisplay::ImageDisplay() : dataPtr(gz::utils::MakeUniqueImpl()) { + this->dataPtr->provider = new ImageProvider(); } ///////////////////////////////////////////////// ImageDisplay::~ImageDisplay() { - App()->Engine()->removeImageProvider( - this->CardItem()->objectName() + "imagedisplay"); + App()->Engine()->removeImageProvider(this->ImageProviderName()); +} + +void ImageDisplay::RegisterImageProvider(const QString &_uniqueName) +{ + this->dataPtr->providerName = _uniqueName; + App()->Engine()->addImageProvider(_uniqueName, + this->dataPtr->provider); +} + +QString ImageDisplay::ImageProviderName() { + return this->dataPtr->providerName; } ///////////////////////////////////////////////// @@ -95,13 +109,11 @@ void ImageDisplay::LoadConfig(const tinyxml2::XMLElement *_pluginElem) this->PluginItem()->setProperty("showPicker", topicPicker); if (!topic.empty()) - this->OnTopic(QString::fromStdString(topic)); + { + this->SetTopicList({QString::fromStdString(topic)}); + } else this->OnRefresh(); - - this->dataPtr->provider = new ImageProvider(); - App()->Engine()->addImageProvider( - this->CardItem()->objectName() + "imagedisplay", this->dataPtr->provider); } ///////////////////////////////////////////////// diff --git a/src/plugins/image_display/ImageDisplay.hh b/src/plugins/image_display/ImageDisplay.hh index e89754537..0a110c59c 100644 --- a/src/plugins/image_display/ImageDisplay.hh +++ b/src/plugins/image_display/ImageDisplay.hh @@ -18,8 +18,9 @@ #ifndef GZ_GUI_PLUGINS_IMAGEDISPLAY_HH_ #define GZ_GUI_PLUGINS_IMAGEDISPLAY_HH_ -#include -#include +#include +#include +#include #include #include @@ -53,8 +54,7 @@ namespace gz::gui::plugins if (!this->img.isNull()) { // Must return a copy - QImage copy(this->img); - return copy; + return this->img; } // Placeholder in case we have no image yet @@ -115,6 +115,13 @@ namespace gz::gui::plugins /// \param[in] _topicList Message type public: Q_INVOKABLE void SetTopicList(const QStringList &_topicList); + /// \brief Register the image provider with the given name + /// \param[in] _uniqueName Unique name for the provider to be registered + public: Q_INVOKABLE void RegisterImageProvider(const QString &_uniqueName); + + /// \brief Get the provider name unique to this plugin instance + public: Q_INVOKABLE QString ImageProviderName(); + /// \brief Notify that topic list has changed signals: void TopicListChanged(); diff --git a/src/plugins/image_display/ImageDisplay.qml b/src/plugins/image_display/ImageDisplay.qml index 48d1191a6..0fa6ab326 100644 --- a/src/plugins/image_display/ImageDisplay.qml +++ b/src/plugins/image_display/ImageDisplay.qml @@ -44,6 +44,7 @@ Rectangle { return; uniqueName = parent.card().objectName + "imagedisplay"; + ImageDisplay.RegisterImageProvider(uniqueName); image.reload(); } diff --git a/src/plugins/world_stats/WorldStats.qml b/src/plugins/world_stats/WorldStats.qml index ef8cf673f..b6e8739cc 100644 --- a/src/plugins/world_stats/WorldStats.qml +++ b/src/plugins/world_stats/WorldStats.qml @@ -93,7 +93,7 @@ Rectangle { } PropertyChanges { target: hideButton - x: worldStats.width - hideToolButton.width - compactLabel.width - 10 + x: worldStats.width - hideToolButton.width - compactLabel.implicitWidth - 10 } PropertyChanges { target: compactLabel