diff --git a/examples/graph/src/main.rs b/examples/graph/src/main.rs index 7b1ff0a3..c7f4b8ea 100644 --- a/examples/graph/src/main.rs +++ b/examples/graph/src/main.rs @@ -1,14 +1,14 @@ #![allow(non_snake_case)] #![allow(unused_variables)] -#[macro_use] -extern crate qmetaobject; -use qmetaobject::scenegraph::*; -use qmetaobject::*; + #[macro_use] extern crate cstr; #[macro_use] extern crate cpp; +use qmetaobject::scenegraph::*; +use qmetaobject::*; + mod nodes; #[derive(Default, QObject)] diff --git a/examples/graph/src/nodes.rs b/examples/graph/src/nodes.rs index 0dc80ad7..2411d71d 100644 --- a/examples/graph/src/nodes.rs +++ b/examples/graph/src/nodes.rs @@ -1,5 +1,5 @@ use qmetaobject::scenegraph::SGNode; -use qmetaobject::{QColor, QQuickItem, QRectF}; +use qmetaobject::{qrc, QColor, QQuickItem, QRectF}; qrc! { init_resource, diff --git a/qmetaobject/src/connections.rs b/qmetaobject/src/connections.rs index 6fd157f8..b70a023a 100644 --- a/qmetaobject/src/connections.rs +++ b/qmetaobject/src/connections.rs @@ -282,8 +282,9 @@ impl Signal { /// # Example /// /// ``` - /// # #[macro_use] extern crate cpp; - /// # use qmetaobject::*; + /// #[macro_use] extern crate cpp; + /// use qmetaobject::*; + /// /// fn object_name_changed() -> Signal { /// unsafe { /// Signal::new(cpp!([] -> SignalInner as "SignalInner" { diff --git a/qmetaobject/src/future.rs b/qmetaobject/src/future.rs index c68d7e89..f96c9d11 100644 --- a/qmetaobject/src/future.rs +++ b/qmetaobject/src/future.rs @@ -1,4 +1,5 @@ use std::future::Future; +use std::mem::replace; use std::os::raw::c_void; use std::pin::Pin; use std::task::{Context, Poll, RawWaker, RawWakerVTable, Waker}; @@ -90,7 +91,7 @@ cpp! {{ ~Waker() { rust!(QtDestroyFuture [future: *mut dyn Future as "TraitObject"] { - std::mem::drop(Box::from_raw(future)) + drop(Box::from_raw(future)); }); } }; @@ -160,7 +161,7 @@ pub unsafe fn wait_on_signal( type Output = ::Tuple; fn poll(mut self: Pin<&mut Self>, ctx: &mut Context) -> Poll { let state = &mut self.0; - *state = match std::mem::replace(state, ConnectionFutureState::Invalid) { + *state = match replace(state, ConnectionFutureState::Invalid) { ConnectionFutureState::Finished { result } => { return Poll::Ready(result); } @@ -181,7 +182,7 @@ pub unsafe fn wait_on_signal( for *mut ConnectionFutureState { unsafe fn apply(&mut self, a: *const *const c_void) { - if let ConnectionFutureState::Started { mut handle, waker } = std::mem::replace( + if let ConnectionFutureState::Started { mut handle, waker } = replace( &mut **self, ConnectionFutureState::Finished { result: Args::args_array_to_tuple(a) }, ) { diff --git a/qmetaobject/src/lib.rs b/qmetaobject/src/lib.rs index 90c706eb..d64c4b90 100644 --- a/qmetaobject/src/lib.rs +++ b/qmetaobject/src/lib.rs @@ -22,7 +22,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ``` #[macro_use] extern crate cstr; - extern crate qmetaobject; use qmetaobject::*; @@ -88,7 +87,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. All the method are provided so you can just implement the QMetaType like this: ```rust - # use qmetaobject::QMetaType; + use qmetaobject::QMetaType; + #[derive(Default, Clone)] struct MyPoint(u32, u32); @@ -115,19 +115,20 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. This can be done like so: ``` - # extern crate qmetaobject; - # use qmetaobject::*; - #[derive(QObject,Default)] + use qmetaobject::*; + # use std::cell::RefCell; + + #[derive(QObject, Default)] struct MyAsyncObject { base: qt_base_class!(trait QObject), result: qt_property!(QString; NOTIFY result_changed), result_changed: qt_signal!(), recompute_result: qt_method!(fn recompute_result(&self, name: String) { let qptr = QPointer::from(&*self); - let set_value = qmetaobject::queued_callback(move |val: QString| { - qptr.as_pinned().map(|self_| { - self_.borrow_mut().result = val; - self_.borrow().result_changed(); + let set_value = queued_callback(move |val: QString| { + qptr.as_pinned().map(|this| { + this.borrow_mut().result = val; + this.borrow().result_changed(); }); }); std::thread::spawn(move || { @@ -137,9 +138,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. }).join(); }) } - # let obj = std::cell::RefCell::new(MyAsyncObject::default()); + # let obj = RefCell::new(MyAsyncObject::default()); # let mut engine = QmlEngine::new(); - # unsafe { qmetaobject::connect( + # unsafe { connect( # QObject::cpp_construct(&obj), # obj.borrow().result_changed.to_cpp_representation(&*obj.borrow()), # || engine.quit() @@ -157,9 +158,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #[macro_use] extern crate cpp; -#[allow(unused_imports)] -#[macro_use] -extern crate qmetaobject_impl; #[doc(hidden)] pub use qmetaobject_impl::*; @@ -173,7 +171,8 @@ pub use lazy_static::*; #[macro_export] macro_rules! qmetaobject_lazy_static { ($($t:tt)*) => { lazy_static!($($t)*) } } -use std::cell::RefCell; +use std::cell::{RefCell, RefMut}; +use std::ffi::{CStr, CString}; use std::os::raw::{c_char, c_void}; pub use qttypes; @@ -440,11 +439,11 @@ impl Clone for QPointer { /// Same as std::cell::RefMut, but does not allow to move from pub struct QObjectRefMut<'b, T: QObject + ?Sized + 'b> { old_value: *mut c_void, - inner: std::cell::RefMut<'b, T>, + inner: RefMut<'b, T>, } impl<'b, T: QObject + ?Sized> std::ops::Deref for QObjectRefMut<'b, T> { - type Target = std::cell::RefMut<'b, T>; + type Target = RefMut<'b, T>; #[inline] fn deref(&self) -> &Self::Target { @@ -543,7 +542,7 @@ impl QObjectBox { pub fn into_leaked_cpp_ptr(obj: T) -> *mut c_void { let b = Box::new(RefCell::new(obj)); let obj_ptr = unsafe { QObject::cpp_construct(&b) }; - std::boxed::Box::into_raw(b); + Box::into_raw(b); obj_ptr } @@ -640,7 +639,8 @@ unsafe impl Send for QMetaObject {} /// The trait needs to be like the QObject trait, see the documentation of the QObject trait. /// /// ``` -/// # #[macro_use] extern crate qmetaobject; use qmetaobject::QObject; +/// use qmetaobject::*; +/// /// #[derive(QObject)] /// struct Foo { /// base : qt_base_class!(trait QObject), @@ -670,7 +670,8 @@ macro_rules! qt_base_class { /// `ALIAS` followed by an identifier allow to give a different name than the actual field name. /// /// ``` -/// # #[macro_use] extern crate qmetaobject; use qmetaobject::QObject; +/// use qmetaobject::*; +/// /// #[derive(QObject)] /// struct Foo { /// base: qt_base_class!(trait QObject), @@ -696,7 +697,8 @@ macro_rules! qt_property { /// Can be used within a struct that derives from QObject or QGadget /// /// ``` -/// # #[macro_use] extern crate qmetaobject; use qmetaobject::QObject; +/// use qmetaobject::*; +/// /// #[derive(QObject)] /// struct Foo { /// base: qt_base_class!(trait QObject), @@ -726,7 +728,8 @@ macro_rules! qt_method { /// To be used within a struct that derives from QObject /// /// ``` -/// # #[macro_use] extern crate qmetaobject; use qmetaobject::QObject; +/// use qmetaobject::*; +/// /// #[derive(QObject)] /// struct Foo { /// base: qt_base_class!(trait QObject), @@ -748,15 +751,16 @@ macro_rules! qt_signal { /// the IID /// /// ``` -/// # #[macro_use] extern crate qmetaobject; -/// # use qmetaobject::qtdeclarative::QQmlExtensionPlugin; +/// use qmetaobject::*; +/// # use std::ffi::CStr; +/// /// #[derive(Default, QObject)] /// struct MyPlugin { /// base: qt_base_class!(trait QQmlExtensionPlugin), /// plugin: qt_plugin!("org.qt-project.Qt.QQmlExtensionInterface/1.0") /// } /// # impl QQmlExtensionPlugin for MyPlugin { -/// # fn register_types(&mut self, uri: &std::ffi::CStr) {} +/// # fn register_types(&mut self, uri: &CStr) {} /// # } /// ``` #[macro_export] @@ -841,8 +845,8 @@ where /// callback will not be recieved. /// /// ``` -/// # extern crate qmetaobject; -/// # use qmetaobject::queued_callback; +/// use qmetaobject::queued_callback; +/// /// let callback = queued_callback(|()| println!("hello from main thread")); /// std::thread::spawn(move || {callback(());}).join(); /// ``` @@ -989,10 +993,9 @@ pub const USER_ROLE: i32 = 0x0100; /// ``` /// then the following Rust code: /// ``` -/// # extern crate qmetaobject; -/// # use qmetaobject::qrc; +/// use qmetaobject::qrc; /// # // For maintainers: this is actually tested against real files. -/// // private fn, and base directory shortcut +/// // private fn, base directory shortcut /// qrc!(my_resource_1, /// "tests/qml" as "foo1" { /// "main.qml", @@ -1016,6 +1019,7 @@ pub const USER_ROLE: i32 = 0x0100; /// # fn use_resource(_r: &str) { /// # // at the time of writing, it is the only way to test the existence of a resource. /// # use qmetaobject::*; +/// # /// # let mut engine = QmlEngine::new(); /// # let mut c = QmlComponent::new(&engine); /// # c.load_url(QUrl::from(QString::from("qrc:/foo2/baz/Foo.qml")), CompilationMode::PreferSynchronous); diff --git a/qmetaobject/src/listmodel.rs b/qmetaobject/src/listmodel.rs index 97191ee6..3a8e6316 100644 --- a/qmetaobject/src/listmodel.rs +++ b/qmetaobject/src/listmodel.rs @@ -223,7 +223,7 @@ where QVariant::default() } } - fn role_names(&self) -> std::collections::HashMap { + fn role_names(&self) -> HashMap { T::names().iter().enumerate().map(|(i, x)| (i as i32 + USER_ROLE, x.clone())).collect() } } diff --git a/qmetaobject/src/log.rs b/qmetaobject/src/log.rs index 8085518f..a7e4df74 100644 --- a/qmetaobject/src/log.rs +++ b/qmetaobject/src/log.rs @@ -1,5 +1,6 @@ //! Logging facilities and forwarding +use std::ffi::CStr; use std::os::raw::c_char; #[cfg(feature = "log")] @@ -33,7 +34,7 @@ impl QMessageLogContext { if x.is_null() { return ""; } - std::ffi::CStr::from_ptr(x).to_str().unwrap() + CStr::from_ptr(x).to_str().unwrap() } } @@ -46,7 +47,7 @@ impl QMessageLogContext { if x.is_null() { return ""; } - std::ffi::CStr::from_ptr(x).to_str().unwrap() + CStr::from_ptr(x).to_str().unwrap() } } @@ -59,7 +60,7 @@ impl QMessageLogContext { if x.is_null() { return ""; } - std::ffi::CStr::from_ptr(x).to_str().unwrap() + CStr::from_ptr(x).to_str().unwrap() } } } diff --git a/qmetaobject/src/qmetatype.rs b/qmetaobject/src/qmetatype.rs index 707a266b..2271b3eb 100644 --- a/qmetaobject/src/qmetatype.rs +++ b/qmetaobject/src/qmetatype.rs @@ -18,12 +18,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. use super::*; fn register_metatype_common( - name: *const std::os::raw::c_char, + name: *const c_char, gadget_metaobject: *const QMetaObject, ) -> i32 { use std::any::TypeId; use std::collections::{HashMap, HashSet}; - use std::ffi::{CStr, CString}; use std::sync::Mutex; lazy_static! { @@ -164,7 +163,8 @@ fn register_metatype_qobject() -> i32 { /// as a parameter of a qt_method! /// /// ``` -/// # use ::qmetaobject::QMetaType; +/// use qmetaobject::QMetaType; +/// /// #[derive(Default, Clone)] /// struct MyStruct(u32, String); /// @@ -176,7 +176,7 @@ pub trait QMetaType: Clone + Default + 'static { /// See the Qt documentation of qRegisterMetaType() /// /// The default implementation should work for most types - fn register(name: Option<&std::ffi::CStr>) -> i32 { + fn register(name: Option<&CStr>) -> i32 { register_metatype_common::( name.map_or(std::ptr::null(), |x| x.as_ptr()), std::ptr::null(), @@ -240,7 +240,7 @@ impl QMetaType for String { macro_rules! qdeclare_builtin_metatype { ($name:ty => $value:expr) => { impl QMetaType for $name { - fn register(_name: Option<&std::ffi::CStr>) -> i32 { + fn register(_name: Option<&CStr>) -> i32 { $value } } @@ -275,7 +275,7 @@ qdeclare_builtin_metatype! {QSizeF => 22} qdeclare_builtin_metatype! {QPoint => 25} qdeclare_builtin_metatype! {QPointF => 26} impl QMetaType for QVariant { - fn register(_name: Option<&std::ffi::CStr>) -> i32 { + fn register(_name: Option<&CStr>) -> i32 { 41 } fn to_qvariant(&self) -> QVariant { @@ -305,7 +305,7 @@ impl QMetaType for QJSValue {} /// /// Don't implement this trait, implement the QMetaType trait. pub trait PropertyType { - fn register_type(name: &std::ffi::CStr) -> i32; + fn register_type(name: &CStr) -> i32; // Note: this is &mut self because of the lazy initialization of the QObject* for the QObject impl unsafe fn pass_to_qt(&mut self, a: *mut c_void); unsafe fn read_from_qt(a: *const c_void) -> Self; @@ -315,7 +315,7 @@ impl PropertyType for T where T: QMetaType, { - fn register_type(name: &std::ffi::CStr) -> i32 { + fn register_type(name: &CStr) -> i32 { ::register(Some(name)) } @@ -332,21 +332,21 @@ where } } -impl PropertyType for ::std::cell::RefCell +impl PropertyType for RefCell where T: QObject, { - fn register_type(_name: &::std::ffi::CStr) -> i32 { + fn register_type(_name: &CStr) -> i32 { register_metatype_qobject::() } - unsafe fn pass_to_qt(&mut self, a: *mut ::std::os::raw::c_void) { + unsafe fn pass_to_qt(&mut self, a: *mut c_void) { let pinned = QObjectPinned::new(self); - let r = a as *mut *const ::std::os::raw::c_void; + let r = a as *mut *const c_void; *r = pinned.get_or_create_cpp_object() } - unsafe fn read_from_qt(_a: *const ::std::os::raw::c_void) -> Self { + unsafe fn read_from_qt(_a: *const c_void) -> Self { panic!("Cannot write into an Object property"); } } @@ -355,21 +355,21 @@ impl PropertyType for QPointer where T: QObject, { - fn register_type(_name: &::std::ffi::CStr) -> i32 { + fn register_type(_name: &CStr) -> i32 { register_metatype_qobject::() } - unsafe fn pass_to_qt(&mut self, a: *mut ::std::os::raw::c_void) { + unsafe fn pass_to_qt(&mut self, a: *mut c_void) { let pinned = self.as_pinned(); - let r = a as *mut *const ::std::os::raw::c_void; + let r = a as *mut *const c_void; match pinned { Some(pinned) => *r = pinned.get_or_create_cpp_object(), None => *r = std::ptr::null(), } } - unsafe fn read_from_qt(a: *const ::std::os::raw::c_void) -> Self { - let r = a as *const *mut ::std::os::raw::c_void; + unsafe fn read_from_qt(a: *const c_void) -> Self { + let r = a as *const *mut c_void; if a.is_null() || (*r).is_null() { Self::default() } else { @@ -387,7 +387,7 @@ fn test_qmetatype() { } impl QMetaType for MyInt {} - assert_eq!(MyInt::register(Some(&std::ffi::CString::new("MyInt").unwrap())), MyInt::id()); + assert_eq!(MyInt::register(Some(&CString::new("MyInt").unwrap())), MyInt::id()); let m42 = MyInt { x: 42 }; let m43 = MyInt { x: 43 }; @@ -406,7 +406,7 @@ fn test_qmetatype_register_wrong_type1() { struct MyType {} impl QMetaType for MyType {} // registering with the name of an existing type should panic - MyType::register(Some(&std::ffi::CString::new("QString").unwrap())); + MyType::register(Some(&CString::new("QString").unwrap())); } #[test] @@ -415,9 +415,9 @@ fn test_qmetatype_register_wrong_type2() { #[derive(Default, Clone, Debug, Eq, PartialEq)] struct MyType {} impl QMetaType for MyType {} - String::register(Some(&std::ffi::CString::new("String").unwrap())); + String::register(Some(&CString::new("String").unwrap())); // registering with the name of an existing type should panic - MyType::register(Some(&std::ffi::CString::new("String").unwrap())); + MyType::register(Some(&CString::new("String").unwrap())); } #[test] diff --git a/qmetaobject/src/qtdeclarative.rs b/qmetaobject/src/qtdeclarative.rs index 1e2f49b9..4c021e6a 100644 --- a/qmetaobject/src/qtdeclarative.rs +++ b/qmetaobject/src/qtdeclarative.rs @@ -15,8 +15,8 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FO OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -use super::scenegraph::*; -use super::*; +use crate::scenegraph::*; +use crate::*; /// Qt is not thread safe, and the engine can only be created once and in one thread. /// So this is a guard that will be used to panic if the engine is created twice @@ -80,8 +80,6 @@ cpp_class!( impl QmlEngine { /// Create a new QmlEngine pub fn new() -> QmlEngine { - use std::ffi::CString; - let mut arguments: Vec<*mut c_char> = std::env::args() .map(|arg| CString::new(arg.into_bytes()).expect("argument contains invalid c-string!")) .map(|arg| arg.into_raw()) @@ -387,10 +385,10 @@ impl QmlComponent { /// /// Refer to the Qt documentation for qmlRegisterType. pub fn qml_register_type( - uri: &std::ffi::CStr, + uri: &CStr, version_major: u32, version_minor: u32, - qml_name: &std::ffi::CStr, + qml_name: &CStr, ) { let uri_ptr = uri.as_ptr(); let qml_name_ptr = qml_name.as_ptr(); @@ -517,10 +515,10 @@ pub trait QSingletonInit { /// /// [qt]: https://doc.qt.io/qt-5/qqmlengine.html#qmlRegisterSingletonType-3 pub fn qml_register_singleton_type( - uri: &std::ffi::CStr, + uri: &CStr, version_major: u32, version_minor: u32, - qml_name: &std::ffi::CStr, + qml_name: &CStr, ) { let uri_ptr = uri.as_ptr(); let qml_name_ptr = qml_name.as_ptr(); @@ -615,10 +613,10 @@ pub fn qml_register_singleton_type( - uri: &std::ffi::CStr, + uri: &CStr, version_major: u32, version_minor: u32, - type_name: &std::ffi::CStr, + type_name: &CStr, obj: T, ) { let uri_ptr = uri.as_ptr(); @@ -654,10 +652,10 @@ pub fn qml_register_singleton_instance( /// [qt]: https://doc.qt.io/qt-5/qqmlengine.html#qmlRegisterUncreatableMetaObject #[cfg(qt_5_8)] pub fn qml_register_enum( - uri: &std::ffi::CStr, + uri: &CStr, version_major: u32, version_minor: u32, - qml_name: &std::ffi::CStr, + qml_name: &CStr, ) { let uri_ptr = uri.as_ptr(); let qml_name_ptr = qml_name.as_ptr(); @@ -974,7 +972,9 @@ mod qjsvalue_tests { /// See also the 'qmlextensionplugins' example. /// /// ``` -/// # extern crate qmetaobject; use qmetaobject::*; +/// use qmetaobject::*; +/// use std::ffi::CStr; +/// /// #[derive(Default, QObject)] /// struct QExampleQmlPlugin { /// base: qt_base_class!(trait QQmlExtensionPlugin), @@ -982,12 +982,11 @@ mod qjsvalue_tests { /// } /// /// impl QQmlExtensionPlugin for QExampleQmlPlugin { -/// fn register_types(&mut self, uri: &std::ffi::CStr) { +/// fn register_types(&mut self, uri: &CStr) { /// // call `qml_register_type` here /// } /// } /// ``` - pub trait QQmlExtensionPlugin: QObject { #[doc(hidden)] // implementation detail for the QObject custom derive fn get_object_description() -> &'static QObjectDescription @@ -1002,7 +1001,7 @@ pub trait QQmlExtensionPlugin: QObject { } /// Refer to the Qt documentation of QQmlExtensionPlugin::registerTypes - fn register_types(&mut self, uri: &std::ffi::CStr); + fn register_types(&mut self, uri: &CStr); } cpp! {{ @@ -1013,9 +1012,9 @@ cpp! {{ void registerTypes(const char *uri) override { rust!(Rust_QQmlExtensionPlugin_registerTypes[ rust_object: QObjectPinned as "TraitObject", - uri: *const std::os::raw::c_char as "const char *" + uri: *const c_char as "const char *" ] { - rust_object.borrow_mut().register_types(unsafe { std::ffi::CStr::from_ptr(uri) }); + rust_object.borrow_mut().register_types(unsafe { CStr::from_ptr(uri) }); }); } }; diff --git a/qmetaobject/src/scenegraph.rs b/qmetaobject/src/scenegraph.rs index ecd45985..ac826818 100644 --- a/qmetaobject/src/scenegraph.rs +++ b/qmetaobject/src/scenegraph.rs @@ -16,9 +16,7 @@ OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#[cfg(qt_5_8)] use super::*; -use std::os::raw::c_void; /// A typed node in the scene graph /// @@ -120,12 +118,15 @@ impl SGNode { /// call reset() if you want to change the size. /// /// ``` - /// # use qmetaobject::{QRectF, QObject, qtdeclarative::QQuickItem}; - /// # use qmetaobject::scenegraph::{SGNode, ContainerNode, RectangleNode}; + /// extern crate qttypes; + /// # use qmetaobject::{QObject, qtdeclarative::QQuickItem}; + /// use qmetaobject::scenegraph::{SGNode, ContainerNode, RectangleNode}; + /// use qttypes::QRectF; + /// /// # struct Dummy { items : Vec, _phantom :T } /// # impl QQuickItem for Dummy where Dummy : QObject { /// // in the reimplementation of QQuickItem::update_paint_node - /// fn update_paint_node(&mut self, mut node : SGNode ) -> SGNode { + /// fn update_paint_node(&mut self, mut node: SGNode) -> SGNode { /// let items : &Vec = &self.items; /// node.update_dynamic(items.iter(), /// |i, mut n| -> SGNode { n.create(self); n.set_rect(*i); n }); @@ -180,8 +181,11 @@ impl SGNode { /// In this example, the node has two children node /// /// ``` - /// # use qmetaobject::{QRectF, QObject, qtdeclarative::QQuickItem}; - /// # use qmetaobject::scenegraph::{SGNode, ContainerNode, RectangleNode}; + /// extern crate qttypes; + /// # use qmetaobject::{QObject, qtdeclarative::QQuickItem}; + /// use qmetaobject::scenegraph::{SGNode, ContainerNode, RectangleNode}; + /// use qttypes::QRectF; + /// /// # struct Dummy { items : Vec, _phantom :T } /// # impl QQuickItem for Dummy where Dummy : QObject { /// // in the reimplementation of QQuickItem::update_paint_node @@ -339,9 +343,10 @@ impl SGNode { pub enum RectangleNode {} cpp! {{ -#if QT_VERSION < QT_VERSION_CHECK(5, 8, 0) + // Just a stub for compatibility + #if QT_VERSION < QT_VERSION_CHECK(5, 8, 0) struct QSGRectangleNode{}; -#endif + #endif }} #[cfg(qt_5_8)] @@ -349,18 +354,18 @@ impl SGNode { pub fn set_color(&mut self, color: QColor) { let raw = self.raw; cpp!(unsafe [raw as "QSGRectangleNode*", color as "QColor"] { - #if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) - if(raw) raw->setColor(color); - #endif - }); + #if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) + if(raw) raw->setColor(color); + #endif + }); } pub fn set_rect(&mut self, rect: QRectF) { let raw = self.raw; cpp!(unsafe [raw as "QSGRectangleNode*", rect as "QRectF"] { - #if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) - if (raw) raw->setRect(rect); - #endif - }); + #if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) + if (raw) raw->setRect(rect); + #endif + }); } pub fn create(&mut self, item: &dyn QQuickItem) { @@ -369,13 +374,13 @@ impl SGNode { } let item = item.get_cpp_object(); self.raw = cpp!(unsafe [item as "QQuickItem*"] -> *mut c_void as "void*" { - if (!item) return nullptr; - #if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) - if (auto window = item->window()) - return window->createRectangleNode(); - #endif - return nullptr; - }); + #if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) + if (!item) return nullptr; + if (auto window = item->window()) + return window->createRectangleNode(); + #endif + return nullptr; + }); } }