Skip to content

Commit b97d362

Browse files
Use Self type in examples
1 parent 96365ba commit b97d362

12 files changed

+44
-57
lines changed

crates/cxx-qt-gen/test_inputs/passthrough_and_naming.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,17 @@ pub mod ffi {
113113
fn errorOccurred(self: Pin<&mut ExternObject>);
114114
}
115115

116-
extern "RustQt" {
116+
unsafe extern "RustQt" {
117117
#[qobject]
118118
#[base = QStringListModel]
119119
#[qproperty(i32, property_name, cxx_name = "propertyName")]
120120
type MyObject = super::MyObjectRust;
121-
}
122121

123-
unsafe extern "RustQt" {
124122
#[qsignal]
125-
fn ready(self: Pin<&mut MyObject>);
123+
fn ready(self: Pin<&mut Self>);
126124

127125
#[qinvokable]
128-
fn invokable_name(self: Pin<&mut MyObject>);
126+
fn invokable_name(self: Pin<&mut Self>);
129127
}
130128

131129
extern "RustQt" {

examples/qml_features/rust/src/containers.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -46,32 +46,32 @@ pub mod qobject {
4646

4747
/// Reset all the containers
4848
#[qinvokable]
49-
fn reset(self: Pin<&mut RustContainers>);
49+
fn reset(self: Pin<&mut Self>);
5050

5151
/// Append the given number to the vector container
5252
#[qinvokable]
5353
#[cxx_name = "appendVector"]
54-
fn append_vector(self: Pin<&mut RustContainers>, value: i32);
54+
fn append_vector(self: Pin<&mut Self>, value: i32);
5555

5656
/// Append the given number to the list container
5757
#[qinvokable]
5858
#[cxx_name = "appendList"]
59-
fn append_list(self: Pin<&mut RustContainers>, value: i32);
59+
fn append_list(self: Pin<&mut Self>, value: i32);
6060

6161
/// Insert the given number into the set container
6262
#[qinvokable]
6363
#[cxx_name = "insertSet"]
64-
fn insert_set(self: Pin<&mut RustContainers>, value: i32);
64+
fn insert_set(self: Pin<&mut Self>, value: i32);
6565

6666
/// Insert the given string and variant to the hash container
6767
#[qinvokable]
6868
#[cxx_name = "insertHash"]
69-
fn insert_hash(self: Pin<&mut RustContainers>, key: QString, value: QVariant);
69+
fn insert_hash(self: Pin<&mut Self>, key: QString, value: QVariant);
7070

7171
/// Insert the given string and variant to the map container
7272
#[qinvokable]
7373
#[cxx_name = "insertMap"]
74-
fn insert_map(self: Pin<&mut RustContainers>, key: QString, value: QVariant);
74+
fn insert_map(self: Pin<&mut Self>, key: QString, value: QVariant);
7575
}
7676
}
7777

examples/qml_features/rust/src/custom_parent_class.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ pub mod qobject {
4343
/// Override QQuickPaintedItem::paint to draw two rectangles in Rust using QPainter
4444
#[qinvokable]
4545
#[cxx_override]
46-
unsafe fn paint(self: Pin<&mut CustomParentClass>, painter: *mut QPainter);
46+
unsafe fn paint(self: Pin<&mut Self>, painter: *mut QPainter);
4747

4848
/// Define that we need to inherit size() from the base class
4949
#[inherit]
50-
fn size(self: &CustomParentClass) -> QSizeF;
50+
fn size(self: &Self) -> QSizeF;
5151

5252
/// Define that we need to inherit update() from the base class
5353
#[inherit]
54-
fn update(self: Pin<&mut CustomParentClass>);
54+
fn update(self: Pin<&mut Self>);
5555
}
5656

5757
impl cxx_qt::Constructor<()> for CustomParentClass {}

examples/qml_features/rust/src/externcxxqt.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ pub mod ffi {
3737
#[qinvokable]
3838
#[cxx_name = "connectToExternal"]
3939
unsafe fn connect_to_external(
40-
self: Pin<&mut ExternalCxxQtHelper>,
40+
self: Pin<&mut Self>,
4141
external: *mut ExternalQObject,
4242
);
4343

4444
#[qinvokable]
4545
#[cxx_name = "triggerOnExternal"]
4646
unsafe fn trigger_on_external(
47-
self: Pin<&mut ExternalCxxQtHelper>,
47+
self: Pin<&mut Self>,
4848
external: *mut ExternalQObject,
4949
amount: u32,
5050
);

examples/qml_features/rust/src/multiple_qobjects.rs

+12-20
Original file line numberDiff line numberDiff line change
@@ -23,53 +23,45 @@ pub mod qobject {
2323
#[qproperty(i32, counter)]
2424
#[qproperty(QColor, color)]
2525
type FirstObject = super::FirstObjectRust;
26-
}
2726

28-
// Enabling threading on the qobject
29-
impl cxx_qt::Threading for FirstObject {}
30-
31-
extern "RustQt" {
3227
/// Accepted Q_SIGNAL
3328
#[qsignal]
34-
fn accepted(self: Pin<&mut FirstObject>);
29+
fn accepted(self: Pin<&mut Self>);
3530

3631
/// Rejected Q_SIGNAL
3732
#[qsignal]
38-
fn rejected(self: Pin<&mut FirstObject>);
39-
}
33+
fn rejected(self: Pin<&mut Self>);
4034

41-
extern "RustQt" {
4235
/// A Q_INVOKABLE on the first QObject which increments a counter
4336
#[qinvokable]
44-
fn increment(self: Pin<&mut FirstObject>);
37+
fn increment(self: Pin<&mut Self>);
4538
}
4639

40+
// Enabling threading on the qobject
41+
impl cxx_qt::Threading for FirstObject {}
42+
4743
extern "RustQt" {
4844
#[qobject]
4945
#[qml_element]
5046
#[qproperty(i32, counter)]
5147
#[qproperty(QUrl, url)]
5248
type SecondObject = super::SecondObjectRust;
53-
}
5449

55-
// Enabling threading on the qobject
56-
impl cxx_qt::Threading for SecondObject {}
57-
58-
extern "RustQt" {
5950
/// Accepted Q_SIGNAL
6051
#[qsignal]
61-
fn accepted(self: Pin<&mut SecondObject>);
52+
fn accepted(self: Pin<&mut Self>);
6253

6354
/// Rejected Q_SIGNAL
6455
#[qsignal]
65-
fn rejected(self: Pin<&mut SecondObject>);
66-
}
56+
fn rejected(self: Pin<&mut Self>);
6757

68-
extern "RustQt" {
6958
/// A Q_INVOKABLE on the second QObject which increments a counter
7059
#[qinvokable]
71-
fn increment(self: Pin<&mut SecondObject>);
60+
fn increment(self: Pin<&mut Self>);
7261
}
62+
63+
// Enabling threading on the qobject
64+
impl cxx_qt::Threading for SecondObject {}
7365
}
7466

7567
use core::pin::Pin;

examples/qml_features/rust/src/naming.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ pub mod qobject {
1515
#[cxx_name = "RenamedObject"]
1616
#[namespace = "my_namespace"]
1717
type NamedObject = super::NamedObjectRust;
18-
}
1918

20-
extern "RustQt" {
2119
#[qinvokable]
2220
#[cxx_name = "increment"]
2321
#[rust_name = "plus_one"]
2422
fn increment_number(self: Pin<&mut NamedObject>);
23+
2524
}
2625

2726
#[auto_cxx_name]

examples/qml_features/rust/src/nested_qobjects.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub mod qobject {
4444
///
4545
/// Due to a raw pointer this is considered unsafe in CXX
4646
#[qsignal]
47-
unsafe fn called(self: Pin<&mut OuterObject>, inner: *mut InnerObject);
47+
unsafe fn called(self: Pin<&mut Self>, inner: *mut InnerObject);
4848
}
4949

5050
extern "RustQt" {

examples/qml_features/rust/src/properties.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ pub mod qobject {
3131
/// Custom on changed signal, used for all the properties
3232
#[qsignal]
3333
#[cxx_name = "connectedStateChanged"]
34-
fn connected_state_changed(self: Pin<&mut RustProperties>);
34+
fn connected_state_changed(self: Pin<&mut Self>);
3535

3636
/// Custom setter for connected_url, which also handles setting the other qproperties
3737
#[cxx_name = "setUrl"]
38-
fn set_url(self: Pin<&mut RustProperties>, url: QUrl);
38+
fn set_url(self: Pin<&mut Self>, url: QUrl);
3939

4040
/// Resets value of connected_url to empty, as well as calling the other disconnected logic
4141
#[cxx_name = "resetUrl"]
42-
fn reset_url(self: Pin<&mut RustProperties>);
42+
fn reset_url(self: Pin<&mut Self>);
4343
}
4444

4545
impl cxx_qt::Constructor<()> for RustProperties {}

examples/qml_features/rust/src/serialisation.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ pub mod qobject {
2828

2929
/// An error signal
3030
#[qsignal]
31-
fn error(self: Pin<&mut Serialisation>, message: QString);
31+
fn error(self: Pin<&mut Self>, message: QString);
3232

3333
/// Retrieve the JSON form of this QObject
3434
#[qinvokable]
3535
#[cxx_name = "asJsonStr"]
36-
fn as_json_str(self: Pin<&mut Serialisation>) -> QString;
36+
fn as_json_str(self: Pin<&mut Self>) -> QString;
3737

3838
/// From a given JSON string try to load values for the Q_PROPERTYs
3939
// ANCHOR: book_grab_values
4040
#[qinvokable]
4141
#[cxx_name = "fromJsonStr"]
42-
fn from_json_str(self: Pin<&mut Serialisation>, string: &QString);
42+
fn from_json_str(self: Pin<&mut Self>, string: &QString);
4343
// ANCHOR_END: book_grab_values
4444
}
4545
}

examples/qml_features/rust/src/singleton.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub mod qobject {
1818

1919
/// Increment the persistent value Q_PROPERTY of the QML_SINGLETON
2020
#[qinvokable]
21-
fn increment(self: Pin<&mut RustSingleton>);
21+
fn increment(self: Pin<&mut Self>);
2222
}
2323
}
2424

examples/qml_features/rust/src/threading.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,22 @@ pub mod qobject {
2727
#[qproperty(QString, title)]
2828
#[qproperty(QUrl, url)]
2929
type ThreadingWebsite = super::ThreadingWebsiteRust;
30-
}
31-
32-
// ANCHOR: book_threading_trait
33-
// Enabling threading on the qobject
34-
impl cxx_qt::Threading for ThreadingWebsite {}
35-
// ANCHOR_END: book_threading_trait
3630

37-
extern "RustQt" {
3831
/// Swap the URL between kdab.com and github.com
3932
#[qinvokable]
4033
#[cxx_name = "changeUrl"]
41-
fn change_url(self: Pin<&mut ThreadingWebsite>);
34+
fn change_url(self: Pin<&mut Self>);
4235

4336
/// Simulate delay of a network request to retrieve the title of the website
4437
#[qinvokable]
4538
#[cxx_name = "fetchTitle"]
46-
fn fetch_title(self: Pin<&mut ThreadingWebsite>);
39+
fn fetch_title(self: Pin<&mut Self>);
4740
}
41+
42+
// ANCHOR: book_threading_trait
43+
// Enabling threading on the qobject
44+
impl cxx_qt::Threading for ThreadingWebsite {}
45+
// ANCHOR_END: book_threading_trait
4846
}
4947

5048
use core::pin::Pin;

examples/qml_features/rust/src/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ pub mod ffi {
8383
/// Load the value from a QVariant
8484
#[qinvokable]
8585
#[cxx_name = "loadFromVariant"]
86-
fn load_from_variant(self: Pin<&mut Types>, variant: &QVariant);
86+
fn load_from_variant(self: Pin<&mut Self>, variant: &QVariant);
8787

8888
/// Toggle the boolean Q_PROPERTY
8989
#[qinvokable]
9090
#[cxx_name = "toggleBoolean"]
91-
fn toggle_boolean(self: Pin<&mut Types>);
91+
fn toggle_boolean(self: Pin<&mut Self>);
9292
}
9393
}
9494

0 commit comments

Comments
 (0)