snapshot
parent
32fed925e9
commit
754214e7b4
|
@ -17,6 +17,17 @@ pub struct COption<T> {
|
|||
some: bool,
|
||||
}
|
||||
|
||||
impl<T> COption<T> {
|
||||
#![allow(dead_code)]
|
||||
fn into(self) -> Option<T> {
|
||||
if self.some {
|
||||
Some(self.data)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<Option<T>> for COption<T>
|
||||
where
|
||||
T: Default,
|
||||
|
@ -135,23 +146,23 @@ pub extern "C" fn demo_new(
|
|||
fibonacci_list_end_remove_rows: fn(*const FibonacciListQObject),
|
||||
file_system_tree: *mut FileSystemTreeQObject,
|
||||
file_system_tree_path_changed: fn(*const FileSystemTreeQObject),
|
||||
file_system_tree_new_data_ready: fn(*const FileSystemTreeQObject, index: usize, valid: bool),
|
||||
file_system_tree_new_data_ready: fn(*const FileSystemTreeQObject, index: COption<usize>),
|
||||
file_system_tree_data_changed: fn(*const FileSystemTreeQObject, usize, usize),
|
||||
file_system_tree_begin_reset_model: fn(*const FileSystemTreeQObject),
|
||||
file_system_tree_end_reset_model: fn(*const FileSystemTreeQObject),
|
||||
file_system_tree_begin_insert_rows: fn(*const FileSystemTreeQObject, index: usize, valid: bool, usize, usize),
|
||||
file_system_tree_begin_insert_rows: fn(*const FileSystemTreeQObject, index: COption<usize>, usize, usize),
|
||||
file_system_tree_end_insert_rows: fn(*const FileSystemTreeQObject),
|
||||
file_system_tree_begin_remove_rows: fn(*const FileSystemTreeQObject, index: usize, valid: bool, usize, usize),
|
||||
file_system_tree_begin_remove_rows: fn(*const FileSystemTreeQObject, index: COption<usize>, usize, usize),
|
||||
file_system_tree_end_remove_rows: fn(*const FileSystemTreeQObject),
|
||||
processes: *mut ProcessesQObject,
|
||||
processes_active_changed: fn(*const ProcessesQObject),
|
||||
processes_new_data_ready: fn(*const ProcessesQObject, index: usize, valid: bool),
|
||||
processes_new_data_ready: fn(*const ProcessesQObject, index: COption<usize>),
|
||||
processes_data_changed: fn(*const ProcessesQObject, usize, usize),
|
||||
processes_begin_reset_model: fn(*const ProcessesQObject),
|
||||
processes_end_reset_model: fn(*const ProcessesQObject),
|
||||
processes_begin_insert_rows: fn(*const ProcessesQObject, index: usize, valid: bool, usize, usize),
|
||||
processes_begin_insert_rows: fn(*const ProcessesQObject, index: COption<usize>, usize, usize),
|
||||
processes_end_insert_rows: fn(*const ProcessesQObject),
|
||||
processes_begin_remove_rows: fn(*const ProcessesQObject, index: usize, valid: bool, usize, usize),
|
||||
processes_begin_remove_rows: fn(*const ProcessesQObject, index: COption<usize>, usize, usize),
|
||||
processes_end_remove_rows: fn(*const ProcessesQObject),
|
||||
time_series: *mut TimeSeriesQObject,
|
||||
time_series_new_data_ready: fn(*const TimeSeriesQObject),
|
||||
|
@ -499,7 +510,7 @@ pub struct FileSystemTreeQObject {}
|
|||
pub struct FileSystemTreeEmitter {
|
||||
qobject: Arc<Mutex<*const FileSystemTreeQObject>>,
|
||||
path_changed: fn(*const FileSystemTreeQObject),
|
||||
new_data_ready: fn(*const FileSystemTreeQObject, index: usize, valid: bool),
|
||||
new_data_ready: fn(*const FileSystemTreeQObject, index: COption<usize>),
|
||||
}
|
||||
|
||||
unsafe impl Send for FileSystemTreeEmitter {}
|
||||
|
@ -517,7 +528,7 @@ impl FileSystemTreeEmitter {
|
|||
pub fn new_data_ready(&self, item: Option<usize>) {
|
||||
let ptr = *self.qobject.lock().unwrap();
|
||||
if !ptr.is_null() {
|
||||
(self.new_data_ready)(ptr, item.unwrap_or(13), item.is_some());
|
||||
(self.new_data_ready)(ptr, item.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -527,9 +538,9 @@ pub struct FileSystemTreeTree {
|
|||
data_changed: fn(*const FileSystemTreeQObject, usize, usize),
|
||||
begin_reset_model: fn(*const FileSystemTreeQObject),
|
||||
end_reset_model: fn(*const FileSystemTreeQObject),
|
||||
begin_insert_rows: fn(*const FileSystemTreeQObject, index: usize, valid: bool, usize, usize),
|
||||
begin_insert_rows: fn(*const FileSystemTreeQObject, index: COption<usize>, usize, usize),
|
||||
end_insert_rows: fn(*const FileSystemTreeQObject),
|
||||
begin_remove_rows: fn(*const FileSystemTreeQObject, index: usize, valid: bool, usize, usize),
|
||||
begin_remove_rows: fn(*const FileSystemTreeQObject, index: COption<usize>, usize, usize),
|
||||
end_remove_rows: fn(*const FileSystemTreeQObject),
|
||||
}
|
||||
|
||||
|
@ -544,13 +555,13 @@ impl FileSystemTreeTree {
|
|||
(self.end_reset_model)(self.qobject);
|
||||
}
|
||||
pub fn begin_insert_rows(&self, index: Option<usize>, first: usize, last: usize) {
|
||||
(self.begin_insert_rows)(self.qobject, index.unwrap_or(13), index.is_some(), first, last);
|
||||
(self.begin_insert_rows)(self.qobject, index.into(), first, last);
|
||||
}
|
||||
pub fn end_insert_rows(&self) {
|
||||
(self.end_insert_rows)(self.qobject);
|
||||
}
|
||||
pub fn begin_remove_rows(&self, index: Option<usize>, first: usize, last: usize) {
|
||||
(self.begin_remove_rows)(self.qobject, index.unwrap_or(13), index.is_some(), first, last);
|
||||
(self.begin_remove_rows)(self.qobject, index.into(), first, last);
|
||||
}
|
||||
pub fn end_remove_rows(&self) {
|
||||
(self.end_remove_rows)(self.qobject);
|
||||
|
@ -583,13 +594,13 @@ pub trait FileSystemTreeTrait {
|
|||
pub extern "C" fn file_system_tree_new(
|
||||
file_system_tree: *mut FileSystemTreeQObject,
|
||||
file_system_tree_path_changed: fn(*const FileSystemTreeQObject),
|
||||
file_system_tree_new_data_ready: fn(*const FileSystemTreeQObject, index: usize, valid: bool),
|
||||
file_system_tree_new_data_ready: fn(*const FileSystemTreeQObject, index: COption<usize>),
|
||||
file_system_tree_data_changed: fn(*const FileSystemTreeQObject, usize, usize),
|
||||
file_system_tree_begin_reset_model: fn(*const FileSystemTreeQObject),
|
||||
file_system_tree_end_reset_model: fn(*const FileSystemTreeQObject),
|
||||
file_system_tree_begin_insert_rows: fn(*const FileSystemTreeQObject, index: usize, valid: bool, usize, usize),
|
||||
file_system_tree_begin_insert_rows: fn(*const FileSystemTreeQObject, index: COption<usize>, usize, usize),
|
||||
file_system_tree_end_insert_rows: fn(*const FileSystemTreeQObject),
|
||||
file_system_tree_begin_remove_rows: fn(*const FileSystemTreeQObject, index: usize, valid: bool, usize, usize),
|
||||
file_system_tree_begin_remove_rows: fn(*const FileSystemTreeQObject, index: COption<usize>, usize, usize),
|
||||
file_system_tree_end_remove_rows: fn(*const FileSystemTreeQObject),
|
||||
) -> *mut FileSystemTree {
|
||||
let file_system_tree_emit = FileSystemTreeEmitter {
|
||||
|
@ -647,34 +658,20 @@ pub extern "C" fn file_system_tree_path_set_none(ptr: *mut FileSystemTree) {
|
|||
#[no_mangle]
|
||||
pub unsafe extern "C" fn file_system_tree_row_count(
|
||||
ptr: *const FileSystemTree,
|
||||
index: usize,
|
||||
valid: bool,
|
||||
index: COption<usize>,
|
||||
) -> c_int {
|
||||
to_c_int(if valid {
|
||||
(&*ptr).row_count(Some(index))
|
||||
} else {
|
||||
(&*ptr).row_count(None)
|
||||
})
|
||||
to_c_int((&*ptr).row_count(index.into()))
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn file_system_tree_can_fetch_more(
|
||||
ptr: *const FileSystemTree,
|
||||
index: usize,
|
||||
valid: bool,
|
||||
index: COption<usize>,
|
||||
) -> bool {
|
||||
if valid {
|
||||
(&*ptr).can_fetch_more(Some(index))
|
||||
} else {
|
||||
(&*ptr).can_fetch_more(None)
|
||||
}
|
||||
(&*ptr).can_fetch_more(index.into())
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn file_system_tree_fetch_more(ptr: *mut FileSystemTree, index: usize, valid: bool) {
|
||||
if valid {
|
||||
(&mut *ptr).fetch_more(Some(index))
|
||||
} else {
|
||||
(&mut *ptr).fetch_more(None)
|
||||
}
|
||||
pub unsafe extern "C" fn file_system_tree_fetch_more(ptr: *mut FileSystemTree, index: COption<usize>) {
|
||||
(&mut *ptr).fetch_more(index.into())
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn file_system_tree_sort(
|
||||
|
@ -687,15 +684,10 @@ pub unsafe extern "C" fn file_system_tree_sort(
|
|||
#[no_mangle]
|
||||
pub unsafe extern "C" fn file_system_tree_index(
|
||||
ptr: *const FileSystemTree,
|
||||
index: usize,
|
||||
valid: bool,
|
||||
index: COption<usize>,
|
||||
row: c_int,
|
||||
) -> usize {
|
||||
if !valid {
|
||||
(&*ptr).index(None, to_usize(row))
|
||||
} else {
|
||||
(&*ptr).index(Some(index), to_usize(row))
|
||||
}
|
||||
(&*ptr).index(index.into(), to_usize(row))
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn file_system_tree_parent(ptr: *const FileSystemTree, index: usize) -> QModelIndex {
|
||||
|
@ -778,7 +770,7 @@ pub struct ProcessesQObject {}
|
|||
pub struct ProcessesEmitter {
|
||||
qobject: Arc<Mutex<*const ProcessesQObject>>,
|
||||
active_changed: fn(*const ProcessesQObject),
|
||||
new_data_ready: fn(*const ProcessesQObject, index: usize, valid: bool),
|
||||
new_data_ready: fn(*const ProcessesQObject, index: COption<usize>),
|
||||
}
|
||||
|
||||
unsafe impl Send for ProcessesEmitter {}
|
||||
|
@ -796,7 +788,7 @@ impl ProcessesEmitter {
|
|||
pub fn new_data_ready(&self, item: Option<usize>) {
|
||||
let ptr = *self.qobject.lock().unwrap();
|
||||
if !ptr.is_null() {
|
||||
(self.new_data_ready)(ptr, item.unwrap_or(13), item.is_some());
|
||||
(self.new_data_ready)(ptr, item.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -806,9 +798,9 @@ pub struct ProcessesTree {
|
|||
data_changed: fn(*const ProcessesQObject, usize, usize),
|
||||
begin_reset_model: fn(*const ProcessesQObject),
|
||||
end_reset_model: fn(*const ProcessesQObject),
|
||||
begin_insert_rows: fn(*const ProcessesQObject, index: usize, valid: bool, usize, usize),
|
||||
begin_insert_rows: fn(*const ProcessesQObject, index: COption<usize>, usize, usize),
|
||||
end_insert_rows: fn(*const ProcessesQObject),
|
||||
begin_remove_rows: fn(*const ProcessesQObject, index: usize, valid: bool, usize, usize),
|
||||
begin_remove_rows: fn(*const ProcessesQObject, index: COption<usize>, usize, usize),
|
||||
end_remove_rows: fn(*const ProcessesQObject),
|
||||
}
|
||||
|
||||
|
@ -823,13 +815,13 @@ impl ProcessesTree {
|
|||
(self.end_reset_model)(self.qobject);
|
||||
}
|
||||
pub fn begin_insert_rows(&self, index: Option<usize>, first: usize, last: usize) {
|
||||
(self.begin_insert_rows)(self.qobject, index.unwrap_or(13), index.is_some(), first, last);
|
||||
(self.begin_insert_rows)(self.qobject, index.into(), first, last);
|
||||
}
|
||||
pub fn end_insert_rows(&self) {
|
||||
(self.end_insert_rows)(self.qobject);
|
||||
}
|
||||
pub fn begin_remove_rows(&self, index: Option<usize>, first: usize, last: usize) {
|
||||
(self.begin_remove_rows)(self.qobject, index.unwrap_or(13), index.is_some(), first, last);
|
||||
(self.begin_remove_rows)(self.qobject, index.into(), first, last);
|
||||
}
|
||||
pub fn end_remove_rows(&self) {
|
||||
(self.end_remove_rows)(self.qobject);
|
||||
|
@ -863,13 +855,13 @@ pub trait ProcessesTrait {
|
|||
pub extern "C" fn processes_new(
|
||||
processes: *mut ProcessesQObject,
|
||||
processes_active_changed: fn(*const ProcessesQObject),
|
||||
processes_new_data_ready: fn(*const ProcessesQObject, index: usize, valid: bool),
|
||||
processes_new_data_ready: fn(*const ProcessesQObject, index: COption<usize>),
|
||||
processes_data_changed: fn(*const ProcessesQObject, usize, usize),
|
||||
processes_begin_reset_model: fn(*const ProcessesQObject),
|
||||
processes_end_reset_model: fn(*const ProcessesQObject),
|
||||
processes_begin_insert_rows: fn(*const ProcessesQObject, index: usize, valid: bool, usize, usize),
|
||||
processes_begin_insert_rows: fn(*const ProcessesQObject, index: COption<usize>, usize, usize),
|
||||
processes_end_insert_rows: fn(*const ProcessesQObject),
|
||||
processes_begin_remove_rows: fn(*const ProcessesQObject, index: usize, valid: bool, usize, usize),
|
||||
processes_begin_remove_rows: fn(*const ProcessesQObject, index: COption<usize>, usize, usize),
|
||||
processes_end_remove_rows: fn(*const ProcessesQObject),
|
||||
) -> *mut Processes {
|
||||
let processes_emit = ProcessesEmitter {
|
||||
|
@ -909,34 +901,20 @@ pub unsafe extern "C" fn processes_active_set(ptr: *mut Processes, v: bool) {
|
|||
#[no_mangle]
|
||||
pub unsafe extern "C" fn processes_row_count(
|
||||
ptr: *const Processes,
|
||||
index: usize,
|
||||
valid: bool,
|
||||
index: COption<usize>,
|
||||
) -> c_int {
|
||||
to_c_int(if valid {
|
||||
(&*ptr).row_count(Some(index))
|
||||
} else {
|
||||
(&*ptr).row_count(None)
|
||||
})
|
||||
to_c_int((&*ptr).row_count(index.into()))
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn processes_can_fetch_more(
|
||||
ptr: *const Processes,
|
||||
index: usize,
|
||||
valid: bool,
|
||||
index: COption<usize>,
|
||||
) -> bool {
|
||||
if valid {
|
||||
(&*ptr).can_fetch_more(Some(index))
|
||||
} else {
|
||||
(&*ptr).can_fetch_more(None)
|
||||
}
|
||||
(&*ptr).can_fetch_more(index.into())
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn processes_fetch_more(ptr: *mut Processes, index: usize, valid: bool) {
|
||||
if valid {
|
||||
(&mut *ptr).fetch_more(Some(index))
|
||||
} else {
|
||||
(&mut *ptr).fetch_more(None)
|
||||
}
|
||||
pub unsafe extern "C" fn processes_fetch_more(ptr: *mut Processes, index: COption<usize>) {
|
||||
(&mut *ptr).fetch_more(index.into())
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn processes_sort(
|
||||
|
@ -949,15 +927,10 @@ pub unsafe extern "C" fn processes_sort(
|
|||
#[no_mangle]
|
||||
pub unsafe extern "C" fn processes_index(
|
||||
ptr: *const Processes,
|
||||
index: usize,
|
||||
valid: bool,
|
||||
index: COption<usize>,
|
||||
row: c_int,
|
||||
) -> usize {
|
||||
if !valid {
|
||||
(&*ptr).index(None, to_usize(row))
|
||||
} else {
|
||||
(&*ptr).index(Some(index), to_usize(row))
|
||||
}
|
||||
(&*ptr).index(index.into(), to_usize(row))
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn processes_parent(ptr: *const Processes, index: usize) -> QModelIndex {
|
||||
|
|
58
src/rust.cpp
58
src/rust.cpp
|
@ -82,13 +82,13 @@ void rConstructorArgsDecl(QTextStream& r, const QString& name, const Object& o,
|
|||
r << QString(",\n %2_new_data_ready: fn(*const %1QObject)")
|
||||
.arg(o.name, snakeCase(name));
|
||||
} else if (o.type == ObjectType::Tree) {
|
||||
r << QString(",\n %2_new_data_ready: fn(*const %1QObject, index: usize, valid: bool)")
|
||||
r << QString(",\n %2_new_data_ready: fn(*const %1QObject, index: COption<usize>)")
|
||||
.arg(o.name, snakeCase(name));
|
||||
}
|
||||
if (o.type != ObjectType::Object) {
|
||||
QString indexDecl;
|
||||
if (o.type == ObjectType::Tree) {
|
||||
indexDecl = " index: usize, valid: bool,";
|
||||
indexDecl = " index: COption<usize>,";
|
||||
}
|
||||
r << QString(R"(,
|
||||
%3_data_changed: fn(*const %1QObject, usize, usize),
|
||||
|
@ -221,7 +221,7 @@ pub struct %1Emitter {
|
|||
r << QString(" new_data_ready: fn(*const %1QObject),\n")
|
||||
.arg(o.name);
|
||||
} else if (o.type == ObjectType::Tree) {
|
||||
r << QString(" new_data_ready: fn(*const %1QObject, index: usize, valid: bool),\n")
|
||||
r << QString(" new_data_ready: fn(*const %1QObject, index: COption<usize>),\n")
|
||||
.arg(o.name);
|
||||
}
|
||||
r << QString(R"(}
|
||||
|
@ -257,7 +257,7 @@ impl %1Emitter {
|
|||
r << R"( pub fn new_data_ready(&self, item: Option<usize>) {
|
||||
let ptr = *self.qobject.lock().unwrap();
|
||||
if !ptr.is_null() {
|
||||
(self.new_data_ready)(ptr, item.unwrap_or(13), item.is_some());
|
||||
(self.new_data_ready)(ptr, item.into());
|
||||
}
|
||||
}
|
||||
)";
|
||||
|
@ -272,8 +272,8 @@ impl %1Emitter {
|
|||
QString indexCDecl;
|
||||
if (o.type == ObjectType::Tree) {
|
||||
indexDecl = " index: Option<usize>,";
|
||||
indexCDecl = " index: usize, valid: bool,";
|
||||
index = " index.unwrap_or(13), index.is_some(),";
|
||||
indexCDecl = " index: COption<usize>,";
|
||||
index = " index.into(),";
|
||||
}
|
||||
r << QString(R"(}
|
||||
|
||||
|
@ -601,34 +601,20 @@ pub unsafe extern "C" fn %2_sort(
|
|||
#[no_mangle]
|
||||
pub unsafe extern "C" fn %2_row_count(
|
||||
ptr: *const %1,
|
||||
index: usize,
|
||||
valid: bool,
|
||||
index: COption<usize>,
|
||||
) -> c_int {
|
||||
to_c_int(if valid {
|
||||
(&*ptr).row_count(Some(index))
|
||||
} else {
|
||||
(&*ptr).row_count(None)
|
||||
})
|
||||
to_c_int((&*ptr).row_count(index.into()))
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn %2_can_fetch_more(
|
||||
ptr: *const %1,
|
||||
index: usize,
|
||||
valid: bool,
|
||||
index: COption<usize>,
|
||||
) -> bool {
|
||||
if valid {
|
||||
(&*ptr).can_fetch_more(Some(index))
|
||||
} else {
|
||||
(&*ptr).can_fetch_more(None)
|
||||
}
|
||||
(&*ptr).can_fetch_more(index.into())
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn %2_fetch_more(ptr: *mut %1, index: usize, valid: bool) {
|
||||
if valid {
|
||||
(&mut *ptr).fetch_more(Some(index))
|
||||
} else {
|
||||
(&mut *ptr).fetch_more(None)
|
||||
}
|
||||
pub unsafe extern "C" fn %2_fetch_more(ptr: *mut %1, index: COption<usize>) {
|
||||
(&mut *ptr).fetch_more(index.into())
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn %2_sort(
|
||||
|
@ -641,15 +627,10 @@ pub unsafe extern "C" fn %2_sort(
|
|||
#[no_mangle]
|
||||
pub unsafe extern "C" fn %2_index(
|
||||
ptr: *const %1,
|
||||
index: usize,
|
||||
valid: bool,
|
||||
index: COption<usize>,
|
||||
row: c_int,
|
||||
) -> usize {
|
||||
if !valid {
|
||||
(&*ptr).index(None, to_usize(row))
|
||||
} else {
|
||||
(&*ptr).index(Some(index), to_usize(row))
|
||||
}
|
||||
(&*ptr).index(index.into(), to_usize(row))
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn %2_parent(ptr: *const %1, index: usize) -> QModelIndex {
|
||||
|
@ -819,6 +800,17 @@ pub struct COption<T> {
|
|||
some: bool,
|
||||
}
|
||||
|
||||
impl<T> COption<T> {
|
||||
#![allow(dead_code)]
|
||||
fn into(self) -> Option<T> {
|
||||
if self.some {
|
||||
Some(self.data)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<Option<T>> for COption<T>
|
||||
where
|
||||
T: Default,
|
||||
|
|
|
@ -17,6 +17,17 @@ pub struct COption<T> {
|
|||
some: bool,
|
||||
}
|
||||
|
||||
impl<T> COption<T> {
|
||||
#![allow(dead_code)]
|
||||
fn into(self) -> Option<T> {
|
||||
if self.some {
|
||||
Some(self.data)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<Option<T>> for COption<T>
|
||||
where
|
||||
T: Default,
|
||||
|
|
|
@ -17,6 +17,17 @@ pub struct COption<T> {
|
|||
some: bool,
|
||||
}
|
||||
|
||||
impl<T> COption<T> {
|
||||
#![allow(dead_code)]
|
||||
fn into(self) -> Option<T> {
|
||||
if self.some {
|
||||
Some(self.data)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<Option<T>> for COption<T>
|
||||
where
|
||||
T: Default,
|
||||
|
|
|
@ -17,6 +17,17 @@ pub struct COption<T> {
|
|||
some: bool,
|
||||
}
|
||||
|
||||
impl<T> COption<T> {
|
||||
#![allow(dead_code)]
|
||||
fn into(self) -> Option<T> {
|
||||
if self.some {
|
||||
Some(self.data)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<Option<T>> for COption<T>
|
||||
where
|
||||
T: Default,
|
||||
|
|
|
@ -17,6 +17,17 @@ pub struct COption<T> {
|
|||
some: bool,
|
||||
}
|
||||
|
||||
impl<T> COption<T> {
|
||||
#![allow(dead_code)]
|
||||
fn into(self) -> Option<T> {
|
||||
if self.some {
|
||||
Some(self.data)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<Option<T>> for COption<T>
|
||||
where
|
||||
T: Default,
|
||||
|
@ -85,7 +96,7 @@ pub struct PersonsQObject {}
|
|||
#[derive(Clone)]
|
||||
pub struct PersonsEmitter {
|
||||
qobject: Arc<Mutex<*const PersonsQObject>>,
|
||||
new_data_ready: fn(*const PersonsQObject, index: usize, valid: bool),
|
||||
new_data_ready: fn(*const PersonsQObject, index: COption<usize>),
|
||||
}
|
||||
|
||||
unsafe impl Send for PersonsEmitter {}
|
||||
|
@ -97,7 +108,7 @@ impl PersonsEmitter {
|
|||
pub fn new_data_ready(&self, item: Option<usize>) {
|
||||
let ptr = *self.qobject.lock().unwrap();
|
||||
if !ptr.is_null() {
|
||||
(self.new_data_ready)(ptr, item.unwrap_or(13), item.is_some());
|
||||
(self.new_data_ready)(ptr, item.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -107,9 +118,9 @@ pub struct PersonsTree {
|
|||
data_changed: fn(*const PersonsQObject, usize, usize),
|
||||
begin_reset_model: fn(*const PersonsQObject),
|
||||
end_reset_model: fn(*const PersonsQObject),
|
||||
begin_insert_rows: fn(*const PersonsQObject, index: usize, valid: bool, usize, usize),
|
||||
begin_insert_rows: fn(*const PersonsQObject, index: COption<usize>, usize, usize),
|
||||
end_insert_rows: fn(*const PersonsQObject),
|
||||
begin_remove_rows: fn(*const PersonsQObject, index: usize, valid: bool, usize, usize),
|
||||
begin_remove_rows: fn(*const PersonsQObject, index: COption<usize>, usize, usize),
|
||||
end_remove_rows: fn(*const PersonsQObject),
|
||||
}
|
||||
|
||||
|
@ -124,13 +135,13 @@ impl PersonsTree {
|
|||
(self.end_reset_model)(self.qobject);
|
||||
}
|
||||
pub fn begin_insert_rows(&self, index: Option<usize>, first: usize, last: usize) {
|
||||
(self.begin_insert_rows)(self.qobject, index.unwrap_or(13), index.is_some(), first, last);
|
||||
(self.begin_insert_rows)(self.qobject, index.into(), first, last);
|
||||
}
|
||||
pub fn end_insert_rows(&self) {
|
||||
(self.end_insert_rows)(self.qobject);
|
||||
}
|
||||
pub fn begin_remove_rows(&self, index: Option<usize>, first: usize, last: usize) {
|
||||
(self.begin_remove_rows)(self.qobject, index.unwrap_or(13), index.is_some(), first, last);
|
||||
(self.begin_remove_rows)(self.qobject, index.into(), first, last);
|
||||
}
|
||||
pub fn end_remove_rows(&self) {
|
||||
(self.end_remove_rows)(self.qobject);
|
||||
|
@ -156,13 +167,13 @@ pub trait PersonsTrait {
|
|||
#[no_mangle]
|
||||
pub extern "C" fn persons_new(
|
||||
persons: *mut PersonsQObject,
|
||||
persons_new_data_ready: fn(*const PersonsQObject, index: usize, valid: bool),
|
||||
persons_new_data_ready: fn(*const PersonsQObject, index: COption<usize>),
|
||||
persons_data_changed: fn(*const PersonsQObject, usize, usize),
|
||||
persons_begin_reset_model: fn(*const PersonsQObject),
|
||||
persons_end_reset_model: fn(*const PersonsQObject),
|
||||
persons_begin_insert_rows: fn(*const PersonsQObject, index: usize, valid: bool, usize, usize),
|
||||
persons_begin_insert_rows: fn(*const PersonsQObject, index: COption<usize>, usize, usize),
|
||||
persons_end_insert_rows: fn(*const PersonsQObject),
|
||||
persons_begin_remove_rows: fn(*const PersonsQObject, index: usize, valid: bool, usize, usize),
|
||||
persons_begin_remove_rows: fn(*const PersonsQObject, index: COption<usize>, usize, usize),
|
||||
persons_end_remove_rows: fn(*const PersonsQObject),
|
||||
) -> *mut Persons {
|
||||
let persons_emit = PersonsEmitter {
|
||||
|
@ -191,34 +202,20 @@ pub unsafe extern "C" fn persons_free(ptr: *mut Persons) {
|
|||
#[no_mangle]
|
||||
pub unsafe extern "C" fn persons_row_count(
|
||||
ptr: *const Persons,
|
||||
index: usize,
|
||||
valid: bool,
|
||||
index: COption<usize>,
|
||||
) -> c_int {
|
||||
to_c_int(if valid {
|
||||
(&*ptr).row_count(Some(index))
|
||||
} else {
|
||||
(&*ptr).row_count(None)
|
||||
})
|
||||
to_c_int((&*ptr).row_count(index.into()))
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn persons_can_fetch_more(
|
||||
ptr: *const Persons,
|
||||
index: usize,
|
||||
valid: bool,
|
||||
index: COption<usize>,
|
||||
) -> bool {
|
||||
if valid {
|
||||
(&*ptr).can_fetch_more(Some(index))
|
||||
} else {
|
||||
(&*ptr).can_fetch_more(None)
|
||||
}
|
||||
(&*ptr).can_fetch_more(index.into())
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn persons_fetch_more(ptr: *mut Persons, index: usize, valid: bool) {
|
||||
if valid {
|
||||
(&mut *ptr).fetch_more(Some(index))
|
||||
} else {
|
||||
(&mut *ptr).fetch_more(None)
|
||||
}
|
||||
pub unsafe extern "C" fn persons_fetch_more(ptr: *mut Persons, index: COption<usize>) {
|
||||
(&mut *ptr).fetch_more(index.into())
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn persons_sort(
|
||||
|
@ -231,15 +228,10 @@ pub unsafe extern "C" fn persons_sort(
|
|||
#[no_mangle]
|
||||
pub unsafe extern "C" fn persons_index(
|
||||
ptr: *const Persons,
|
||||
index: usize,
|
||||
valid: bool,
|
||||
index: COption<usize>,
|
||||
row: c_int,
|
||||
) -> usize {
|
||||
if !valid {
|
||||
(&*ptr).index(None, to_usize(row))
|
||||
} else {
|
||||
(&*ptr).index(Some(index), to_usize(row))
|
||||
}
|
||||
(&*ptr).index(index.into(), to_usize(row))
|
||||
}
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn persons_parent(ptr: *const Persons, index: usize) -> QModelIndex {
|
||||
|
|
Loading…
Reference in New Issue