Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions crates/cxx-qt-lib/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,11 @@ fn main() {
}

if qt_qml_enabled() {
rust_bridges.extend(["qml/qqmlapplicationengine", "qml/qqmlengine"]);
rust_bridges.extend([
"qml/qqmlapplicationengine",
"qml/qqmlengine",
"qml/qqmlimageproviderbase",
]);
}

if qt_quickcontrols_enabled() {
Expand Down Expand Up @@ -312,7 +316,11 @@ fn main() {
}

if qt_qml_enabled() {
cpp_files.extend(["qml/qqmlapplicationengine", "qml/qqmlengine"]);
cpp_files.extend([
"qml/qqmlapplicationengine",
"qml/qqmlengine",
"qml/qqmlimageproviderbase",
]);
}

if !emscripten_targeted {
Expand Down
24 changes: 24 additions & 0 deletions crates/cxx-qt-lib/include/qml/qqmlimageproviderbase.h
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 <info@kdab.com>
// clang-format on
// SPDX-FileContributor: Andrew Hayzen <andrew.hayzen@kdab.com>
//
// SPDX-License-Identifier: MIT OR Apache-2.0
#pragma once

// The definitions file is auto-generated by the build script
#include <cxx-qt-lib/definitions.h>

#ifdef CXX_QT_QML_FEATURE

#include <QtQml/QQmlImageProviderBase>

namespace rust {
namespace cxxqtlib1 {

using QQmlImageProviderBaseImageType = QQmlImageProviderBase::ImageType;

}
}

#endif
9 changes: 9 additions & 0 deletions crates/cxx-qt-lib/include/qqmlimageproviderbase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// clang-format off
// SPDX-FileCopyrightText: 2025 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
// clang-format on
// SPDX-FileContributor: Leon Matthes <leon.matthes@kdab.com>
//
// SPDX-License-Identifier: MIT OR Apache-2.0
#pragma once

#include "qml/qqmlimageproviderbase.h"
4 changes: 4 additions & 0 deletions crates/cxx-qt-lib/src/qml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ pub use qqmlapplicationengine::QQmlApplicationEngine;

mod qqmlengine;
pub use qqmlengine::QQmlEngine;

mod qqmlimageproviderbase;
pub use qqmlimageproviderbase::QQmlImageProviderBase;
pub use qqmlimageproviderbase::QQmlImageProviderBaseImageType;
14 changes: 14 additions & 0 deletions crates/cxx-qt-lib/src/qml/qqmlapplicationengine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ mod ffi {
include!("cxx-qt-lib/qurl.h");
type QUrl = crate::QUrl;

include!("cxx-qt-lib/qqmlimageproviderbase.h");
type QQmlImageProviderBase = crate::QQmlImageProviderBase;

/// 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);
Expand Down Expand Up @@ -71,6 +74,17 @@ mod ffi {
/// Sets `path` as string for storing offline user data.
#[rust_name = "set_offline_storage_path"]
fn setOfflineStoragePath(self: Pin<&mut QQmlApplicationEngine>, dir: &QString);

#[rust_name = "add_image_provider"]
unsafe fn addImageProvider(
self: Pin<&mut QQmlApplicationEngine>,
provider_id: &QString,
provider: *mut QQmlImageProviderBase,
);

#[rust_name = "remove_image_provider"]
fn removeImageProvider(self: Pin<&mut QQmlApplicationEngine>, provider_id: &QString);
Comment on lines +78 to +86
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these should be on the QQmlEngine rather than the QQmlApplicationEngine (which inherits from the QQmlEngine)


}

unsafe extern "C++Qt" {
Expand Down
8 changes: 8 additions & 0 deletions crates/cxx-qt-lib/src/qml/qqmlimageproviderbase.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// clang-format off
// SPDX-FileCopyrightText: 2023 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
// clang-format on
// SPDX-FileContributor: Andrew Hayzen <andrew.hayzen@kdab.com>
//
// SPDX-License-Identifier: MIT OR Apache-2.0

#include "cxx-qt-lib/qqmlimageproviderbase.h"
29 changes: 29 additions & 0 deletions crates/cxx-qt-lib/src/qml/qqmlimageproviderbase.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#[cxx_qt::bridge]
mod ffi {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove empty line :-)

#[repr(i32)]
#[namespace = "rust::cxxqtlib1"]
#[derive(Debug)]
enum QQmlImageProviderBaseImageType {
Invalid = 0,
Image,
Pixmap,
Texture,
ImageResponse,
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Qt 5 these enums are slightly different either have a cfg like #[cfg(cxxqt_qt_version_major = "6")] and #[cfg(cxxqt_qt_version_major = "5")] to have different enums or disable all of this for Qt 5.

In Qt 5

In Qt 6

Note in Qt 5 there is a gap of no 3 :-) And do we need the Invalid = 0 ? As that is not defined on the Qt side ?


extern "C++Qt" {
include!("cxx-qt-lib/qqmlimageproviderbase.h");

#[qobject]
type QQmlImageProviderBase;
Comment on lines +23 to +24
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Qt 5, this is just a normal class and does no inherit from QObject, so again might need a cfg block to have two different types if we want to make it work with Qt 5

}

#[namespace = "rust::cxxqtlib1"]
unsafe extern "C++" {
type QQmlImageProviderBaseImageType;
}
}

pub use ffi::QQmlImageProviderBase;
pub use ffi::QQmlImageProviderBaseImageType;
Loading