Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SpawnCloneFromName event #278

Merged
merged 1 commit into from
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}