Skip to content

Commit

Permalink
add missing helper test class
Browse files Browse the repository at this point in the history
Signed-off-by: Ashton Larkin <ashton@openrobotics.org>
  • Loading branch information
adlarkin committed Nov 3, 2021
1 parent 84887d0 commit 4148b9a
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/plugins/world_control/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ign_gui_add_plugin(WorldControl
SOURCES
WorldControl.cc
WorldControlEventListener.cc
QT_HEADERS
WorldControl.hh
WorldControlEventListener.hh
Expand Down
48 changes: 48 additions & 0 deletions src/plugins/world_control/WorldControlEventListener.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2021 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#include "WorldControlEventListener.hh"

using namespace ignition;
using namespace gui;

WorldControlEventListener::WorldControlEventListener()
{
ignition::gui::App()->findChild<
ignition::gui::MainWindow *>()->installEventFilter(this);
}

WorldControlEventListener::~WorldControlEventListener() = default;

bool WorldControlEventListener::eventFilter(QObject *_obj, QEvent *_event)
{
if (_event->type() == ignition::gui::events::WorldControl::kType)
{
auto worldControlEvent =
reinterpret_cast<gui::events::WorldControl *>(_event);
if (worldControlEvent)
{
this->listenedToPlay = !worldControlEvent->WorldControlInfo().pause();
this->listenedToPause = worldControlEvent->WorldControlInfo().pause();
this->listenedToStep =
worldControlEvent->WorldControlInfo().multi_step() > 0u;
}
}

// Standard event processing
return QObject::eventFilter(_obj, _event);
}
58 changes: 58 additions & 0 deletions src/plugins/world_control/WorldControlEventListener.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (C) 2021 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef IGNITION_GUI_WORLDCONTROLEVENTLISTENER_HH_
#define IGNITION_GUI_WORLDCONTROLEVENTLISTENER_HH_

#include "ignition/gui/Application.hh"
#include "ignition/gui/Export.hh"
#include "ignition/gui/GuiEvents.hh"
#include "ignition/gui/MainWindow.hh"
#include "ignition/gui/qt.h"

namespace ignition
{
namespace gui
{
/// \brief Helper class for testing listening to events emitted by the
/// WorldControl plugin. This is used for testing the event behavior of
/// the WorldControl plugin.
class IGNITION_GUI_VISIBLE WorldControlEventListener : public QObject
{
Q_OBJECT

/// \brief Constructor
public: WorldControlEventListener();

/// \brief Destructor
public: virtual ~WorldControlEventListener() override;

// Documentation inherited
protected: bool eventFilter(QObject *_obj, QEvent *_event) override;

/// \brief Whether a play event has been received (true) or not (false)
public: bool listenedToPlay{false};

/// \brief Whether a pause event has been received (true) or not (false)
public: bool listenedToPause{false};

/// \brief Whether a pause event has been received (true) or not (false)
public: bool listenedToStep{false};
};
}
}

#endif

0 comments on commit 4148b9a

Please sign in to comment.