Skip to content

Commit

Permalink
Improve inserting WorldControl and WorldStats from menu (#349)
Browse files Browse the repository at this point in the history
Signed-off-by: Louise Poubel <[email protected]>
  • Loading branch information
chapulina authored Jan 19, 2022
1 parent 5802201 commit a6afb94
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 5 deletions.
9 changes: 9 additions & 0 deletions src/plugins/world_control/WorldControl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ void WorldControl::LoadConfig(const tinyxml2::XMLElement *_pluginElem)
return;
}

// If no elements were set, show all buttons. We assume that the user never
// wants to hide all buttons. This happens for example when the plugin is
// inserted from the menu.
if (_pluginElem->NoChildren())
{
this->PluginItem()->setProperty("showPlay", true);
this->PluginItem()->setProperty("showStep", true);
}

// World name from window, to construct default topics and services
std::string worldName;
auto worldNames = gui::worldNames();
Expand Down
6 changes: 5 additions & 1 deletion src/plugins/world_control/WorldControl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,19 @@ namespace plugins
///
/// ## Configuration
///
/// * \<play_pause\> : Set to true to see a play/pause and step buttons,
/// * \<play_pause\> : Set to true to see a play/pause button,
/// false by default.
/// * \<step\> : Set to true to see a step button, false by default.
/// * \<start_paused\> : Set to false to start playing, false by default.
/// * \<service\> : Service for world control, optional. If not presnt,
/// the plugin will attempt to create a topic with the main
/// window's `worldName` property.
/// * \<stats_topic\> : Topic to receive world statistics, optional. If not
/// present, the plugin will attempt to create a topic with the
/// main window's `worldName` property.
///
/// If no elements are filled for the plugin, both the play/pause and the
/// step buttons will be displayed.
class WorldControl_EXPORTS_API WorldControl: public ignition::gui::Plugin
{
Q_OBJECT
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/world_control/WorldControl.qml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ RowLayout {
*/
RoundButton {
id: playButton
objectName: "playButton"
visible: showPlay
text: paused ? playIcon : pauseIcon
checkable: true
Expand Down Expand Up @@ -123,6 +124,7 @@ RowLayout {

RoundButton {
id: stepButton
objectName: "stepButton"
text: stepIcon
visible: showStep
height: playButton.height * 0.8
Expand Down
8 changes: 8 additions & 0 deletions src/plugins/world_control/WorldControl_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ TEST(WorldControlTest, IGN_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Load))
auto plugin = plugins[0];
EXPECT_EQ(plugin->Title(), "World control");

// Check that all buttons are visible
for (auto name : {"playButton", "stepButton"})
{
auto obj = plugin->PluginItem()->findChild<QObject *>(name);
ASSERT_NE(nullptr, obj) << name;
EXPECT_TRUE(obj->property("visible").toBool()) << name;
}

// Cleanup
plugins.clear();
}
Expand Down
11 changes: 11 additions & 0 deletions src/plugins/world_stats/WorldStats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ void WorldStats::LoadConfig(const tinyxml2::XMLElement *_pluginElem)
return;
}

// If no elements were set, show everything. We assume that the user never
// wants to hide everything. This happens for example when the plugin is
// inserted from the menu.
if (_pluginElem->NoChildren())
{
this->PluginItem()->setProperty("showSimTime", true);
this->PluginItem()->setProperty("showRealTime", true);
this->PluginItem()->setProperty("showRealTimeFactor", true);
this->PluginItem()->setProperty("showIterations", true);
}

// World name from window, to construct default topics and services
std::string worldName;
auto worldNames = gui::worldNames();
Expand Down
13 changes: 9 additions & 4 deletions src/plugins/world_stats/WorldStats.hh
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ namespace plugins
{
class WorldStatsPrivate;

/// \brief This plugin provides a time panel which may:
/// * Display simulation time
/// * Display real time
/// * Have a play / pause and step buttons
/// \brief This plugin provides a time panel which may display:
/// * Simulation time
/// * Real time
/// * Real time factor
/// * Iterations
///
/// ## Configuration
///
Expand All @@ -62,9 +63,13 @@ namespace plugins
/// * \<real_time\> : True to display a real time widget, false by default.
/// * \<real_time_factor\> : True to display a real time factor widget,
/// false by default.
/// * \<iterations\> : True to display an iterations widget, false by default.
/// * \<topic\> : Topic to receive world statistics, optional. If not present,
/// the plugin will attempt to create a topic with the main
/// window's `worldName` property.
///
/// If no elements are filled for the plugin, all properties will be
/// displayed.
class WorldStats_EXPORTS_API WorldStats: public ignition::gui::Plugin
{
Q_OBJECT
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/world_stats/WorldStats.qml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ Rectangle {
}
}
Label {
objectName: "realTimeFactorValue"
text: WorldStats.realTimeFactor
visible: showRealTimeFactor
Layout.alignment: Qt.AlignRight
Expand All @@ -190,6 +191,7 @@ Rectangle {
}
}
Label {
objectName: "simTimeValue"
text: WorldStats.simTime
visible: showSimTime
Layout.alignment: Qt.AlignRight
Expand All @@ -214,6 +216,7 @@ Rectangle {
}
}
Label {
objectName: "realTimeValue"
text: WorldStats.realTime
visible: showRealTime
Layout.alignment: Qt.AlignRight
Expand All @@ -238,6 +241,7 @@ Rectangle {
}
}
Label {
objectName: "iterationsValue"
text: WorldStats.iterations
visible: showIterations
Layout.alignment: Qt.AlignRight
Expand Down
13 changes: 13 additions & 0 deletions src/plugins/world_stats/WorldStats_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ TEST(WorldStatsTest, IGN_UTILS_TEST_ENABLED_ONLY_ON_LINUX(Load))
auto plugin = plugins[0];
EXPECT_EQ(plugin->Title(), "World stats");

// Check that everything is visible
for (auto name : {
"realTimeFactorValue",
"simTimeValue",
"realTimeValue",
"iterationsValue",
})
{
auto obj = plugin->PluginItem()->findChild<QObject *>(name);
ASSERT_NE(nullptr, obj) << name;
EXPECT_TRUE(obj->property("visible").toBool()) << name;
}

// Cleanup
plugins.clear();
}
Expand Down

0 comments on commit a6afb94

Please sign in to comment.