Move all generated demo files into one binding
parent
631f96d350
commit
cb95cec1ba
|
@ -1,43 +1,13 @@
|
||||||
set(CMAKE_AUTORCC ON)
|
set(CMAKE_AUTORCC ON)
|
||||||
|
|
||||||
# generate c++ and rust code from fibonacci.json
|
# generate c++ and rust code from bindings.json
|
||||||
add_custom_command(
|
|
||||||
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/rust/src/fibonacci_interface.rs"
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/Fibonacci.h"
|
|
||||||
# if the cpp file is marked GENERATED, CMake will not check it for moc
|
|
||||||
# "${CMAKE_CURRENT_SOURCE_DIR}/src/Fibonacci.cpp"
|
|
||||||
COMMAND ${CMAKE_BINARY_DIR}/src/rust_qt_binding_generator "${CMAKE_CURRENT_SOURCE_DIR}/fibonacci.json"
|
|
||||||
DEPENDS rust_qt_binding_generator fibonacci.json
|
|
||||||
)
|
|
||||||
|
|
||||||
# generate c++ and rust code from tree.json
|
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/rust/src/interface.rs"
|
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/rust/src/interface.rs"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/Tree.h"
|
"${CMAKE_CURRENT_SOURCE_DIR}/src/Bindings.h"
|
||||||
# if the cpp file is marked GENERATED, CMake will not check it for moc
|
# if the cpp file is marked GENERATED, CMake will not check it for moc
|
||||||
# "${CMAKE_CURRENT_SOURCE_DIR}/src/Tree.cpp"
|
# "${CMAKE_CURRENT_SOURCE_DIR}/src/Bindings.cpp"
|
||||||
COMMAND ${CMAKE_BINARY_DIR}/src/rust_qt_binding_generator "${CMAKE_CURRENT_SOURCE_DIR}/tree.json"
|
COMMAND ${CMAKE_BINARY_DIR}/src/rust_qt_binding_generator "${CMAKE_CURRENT_SOURCE_DIR}/bindings.json"
|
||||||
DEPENDS rust_qt_binding_generator tree.json
|
DEPENDS rust_qt_binding_generator bindings.json
|
||||||
)
|
|
||||||
|
|
||||||
# generate c++ and rust code from processes.json
|
|
||||||
add_custom_command(
|
|
||||||
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/rust/src/processes_interface.rs"
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/Processes.h"
|
|
||||||
# if the cpp file is marked GENERATED, CMake will not check it for moc
|
|
||||||
# "${CMAKE_CURRENT_SOURCE_DIR}/src/Processes.cpp"
|
|
||||||
COMMAND ${CMAKE_BINARY_DIR}/src/rust_qt_binding_generator "${CMAKE_CURRENT_SOURCE_DIR}/processes.json"
|
|
||||||
DEPENDS rust_qt_binding_generator processes.json
|
|
||||||
)
|
|
||||||
|
|
||||||
# generate c++ and rust code from time_series.json
|
|
||||||
add_custom_command(
|
|
||||||
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/rust/src/time_series_interface.rs"
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/TimeSeries.h"
|
|
||||||
# if the cpp file is marked GENERATED, CMake will not check it for moc
|
|
||||||
# "${CMAKE_CURRENT_SOURCE_DIR}/src/TimeSeries.cpp"
|
|
||||||
COMMAND ${CMAKE_BINARY_DIR}/src/rust_qt_binding_generator "${CMAKE_CURRENT_SOURCE_DIR}/time_series.json"
|
|
||||||
DEPENDS rust_qt_binding_generator time_series.json
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# compile the rust code into a static library
|
# compile the rust code into a static library
|
||||||
|
@ -45,14 +15,11 @@ add_custom_command(
|
||||||
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/rust/${RUST_TARGET_DIR}/librust.a"
|
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/rust/${RUST_TARGET_DIR}/librust.a"
|
||||||
COMMAND ${CARGO} build ${RUST_BUILD_FLAG}
|
COMMAND ${CARGO} build ${RUST_BUILD_FLAG}
|
||||||
DEPENDS rust/src/lib.rs
|
DEPENDS rust/src/lib.rs
|
||||||
rust/src/fibonacci_interface.rs
|
rust/src/implementation/mod.rs
|
||||||
rust/src/fibonacci_implementation.rs
|
rust/src/implementation/time_series.rs
|
||||||
rust/src/implementation.rs
|
rust/src/implementation/fibonacci.rs
|
||||||
|
rust/src/implementation/processes.rs
|
||||||
rust/src/interface.rs
|
rust/src/interface.rs
|
||||||
rust/src/time_series_interface.rs
|
|
||||||
rust/src/time_series_implementation.rs
|
|
||||||
rust/src/processes_interface.rs
|
|
||||||
rust/src/processes_implementation.rs
|
|
||||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/rust"
|
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/rust"
|
||||||
)
|
)
|
||||||
add_custom_target(rust_target DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/rust/${RUST_TARGET_DIR}/librust.a")
|
add_custom_target(rust_target DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/rust/${RUST_TARGET_DIR}/librust.a")
|
||||||
|
@ -70,8 +37,8 @@ if (Qt5Charts_FOUND)
|
||||||
list(APPEND DemoLibs Qt5::Charts)
|
list(APPEND DemoLibs Qt5::Charts)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(Demo_SRCS src/main.cpp src/Fibonacci.cpp src/Tree.cpp src/TimeSeries.cpp
|
set(Demo_SRCS src/main.cpp src/Bindings.cpp src/SortedModel.cpp
|
||||||
src/Processes.cpp src/SortedModel.cpp resource_file.qrc)
|
resource_file.qrc)
|
||||||
|
|
||||||
add_executable(Demo ${Demo_SRCS})
|
add_executable(Demo ${Demo_SRCS})
|
||||||
add_dependencies(Demo rust_target)
|
add_dependencies(Demo rust_target)
|
||||||
|
|
|
@ -0,0 +1,143 @@
|
||||||
|
{
|
||||||
|
"cppFile": "src/Bindings.cpp",
|
||||||
|
"rust": {
|
||||||
|
"dir": "rust",
|
||||||
|
"interfaceModule": "interface",
|
||||||
|
"implementationModule": "implementation"
|
||||||
|
},
|
||||||
|
"objects": {
|
||||||
|
"Demo": {
|
||||||
|
"type": "Object",
|
||||||
|
"properties": {
|
||||||
|
"fileSystemTree": {
|
||||||
|
"type": "FileSystemTree"
|
||||||
|
},
|
||||||
|
"fibonacci": {
|
||||||
|
"type": "Fibonacci"
|
||||||
|
},
|
||||||
|
"fibonacciList": {
|
||||||
|
"type": "FibonacciList"
|
||||||
|
},
|
||||||
|
"processes": {
|
||||||
|
"type": "Processes"
|
||||||
|
},
|
||||||
|
"timeSeries": {
|
||||||
|
"type": "TimeSeries"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"FileSystemTree": {
|
||||||
|
"type": "UniformTree",
|
||||||
|
"properties": {
|
||||||
|
"path": {
|
||||||
|
"type": "QString",
|
||||||
|
"write": true,
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"itemProperties": {
|
||||||
|
"fileName": {
|
||||||
|
"type": "QString",
|
||||||
|
"roles": [ ["display"] ],
|
||||||
|
"rustByValue": true
|
||||||
|
},
|
||||||
|
"fileIcon": {
|
||||||
|
"type": "QByteArray",
|
||||||
|
"roles": [ ["decoration"] ]
|
||||||
|
},
|
||||||
|
"fileSize": {
|
||||||
|
"type": "quint64",
|
||||||
|
"optional": true,
|
||||||
|
"roles": [ [], ["display"] ]
|
||||||
|
},
|
||||||
|
"filePath": {
|
||||||
|
"type": "QString",
|
||||||
|
"optional": true,
|
||||||
|
"roles": [ [], [], ["display"] ],
|
||||||
|
"rustByValue": true
|
||||||
|
},
|
||||||
|
"filePermissions": {
|
||||||
|
"type": "qint32",
|
||||||
|
"roles": [ [], [], [], ["display"] ]
|
||||||
|
},
|
||||||
|
"fileType": {
|
||||||
|
"type": "qint32",
|
||||||
|
"roles": [ [], [], [], [],["display"] ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Fibonacci": {
|
||||||
|
"type": "Object",
|
||||||
|
"properties": {
|
||||||
|
"input": {
|
||||||
|
"type": "quint32",
|
||||||
|
"write": true
|
||||||
|
},
|
||||||
|
"result": {
|
||||||
|
"type": "quint64"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"FibonacciList": {
|
||||||
|
"type": "List",
|
||||||
|
"itemProperties": {
|
||||||
|
"result": {
|
||||||
|
"type": "quint64",
|
||||||
|
"roles": [ [ "display" ] ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Processes": {
|
||||||
|
"type": "UniformTree",
|
||||||
|
"properties": {
|
||||||
|
"active": {
|
||||||
|
"type": "bool",
|
||||||
|
"write": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"itemProperties": {
|
||||||
|
"pid": {
|
||||||
|
"type": "quint32",
|
||||||
|
"roles": [ ["toolTip"] ]
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "QString",
|
||||||
|
"roles": [ ["display"] ]
|
||||||
|
},
|
||||||
|
"cpuUsage": {
|
||||||
|
"type": "float",
|
||||||
|
"roles": [ [], ["display"] ]
|
||||||
|
},
|
||||||
|
"memory": {
|
||||||
|
"type": "quint64",
|
||||||
|
"roles": [ [], [], ["display"] ]
|
||||||
|
},
|
||||||
|
"uid": {
|
||||||
|
"type": "quint32"
|
||||||
|
},
|
||||||
|
"cpuPercentage": {
|
||||||
|
"type": "quint8"
|
||||||
|
},
|
||||||
|
"cmd": {
|
||||||
|
"type": "QString",
|
||||||
|
"rustByValue": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"TimeSeries": {
|
||||||
|
"type": "List",
|
||||||
|
"itemProperties": {
|
||||||
|
"input": {
|
||||||
|
"type": "quint32",
|
||||||
|
"write": true,
|
||||||
|
"roles": [ [ "display", "edit" ] ]
|
||||||
|
},
|
||||||
|
"result": {
|
||||||
|
"type": "quint32",
|
||||||
|
"write": true,
|
||||||
|
"roles": [ [], [ "display", "edit" ] ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,31 +0,0 @@
|
||||||
{
|
|
||||||
"cppFile": "src/Fibonacci.cpp",
|
|
||||||
"rust": {
|
|
||||||
"dir": "rust",
|
|
||||||
"interfaceModule": "fibonacci_interface",
|
|
||||||
"implementationModule": "fibonacci_implementation"
|
|
||||||
},
|
|
||||||
"objects": {
|
|
||||||
"Fibonacci": {
|
|
||||||
"type": "Object",
|
|
||||||
"properties": {
|
|
||||||
"input": {
|
|
||||||
"type": "quint32",
|
|
||||||
"write": true
|
|
||||||
},
|
|
||||||
"result": {
|
|
||||||
"type": "quint64"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"FibonacciList": {
|
|
||||||
"type": "List",
|
|
||||||
"itemProperties": {
|
|
||||||
"result": {
|
|
||||||
"type": "quint64",
|
|
||||||
"roles": [ [ "display" ] ]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,47 +0,0 @@
|
||||||
{
|
|
||||||
"cppFile": "src/Processes.cpp",
|
|
||||||
"rust": {
|
|
||||||
"dir": "rust",
|
|
||||||
"interfaceModule": "processes_interface",
|
|
||||||
"implementationModule": "processes_implementation"
|
|
||||||
},
|
|
||||||
"objects": {
|
|
||||||
"Processes": {
|
|
||||||
"type": "UniformTree",
|
|
||||||
"properties": {
|
|
||||||
"active": {
|
|
||||||
"type": "bool",
|
|
||||||
"write": true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"itemProperties": {
|
|
||||||
"pid": {
|
|
||||||
"type": "quint32",
|
|
||||||
"roles": [ ["toolTip"] ]
|
|
||||||
},
|
|
||||||
"name": {
|
|
||||||
"type": "QString",
|
|
||||||
"roles": [ ["display"] ]
|
|
||||||
},
|
|
||||||
"cpuUsage": {
|
|
||||||
"type": "float",
|
|
||||||
"roles": [ [], ["display"] ]
|
|
||||||
},
|
|
||||||
"memory": {
|
|
||||||
"type": "quint64",
|
|
||||||
"roles": [ [], [], ["display"] ]
|
|
||||||
},
|
|
||||||
"uid": {
|
|
||||||
"type": "quint32"
|
|
||||||
},
|
|
||||||
"cpuPercentage": {
|
|
||||||
"type": "quint8"
|
|
||||||
},
|
|
||||||
"cmd": {
|
|
||||||
"type": "QString",
|
|
||||||
"rustByValue": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,251 +0,0 @@
|
||||||
/* generated by rust_qt_binding_generator */
|
|
||||||
#![allow(unknown_lints)]
|
|
||||||
#![allow(mutex_atomic, needless_pass_by_value)]
|
|
||||||
use libc::{c_int, c_void, uint8_t, uint16_t};
|
|
||||||
use std::slice;
|
|
||||||
|
|
||||||
use std::sync::{Arc, Mutex};
|
|
||||||
use std::ptr::null;
|
|
||||||
|
|
||||||
use fibonacci_implementation::*;
|
|
||||||
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
pub struct COption<T> {
|
|
||||||
data: T,
|
|
||||||
some: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> From<Option<T>> for COption<T>
|
|
||||||
where
|
|
||||||
T: Default,
|
|
||||||
{
|
|
||||||
fn from(t: Option<T>) -> COption<T> {
|
|
||||||
if let Some(v) = t {
|
|
||||||
COption {
|
|
||||||
data: v,
|
|
||||||
some: true,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
COption {
|
|
||||||
data: T::default(),
|
|
||||||
some: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
pub enum SortOrder {
|
|
||||||
Ascending = 0,
|
|
||||||
Descending = 1,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
pub struct QModelIndex {
|
|
||||||
row: c_int,
|
|
||||||
internal_id: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct FibonacciQObject {}
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct FibonacciEmitter {
|
|
||||||
qobject: Arc<Mutex<*const FibonacciQObject>>,
|
|
||||||
input_changed: fn(*const FibonacciQObject),
|
|
||||||
result_changed: fn(*const FibonacciQObject),
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl Send for FibonacciEmitter {}
|
|
||||||
|
|
||||||
impl FibonacciEmitter {
|
|
||||||
fn clear(&self) {
|
|
||||||
*self.qobject.lock().unwrap() = null();
|
|
||||||
}
|
|
||||||
pub fn input_changed(&self) {
|
|
||||||
let ptr = *self.qobject.lock().unwrap();
|
|
||||||
if !ptr.is_null() {
|
|
||||||
(self.input_changed)(ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn result_changed(&self) {
|
|
||||||
let ptr = *self.qobject.lock().unwrap();
|
|
||||||
if !ptr.is_null() {
|
|
||||||
(self.result_changed)(ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait FibonacciTrait {
|
|
||||||
fn create(emit: FibonacciEmitter) -> Self;
|
|
||||||
fn emit(&self) -> &FibonacciEmitter;
|
|
||||||
fn input(&self) -> u32;
|
|
||||||
fn set_input(&mut self, value: u32);
|
|
||||||
fn result(&self) -> u64;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub extern "C" fn fibonacci_new(
|
|
||||||
fibonacci: *mut FibonacciQObject,
|
|
||||||
input_changed: fn(*const FibonacciQObject),
|
|
||||||
result_changed: fn(*const FibonacciQObject),
|
|
||||||
) -> *mut Fibonacci {
|
|
||||||
let fibonacci_emit = FibonacciEmitter {
|
|
||||||
qobject: Arc::new(Mutex::new(fibonacci)),
|
|
||||||
input_changed: input_changed,
|
|
||||||
result_changed: result_changed,
|
|
||||||
};
|
|
||||||
let d_fibonacci = Fibonacci::create(fibonacci_emit);
|
|
||||||
Box::into_raw(Box::new(d_fibonacci))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn fibonacci_free(ptr: *mut Fibonacci) {
|
|
||||||
Box::from_raw(ptr).emit().clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn fibonacci_input_get(ptr: *const Fibonacci) -> u32 {
|
|
||||||
(&*ptr).input()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn fibonacci_input_set(ptr: *mut Fibonacci, v: u32) {
|
|
||||||
(&mut *ptr).set_input(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn fibonacci_result_get(ptr: *const Fibonacci) -> u64 {
|
|
||||||
(&*ptr).result()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct FibonacciListQObject {}
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct FibonacciListEmitter {
|
|
||||||
qobject: Arc<Mutex<*const FibonacciListQObject>>,
|
|
||||||
new_data_ready: fn(*const FibonacciListQObject),
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl Send for FibonacciListEmitter {}
|
|
||||||
|
|
||||||
impl FibonacciListEmitter {
|
|
||||||
fn clear(&self) {
|
|
||||||
*self.qobject.lock().unwrap() = null();
|
|
||||||
}
|
|
||||||
pub fn new_data_ready(&self) {
|
|
||||||
let ptr = *self.qobject.lock().unwrap();
|
|
||||||
if !ptr.is_null() {
|
|
||||||
(self.new_data_ready)(ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct FibonacciListList {
|
|
||||||
qobject: *const FibonacciListQObject,
|
|
||||||
data_changed: fn(*const FibonacciListQObject, usize, usize),
|
|
||||||
begin_reset_model: fn(*const FibonacciListQObject),
|
|
||||||
end_reset_model: fn(*const FibonacciListQObject),
|
|
||||||
begin_insert_rows: fn(*const FibonacciListQObject, usize, usize),
|
|
||||||
end_insert_rows: fn(*const FibonacciListQObject),
|
|
||||||
begin_remove_rows: fn(*const FibonacciListQObject, usize, usize),
|
|
||||||
end_remove_rows: fn(*const FibonacciListQObject),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FibonacciListList {
|
|
||||||
pub fn data_changed(&self, first: usize, last: usize) {
|
|
||||||
(self.data_changed)(self.qobject, first, last);
|
|
||||||
}
|
|
||||||
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: usize, last: usize) {
|
|
||||||
(self.begin_insert_rows)(self.qobject, first, last);
|
|
||||||
}
|
|
||||||
pub fn end_insert_rows(&self) {
|
|
||||||
(self.end_insert_rows)(self.qobject);
|
|
||||||
}
|
|
||||||
pub fn begin_remove_rows(&self, first: usize, last: usize) {
|
|
||||||
(self.begin_remove_rows)(self.qobject, first, last);
|
|
||||||
}
|
|
||||||
pub fn end_remove_rows(&self) {
|
|
||||||
(self.end_remove_rows)(self.qobject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait FibonacciListTrait {
|
|
||||||
fn create(emit: FibonacciListEmitter, model: FibonacciListList) -> Self;
|
|
||||||
fn emit(&self) -> &FibonacciListEmitter;
|
|
||||||
fn row_count(&self) -> usize;
|
|
||||||
fn can_fetch_more(&self) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
fn fetch_more(&mut self) {}
|
|
||||||
fn sort(&mut self, u8, SortOrder) {}
|
|
||||||
fn result(&self, item: usize) -> u64;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub extern "C" fn fibonacci_list_new(
|
|
||||||
fibonacci_list: *mut FibonacciListQObject,
|
|
||||||
new_data_ready: fn(*const FibonacciListQObject),
|
|
||||||
data_changed: fn(*const FibonacciListQObject, usize, usize),
|
|
||||||
begin_reset_model: fn(*const FibonacciListQObject),
|
|
||||||
end_reset_model: fn(*const FibonacciListQObject),
|
|
||||||
begin_insert_rows: fn(*const FibonacciListQObject, usize, usize),
|
|
||||||
end_insert_rows: fn(*const FibonacciListQObject),
|
|
||||||
begin_remove_rows: fn(*const FibonacciListQObject, usize, usize),
|
|
||||||
end_remove_rows: fn(*const FibonacciListQObject),
|
|
||||||
) -> *mut FibonacciList {
|
|
||||||
let fibonacci_list_emit = FibonacciListEmitter {
|
|
||||||
qobject: Arc::new(Mutex::new(fibonacci_list)),
|
|
||||||
new_data_ready: new_data_ready,
|
|
||||||
};
|
|
||||||
let model = FibonacciListList {
|
|
||||||
qobject: fibonacci_list,
|
|
||||||
data_changed: data_changed,
|
|
||||||
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,
|
|
||||||
end_remove_rows: end_remove_rows,
|
|
||||||
};
|
|
||||||
let d_fibonacci_list = FibonacciList::create(fibonacci_list_emit, model);
|
|
||||||
Box::into_raw(Box::new(d_fibonacci_list))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn fibonacci_list_free(ptr: *mut FibonacciList) {
|
|
||||||
Box::from_raw(ptr).emit().clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn fibonacci_list_row_count(ptr: *const FibonacciList) -> c_int {
|
|
||||||
(&*ptr).row_count() as c_int
|
|
||||||
}
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn fibonacci_list_can_fetch_more(ptr: *const FibonacciList) -> bool {
|
|
||||||
(&*ptr).can_fetch_more()
|
|
||||||
}
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn fibonacci_list_fetch_more(ptr: *mut FibonacciList) {
|
|
||||||
(&mut *ptr).fetch_more()
|
|
||||||
}
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn fibonacci_list_sort(
|
|
||||||
ptr: *mut FibonacciList,
|
|
||||||
column: u8,
|
|
||||||
order: SortOrder,
|
|
||||||
) {
|
|
||||||
(&mut *ptr).sort(column, order)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn fibonacci_list_data_result(ptr: *const FibonacciList, row: c_int) -> u64 {
|
|
||||||
(&*ptr).result(row as usize).into()
|
|
||||||
}
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
use interface::*;
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
pub struct Demo {
|
||||||
|
emit: DemoEmitter,
|
||||||
|
fibonacci: Fibonacci,
|
||||||
|
fibonacci_list: FibonacciList,
|
||||||
|
file_system_tree: FileSystemTree,
|
||||||
|
processes: Processes,
|
||||||
|
time_series: TimeSeries
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DemoTrait for Demo {
|
||||||
|
fn create(emit: DemoEmitter,
|
||||||
|
fibonacci: Fibonacci,
|
||||||
|
fibonacci_list: FibonacciList,
|
||||||
|
file_system_tree: FileSystemTree,
|
||||||
|
processes: Processes,
|
||||||
|
time_series: TimeSeries) -> Self {
|
||||||
|
Demo {
|
||||||
|
emit: emit,
|
||||||
|
fibonacci: fibonacci,
|
||||||
|
fibonacci_list: fibonacci_list,
|
||||||
|
file_system_tree: file_system_tree,
|
||||||
|
processes: processes,
|
||||||
|
time_series: time_series
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn emit(&self) -> &DemoEmitter {
|
||||||
|
&self.emit
|
||||||
|
}
|
||||||
|
fn fibonacci(&self) -> &Fibonacci {
|
||||||
|
&self.fibonacci
|
||||||
|
}
|
||||||
|
fn fibonacci_mut(&mut self) -> &mut Fibonacci {
|
||||||
|
&mut self.fibonacci
|
||||||
|
}
|
||||||
|
fn fibonacci_list(&self) -> &FibonacciList {
|
||||||
|
&self.fibonacci_list
|
||||||
|
}
|
||||||
|
fn fibonacci_list_mut(&mut self) -> &mut FibonacciList {
|
||||||
|
&mut self.fibonacci_list
|
||||||
|
}
|
||||||
|
fn file_system_tree(&self) -> &FileSystemTree {
|
||||||
|
&self.file_system_tree
|
||||||
|
}
|
||||||
|
fn file_system_tree_mut(&mut self) -> &mut FileSystemTree {
|
||||||
|
&mut self.file_system_tree
|
||||||
|
}
|
||||||
|
fn processes(&self) -> &Processes {
|
||||||
|
&self.processes
|
||||||
|
}
|
||||||
|
fn processes_mut(&mut self) -> &mut Processes {
|
||||||
|
&mut self.processes
|
||||||
|
}
|
||||||
|
fn time_series(&self) -> &TimeSeries {
|
||||||
|
&self.time_series
|
||||||
|
}
|
||||||
|
fn time_series_mut(&mut self) -> &mut TimeSeries {
|
||||||
|
&mut self.time_series
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use fibonacci_interface::*;
|
use interface::*;
|
||||||
use std::sync::atomic::AtomicUsize;
|
use std::sync::atomic::AtomicUsize;
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
|
@ -48,7 +48,7 @@ impl Item for DirEntry {
|
||||||
fn icon(&self) -> &[u8] {
|
fn icon(&self) -> &[u8] {
|
||||||
&self.icon
|
&self.icon
|
||||||
}
|
}
|
||||||
fn retrieve(id: usize, parents: Vec<&DirEntry>, q: Incoming<Self>, emit: TreeEmitter) {
|
fn retrieve(id: usize, parents: Vec<&DirEntry>, q: Incoming<Self>, emit: FileSystemTreeEmitter) {
|
||||||
let mut v = Vec::new();
|
let mut v = Vec::new();
|
||||||
let path: PathBuf = parents.into_iter().map(|e| &e.name).collect();
|
let path: PathBuf = parents.into_iter().map(|e| &e.name).collect();
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
|
@ -87,7 +87,7 @@ impl Default for DirEntry {
|
||||||
pub trait Item: Default {
|
pub trait Item: Default {
|
||||||
fn create(name: &str) -> Self;
|
fn create(name: &str) -> Self;
|
||||||
fn can_fetch_more(&self) -> bool;
|
fn can_fetch_more(&self) -> bool;
|
||||||
fn retrieve(id: usize, parents: Vec<&Self>, q: Incoming<Self>, emit: TreeEmitter);
|
fn retrieve(id: usize, parents: Vec<&Self>, q: Incoming<Self>, emit: FileSystemTreeEmitter);
|
||||||
fn file_name(&self) -> String;
|
fn file_name(&self) -> String;
|
||||||
fn file_path(&self) -> Option<String>;
|
fn file_path(&self) -> Option<String>;
|
||||||
fn file_permissions(&self) -> i32;
|
fn file_permissions(&self) -> i32;
|
||||||
|
@ -96,7 +96,7 @@ pub trait Item: Default {
|
||||||
fn icon(&self) -> &[u8];
|
fn icon(&self) -> &[u8];
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Tree = RGeneralItemModel<DirEntry>;
|
pub type FileSystemTree = RGeneralItemModel<DirEntry>;
|
||||||
|
|
||||||
struct Entry<T: Item> {
|
struct Entry<T: Item> {
|
||||||
parent: Option<usize>,
|
parent: Option<usize>,
|
||||||
|
@ -106,8 +106,8 @@ struct Entry<T: Item> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct RGeneralItemModel<T: Item> {
|
pub struct RGeneralItemModel<T: Item> {
|
||||||
emit: TreeEmitter,
|
emit: FileSystemTreeEmitter,
|
||||||
model: TreeUniformTree,
|
model: FileSystemTreeUniformTree,
|
||||||
entries: Vec<Entry<T>>,
|
entries: Vec<Entry<T>>,
|
||||||
path: Option<String>,
|
path: Option<String>,
|
||||||
incoming: Incoming<T>,
|
incoming: Incoming<T>,
|
||||||
|
@ -185,11 +185,11 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Item> TreeTrait for RGeneralItemModel<T>
|
impl<T: Item> FileSystemTreeTrait for RGeneralItemModel<T>
|
||||||
where
|
where
|
||||||
T: Sync + Send,
|
T: Sync + Send,
|
||||||
{
|
{
|
||||||
fn create(emit: TreeEmitter, model: TreeUniformTree) -> Self {
|
fn create(emit: FileSystemTreeEmitter, model: FileSystemTreeUniformTree) -> Self {
|
||||||
let mut tree = RGeneralItemModel {
|
let mut tree = RGeneralItemModel {
|
||||||
emit: emit,
|
emit: emit,
|
||||||
model: model,
|
model: model,
|
||||||
|
@ -200,7 +200,7 @@ where
|
||||||
tree.reset();
|
tree.reset();
|
||||||
tree
|
tree
|
||||||
}
|
}
|
||||||
fn emit(&self) -> &TreeEmitter {
|
fn emit(&self) -> &FileSystemTreeEmitter {
|
||||||
&self.emit
|
&self.emit
|
||||||
}
|
}
|
||||||
fn path(&self) -> Option<&str> {
|
fn path(&self) -> Option<&str> {
|
|
@ -0,0 +1,11 @@
|
||||||
|
mod demo;
|
||||||
|
mod fibonacci;
|
||||||
|
mod file_system_tree;
|
||||||
|
mod processes;
|
||||||
|
mod time_series;
|
||||||
|
|
||||||
|
pub use self::demo::*;
|
||||||
|
pub use self::fibonacci::*;
|
||||||
|
pub use self::file_system_tree::*;
|
||||||
|
pub use self::processes::*;
|
||||||
|
pub use self::time_series::*;
|
|
@ -1,9 +1,11 @@
|
||||||
use processes_interface::*;
|
use interface::*;
|
||||||
use sysinfo::*;
|
use sysinfo::*;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use libc::pid_t;
|
use libc::pid_t;
|
||||||
use std::{thread, time};
|
use std::thread;
|
||||||
|
use std::time::Duration;
|
||||||
|
use std::sync::mpsc::{channel, Sender, Receiver, RecvTimeoutError};
|
||||||
|
|
||||||
struct ProcessItem {
|
struct ProcessItem {
|
||||||
row: usize,
|
row: usize,
|
||||||
|
@ -18,12 +20,19 @@ struct ProcessTree {
|
||||||
cpusum: f32,
|
cpusum: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum ChangeState {
|
||||||
|
Active,
|
||||||
|
Inactive,
|
||||||
|
Quit
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Processes {
|
pub struct Processes {
|
||||||
emit: ProcessesEmitter,
|
emit: ProcessesEmitter,
|
||||||
model: ProcessesUniformTree,
|
model: ProcessesUniformTree,
|
||||||
p: ProcessTree,
|
p: ProcessTree,
|
||||||
incoming: Arc<Mutex<Option<ProcessTree>>>,
|
incoming: Arc<Mutex<Option<ProcessTree>>>,
|
||||||
active: bool,
|
active: bool,
|
||||||
|
channel: Sender<ChangeState>
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_process_hierarchy(parent: Option<pid_t>, processes: &HashMap<pid_t, Process>) {
|
fn check_process_hierarchy(parent: Option<pid_t>, processes: &HashMap<pid_t, Process>) {
|
||||||
|
@ -101,13 +110,27 @@ fn update() -> ProcessTree {
|
||||||
p
|
p
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_thread(emit: ProcessesEmitter, incoming: Arc<Mutex<Option<ProcessTree>>>) {
|
fn update_thread(
|
||||||
|
emit: ProcessesEmitter,
|
||||||
|
incoming: Arc<Mutex<Option<ProcessTree>>>,
|
||||||
|
mut active: bool,
|
||||||
|
statusChannel: Receiver<ChangeState>,
|
||||||
|
) {
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let second = time::Duration::new(1, 0);
|
|
||||||
loop {
|
loop {
|
||||||
*incoming.lock().unwrap() = Some(update());
|
let mut timeout = Duration::from_secs(10000);
|
||||||
emit.new_data_ready(None);
|
if active {
|
||||||
thread::sleep(second);
|
*incoming.lock().unwrap() = Some(update());
|
||||||
|
emit.new_data_ready(None);
|
||||||
|
timeout = Duration::from_secs(1);
|
||||||
|
}
|
||||||
|
match statusChannel.recv_timeout(timeout) {
|
||||||
|
Err(RecvTimeoutError::Timeout) => {},
|
||||||
|
Err(RecvTimeoutError::Disconnected) => { return; },
|
||||||
|
Ok(ChangeState::Active) => { active = true; },
|
||||||
|
Ok(ChangeState::Inactive) => { active = false; },
|
||||||
|
Ok(ChangeState::Quit) => { return; },
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -279,14 +302,16 @@ fn sync_tree(
|
||||||
|
|
||||||
impl ProcessesTrait for Processes {
|
impl ProcessesTrait for Processes {
|
||||||
fn create(emit: ProcessesEmitter, model: ProcessesUniformTree) -> Processes {
|
fn create(emit: ProcessesEmitter, model: ProcessesUniformTree) -> Processes {
|
||||||
|
let (tx, rx) = channel();
|
||||||
let p = Processes {
|
let p = Processes {
|
||||||
emit: emit.clone(),
|
emit: emit.clone(),
|
||||||
model: model,
|
model: model,
|
||||||
p: ProcessTree::default(),
|
p: ProcessTree::default(),
|
||||||
incoming: Arc::new(Mutex::new(None)),
|
incoming: Arc::new(Mutex::new(None)),
|
||||||
active: true,
|
active: false,
|
||||||
|
channel: tx,
|
||||||
};
|
};
|
||||||
update_thread(emit, p.incoming.clone());
|
update_thread(emit, p.incoming.clone(), p.active, rx);
|
||||||
p
|
p
|
||||||
}
|
}
|
||||||
fn emit(&self) -> &ProcessesEmitter {
|
fn emit(&self) -> &ProcessesEmitter {
|
||||||
|
@ -371,6 +396,19 @@ impl ProcessesTrait for Processes {
|
||||||
self.active
|
self.active
|
||||||
}
|
}
|
||||||
fn set_active(&mut self, active: bool) {
|
fn set_active(&mut self, active: bool) {
|
||||||
self.active = active
|
if self.active != active {
|
||||||
|
self.active = active;
|
||||||
|
if active {
|
||||||
|
self.channel.send(ChangeState::Active);
|
||||||
|
} else {
|
||||||
|
self.channel.send(ChangeState::Inactive);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for Processes {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
self.channel.send(ChangeState::Quit);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
use time_series_interface::*;
|
use interface::*;
|
||||||
|
|
||||||
#[derive(Default, Clone)]
|
#[derive(Default, Clone)]
|
||||||
struct TimeSeriesItem {
|
struct TimeSeriesItem {
|
File diff suppressed because it is too large
Load Diff
|
@ -1,14 +1,5 @@
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
extern crate sysinfo;
|
extern crate sysinfo;
|
||||||
|
|
||||||
mod fibonacci_implementation;
|
|
||||||
pub mod fibonacci_interface;
|
|
||||||
|
|
||||||
mod implementation;
|
mod implementation;
|
||||||
pub mod interface;
|
pub mod interface;
|
||||||
|
|
||||||
mod time_series_implementation;
|
|
||||||
pub mod time_series_interface;
|
|
||||||
|
|
||||||
mod processes_implementation;
|
|
||||||
pub mod processes_interface;
|
|
||||||
|
|
|
@ -1,338 +0,0 @@
|
||||||
/* generated by rust_qt_binding_generator */
|
|
||||||
#![allow(unknown_lints)]
|
|
||||||
#![allow(mutex_atomic, needless_pass_by_value)]
|
|
||||||
use libc::{c_int, c_void, uint8_t, uint16_t};
|
|
||||||
use std::slice;
|
|
||||||
|
|
||||||
use std::sync::{Arc, Mutex};
|
|
||||||
use std::ptr::null;
|
|
||||||
|
|
||||||
use processes_implementation::*;
|
|
||||||
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
pub struct COption<T> {
|
|
||||||
data: T,
|
|
||||||
some: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> From<Option<T>> for COption<T>
|
|
||||||
where
|
|
||||||
T: Default,
|
|
||||||
{
|
|
||||||
fn from(t: Option<T>) -> COption<T> {
|
|
||||||
if let Some(v) = t {
|
|
||||||
COption {
|
|
||||||
data: v,
|
|
||||||
some: true,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
COption {
|
|
||||||
data: T::default(),
|
|
||||||
some: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
pub struct QString {
|
|
||||||
data: *const uint8_t,
|
|
||||||
len: c_int,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
pub struct QStringIn {
|
|
||||||
data: *const uint16_t,
|
|
||||||
len: c_int,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl QStringIn {
|
|
||||||
fn convert(&self) -> String {
|
|
||||||
let data = unsafe { slice::from_raw_parts(self.data, self.len as usize) };
|
|
||||||
String::from_utf16_lossy(data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> From<&'a str> for QString {
|
|
||||||
fn from(string: &'a str) -> QString {
|
|
||||||
QString {
|
|
||||||
len: string.len() as c_int,
|
|
||||||
data: string.as_ptr(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> From<&'a String> for QString {
|
|
||||||
fn from(string: &'a String) -> QString {
|
|
||||||
QString {
|
|
||||||
len: string.len() as c_int,
|
|
||||||
data: string.as_ptr(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
pub enum SortOrder {
|
|
||||||
Ascending = 0,
|
|
||||||
Descending = 1,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
pub struct QModelIndex {
|
|
||||||
row: c_int,
|
|
||||||
internal_id: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct ProcessesQObject {}
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct ProcessesEmitter {
|
|
||||||
qobject: Arc<Mutex<*const ProcessesQObject>>,
|
|
||||||
active_changed: fn(*const ProcessesQObject),
|
|
||||||
new_data_ready: fn(*const ProcessesQObject, item: usize, valid: bool),
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl Send for ProcessesEmitter {}
|
|
||||||
|
|
||||||
impl ProcessesEmitter {
|
|
||||||
fn clear(&self) {
|
|
||||||
*self.qobject.lock().unwrap() = null();
|
|
||||||
}
|
|
||||||
pub fn active_changed(&self) {
|
|
||||||
let ptr = *self.qobject.lock().unwrap();
|
|
||||||
if !ptr.is_null() {
|
|
||||||
(self.active_changed)(ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct ProcessesUniformTree {
|
|
||||||
qobject: *const ProcessesQObject,
|
|
||||||
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, item: usize, valid: bool, usize, usize),
|
|
||||||
end_insert_rows: fn(*const ProcessesQObject),
|
|
||||||
begin_remove_rows: fn(*const ProcessesQObject, item: usize, valid: bool, usize, usize),
|
|
||||||
end_remove_rows: fn(*const ProcessesQObject),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ProcessesUniformTree {
|
|
||||||
pub fn data_changed(&self, first: usize, last: usize) {
|
|
||||||
(self.data_changed)(self.qobject, first, last);
|
|
||||||
}
|
|
||||||
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, item: Option<usize>, first: usize, last: usize) {
|
|
||||||
(self.begin_insert_rows)(self.qobject, item.unwrap_or(13), item.is_some(), first, last);
|
|
||||||
}
|
|
||||||
pub fn end_insert_rows(&self) {
|
|
||||||
(self.end_insert_rows)(self.qobject);
|
|
||||||
}
|
|
||||||
pub fn begin_remove_rows(&self, item: Option<usize>, first: usize, last: usize) {
|
|
||||||
(self.begin_remove_rows)(self.qobject, item.unwrap_or(13), item.is_some(), first, last);
|
|
||||||
}
|
|
||||||
pub fn end_remove_rows(&self) {
|
|
||||||
(self.end_remove_rows)(self.qobject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait ProcessesTrait {
|
|
||||||
fn create(emit: ProcessesEmitter, model: ProcessesUniformTree) -> Self;
|
|
||||||
fn emit(&self) -> &ProcessesEmitter;
|
|
||||||
fn active(&self) -> bool;
|
|
||||||
fn set_active(&mut self, value: bool);
|
|
||||||
fn row_count(&self, Option<usize>) -> usize;
|
|
||||||
fn can_fetch_more(&self, Option<usize>) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
fn fetch_more(&mut self, Option<usize>) {}
|
|
||||||
fn sort(&mut self, u8, SortOrder) {}
|
|
||||||
fn index(&self, item: Option<usize>, row: usize) -> usize;
|
|
||||||
fn parent(&self, item: usize) -> Option<usize>;
|
|
||||||
fn row(&self, item: usize) -> usize;
|
|
||||||
fn cmd(&self, item: usize) -> String;
|
|
||||||
fn cpu_percentage(&self, item: usize) -> u8;
|
|
||||||
fn cpu_usage(&self, item: usize) -> f32;
|
|
||||||
fn memory(&self, item: usize) -> u64;
|
|
||||||
fn name(&self, item: usize) -> &str;
|
|
||||||
fn pid(&self, item: usize) -> u32;
|
|
||||||
fn uid(&self, item: usize) -> u32;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub extern "C" fn processes_new(
|
|
||||||
processes: *mut ProcessesQObject,
|
|
||||||
active_changed: fn(*const ProcessesQObject),
|
|
||||||
new_data_ready: fn(*const ProcessesQObject, item: usize, valid: bool),
|
|
||||||
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, item: usize, valid: bool, usize, usize),
|
|
||||||
end_insert_rows: fn(*const ProcessesQObject),
|
|
||||||
begin_remove_rows: fn(*const ProcessesQObject, item: usize, valid: bool, usize, usize),
|
|
||||||
end_remove_rows: fn(*const ProcessesQObject),
|
|
||||||
) -> *mut Processes {
|
|
||||||
let processes_emit = ProcessesEmitter {
|
|
||||||
qobject: Arc::new(Mutex::new(processes)),
|
|
||||||
active_changed: active_changed,
|
|
||||||
new_data_ready: new_data_ready,
|
|
||||||
};
|
|
||||||
let model = ProcessesUniformTree {
|
|
||||||
qobject: processes,
|
|
||||||
data_changed: data_changed,
|
|
||||||
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,
|
|
||||||
end_remove_rows: end_remove_rows,
|
|
||||||
};
|
|
||||||
let d_processes = Processes::create(processes_emit, model);
|
|
||||||
Box::into_raw(Box::new(d_processes))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn processes_free(ptr: *mut Processes) {
|
|
||||||
Box::from_raw(ptr).emit().clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn processes_active_get(ptr: *const Processes) -> bool {
|
|
||||||
(&*ptr).active()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn processes_active_set(ptr: *mut Processes, v: bool) {
|
|
||||||
(&mut *ptr).set_active(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn processes_row_count(
|
|
||||||
ptr: *const Processes,
|
|
||||||
item: usize,
|
|
||||||
valid: bool,
|
|
||||||
) -> c_int {
|
|
||||||
if valid {
|
|
||||||
(&*ptr).row_count(Some(item)) as c_int
|
|
||||||
} else {
|
|
||||||
(&*ptr).row_count(None) as c_int
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn processes_can_fetch_more(
|
|
||||||
ptr: *const Processes,
|
|
||||||
item: usize,
|
|
||||||
valid: bool,
|
|
||||||
) -> bool {
|
|
||||||
if valid {
|
|
||||||
(&*ptr).can_fetch_more(Some(item))
|
|
||||||
} else {
|
|
||||||
(&*ptr).can_fetch_more(None)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn processes_fetch_more(ptr: *mut Processes, item: usize, valid: bool) {
|
|
||||||
if valid {
|
|
||||||
(&mut *ptr).fetch_more(Some(item))
|
|
||||||
} else {
|
|
||||||
(&mut *ptr).fetch_more(None)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn processes_sort(
|
|
||||||
ptr: *mut Processes,
|
|
||||||
column: u8,
|
|
||||||
order: SortOrder
|
|
||||||
) {
|
|
||||||
(&mut *ptr).sort(column, order)
|
|
||||||
}
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn processes_index(
|
|
||||||
ptr: *const Processes,
|
|
||||||
item: usize,
|
|
||||||
valid: bool,
|
|
||||||
row: c_int,
|
|
||||||
) -> usize {
|
|
||||||
if !valid {
|
|
||||||
(&*ptr).index(None, row as usize)
|
|
||||||
} else {
|
|
||||||
(&*ptr).index(Some(item), row as usize)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn processes_parent(ptr: *const Processes, index: usize) -> QModelIndex {
|
|
||||||
if let Some(parent) = (&*ptr).parent(index) {
|
|
||||||
QModelIndex {
|
|
||||||
row: (&*ptr).row(parent) as c_int,
|
|
||||||
internal_id: parent,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
QModelIndex {
|
|
||||||
row: -1,
|
|
||||||
internal_id: 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn processes_row(ptr: *const Processes, item: usize) -> c_int {
|
|
||||||
(&*ptr).row(item) as c_int
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn processes_data_cmd(
|
|
||||||
ptr: *const Processes, item: usize,
|
|
||||||
d: *mut c_void,
|
|
||||||
set: fn(*mut c_void, QString),
|
|
||||||
) {
|
|
||||||
let data = (&*ptr).cmd(item);
|
|
||||||
set(d, (&data).into());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn processes_data_cpu_percentage(ptr: *const Processes, item: usize) -> u8 {
|
|
||||||
(&*ptr).cpu_percentage(item).into()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn processes_data_cpu_usage(ptr: *const Processes, item: usize) -> f32 {
|
|
||||||
(&*ptr).cpu_usage(item).into()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn processes_data_memory(ptr: *const Processes, item: usize) -> u64 {
|
|
||||||
(&*ptr).memory(item).into()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn processes_data_name(
|
|
||||||
ptr: *const Processes, item: usize,
|
|
||||||
d: *mut c_void,
|
|
||||||
set: fn(*mut c_void, QString),
|
|
||||||
) {
|
|
||||||
let data = (&*ptr).name(item);
|
|
||||||
set(d, (data).into());
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn processes_data_pid(ptr: *const Processes, item: usize) -> u32 {
|
|
||||||
(&*ptr).pid(item).into()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn processes_data_uid(ptr: *const Processes, item: usize) -> u32 {
|
|
||||||
(&*ptr).uid(item).into()
|
|
||||||
}
|
|
|
@ -1,203 +0,0 @@
|
||||||
/* generated by rust_qt_binding_generator */
|
|
||||||
#![allow(unknown_lints)]
|
|
||||||
#![allow(mutex_atomic, needless_pass_by_value)]
|
|
||||||
use libc::{c_int, c_void, uint8_t, uint16_t};
|
|
||||||
use std::slice;
|
|
||||||
|
|
||||||
use std::sync::{Arc, Mutex};
|
|
||||||
use std::ptr::null;
|
|
||||||
|
|
||||||
use time_series_implementation::*;
|
|
||||||
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
pub struct COption<T> {
|
|
||||||
data: T,
|
|
||||||
some: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> From<Option<T>> for COption<T>
|
|
||||||
where
|
|
||||||
T: Default,
|
|
||||||
{
|
|
||||||
fn from(t: Option<T>) -> COption<T> {
|
|
||||||
if let Some(v) = t {
|
|
||||||
COption {
|
|
||||||
data: v,
|
|
||||||
some: true,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
COption {
|
|
||||||
data: T::default(),
|
|
||||||
some: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
pub enum SortOrder {
|
|
||||||
Ascending = 0,
|
|
||||||
Descending = 1,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[repr(C)]
|
|
||||||
pub struct QModelIndex {
|
|
||||||
row: c_int,
|
|
||||||
internal_id: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct TimeSeriesQObject {}
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct TimeSeriesEmitter {
|
|
||||||
qobject: Arc<Mutex<*const TimeSeriesQObject>>,
|
|
||||||
new_data_ready: fn(*const TimeSeriesQObject),
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl Send for TimeSeriesEmitter {}
|
|
||||||
|
|
||||||
impl TimeSeriesEmitter {
|
|
||||||
fn clear(&self) {
|
|
||||||
*self.qobject.lock().unwrap() = null();
|
|
||||||
}
|
|
||||||
pub fn new_data_ready(&self) {
|
|
||||||
let ptr = *self.qobject.lock().unwrap();
|
|
||||||
if !ptr.is_null() {
|
|
||||||
(self.new_data_ready)(ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct TimeSeriesList {
|
|
||||||
qobject: *const TimeSeriesQObject,
|
|
||||||
data_changed: fn(*const TimeSeriesQObject, usize, usize),
|
|
||||||
begin_reset_model: fn(*const TimeSeriesQObject),
|
|
||||||
end_reset_model: fn(*const TimeSeriesQObject),
|
|
||||||
begin_insert_rows: fn(*const TimeSeriesQObject, usize, usize),
|
|
||||||
end_insert_rows: fn(*const TimeSeriesQObject),
|
|
||||||
begin_remove_rows: fn(*const TimeSeriesQObject, usize, usize),
|
|
||||||
end_remove_rows: fn(*const TimeSeriesQObject),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TimeSeriesList {
|
|
||||||
pub fn data_changed(&self, first: usize, last: usize) {
|
|
||||||
(self.data_changed)(self.qobject, first, last);
|
|
||||||
}
|
|
||||||
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: usize, last: usize) {
|
|
||||||
(self.begin_insert_rows)(self.qobject, first, last);
|
|
||||||
}
|
|
||||||
pub fn end_insert_rows(&self) {
|
|
||||||
(self.end_insert_rows)(self.qobject);
|
|
||||||
}
|
|
||||||
pub fn begin_remove_rows(&self, first: usize, last: usize) {
|
|
||||||
(self.begin_remove_rows)(self.qobject, first, last);
|
|
||||||
}
|
|
||||||
pub fn end_remove_rows(&self) {
|
|
||||||
(self.end_remove_rows)(self.qobject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait TimeSeriesTrait {
|
|
||||||
fn create(emit: TimeSeriesEmitter, model: TimeSeriesList) -> Self;
|
|
||||||
fn emit(&self) -> &TimeSeriesEmitter;
|
|
||||||
fn row_count(&self) -> usize;
|
|
||||||
fn can_fetch_more(&self) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
fn fetch_more(&mut self) {}
|
|
||||||
fn sort(&mut self, u8, SortOrder) {}
|
|
||||||
fn input(&self, item: usize) -> u32;
|
|
||||||
fn set_input(&mut self, item: usize, u32) -> bool;
|
|
||||||
fn result(&self, item: usize) -> u32;
|
|
||||||
fn set_result(&mut self, item: usize, u32) -> bool;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub extern "C" fn time_series_new(
|
|
||||||
time_series: *mut TimeSeriesQObject,
|
|
||||||
new_data_ready: fn(*const TimeSeriesQObject),
|
|
||||||
data_changed: fn(*const TimeSeriesQObject, usize, usize),
|
|
||||||
begin_reset_model: fn(*const TimeSeriesQObject),
|
|
||||||
end_reset_model: fn(*const TimeSeriesQObject),
|
|
||||||
begin_insert_rows: fn(*const TimeSeriesQObject, usize, usize),
|
|
||||||
end_insert_rows: fn(*const TimeSeriesQObject),
|
|
||||||
begin_remove_rows: fn(*const TimeSeriesQObject, usize, usize),
|
|
||||||
end_remove_rows: fn(*const TimeSeriesQObject),
|
|
||||||
) -> *mut TimeSeries {
|
|
||||||
let time_series_emit = TimeSeriesEmitter {
|
|
||||||
qobject: Arc::new(Mutex::new(time_series)),
|
|
||||||
new_data_ready: new_data_ready,
|
|
||||||
};
|
|
||||||
let model = TimeSeriesList {
|
|
||||||
qobject: time_series,
|
|
||||||
data_changed: data_changed,
|
|
||||||
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,
|
|
||||||
end_remove_rows: end_remove_rows,
|
|
||||||
};
|
|
||||||
let d_time_series = TimeSeries::create(time_series_emit, model);
|
|
||||||
Box::into_raw(Box::new(d_time_series))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn time_series_free(ptr: *mut TimeSeries) {
|
|
||||||
Box::from_raw(ptr).emit().clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn time_series_row_count(ptr: *const TimeSeries) -> c_int {
|
|
||||||
(&*ptr).row_count() as c_int
|
|
||||||
}
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn time_series_can_fetch_more(ptr: *const TimeSeries) -> bool {
|
|
||||||
(&*ptr).can_fetch_more()
|
|
||||||
}
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn time_series_fetch_more(ptr: *mut TimeSeries) {
|
|
||||||
(&mut *ptr).fetch_more()
|
|
||||||
}
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn time_series_sort(
|
|
||||||
ptr: *mut TimeSeries,
|
|
||||||
column: u8,
|
|
||||||
order: SortOrder,
|
|
||||||
) {
|
|
||||||
(&mut *ptr).sort(column, order)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn time_series_data_input(ptr: *const TimeSeries, row: c_int) -> u32 {
|
|
||||||
(&*ptr).input(row as usize).into()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn time_series_set_data_input(
|
|
||||||
ptr: *mut TimeSeries, row: c_int,
|
|
||||||
v: u32,
|
|
||||||
) -> bool {
|
|
||||||
(&mut *ptr).set_input(row as usize, v)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn time_series_data_result(ptr: *const TimeSeries, row: c_int) -> u32 {
|
|
||||||
(&*ptr).result(row as usize).into()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn time_series_set_data_result(
|
|
||||||
ptr: *mut TimeSeries, row: c_int,
|
|
||||||
v: u32,
|
|
||||||
) -> bool {
|
|
||||||
(&mut *ptr).set_result(row as usize, v)
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,228 @@
|
||||||
|
/* generated by rust_qt_binding_generator */
|
||||||
|
#ifndef BINDINGS_H
|
||||||
|
#define BINDINGS_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QAbstractItemModel>
|
||||||
|
|
||||||
|
class Demo;
|
||||||
|
class Fibonacci;
|
||||||
|
class FibonacciList;
|
||||||
|
class FileSystemTree;
|
||||||
|
class Processes;
|
||||||
|
class TimeSeries;
|
||||||
|
|
||||||
|
class Demo : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
class Private;
|
||||||
|
private:
|
||||||
|
Fibonacci* const m_fibonacci;
|
||||||
|
FibonacciList* const m_fibonacciList;
|
||||||
|
FileSystemTree* const m_fileSystemTree;
|
||||||
|
Processes* const m_processes;
|
||||||
|
TimeSeries* const m_timeSeries;
|
||||||
|
Private * m_d;
|
||||||
|
bool m_ownsPrivate;
|
||||||
|
Q_PROPERTY(Fibonacci* fibonacci READ fibonacci FINAL)
|
||||||
|
Q_PROPERTY(FibonacciList* fibonacciList READ fibonacciList FINAL)
|
||||||
|
Q_PROPERTY(FileSystemTree* fileSystemTree READ fileSystemTree FINAL)
|
||||||
|
Q_PROPERTY(Processes* processes READ processes FINAL)
|
||||||
|
Q_PROPERTY(TimeSeries* timeSeries READ timeSeries FINAL)
|
||||||
|
explicit Demo(bool owned, QObject *parent);
|
||||||
|
public:
|
||||||
|
explicit Demo(QObject *parent = nullptr);
|
||||||
|
~Demo();
|
||||||
|
const Fibonacci* fibonacci() const;
|
||||||
|
Fibonacci* fibonacci();
|
||||||
|
const FibonacciList* fibonacciList() const;
|
||||||
|
FibonacciList* fibonacciList();
|
||||||
|
const FileSystemTree* fileSystemTree() const;
|
||||||
|
FileSystemTree* fileSystemTree();
|
||||||
|
const Processes* processes() const;
|
||||||
|
Processes* processes();
|
||||||
|
const TimeSeries* timeSeries() const;
|
||||||
|
TimeSeries* timeSeries();
|
||||||
|
signals:
|
||||||
|
};
|
||||||
|
|
||||||
|
class Fibonacci : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
friend class Demo;
|
||||||
|
public:
|
||||||
|
class Private;
|
||||||
|
private:
|
||||||
|
Private * m_d;
|
||||||
|
bool m_ownsPrivate;
|
||||||
|
Q_PROPERTY(quint32 input READ input WRITE setInput NOTIFY inputChanged FINAL)
|
||||||
|
Q_PROPERTY(quint64 result READ result NOTIFY resultChanged FINAL)
|
||||||
|
explicit Fibonacci(bool owned, QObject *parent);
|
||||||
|
public:
|
||||||
|
explicit Fibonacci(QObject *parent = nullptr);
|
||||||
|
~Fibonacci();
|
||||||
|
quint32 input() const;
|
||||||
|
void setInput(uint v);
|
||||||
|
quint64 result() const;
|
||||||
|
signals:
|
||||||
|
void inputChanged();
|
||||||
|
void resultChanged();
|
||||||
|
};
|
||||||
|
|
||||||
|
class FibonacciList : public QAbstractItemModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
friend class Demo;
|
||||||
|
public:
|
||||||
|
class Private;
|
||||||
|
private:
|
||||||
|
Private * m_d;
|
||||||
|
bool m_ownsPrivate;
|
||||||
|
explicit FibonacciList(bool owned, QObject *parent);
|
||||||
|
public:
|
||||||
|
explicit FibonacciList(QObject *parent = nullptr);
|
||||||
|
~FibonacciList();
|
||||||
|
|
||||||
|
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||||
|
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
QModelIndex parent(const QModelIndex &index) const override;
|
||||||
|
bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
bool canFetchMore(const QModelIndex &parent) const override;
|
||||||
|
void fetchMore(const QModelIndex &parent) override;
|
||||||
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||||
|
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
|
||||||
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||||
|
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);
|
||||||
|
signals:
|
||||||
|
// new data is ready to be made available to the model with fetchMore()
|
||||||
|
void newDataReady(const QModelIndex &parent) const;
|
||||||
|
private:
|
||||||
|
QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData;
|
||||||
|
void initHeaderData();
|
||||||
|
signals:
|
||||||
|
};
|
||||||
|
|
||||||
|
class FileSystemTree : public QAbstractItemModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
friend class Demo;
|
||||||
|
public:
|
||||||
|
class Private;
|
||||||
|
private:
|
||||||
|
Private * m_d;
|
||||||
|
bool m_ownsPrivate;
|
||||||
|
Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged FINAL)
|
||||||
|
explicit FileSystemTree(bool owned, QObject *parent);
|
||||||
|
public:
|
||||||
|
explicit FileSystemTree(QObject *parent = nullptr);
|
||||||
|
~FileSystemTree();
|
||||||
|
QString path() const;
|
||||||
|
void setPath(const QString& v);
|
||||||
|
|
||||||
|
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||||
|
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
QModelIndex parent(const QModelIndex &index) const override;
|
||||||
|
bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
bool canFetchMore(const QModelIndex &parent) const override;
|
||||||
|
void fetchMore(const QModelIndex &parent) override;
|
||||||
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||||
|
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
|
||||||
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||||
|
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);
|
||||||
|
signals:
|
||||||
|
// new data is ready to be made available to the model with fetchMore()
|
||||||
|
void newDataReady(const QModelIndex &parent) const;
|
||||||
|
private:
|
||||||
|
QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData;
|
||||||
|
void initHeaderData();
|
||||||
|
signals:
|
||||||
|
void pathChanged();
|
||||||
|
};
|
||||||
|
|
||||||
|
class Processes : public QAbstractItemModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
friend class Demo;
|
||||||
|
public:
|
||||||
|
class Private;
|
||||||
|
private:
|
||||||
|
Private * m_d;
|
||||||
|
bool m_ownsPrivate;
|
||||||
|
Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged FINAL)
|
||||||
|
explicit Processes(bool owned, QObject *parent);
|
||||||
|
public:
|
||||||
|
explicit Processes(QObject *parent = nullptr);
|
||||||
|
~Processes();
|
||||||
|
bool active() const;
|
||||||
|
void setActive(bool v);
|
||||||
|
|
||||||
|
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||||
|
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
QModelIndex parent(const QModelIndex &index) const override;
|
||||||
|
bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
bool canFetchMore(const QModelIndex &parent) const override;
|
||||||
|
void fetchMore(const QModelIndex &parent) override;
|
||||||
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||||
|
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
|
||||||
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||||
|
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);
|
||||||
|
signals:
|
||||||
|
// new data is ready to be made available to the model with fetchMore()
|
||||||
|
void newDataReady(const QModelIndex &parent) const;
|
||||||
|
private:
|
||||||
|
QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData;
|
||||||
|
void initHeaderData();
|
||||||
|
signals:
|
||||||
|
void activeChanged();
|
||||||
|
};
|
||||||
|
|
||||||
|
class TimeSeries : public QAbstractItemModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
friend class Demo;
|
||||||
|
public:
|
||||||
|
class Private;
|
||||||
|
private:
|
||||||
|
Private * m_d;
|
||||||
|
bool m_ownsPrivate;
|
||||||
|
explicit TimeSeries(bool owned, QObject *parent);
|
||||||
|
public:
|
||||||
|
explicit TimeSeries(QObject *parent = nullptr);
|
||||||
|
~TimeSeries();
|
||||||
|
|
||||||
|
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||||
|
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
QModelIndex parent(const QModelIndex &index) const override;
|
||||||
|
bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
bool canFetchMore(const QModelIndex &parent) const override;
|
||||||
|
void fetchMore(const QModelIndex &parent) override;
|
||||||
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||||
|
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
|
||||||
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||||
|
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);
|
||||||
|
signals:
|
||||||
|
// new data is ready to be made available to the model with fetchMore()
|
||||||
|
void newDataReady(const QModelIndex &parent) const;
|
||||||
|
private:
|
||||||
|
QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData;
|
||||||
|
void initHeaderData();
|
||||||
|
signals:
|
||||||
|
};
|
||||||
|
#endif // BINDINGS_H
|
|
@ -1,253 +0,0 @@
|
||||||
/* generated by rust_qt_binding_generator */
|
|
||||||
#include "Fibonacci.h"
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
template <typename T>
|
|
||||||
struct option {
|
|
||||||
public:
|
|
||||||
T value;
|
|
||||||
bool some;
|
|
||||||
operator QVariant() const {
|
|
||||||
if (some) {
|
|
||||||
return QVariant(value);
|
|
||||||
}
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
struct qbytearray_t {
|
|
||||||
private:
|
|
||||||
const char* data;
|
|
||||||
int len;
|
|
||||||
public:
|
|
||||||
qbytearray_t(const QByteArray& v):
|
|
||||||
data(v.data()),
|
|
||||||
len(v.size()) {
|
|
||||||
}
|
|
||||||
operator QByteArray() const {
|
|
||||||
return QByteArray(data, len);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
struct qstring_t {
|
|
||||||
private:
|
|
||||||
const void* data;
|
|
||||||
int len;
|
|
||||||
public:
|
|
||||||
qstring_t(const QString& v):
|
|
||||||
data(static_cast<const void*>(v.utf16())),
|
|
||||||
len(v.size()) {
|
|
||||||
}
|
|
||||||
operator QString() const {
|
|
||||||
return QString::fromUtf8(static_cast<const char*>(data), len);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
struct qmodelindex_t {
|
|
||||||
int row;
|
|
||||||
quintptr id;
|
|
||||||
};
|
|
||||||
inline void fibonacciInputChanged(Fibonacci* o)
|
|
||||||
{
|
|
||||||
emit o->inputChanged();
|
|
||||||
}
|
|
||||||
inline void fibonacciResultChanged(Fibonacci* o)
|
|
||||||
{
|
|
||||||
emit o->resultChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
typedef void (*qstring_set)(QString*, qstring_t*);
|
|
||||||
void set_qstring(QString* v, qstring_t* val) {
|
|
||||||
*v = *val;
|
|
||||||
}
|
|
||||||
typedef void (*qbytearray_set)(QByteArray*, qbytearray_t*);
|
|
||||||
void set_qbytearray(QByteArray* v, qbytearray_t* val) {
|
|
||||||
*v = *val;
|
|
||||||
}
|
|
||||||
extern "C" {
|
|
||||||
Fibonacci::Private* fibonacci_new(Fibonacci*, void (*)(Fibonacci*), void (*)(Fibonacci*));
|
|
||||||
void fibonacci_free(Fibonacci::Private*);
|
|
||||||
quint32 fibonacci_input_get(const Fibonacci::Private*);
|
|
||||||
void fibonacci_input_set(Fibonacci::Private*, uint);
|
|
||||||
quint64 fibonacci_result_get(const Fibonacci::Private*);
|
|
||||||
};
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
quint64 fibonacci_list_data_result(const FibonacciList::Private*, int);
|
|
||||||
void fibonacci_list_sort(FibonacciList::Private*, unsigned char column, Qt::SortOrder order = Qt::AscendingOrder);
|
|
||||||
|
|
||||||
int fibonacci_list_row_count(const FibonacciList::Private*);
|
|
||||||
bool fibonacci_list_can_fetch_more(const FibonacciList::Private*);
|
|
||||||
void fibonacci_list_fetch_more(FibonacciList::Private*);
|
|
||||||
}
|
|
||||||
int FibonacciList::columnCount(const QModelIndex &parent) const
|
|
||||||
{
|
|
||||||
return (parent.isValid()) ? 0 : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FibonacciList::hasChildren(const QModelIndex &parent) const
|
|
||||||
{
|
|
||||||
return rowCount(parent) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int FibonacciList::rowCount(const QModelIndex &parent) const
|
|
||||||
{
|
|
||||||
return (parent.isValid()) ? 0 : fibonacci_list_row_count(m_d);
|
|
||||||
}
|
|
||||||
|
|
||||||
QModelIndex FibonacciList::index(int row, int column, const QModelIndex &parent) const
|
|
||||||
{
|
|
||||||
if (!parent.isValid() && row >= 0 && row < rowCount(parent) && column >= 0 && column < 1) {
|
|
||||||
return createIndex(row, column, (quintptr)row);
|
|
||||||
}
|
|
||||||
return QModelIndex();
|
|
||||||
}
|
|
||||||
|
|
||||||
QModelIndex FibonacciList::parent(const QModelIndex &) const
|
|
||||||
{
|
|
||||||
return QModelIndex();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FibonacciList::canFetchMore(const QModelIndex &parent) const
|
|
||||||
{
|
|
||||||
return (parent.isValid()) ? 0 : fibonacci_list_can_fetch_more(m_d);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FibonacciList::fetchMore(const QModelIndex &parent)
|
|
||||||
{
|
|
||||||
if (!parent.isValid()) {
|
|
||||||
fibonacci_list_fetch_more(m_d);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void FibonacciList::sort(int column, Qt::SortOrder order)
|
|
||||||
{
|
|
||||||
fibonacci_list_sort(m_d, column, order);
|
|
||||||
}
|
|
||||||
Qt::ItemFlags FibonacciList::flags(const QModelIndex &i) const
|
|
||||||
{
|
|
||||||
auto flags = QAbstractItemModel::flags(i);
|
|
||||||
return flags;
|
|
||||||
}
|
|
||||||
QVariant FibonacciList::data(const QModelIndex &index, int role) const
|
|
||||||
{
|
|
||||||
QVariant v;
|
|
||||||
Q_ASSERT(rowCount(index.parent()) > index.row());
|
|
||||||
QString s;
|
|
||||||
QByteArray b;
|
|
||||||
switch (index.column()) {
|
|
||||||
case 0:
|
|
||||||
switch (role) {
|
|
||||||
case Qt::DisplayRole:
|
|
||||||
case Qt::UserRole + 0:
|
|
||||||
v = fibonacci_list_data_result(m_d, index.row());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
QHash<int, QByteArray> FibonacciList::roleNames() const {
|
|
||||||
QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
|
|
||||||
names.insert(Qt::UserRole + 0, "result");
|
|
||||||
return names;
|
|
||||||
}
|
|
||||||
bool FibonacciList::setData(const QModelIndex &index, const QVariant &value, int role)
|
|
||||||
{
|
|
||||||
bool set = false;
|
|
||||||
if (set) {
|
|
||||||
emit dataChanged(index, index, QVector<int>() << role);
|
|
||||||
}
|
|
||||||
return set;
|
|
||||||
}
|
|
||||||
extern "C" {
|
|
||||||
FibonacciList::Private* fibonacci_list_new(FibonacciList*,
|
|
||||||
void (*)(const FibonacciList*),
|
|
||||||
void (*)(FibonacciList*, quintptr, quintptr),
|
|
||||||
void (*)(FibonacciList*),
|
|
||||||
void (*)(FibonacciList*),
|
|
||||||
void (*)(FibonacciList*, int, int),
|
|
||||||
void (*)(FibonacciList*),
|
|
||||||
void (*)(FibonacciList*, int, int),
|
|
||||||
void (*)(FibonacciList*));
|
|
||||||
void fibonacci_list_free(FibonacciList::Private*);
|
|
||||||
};
|
|
||||||
|
|
||||||
Fibonacci::Fibonacci(bool /*owned*/, QObject *parent):
|
|
||||||
QObject(parent),
|
|
||||||
m_d(0),
|
|
||||||
m_ownsPrivate(false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Fibonacci::Fibonacci(QObject *parent):
|
|
||||||
QObject(parent),
|
|
||||||
m_d(fibonacci_new(this,
|
|
||||||
fibonacciInputChanged,
|
|
||||||
fibonacciResultChanged)),
|
|
||||||
m_ownsPrivate(true)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Fibonacci::~Fibonacci() {
|
|
||||||
if (m_ownsPrivate) {
|
|
||||||
fibonacci_free(m_d);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
quint32 Fibonacci::input() const
|
|
||||||
{
|
|
||||||
return fibonacci_input_get(m_d);
|
|
||||||
}
|
|
||||||
void Fibonacci::setInput(uint v) {
|
|
||||||
fibonacci_input_set(m_d, v);
|
|
||||||
}
|
|
||||||
quint64 Fibonacci::result() const
|
|
||||||
{
|
|
||||||
return fibonacci_result_get(m_d);
|
|
||||||
}
|
|
||||||
FibonacciList::FibonacciList(bool /*owned*/, QObject *parent):
|
|
||||||
QAbstractItemModel(parent),
|
|
||||||
m_d(0),
|
|
||||||
m_ownsPrivate(false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
FibonacciList::FibonacciList(QObject *parent):
|
|
||||||
QAbstractItemModel(parent),
|
|
||||||
m_d(fibonacci_list_new(this,
|
|
||||||
[](const FibonacciList* o) {
|
|
||||||
emit o->newDataReady(QModelIndex());
|
|
||||||
},
|
|
||||||
[](FibonacciList* o, quintptr first, quintptr last) {
|
|
||||||
o->dataChanged(o->createIndex(first, 0, first),
|
|
||||||
o->createIndex(last, 0, last));
|
|
||||||
},
|
|
||||||
[](FibonacciList* o) {
|
|
||||||
o->beginResetModel();
|
|
||||||
},
|
|
||||||
[](FibonacciList* o) {
|
|
||||||
o->endResetModel();
|
|
||||||
},
|
|
||||||
[](FibonacciList* o, int first, int last) {
|
|
||||||
o->beginInsertRows(QModelIndex(), first, last);
|
|
||||||
},
|
|
||||||
[](FibonacciList* o) {
|
|
||||||
o->endInsertRows();
|
|
||||||
},
|
|
||||||
[](FibonacciList* o, int first, int last) {
|
|
||||||
o->beginRemoveRows(QModelIndex(), first, last);
|
|
||||||
},
|
|
||||||
[](FibonacciList* o) {
|
|
||||||
o->endRemoveRows();
|
|
||||||
}
|
|
||||||
)),
|
|
||||||
m_ownsPrivate(true)
|
|
||||||
{
|
|
||||||
connect(this, &FibonacciList::newDataReady, this, [this](const QModelIndex& i) {
|
|
||||||
fetchMore(i);
|
|
||||||
}, Qt::QueuedConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
FibonacciList::~FibonacciList() {
|
|
||||||
if (m_ownsPrivate) {
|
|
||||||
fibonacci_list_free(m_d);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,63 +0,0 @@
|
||||||
/* generated by rust_qt_binding_generator */
|
|
||||||
#ifndef FIBONACCI_H
|
|
||||||
#define FIBONACCI_H
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QAbstractItemModel>
|
|
||||||
|
|
||||||
class Fibonacci;
|
|
||||||
class FibonacciList;
|
|
||||||
|
|
||||||
class Fibonacci : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
class Private;
|
|
||||||
private:
|
|
||||||
Private * m_d;
|
|
||||||
bool m_ownsPrivate;
|
|
||||||
Q_PROPERTY(quint32 input READ input WRITE setInput NOTIFY inputChanged FINAL)
|
|
||||||
Q_PROPERTY(quint64 result READ result NOTIFY resultChanged FINAL)
|
|
||||||
explicit Fibonacci(bool owned, QObject *parent);
|
|
||||||
public:
|
|
||||||
explicit Fibonacci(QObject *parent = nullptr);
|
|
||||||
~Fibonacci();
|
|
||||||
quint32 input() const;
|
|
||||||
void setInput(uint v);
|
|
||||||
quint64 result() const;
|
|
||||||
signals:
|
|
||||||
void inputChanged();
|
|
||||||
void resultChanged();
|
|
||||||
};
|
|
||||||
|
|
||||||
class FibonacciList : public QAbstractItemModel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
class Private;
|
|
||||||
private:
|
|
||||||
Private * m_d;
|
|
||||||
bool m_ownsPrivate;
|
|
||||||
explicit FibonacciList(bool owned, QObject *parent);
|
|
||||||
public:
|
|
||||||
explicit FibonacciList(QObject *parent = nullptr);
|
|
||||||
~FibonacciList();
|
|
||||||
|
|
||||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
|
||||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
|
||||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
|
|
||||||
QModelIndex parent(const QModelIndex &index) const override;
|
|
||||||
bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
|
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
||||||
bool canFetchMore(const QModelIndex &parent) const override;
|
|
||||||
void fetchMore(const QModelIndex &parent) override;
|
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
|
||||||
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
|
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
|
||||||
signals:
|
|
||||||
// new data is ready to be made available to the model with fetchMore()
|
|
||||||
void newDataReady(const QModelIndex &parent) const;
|
|
||||||
signals:
|
|
||||||
};
|
|
||||||
#endif // FIBONACCI_H
|
|
|
@ -1,303 +0,0 @@
|
||||||
/* generated by rust_qt_binding_generator */
|
|
||||||
#include "Processes.h"
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
template <typename T>
|
|
||||||
struct option {
|
|
||||||
public:
|
|
||||||
T value;
|
|
||||||
bool some;
|
|
||||||
operator QVariant() const {
|
|
||||||
if (some) {
|
|
||||||
return QVariant(value);
|
|
||||||
}
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
struct qbytearray_t {
|
|
||||||
private:
|
|
||||||
const char* data;
|
|
||||||
int len;
|
|
||||||
public:
|
|
||||||
qbytearray_t(const QByteArray& v):
|
|
||||||
data(v.data()),
|
|
||||||
len(v.size()) {
|
|
||||||
}
|
|
||||||
operator QByteArray() const {
|
|
||||||
return QByteArray(data, len);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
struct qstring_t {
|
|
||||||
private:
|
|
||||||
const void* data;
|
|
||||||
int len;
|
|
||||||
public:
|
|
||||||
qstring_t(const QString& v):
|
|
||||||
data(static_cast<const void*>(v.utf16())),
|
|
||||||
len(v.size()) {
|
|
||||||
}
|
|
||||||
operator QString() const {
|
|
||||||
return QString::fromUtf8(static_cast<const char*>(data), len);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
struct qmodelindex_t {
|
|
||||||
int row;
|
|
||||||
quintptr id;
|
|
||||||
};
|
|
||||||
inline void processesActiveChanged(Processes* o)
|
|
||||||
{
|
|
||||||
emit o->activeChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
typedef void (*qstring_set)(QString*, qstring_t*);
|
|
||||||
void set_qstring(QString* v, qstring_t* val) {
|
|
||||||
*v = *val;
|
|
||||||
}
|
|
||||||
typedef void (*qbytearray_set)(QByteArray*, qbytearray_t*);
|
|
||||||
void set_qbytearray(QByteArray* v, qbytearray_t* val) {
|
|
||||||
*v = *val;
|
|
||||||
}
|
|
||||||
extern "C" {
|
|
||||||
void processes_data_cmd(const Processes::Private*, quintptr, QString*, qstring_set);
|
|
||||||
quint8 processes_data_cpu_percentage(const Processes::Private*, quintptr);
|
|
||||||
float processes_data_cpu_usage(const Processes::Private*, quintptr);
|
|
||||||
quint64 processes_data_memory(const Processes::Private*, quintptr);
|
|
||||||
void processes_data_name(const Processes::Private*, quintptr, QString*, qstring_set);
|
|
||||||
uint processes_data_pid(const Processes::Private*, quintptr);
|
|
||||||
uint processes_data_uid(const Processes::Private*, quintptr);
|
|
||||||
void processes_sort(Processes::Private*, unsigned char column, Qt::SortOrder order = Qt::AscendingOrder);
|
|
||||||
|
|
||||||
int processes_row_count(const Processes::Private*, quintptr, bool);
|
|
||||||
bool processes_can_fetch_more(const Processes::Private*, quintptr, bool);
|
|
||||||
void processes_fetch_more(Processes::Private*, quintptr, bool);
|
|
||||||
quintptr processes_index(const Processes::Private*, quintptr, bool, int);
|
|
||||||
qmodelindex_t processes_parent(const Processes::Private*, quintptr);
|
|
||||||
int processes_row(const Processes::Private*, quintptr);
|
|
||||||
}
|
|
||||||
int Processes::columnCount(const QModelIndex &) const
|
|
||||||
{
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Processes::hasChildren(const QModelIndex &parent) const
|
|
||||||
{
|
|
||||||
return rowCount(parent) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Processes::rowCount(const QModelIndex &parent) const
|
|
||||||
{
|
|
||||||
if (parent.isValid() && parent.column() != 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return processes_row_count(m_d, parent.internalId(), parent.isValid());
|
|
||||||
}
|
|
||||||
|
|
||||||
QModelIndex Processes::index(int row, int column, const QModelIndex &parent) const
|
|
||||||
{
|
|
||||||
if (row < 0 || column < 0 || column >= 3) {
|
|
||||||
return QModelIndex();
|
|
||||||
}
|
|
||||||
if (parent.isValid() && parent.column() != 0) {
|
|
||||||
return QModelIndex();
|
|
||||||
}
|
|
||||||
if (row >= rowCount(parent)) {
|
|
||||||
return QModelIndex();
|
|
||||||
}
|
|
||||||
const quintptr id = processes_index(m_d, parent.internalId(), parent.isValid(), row);
|
|
||||||
return createIndex(row, column, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
QModelIndex Processes::parent(const QModelIndex &index) const
|
|
||||||
{
|
|
||||||
if (!index.isValid()) {
|
|
||||||
return QModelIndex();
|
|
||||||
}
|
|
||||||
const qmodelindex_t parent = processes_parent(m_d, index.internalId());
|
|
||||||
return parent.row >= 0 ?createIndex(parent.row, 0, parent.id) :QModelIndex();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Processes::canFetchMore(const QModelIndex &parent) const
|
|
||||||
{
|
|
||||||
if (parent.isValid() && parent.column() != 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return processes_can_fetch_more(m_d, parent.internalId(), parent.isValid());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Processes::fetchMore(const QModelIndex &parent)
|
|
||||||
{
|
|
||||||
processes_fetch_more(m_d, parent.internalId(), parent.isValid());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Processes::sort(int column, Qt::SortOrder order)
|
|
||||||
{
|
|
||||||
processes_sort(m_d, column, order);
|
|
||||||
}
|
|
||||||
Qt::ItemFlags Processes::flags(const QModelIndex &i) const
|
|
||||||
{
|
|
||||||
auto flags = QAbstractItemModel::flags(i);
|
|
||||||
return flags;
|
|
||||||
}
|
|
||||||
QVariant Processes::data(const QModelIndex &index, int role) const
|
|
||||||
{
|
|
||||||
QVariant v;
|
|
||||||
Q_ASSERT(rowCount(index.parent()) > index.row());
|
|
||||||
QString s;
|
|
||||||
QByteArray b;
|
|
||||||
switch (index.column()) {
|
|
||||||
case 0:
|
|
||||||
switch (role) {
|
|
||||||
case Qt::UserRole + 0:
|
|
||||||
processes_data_cmd(m_d, index.internalId(), &s, set_qstring);
|
|
||||||
if (!s.isNull()) v.setValue<QString>(s);
|
|
||||||
break;
|
|
||||||
case Qt::UserRole + 1:
|
|
||||||
v = processes_data_cpu_percentage(m_d, index.internalId());
|
|
||||||
break;
|
|
||||||
case Qt::UserRole + 2:
|
|
||||||
v = processes_data_cpu_usage(m_d, index.internalId());
|
|
||||||
break;
|
|
||||||
case Qt::UserRole + 3:
|
|
||||||
v = processes_data_memory(m_d, index.internalId());
|
|
||||||
break;
|
|
||||||
case Qt::DisplayRole:
|
|
||||||
case Qt::UserRole + 4:
|
|
||||||
processes_data_name(m_d, index.internalId(), &s, set_qstring);
|
|
||||||
if (!s.isNull()) v.setValue<QString>(s);
|
|
||||||
break;
|
|
||||||
case Qt::ToolTipRole:
|
|
||||||
case Qt::UserRole + 5:
|
|
||||||
v = processes_data_pid(m_d, index.internalId());
|
|
||||||
break;
|
|
||||||
case Qt::UserRole + 6:
|
|
||||||
v = processes_data_uid(m_d, index.internalId());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
switch (role) {
|
|
||||||
case Qt::DisplayRole:
|
|
||||||
case Qt::UserRole + 2:
|
|
||||||
v = processes_data_cpu_usage(m_d, index.internalId());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
switch (role) {
|
|
||||||
case Qt::DisplayRole:
|
|
||||||
case Qt::UserRole + 3:
|
|
||||||
v = processes_data_memory(m_d, index.internalId());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
QHash<int, QByteArray> Processes::roleNames() const {
|
|
||||||
QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
|
|
||||||
names.insert(Qt::UserRole + 0, "cmd");
|
|
||||||
names.insert(Qt::UserRole + 1, "cpuPercentage");
|
|
||||||
names.insert(Qt::UserRole + 2, "cpuUsage");
|
|
||||||
names.insert(Qt::UserRole + 3, "memory");
|
|
||||||
names.insert(Qt::UserRole + 4, "name");
|
|
||||||
names.insert(Qt::UserRole + 5, "pid");
|
|
||||||
names.insert(Qt::UserRole + 6, "uid");
|
|
||||||
return names;
|
|
||||||
}
|
|
||||||
bool Processes::setData(const QModelIndex &index, const QVariant &value, int role)
|
|
||||||
{
|
|
||||||
bool set = false;
|
|
||||||
if (set) {
|
|
||||||
emit dataChanged(index, index, QVector<int>() << role);
|
|
||||||
}
|
|
||||||
return set;
|
|
||||||
}
|
|
||||||
extern "C" {
|
|
||||||
Processes::Private* processes_new(Processes*, void (*)(Processes*),
|
|
||||||
void (*)(const Processes*, quintptr, bool),
|
|
||||||
void (*)(Processes*, quintptr, quintptr),
|
|
||||||
void (*)(Processes*),
|
|
||||||
void (*)(Processes*),
|
|
||||||
void (*)(Processes*, option<quintptr>, int, int),
|
|
||||||
void (*)(Processes*),
|
|
||||||
void (*)(Processes*, option<quintptr>, int, int),
|
|
||||||
void (*)(Processes*));
|
|
||||||
void processes_free(Processes::Private*);
|
|
||||||
bool processes_active_get(const Processes::Private*);
|
|
||||||
void processes_active_set(Processes::Private*, bool);
|
|
||||||
};
|
|
||||||
|
|
||||||
Processes::Processes(bool /*owned*/, QObject *parent):
|
|
||||||
QAbstractItemModel(parent),
|
|
||||||
m_d(0),
|
|
||||||
m_ownsPrivate(false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Processes::Processes(QObject *parent):
|
|
||||||
QAbstractItemModel(parent),
|
|
||||||
m_d(processes_new(this,
|
|
||||||
processesActiveChanged,
|
|
||||||
[](const Processes* o, quintptr id, bool valid) {
|
|
||||||
if (valid) {
|
|
||||||
int row = processes_row(o->m_d, id);
|
|
||||||
emit o->newDataReady(o->createIndex(row, 0, id));
|
|
||||||
} else {
|
|
||||||
emit o->newDataReady(QModelIndex());
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[](Processes* o, quintptr first, quintptr last) {
|
|
||||||
quintptr frow = processes_row(o->m_d, first);
|
|
||||||
quintptr lrow = processes_row(o->m_d, first);
|
|
||||||
o->dataChanged(o->createIndex(frow, 0, first),
|
|
||||||
o->createIndex(lrow, 2, last));
|
|
||||||
},
|
|
||||||
[](Processes* o) {
|
|
||||||
o->beginResetModel();
|
|
||||||
},
|
|
||||||
[](Processes* o) {
|
|
||||||
o->endResetModel();
|
|
||||||
},
|
|
||||||
[](Processes* o, option<quintptr> id, int first, int last) {
|
|
||||||
if (id.some) {
|
|
||||||
int row = processes_row(o->m_d, id.value);
|
|
||||||
o->beginInsertRows(o->createIndex(row, 0, id.value), first, last);
|
|
||||||
} else {
|
|
||||||
o->beginInsertRows(QModelIndex(), first, last);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[](Processes* o) {
|
|
||||||
o->endInsertRows();
|
|
||||||
},
|
|
||||||
[](Processes* o, option<quintptr> id, int first, int last) {
|
|
||||||
if (id.some) {
|
|
||||||
int row = processes_row(o->m_d, id.value);
|
|
||||||
o->beginRemoveRows(o->createIndex(row, 0, id.value), first, last);
|
|
||||||
} else {
|
|
||||||
o->beginRemoveRows(QModelIndex(), first, last);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[](Processes* o) {
|
|
||||||
o->endRemoveRows();
|
|
||||||
}
|
|
||||||
)),
|
|
||||||
m_ownsPrivate(true)
|
|
||||||
{
|
|
||||||
connect(this, &Processes::newDataReady, this, [this](const QModelIndex& i) {
|
|
||||||
fetchMore(i);
|
|
||||||
}, Qt::QueuedConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
Processes::~Processes() {
|
|
||||||
if (m_ownsPrivate) {
|
|
||||||
processes_free(m_d);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bool Processes::active() const
|
|
||||||
{
|
|
||||||
return processes_active_get(m_d);
|
|
||||||
}
|
|
||||||
void Processes::setActive(bool v) {
|
|
||||||
processes_active_set(m_d, v);
|
|
||||||
}
|
|
|
@ -1,44 +0,0 @@
|
||||||
/* generated by rust_qt_binding_generator */
|
|
||||||
#ifndef PROCESSES_H
|
|
||||||
#define PROCESSES_H
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QAbstractItemModel>
|
|
||||||
|
|
||||||
class Processes;
|
|
||||||
|
|
||||||
class Processes : public QAbstractItemModel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
class Private;
|
|
||||||
private:
|
|
||||||
Private * m_d;
|
|
||||||
bool m_ownsPrivate;
|
|
||||||
Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged FINAL)
|
|
||||||
explicit Processes(bool owned, QObject *parent);
|
|
||||||
public:
|
|
||||||
explicit Processes(QObject *parent = nullptr);
|
|
||||||
~Processes();
|
|
||||||
bool active() const;
|
|
||||||
void setActive(bool v);
|
|
||||||
|
|
||||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
|
||||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
|
||||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
|
|
||||||
QModelIndex parent(const QModelIndex &index) const override;
|
|
||||||
bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
|
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
||||||
bool canFetchMore(const QModelIndex &parent) const override;
|
|
||||||
void fetchMore(const QModelIndex &parent) override;
|
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
|
||||||
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
|
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
|
||||||
signals:
|
|
||||||
// new data is ready to be made available to the model with fetchMore()
|
|
||||||
void newDataReady(const QModelIndex &parent) const;
|
|
||||||
signals:
|
|
||||||
void activeChanged();
|
|
||||||
};
|
|
||||||
#endif // PROCESSES_H
|
|
|
@ -1,241 +0,0 @@
|
||||||
/* generated by rust_qt_binding_generator */
|
|
||||||
#include "TimeSeries.h"
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
template <typename T>
|
|
||||||
struct option {
|
|
||||||
public:
|
|
||||||
T value;
|
|
||||||
bool some;
|
|
||||||
operator QVariant() const {
|
|
||||||
if (some) {
|
|
||||||
return QVariant(value);
|
|
||||||
}
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
struct qbytearray_t {
|
|
||||||
private:
|
|
||||||
const char* data;
|
|
||||||
int len;
|
|
||||||
public:
|
|
||||||
qbytearray_t(const QByteArray& v):
|
|
||||||
data(v.data()),
|
|
||||||
len(v.size()) {
|
|
||||||
}
|
|
||||||
operator QByteArray() const {
|
|
||||||
return QByteArray(data, len);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
struct qstring_t {
|
|
||||||
private:
|
|
||||||
const void* data;
|
|
||||||
int len;
|
|
||||||
public:
|
|
||||||
qstring_t(const QString& v):
|
|
||||||
data(static_cast<const void*>(v.utf16())),
|
|
||||||
len(v.size()) {
|
|
||||||
}
|
|
||||||
operator QString() const {
|
|
||||||
return QString::fromUtf8(static_cast<const char*>(data), len);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
struct qmodelindex_t {
|
|
||||||
int row;
|
|
||||||
quintptr id;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
typedef void (*qstring_set)(QString*, qstring_t*);
|
|
||||||
void set_qstring(QString* v, qstring_t* val) {
|
|
||||||
*v = *val;
|
|
||||||
}
|
|
||||||
typedef void (*qbytearray_set)(QByteArray*, qbytearray_t*);
|
|
||||||
void set_qbytearray(QByteArray* v, qbytearray_t* val) {
|
|
||||||
*v = *val;
|
|
||||||
}
|
|
||||||
extern "C" {
|
|
||||||
uint time_series_data_input(const TimeSeries::Private*, int);
|
|
||||||
bool time_series_set_data_input(TimeSeries::Private*, int, uint);
|
|
||||||
uint time_series_data_result(const TimeSeries::Private*, int);
|
|
||||||
bool time_series_set_data_result(TimeSeries::Private*, int, uint);
|
|
||||||
void time_series_sort(TimeSeries::Private*, unsigned char column, Qt::SortOrder order = Qt::AscendingOrder);
|
|
||||||
|
|
||||||
int time_series_row_count(const TimeSeries::Private*);
|
|
||||||
bool time_series_can_fetch_more(const TimeSeries::Private*);
|
|
||||||
void time_series_fetch_more(TimeSeries::Private*);
|
|
||||||
}
|
|
||||||
int TimeSeries::columnCount(const QModelIndex &parent) const
|
|
||||||
{
|
|
||||||
return (parent.isValid()) ? 0 : 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TimeSeries::hasChildren(const QModelIndex &parent) const
|
|
||||||
{
|
|
||||||
return rowCount(parent) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int TimeSeries::rowCount(const QModelIndex &parent) const
|
|
||||||
{
|
|
||||||
return (parent.isValid()) ? 0 : time_series_row_count(m_d);
|
|
||||||
}
|
|
||||||
|
|
||||||
QModelIndex TimeSeries::index(int row, int column, const QModelIndex &parent) const
|
|
||||||
{
|
|
||||||
if (!parent.isValid() && row >= 0 && row < rowCount(parent) && column >= 0 && column < 2) {
|
|
||||||
return createIndex(row, column, (quintptr)row);
|
|
||||||
}
|
|
||||||
return QModelIndex();
|
|
||||||
}
|
|
||||||
|
|
||||||
QModelIndex TimeSeries::parent(const QModelIndex &) const
|
|
||||||
{
|
|
||||||
return QModelIndex();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TimeSeries::canFetchMore(const QModelIndex &parent) const
|
|
||||||
{
|
|
||||||
return (parent.isValid()) ? 0 : time_series_can_fetch_more(m_d);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TimeSeries::fetchMore(const QModelIndex &parent)
|
|
||||||
{
|
|
||||||
if (!parent.isValid()) {
|
|
||||||
time_series_fetch_more(m_d);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TimeSeries::sort(int column, Qt::SortOrder order)
|
|
||||||
{
|
|
||||||
time_series_sort(m_d, column, order);
|
|
||||||
}
|
|
||||||
Qt::ItemFlags TimeSeries::flags(const QModelIndex &i) const
|
|
||||||
{
|
|
||||||
auto flags = QAbstractItemModel::flags(i);
|
|
||||||
if (i.column() == 0) {
|
|
||||||
flags |= Qt::ItemIsEditable;
|
|
||||||
}
|
|
||||||
if (i.column() == 1) {
|
|
||||||
flags |= Qt::ItemIsEditable;
|
|
||||||
}
|
|
||||||
return flags;
|
|
||||||
}
|
|
||||||
QVariant TimeSeries::data(const QModelIndex &index, int role) const
|
|
||||||
{
|
|
||||||
QVariant v;
|
|
||||||
Q_ASSERT(rowCount(index.parent()) > index.row());
|
|
||||||
QString s;
|
|
||||||
QByteArray b;
|
|
||||||
switch (index.column()) {
|
|
||||||
case 0:
|
|
||||||
switch (role) {
|
|
||||||
case Qt::DisplayRole:
|
|
||||||
case Qt::EditRole:
|
|
||||||
case Qt::UserRole + 0:
|
|
||||||
v = time_series_data_input(m_d, index.row());
|
|
||||||
break;
|
|
||||||
case Qt::UserRole + 1:
|
|
||||||
v = time_series_data_result(m_d, index.row());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
switch (role) {
|
|
||||||
case Qt::DisplayRole:
|
|
||||||
case Qt::EditRole:
|
|
||||||
case Qt::UserRole + 1:
|
|
||||||
v = time_series_data_result(m_d, index.row());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
QHash<int, QByteArray> TimeSeries::roleNames() const {
|
|
||||||
QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
|
|
||||||
names.insert(Qt::UserRole + 0, "input");
|
|
||||||
names.insert(Qt::UserRole + 1, "result");
|
|
||||||
return names;
|
|
||||||
}
|
|
||||||
bool TimeSeries::setData(const QModelIndex &index, const QVariant &value, int role)
|
|
||||||
{
|
|
||||||
bool set = false;
|
|
||||||
if (index.column() == 0) {
|
|
||||||
if (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole + 0) {
|
|
||||||
set = time_series_set_data_input(m_d, index.row(), value.value<quint32>());
|
|
||||||
}
|
|
||||||
if (role == Qt::UserRole + 1) {
|
|
||||||
set = time_series_set_data_result(m_d, index.row(), value.value<quint32>());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (index.column() == 1) {
|
|
||||||
if (role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::UserRole + 1) {
|
|
||||||
set = time_series_set_data_result(m_d, index.row(), value.value<quint32>());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (set) {
|
|
||||||
emit dataChanged(index, index, QVector<int>() << role);
|
|
||||||
}
|
|
||||||
return set;
|
|
||||||
}
|
|
||||||
extern "C" {
|
|
||||||
TimeSeries::Private* time_series_new(TimeSeries*,
|
|
||||||
void (*)(const TimeSeries*),
|
|
||||||
void (*)(TimeSeries*, quintptr, quintptr),
|
|
||||||
void (*)(TimeSeries*),
|
|
||||||
void (*)(TimeSeries*),
|
|
||||||
void (*)(TimeSeries*, int, int),
|
|
||||||
void (*)(TimeSeries*),
|
|
||||||
void (*)(TimeSeries*, int, int),
|
|
||||||
void (*)(TimeSeries*));
|
|
||||||
void time_series_free(TimeSeries::Private*);
|
|
||||||
};
|
|
||||||
|
|
||||||
TimeSeries::TimeSeries(bool /*owned*/, QObject *parent):
|
|
||||||
QAbstractItemModel(parent),
|
|
||||||
m_d(0),
|
|
||||||
m_ownsPrivate(false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
TimeSeries::TimeSeries(QObject *parent):
|
|
||||||
QAbstractItemModel(parent),
|
|
||||||
m_d(time_series_new(this,
|
|
||||||
[](const TimeSeries* o) {
|
|
||||||
emit o->newDataReady(QModelIndex());
|
|
||||||
},
|
|
||||||
[](TimeSeries* o, quintptr first, quintptr last) {
|
|
||||||
o->dataChanged(o->createIndex(first, 0, first),
|
|
||||||
o->createIndex(last, 1, last));
|
|
||||||
},
|
|
||||||
[](TimeSeries* o) {
|
|
||||||
o->beginResetModel();
|
|
||||||
},
|
|
||||||
[](TimeSeries* o) {
|
|
||||||
o->endResetModel();
|
|
||||||
},
|
|
||||||
[](TimeSeries* o, int first, int last) {
|
|
||||||
o->beginInsertRows(QModelIndex(), first, last);
|
|
||||||
},
|
|
||||||
[](TimeSeries* o) {
|
|
||||||
o->endInsertRows();
|
|
||||||
},
|
|
||||||
[](TimeSeries* o, int first, int last) {
|
|
||||||
o->beginRemoveRows(QModelIndex(), first, last);
|
|
||||||
},
|
|
||||||
[](TimeSeries* o) {
|
|
||||||
o->endRemoveRows();
|
|
||||||
}
|
|
||||||
)),
|
|
||||||
m_ownsPrivate(true)
|
|
||||||
{
|
|
||||||
connect(this, &TimeSeries::newDataReady, this, [this](const QModelIndex& i) {
|
|
||||||
fetchMore(i);
|
|
||||||
}, Qt::QueuedConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
TimeSeries::~TimeSeries() {
|
|
||||||
if (m_ownsPrivate) {
|
|
||||||
time_series_free(m_d);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
/* generated by rust_qt_binding_generator */
|
|
||||||
#ifndef TIMESERIES_H
|
|
||||||
#define TIMESERIES_H
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QAbstractItemModel>
|
|
||||||
|
|
||||||
class TimeSeries;
|
|
||||||
|
|
||||||
class TimeSeries : public QAbstractItemModel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
class Private;
|
|
||||||
private:
|
|
||||||
Private * m_d;
|
|
||||||
bool m_ownsPrivate;
|
|
||||||
explicit TimeSeries(bool owned, QObject *parent);
|
|
||||||
public:
|
|
||||||
explicit TimeSeries(QObject *parent = nullptr);
|
|
||||||
~TimeSeries();
|
|
||||||
|
|
||||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
|
||||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
|
||||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
|
|
||||||
QModelIndex parent(const QModelIndex &index) const override;
|
|
||||||
bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
|
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
||||||
bool canFetchMore(const QModelIndex &parent) const override;
|
|
||||||
void fetchMore(const QModelIndex &parent) override;
|
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
|
||||||
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
|
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
|
||||||
signals:
|
|
||||||
// new data is ready to be made available to the model with fetchMore()
|
|
||||||
void newDataReady(const QModelIndex &parent) const;
|
|
||||||
signals:
|
|
||||||
};
|
|
||||||
#endif // TIMESERIES_H
|
|
|
@ -1,323 +0,0 @@
|
||||||
/* generated by rust_qt_binding_generator */
|
|
||||||
#include "Tree.h"
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
template <typename T>
|
|
||||||
struct option {
|
|
||||||
public:
|
|
||||||
T value;
|
|
||||||
bool some;
|
|
||||||
operator QVariant() const {
|
|
||||||
if (some) {
|
|
||||||
return QVariant(value);
|
|
||||||
}
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
struct qbytearray_t {
|
|
||||||
private:
|
|
||||||
const char* data;
|
|
||||||
int len;
|
|
||||||
public:
|
|
||||||
qbytearray_t(const QByteArray& v):
|
|
||||||
data(v.data()),
|
|
||||||
len(v.size()) {
|
|
||||||
}
|
|
||||||
operator QByteArray() const {
|
|
||||||
return QByteArray(data, len);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
struct qstring_t {
|
|
||||||
private:
|
|
||||||
const void* data;
|
|
||||||
int len;
|
|
||||||
public:
|
|
||||||
qstring_t(const QString& v):
|
|
||||||
data(static_cast<const void*>(v.utf16())),
|
|
||||||
len(v.size()) {
|
|
||||||
}
|
|
||||||
operator QString() const {
|
|
||||||
return QString::fromUtf8(static_cast<const char*>(data), len);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
struct qmodelindex_t {
|
|
||||||
int row;
|
|
||||||
quintptr id;
|
|
||||||
};
|
|
||||||
inline void treePathChanged(Tree* o)
|
|
||||||
{
|
|
||||||
emit o->pathChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
typedef void (*qstring_set)(QString*, qstring_t*);
|
|
||||||
void set_qstring(QString* v, qstring_t* val) {
|
|
||||||
*v = *val;
|
|
||||||
}
|
|
||||||
typedef void (*qbytearray_set)(QByteArray*, qbytearray_t*);
|
|
||||||
void set_qbytearray(QByteArray* v, qbytearray_t* val) {
|
|
||||||
*v = *val;
|
|
||||||
}
|
|
||||||
extern "C" {
|
|
||||||
void tree_data_file_icon(const Tree::Private*, quintptr, QByteArray*, qbytearray_set);
|
|
||||||
void tree_data_file_name(const Tree::Private*, quintptr, QString*, qstring_set);
|
|
||||||
void tree_data_file_path(const Tree::Private*, quintptr, QString*, qstring_set);
|
|
||||||
qint32 tree_data_file_permissions(const Tree::Private*, quintptr);
|
|
||||||
option<quint64> tree_data_file_size(const Tree::Private*, quintptr);
|
|
||||||
qint32 tree_data_file_type(const Tree::Private*, quintptr);
|
|
||||||
void tree_sort(Tree::Private*, unsigned char column, Qt::SortOrder order = Qt::AscendingOrder);
|
|
||||||
|
|
||||||
int tree_row_count(const Tree::Private*, quintptr, bool);
|
|
||||||
bool tree_can_fetch_more(const Tree::Private*, quintptr, bool);
|
|
||||||
void tree_fetch_more(Tree::Private*, quintptr, bool);
|
|
||||||
quintptr tree_index(const Tree::Private*, quintptr, bool, int);
|
|
||||||
qmodelindex_t tree_parent(const Tree::Private*, quintptr);
|
|
||||||
int tree_row(const Tree::Private*, quintptr);
|
|
||||||
}
|
|
||||||
int Tree::columnCount(const QModelIndex &) const
|
|
||||||
{
|
|
||||||
return 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Tree::hasChildren(const QModelIndex &parent) const
|
|
||||||
{
|
|
||||||
return rowCount(parent) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Tree::rowCount(const QModelIndex &parent) const
|
|
||||||
{
|
|
||||||
if (parent.isValid() && parent.column() != 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return tree_row_count(m_d, parent.internalId(), parent.isValid());
|
|
||||||
}
|
|
||||||
|
|
||||||
QModelIndex Tree::index(int row, int column, const QModelIndex &parent) const
|
|
||||||
{
|
|
||||||
if (row < 0 || column < 0 || column >= 5) {
|
|
||||||
return QModelIndex();
|
|
||||||
}
|
|
||||||
if (parent.isValid() && parent.column() != 0) {
|
|
||||||
return QModelIndex();
|
|
||||||
}
|
|
||||||
if (row >= rowCount(parent)) {
|
|
||||||
return QModelIndex();
|
|
||||||
}
|
|
||||||
const quintptr id = tree_index(m_d, parent.internalId(), parent.isValid(), row);
|
|
||||||
return createIndex(row, column, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
QModelIndex Tree::parent(const QModelIndex &index) const
|
|
||||||
{
|
|
||||||
if (!index.isValid()) {
|
|
||||||
return QModelIndex();
|
|
||||||
}
|
|
||||||
const qmodelindex_t parent = tree_parent(m_d, index.internalId());
|
|
||||||
return parent.row >= 0 ?createIndex(parent.row, 0, parent.id) :QModelIndex();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Tree::canFetchMore(const QModelIndex &parent) const
|
|
||||||
{
|
|
||||||
if (parent.isValid() && parent.column() != 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return tree_can_fetch_more(m_d, parent.internalId(), parent.isValid());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Tree::fetchMore(const QModelIndex &parent)
|
|
||||||
{
|
|
||||||
tree_fetch_more(m_d, parent.internalId(), parent.isValid());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Tree::sort(int column, Qt::SortOrder order)
|
|
||||||
{
|
|
||||||
tree_sort(m_d, column, order);
|
|
||||||
}
|
|
||||||
Qt::ItemFlags Tree::flags(const QModelIndex &i) const
|
|
||||||
{
|
|
||||||
auto flags = QAbstractItemModel::flags(i);
|
|
||||||
return flags;
|
|
||||||
}
|
|
||||||
QVariant Tree::data(const QModelIndex &index, int role) const
|
|
||||||
{
|
|
||||||
QVariant v;
|
|
||||||
Q_ASSERT(rowCount(index.parent()) > index.row());
|
|
||||||
QString s;
|
|
||||||
QByteArray b;
|
|
||||||
switch (index.column()) {
|
|
||||||
case 0:
|
|
||||||
switch (role) {
|
|
||||||
case Qt::DecorationRole:
|
|
||||||
case Qt::UserRole + 0:
|
|
||||||
tree_data_file_icon(m_d, index.internalId(), &b, set_qbytearray);
|
|
||||||
if (!b.isNull()) v.setValue<QByteArray>(b);
|
|
||||||
break;
|
|
||||||
case Qt::DisplayRole:
|
|
||||||
case Qt::UserRole + 1:
|
|
||||||
tree_data_file_name(m_d, index.internalId(), &s, set_qstring);
|
|
||||||
if (!s.isNull()) v.setValue<QString>(s);
|
|
||||||
break;
|
|
||||||
case Qt::UserRole + 2:
|
|
||||||
tree_data_file_path(m_d, index.internalId(), &s, set_qstring);
|
|
||||||
if (!s.isNull()) v.setValue<QString>(s);
|
|
||||||
break;
|
|
||||||
case Qt::UserRole + 3:
|
|
||||||
v = tree_data_file_permissions(m_d, index.internalId());
|
|
||||||
break;
|
|
||||||
case Qt::UserRole + 4:
|
|
||||||
v = tree_data_file_size(m_d, index.internalId());
|
|
||||||
break;
|
|
||||||
case Qt::UserRole + 5:
|
|
||||||
v = tree_data_file_type(m_d, index.internalId());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
switch (role) {
|
|
||||||
case Qt::DisplayRole:
|
|
||||||
case Qt::UserRole + 4:
|
|
||||||
v = tree_data_file_size(m_d, index.internalId());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
switch (role) {
|
|
||||||
case Qt::DisplayRole:
|
|
||||||
case Qt::UserRole + 2:
|
|
||||||
tree_data_file_path(m_d, index.internalId(), &s, set_qstring);
|
|
||||||
if (!s.isNull()) v.setValue<QString>(s);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
switch (role) {
|
|
||||||
case Qt::DisplayRole:
|
|
||||||
case Qt::UserRole + 3:
|
|
||||||
v = tree_data_file_permissions(m_d, index.internalId());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
switch (role) {
|
|
||||||
case Qt::DisplayRole:
|
|
||||||
case Qt::UserRole + 5:
|
|
||||||
v = tree_data_file_type(m_d, index.internalId());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
QHash<int, QByteArray> Tree::roleNames() const {
|
|
||||||
QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
|
|
||||||
names.insert(Qt::UserRole + 0, "fileIcon");
|
|
||||||
names.insert(Qt::UserRole + 1, "fileName");
|
|
||||||
names.insert(Qt::UserRole + 2, "filePath");
|
|
||||||
names.insert(Qt::UserRole + 3, "filePermissions");
|
|
||||||
names.insert(Qt::UserRole + 4, "fileSize");
|
|
||||||
names.insert(Qt::UserRole + 5, "fileType");
|
|
||||||
return names;
|
|
||||||
}
|
|
||||||
bool Tree::setData(const QModelIndex &index, const QVariant &value, int role)
|
|
||||||
{
|
|
||||||
bool set = false;
|
|
||||||
if (set) {
|
|
||||||
emit dataChanged(index, index, QVector<int>() << role);
|
|
||||||
}
|
|
||||||
return set;
|
|
||||||
}
|
|
||||||
extern "C" {
|
|
||||||
Tree::Private* tree_new(Tree*, void (*)(Tree*),
|
|
||||||
void (*)(const Tree*, quintptr, bool),
|
|
||||||
void (*)(Tree*, quintptr, quintptr),
|
|
||||||
void (*)(Tree*),
|
|
||||||
void (*)(Tree*),
|
|
||||||
void (*)(Tree*, option<quintptr>, int, int),
|
|
||||||
void (*)(Tree*),
|
|
||||||
void (*)(Tree*, option<quintptr>, int, int),
|
|
||||||
void (*)(Tree*));
|
|
||||||
void tree_free(Tree::Private*);
|
|
||||||
void tree_path_get(const Tree::Private*, QString*, qstring_set);
|
|
||||||
void tree_path_set(Tree::Private*, qstring_t);
|
|
||||||
void tree_path_set_none(Tree::Private*);
|
|
||||||
};
|
|
||||||
|
|
||||||
Tree::Tree(bool /*owned*/, QObject *parent):
|
|
||||||
QAbstractItemModel(parent),
|
|
||||||
m_d(0),
|
|
||||||
m_ownsPrivate(false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Tree::Tree(QObject *parent):
|
|
||||||
QAbstractItemModel(parent),
|
|
||||||
m_d(tree_new(this,
|
|
||||||
treePathChanged,
|
|
||||||
[](const Tree* o, quintptr id, bool valid) {
|
|
||||||
if (valid) {
|
|
||||||
int row = tree_row(o->m_d, id);
|
|
||||||
emit o->newDataReady(o->createIndex(row, 0, id));
|
|
||||||
} else {
|
|
||||||
emit o->newDataReady(QModelIndex());
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[](Tree* o, quintptr first, quintptr last) {
|
|
||||||
quintptr frow = tree_row(o->m_d, first);
|
|
||||||
quintptr lrow = tree_row(o->m_d, first);
|
|
||||||
o->dataChanged(o->createIndex(frow, 0, first),
|
|
||||||
o->createIndex(lrow, 4, last));
|
|
||||||
},
|
|
||||||
[](Tree* o) {
|
|
||||||
o->beginResetModel();
|
|
||||||
},
|
|
||||||
[](Tree* o) {
|
|
||||||
o->endResetModel();
|
|
||||||
},
|
|
||||||
[](Tree* o, option<quintptr> id, int first, int last) {
|
|
||||||
if (id.some) {
|
|
||||||
int row = tree_row(o->m_d, id.value);
|
|
||||||
o->beginInsertRows(o->createIndex(row, 0, id.value), first, last);
|
|
||||||
} else {
|
|
||||||
o->beginInsertRows(QModelIndex(), first, last);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[](Tree* o) {
|
|
||||||
o->endInsertRows();
|
|
||||||
},
|
|
||||||
[](Tree* o, option<quintptr> id, int first, int last) {
|
|
||||||
if (id.some) {
|
|
||||||
int row = tree_row(o->m_d, id.value);
|
|
||||||
o->beginRemoveRows(o->createIndex(row, 0, id.value), first, last);
|
|
||||||
} else {
|
|
||||||
o->beginRemoveRows(QModelIndex(), first, last);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
[](Tree* o) {
|
|
||||||
o->endRemoveRows();
|
|
||||||
}
|
|
||||||
)),
|
|
||||||
m_ownsPrivate(true)
|
|
||||||
{
|
|
||||||
connect(this, &Tree::newDataReady, this, [this](const QModelIndex& i) {
|
|
||||||
fetchMore(i);
|
|
||||||
}, Qt::QueuedConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
Tree::~Tree() {
|
|
||||||
if (m_ownsPrivate) {
|
|
||||||
tree_free(m_d);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
QString Tree::path() const
|
|
||||||
{
|
|
||||||
QString v;
|
|
||||||
tree_path_get(m_d, &v, set_qstring);
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
void Tree::setPath(const QString& v) {
|
|
||||||
if (v.isNull()) {
|
|
||||||
tree_path_set_none(m_d);
|
|
||||||
} else {
|
|
||||||
tree_path_set(m_d, v);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,44 +0,0 @@
|
||||||
/* generated by rust_qt_binding_generator */
|
|
||||||
#ifndef TREE_H
|
|
||||||
#define TREE_H
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QAbstractItemModel>
|
|
||||||
|
|
||||||
class Tree;
|
|
||||||
|
|
||||||
class Tree : public QAbstractItemModel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
class Private;
|
|
||||||
private:
|
|
||||||
Private * m_d;
|
|
||||||
bool m_ownsPrivate;
|
|
||||||
Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged FINAL)
|
|
||||||
explicit Tree(bool owned, QObject *parent);
|
|
||||||
public:
|
|
||||||
explicit Tree(QObject *parent = nullptr);
|
|
||||||
~Tree();
|
|
||||||
QString path() const;
|
|
||||||
void setPath(const QString& v);
|
|
||||||
|
|
||||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
|
||||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
|
||||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
|
|
||||||
QModelIndex parent(const QModelIndex &index) const override;
|
|
||||||
bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
|
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
||||||
bool canFetchMore(const QModelIndex &parent) const override;
|
|
||||||
void fetchMore(const QModelIndex &parent) override;
|
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
|
||||||
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
|
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
|
||||||
signals:
|
|
||||||
// new data is ready to be made available to the model with fetchMore()
|
|
||||||
void newDataReady(const QModelIndex &parent) const;
|
|
||||||
signals:
|
|
||||||
void pathChanged();
|
|
||||||
};
|
|
||||||
#endif // TREE_H
|
|
|
@ -1,7 +1,4 @@
|
||||||
#include "Tree.h"
|
#include "Bindings.h"
|
||||||
#include "Fibonacci.h"
|
|
||||||
#include "TimeSeries.h"
|
|
||||||
#include "Processes.h"
|
|
||||||
#include "SortedModel.h"
|
#include "SortedModel.h"
|
||||||
|
|
||||||
#ifdef QT_CHARTS_LIB
|
#ifdef QT_CHARTS_LIB
|
||||||
|
@ -39,15 +36,11 @@
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
struct Models {
|
struct Model {
|
||||||
QStringListModel styles;
|
QStringListModel styles;
|
||||||
Fibonacci fibonacci;
|
Demo demo;
|
||||||
FibonacciList fibonacciList;
|
|
||||||
Tree fileSystem;
|
|
||||||
SortedModel sortedFileSystem;
|
SortedModel sortedFileSystem;
|
||||||
Processes processes;
|
|
||||||
SortedModel sortedProcesses;
|
SortedModel sortedProcesses;
|
||||||
TimeSeries timeSeries;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void setStyle(QWidget* w, QStyle* style) {
|
void setStyle(QWidget* w, QStyle* style) {
|
||||||
|
@ -80,20 +73,18 @@ void copyWindowGeometry(QWidget* w, QQmlContext* c) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void createQtQuick(const QString& name, const QString& qml, Models* models,
|
void createQtQuick(const QString& name, const QString& qml, Model* model,
|
||||||
QWidget* widgets, const QString& initialTab) {
|
QWidget* widgets, const QString& initialTab) {
|
||||||
QQmlApplicationEngine* engine = new QQmlApplicationEngine();
|
QQmlApplicationEngine* engine = new QQmlApplicationEngine();
|
||||||
QQmlContext* c = engine->rootContext();
|
QQmlContext* c = engine->rootContext();
|
||||||
c->setContextProperty("styles", &models->styles);
|
c->setContextProperty("styles", &model->styles);
|
||||||
c->setContextProperty("fibonacci", &models->fibonacci);
|
c->setContextProperty("demo", &model->demo);
|
||||||
c->setContextProperty("fibonacciList", &models->fibonacciList);
|
c->setContextProperty("sortedFileSystem", &model->sortedFileSystem);
|
||||||
c->setContextProperty("sortedFileSystem", &models->sortedFileSystem);
|
c->setContextProperty("processes", &model->sortedProcesses);
|
||||||
c->setContextProperty("processes", &models->sortedProcesses);
|
|
||||||
c->setContextProperty("timeSeries", &models->timeSeries);
|
|
||||||
|
|
||||||
c->setContextProperty("widgets", widgets);
|
c->setContextProperty("widgets", widgets);
|
||||||
c->setContextProperty("qtquickIndex",
|
c->setContextProperty("qtquickIndex",
|
||||||
QVariant(models->styles.stringList().indexOf(name)));
|
QVariant(model->styles.stringList().indexOf(name)));
|
||||||
c->setContextProperty("initialTab", initialTab);
|
c->setContextProperty("initialTab", initialTab);
|
||||||
copyWindowGeometry(widgets, engine->rootContext());
|
copyWindowGeometry(widgets, engine->rootContext());
|
||||||
engine->load(QUrl(qml));
|
engine->load(QUrl(qml));
|
||||||
|
@ -101,9 +92,9 @@ void createQtQuick(const QString& name, const QString& qml, Models* models,
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QComboBox* createStyleComboBox(Models* models) {
|
QComboBox* createStyleComboBox(Model* model) {
|
||||||
QComboBox* box = new QComboBox();
|
QComboBox* box = new QComboBox();
|
||||||
box->setModel(&models->styles);
|
box->setModel(&model->styles);
|
||||||
auto styles = QStyleFactory::keys();
|
auto styles = QStyleFactory::keys();
|
||||||
QString currentStyle = QApplication::style()->objectName().toLower();
|
QString currentStyle = QApplication::style()->objectName().toLower();
|
||||||
for (auto v: styles) {
|
for (auto v: styles) {
|
||||||
|
@ -121,10 +112,10 @@ QComboBox* createStyleComboBox(Models* models) {
|
||||||
return box;
|
return box;
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget* createStyleTab(Models* models, QWidget* tabs, QComboBox* box,
|
QWidget* createStyleTab(Model* model, QWidget* tabs, QComboBox* box,
|
||||||
const QString& initialTab) {
|
const QString& initialTab) {
|
||||||
QRect windowRect;
|
QRect windowRect;
|
||||||
auto f = [windowRect, box, tabs, models, initialTab](const QString &text) mutable {
|
auto f = [windowRect, box, tabs, model, initialTab](const QString &text) mutable {
|
||||||
QWindow* window = getWindow(tabs);
|
QWindow* window = getWindow(tabs);
|
||||||
bool visible = tabs->isVisible();
|
bool visible = tabs->isVisible();
|
||||||
if (text.startsWith("QWidgets ")) {
|
if (text.startsWith("QWidgets ")) {
|
||||||
|
@ -148,16 +139,16 @@ QWidget* createStyleTab(Models* models, QWidget* tabs, QComboBox* box,
|
||||||
#ifdef QTQUICKCONTROLS2
|
#ifdef QTQUICKCONTROLS2
|
||||||
if (text == "QtQuick Controls 2") {
|
if (text == "QtQuick Controls 2") {
|
||||||
createQtQuick("QtQuick Controls 2", "qrc:///demo-qtquick2.qml",
|
createQtQuick("QtQuick Controls 2", "qrc:///demo-qtquick2.qml",
|
||||||
models, box, initialTab);
|
model, box, initialTab);
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
createQtQuick("QtQuick", "qrc:///demo.qml", models, box, initialTab);
|
createQtQuick("QtQuick", "qrc:///demo.qml", model, box, initialTab);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
box->connect(box, &QComboBox::currentTextChanged, box, f);
|
box->connect(box, &QComboBox::currentTextChanged, box, f);
|
||||||
|
|
||||||
QSvgWidget* logo = new QSvgWidget("/home/oever/src/rust_qt_binding_generator/logo.svg");
|
QSvgWidget* logo = new QSvgWidget(":/logo.svg");
|
||||||
logo->setFixedSize(logo->renderer()->defaultSize());
|
logo->setFixedSize(logo->renderer()->defaultSize());
|
||||||
|
|
||||||
QWidget* tab = new QWidget;
|
QWidget* tab = new QWidget;
|
||||||
|
@ -168,9 +159,9 @@ QWidget* createStyleTab(Models* models, QWidget* tabs, QComboBox* box,
|
||||||
return tab;
|
return tab;
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget* createObjectTab(Models* models) {
|
QWidget* createObjectTab(Model* model) {
|
||||||
QWidget* view = new QWidget;
|
QWidget* view = new QWidget;
|
||||||
Fibonacci* fibonacci = &models->fibonacci;
|
Fibonacci* fibonacci = model->demo.fibonacci();
|
||||||
|
|
||||||
QLineEdit* input = new QLineEdit;
|
QLineEdit* input = new QLineEdit;
|
||||||
input->setPlaceholderText("Your number");
|
input->setPlaceholderText("Your number");
|
||||||
|
@ -198,31 +189,31 @@ QWidget* createObjectTab(Models* models) {
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget* createListTab(Models* models) {
|
QWidget* createListTab(Model* model) {
|
||||||
QListView* view = new QListView();
|
QListView* view = new QListView();
|
||||||
view->setModel(&models->fibonacciList);
|
view->setModel(model->demo.fibonacciList());
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget* createTreeTab(Models* models) {
|
QWidget* createTreeTab(Model* model) {
|
||||||
QTreeView* view = new QTreeView();
|
QTreeView* view = new QTreeView();
|
||||||
view->setUniformRowHeights(true);
|
view->setUniformRowHeights(true);
|
||||||
view->setSortingEnabled(true);
|
view->setSortingEnabled(true);
|
||||||
view->setModel(&models->sortedFileSystem);
|
view->setModel(&model->sortedFileSystem);
|
||||||
auto root = models->sortedFileSystem.index(0, 0);
|
auto root = model->sortedFileSystem.index(0, 0);
|
||||||
view->expand(root);
|
view->expand(root);
|
||||||
view->sortByColumn(0, Qt::AscendingOrder);
|
view->sortByColumn(0, Qt::AscendingOrder);
|
||||||
view->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
view->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget* createProcessesTab(Models* models) {
|
QWidget* createProcessesTab(Model* model) {
|
||||||
QTreeView* view = new QTreeView();
|
QTreeView* view = new QTreeView();
|
||||||
view->setUniformRowHeights(true);
|
view->setUniformRowHeights(true);
|
||||||
view->setSortingEnabled(true);
|
view->setSortingEnabled(true);
|
||||||
view->setModel(&models->sortedProcesses);
|
view->setModel(&model->sortedProcesses);
|
||||||
// expand when the model is populated
|
// expand when the model is populated
|
||||||
view->connect(&models->sortedProcesses, &QAbstractItemModel::rowsInserted,
|
view->connect(&model->sortedProcesses, &QAbstractItemModel::rowsInserted,
|
||||||
view, [view](const QModelIndex& index) {
|
view, [view](const QModelIndex& index) {
|
||||||
if (!index.isValid()) {
|
if (!index.isValid()) {
|
||||||
view->expandAll();
|
view->expandAll();
|
||||||
|
@ -237,14 +228,14 @@ QWidget* createProcessesTab(Models* models) {
|
||||||
|
|
||||||
using namespace QtCharts;
|
using namespace QtCharts;
|
||||||
|
|
||||||
QWidget* createChartTab(Models* models) {
|
QWidget* createChartTab(Model* model) {
|
||||||
QLineSeries *series = new QLineSeries();
|
QLineSeries *series = new QLineSeries();
|
||||||
series->setName("Line 1");
|
series->setName("Line 1");
|
||||||
QVXYModelMapper *mapper = new QVXYModelMapper(series);
|
QVXYModelMapper *mapper = new QVXYModelMapper(series);
|
||||||
mapper->setXColumn(0);
|
mapper->setXColumn(0);
|
||||||
mapper->setYColumn(1);
|
mapper->setYColumn(1);
|
||||||
mapper->setSeries(series);
|
mapper->setSeries(series);
|
||||||
mapper->setModel(&models->timeSeries);
|
mapper->setModel(model->demo.timeSeries());
|
||||||
|
|
||||||
QChart* chart = new QChart;
|
QChart* chart = new QChart;
|
||||||
chart->addSeries(series);
|
chart->addSeries(series);
|
||||||
|
@ -263,7 +254,7 @@ QWidget* createChartTab(Models* models) {
|
||||||
|
|
||||||
QWidget* view = new QWidget;
|
QWidget* view = new QWidget;
|
||||||
QTableView* data = new QTableView;
|
QTableView* data = new QTableView;
|
||||||
data->setModel(&models->timeSeries);
|
data->setModel(model->demo.timeSeries());
|
||||||
QChartView *chartView = new QChartView(chart);
|
QChartView *chartView = new QChartView(chart);
|
||||||
|
|
||||||
QHBoxLayout *layout = new QHBoxLayout;
|
QHBoxLayout *layout = new QHBoxLayout;
|
||||||
|
@ -274,18 +265,22 @@ QWidget* createChartTab(Models* models) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void createWidgets(Models* models, const QString& initialStyle,
|
void createWidgets(Model* model, const QString& initialStyle,
|
||||||
const QString& initialTab) {
|
const QString& initialTab) {
|
||||||
QTabWidget* tabs = new QTabWidget();
|
QTabWidget* tabs = new QTabWidget();
|
||||||
|
|
||||||
QComboBox* box = createStyleComboBox(models);
|
QComboBox* box = createStyleComboBox(model);
|
||||||
tabs->addTab(createStyleTab(models, tabs, box, initialTab), "style");
|
tabs->addTab(createStyleTab(model, tabs, box, initialTab), "style");
|
||||||
tabs->addTab(createObjectTab(models), "object");
|
tabs->addTab(createObjectTab(model), "object");
|
||||||
tabs->addTab(createListTab(models), "list");
|
tabs->addTab(createListTab(model), "list");
|
||||||
tabs->addTab(createTreeTab(models), "tree");
|
tabs->addTab(createTreeTab(model), "tree");
|
||||||
tabs->addTab(createProcessesTab(models), "processes");
|
const int procTab = tabs->addTab(createProcessesTab(model), "processes");
|
||||||
|
tabs->connect(tabs, &QTabWidget::currentChanged, model->demo.processes(),
|
||||||
|
[model, procTab](int current) {
|
||||||
|
model->demo.processes()->setActive(current == procTab);
|
||||||
|
});
|
||||||
#ifdef QT_CHARTS_LIB
|
#ifdef QT_CHARTS_LIB
|
||||||
tabs->addTab(createChartTab(models), "chart");
|
tabs->addTab(createChartTab(model), "chart");
|
||||||
#endif
|
#endif
|
||||||
tabs->setMinimumSize(QSize(500, 500));
|
tabs->setMinimumSize(QSize(500, 500));
|
||||||
tabs->show();
|
tabs->show();
|
||||||
|
@ -326,14 +321,14 @@ int main (int argc, char *argv[])
|
||||||
parser.addOption(initialTabOption);
|
parser.addOption(initialTabOption);
|
||||||
parser.process(app);
|
parser.process(app);
|
||||||
|
|
||||||
Models models;
|
Model model;
|
||||||
models.fileSystem.setPath("/");
|
model.demo.fileSystemTree()->setPath("/");
|
||||||
models.sortedFileSystem.setSourceModel(&models.fileSystem);
|
model.sortedFileSystem.setSourceModel(model.demo.fileSystemTree());
|
||||||
models.sortedFileSystem.setDynamicSortFilter(true);
|
model.sortedFileSystem.setDynamicSortFilter(true);
|
||||||
models.sortedProcesses.setSourceModel(&models.processes);
|
model.sortedProcesses.setSourceModel(model.demo.processes());
|
||||||
models.sortedProcesses.setDynamicSortFilter(true);
|
model.sortedProcesses.setDynamicSortFilter(true);
|
||||||
|
|
||||||
createWidgets(&models, parser.value(initialStyleOption),
|
createWidgets(&model, parser.value(initialStyleOption),
|
||||||
parser.value(initialTabOption));
|
parser.value(initialTabOption));
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
|
|
77
src/cpp.cpp
77
src/cpp.cpp
|
@ -49,9 +49,14 @@ void writeHeaderItemModel(QTextStream& h) {
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||||
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
|
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||||
|
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);
|
||||||
signals:
|
signals:
|
||||||
// new data is ready to be made available to the model with fetchMore()
|
// new data is ready to be made available to the model with fetchMore()
|
||||||
void newDataReady(const QModelIndex &parent) const;
|
void newDataReady(const QModelIndex &parent) const;
|
||||||
|
private:
|
||||||
|
QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData;
|
||||||
|
void initHeaderData();
|
||||||
)");
|
)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,6 +275,23 @@ QVariant %1::data(const QModelIndex &index, int role) const
|
||||||
}
|
}
|
||||||
cpp << " return names;\n";
|
cpp << " return names;\n";
|
||||||
cpp << QString(R"(}
|
cpp << QString(R"(}
|
||||||
|
QVariant %1::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
|
{
|
||||||
|
if (orientation != Qt::Horizontal) {
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
return m_headerData.value(qMakePair(section, (Qt::ItemDataRole)role), role == Qt::DisplayRole ?QString::number(section + 1) :QVariant());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool %1::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)
|
||||||
|
{
|
||||||
|
if (orientation != Qt::Horizontal) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
m_headerData.insert(qMakePair(section, (Qt::ItemDataRole)role), value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool %1::setData(const QModelIndex &index, const QVariant &value, int role)
|
bool %1::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
{
|
{
|
||||||
)").arg(o.name);
|
)").arg(o.name);
|
||||||
|
@ -545,7 +567,7 @@ void initializeMembersEmpty(QTextStream& cpp, const Object& o, const Configurati
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void initializeMembersZero(QTextStream& cpp, const Object& o, const Configuration& conf)
|
void initializeMembersZero(QTextStream& cpp, const Object& o)
|
||||||
{
|
{
|
||||||
for (const Property& p: o.properties) {
|
for (const Property& p: o.properties) {
|
||||||
if (p.type.type == BindingType::Object) {
|
if (p.type.type == BindingType::Object) {
|
||||||
|
@ -559,14 +581,28 @@ void initializeMembers(QTextStream& cpp, const QString& prefix, const Object& o,
|
||||||
{
|
{
|
||||||
for (const Property& p: o.properties) {
|
for (const Property& p: o.properties) {
|
||||||
if (p.type.type == BindingType::Object) {
|
if (p.type.type == BindingType::Object) {
|
||||||
cpp << QString(" %1m_%2->m_d = %3_%2_get(%1m_d);\n")
|
cpp << QString(" %1m_%2->m_d = %3_%4_get(%1m_d);\n")
|
||||||
.arg(prefix, p.name, snakeCase(o.name));
|
.arg(prefix, p.name, snakeCase(o.name), snakeCase(p.name));
|
||||||
initializeMembers(cpp, "m_" + p.name + "->",
|
initializeMembers(cpp, "m_" + p.name + "->",
|
||||||
conf.findObject(p.type.name), conf);
|
conf.findObject(p.type.name), conf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void connect(QTextStream& cpp, const QString& d, const Object& o, const Configuration& conf) {
|
||||||
|
for (auto p: o.properties) {
|
||||||
|
if (p.type.type == BindingType::Object) {
|
||||||
|
connect(cpp, d + "->m_" + p.name, conf.findObject(p.type.name), conf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (o.type != ObjectType::Object) {
|
||||||
|
cpp << QString(R"( connect(%2, &%1::newDataReady, %2, [this](const QModelIndex& i) {
|
||||||
|
%2->fetchMore(i);
|
||||||
|
}, Qt::QueuedConnection);
|
||||||
|
)").arg(o.name, d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void writeCppObject(QTextStream& cpp, const Object& o, const Configuration& conf) {
|
void writeCppObject(QTextStream& cpp, const Object& o, const Configuration& conf) {
|
||||||
const QString lcname(snakeCase(o.name));
|
const QString lcname(snakeCase(o.name));
|
||||||
cpp << QString("%1::%1(bool /*owned*/, QObject *parent):\n %2(parent),")
|
cpp << QString("%1::%1(bool /*owned*/, QObject *parent):\n %2(parent),")
|
||||||
|
@ -577,19 +613,20 @@ void writeCppObject(QTextStream& cpp, const Object& o, const Configuration& conf
|
||||||
.arg(p.name, p.type.name);
|
.arg(p.name, p.type.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cpp << " m_d(0),\n m_ownsPrivate(false)\n{\n}\n\n";
|
cpp << " m_d(0),\n m_ownsPrivate(false)\n{\n";
|
||||||
cpp << QString("%1::%1(QObject *parent):\n %2(parent),")
|
if (o.type != ObjectType::Object) {
|
||||||
|
cpp << " initHeaderData();\n";
|
||||||
|
}
|
||||||
|
cpp << QString("}\n\n%1::%1(QObject *parent):\n %2(parent),")
|
||||||
.arg(o.name, baseType(o)) << endl;
|
.arg(o.name, baseType(o)) << endl;
|
||||||
initializeMembersZero(cpp, o, conf);
|
initializeMembersZero(cpp, o);
|
||||||
cpp << QString(" m_d(%1_new(this").arg(lcname);
|
cpp << QString(" m_d(%1_new(this").arg(lcname);
|
||||||
constructorArgs(cpp, "", o, conf);
|
constructorArgs(cpp, "", o, conf);
|
||||||
cpp << ")),\n m_ownsPrivate(true)\n{\n";
|
cpp << ")),\n m_ownsPrivate(true)\n{\n";
|
||||||
initializeMembers(cpp, "", o, conf);
|
initializeMembers(cpp, "", o, conf);
|
||||||
|
connect(cpp, "this", o, conf);
|
||||||
if (o.type != ObjectType::Object) {
|
if (o.type != ObjectType::Object) {
|
||||||
cpp << QString(R"( connect(this, &%1::newDataReady, this, [this](const QModelIndex& i) {
|
cpp << " initHeaderData();\n";
|
||||||
fetchMore(i);
|
|
||||||
}, Qt::QueuedConnection);
|
|
||||||
)").arg(o.name);
|
|
||||||
}
|
}
|
||||||
cpp << QString(R"(}
|
cpp << QString(R"(}
|
||||||
|
|
||||||
|
@ -600,18 +637,32 @@ void writeCppObject(QTextStream& cpp, const Object& o, const Configuration& conf
|
||||||
}
|
}
|
||||||
)").arg(o.name, lcname);
|
)").arg(o.name, lcname);
|
||||||
|
|
||||||
|
if (o.type != ObjectType::Object) {
|
||||||
|
cpp << QString("void %1::initHeaderData() {\n").arg(o.name);
|
||||||
|
|
||||||
|
for (int col = 0; col < o.columnCount; ++col) {
|
||||||
|
for (auto ip: o.itemProperties) {
|
||||||
|
auto roles = ip.roles.value(col);
|
||||||
|
if (roles.contains(Qt::DisplayRole)) {
|
||||||
|
cpp << QString(" m_headerData.insert(qMakePair(%1, Qt::DisplayRole), QVariant(\"%2\"));\n").arg(QString::number(col), ip.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cpp << " }\n";
|
||||||
|
}
|
||||||
|
|
||||||
for (const Property& p: o.properties) {
|
for (const Property& p: o.properties) {
|
||||||
const QString base = QString("%1_%2").arg(lcname, snakeCase(p.name));
|
const QString base = QString("%1_%2").arg(lcname, snakeCase(p.name));
|
||||||
if (p.type.type == BindingType::Object) {
|
if (p.type.type == BindingType::Object) {
|
||||||
cpp << QString(R"(const %3* %1::%2() const
|
cpp << QString(R"(const %3* %1::%2() const
|
||||||
{
|
{
|
||||||
return m_%4;
|
return m_%2;
|
||||||
}
|
}
|
||||||
%3* %1::%2()
|
%3* %1::%2()
|
||||||
{
|
{
|
||||||
return m_%4;
|
return m_%2;
|
||||||
}
|
}
|
||||||
)").arg(o.name, p.name, p.type.name, snakeCase(p.name));
|
)").arg(o.name, p.name, p.type.name);
|
||||||
} else if (p.type.isComplex()) {
|
} else if (p.type.isComplex()) {
|
||||||
cpp << QString("%3 %1::%2() const\n{\n").arg(o.name, p.name, p.type.name);
|
cpp << QString("%3 %1::%2() const\n{\n").arg(o.name, p.name, p.type.name);
|
||||||
cpp << " " << p.type.name << " v;\n";
|
cpp << " " << p.type.name << " v;\n";
|
||||||
|
|
57
src/rust.cpp
57
src/rust.cpp
|
@ -48,7 +48,7 @@ QString rustTypeInit(const T& p)
|
||||||
}
|
}
|
||||||
|
|
||||||
void rConstructorArgsDecl(QTextStream& r, const QString& name, const Object& o, const Configuration& conf) {
|
void rConstructorArgsDecl(QTextStream& r, const QString& name, const Object& o, const Configuration& conf) {
|
||||||
r << QString(" %2: *mut %1QObject").arg(o.name, name);
|
r << QString(" %2: *mut %1QObject").arg(o.name, snakeCase(name));
|
||||||
for (const Property& p: o.properties) {
|
for (const Property& p: o.properties) {
|
||||||
if (p.type.type == BindingType::Object) {
|
if (p.type.type == BindingType::Object) {
|
||||||
r << QString(",\n");
|
r << QString(",\n");
|
||||||
|
@ -59,11 +59,11 @@ void rConstructorArgsDecl(QTextStream& r, const QString& name, const Object& o,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (o.type == ObjectType::List) {
|
if (o.type == ObjectType::List) {
|
||||||
r << QString(",\n new_data_ready: fn(*const %1QObject)")
|
r << QString(",\n %2_new_data_ready: fn(*const %1QObject)")
|
||||||
.arg(o.name);
|
.arg(o.name, snakeCase(o.name));
|
||||||
} else if (o.type == ObjectType::UniformTree) {
|
} else if (o.type == ObjectType::UniformTree) {
|
||||||
r << QString(",\n 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);
|
.arg(o.name, snakeCase(o.name));
|
||||||
}
|
}
|
||||||
if (o.type != ObjectType::Object) {
|
if (o.type != ObjectType::Object) {
|
||||||
QString indexDecl;
|
QString indexDecl;
|
||||||
|
@ -71,13 +71,14 @@ void rConstructorArgsDecl(QTextStream& r, const QString& name, const Object& o,
|
||||||
indexDecl = " item: usize, valid: bool,";
|
indexDecl = " item: usize, valid: bool,";
|
||||||
}
|
}
|
||||||
r << QString(R"(,
|
r << QString(R"(,
|
||||||
data_changed: fn(*const %1QObject, usize, usize),
|
%3_data_changed: fn(*const %1QObject, usize, usize),
|
||||||
begin_reset_model: fn(*const %1QObject),
|
%3_begin_reset_model: fn(*const %1QObject),
|
||||||
end_reset_model: fn(*const %1QObject),
|
%3_end_reset_model: fn(*const %1QObject),
|
||||||
begin_insert_rows: fn(*const %1QObject,%2 usize, usize),
|
%3_begin_insert_rows: fn(*const %1QObject,%2 usize, usize),
|
||||||
end_insert_rows: fn(*const %1QObject),
|
%3_end_insert_rows: fn(*const %1QObject),
|
||||||
begin_remove_rows: fn(*const %1QObject,%2 usize, usize),
|
%3_begin_remove_rows: fn(*const %1QObject,%2 usize, usize),
|
||||||
end_remove_rows: fn(*const %1QObject))").arg(o.name, indexDecl);
|
%3_end_remove_rows: fn(*const %1QObject))").arg(o.name, indexDecl,
|
||||||
|
snakeCase(o.name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,13 +91,14 @@ void rConstructorArgs(QTextStream& r, const QString& name, const Object& o, cons
|
||||||
}
|
}
|
||||||
r << QString(R"( let %2_emit = %1Emitter {
|
r << QString(R"( let %2_emit = %1Emitter {
|
||||||
qobject: Arc::new(Mutex::new(%2)),
|
qobject: Arc::new(Mutex::new(%2)),
|
||||||
)").arg(o.name, name);
|
)").arg(o.name, snakeCase(name));
|
||||||
for (const Property& p: o.properties) {
|
for (const Property& p: o.properties) {
|
||||||
if (p.type.type == BindingType::Object) continue;
|
if (p.type.type == BindingType::Object) continue;
|
||||||
r << QString(" %1_changed: %1_changed,\n").arg(snakeCase(p.name));
|
r << QString(" %1_changed: %1_changed,\n").arg(snakeCase(p.name));
|
||||||
}
|
}
|
||||||
if (o.type != ObjectType::Object) {
|
if (o.type != ObjectType::Object) {
|
||||||
r << QString(" new_data_ready: new_data_ready,\n");
|
r << QString(" new_data_ready: %1_new_data_ready,\n")
|
||||||
|
.arg(snakeCase(o.name));
|
||||||
}
|
}
|
||||||
QString model = "";
|
QString model = "";
|
||||||
if (o.type != ObjectType::Object) {
|
if (o.type != ObjectType::Object) {
|
||||||
|
@ -105,20 +107,20 @@ void rConstructorArgs(QTextStream& r, const QString& name, const Object& o, cons
|
||||||
r << QString(R"( };
|
r << QString(R"( };
|
||||||
let model = %1%2 {
|
let model = %1%2 {
|
||||||
qobject: %3,
|
qobject: %3,
|
||||||
data_changed: data_changed,
|
data_changed: %4_data_changed,
|
||||||
begin_reset_model: begin_reset_model,
|
begin_reset_model: %4_begin_reset_model,
|
||||||
end_reset_model: end_reset_model,
|
end_reset_model: %4_end_reset_model,
|
||||||
begin_insert_rows: begin_insert_rows,
|
begin_insert_rows: %4_begin_insert_rows,
|
||||||
end_insert_rows: end_insert_rows,
|
end_insert_rows: %4_end_insert_rows,
|
||||||
begin_remove_rows: begin_remove_rows,
|
begin_remove_rows: %4_begin_remove_rows,
|
||||||
end_remove_rows: end_remove_rows,
|
end_remove_rows: %4_end_remove_rows,
|
||||||
)").arg(o.name, type, name);
|
)").arg(o.name, type, snakeCase(name), snakeCase(o.name));
|
||||||
}
|
}
|
||||||
r << QString(" };\n let d_%3 = %1::create(%3_emit%2")
|
r << QString(" };\n let d_%3 = %1::create(%3_emit%2")
|
||||||
.arg(o.name, model, name);
|
.arg(o.name, model, snakeCase(name));
|
||||||
for (const Property& p: o.properties) {
|
for (const Property& p: o.properties) {
|
||||||
if (p.type.type == BindingType::Object) {
|
if (p.type.type == BindingType::Object) {
|
||||||
r << ",\n d_" << p.name;
|
r << ",\n d_" << snakeCase(p.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
r << ");\n";
|
r << ");\n";
|
||||||
|
@ -560,8 +562,11 @@ pub unsafe extern "C" fn %2_set_data_%3_none(ptr: *mut %1, row: c_int%4) -> bool
|
||||||
|
|
||||||
QString rustFile(const QDir rustdir, const QString& module) {
|
QString rustFile(const QDir rustdir, const QString& module) {
|
||||||
QDir src(rustdir.absoluteFilePath("src"));
|
QDir src(rustdir.absoluteFilePath("src"));
|
||||||
QString path = src.absoluteFilePath(module + ".rs");
|
QString modulePath = src.absoluteFilePath(module + "/mod.rs");
|
||||||
return path;
|
if (QFile::exists(modulePath)) {
|
||||||
|
return modulePath;
|
||||||
|
}
|
||||||
|
return src.absoluteFilePath(module + ".rs");
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeRustTypes(const Configuration& conf, QTextStream& r) {
|
void writeRustTypes(const Configuration& conf, QTextStream& r) {
|
||||||
|
|
|
@ -159,28 +159,28 @@ pub trait PersonsTrait {
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn persons_new(
|
pub extern "C" fn persons_new(
|
||||||
persons: *mut PersonsQObject,
|
persons: *mut PersonsQObject,
|
||||||
new_data_ready: fn(*const PersonsQObject),
|
persons_new_data_ready: fn(*const PersonsQObject),
|
||||||
data_changed: fn(*const PersonsQObject, usize, usize),
|
persons_data_changed: fn(*const PersonsQObject, usize, usize),
|
||||||
begin_reset_model: fn(*const PersonsQObject),
|
persons_begin_reset_model: fn(*const PersonsQObject),
|
||||||
end_reset_model: fn(*const PersonsQObject),
|
persons_end_reset_model: fn(*const PersonsQObject),
|
||||||
begin_insert_rows: fn(*const PersonsQObject, usize, usize),
|
persons_begin_insert_rows: fn(*const PersonsQObject, usize, usize),
|
||||||
end_insert_rows: fn(*const PersonsQObject),
|
persons_end_insert_rows: fn(*const PersonsQObject),
|
||||||
begin_remove_rows: fn(*const PersonsQObject, usize, usize),
|
persons_begin_remove_rows: fn(*const PersonsQObject, usize, usize),
|
||||||
end_remove_rows: fn(*const PersonsQObject),
|
persons_end_remove_rows: fn(*const PersonsQObject),
|
||||||
) -> *mut Persons {
|
) -> *mut Persons {
|
||||||
let persons_emit = PersonsEmitter {
|
let persons_emit = PersonsEmitter {
|
||||||
qobject: Arc::new(Mutex::new(persons)),
|
qobject: Arc::new(Mutex::new(persons)),
|
||||||
new_data_ready: new_data_ready,
|
new_data_ready: persons_new_data_ready,
|
||||||
};
|
};
|
||||||
let model = PersonsList {
|
let model = PersonsList {
|
||||||
qobject: persons,
|
qobject: persons,
|
||||||
data_changed: data_changed,
|
data_changed: persons_data_changed,
|
||||||
begin_reset_model: begin_reset_model,
|
begin_reset_model: persons_begin_reset_model,
|
||||||
end_reset_model: end_reset_model,
|
end_reset_model: persons_end_reset_model,
|
||||||
begin_insert_rows: begin_insert_rows,
|
begin_insert_rows: persons_begin_insert_rows,
|
||||||
end_insert_rows: end_insert_rows,
|
end_insert_rows: persons_end_insert_rows,
|
||||||
begin_remove_rows: begin_remove_rows,
|
begin_remove_rows: persons_begin_remove_rows,
|
||||||
end_remove_rows: end_remove_rows,
|
end_remove_rows: persons_end_remove_rows,
|
||||||
};
|
};
|
||||||
let d_persons = Persons::create(persons_emit, model);
|
let d_persons = Persons::create(persons_emit, model);
|
||||||
Box::into_raw(Box::new(d_persons))
|
Box::into_raw(Box::new(d_persons))
|
||||||
|
|
|
@ -162,28 +162,28 @@ pub trait PersonsTrait {
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn persons_new(
|
pub extern "C" fn persons_new(
|
||||||
persons: *mut PersonsQObject,
|
persons: *mut PersonsQObject,
|
||||||
new_data_ready: fn(*const PersonsQObject, item: usize, valid: bool),
|
persons_new_data_ready: fn(*const PersonsQObject, item: usize, valid: bool),
|
||||||
data_changed: fn(*const PersonsQObject, usize, usize),
|
persons_data_changed: fn(*const PersonsQObject, usize, usize),
|
||||||
begin_reset_model: fn(*const PersonsQObject),
|
persons_begin_reset_model: fn(*const PersonsQObject),
|
||||||
end_reset_model: fn(*const PersonsQObject),
|
persons_end_reset_model: fn(*const PersonsQObject),
|
||||||
begin_insert_rows: fn(*const PersonsQObject, item: usize, valid: bool, usize, usize),
|
persons_begin_insert_rows: fn(*const PersonsQObject, item: usize, valid: bool, usize, usize),
|
||||||
end_insert_rows: fn(*const PersonsQObject),
|
persons_end_insert_rows: fn(*const PersonsQObject),
|
||||||
begin_remove_rows: fn(*const PersonsQObject, item: usize, valid: bool, usize, usize),
|
persons_begin_remove_rows: fn(*const PersonsQObject, item: usize, valid: bool, usize, usize),
|
||||||
end_remove_rows: fn(*const PersonsQObject),
|
persons_end_remove_rows: fn(*const PersonsQObject),
|
||||||
) -> *mut Persons {
|
) -> *mut Persons {
|
||||||
let persons_emit = PersonsEmitter {
|
let persons_emit = PersonsEmitter {
|
||||||
qobject: Arc::new(Mutex::new(persons)),
|
qobject: Arc::new(Mutex::new(persons)),
|
||||||
new_data_ready: new_data_ready,
|
new_data_ready: persons_new_data_ready,
|
||||||
};
|
};
|
||||||
let model = PersonsUniformTree {
|
let model = PersonsUniformTree {
|
||||||
qobject: persons,
|
qobject: persons,
|
||||||
data_changed: data_changed,
|
data_changed: persons_data_changed,
|
||||||
begin_reset_model: begin_reset_model,
|
begin_reset_model: persons_begin_reset_model,
|
||||||
end_reset_model: end_reset_model,
|
end_reset_model: persons_end_reset_model,
|
||||||
begin_insert_rows: begin_insert_rows,
|
begin_insert_rows: persons_begin_insert_rows,
|
||||||
end_insert_rows: end_insert_rows,
|
end_insert_rows: persons_end_insert_rows,
|
||||||
begin_remove_rows: begin_remove_rows,
|
begin_remove_rows: persons_begin_remove_rows,
|
||||||
end_remove_rows: end_remove_rows,
|
end_remove_rows: persons_end_remove_rows,
|
||||||
};
|
};
|
||||||
let d_persons = Persons::create(persons_emit, model);
|
let d_persons = Persons::create(persons_emit, model);
|
||||||
Box::into_raw(Box::new(d_persons))
|
Box::into_raw(Box::new(d_persons))
|
||||||
|
|
|
@ -140,6 +140,23 @@ QHash<int, QByteArray> Persons::roleNames() const {
|
||||||
names.insert(Qt::UserRole + 0, "userName");
|
names.insert(Qt::UserRole + 0, "userName");
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
QVariant Persons::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
|
{
|
||||||
|
if (orientation != Qt::Horizontal) {
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
return m_headerData.value(qMakePair(section, (Qt::ItemDataRole)role), role == Qt::DisplayRole ?QString::number(section + 1) :QVariant());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Persons::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)
|
||||||
|
{
|
||||||
|
if (orientation != Qt::Horizontal) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
m_headerData.insert(qMakePair(section, (Qt::ItemDataRole)role), value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool Persons::setData(const QModelIndex &index, const QVariant &value, int role)
|
bool Persons::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
{
|
{
|
||||||
bool set = false;
|
bool set = false;
|
||||||
|
@ -171,6 +188,7 @@ Persons::Persons(bool /*owned*/, QObject *parent):
|
||||||
m_d(0),
|
m_d(0),
|
||||||
m_ownsPrivate(false)
|
m_ownsPrivate(false)
|
||||||
{
|
{
|
||||||
|
initHeaderData();
|
||||||
}
|
}
|
||||||
|
|
||||||
Persons::Persons(QObject *parent):
|
Persons::Persons(QObject *parent):
|
||||||
|
@ -205,8 +223,9 @@ Persons::Persons(QObject *parent):
|
||||||
m_ownsPrivate(true)
|
m_ownsPrivate(true)
|
||||||
{
|
{
|
||||||
connect(this, &Persons::newDataReady, this, [this](const QModelIndex& i) {
|
connect(this, &Persons::newDataReady, this, [this](const QModelIndex& i) {
|
||||||
fetchMore(i);
|
this->fetchMore(i);
|
||||||
}, Qt::QueuedConnection);
|
}, Qt::QueuedConnection);
|
||||||
|
initHeaderData();
|
||||||
}
|
}
|
||||||
|
|
||||||
Persons::~Persons() {
|
Persons::~Persons() {
|
||||||
|
@ -214,3 +233,6 @@ Persons::~Persons() {
|
||||||
persons_free(m_d);
|
persons_free(m_d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void Persons::initHeaderData() {
|
||||||
|
m_headerData.insert(qMakePair(0, Qt::DisplayRole), QVariant("userName"));
|
||||||
|
}
|
||||||
|
|
|
@ -32,9 +32,14 @@ public:
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||||
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
|
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||||
|
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);
|
||||||
signals:
|
signals:
|
||||||
// new data is ready to be made available to the model with fetchMore()
|
// new data is ready to be made available to the model with fetchMore()
|
||||||
void newDataReady(const QModelIndex &parent) const;
|
void newDataReady(const QModelIndex &parent) const;
|
||||||
|
private:
|
||||||
|
QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData;
|
||||||
|
void initHeaderData();
|
||||||
signals:
|
signals:
|
||||||
};
|
};
|
||||||
#endif // TEST_LIST_RUST_H
|
#endif // TEST_LIST_RUST_H
|
||||||
|
|
|
@ -158,6 +158,23 @@ QHash<int, QByteArray> Persons::roleNames() const {
|
||||||
names.insert(Qt::UserRole + 0, "userName");
|
names.insert(Qt::UserRole + 0, "userName");
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
QVariant Persons::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
|
{
|
||||||
|
if (orientation != Qt::Horizontal) {
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
return m_headerData.value(qMakePair(section, (Qt::ItemDataRole)role), role == Qt::DisplayRole ?QString::number(section + 1) :QVariant());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Persons::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role)
|
||||||
|
{
|
||||||
|
if (orientation != Qt::Horizontal) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
m_headerData.insert(qMakePair(section, (Qt::ItemDataRole)role), value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool Persons::setData(const QModelIndex &index, const QVariant &value, int role)
|
bool Persons::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
{
|
{
|
||||||
bool set = false;
|
bool set = false;
|
||||||
|
@ -189,6 +206,7 @@ Persons::Persons(bool /*owned*/, QObject *parent):
|
||||||
m_d(0),
|
m_d(0),
|
||||||
m_ownsPrivate(false)
|
m_ownsPrivate(false)
|
||||||
{
|
{
|
||||||
|
initHeaderData();
|
||||||
}
|
}
|
||||||
|
|
||||||
Persons::Persons(QObject *parent):
|
Persons::Persons(QObject *parent):
|
||||||
|
@ -240,8 +258,9 @@ Persons::Persons(QObject *parent):
|
||||||
m_ownsPrivate(true)
|
m_ownsPrivate(true)
|
||||||
{
|
{
|
||||||
connect(this, &Persons::newDataReady, this, [this](const QModelIndex& i) {
|
connect(this, &Persons::newDataReady, this, [this](const QModelIndex& i) {
|
||||||
fetchMore(i);
|
this->fetchMore(i);
|
||||||
}, Qt::QueuedConnection);
|
}, Qt::QueuedConnection);
|
||||||
|
initHeaderData();
|
||||||
}
|
}
|
||||||
|
|
||||||
Persons::~Persons() {
|
Persons::~Persons() {
|
||||||
|
@ -249,3 +268,6 @@ Persons::~Persons() {
|
||||||
persons_free(m_d);
|
persons_free(m_d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void Persons::initHeaderData() {
|
||||||
|
m_headerData.insert(qMakePair(0, Qt::DisplayRole), QVariant("userName"));
|
||||||
|
}
|
||||||
|
|
|
@ -32,9 +32,14 @@ public:
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||||
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
|
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||||
|
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole);
|
||||||
signals:
|
signals:
|
||||||
// new data is ready to be made available to the model with fetchMore()
|
// new data is ready to be made available to the model with fetchMore()
|
||||||
void newDataReady(const QModelIndex &parent) const;
|
void newDataReady(const QModelIndex &parent) const;
|
||||||
|
private:
|
||||||
|
QHash<QPair<int,Qt::ItemDataRole>, QVariant> m_headerData;
|
||||||
|
void initHeaderData();
|
||||||
signals:
|
signals:
|
||||||
};
|
};
|
||||||
#endif // TEST_TREE_RUST_H
|
#endif // TEST_TREE_RUST_H
|
||||||
|
|
Loading…
Reference in New Issue