Skip to content

Commit 9f06cf3

Browse files
Replace manual upcast impl for C++ type with generation
1 parent 1ee7958 commit 9f06cf3

File tree

3 files changed

+16
-63
lines changed

3 files changed

+16
-63
lines changed

crates/cxx-qt-gen/src/generator/rust/externcxxqt.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ impl GeneratedRustFragment {
3131
.iter()
3232
.map(|ty| -> Result<GeneratedRustFragment> {
3333
let mut generated = vec![];
34-
3534
let qobject_names = QObjectNames::from_extern_qobject(ty, type_names)?;
3635

3736
generated.push(GeneratedRustFragment::generate_casting_impl(

crates/cxx-qt-lib/src/gui/qguiapplication.rs

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66

77
use crate::{QByteArray, QFont, QString, QStringList, QVector};
88
use core::pin::Pin;
9-
use cxx_qt::Upcast;
109

11-
#[cxx::bridge]
10+
#[cxx_qt::bridge]
1211
mod ffi {
1312
unsafe extern "C++" {
1413
include!("cxx-qt-lib/qbytearray.h");
@@ -22,25 +21,15 @@ mod ffi {
2221
include!("cxx-qt-lib/qfont.h");
2322
type QFont = crate::QFont;
2423

25-
include!("cxx-qt-lib/qguiapplication.h");
26-
type QGuiApplication;
27-
2824
include!("cxx-qt-lib/qcoreapplication.h");
2925
type QCoreApplication;
26+
}
3027

31-
include!("cxx-qt/casting.h");
32-
33-
#[doc(hidden)]
34-
#[rust_name = "upcast_qguiapplication"]
35-
#[cxx_name = "upcastPtr"]
36-
#[namespace = "rust::cxxqt1"]
37-
unsafe fn upcast(thiz: *const QGuiApplication) -> *const QCoreApplication;
38-
39-
#[doc(hidden)]
40-
#[rust_name = "downcast_qcoreapplication"]
41-
#[cxx_name = "downcastPtr"]
42-
#[namespace = "rust::cxxqt1"]
43-
unsafe fn downcast(base: *const QCoreApplication) -> *const QGuiApplication;
28+
unsafe extern "C++Qt" {
29+
include!("cxx-qt-lib/qguiapplication.h");
30+
#[qobject]
31+
#[base = QCoreApplication]
32+
type QGuiApplication;
4433
}
4534

4635
#[namespace = "rust::cxxqtlib1"]
@@ -116,19 +105,7 @@ mod ffi {
116105
impl UniquePtr<QGuiApplication> {}
117106
}
118107

119-
pub use ffi::{
120-
downcast_qcoreapplication, upcast_qguiapplication, QCoreApplication, QGuiApplication,
121-
};
122-
123-
impl Upcast<QCoreApplication> for QGuiApplication {
124-
unsafe fn upcast_ptr(this: *const Self) -> *const QCoreApplication {
125-
upcast_qguiapplication(this)
126-
}
127-
128-
unsafe fn from_base_ptr(base: *const QCoreApplication) -> *const Self {
129-
downcast_qcoreapplication(base)
130-
}
131-
}
108+
pub use ffi::QGuiApplication;
132109

133110
impl QGuiApplication {
134111
/// Prepends path to the beginning of the library path list,

crates/cxx-qt-lib/src/qml/qqmlapplicationengine.rs

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//
44
// SPDX-License-Identifier: MIT OR Apache-2.0
55

6-
#[cxx::bridge]
6+
#[cxx_qt::bridge]
77
mod ffi {
88
unsafe extern "C++" {
99
include!("cxx-qt-lib/qstring.h");
@@ -13,23 +13,6 @@ mod ffi {
1313
include!("cxx-qt-lib/qurl.h");
1414
type QUrl = crate::QUrl;
1515

16-
include!("cxx-qt-lib/qqmlapplicationengine.h");
17-
type QQmlApplicationEngine;
18-
19-
include!("cxx-qt/casting.h");
20-
21-
#[doc(hidden)]
22-
#[rust_name = "upcast_qqmlapplication_engine"]
23-
#[cxx_name = "upcastPtr"]
24-
#[namespace = "rust::cxxqt1"]
25-
unsafe fn upcast(thiz: *const QQmlApplicationEngine) -> *const QQmlEngine;
26-
27-
#[doc(hidden)]
28-
#[rust_name = "downcast_qqml_engine"]
29-
#[cxx_name = "downcastPtr"]
30-
#[namespace = "rust::cxxqt1"]
31-
unsafe fn downcast(base: *const QQmlEngine) -> *const QQmlApplicationEngine;
32-
3316
/// Adds path as a directory where the engine searches for installed modules in a URL-based directory structure.
3417
#[rust_name = "add_import_path"]
3518
fn addImportPath(self: Pin<&mut QQmlApplicationEngine>, path: &QString);
@@ -75,6 +58,13 @@ mod ffi {
7558
fn setOfflineStoragePath(self: Pin<&mut QQmlApplicationEngine>, dir: &QString);
7659
}
7760

61+
unsafe extern "C++Qt" {
62+
include!("cxx-qt-lib/qqmlapplicationengine.h");
63+
#[qobject]
64+
#[base = QQmlEngine]
65+
type QQmlApplicationEngine;
66+
}
67+
7868
unsafe extern "C++" {
7969
include!("cxx-qt-lib/qqmlengine.h");
8070
type QQmlEngine = crate::QQmlEngine;
@@ -94,21 +84,8 @@ mod ffi {
9484
impl UniquePtr<QQmlApplicationEngine> {}
9585
}
9686

97-
use crate::QQmlEngine;
98-
use cxx_qt::Upcast;
99-
10087
pub use ffi::QQmlApplicationEngine;
10188

102-
impl Upcast<QQmlEngine> for QQmlApplicationEngine {
103-
unsafe fn upcast_ptr(this: *const Self) -> *const QQmlEngine {
104-
ffi::upcast_qqmlapplication_engine(this)
105-
}
106-
107-
unsafe fn from_base_ptr(base: *const QQmlEngine) -> *const Self {
108-
ffi::downcast_qqml_engine(base)
109-
}
110-
}
111-
11289
impl QQmlApplicationEngine {
11390
/// Create a new QQmlApplicationEngine
11491
pub fn new() -> cxx::UniquePtr<Self> {

0 commit comments

Comments
 (0)