-
Notifications
You must be signed in to change notification settings - Fork 87
Draft: Add support for attributes to #[qproperty] #451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,15 +4,30 @@ | |
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't forget to add an entry to the CHANGELOG.md :-) And update anything in the book and we'll have to find somewhere in the properties example of qml_features to use it |
||
|
||
use crate::generator::{cpp::types::CppType, naming::property::QPropertyName}; | ||
use crate::parser::property::ParsedQProperty; | ||
|
||
/// Generate the metaobject line for a given property | ||
pub fn generate(idents: &QPropertyName, cxx_ty: &CppType) -> String { | ||
pub fn generate(idents: &QPropertyName, property: &ParsedQProperty, cxx_ty: &CppType) -> String { | ||
let getter_setter_not_explicit = property.get.is_none() && property.set.is_none(); | ||
|
||
let getter = if getter_setter_not_explicit || property.get.is_some() { | ||
format!("READ {ident_getter}", ident_getter = idents.getter.cpp) | ||
} else { | ||
String::new() | ||
}; | ||
|
||
let setter = if getter_setter_not_explicit || property.set.is_some() { | ||
format!("WRITE {ident_setter}", ident_setter = idents.setter.cpp) | ||
} else { | ||
String::new() | ||
}; | ||
|
||
format!( | ||
"Q_PROPERTY({ty} {ident} READ {ident_getter} WRITE {ident_setter} NOTIFY {ident_notify})", | ||
"Q_PROPERTY({ty} {ident} {getter} {setter} NOTIFY {ident_notify})", | ||
ty = cxx_ty.as_cxx_ty(), | ||
ident = idents.name.cpp, | ||
ident_getter = idents.getter.cpp, | ||
ident_setter = idents.setter.cpp, | ||
getter = getter, | ||
setter = setter, | ||
ident_notify = idents.notify.cpp, | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ use crate::{ | |
use quote::quote; | ||
use syn::{Ident, ImplItemMethod, Item, Result}; | ||
|
||
#[derive(Default)] | ||
#[derive(Default, Debug)] | ||
pub struct GeneratedRustQObjectBlocks { | ||
/// Module for the CXX bridge | ||
pub cxx_mod_contents: Vec<Item>, | ||
|
@@ -33,6 +33,7 @@ impl GeneratedRustQObjectBlocks { | |
} | ||
} | ||
|
||
#[derive(Debug)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any reasoning for these extra derive Debug's ? They could be done in a separate commit if they are useful ... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mostly for debugging, I'll remove then |
||
pub struct GeneratedRustQObject { | ||
/// Ident of the Rust name for the C++ object | ||
pub cpp_struct_ident: Ident, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove before merging