add base class property for objects

master
an 2019-07-03 22:33:40 -04:00
parent 874d6c36ce
commit fddfbd59c5
3 changed files with 21 additions and 9 deletions

View File

@ -1,4 +1,5 @@
Code:
Alison G. Watson <marrub@greyserv.net>
Jos van den Oever <vandenoever@kde.org>
Art:
Alessandro Longo <alessandro.longo@kdemail.net>

View File

@ -42,6 +42,8 @@ mod json {
pub object_type: super::ObjectType,
#[serde(default)]
pub properties: BTreeMap<String, Property>,
#[serde(rename = "baseClass", default)]
pub base_class: String,
}
#[derive(Deserialize)]
@ -135,6 +137,7 @@ pub struct Object {
pub item_properties: BTreeMap<String, ItemProperty>,
pub object_type: ObjectType,
pub properties: BTreeMap<String, Property>,
pub base_class: String,
}
impl ObjectPrivate for Object {
@ -454,6 +457,7 @@ fn post_process_object(
object_type: a.1.object_type,
functions: a.1.functions.clone(),
item_properties: a.1.item_properties.clone(),
base_class: a.1.base_class.clone(),
properties,
});
b.insert(a.0.clone(), object);

View File

@ -24,11 +24,18 @@ fn write_property(name: &str) -> String {
format!("WRITE set{} ", upper_initial(name))
}
fn base_type(o: &Object) -> &str {
if o.object_type != ObjectType::Object {
return "QAbstractItemModel";
}
"QObject"
fn base_type(o: &Object) -> (&str, bool) {
let model = o.object_type != ObjectType::Object;
let name = if o.base_class != "" {
&o.base_class
} else if o.object_type == ObjectType::Object {
"QAbstractItemModel"
} else {
"QObject"
};
(name, model)
}
fn model_is_writable(o: &Object) -> bool {
@ -121,7 +128,7 @@ class {} : public {}
{{
Q_OBJECT",
o.name,
base_type(o)
base_type(o).0
)?;
for object in conf.objects.values() {
if object.contains_object() && o.name != object.name {
@ -200,7 +207,7 @@ public:
}
writeln!(h, "){};", if f.mutable { "" } else { " const" })?;
}
if base_type(o) == "QAbstractItemModel" {
if base_type(o).1 {
write_header_item_model(h, o)?;
}
writeln!(h, "Q_SIGNALS:")?;
@ -373,7 +380,7 @@ fn write_cpp_object(w: &mut Vec<u8>, o: &Object, conf: &Config) -> Result<()> {
"{}::{0}(bool /*owned*/, QObject *parent):
{}(parent),",
o.name,
base_type(o)
base_type(o).0
)?;
initialize_members_zero(w, o)?;
writeln!(
@ -392,7 +399,7 @@ fn write_cpp_object(w: &mut Vec<u8>, o: &Object, conf: &Config) -> Result<()> {
{}::{0}(QObject *parent):
{}(parent),",
o.name,
base_type(o)
base_type(o).0
)?;
initialize_members_zero(w, o)?;
write!(w, " m_d({}_new(this", lcname)?;