Skip to content

Commit

Permalink
Use qmldir to define QML module with IgnSpinBox (#319)
Browse files Browse the repository at this point in the history
Signed-off-by: William Wedler <william.wedler@resquared.com>
Co-authored-by: Louise Poubel <louise@openrobotics.org>
  • Loading branch information
zflat and chapulina authored Dec 2, 2021
1 parent aa8632d commit 1827899
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 1 deletion.
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 @@ -20,4 +20,10 @@
<file>qml/images/menu.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>
2 changes: 2 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
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/";
}
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

0 comments on commit 1827899

Please sign in to comment.