Skip to content

Commit

Permalink
Fix image display test (#468)
Browse files Browse the repository at this point in the history
Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
  • Loading branch information
jennuine committed Aug 19, 2022
1 parent d27c387 commit d43ea6a
Show file tree
Hide file tree
Showing 5 changed files with 515 additions and 149 deletions.
3 changes: 1 addition & 2 deletions src/plugins/image_display/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ ign_gui_add_plugin(ImageDisplay
QT_HEADERS
ImageDisplay.hh
TEST_SOURCES
# ImageDisplay_TEST.cc
ImageDisplay_TEST.cc
)

40 changes: 6 additions & 34 deletions src/plugins/image_display/ImageDisplay.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@

#include "ImageDisplay.hh"

#include <QQuickImageProvider>

#include <algorithm>
#include <iostream>
#include <limits>
#include <string>
Expand All @@ -39,37 +36,6 @@ namespace gui
{
namespace plugins
{
class ImageProvider : public QQuickImageProvider
{
public: ImageProvider()
: QQuickImageProvider(QQuickImageProvider::Image)
{
}

public: QImage requestImage(const QString &, QSize *,
const QSize &) override
{
if (!this->img.isNull())
{
// Must return a copy
QImage copy(this->img);
return copy;
}

// Placeholder in case we have no image yet
QImage i(400, 400, QImage::Format_RGB888);
i.fill(QColor(128, 128, 128, 100));
return i;
}

public: void SetImage(const QImage &_image)
{
this->img = _image;
}

private: QImage img;
};

class ImageDisplayPrivate
{
/// \brief List of topics publishing image messages.
Expand Down Expand Up @@ -184,7 +150,11 @@ void ImageDisplay::OnTopic(const QString _topic)
{
auto topic = _topic.toStdString();
if (topic.empty())
{
// LCOV_EXCL_START
return;
// LCOV_EXCL_STOP
}

// Unsubscribe
auto subs = this->dataPtr->node.SubscribedTopics();
Expand All @@ -195,8 +165,10 @@ void ImageDisplay::OnTopic(const QString _topic)
if (!this->dataPtr->node.Subscribe(topic, &ImageDisplay::OnImageMsg,
this))
{
// LCOV_EXCL_START
ignerr << "Unable to subscribe to topic [" << topic << "]" << std::endl;
return;
// LCOV_EXCL_STOP
}
App()->findChild<MainWindow *>()->notifyWithDuration(
QString::fromStdString("Subscribed to: <b>" + topic + "</b>"), 4000);
Expand Down
46 changes: 45 additions & 1 deletion src/plugins/image_display/ImageDisplay.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
#ifndef IGNITION_GUI_PLUGINS_IMAGEDISPLAY_HH_
#define IGNITION_GUI_PLUGINS_IMAGEDISPLAY_HH_

#include <algorithm>
#include <memory>
#include <QQuickImageProvider>

#ifdef _MSC_VER
#pragma warning(push, 0)
#endif
Expand All @@ -27,6 +30,16 @@
#pragma warning(pop)
#endif

#ifndef _WIN32
# define ImageDisplay_EXPORTS_API
#else
# if (defined(ImageDisplay_EXPORTS))
# define ImageDisplay_EXPORTS_API __declspec(dllexport)
# else
# define ImageDisplay_EXPORTS_API __declspec(dllimport)
# endif
#endif

#include "ignition/gui/Plugin.hh"

namespace ignition
Expand All @@ -37,14 +50,45 @@ namespace plugins
{
class ImageDisplayPrivate;

class ImageProvider : public QQuickImageProvider
{
public: ImageProvider()
: QQuickImageProvider(QQuickImageProvider::Image)
{
}

public: QImage requestImage(const QString &, QSize *,
const QSize &) override
{
if (!this->img.isNull())
{
// Must return a copy
QImage copy(this->img);
return copy;
}

// Placeholder in case we have no image yet
QImage i(400, 400, QImage::Format_RGB888);
i.fill(QColor(128, 128, 128, 100));
return i;
}

public: void SetImage(const QImage &_image)
{
this->img = _image;
}

private: QImage img;
};

/// \brief Display images coming through an Ignition transport topic.
///
/// ## Configuration
///
/// \<topic\> : Set the topic to receive image messages.
/// \<topic_picker\> : Whether to show the topic picker, true by default. If
/// this is false, a \<topic\> must be specified.
class ImageDisplay : public Plugin
class ImageDisplay_EXPORTS_API ImageDisplay : public Plugin
{
Q_OBJECT

Expand Down
2 changes: 2 additions & 0 deletions src/plugins/image_display/ImageDisplay.qml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Rectangle {
RowLayout {
visible: showPicker
RoundButton {
objectName: "refreshButton"
text: "\u21bb"
Material.background: Material.primary
onClicked: {
Expand All @@ -72,6 +73,7 @@ Rectangle {
}
ComboBox {
id: combo
objectName: "topicsCombo"
Layout.fillWidth: true
model: ImageDisplay.topicList
onCurrentIndexChanged: {
Expand Down
Loading

0 comments on commit d43ea6a

Please sign in to comment.