forked from KDAB/cxx-qt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cxx-qt-lib: add QQmlApplicationEngine
- Loading branch information
1 parent
03a40ac
commit 4b065dc
Showing
17 changed files
with
237 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
crates/cxx-qt-lib-headers/include/qml/qqmlapplicationengine.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// clang-format off | ||
// SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]> | ||
// clang-format on | ||
// SPDX-FileContributor: Andrew Hayzen <[email protected]> | ||
// | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
#pragma once | ||
|
||
#ifdef CXX_QT_QML_FEATURE | ||
|
||
#include <memory> | ||
|
||
#include <QtQml/QQmlApplicationEngine> | ||
|
||
namespace rust { | ||
namespace cxxqtlib1 { | ||
|
||
::std::unique_ptr<QQmlApplicationEngine> | ||
qqmlapplicationengineNew(); | ||
|
||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// clang-format off | ||
// SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]> | ||
// clang-format on | ||
// SPDX-FileContributor: Andrew Hayzen <[email protected]> | ||
// | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
|
||
#ifdef CXX_QT_GUI_FEATURE | ||
#include "cxx-qt-lib/qqmlapplicationengine.h" | ||
|
||
namespace rust { | ||
namespace cxxqtlib1 { | ||
|
||
::std::unique_ptr<QQmlApplicationEngine> | ||
qqmlapplicationengineNew() | ||
{ | ||
return ::std::make_unique<QQmlApplicationEngine>(); | ||
} | ||
|
||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]> | ||
// SPDX-FileContributor: Andrew Hayzen <[email protected]> | ||
// | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
|
||
#[cxx::bridge] | ||
mod ffi { | ||
unsafe extern "C++" { | ||
include!("cxx-qt-lib/qstring.h"); | ||
type QString = crate::QString; | ||
include!("cxx-qt-lib/qstringlist.h"); | ||
type QStringList = crate::QStringList; | ||
include!("cxx-qt-lib/qurl.h"); | ||
type QUrl = crate::QUrl; | ||
|
||
include!("cxx-qt-lib/qqmlapplicationengine.h"); | ||
type QQmlApplicationEngine; | ||
|
||
/// Adds path as a directory where the engine searches for installed modules in a URL-based directory structure. | ||
#[rust_name = "add_import_path"] | ||
fn addImportPath(self: Pin<&mut QQmlApplicationEngine>, path: &QString); | ||
|
||
/// Adds path as a directory where the engine searches for native plugins for imported modules (referenced in the qmldir file). | ||
#[rust_name = "add_plugin_path"] | ||
fn addPluginPath(self: Pin<&mut QQmlApplicationEngine>, path: &QString); | ||
|
||
/// Return the base URL for this engine. | ||
/// The base URL is only used to resolve components when a relative URL is passed to the QQmlComponent constructor. | ||
#[rust_name = "base_url"] | ||
fn baseUrl(self: &QQmlApplicationEngine) -> QUrl; | ||
|
||
/// Returns the list of directories where the engine searches for installed modules in a URL-based directory structure. | ||
#[rust_name = "import_path_list"] | ||
fn importPathList(self: &QQmlApplicationEngine) -> QStringList; | ||
|
||
/// Loads the root QML file located at url. | ||
fn load(self: Pin<&mut QQmlApplicationEngine>, url: &QUrl); | ||
|
||
/// Returns the list of directories where the engine searches for native plugins for imported modules (referenced in the qmldir file). | ||
#[rust_name = "plugin_path_list"] | ||
fn pluginPathList(self: &QQmlApplicationEngine) -> QStringList; | ||
|
||
/// Set the base URL for this engine to url. | ||
#[rust_name = "set_base_url"] | ||
fn setBaseUrl(self: Pin<&mut QQmlApplicationEngine>, url: &QUrl); | ||
|
||
/// Sets paths as the list of directories where the engine searches for installed modules in a URL-based directory structure. | ||
#[rust_name = "set_import_path_list"] | ||
fn setImportPathList(self: Pin<&mut QQmlApplicationEngine>, paths: &QStringList); | ||
|
||
/// Sets the list of directories where the engine searches for native plugins for imported modules (referenced in the qmldir file) to paths. | ||
#[rust_name = "set_plugin_path_list"] | ||
fn setPluginPathList(self: Pin<&mut QQmlApplicationEngine>, paths: &QStringList); | ||
} | ||
|
||
#[namespace = "rust::cxxqtlib1"] | ||
unsafe extern "C++" { | ||
#[doc(hidden)] | ||
#[rust_name = "qqmlapplicationengine_new"] | ||
fn qqmlapplicationengineNew() -> UniquePtr<QQmlApplicationEngine>; | ||
} | ||
|
||
impl UniquePtr<QQmlApplicationEngine> {} | ||
} | ||
|
||
pub use ffi::QQmlApplicationEngine; | ||
|
||
impl QQmlApplicationEngine { | ||
/// Create a new QQmlApplicationEngine | ||
pub fn new() -> cxx::UniquePtr<Self> { | ||
ffi::qqmlapplicationengine_new() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// clang-format off | ||
// SPDX-FileCopyrightText: 2022 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]> | ||
// clang-format on | ||
// SPDX-FileContributor: Andrew Hayzen <[email protected]> | ||
// | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
#pragma once | ||
|
||
#include <QtCore/QCoreApplication> | ||
#include <QtQml/QQmlApplicationEngine> | ||
#include <QtTest/QTest> | ||
|
||
#include "cxx-qt-gen/qqmlapplicationengine_cxx.cxx.h" | ||
|
||
class QQmlApplicationEngineTest : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
private Q_SLOTS: | ||
void construct() | ||
{ | ||
// QQmlEngine requires a QApplication | ||
std::vector<char*> args; | ||
std::string path = "/path"; | ||
args.push_back(path.data()); | ||
auto argc = static_cast<int>(args.size()); | ||
QCoreApplication app(argc, args.data()); | ||
|
||
const auto engine = construct_qqmlapplicationengine(); | ||
QVERIFY(engine != nullptr); | ||
QCOMPARE(engine->baseUrl(), QUrl(QStringLiteral("qrc:/kdab.qml"))); | ||
} | ||
|
||
void read() | ||
{ | ||
// QQmlEngine requires a QApplication | ||
std::vector<char*> args; | ||
std::string path = "/path"; | ||
args.push_back(path.data()); | ||
auto argc = static_cast<int>(args.size()); | ||
QCoreApplication app(argc, args.data()); | ||
|
||
QQmlApplicationEngine engine; | ||
engine.setBaseUrl(QUrl(QStringLiteral("qrc:/kdab.qml"))); | ||
QVERIFY(read_qqmlapplicationengine(engine)); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.