Skip to content

Commit

Permalink
cxx-qt-gen: ensure test_inputs follow new qinvokable syntax
Browse files Browse the repository at this point in the history
Related to KDAB#558
  • Loading branch information
ahayzen-kdab committed Jun 21, 2023
1 parent 386a7aa commit 342d74f
Show file tree
Hide file tree
Showing 14 changed files with 114 additions and 222 deletions.
10 changes: 3 additions & 7 deletions crates/cxx-qt-gen/test_inputs/inheritance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,11 @@ mod inheritance {
unsafe fn fetch_more(self: Pin<&mut qobject::MyObject>, index: &QModelIndex);
}

impl qobject::MyObject {
unsafe extern "RustQt" {
#[qinvokable(cxx_override)]
pub fn data(&self, _index: &QModelIndex, _role: i32) -> QVariant {
QVariant::default()
}
fn data(self: &qobject::MyObject, _index: &QModelIndex, _role: i32) -> QVariant;

#[qinvokable(cxx_override)]
pub fn has_children(&self, _parent: &QModelIndex) -> bool {
false
}
fn has_children(self: &qobject::MyObject, _parent: &QModelIndex) -> bool;
}
}
57 changes: 0 additions & 57 deletions crates/cxx-qt-gen/test_inputs/invokables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,62 +43,5 @@ mod ffi {
fn invokable_virtual(self: &qobject::MyObject);
}

impl qobject::MyObject {
pub fn invokable(&self) {
println!("invokable");
}

pub fn invokable_mutable(self: Pin<&mut Self>) {
println!("This method is mutable!");
}

pub fn invokable_parameters(&self, opaque: &QColor, trivial: &QPoint, primitive: i32) {
println!(
"Red: {}, Point X: {}, Number: {}",
opaque.red(),
trivial.x(),
primitive,
);
}

pub fn invokable_return_opaque(self: Pin<&mut Self>) -> UniquePtr<Opaque> {
Opaque::new()
}

pub fn invokable_return_trivial(self: Pin<&mut Self>) -> QPoint {
QPoint::new(1, 2)
}

pub fn invokable_final(&self) {
println!("Final");
}

pub fn invokable_override(&self) {
println!("Override");
}

pub fn invokable_virtual(&self) {
println!("Virtual");
}

pub fn cpp_context_method(&self) {
println!("C++ context method");
}

pub fn cpp_context_method_mutable(self: Pin<&mut Self>) {
println!("mutable method");
}

pub fn cpp_context_method_return_opaque(&self) -> UniquePtr<Opaque> {
Opaque::new()
}
}

impl MyObject {
pub fn rust_only_method(&self) {
println!("QML or C++ can't call this :)");
}
}

impl cxx_qt::Threading for qobject::MyObject {}
}
44 changes: 3 additions & 41 deletions crates/cxx-qt-gen/test_inputs/passthrough_and_naming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,39 +85,12 @@ pub mod ffi {
property_name: i32,
}

impl Default for MyObject {
fn default() -> Self {
Self { property_name: 32 }
}
}

unsafe extern "RustQt" {
#[qsignal]
fn ready(self: Pin<&mut qobject::MyObject>);
}

impl qobject::MyObject {
pub const MY_CONSTANT: i32 = 42; // the answer to everything ;)

type MyType = i32;

my_macro!();

#[qinvokable]
pub fn invokable_name(self: Pin<&mut Self>) {
println!("Bye from Rust!");
self.as_mut().set_property_name(5);
}
}

impl MyObject {
fn test_angled(&self, optional: Option<bool>) -> Option<bool> {
optional
}

fn test_unknown(&self, unknown: MyType) -> MyType {
unknown
}
fn invokable_name(self: Pin<&mut qobject::MyObject>);
}

impl MyTrait for MyObject {
Expand All @@ -134,23 +107,12 @@ pub mod ffi {

unsafe impl !cxx_qt::Locking for qobject::SecondObject {}

impl Default for SecondObject {
fn default() -> Self {
Self { property_name: 32 }
}
}

unsafe extern "RustQt" {
#[my_attribute]
#[qsignal]
fn ready(self: Pin<&mut qobject::SecondObject>);
}

impl qobject::SecondObject {
#[qinvokable]
pub fn invokable_name(self: Pin<&mut Self>) {
println!("Bye from second Rust!");
self.as_mut().set_property_name(5);
}
fn invokable_name(self: Pin<&mut qobject::SecondObject>);
}
}
}
17 changes: 3 additions & 14 deletions crates/cxx-qt-gen/test_inputs/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,12 @@ mod ffi {
third: QPoint,
fourth: &'a QPoint,
);

#[qinvokable]
fn invokable(self: Pin<&mut qobject::MyObject>);
}

#[cxx_qt::qobject]
#[derive(Default)]
pub struct MyObject;

impl qobject::MyObject {
#[qinvokable]
pub fn invokable(self: Pin<&mut Self>) {
self.as_mut().on_data_changed(
|_sender, _first, _second, _third, _fourth| {
println!("DataChanged");
},
cxx_qt_lib::ConnectionType::AutoConnection,
);
self.as_mut()
.data_changed(1, Opaque::new(), QPoint::new(1, 2), &QPoint::new(1, 2));
}
}
}
14 changes: 14 additions & 0 deletions crates/cxx-qt-gen/test_outputs/inheritance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,17 @@ MyObject::unsafeRustMut()
{
return *m_rustObj;
}

QVariant
MyObject::data(QModelIndex const& _index, ::std::int32_t _role) const
{
const ::std::lock_guard<::std::recursive_mutex> guard(*m_rustObjMutex);
return m_rustObj->dataWrapper(*this, _index, _role);
}

bool
MyObject::hasChildren(QModelIndex const& _parent) const
{
const ::std::lock_guard<::std::recursive_mutex> guard(*m_rustObjMutex);
return m_rustObj->hasChildrenWrapper(*this, _parent);
}
3 changes: 3 additions & 0 deletions crates/cxx-qt-gen/test_outputs/inheritance.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class MyObject : public QAbstractItemModel
MyObjectRust& unsafeRustMut();

public:
Q_INVOKABLE QVariant data(QModelIndex const& _index,
::std::int32_t _role) const override;
Q_INVOKABLE bool hasChildren(QModelIndex const& _parent) const override;
template<class... Args>
bool hasChildrenCxxQtInherit(Args... args) const
{
Expand Down
44 changes: 34 additions & 10 deletions crates/cxx-qt-gen/test_outputs/inheritance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@ mod inheritance {
include!("cxx-qt-lib/qvariant.h");
type QVariant = cxx_qt_lib::QVariant;
}
impl qobject::MyObject {
#[qinvokable(cxx_override)]
pub fn data(&self, _index: &QModelIndex, _role: i32) -> QVariant {
QVariant::default()
}
#[qinvokable(cxx_override)]
pub fn has_children(&self, _parent: &QModelIndex) -> bool {
false
}
}
unsafe extern "C++" {
include ! (< QtCore / QObject >);
include!("cxx-qt-lib/qt.h");
Expand Down Expand Up @@ -46,6 +36,19 @@ mod inheritance {
#[cxx_name = "MyObjectRust"]
type MyObject;
}
extern "Rust" {
#[cxx_name = "dataWrapper"]
fn data_wrapper(
self: &MyObject,
cpp: &MyObjectQt,
_index: &QModelIndex,
_role: i32,
) -> QVariant;
}
extern "Rust" {
#[cxx_name = "hasChildrenWrapper"]
fn has_children_wrapper(self: &MyObject, cpp: &MyObjectQt, _parent: &QModelIndex) -> bool;
}
unsafe extern "C++" {
#[doc = " Inherited hasChildren from the base class"]
#[cxx_name = "hasChildrenCxxQtInherit"]
Expand Down Expand Up @@ -84,6 +87,27 @@ pub mod cxx_qt_inheritance {
pub struct MyObject {
data: Vec<i32>,
}
impl MyObject {
#[doc(hidden)]
pub fn data_wrapper(
self: &MyObject,
cpp: &MyObjectQt,
_index: &QModelIndex,
_role: i32,
) -> QVariant {
return cpp.data(_index, _role);
}
}
impl MyObject {
#[doc(hidden)]
pub fn has_children_wrapper(
self: &MyObject,
cpp: &MyObjectQt,
_parent: &QModelIndex,
) -> bool {
return cpp.has_children(_parent);
}
}
impl cxx_qt::Locking for MyObjectQt {}
impl cxx_qt::CxxQtType for MyObjectQt {
type Rust = MyObject;
Expand Down
45 changes: 0 additions & 45 deletions crates/cxx-qt-gen/test_outputs/invokables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,6 @@ mod ffi {
include!("cxx-qt-lib/qpoint.h");
type QPoint = cxx_qt_lib::QPoint;
}
impl qobject::MyObject {
pub fn invokable(&self) {
println!("invokable");
}
pub fn invokable_mutable(self: Pin<&mut Self>) {
println!("This method is mutable!");
}
pub fn invokable_parameters(&self, opaque: &QColor, trivial: &QPoint, primitive: i32) {
println!(
"Red: {}, Point X: {}, Number: {}",
opaque.red(),
trivial.x(),
primitive,
);
}
pub fn invokable_return_opaque(self: Pin<&mut Self>) -> UniquePtr<Opaque> {
Opaque::new()
}
pub fn invokable_return_trivial(self: Pin<&mut Self>) -> QPoint {
QPoint::new(1, 2)
}
pub fn invokable_final(&self) {
println!("Final");
}
pub fn invokable_override(&self) {
println!("Override");
}
pub fn invokable_virtual(&self) {
println!("Virtual");
}
pub fn cpp_context_method(&self) {
println!("C++ context method");
}
pub fn cpp_context_method_mutable(self: Pin<&mut Self>) {
println!("mutable method");
}
pub fn cpp_context_method_return_opaque(&self) -> UniquePtr<Opaque> {
Opaque::new()
}
}
unsafe extern "C++" {
include ! (< QtCore / QObject >);
include!("cxx-qt-lib/qt.h");
Expand Down Expand Up @@ -175,11 +135,6 @@ pub mod cxx_qt_ffi {
use std::pin::Pin;
#[doc(hidden)]
type UniquePtr<T> = cxx::UniquePtr<T>;
impl MyObject {
pub fn rust_only_method(&self) {
println!("QML or C++ can't call this :)");
}
}
#[derive(Default)]
pub struct MyObject;
impl MyObject {
Expand Down
14 changes: 14 additions & 0 deletions crates/cxx-qt-gen/test_outputs/passthrough_and_naming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ MyObject::propertyNameChangedConnect(::rust::Fn<void(MyObject&)> func,
type);
}

void
MyObject::invokableName()
{
const ::std::lock_guard<::std::recursive_mutex> guard(*m_rustObjMutex);
m_rustObj->invokableNameWrapper(*this);
}

::QMetaObject::Connection
MyObject::readyConnect(::rust::Fn<void(MyObject&)> func,
::Qt::ConnectionType type)
Expand Down Expand Up @@ -117,6 +124,13 @@ SecondObject::propertyNameChangedConnect(::rust::Fn<void(SecondObject&)> func,
type);
}

void
SecondObject::invokableName()
{

m_rustObj->invokableNameWrapper(*this);
}

::QMetaObject::Connection
SecondObject::readyConnect(::rust::Fn<void(SecondObject&)> func,
::Qt::ConnectionType type)
Expand Down
2 changes: 2 additions & 0 deletions crates/cxx-qt-gen/test_outputs/passthrough_and_naming.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class MyObject : public QStringListModel
::QMetaObject::Connection propertyNameChangedConnect(
::rust::Fn<void(MyObject&)> func,
::Qt::ConnectionType type);
Q_INVOKABLE void invokableName();
Q_SIGNAL void ready();
::QMetaObject::Connection readyConnect(::rust::Fn<void(MyObject&)> func,
::Qt::ConnectionType type);
Expand Down Expand Up @@ -75,6 +76,7 @@ class SecondObject : public QObject
::QMetaObject::Connection propertyNameChangedConnect(
::rust::Fn<void(SecondObject&)> func,
::Qt::ConnectionType type);
Q_INVOKABLE void invokableName();
Q_SIGNAL void ready();
::QMetaObject::Connection readyConnect(::rust::Fn<void(SecondObject&)> func,
::Qt::ConnectionType type);
Expand Down
Loading

0 comments on commit 342d74f

Please sign in to comment.