Skip to content

Commit

Permalink
4 ➡️ 5 (#330)
Browse files Browse the repository at this point in the history
Signed-off-by: Louise Poubel <[email protected]>
  • Loading branch information
chapulina authored Dec 7, 2021
2 parents 0361d32 + bf57a80 commit 01c2eff
Show file tree
Hide file tree
Showing 16 changed files with 207 additions and 4 deletions.
10 changes: 10 additions & 0 deletions include/ignition/gui/Helpers.hh
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ namespace ignition
IGNITION_GUI_VISIBLE
QStringList worldNames();


/// \brief Import path for ign-gui QML modules added to the Qt resource
/// system. This helper function returns the QRC resource path where custom
/// ignition QML modules can be imported from. To import an ignition QML
/// module, add this path to the QML engine's import path list before
/// attempting to load a QML file that imports ignition QML modules.
/// \return Resousrce path prefix as a string
IGNITION_GUI_VISIBLE
const QString qmlQrcImportPath();

/// \brief Returns the first element on a QList which matches the given
/// property.
/// \param[in] _list The list to search through.
Expand Down
3 changes: 3 additions & 0 deletions include/ignition/gui/qml/qmldir
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module ignition.gui

IgnSpinBox 1.0 IgnSpinBox.qml
6 changes: 6 additions & 0 deletions include/ignition/gui/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@
<file>qml/images/export_icon.png</file>
<file>qml/images/search.svg</file>
</qresource>
<qresource prefix="ign-gui-qml/ignition/gui">
<!-- This qmldir file defines a QML module that can be imported -->
<file alias="qmldir">qml/qmldir</file>
<!-- Add any QML components referenced in the qmldir file here -->
<file alias="IgnSpinBox.qml">qml/IgnSpinBox.qml</file>
</qresource>
</RCC>
5 changes: 5 additions & 0 deletions src/Application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "ignition/gui/Application.hh"
#include "ignition/gui/config.hh"
#include "ignition/gui/Dialog.hh"
#include "ignition/gui/Helpers.hh"
#include "ignition/gui/MainWindow.hh"
#include "ignition/gui/Plugin.hh"

Expand Down Expand Up @@ -91,6 +92,7 @@ Application::Application(int &_argc, char **_argv, const WindowType _type)

// QML engine
this->dataPtr->engine = new QQmlApplicationEngine();
this->dataPtr->engine->addImportPath(qmlQrcImportPath());

// Install signal handler for graceful shutdown
this->dataPtr->signalHandler.AddCallback(
Expand Down Expand Up @@ -387,6 +389,9 @@ bool Application::LoadPlugin(const std::string &_filename,
else
plugin->Load(_pluginElem);

if (nullptr == plugin->CardItem())
return false;

// Store plugin in queue to be added to the window
this->dataPtr->pluginsToAdd.push(plugin);

Expand Down
8 changes: 8 additions & 0 deletions src/Application_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ TEST(ApplicationTest, IGN_UTILS_TEST_ENABLED_ONLY_ON_LINUX(LoadPlugin))

EXPECT_FALSE(app.LoadPlugin("TestNotRegisteredPlugin"));
}

// Plugin with invalid QML
{
Application app(g_argc, g_argv);
app.AddPluginPath(std::string(PROJECT_BINARY_PATH) + "/lib");

EXPECT_FALSE(app.LoadPlugin("TestInvalidQmlPlugin"));
}
}

//////////////////////////////////////////////////
Expand Down
6 changes: 6 additions & 0 deletions src/Helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,9 @@ QStringList ignition::gui::worldNames()

return worldNamesVariant.toStringList();
}

/////////////////////////////////////////////////
const QString ignition::gui::qmlQrcImportPath()
{
return "qrc:/ign-gui-qml/";
}
20 changes: 20 additions & 0 deletions src/ign.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ char* g_argv[] =
reinterpret_cast<char*>(const_cast<char*>("./ignition")),
};

//////////////////////////////////////////////////
void startConsoleLog()
{
std::string home;
ignition::common::env(IGN_HOMEDIR, home);

std::string logPathMod = ignition::common::joinPaths(home,
".ignition", "gui", "log",
ignition::common::timeToIso(IGN_SYSTEM_TIME()));
ignLogInit(logPathMod, "console.log");
}

//////////////////////////////////////////////////
extern "C" IGNITION_GUI_VISIBLE char *ignitionVersion()
{
Expand All @@ -42,6 +54,8 @@ extern "C" IGNITION_GUI_VISIBLE char *ignitionVersion()
//////////////////////////////////////////////////
extern "C" IGNITION_GUI_VISIBLE void cmdPluginList()
{
startConsoleLog();

ignition::gui::Application app(g_argc, g_argv);

auto pluginsList = app.PluginList();
Expand All @@ -65,6 +79,8 @@ extern "C" IGNITION_GUI_VISIBLE void cmdPluginList()
//////////////////////////////////////////////////
extern "C" IGNITION_GUI_VISIBLE void cmdStandalone(const char *_filename)
{
startConsoleLog();

ignition::gui::Application app(g_argc, g_argv,
ignition::gui::WindowType::kDialog);

Expand All @@ -79,6 +95,8 @@ extern "C" IGNITION_GUI_VISIBLE void cmdStandalone(const char *_filename)
//////////////////////////////////////////////////
extern "C" IGNITION_GUI_VISIBLE void cmdConfig(const char *_config)
{
startConsoleLog();

ignition::gui::Application app(g_argc, g_argv);

if (!app.findChild<ignition::gui::MainWindow *>())
Expand All @@ -103,6 +121,8 @@ extern "C" IGNITION_GUI_VISIBLE void cmdVerbose(const char *_verbosity)
//////////////////////////////////////////////////
extern "C" IGNITION_GUI_VISIBLE void cmdEmptyWindow()
{
startConsoleLog();

ignition::gui::Application app(g_argc, g_argv);

if (!app.findChild<ignition::gui::MainWindow *>())
Expand Down
39 changes: 38 additions & 1 deletion src/ign_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include <string>

#include <ignition/common/Filesystem.hh>
#include <ignition/common/Util.hh>
#include <ignition/utilities/ExtraTestMacros.hh>

#include "test_config.h" // NOLINT(build/include)
Expand Down Expand Up @@ -52,10 +54,45 @@ std::string custom_exec_str(std::string _cmd)
return result;
}

using namespace ignition;

class CmdLine : public ::testing::Test
{
// Documentation inherited
protected: void SetUp() override
{
// Change environment variable so that test files aren't written to $HOME
common::env(IGN_HOMEDIR, this->realHome);
EXPECT_TRUE(common::setenv(IGN_HOMEDIR, this->kFakeHome.c_str()));
}

// Documentation inherited
protected: void TearDown() override
{
// Restore $HOME
EXPECT_TRUE(common::setenv(IGN_HOMEDIR, this->realHome.c_str()));
}

/// \brief Directory to act as $HOME for tests
public: const std::string kFakeHome = common::joinPaths(PROJECT_BINARY_PATH,
"test", "fake_home");

/// \brief Store user's real $HOME to set it back at the end of tests.
public: std::string realHome;
};

// See https://github.com/ignitionrobotics/ign-gui/issues/75
TEST(CmdLine, IGN_UTILS_TEST_ENABLED_ONLY_ON_LINUX(list))
TEST_F(CmdLine, IGN_UTILS_TEST_ENABLED_ONLY_ON_LINUX(list))
{
// Clear home if it exists
common::removeAll(this->kFakeHome);

EXPECT_FALSE(common::exists(this->kFakeHome));

std::string output = custom_exec_str("ign gui -l");
EXPECT_NE(output.find("TopicEcho"), std::string::npos) << output;
EXPECT_NE(output.find("Publisher"), std::string::npos) << output;

EXPECT_TRUE(common::exists(common::joinPaths(this->kFakeHome, ".ignition",
"gui")));
}
2 changes: 1 addition & 1 deletion src/plugins/teleop/Teleop.qml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import QtQuick.Controls 2.2
import QtQuick.Controls.Material 2.1
import QtQuick.Controls.Styles 1.4
import QtQuick.Layouts 1.3
import "qrc:/qml"
import ignition.gui 1.0

Rectangle {
color:"transparent"
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/topic_echo/TopicEcho.qml
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ Rectangle {
currentIndex: -1

delegate: ItemDelegate {
width: parent.width
text: display
width: listView.width
text: model.display
}

model: TopicEchoMsgList
Expand Down
1 change: 1 addition & 0 deletions test/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ link_directories(

set (plugins
TestBadInheritancePlugin
TestInvalidQmlPlugin
TestNotRegisteredPlugin
TestPlugin
)
Expand Down
38 changes: 38 additions & 0 deletions test/plugins/TestInvalidQmlPlugin.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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 <ignition/plugin/Register.hh>

#include "TestInvalidQmlPlugin.hh"

using namespace ignition;
using namespace gui;

/////////////////////////////////////////////////
TestInvalidQmlPlugin::TestInvalidQmlPlugin()
: Plugin()
{
}

/////////////////////////////////////////////////
TestInvalidQmlPlugin::~TestInvalidQmlPlugin()
{
}

// Register this plugin
IGNITION_ADD_PLUGIN(ignition::gui::TestInvalidQmlPlugin,
ignition::gui::Plugin)
40 changes: 40 additions & 0 deletions test/plugins/TestInvalidQmlPlugin.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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_TEST_MALFORMEDPLUGIN_HH_
#define IGNITION_GUI_TEST_MALFORMEDPLUGIN_HH_

#include <ignition/gui/Plugin.hh>

namespace ignition
{
namespace gui
{
class TestInvalidQmlPlugin : public Plugin
{
Q_OBJECT

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

/// \brief Destructor
public: virtual ~TestInvalidQmlPlugin();
};
}
}

#endif
21 changes: 21 additions & 0 deletions test/plugins/TestInvalidQmlPlugin.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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.
*
*/
import QtQuick 2.9

Rectangle {
banana: fail
}
5 changes: 5 additions & 0 deletions test/plugins/TestInvalidQmlPlugin.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource prefix="TestInvalidQmlPlugin/">
<file>TestInvalidQmlPlugin.qml</file>
</qresource>
</RCC>
3 changes: 3 additions & 0 deletions tutorials/02_commandline.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ If you have Ignition Tools installed, you can use the `ign gui` command line too
--force-version <VERSION> Use a specific library version.

--versions Show the available versions.

When using the command line tool, all console messages are logged to
`$HOME/.ignition/gui/log/<timestamp>`.

0 comments on commit 01c2eff

Please sign in to comment.