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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

use qmldir to define QML module with IgnSpinBox #319

Merged
merged 5 commits into from Dec 2, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/ignition/gui/Helpers.hh
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
@@ -0,0 +1,3 @@
module ignition.gui

IgnSpinBox 1.0 IgnSpinBox.qml
6 changes: 6 additions & 0 deletions include/ignition/gui/resources.qrc
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">
chapulina marked this conversation as resolved.
Show resolved Hide resolved
<!-- 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
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
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
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