Use the name Tree instead of UniformTree

master
Jos van den Oever 2017-09-03 15:13:11 +02:00
parent bb6b133310
commit ea3c8ebc79
12 changed files with 50 additions and 50 deletions

View File

@ -42,7 +42,7 @@ This will create four files:
* *src/person.h* * *src/person.h*
* *src/person.cpp* * *src/person.cpp*
* rust/src/implemenation.rs * rust/src/implementation.rs
* *rust/src/interface.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. 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.

View File

@ -27,7 +27,7 @@
} }
}, },
"FileSystemTree": { "FileSystemTree": {
"type": "UniformTree", "type": "Tree",
"properties": { "properties": {
"path": { "path": {
"type": "QString", "type": "QString",
@ -92,7 +92,7 @@
} }
}, },
"Processes": { "Processes": {
"type": "UniformTree", "type": "Tree",
"properties": { "properties": {
"active": { "active": {
"type": "bool", "type": "bool",

View File

@ -107,7 +107,7 @@ struct Entry<T: Item> {
pub struct RGeneralItemModel<T: Item> { pub struct RGeneralItemModel<T: Item> {
emit: FileSystemTreeEmitter, emit: FileSystemTreeEmitter,
model: FileSystemTreeUniformTree, model: FileSystemTreeTree,
entries: Vec<Entry<T>>, entries: Vec<Entry<T>>,
path: Option<String>, path: Option<String>,
incoming: Incoming<T>, incoming: Incoming<T>,
@ -189,7 +189,7 @@ impl<T: Item> FileSystemTreeTrait for RGeneralItemModel<T>
where where
T: Sync + Send, T: Sync + Send,
{ {
fn create(emit: FileSystemTreeEmitter, model: FileSystemTreeUniformTree) -> Self { fn create(emit: FileSystemTreeEmitter, model: FileSystemTreeTree) -> Self {
let mut tree = RGeneralItemModel { let mut tree = RGeneralItemModel {
emit: emit, emit: emit,
model: model, model: model,

View File

@ -28,7 +28,7 @@ enum ChangeState {
pub struct Processes { pub struct Processes {
emit: ProcessesEmitter, emit: ProcessesEmitter,
model: ProcessesUniformTree, model: ProcessesTree,
p: ProcessTree, p: ProcessTree,
incoming: Arc<Mutex<Option<ProcessTree>>>, incoming: Arc<Mutex<Option<ProcessTree>>>,
active: bool, active: bool,
@ -160,7 +160,7 @@ fn move_process(
} }
fn remove_row( fn remove_row(
model: &ProcessesUniformTree, model: &ProcessesTree,
parent: pid_t, parent: pid_t,
row: usize, row: usize,
map: &mut HashMap<pid_t, ProcessItem>, map: &mut HashMap<pid_t, ProcessItem>,
@ -187,7 +187,7 @@ fn remove_row(
} }
fn insert_row( fn insert_row(
model: &ProcessesUniformTree, model: &ProcessesTree,
parent: pid_t, parent: pid_t,
row: usize, row: usize,
map: &mut HashMap<pid_t, ProcessItem>, map: &mut HashMap<pid_t, ProcessItem>,
@ -218,7 +218,7 @@ fn cmp_f32(a: f32, b: f32) -> bool {
((a - b) / a).abs() < 0.01 ((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; let mut changed = a.name != b.name;
if changed { if changed {
a.name.clone_from(&b.name); 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( fn sync_tree(
model: &ProcessesUniformTree, model: &ProcessesTree,
parent: pid_t, parent: pid_t,
amap: &mut HashMap<pid_t, ProcessItem>, amap: &mut HashMap<pid_t, ProcessItem>,
bmap: &mut HashMap<pid_t, ProcessItem>, bmap: &mut HashMap<pid_t, ProcessItem>,
@ -303,7 +303,7 @@ fn sync_tree(
} }
impl ProcessesTrait for Processes { impl ProcessesTrait for Processes {
fn create(emit: ProcessesEmitter, model: ProcessesUniformTree) -> Processes { fn create(emit: ProcessesEmitter, model: ProcessesTree) -> Processes {
let (tx, rx) = channel(); let (tx, rx) = channel();
let p = Processes { let p = Processes {
emit: emit.clone(), emit: emit.clone(),

View File

@ -215,7 +215,7 @@ pub extern "C" fn demo_new(
path_changed: path_changed, path_changed: path_changed,
new_data_ready: file_system_tree_new_data_ready, new_data_ready: file_system_tree_new_data_ready,
}; };
let model = FileSystemTreeUniformTree { let model = FileSystemTreeTree {
qobject: file_system_tree, qobject: file_system_tree,
data_changed: file_system_tree_data_changed, data_changed: file_system_tree_data_changed,
begin_reset_model: file_system_tree_begin_reset_model, begin_reset_model: file_system_tree_begin_reset_model,
@ -231,7 +231,7 @@ pub extern "C" fn demo_new(
active_changed: active_changed, active_changed: active_changed,
new_data_ready: processes_new_data_ready, new_data_ready: processes_new_data_ready,
}; };
let model = ProcessesUniformTree { let model = ProcessesTree {
qobject: processes, qobject: processes,
data_changed: processes_data_changed, data_changed: processes_data_changed,
begin_reset_model: processes_begin_reset_model, begin_reset_model: processes_begin_reset_model,
@ -536,7 +536,7 @@ impl FileSystemTreeEmitter {
} }
} }
pub struct FileSystemTreeUniformTree { pub struct FileSystemTreeTree {
qobject: *const FileSystemTreeQObject, qobject: *const FileSystemTreeQObject,
data_changed: fn(*const FileSystemTreeQObject, usize, usize), data_changed: fn(*const FileSystemTreeQObject, usize, usize),
begin_reset_model: fn(*const FileSystemTreeQObject), begin_reset_model: fn(*const FileSystemTreeQObject),
@ -547,7 +547,7 @@ pub struct FileSystemTreeUniformTree {
end_remove_rows: fn(*const FileSystemTreeQObject), end_remove_rows: fn(*const FileSystemTreeQObject),
} }
impl FileSystemTreeUniformTree { impl FileSystemTreeTree {
pub fn data_changed(&self, first: usize, last: usize) { pub fn data_changed(&self, first: usize, last: usize) {
(self.data_changed)(self.qobject, first, last); (self.data_changed)(self.qobject, first, last);
} }
@ -572,7 +572,7 @@ impl FileSystemTreeUniformTree {
} }
pub trait FileSystemTreeTrait { pub trait FileSystemTreeTrait {
fn create(emit: FileSystemTreeEmitter, model: FileSystemTreeUniformTree) -> Self; fn create(emit: FileSystemTreeEmitter, model: FileSystemTreeTree) -> Self;
fn emit(&self) -> &FileSystemTreeEmitter; fn emit(&self) -> &FileSystemTreeEmitter;
fn path(&self) -> Option<&str>; fn path(&self) -> Option<&str>;
fn set_path(&mut self, value: Option<String>); fn set_path(&mut self, value: Option<String>);
@ -611,7 +611,7 @@ pub extern "C" fn file_system_tree_new(
path_changed: path_changed, path_changed: path_changed,
new_data_ready: file_system_tree_new_data_ready, new_data_ready: file_system_tree_new_data_ready,
}; };
let model = FileSystemTreeUniformTree { let model = FileSystemTreeTree {
qobject: file_system_tree, qobject: file_system_tree,
data_changed: file_system_tree_data_changed, data_changed: file_system_tree_data_changed,
begin_reset_model: file_system_tree_begin_reset_model, begin_reset_model: file_system_tree_begin_reset_model,
@ -799,7 +799,7 @@ impl ProcessesEmitter {
} }
} }
pub struct ProcessesUniformTree { pub struct ProcessesTree {
qobject: *const ProcessesQObject, qobject: *const ProcessesQObject,
data_changed: fn(*const ProcessesQObject, usize, usize), data_changed: fn(*const ProcessesQObject, usize, usize),
begin_reset_model: fn(*const ProcessesQObject), begin_reset_model: fn(*const ProcessesQObject),
@ -810,7 +810,7 @@ pub struct ProcessesUniformTree {
end_remove_rows: fn(*const ProcessesQObject), end_remove_rows: fn(*const ProcessesQObject),
} }
impl ProcessesUniformTree { impl ProcessesTree {
pub fn data_changed(&self, first: usize, last: usize) { pub fn data_changed(&self, first: usize, last: usize) {
(self.data_changed)(self.qobject, first, last); (self.data_changed)(self.qobject, first, last);
} }
@ -835,7 +835,7 @@ impl ProcessesUniformTree {
} }
pub trait ProcessesTrait { pub trait ProcessesTrait {
fn create(emit: ProcessesEmitter, model: ProcessesUniformTree) -> Self; fn create(emit: ProcessesEmitter, model: ProcessesTree) -> Self;
fn emit(&self) -> &ProcessesEmitter; fn emit(&self) -> &ProcessesEmitter;
fn active(&self) -> bool; fn active(&self) -> bool;
fn set_active(&mut self, value: bool); fn set_active(&mut self, value: bool);
@ -875,7 +875,7 @@ pub extern "C" fn processes_new(
active_changed: active_changed, active_changed: active_changed,
new_data_ready: processes_new_data_ready, new_data_ready: processes_new_data_ready,
}; };
let model = ProcessesUniformTree { let model = ProcessesTree {
qobject: processes, qobject: processes,
data_changed: processes_data_changed, data_changed: processes_data_changed,
begin_reset_model: processes_begin_reset_model, begin_reset_model: processes_begin_reset_model,

View File

@ -177,7 +177,7 @@ void writeCppModel(QTextStream& cpp, const Object& o) {
const QString lcname(snakeCase(o.name)); const QString lcname(snakeCase(o.name));
QString indexDecl = ", int"; QString indexDecl = ", int";
QString index = ", index.row()"; QString index = ", index.row()";
if (o.type == ObjectType::UniformTree) { if (o.type == ObjectType::Tree) {
indexDecl = ", quintptr"; indexDecl = ", quintptr";
index = ", index.internalId()"; index = ", index.internalId()";
} }
@ -501,7 +501,7 @@ void constructorArgsDecl(QTextStream& cpp, const Object& o, const Configuration&
void (*)(%1*, int, int), void (*)(%1*, int, int),
void (*)(%1*))").arg(o.name); void (*)(%1*))").arg(o.name);
} }
if (o.type == ObjectType::UniformTree) { if (o.type == ObjectType::Tree) {
cpp << QString(R"(, cpp << QString(R"(,
void (*)(const %1*, quintptr, bool), void (*)(const %1*, quintptr, bool),
void (*)(%1*, quintptr, quintptr), 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)); )").arg(o.name, QString::number(o.columnCount - 1));
} }
if (o.type == ObjectType::UniformTree) { if (o.type == ObjectType::Tree) {
cpp << QString(R"(, cpp << QString(R"(,
[](const %1* o, quintptr id, bool valid) { [](const %1* o, quintptr id, bool valid) {
if (valid) { if (valid) {

View File

@ -149,8 +149,8 @@ parseObject(const QString& name, const QJsonObject& json) {
QString type = json.value("type").toString(); QString type = json.value("type").toString();
if (type == "List") { if (type == "List") {
o.type = ObjectType::List; o.type = ObjectType::List;
} else if (type == "UniformTree") { } else if (type == "Tree") {
o.type = ObjectType::UniformTree; o.type = ObjectType::Tree;
} else { } else {
o.type = ObjectType::Object; o.type = ObjectType::Object;
} }

View File

@ -61,13 +61,13 @@ void rConstructorArgsDecl(QTextStream& r, const QString& name, const Object& o,
if (o.type == ObjectType::List) { if (o.type == ObjectType::List) {
r << QString(",\n %2_new_data_ready: fn(*const %1QObject)") r << QString(",\n %2_new_data_ready: fn(*const %1QObject)")
.arg(o.name, snakeCase(o.name)); .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)") r << QString(",\n %2_new_data_ready: fn(*const %1QObject, item: usize, valid: bool)")
.arg(o.name, snakeCase(o.name)); .arg(o.name, snakeCase(o.name));
} }
if (o.type != ObjectType::Object) { if (o.type != ObjectType::Object) {
QString indexDecl; QString indexDecl;
if (o.type == ObjectType::UniformTree) { if (o.type == ObjectType::Tree) {
indexDecl = " item: usize, valid: bool,"; indexDecl = " item: usize, valid: bool,";
} }
r << QString(R"(, r << QString(R"(,
@ -102,7 +102,7 @@ void rConstructorArgs(QTextStream& r, const QString& name, const Object& o, cons
} }
QString model = ""; QString model = "";
if (o.type != ObjectType::Object) { 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"; model = ", model";
r << QString(R"( }; r << QString(R"( };
let model = %1%2 { let model = %1%2 {
@ -145,7 +145,7 @@ pub struct %1Emitter {
if (o.type == ObjectType::List) { if (o.type == ObjectType::List) {
r << QString(" new_data_ready: fn(*const %1QObject),\n") r << QString(" new_data_ready: fn(*const %1QObject),\n")
.arg(o.name); .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") r << QString(" new_data_ready: fn(*const %1QObject, item: usize, valid: bool),\n")
.arg(o.name); .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<usize>) { r << R"( pub fn new_data_ready(&self, item: Option<usize>) {
let ptr = *self.qobject.lock().unwrap(); let ptr = *self.qobject.lock().unwrap();
if !ptr.is_null() { if !ptr.is_null() {
@ -190,12 +190,12 @@ impl %1Emitter {
QString modelStruct = ""; QString modelStruct = "";
if (o.type != ObjectType::Object) { 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; modelStruct = ", model: " + o.name + type;
QString index; QString index;
QString indexDecl; QString indexDecl;
QString indexCDecl; QString indexCDecl;
if (o.type == ObjectType::UniformTree) { if (o.type == ObjectType::Tree) {
indexDecl = " item: Option<usize>,"; indexDecl = " item: Option<usize>,";
indexCDecl = " item: usize, valid: bool,"; indexCDecl = " item: usize, valid: bool,";
index = " item.unwrap_or(13), item.is_some(),"; index = " item.unwrap_or(13), item.is_some(),";
@ -270,7 +270,7 @@ pub trait %1Trait {
fn fetch_more(&mut self) {} fn fetch_more(&mut self) {}
fn sort(&mut self, u8, SortOrder) {} 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>) -> usize; r << R"( fn row_count(&self, Option<usize>) -> usize;
fn can_fetch_more(&self, Option<usize>) -> bool { fn can_fetch_more(&self, Option<usize>) -> bool {
false false
@ -410,7 +410,7 @@ pub unsafe extern "C" fn %2_sort(
(&mut *ptr).sort(column, order) (&mut *ptr).sort(column, order)
} }
)").arg(o.name, lcname); )").arg(o.name, lcname);
} else if (o.type == ObjectType::UniformTree) { } else if (o.type == ObjectType::Tree) {
r << QString(R"( r << QString(R"(
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn %2_row_count( 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) { if (o.type != ObjectType::Object) {
QString indexDecl = ", row: c_int"; QString indexDecl = ", row: c_int";
QString index = "row as usize"; QString index = "row as usize";
if (o.type == ObjectType::UniformTree) { if (o.type == ObjectType::Tree) {
indexDecl = ", item: usize"; indexDecl = ", item: usize";
index = "item"; index = "item";
} }
@ -744,9 +744,9 @@ void writeRustImplementationObject(QTextStream& r, const Object& o) {
if (o.type == ObjectType::List) { if (o.type == ObjectType::List) {
modelStruct = ", model: " + o.name + "List"; modelStruct = ", model: " + o.name + "List";
r << QString(" model: %1List,\n").arg(o.name); r << QString(" model: %1List,\n").arg(o.name);
} else if (o.type == ObjectType::UniformTree) { } else if (o.type == ObjectType::Tree) {
modelStruct = ", model: " + o.name + "UniformTree"; modelStruct = ", model: " + o.name + "Tree";
r << QString(" model: %1UniformTree,\n").arg(o.name); r << QString(" model: %1Tree,\n").arg(o.name);
} }
for (const Property& p: o.properties) { for (const Property& p: o.properties) {
const QString lc(snakeCase(p.name)); const QString lc(snakeCase(p.name));
@ -826,7 +826,7 @@ void writeRustImplementationObject(QTextStream& r, const Object& o) {
} }
if (o.type == ObjectType::List) { if (o.type == ObjectType::List) {
r << " fn row_count(&self) -> usize {\n self.list.len()\n }\n"; 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>) -> usize { r << R"( fn row_count(&self, item: Option<usize>) -> usize {
self.list.len() self.list.len()
} }
@ -843,7 +843,7 @@ void writeRustImplementationObject(QTextStream& r, const Object& o) {
} }
if (o.type != ObjectType::Object) { if (o.type != ObjectType::Object) {
QString index; QString index;
if (o.type == ObjectType::UniformTree) { if (o.type == ObjectType::Tree) {
index = ", item: usize"; index = ", item: usize";
} }
for (auto ip: o.itemProperties) { for (auto ip: o.itemProperties) {

View File

@ -9,7 +9,7 @@
enum class ObjectType { enum class ObjectType {
Object, Object,
List, List,
UniformTree Tree
}; };
enum class BindingType { enum class BindingType {
@ -129,7 +129,7 @@ struct Configuration {
} }
bool hasListOrTree() const { bool hasListOrTree() const {
for (auto o: objects) { for (auto o: objects) {
if (o.type == ObjectType::List || o.type == ObjectType::UniformTree) { if (o.type == ObjectType::List || o.type == ObjectType::Tree) {
return true; return true;
} }
} }

View File

@ -10,12 +10,12 @@ struct PersonsItem {
pub struct Persons { pub struct Persons {
emit: PersonsEmitter, emit: PersonsEmitter,
model: PersonsUniformTree, model: PersonsTree,
list: Vec<PersonsItem>, list: Vec<PersonsItem>,
} }
impl PersonsTrait for Persons { impl PersonsTrait for Persons {
fn create(emit: PersonsEmitter, model: PersonsUniformTree) -> Persons { fn create(emit: PersonsEmitter, model: PersonsTree) -> Persons {
Persons { Persons {
emit: emit, emit: emit,
model: model, model: model,

View File

@ -108,7 +108,7 @@ impl PersonsEmitter {
} }
} }
pub struct PersonsUniformTree { pub struct PersonsTree {
qobject: *const PersonsQObject, qobject: *const PersonsQObject,
data_changed: fn(*const PersonsQObject, usize, usize), data_changed: fn(*const PersonsQObject, usize, usize),
begin_reset_model: fn(*const PersonsQObject), begin_reset_model: fn(*const PersonsQObject),
@ -119,7 +119,7 @@ pub struct PersonsUniformTree {
end_remove_rows: fn(*const PersonsQObject), end_remove_rows: fn(*const PersonsQObject),
} }
impl PersonsUniformTree { impl PersonsTree {
pub fn data_changed(&self, first: usize, last: usize) { pub fn data_changed(&self, first: usize, last: usize) {
(self.data_changed)(self.qobject, first, last); (self.data_changed)(self.qobject, first, last);
} }
@ -144,7 +144,7 @@ impl PersonsUniformTree {
} }
pub trait PersonsTrait { pub trait PersonsTrait {
fn create(emit: PersonsEmitter, model: PersonsUniformTree) -> Self; fn create(emit: PersonsEmitter, model: PersonsTree) -> Self;
fn emit(&self) -> &PersonsEmitter; fn emit(&self) -> &PersonsEmitter;
fn row_count(&self, Option<usize>) -> usize; fn row_count(&self, Option<usize>) -> usize;
fn can_fetch_more(&self, Option<usize>) -> bool { fn can_fetch_more(&self, Option<usize>) -> bool {
@ -175,7 +175,7 @@ pub extern "C" fn persons_new(
qobject: Arc::new(Mutex::new(persons)), qobject: Arc::new(Mutex::new(persons)),
new_data_ready: persons_new_data_ready, new_data_ready: persons_new_data_ready,
}; };
let model = PersonsUniformTree { let model = PersonsTree {
qobject: persons, qobject: persons,
data_changed: persons_data_changed, data_changed: persons_data_changed,
begin_reset_model: persons_begin_reset_model, begin_reset_model: persons_begin_reset_model,

View File

@ -7,7 +7,7 @@
}, },
"objects": { "objects": {
"Persons": { "Persons": {
"type": "UniformTree", "type": "Tree",
"itemProperties": { "itemProperties": {
"userName": { "userName": {
"type": "QString", "type": "QString",