Fourth step towards using only generated models in Demo
parent
48941e9d29
commit
796f5a87b6
|
@ -33,7 +33,7 @@ add_custom_command(
|
|||
)
|
||||
add_custom_target(rust_target DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/rust/${RUST_TARGET_DIR}/librust.a")
|
||||
|
||||
set(Demo_SRCS src/main.cpp src/Tree.cpp src/Bindings.cpp src/modeltest.cpp
|
||||
set(Demo_SRCS src/main.cpp src/Tree.cpp src/Bindings.cpp #src/modeltest.cpp
|
||||
resource_file.qrc)
|
||||
|
||||
add_executable(Demo ${Demo_SRCS})
|
||||
|
|
|
@ -33,6 +33,8 @@ impl TreeEmitter {
|
|||
|
||||
pub struct TreeUniformTree {
|
||||
qobject: *const TreeQObject,
|
||||
begin_reset_model: fn(*const TreeQObject),
|
||||
end_reset_model: fn(*const TreeQObject),
|
||||
begin_insert_rows: fn(*const TreeQObject,row: c_int, parent: usize, c_int, c_int),
|
||||
end_insert_rows: fn(*const TreeQObject),
|
||||
begin_remove_rows: fn(*const TreeQObject,row: c_int, parent: usize, c_int, c_int),
|
||||
|
@ -40,6 +42,12 @@ pub struct TreeUniformTree {
|
|||
}
|
||||
|
||||
impl TreeUniformTree {
|
||||
pub fn begin_reset_model(&self) {
|
||||
(self.begin_reset_model)(self.qobject);
|
||||
}
|
||||
pub fn end_reset_model(&self) {
|
||||
(self.end_reset_model)(self.qobject);
|
||||
}
|
||||
pub fn begin_insert_rows(&self,row: c_int, parent: usize, first: c_int, last: c_int) {
|
||||
(self.begin_insert_rows)(self.qobject,row, parent, first, last);
|
||||
}
|
||||
|
@ -75,6 +83,8 @@ pub trait TreeTrait {
|
|||
#[no_mangle]
|
||||
pub extern "C" fn tree_new(qobject: *const TreeQObject,
|
||||
path_changed: fn(*const TreeQObject),
|
||||
begin_reset_model: fn(*const TreeQObject),
|
||||
end_reset_model: fn(*const TreeQObject),
|
||||
begin_insert_rows: fn(*const TreeQObject,row: c_int, parent: usize,
|
||||
c_int,
|
||||
c_int),
|
||||
|
@ -90,6 +100,8 @@ pub extern "C" fn tree_new(qobject: *const TreeQObject,
|
|||
};
|
||||
let model = TreeUniformTree {
|
||||
qobject: qobject,
|
||||
begin_reset_model: begin_reset_model,
|
||||
end_reset_model: end_reset_model,
|
||||
begin_insert_rows: begin_insert_rows,
|
||||
end_insert_rows: end_insert_rows,
|
||||
begin_remove_rows: begin_remove_rows,
|
||||
|
|
|
@ -152,6 +152,8 @@ impl DirectoryEmitter {
|
|||
|
||||
pub struct DirectoryList {
|
||||
qobject: *const DirectoryQObject,
|
||||
begin_reset_model: fn(*const DirectoryQObject),
|
||||
end_reset_model: fn(*const DirectoryQObject),
|
||||
begin_insert_rows: fn(*const DirectoryQObject, c_int, c_int),
|
||||
end_insert_rows: fn(*const DirectoryQObject),
|
||||
begin_remove_rows: fn(*const DirectoryQObject, c_int, c_int),
|
||||
|
@ -159,6 +161,12 @@ pub struct DirectoryList {
|
|||
}
|
||||
|
||||
impl DirectoryList {
|
||||
pub fn begin_reset_model(&self) {
|
||||
(self.begin_reset_model)(self.qobject);
|
||||
}
|
||||
pub fn end_reset_model(&self) {
|
||||
(self.end_reset_model)(self.qobject);
|
||||
}
|
||||
pub fn begin_insert_rows(&self, first: c_int, last: c_int) {
|
||||
(self.begin_insert_rows)(self.qobject, first, last);
|
||||
}
|
||||
|
@ -190,6 +198,8 @@ pub trait DirectoryTrait {
|
|||
#[no_mangle]
|
||||
pub extern "C" fn directory_new(qobject: *const DirectoryQObject,
|
||||
path_changed: fn(*const DirectoryQObject),
|
||||
begin_reset_model: fn(*const DirectoryQObject),
|
||||
end_reset_model: fn(*const DirectoryQObject),
|
||||
begin_insert_rows: fn(*const DirectoryQObject,
|
||||
c_int,
|
||||
c_int),
|
||||
|
@ -205,6 +215,8 @@ pub extern "C" fn directory_new(qobject: *const DirectoryQObject,
|
|||
};
|
||||
let model = DirectoryList {
|
||||
qobject: qobject,
|
||||
begin_reset_model: begin_reset_model,
|
||||
end_reset_model: end_reset_model,
|
||||
begin_insert_rows: begin_insert_rows,
|
||||
end_insert_rows: end_insert_rows,
|
||||
begin_remove_rows: begin_remove_rows,
|
||||
|
@ -301,6 +313,8 @@ impl TestTreeEmitter {
|
|||
|
||||
pub struct TestTreeUniformTree {
|
||||
qobject: *const TestTreeQObject,
|
||||
begin_reset_model: fn(*const TestTreeQObject),
|
||||
end_reset_model: fn(*const TestTreeQObject),
|
||||
begin_insert_rows: fn(*const TestTreeQObject,row: c_int, parent: usize, c_int, c_int),
|
||||
end_insert_rows: fn(*const TestTreeQObject),
|
||||
begin_remove_rows: fn(*const TestTreeQObject,row: c_int, parent: usize, c_int, c_int),
|
||||
|
@ -308,6 +322,12 @@ pub struct TestTreeUniformTree {
|
|||
}
|
||||
|
||||
impl TestTreeUniformTree {
|
||||
pub fn begin_reset_model(&self) {
|
||||
(self.begin_reset_model)(self.qobject);
|
||||
}
|
||||
pub fn end_reset_model(&self) {
|
||||
(self.end_reset_model)(self.qobject);
|
||||
}
|
||||
pub fn begin_insert_rows(&self,row: c_int, parent: usize, first: c_int, last: c_int) {
|
||||
(self.begin_insert_rows)(self.qobject,row, parent, first, last);
|
||||
}
|
||||
|
@ -341,6 +361,8 @@ pub trait TestTreeTrait {
|
|||
#[no_mangle]
|
||||
pub extern "C" fn test_tree_new(qobject: *const TestTreeQObject,
|
||||
path_changed: fn(*const TestTreeQObject),
|
||||
begin_reset_model: fn(*const TestTreeQObject),
|
||||
end_reset_model: fn(*const TestTreeQObject),
|
||||
begin_insert_rows: fn(*const TestTreeQObject,row: c_int, parent: usize,
|
||||
c_int,
|
||||
c_int),
|
||||
|
@ -356,6 +378,8 @@ pub extern "C" fn test_tree_new(qobject: *const TestTreeQObject,
|
|||
};
|
||||
let model = TestTreeUniformTree {
|
||||
qobject: qobject,
|
||||
begin_reset_model: begin_reset_model,
|
||||
end_reset_model: end_reset_model,
|
||||
begin_insert_rows: begin_insert_rows,
|
||||
end_insert_rows: end_insert_rows,
|
||||
begin_remove_rows: begin_remove_rows,
|
||||
|
|
|
@ -53,6 +53,8 @@ extern "C" {
|
|||
void person_icon_get(PersonInterface*, QByteArray*, qbytearray_set);
|
||||
void person_icon_set(void*, qbytearray_t);
|
||||
DirectoryInterface* directory_new(Directory*, void (*)(Directory*),
|
||||
void (*)(Directory*),
|
||||
void (*)(Directory*),
|
||||
void (*)(Directory*, int, int),
|
||||
void (*)(Directory*),
|
||||
void (*)(Directory*, int, int),
|
||||
|
@ -61,6 +63,8 @@ extern "C" {
|
|||
void directory_path_get(DirectoryInterface*, QString*, qstring_set);
|
||||
void directory_path_set(void*, qstring_t);
|
||||
TestTreeInterface* test_tree_new(TestTree*, void (*)(TestTree*),
|
||||
void (*)(TestTree*),
|
||||
void (*)(TestTree*),
|
||||
void (*)(TestTree*, int, quintptr, int, int),
|
||||
void (*)(TestTree*),
|
||||
void (*)(TestTree*, int, quintptr, int, int),
|
||||
|
@ -113,6 +117,12 @@ Directory::Directory(QObject *parent):
|
|||
QAbstractItemModel(parent),
|
||||
d(directory_new(this,
|
||||
[](Directory* o) { emit o->pathChanged(); },
|
||||
[](Directory* o) {
|
||||
emit o->beginResetModel();
|
||||
},
|
||||
[](Directory* o) {
|
||||
emit o->endResetModel();
|
||||
},
|
||||
[](Directory* o, int first, int last) {
|
||||
emit o->beginInsertRows(QModelIndex(), first, last);
|
||||
},
|
||||
|
@ -244,6 +254,12 @@ TestTree::TestTree(QObject *parent):
|
|||
QAbstractItemModel(parent),
|
||||
d(test_tree_new(this,
|
||||
[](TestTree* o) { emit o->pathChanged(); },
|
||||
[](TestTree* o) {
|
||||
emit o->beginResetModel();
|
||||
},
|
||||
[](TestTree* o) {
|
||||
emit o->endResetModel();
|
||||
},
|
||||
[](TestTree* o, int row, quintptr id, int first, int last) {
|
||||
emit o->beginInsertRows(o->createIndex(row, 0, id), first, last);
|
||||
},
|
||||
|
|
|
@ -44,6 +44,8 @@ void set_qbytearray(QByteArray* v, qbytearray_t* val) {
|
|||
|
||||
extern "C" {
|
||||
TreeInterface* tree_new(Tree*, void (*)(Tree*),
|
||||
void (*)(Tree*),
|
||||
void (*)(Tree*),
|
||||
void (*)(Tree*, int, quintptr, int, int),
|
||||
void (*)(Tree*),
|
||||
void (*)(Tree*, int, quintptr, int, int),
|
||||
|
@ -56,6 +58,12 @@ Tree::Tree(QObject *parent):
|
|||
QAbstractItemModel(parent),
|
||||
d(tree_new(this,
|
||||
[](Tree* o) { emit o->pathChanged(); },
|
||||
[](Tree* o) {
|
||||
emit o->beginResetModel();
|
||||
},
|
||||
[](Tree* o) {
|
||||
emit o->endResetModel();
|
||||
},
|
||||
[](Tree* o, int row, quintptr id, int first, int last) {
|
||||
emit o->beginInsertRows(o->createIndex(row, 0, id), first, last);
|
||||
},
|
||||
|
|
|
@ -483,6 +483,8 @@ void writeObjectCDecl(QTextStream& cpp, const Object& o) {
|
|||
}
|
||||
if (o.type == ObjectType::List) {
|
||||
cpp << QString(R"(,
|
||||
void (*)(%1*),
|
||||
void (*)(%1*),
|
||||
void (*)(%1*, int, int),
|
||||
void (*)(%1*),
|
||||
void (*)(%1*, int, int),
|
||||
|
@ -490,6 +492,8 @@ void writeObjectCDecl(QTextStream& cpp, const Object& o) {
|
|||
}
|
||||
if (o.type == ObjectType::UniformTree) {
|
||||
cpp << QString(R"(,
|
||||
void (*)(%1*),
|
||||
void (*)(%1*),
|
||||
void (*)(%1*, int, quintptr, int, int),
|
||||
void (*)(%1*),
|
||||
void (*)(%1*, int, quintptr, int, int),
|
||||
|
@ -525,6 +529,12 @@ void writeCppObject(QTextStream& cpp, const Object& o) {
|
|||
}
|
||||
if (o.type == ObjectType::List) {
|
||||
cpp << QString(R"(,
|
||||
[](%1* o) {
|
||||
emit o->beginResetModel();
|
||||
},
|
||||
[](%1* o) {
|
||||
emit o->endResetModel();
|
||||
},
|
||||
[](%1* o, int first, int last) {
|
||||
emit o->beginInsertRows(QModelIndex(), first, last);
|
||||
},
|
||||
|
@ -541,6 +551,12 @@ void writeCppObject(QTextStream& cpp, const Object& o) {
|
|||
}
|
||||
if (o.type == ObjectType::UniformTree) {
|
||||
cpp << QString(R"(,
|
||||
[](%1* o) {
|
||||
emit o->beginResetModel();
|
||||
},
|
||||
[](%1* o) {
|
||||
emit o->endResetModel();
|
||||
},
|
||||
[](%1* o, int row, quintptr id, int first, int last) {
|
||||
emit o->beginInsertRows(o->createIndex(row, 0, id), first, last);
|
||||
},
|
||||
|
@ -745,6 +761,8 @@ impl %1Emitter {
|
|||
|
||||
pub struct %1%2 {
|
||||
qobject: *const %1QObject,
|
||||
begin_reset_model: fn(*const %1QObject),
|
||||
end_reset_model: fn(*const %1QObject),
|
||||
begin_insert_rows: fn(*const %1QObject,%3 c_int, c_int),
|
||||
end_insert_rows: fn(*const %1QObject),
|
||||
begin_remove_rows: fn(*const %1QObject,%3 c_int, c_int),
|
||||
|
@ -752,6 +770,12 @@ pub struct %1%2 {
|
|||
}
|
||||
|
||||
impl %1%2 {
|
||||
pub fn begin_reset_model(&self) {
|
||||
(self.begin_reset_model)(self.qobject);
|
||||
}
|
||||
pub fn end_reset_model(&self) {
|
||||
(self.end_reset_model)(self.qobject);
|
||||
}
|
||||
pub fn begin_insert_rows(&self,%3 first: c_int, last: c_int) {
|
||||
(self.begin_insert_rows)(self.qobject,%4 first, last);
|
||||
}
|
||||
|
@ -816,6 +840,8 @@ pub extern "C" fn %2_new(qobject: *const %1QObject)").arg(o.name, lcname);
|
|||
indexDecl = "row: c_int, parent: usize,";
|
||||
}
|
||||
r << QString(R"(,
|
||||
begin_reset_model: fn(*const %1QObject),
|
||||
end_reset_model: fn(*const %1QObject),
|
||||
begin_insert_rows: fn(*const %1QObject,%2
|
||||
c_int,
|
||||
c_int),
|
||||
|
@ -840,6 +866,8 @@ pub extern "C" fn %2_new(qobject: *const %1QObject)").arg(o.name, lcname);
|
|||
r << QString(R"( };
|
||||
let model = %1%2 {
|
||||
qobject: qobject,
|
||||
begin_reset_model: begin_reset_model,
|
||||
end_reset_model: end_reset_model,
|
||||
begin_insert_rows: begin_insert_rows,
|
||||
end_insert_rows: end_insert_rows,
|
||||
begin_remove_rows: begin_remove_rows,
|
||||
|
|
Loading…
Reference in New Issue