Skip to content

Commit

Permalink
SpawnCloneFromName event (#278)
Browse files Browse the repository at this point in the history
Signed-off-by: Ashton Larkin <[email protected]>
  • Loading branch information
adlarkin authored Sep 8, 2021
1 parent e8b3d16 commit 51e7f4b
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 40 deletions.
98 changes: 58 additions & 40 deletions include/ignition/gui/GuiEvents.hh
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,46 @@ namespace ignition
IGN_UTILS_IMPL_PTR(dataPtr)
};

/// \brief Event which is called to broadcast the key release within
/// the scene.
class IGNITION_GUI_VISIBLE KeyReleaseOnScene : public QEvent
{
/// \brief Constructor
/// \param[in] _key The key released event within the scene
public: explicit KeyReleaseOnScene(const common::KeyEvent &_key);

/// \brief Unique type for this event.
static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 8);

/// \brief Get the released key within the scene that the user released.
/// \return The key code.
public: common::KeyEvent Key() const;

/// \internal
/// \brief Private data pointer
IGN_UTILS_IMPL_PTR(dataPtr)
};

/// \brief Event which is called to broadcast the key press within
/// the scene.
class IGNITION_GUI_VISIBLE KeyPressOnScene : public QEvent
{
/// \brief Constructor
/// \param[in] _key The pressed key within the scene
public: explicit KeyPressOnScene(const common::KeyEvent &_key);

/// \brief Unique type for this event.
static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 9);

/// \brief Get the key within the scene that the user pressed
/// \return The key code.
public: common::KeyEvent Key() const;

/// \internal
/// \brief Private data pointer
IGN_UTILS_IMPL_PTR(dataPtr)
};

/// \brief Event which is called to broadcast information about left
/// mouse clicks on the scene.
/// For the 3D coordinates of that point on the scene, see
Expand Down Expand Up @@ -262,46 +302,6 @@ namespace ignition
IGN_UTILS_IMPL_PTR(dataPtr)
};

/// \brief Event which is called to broadcast the key release within
/// the scene.
class IGNITION_GUI_VISIBLE KeyReleaseOnScene : public QEvent
{
/// \brief Constructor
/// \param[in] _key The key released event within the scene
public: explicit KeyReleaseOnScene(const common::KeyEvent &_key);

/// \brief Unique type for this event.
static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 8);

/// \brief Get the released key within the scene that the user released.
/// \return The key code.
public: common::KeyEvent Key() const;

/// \internal
/// \brief Private data pointer
IGN_UTILS_IMPL_PTR(dataPtr)
};

/// \brief Event which is called to broadcast the key press within
/// the scene.
class IGNITION_GUI_VISIBLE KeyPressOnScene : public QEvent
{
/// \brief Constructor
/// \param[in] _key The pressed key within the scene
public: explicit KeyPressOnScene(const common::KeyEvent &_key);

/// \brief Unique type for this event.
static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 9);

/// \brief Get the key within the scene that the user pressed
/// \return The key code.
public: common::KeyEvent Key() const;

/// \internal
/// \brief Private data pointer
IGN_UTILS_IMPL_PTR(dataPtr)
};

/// \brief Event that block the Interactive View control when some of the
/// other plugins require it. For example: When the transform control is
/// active we should block the movements of the camera.
Expand Down Expand Up @@ -346,6 +346,24 @@ namespace ignition
IGN_UTILS_IMPL_PTR(dataPtr)
};

/// \brief Event called to clone a resource, given its name as a string.
class IGNITION_GUI_VISIBLE SpawnCloneFromName : public QEvent
{
/// \brief Constructor
/// \param[in] _name The name of the resource to clone
public: explicit SpawnCloneFromName(const std::string &_name);

/// \brief Unique type for this event.
static const QEvent::Type kType = QEvent::Type(QEvent::MaxUser - 14);

/// \brief Get the name of the resource to be cloned
/// \return The name of the resource to be cloned
public: const std::string &Name() const;

/// \internal
/// \brief Private data pointer
IGN_UTILS_IMPL_PTR(dataPtr)
};
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions src/GuiEvents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ class ignition::gui::events::KeyPressOnScene::Implementation
public: common::KeyEvent key;
};

class ignition::gui::events::SpawnCloneFromName::Implementation
{
/// \brief The name of the resource to be cloned
public: std::string name;
};

using namespace ignition;
using namespace gui;
using namespace events;
Expand Down Expand Up @@ -294,3 +300,17 @@ common::KeyEvent KeyPressOnScene::Key() const
{
return this->dataPtr->key;
}

/////////////////////////////////////////////////
SpawnCloneFromName::SpawnCloneFromName(
const std::string &_name)
: QEvent(kType), dataPtr(utils::MakeImpl<Implementation>())
{
this->dataPtr->name = _name;
}

/////////////////////////////////////////////////
const std::string &SpawnCloneFromName::Name() const
{
return this->dataPtr->name;
}
9 changes: 9 additions & 0 deletions src/GuiEvents_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,12 @@ TEST(GuiEventsTest, BlockOrbit)
EXPECT_LT(QEvent::User, event2.type());
EXPECT_FALSE(event2.Block());
}

/////////////////////////////////////////////////
TEST(GuiEventsTest, SpawnCloneFromName)
{
events::SpawnCloneFromName toCloneName("thingToClone");

EXPECT_LT(QEvent::User, toCloneName.type());
EXPECT_EQ("thingToClone", toCloneName.Name());
}

0 comments on commit 51e7f4b

Please sign in to comment.