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.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.

View File

@ -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",

View File

@ -107,7 +107,7 @@ struct Entry<T: Item> {
pub struct RGeneralItemModel<T: Item> {
emit: FileSystemTreeEmitter,
model: FileSystemTreeUniformTree,
model: FileSystemTreeTree,
entries: Vec<Entry<T>>,
path: Option<String>,
incoming: Incoming<T>,
@ -189,7 +189,7 @@ impl<T: Item> FileSystemTreeTrait for RGeneralItemModel<T>
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,

View File

@ -28,7 +28,7 @@ enum ChangeState {
pub struct Processes {
emit: ProcessesEmitter,
model: ProcessesUniformTree,
model: ProcessesTree,
p: ProcessTree,
incoming: Arc<Mutex<Option<ProcessTree>>>,
active: bool,
@ -160,7 +160,7 @@ fn move_process(
}
fn remove_row(
model: &ProcessesUniformTree,
model: &ProcessesTree,
parent: pid_t,
row: usize,
map: &mut HashMap<pid_t, ProcessItem>,
@ -187,7 +187,7 @@ fn remove_row(
}
fn insert_row(
model: &ProcessesUniformTree,
model: &ProcessesTree,
parent: pid_t,
row: usize,
map: &mut HashMap<pid_t, ProcessItem>,
@ -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<pid_t, ProcessItem>,
bmap: &mut HashMap<pid_t, ProcessItem>,
@ -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(),

View File

@ -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<String>);
@ -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,

View File

@ -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) {

View File

@ -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;
}

View File

@ -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<usize>) {
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<usize>,";
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>) -> usize;
fn can_fetch_more(&self, Option<usize>) -> 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>) -> 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) {

View File

@ -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;
}
}

View File

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

View File

@ -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>) -> usize;
fn can_fetch_more(&self, Option<usize>) -> 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,

View File

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