From ea3c8ebc79b22fabf9045be41c6ea3db343eeabe Mon Sep 17 00:00:00 2001 From: Jos van den Oever Date: Sun, 3 Sep 2017 15:13:11 +0200 Subject: [PATCH] Use the name Tree instead of UniformTree --- README.md | 2 +- demo/bindings.json | 4 +-- .../src/implementation/file_system_tree.rs | 4 +-- demo/rust/src/implementation/processes.rs | 12 ++++---- demo/rust/src/interface.rs | 20 ++++++------- src/cpp.cpp | 6 ++-- src/parseJson.cpp | 4 +-- src/rust.cpp | 30 +++++++++---------- src/structs.h | 4 +-- tests/rust_tree/src/implementation.rs | 4 +-- tests/rust_tree/src/interface.rs | 8 ++--- tests/test_tree.json | 2 +- 12 files changed, 50 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index 6ef855e..4a48832 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ This will create four files: * *src/person.h* * *src/person.cpp* -* rust/src/implemenation.rs +* rust/src/implementation.rs * *rust/src/interface.rs* Only `implementation.rs` should be changed. The other files are the binding. `implementation.rs` is initialy created with a simple implementation that is shown here with some comments. diff --git a/demo/bindings.json b/demo/bindings.json index e390d1d..d7c7a90 100644 --- a/demo/bindings.json +++ b/demo/bindings.json @@ -27,7 +27,7 @@ } }, "FileSystemTree": { - "type": "UniformTree", + "type": "Tree", "properties": { "path": { "type": "QString", @@ -92,7 +92,7 @@ } }, "Processes": { - "type": "UniformTree", + "type": "Tree", "properties": { "active": { "type": "bool", diff --git a/demo/rust/src/implementation/file_system_tree.rs b/demo/rust/src/implementation/file_system_tree.rs index 979ccc4..c783fb1 100644 --- a/demo/rust/src/implementation/file_system_tree.rs +++ b/demo/rust/src/implementation/file_system_tree.rs @@ -107,7 +107,7 @@ struct Entry { pub struct RGeneralItemModel { emit: FileSystemTreeEmitter, - model: FileSystemTreeUniformTree, + model: FileSystemTreeTree, entries: Vec>, path: Option, incoming: Incoming, @@ -189,7 +189,7 @@ impl FileSystemTreeTrait for RGeneralItemModel where T: Sync + Send, { - fn create(emit: FileSystemTreeEmitter, model: FileSystemTreeUniformTree) -> Self { + fn create(emit: FileSystemTreeEmitter, model: FileSystemTreeTree) -> Self { let mut tree = RGeneralItemModel { emit: emit, model: model, diff --git a/demo/rust/src/implementation/processes.rs b/demo/rust/src/implementation/processes.rs index 0f4b6ff..0049e64 100644 --- a/demo/rust/src/implementation/processes.rs +++ b/demo/rust/src/implementation/processes.rs @@ -28,7 +28,7 @@ enum ChangeState { pub struct Processes { emit: ProcessesEmitter, - model: ProcessesUniformTree, + model: ProcessesTree, p: ProcessTree, incoming: Arc>>, active: bool, @@ -160,7 +160,7 @@ fn move_process( } fn remove_row( - model: &ProcessesUniformTree, + model: &ProcessesTree, parent: pid_t, row: usize, map: &mut HashMap, @@ -187,7 +187,7 @@ fn remove_row( } fn insert_row( - model: &ProcessesUniformTree, + model: &ProcessesTree, parent: pid_t, row: usize, map: &mut HashMap, @@ -218,7 +218,7 @@ fn cmp_f32(a: f32, b: f32) -> bool { ((a - b) / a).abs() < 0.01 } -fn sync_row(model: &ProcessesUniformTree, pid: pid_t, a: &mut Process, b: &Process) -> f32 { +fn sync_row(model: &ProcessesTree, pid: pid_t, a: &mut Process, b: &Process) -> f32 { let mut changed = a.name != b.name; if changed { a.name.clone_from(&b.name); @@ -246,7 +246,7 @@ fn sync_row(model: &ProcessesUniformTree, pid: pid_t, a: &mut Process, b: &Proce } fn sync_tree( - model: &ProcessesUniformTree, + model: &ProcessesTree, parent: pid_t, amap: &mut HashMap, bmap: &mut HashMap, @@ -303,7 +303,7 @@ fn sync_tree( } impl ProcessesTrait for Processes { - fn create(emit: ProcessesEmitter, model: ProcessesUniformTree) -> Processes { + fn create(emit: ProcessesEmitter, model: ProcessesTree) -> Processes { let (tx, rx) = channel(); let p = Processes { emit: emit.clone(), diff --git a/demo/rust/src/interface.rs b/demo/rust/src/interface.rs index e4217b5..a1a4d48 100644 --- a/demo/rust/src/interface.rs +++ b/demo/rust/src/interface.rs @@ -215,7 +215,7 @@ pub extern "C" fn demo_new( path_changed: path_changed, new_data_ready: file_system_tree_new_data_ready, }; - let model = FileSystemTreeUniformTree { + let model = FileSystemTreeTree { qobject: file_system_tree, data_changed: file_system_tree_data_changed, begin_reset_model: file_system_tree_begin_reset_model, @@ -231,7 +231,7 @@ pub extern "C" fn demo_new( active_changed: active_changed, new_data_ready: processes_new_data_ready, }; - let model = ProcessesUniformTree { + let model = ProcessesTree { qobject: processes, data_changed: processes_data_changed, begin_reset_model: processes_begin_reset_model, @@ -536,7 +536,7 @@ impl FileSystemTreeEmitter { } } -pub struct FileSystemTreeUniformTree { +pub struct FileSystemTreeTree { qobject: *const FileSystemTreeQObject, data_changed: fn(*const FileSystemTreeQObject, usize, usize), begin_reset_model: fn(*const FileSystemTreeQObject), @@ -547,7 +547,7 @@ pub struct FileSystemTreeUniformTree { end_remove_rows: fn(*const FileSystemTreeQObject), } -impl FileSystemTreeUniformTree { +impl FileSystemTreeTree { pub fn data_changed(&self, first: usize, last: usize) { (self.data_changed)(self.qobject, first, last); } @@ -572,7 +572,7 @@ impl FileSystemTreeUniformTree { } pub trait FileSystemTreeTrait { - fn create(emit: FileSystemTreeEmitter, model: FileSystemTreeUniformTree) -> Self; + fn create(emit: FileSystemTreeEmitter, model: FileSystemTreeTree) -> Self; fn emit(&self) -> &FileSystemTreeEmitter; fn path(&self) -> Option<&str>; fn set_path(&mut self, value: Option); @@ -611,7 +611,7 @@ pub extern "C" fn file_system_tree_new( path_changed: path_changed, new_data_ready: file_system_tree_new_data_ready, }; - let model = FileSystemTreeUniformTree { + let model = FileSystemTreeTree { qobject: file_system_tree, data_changed: file_system_tree_data_changed, begin_reset_model: file_system_tree_begin_reset_model, @@ -799,7 +799,7 @@ impl ProcessesEmitter { } } -pub struct ProcessesUniformTree { +pub struct ProcessesTree { qobject: *const ProcessesQObject, data_changed: fn(*const ProcessesQObject, usize, usize), begin_reset_model: fn(*const ProcessesQObject), @@ -810,7 +810,7 @@ pub struct ProcessesUniformTree { end_remove_rows: fn(*const ProcessesQObject), } -impl ProcessesUniformTree { +impl ProcessesTree { pub fn data_changed(&self, first: usize, last: usize) { (self.data_changed)(self.qobject, first, last); } @@ -835,7 +835,7 @@ impl ProcessesUniformTree { } pub trait ProcessesTrait { - fn create(emit: ProcessesEmitter, model: ProcessesUniformTree) -> Self; + fn create(emit: ProcessesEmitter, model: ProcessesTree) -> Self; fn emit(&self) -> &ProcessesEmitter; fn active(&self) -> bool; fn set_active(&mut self, value: bool); @@ -875,7 +875,7 @@ pub extern "C" fn processes_new( active_changed: active_changed, new_data_ready: processes_new_data_ready, }; - let model = ProcessesUniformTree { + let model = ProcessesTree { qobject: processes, data_changed: processes_data_changed, begin_reset_model: processes_begin_reset_model, diff --git a/src/cpp.cpp b/src/cpp.cpp index b3d5b37..2341369 100644 --- a/src/cpp.cpp +++ b/src/cpp.cpp @@ -177,7 +177,7 @@ void writeCppModel(QTextStream& cpp, const Object& o) { const QString lcname(snakeCase(o.name)); QString indexDecl = ", int"; QString index = ", index.row()"; - if (o.type == ObjectType::UniformTree) { + if (o.type == ObjectType::Tree) { indexDecl = ", quintptr"; index = ", index.internalId()"; } @@ -501,7 +501,7 @@ void constructorArgsDecl(QTextStream& cpp, const Object& o, const Configuration& void (*)(%1*, int, int), void (*)(%1*))").arg(o.name); } - if (o.type == ObjectType::UniformTree) { + if (o.type == ObjectType::Tree) { cpp << QString(R"(, void (*)(const %1*, quintptr, bool), void (*)(%1*, quintptr, quintptr), @@ -558,7 +558,7 @@ void constructorArgs(QTextStream& cpp, const QString& prefix, const Object& o, c } )").arg(o.name, QString::number(o.columnCount - 1)); } - if (o.type == ObjectType::UniformTree) { + if (o.type == ObjectType::Tree) { cpp << QString(R"(, [](const %1* o, quintptr id, bool valid) { if (valid) { diff --git a/src/parseJson.cpp b/src/parseJson.cpp index 2b56420..ba73847 100644 --- a/src/parseJson.cpp +++ b/src/parseJson.cpp @@ -149,8 +149,8 @@ parseObject(const QString& name, const QJsonObject& json) { QString type = json.value("type").toString(); if (type == "List") { o.type = ObjectType::List; - } else if (type == "UniformTree") { - o.type = ObjectType::UniformTree; + } else if (type == "Tree") { + o.type = ObjectType::Tree; } else { o.type = ObjectType::Object; } diff --git a/src/rust.cpp b/src/rust.cpp index 98cd9b5..eef2387 100644 --- a/src/rust.cpp +++ b/src/rust.cpp @@ -61,13 +61,13 @@ void rConstructorArgsDecl(QTextStream& r, const QString& name, const Object& o, if (o.type == ObjectType::List) { r << QString(",\n %2_new_data_ready: fn(*const %1QObject)") .arg(o.name, snakeCase(o.name)); - } else if (o.type == ObjectType::UniformTree) { + } else if (o.type == ObjectType::Tree) { r << QString(",\n %2_new_data_ready: fn(*const %1QObject, item: usize, valid: bool)") .arg(o.name, snakeCase(o.name)); } if (o.type != ObjectType::Object) { QString indexDecl; - if (o.type == ObjectType::UniformTree) { + if (o.type == ObjectType::Tree) { indexDecl = " item: usize, valid: bool,"; } r << QString(R"(, @@ -102,7 +102,7 @@ void rConstructorArgs(QTextStream& r, const QString& name, const Object& o, cons } QString model = ""; if (o.type != ObjectType::Object) { - const QString type = o.type == ObjectType::List ? "List" : "UniformTree"; + const QString type = o.type == ObjectType::List ? "List" : "Tree"; model = ", model"; r << QString(R"( }; let model = %1%2 { @@ -145,7 +145,7 @@ pub struct %1Emitter { if (o.type == ObjectType::List) { r << QString(" new_data_ready: fn(*const %1QObject),\n") .arg(o.name); - } else if (o.type == ObjectType::UniformTree) { + } else if (o.type == ObjectType::Tree) { r << QString(" new_data_ready: fn(*const %1QObject, item: usize, valid: bool),\n") .arg(o.name); } @@ -178,7 +178,7 @@ impl %1Emitter { } } )"; - } else if (o.type == ObjectType::UniformTree) { + } else if (o.type == ObjectType::Tree) { r << R"( pub fn new_data_ready(&self, item: Option) { let ptr = *self.qobject.lock().unwrap(); if !ptr.is_null() { @@ -190,12 +190,12 @@ impl %1Emitter { QString modelStruct = ""; if (o.type != ObjectType::Object) { - QString type = o.type == ObjectType::List ? "List" : "UniformTree"; + QString type = o.type == ObjectType::List ? "List" : "Tree"; modelStruct = ", model: " + o.name + type; QString index; QString indexDecl; QString indexCDecl; - if (o.type == ObjectType::UniformTree) { + if (o.type == ObjectType::Tree) { indexDecl = " item: Option,"; indexCDecl = " item: usize, valid: bool,"; index = " item.unwrap_or(13), item.is_some(),"; @@ -270,7 +270,7 @@ pub trait %1Trait { fn fetch_more(&mut self) {} fn sort(&mut self, u8, SortOrder) {} )"; - } else if (o.type == ObjectType::UniformTree) { + } else if (o.type == ObjectType::Tree) { r << R"( fn row_count(&self, Option) -> usize; fn can_fetch_more(&self, Option) -> bool { false @@ -410,7 +410,7 @@ pub unsafe extern "C" fn %2_sort( (&mut *ptr).sort(column, order) } )").arg(o.name, lcname); - } else if (o.type == ObjectType::UniformTree) { + } else if (o.type == ObjectType::Tree) { r << QString(R"( #[no_mangle] pub unsafe extern "C" fn %2_row_count( @@ -488,7 +488,7 @@ pub unsafe extern "C" fn %2_row(ptr: *const %1, item: usize) -> c_int { if (o.type != ObjectType::Object) { QString indexDecl = ", row: c_int"; QString index = "row as usize"; - if (o.type == ObjectType::UniformTree) { + if (o.type == ObjectType::Tree) { indexDecl = ", item: usize"; index = "item"; } @@ -744,9 +744,9 @@ void writeRustImplementationObject(QTextStream& r, const Object& o) { if (o.type == ObjectType::List) { modelStruct = ", model: " + o.name + "List"; r << QString(" model: %1List,\n").arg(o.name); - } else if (o.type == ObjectType::UniformTree) { - modelStruct = ", model: " + o.name + "UniformTree"; - r << QString(" model: %1UniformTree,\n").arg(o.name); + } else if (o.type == ObjectType::Tree) { + modelStruct = ", model: " + o.name + "Tree"; + r << QString(" model: %1Tree,\n").arg(o.name); } for (const Property& p: o.properties) { const QString lc(snakeCase(p.name)); @@ -826,7 +826,7 @@ void writeRustImplementationObject(QTextStream& r, const Object& o) { } if (o.type == ObjectType::List) { r << " fn row_count(&self) -> usize {\n self.list.len()\n }\n"; - } else if (o.type == ObjectType::UniformTree) { + } else if (o.type == ObjectType::Tree) { r << R"( fn row_count(&self, item: Option) -> usize { self.list.len() } @@ -843,7 +843,7 @@ void writeRustImplementationObject(QTextStream& r, const Object& o) { } if (o.type != ObjectType::Object) { QString index; - if (o.type == ObjectType::UniformTree) { + if (o.type == ObjectType::Tree) { index = ", item: usize"; } for (auto ip: o.itemProperties) { diff --git a/src/structs.h b/src/structs.h index 1af89da..8536ad5 100644 --- a/src/structs.h +++ b/src/structs.h @@ -9,7 +9,7 @@ enum class ObjectType { Object, List, - UniformTree + Tree }; enum class BindingType { @@ -129,7 +129,7 @@ struct Configuration { } bool hasListOrTree() const { for (auto o: objects) { - if (o.type == ObjectType::List || o.type == ObjectType::UniformTree) { + if (o.type == ObjectType::List || o.type == ObjectType::Tree) { return true; } } diff --git a/tests/rust_tree/src/implementation.rs b/tests/rust_tree/src/implementation.rs index 0c1c3e9..c51679b 100644 --- a/tests/rust_tree/src/implementation.rs +++ b/tests/rust_tree/src/implementation.rs @@ -10,12 +10,12 @@ struct PersonsItem { pub struct Persons { emit: PersonsEmitter, - model: PersonsUniformTree, + model: PersonsTree, list: Vec, } impl PersonsTrait for Persons { - fn create(emit: PersonsEmitter, model: PersonsUniformTree) -> Persons { + fn create(emit: PersonsEmitter, model: PersonsTree) -> Persons { Persons { emit: emit, model: model, diff --git a/tests/rust_tree/src/interface.rs b/tests/rust_tree/src/interface.rs index e4d17b1..88c5d53 100644 --- a/tests/rust_tree/src/interface.rs +++ b/tests/rust_tree/src/interface.rs @@ -108,7 +108,7 @@ impl PersonsEmitter { } } -pub struct PersonsUniformTree { +pub struct PersonsTree { qobject: *const PersonsQObject, data_changed: fn(*const PersonsQObject, usize, usize), begin_reset_model: fn(*const PersonsQObject), @@ -119,7 +119,7 @@ pub struct PersonsUniformTree { end_remove_rows: fn(*const PersonsQObject), } -impl PersonsUniformTree { +impl PersonsTree { pub fn data_changed(&self, first: usize, last: usize) { (self.data_changed)(self.qobject, first, last); } @@ -144,7 +144,7 @@ impl PersonsUniformTree { } pub trait PersonsTrait { - fn create(emit: PersonsEmitter, model: PersonsUniformTree) -> Self; + fn create(emit: PersonsEmitter, model: PersonsTree) -> Self; fn emit(&self) -> &PersonsEmitter; fn row_count(&self, Option) -> usize; fn can_fetch_more(&self, Option) -> bool { @@ -175,7 +175,7 @@ pub extern "C" fn persons_new( qobject: Arc::new(Mutex::new(persons)), new_data_ready: persons_new_data_ready, }; - let model = PersonsUniformTree { + let model = PersonsTree { qobject: persons, data_changed: persons_data_changed, begin_reset_model: persons_begin_reset_model, diff --git a/tests/test_tree.json b/tests/test_tree.json index df6a68b..1b4129c 100644 --- a/tests/test_tree.json +++ b/tests/test_tree.json @@ -7,7 +7,7 @@ }, "objects": { "Persons": { - "type": "UniformTree", + "type": "Tree", "itemProperties": { "userName": { "type": "QString",