From fddfbd59c50b3133affd726e8787c961d2e569a7 Mon Sep 17 00:00:00 2001 From: Alison Watson Date: Wed, 3 Jul 2019 22:33:40 -0400 Subject: [PATCH] add base class property for objects --- AUTHORS | 1 + src/configuration.rs | 4 ++++ src/cpp.rs | 25 ++++++++++++++++--------- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/AUTHORS b/AUTHORS index 22b7828..fdb1f42 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,4 +1,5 @@ Code: + Alison G. Watson Jos van den Oever Art: Alessandro Longo diff --git a/src/configuration.rs b/src/configuration.rs index b63b5a9..1bd1c9f 100644 --- a/src/configuration.rs +++ b/src/configuration.rs @@ -42,6 +42,8 @@ mod json { pub object_type: super::ObjectType, #[serde(default)] pub properties: BTreeMap, + #[serde(rename = "baseClass", default)] + pub base_class: String, } #[derive(Deserialize)] @@ -135,6 +137,7 @@ pub struct Object { pub item_properties: BTreeMap, pub object_type: ObjectType, pub properties: BTreeMap, + 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); diff --git a/src/cpp.rs b/src/cpp.rs index 9b11823..5709286 100644 --- a/src/cpp.rs +++ b/src/cpp.rs @@ -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, 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, 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)?;