Change the json format and add charts
parent
a6f34bb1da
commit
eb9feb6a12
|
@ -4,35 +4,59 @@ cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
|
||||||
cmake_policy(SET CMP0046 NEW)
|
cmake_policy(SET CMP0046 NEW)
|
||||||
cmake_policy(SET CMP0063 NEW)
|
cmake_policy(SET CMP0063 NEW)
|
||||||
set(QT_MIN_VERSION "5.6.0")
|
set(QT_MIN_VERSION "5.6.0")
|
||||||
|
set(KF5_MIN_VERSION "5.2.0")
|
||||||
|
|
||||||
|
find_package(ECM 1.0.0 NO_MODULE)
|
||||||
|
if (ECM_FOUND)
|
||||||
|
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR}
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
||||||
|
include(KDEInstallDirs)
|
||||||
|
include(KDECMakeSettings)
|
||||||
|
include(KDECompilerSettings)
|
||||||
|
endif()
|
||||||
|
|
||||||
include(FeatureSummary)
|
include(FeatureSummary)
|
||||||
|
|
||||||
# Find Qt modules
|
# Find Qt modules
|
||||||
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS
|
find_package(Qt5 ${QT_MIN_VERSION} CONFIG
|
||||||
Core
|
REQUIRED COMPONENTS
|
||||||
Test
|
Core
|
||||||
|
Test
|
||||||
|
OPTIONAL_COMPONENTS
|
||||||
|
Widgets
|
||||||
|
Quick
|
||||||
)
|
)
|
||||||
find_package(Qt5Widgets ${QT_MIN_VERSION} CONFIG)
|
find_package(Qt5QuickControls2 EXACT ${Qt5Core_VERSION})
|
||||||
find_package(Qt5Quick ${QT_MIN_VERSION} CONFIG)
|
find_package(Qt5Charts EXACT ${Qt5Core_VERSION})
|
||||||
find_package(Qt5QuickControls2 ${QT_MIN_VERSION} CONFIG)
|
|
||||||
set(CMAKE_AUTOMOC ON)
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
|
||||||
|
if (ECM_FOUND)
|
||||||
|
# Find KDE Modules
|
||||||
|
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
|
||||||
|
CoreAddons # KAboutData
|
||||||
|
I18n # KLocalizedString
|
||||||
|
WidgetsAddons # KMessageBox
|
||||||
|
)
|
||||||
|
find_package(KF5Kirigami CONFIG)
|
||||||
|
endif()
|
||||||
|
|
||||||
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
|
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
|
||||||
|
|
||||||
string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UPPER)
|
string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UPPER)
|
||||||
if(CMAKE_BUILD_TYPE_UPPER STREQUAL DEBUG)
|
if(CMAKE_BUILD_TYPE_UPPER STREQUAL DEBUG)
|
||||||
set(RUST_TARGET_DIR target/debug/)
|
set(RUST_TARGET_DIR target/debug/)
|
||||||
set(RUST_BUILD_FLAG)
|
set(RUST_BUILD_FLAG)
|
||||||
else()
|
else()
|
||||||
set(RUST_TARGET_DIR target/release/)
|
set(RUST_TARGET_DIR target/release/)
|
||||||
set(RUST_BUILD_FLAG --release)
|
set(RUST_BUILD_FLAG --release)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_subdirectory(rust_qt_binding_generator)
|
add_subdirectory(rust_qt_binding_generator)
|
||||||
|
|
||||||
enable_testing()
|
enable_testing()
|
||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
|
|
||||||
if(Qt5Widgets_FOUND)
|
if(Qt5Widgets_FOUND)
|
||||||
add_subdirectory(demo)
|
add_subdirectory(demo)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ add_custom_command(
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/rust/src/fibonacci_types.rs"
|
"${CMAKE_CURRENT_SOURCE_DIR}/rust/src/fibonacci_types.rs"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/Fibonacci.h"
|
"${CMAKE_CURRENT_SOURCE_DIR}/src/Fibonacci.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/tmp.cpp"
|
# "${CMAKE_CURRENT_SOURCE_DIR}/src/Fibonacci.cpp"
|
||||||
COMMAND ${CMAKE_BINARY_DIR}/rust_qt_binding_generator/rust_qt_binding_generator "${CMAKE_CURRENT_SOURCE_DIR}/fibonacci.json"
|
COMMAND ${CMAKE_BINARY_DIR}/rust_qt_binding_generator/rust_qt_binding_generator "${CMAKE_CURRENT_SOURCE_DIR}/fibonacci.json"
|
||||||
DEPENDS rust_qt_binding_generator fibonacci.json
|
DEPENDS rust_qt_binding_generator fibonacci.json
|
||||||
)
|
)
|
||||||
|
@ -17,11 +17,22 @@ add_custom_command(
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/rust/src/types.rs"
|
"${CMAKE_CURRENT_SOURCE_DIR}/rust/src/types.rs"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/src/Tree.h"
|
"${CMAKE_CURRENT_SOURCE_DIR}/src/Tree.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/tmp.cpp"
|
# "${CMAKE_CURRENT_SOURCE_DIR}/src/Tree.cpp"
|
||||||
COMMAND ${CMAKE_BINARY_DIR}/rust_qt_binding_generator/rust_qt_binding_generator "${CMAKE_CURRENT_SOURCE_DIR}/tree.json"
|
COMMAND ${CMAKE_BINARY_DIR}/rust_qt_binding_generator/rust_qt_binding_generator "${CMAKE_CURRENT_SOURCE_DIR}/tree.json"
|
||||||
DEPENDS rust_qt_binding_generator tree.json
|
DEPENDS rust_qt_binding_generator tree.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}/rust/src/time_series_types.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}/rust_qt_binding_generator/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
|
||||||
add_custom_command(
|
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"
|
||||||
|
@ -33,30 +44,33 @@ add_custom_command(
|
||||||
rust/src/implementation.rs
|
rust/src/implementation.rs
|
||||||
rust/src/interface.rs
|
rust/src/interface.rs
|
||||||
rust/src/types.rs
|
rust/src/types.rs
|
||||||
|
rust/src/time_series_interface.rs
|
||||||
|
rust/src/time_series_implementation.rs
|
||||||
|
rust/src/time_series_types.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")
|
||||||
|
|
||||||
if(Qt5Quick_FOUND)
|
list(APPEND DemoLibs "${CMAKE_CURRENT_SOURCE_DIR}/rust/${RUST_TARGET_DIR}/librust.a")
|
||||||
add_definitions(-DQTQUICK)
|
list(APPEND DemoLibs Qt5::Widgets)
|
||||||
set(Qt5Quick_LIBS Qt5::Quick)
|
if (Qt5Quick_FOUND)
|
||||||
|
list(APPEND DemoLibs Qt5::Quick)
|
||||||
endif()
|
endif()
|
||||||
if(Qt5QuickControls2_FOUND)
|
if (Qt5QuickControls2_FOUND)
|
||||||
add_definitions(-DQTQUICKCONTROLS2)
|
add_definitions(-DQTQUICKCONTROLS2)
|
||||||
set(Qt5QuickControls2_LIBS Qt5::QuickControls2)
|
# list(APPEND DemoLibs Qt5::QuickControls2)
|
||||||
|
endif()
|
||||||
|
if (Qt5Charts_FOUND)
|
||||||
|
list(APPEND DemoLibs Qt5::Charts)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(Demo_SRCS src/main.cpp src/Tree.cpp src/Fibonacci.cpp
|
set(Demo_SRCS src/main.cpp src/Fibonacci.cpp src/Tree.cpp src/TimeSeries.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)
|
||||||
|
|
||||||
target_link_libraries(Demo
|
target_link_libraries(Demo ${DemoLibs})
|
||||||
Qt5::Widgets
|
|
||||||
"${Qt5Quick_LIBS}"
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/rust/${RUST_TARGET_DIR}/librust.a"
|
|
||||||
)
|
|
||||||
|
|
||||||
set_target_properties(Demo PROPERTIES
|
set_target_properties(Demo PROPERTIES
|
||||||
CXX_STANDARD 11
|
CXX_STANDARD 11
|
||||||
|
|
|
@ -6,26 +6,27 @@
|
||||||
"implementationModule": "fibonacci_implementation",
|
"implementationModule": "fibonacci_implementation",
|
||||||
"typesModule": "fibonacci_types"
|
"typesModule": "fibonacci_types"
|
||||||
},
|
},
|
||||||
"objects": [{
|
"objects": {
|
||||||
"name": "Fibonacci",
|
"Fibonacci": {
|
||||||
"type": "Object",
|
"type": "Object",
|
||||||
"properties": [{
|
"properties": {
|
||||||
"name": "input",
|
"input": {
|
||||||
"type": "quint32",
|
"type": "quint32",
|
||||||
"write": true
|
"write": true
|
||||||
}, {
|
},
|
||||||
"name": "result",
|
"result": {
|
||||||
"type": "quint64"
|
"type": "quint64"
|
||||||
}]
|
}
|
||||||
}, {
|
}
|
||||||
"name": "FibonacciList",
|
},
|
||||||
"type": "List",
|
"FibonacciList": {
|
||||||
"roles": [
|
"type": "List",
|
||||||
[{
|
"itemProperties": {
|
||||||
"name": "result",
|
"result": {
|
||||||
"value": "Qt::DisplayRole",
|
"type": "quint64",
|
||||||
"type": "quint64"
|
"roles": [ [ "display" ] ]
|
||||||
}]
|
}
|
||||||
]
|
}
|
||||||
}]
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,14 +36,6 @@ impl Item for DirEntry {
|
||||||
fn file_path(&self) -> Option<String> {
|
fn file_path(&self) -> Option<String> {
|
||||||
self.path.as_ref().map(|p| p.to_string_lossy().into())
|
self.path.as_ref().map(|p| p.to_string_lossy().into())
|
||||||
}
|
}
|
||||||
fn set_file_name(&mut self, file_name: String) -> bool {
|
|
||||||
self.name = file_name.into();
|
|
||||||
true
|
|
||||||
}
|
|
||||||
fn set_file_path(&mut self, file_path: Option<String>) -> bool {
|
|
||||||
self.path = file_path.map(|f| f.into());
|
|
||||||
true
|
|
||||||
}
|
|
||||||
fn file_permissions(&self) -> c_int {
|
fn file_permissions(&self) -> c_int {
|
||||||
42
|
42
|
||||||
}
|
}
|
||||||
|
@ -53,9 +45,6 @@ impl Item for DirEntry {
|
||||||
fn file_size(&self) -> Option<u64> {
|
fn file_size(&self) -> Option<u64> {
|
||||||
self.metadata.as_ref().map(|m|m.len())
|
self.metadata.as_ref().map(|m|m.len())
|
||||||
}
|
}
|
||||||
fn set_file_size(&mut self, file_size: Option<u64>) -> bool {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
fn retrieve(id: usize, parents: Vec<&DirEntry>,
|
fn retrieve(id: usize, parents: Vec<&DirEntry>,
|
||||||
q: Incoming<Self>,
|
q: Incoming<Self>,
|
||||||
emit: TreeEmitter) {
|
emit: TreeEmitter) {
|
||||||
|
@ -98,12 +87,9 @@ pub trait Item: Default {
|
||||||
fn retrieve(id: usize, parents: Vec<&Self>, q: Incoming<Self>, emit: TreeEmitter);
|
fn retrieve(id: usize, parents: Vec<&Self>, q: Incoming<Self>, emit: TreeEmitter);
|
||||||
fn file_name(&self) -> String;
|
fn file_name(&self) -> String;
|
||||||
fn file_path(&self) -> Option<String>;
|
fn file_path(&self) -> Option<String>;
|
||||||
fn set_file_name(&mut self, file_name: String) -> bool;
|
|
||||||
fn file_permissions(&self) -> c_int;
|
fn file_permissions(&self) -> c_int;
|
||||||
fn file_type(&self) -> c_int;
|
fn file_type(&self) -> c_int;
|
||||||
fn file_size(&self) -> Option<u64>;
|
fn file_size(&self) -> Option<u64>;
|
||||||
fn set_file_path(&mut self, file_path: Option<String>) -> bool;
|
|
||||||
fn set_file_size(&mut self, file_size: Option<u64>) -> bool;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Tree = RGeneralItemModel<DirEntry>;
|
pub type Tree = RGeneralItemModel<DirEntry>;
|
||||||
|
@ -284,11 +270,6 @@ impl<T: Item> TreeTrait for RGeneralItemModel<T> where T: Sync + Send {
|
||||||
.map(|entry| entry.data.file_name())
|
.map(|entry| entry.data.file_name())
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
fn set_file_name(&mut self, row: c_int, parent: usize, v: String) -> bool {
|
|
||||||
self.get_mut(row, parent)
|
|
||||||
.map(|mut entry| entry.data.set_file_name(v))
|
|
||||||
.unwrap_or(false)
|
|
||||||
}
|
|
||||||
fn file_permissions(&self, row: c_int, parent: usize) -> c_int {
|
fn file_permissions(&self, row: c_int, parent: usize) -> c_int {
|
||||||
self.get(row, parent)
|
self.get(row, parent)
|
||||||
.map(|entry| entry.data.file_permissions())
|
.map(|entry| entry.data.file_permissions())
|
||||||
|
@ -302,11 +283,6 @@ impl<T: Item> TreeTrait for RGeneralItemModel<T> where T: Sync + Send {
|
||||||
.map(|entry| entry.data.file_path())
|
.map(|entry| entry.data.file_path())
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
}
|
}
|
||||||
fn set_file_path(&mut self, row: c_int, parent: usize, v: Option<String>) -> bool {
|
|
||||||
self.get_mut(row, parent)
|
|
||||||
.map(|mut entry| entry.data.set_file_path(v))
|
|
||||||
.unwrap_or(false)
|
|
||||||
}
|
|
||||||
fn file_type(&self, row: c_int, parent: usize) -> c_int {
|
fn file_type(&self, row: c_int, parent: usize) -> c_int {
|
||||||
self.get(row, parent)
|
self.get(row, parent)
|
||||||
.map(|entry| entry.data.file_type())
|
.map(|entry| entry.data.file_type())
|
||||||
|
@ -317,9 +293,4 @@ impl<T: Item> TreeTrait for RGeneralItemModel<T> where T: Sync + Send {
|
||||||
.map(|entry| entry.data.file_size())
|
.map(|entry| entry.data.file_size())
|
||||||
.unwrap_or(None)
|
.unwrap_or(None)
|
||||||
}
|
}
|
||||||
fn set_file_size(&mut self, row: c_int, parent: usize, v: Option<u64>) -> bool {
|
|
||||||
self.get_mut(row, parent)
|
|
||||||
.map(|mut entry| entry.data.set_file_size(v))
|
|
||||||
.unwrap_or(false)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,15 +78,12 @@ pub trait TreeTrait {
|
||||||
fn can_fetch_more(&self, c_int, usize) -> bool { false }
|
fn can_fetch_more(&self, c_int, usize) -> bool { false }
|
||||||
fn fetch_more(&mut self, c_int, usize) {}
|
fn fetch_more(&mut self, c_int, usize) {}
|
||||||
fn sort(&mut self, c_int, SortOrder) {}
|
fn sort(&mut self, c_int, SortOrder) {}
|
||||||
fn file_name(&self, row: c_int, parent: usize) -> String;
|
|
||||||
fn set_file_name(&mut self, row: c_int, parent: usize, String) -> bool;
|
|
||||||
fn file_icon(&self, row: c_int, parent: usize) -> Vec<u8>;
|
fn file_icon(&self, row: c_int, parent: usize) -> Vec<u8>;
|
||||||
|
fn file_name(&self, row: c_int, parent: usize) -> String;
|
||||||
fn file_path(&self, row: c_int, parent: usize) -> Option<String>;
|
fn file_path(&self, row: c_int, parent: usize) -> Option<String>;
|
||||||
fn set_file_path(&mut self, row: c_int, parent: usize, Option<String>) -> bool;
|
|
||||||
fn file_permissions(&self, row: c_int, parent: usize) -> i32;
|
fn file_permissions(&self, row: c_int, parent: usize) -> i32;
|
||||||
fn file_type(&self, row: c_int, parent: usize) -> i32;
|
|
||||||
fn file_size(&self, row: c_int, parent: usize) -> Option<u64>;
|
fn file_size(&self, row: c_int, parent: usize) -> Option<u64>;
|
||||||
fn set_file_size(&mut self, row: c_int, parent: usize, Option<u64>) -> bool;
|
fn file_type(&self, row: c_int, parent: usize) -> i32;
|
||||||
fn index(&self, row: c_int, parent: usize) -> usize;
|
fn index(&self, row: c_int, parent: usize) -> usize;
|
||||||
fn parent(&self, parent: usize) -> QModelIndex;
|
fn parent(&self, parent: usize) -> QModelIndex;
|
||||||
}
|
}
|
||||||
|
@ -165,20 +162,6 @@ pub unsafe extern "C" fn tree_sort(ptr: *mut Tree, column: c_int, order: SortOrd
|
||||||
(&mut *ptr).sort(column, order)
|
(&mut *ptr).sort(column, order)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn tree_data_file_name(ptr: *const Tree,
|
|
||||||
row: c_int, parent: usize,
|
|
||||||
d: *mut c_void,
|
|
||||||
set: fn(*mut c_void, QString)) {
|
|
||||||
let data = (&*ptr).file_name(row, parent);
|
|
||||||
set(d, QString::from(&data));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn tree_set_data_file_name(ptr: *mut Tree, row: c_int, parent: usize, v: QStringIn) -> bool {
|
|
||||||
(&mut *ptr).set_file_name(row, parent, v.convert())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn tree_data_file_icon(ptr: *const Tree,
|
pub unsafe extern "C" fn tree_data_file_icon(ptr: *const Tree,
|
||||||
row: c_int, parent: usize,
|
row: c_int, parent: usize,
|
||||||
|
@ -188,6 +171,15 @@ pub unsafe extern "C" fn tree_data_file_icon(ptr: *const Tree,
|
||||||
set(d, QByteArray::from(&data));
|
set(d, QByteArray::from(&data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn tree_data_file_name(ptr: *const Tree,
|
||||||
|
row: c_int, parent: usize,
|
||||||
|
d: *mut c_void,
|
||||||
|
set: fn(*mut c_void, QString)) {
|
||||||
|
let data = (&*ptr).file_name(row, parent);
|
||||||
|
set(d, QString::from(&data));
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn tree_data_file_path(ptr: *const Tree,
|
pub unsafe extern "C" fn tree_data_file_path(ptr: *const Tree,
|
||||||
row: c_int, parent: usize,
|
row: c_int, parent: usize,
|
||||||
|
@ -199,39 +191,19 @@ pub unsafe extern "C" fn tree_data_file_path(ptr: *const Tree,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn tree_set_data_file_path(ptr: *mut Tree, row: c_int, parent: usize, v: QStringIn) -> bool {
|
|
||||||
(&mut *ptr).set_file_path(row, parent, Some(v.convert()))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn tree_set_data_file_path_none(ptr: *mut Tree, row: c_int, parent: usize) -> bool {
|
|
||||||
(&mut *ptr).set_file_path(row, parent, None)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn tree_data_file_permissions(ptr: *const Tree, row: c_int, parent: usize) -> i32 {
|
pub unsafe extern "C" fn tree_data_file_permissions(ptr: *const Tree, row: c_int, parent: usize) -> i32 {
|
||||||
(&*ptr).file_permissions(row, parent).into()
|
(&*ptr).file_permissions(row, parent).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn tree_data_file_type(ptr: *const Tree, row: c_int, parent: usize) -> i32 {
|
|
||||||
(&*ptr).file_type(row, parent).into()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn tree_data_file_size(ptr: *const Tree, row: c_int, parent: usize) -> COption<u64> {
|
pub unsafe extern "C" fn tree_data_file_size(ptr: *const Tree, row: c_int, parent: usize) -> COption<u64> {
|
||||||
(&*ptr).file_size(row, parent).into()
|
(&*ptr).file_size(row, parent).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn tree_set_data_file_size(ptr: *mut Tree, row: c_int, parent: usize, v: u64) -> bool {
|
pub unsafe extern "C" fn tree_data_file_type(ptr: *const Tree, row: c_int, parent: usize) -> i32 {
|
||||||
(&mut *ptr).set_file_size(row, parent, Some(v))
|
(&*ptr).file_type(row, parent).into()
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn tree_set_data_file_size_none(ptr: *mut Tree, row: c_int, parent: usize) -> bool {
|
|
||||||
(&mut *ptr).set_file_size(row, parent, None)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
|
|
@ -7,3 +7,7 @@ pub mod fibonacci_interface;
|
||||||
mod types;
|
mod types;
|
||||||
mod implementation;
|
mod implementation;
|
||||||
pub mod interface;
|
pub mod interface;
|
||||||
|
|
||||||
|
mod time_series_types;
|
||||||
|
mod time_series_implementation;
|
||||||
|
pub mod time_series_interface;
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
#![allow(unused_imports)]
|
||||||
|
#![allow(unused_variables)]
|
||||||
|
#![allow(dead_code)]
|
||||||
|
use libc::c_int;
|
||||||
|
use libc::c_uint;
|
||||||
|
use types::*;
|
||||||
|
use time_series_interface::*;
|
||||||
|
|
||||||
|
#[derive (Default, Clone)]
|
||||||
|
struct TimeSeriesItem {
|
||||||
|
input: u32,
|
||||||
|
result: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct TimeSeries {
|
||||||
|
emit: TimeSeriesEmitter,
|
||||||
|
model: TimeSeriesList,
|
||||||
|
list: Vec<TimeSeriesItem>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TimeSeriesTrait for TimeSeries {
|
||||||
|
fn create(emit: TimeSeriesEmitter, model: TimeSeriesList) -> TimeSeries {
|
||||||
|
let mut series = TimeSeries {
|
||||||
|
emit: emit,
|
||||||
|
model: model,
|
||||||
|
list: Vec::new()
|
||||||
|
};
|
||||||
|
for i in 0..100 {
|
||||||
|
series.list.push(TimeSeriesItem {
|
||||||
|
input: i,
|
||||||
|
result: 2 * i
|
||||||
|
});
|
||||||
|
}
|
||||||
|
series
|
||||||
|
}
|
||||||
|
fn emit(&self) -> &TimeSeriesEmitter {
|
||||||
|
&self.emit
|
||||||
|
}
|
||||||
|
fn row_count(&self) -> c_int {
|
||||||
|
self.list.len() as c_int
|
||||||
|
}
|
||||||
|
fn input(&self, row: c_int) -> u32 {
|
||||||
|
self.list[row as usize].input
|
||||||
|
}
|
||||||
|
fn set_input(&mut self, row: c_int, v: u32) -> bool {
|
||||||
|
println!("setting input to {} {}", row, v);
|
||||||
|
self.list[row as usize].input = v;
|
||||||
|
true
|
||||||
|
}
|
||||||
|
fn result(&self, row: c_int) -> u32 {
|
||||||
|
self.list[row as usize].result
|
||||||
|
}
|
||||||
|
fn set_result(&mut self, row: c_int, v: u32) -> bool {
|
||||||
|
self.list[row as usize].result = v;
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,149 @@
|
||||||
|
/* generated by rust_qt_binding_generator */
|
||||||
|
#![allow(unknown_lints)]
|
||||||
|
#![allow(mutex_atomic, needless_pass_by_value)]
|
||||||
|
#![allow(unused_imports)]
|
||||||
|
use libc::{c_int, c_uint, c_void};
|
||||||
|
use types::*;
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
use std::ptr::null;
|
||||||
|
|
||||||
|
use time_series_implementation::*;
|
||||||
|
|
||||||
|
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,
|
||||||
|
begin_reset_model: fn(*const TimeSeriesQObject),
|
||||||
|
end_reset_model: fn(*const TimeSeriesQObject),
|
||||||
|
begin_insert_rows: fn(*const TimeSeriesQObject, c_int, c_int),
|
||||||
|
end_insert_rows: fn(*const TimeSeriesQObject),
|
||||||
|
begin_remove_rows: fn(*const TimeSeriesQObject, c_int, c_int),
|
||||||
|
end_remove_rows: fn(*const TimeSeriesQObject),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TimeSeriesList {
|
||||||
|
pub fn begin_reset_model(&self) {
|
||||||
|
(self.begin_reset_model)(self.qobject);
|
||||||
|
}
|
||||||
|
pub fn end_reset_model(&self) {
|
||||||
|
(self.end_reset_model)(self.qobject);
|
||||||
|
}
|
||||||
|
pub fn begin_insert_rows(&self, first: c_int, last: c_int) {
|
||||||
|
(self.begin_insert_rows)(self.qobject, first, last);
|
||||||
|
}
|
||||||
|
pub fn end_insert_rows(&self) {
|
||||||
|
(self.end_insert_rows)(self.qobject);
|
||||||
|
}
|
||||||
|
pub fn begin_remove_rows(&self, first: c_int, last: c_int) {
|
||||||
|
(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) -> c_int;
|
||||||
|
fn can_fetch_more(&self) -> bool { false }
|
||||||
|
fn fetch_more(&mut self) {}
|
||||||
|
fn sort(&mut self, c_int, SortOrder) {}
|
||||||
|
fn input(&self, row: c_int) -> u32;
|
||||||
|
fn set_input(&mut self, row: c_int, u32) -> bool;
|
||||||
|
fn result(&self, row: c_int) -> u32;
|
||||||
|
fn set_result(&mut self, row: c_int, u32) -> bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn time_series_new(qobject: *const TimeSeriesQObject,
|
||||||
|
new_data_ready: fn(*const TimeSeriesQObject),
|
||||||
|
begin_reset_model: fn(*const TimeSeriesQObject),
|
||||||
|
end_reset_model: fn(*const TimeSeriesQObject),
|
||||||
|
begin_insert_rows: fn(*const TimeSeriesQObject,
|
||||||
|
c_int,
|
||||||
|
c_int),
|
||||||
|
end_insert_rows: fn(*const TimeSeriesQObject),
|
||||||
|
begin_remove_rows: fn(*const TimeSeriesQObject,
|
||||||
|
c_int,
|
||||||
|
c_int),
|
||||||
|
end_remove_rows: fn(*const TimeSeriesQObject))
|
||||||
|
-> *mut TimeSeries {
|
||||||
|
let emit = TimeSeriesEmitter {
|
||||||
|
qobject: Arc::new(Mutex::new(qobject)),
|
||||||
|
new_data_ready: new_data_ready,
|
||||||
|
};
|
||||||
|
let model = TimeSeriesList {
|
||||||
|
qobject: qobject,
|
||||||
|
begin_reset_model: begin_reset_model,
|
||||||
|
end_reset_model: end_reset_model,
|
||||||
|
begin_insert_rows: begin_insert_rows,
|
||||||
|
end_insert_rows: end_insert_rows,
|
||||||
|
begin_remove_rows: begin_remove_rows,
|
||||||
|
end_remove_rows: end_remove_rows,
|
||||||
|
};
|
||||||
|
let d = TimeSeries::create(emit, model);
|
||||||
|
Box::into_raw(Box::new(d))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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()
|
||||||
|
}
|
||||||
|
#[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: c_int, 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).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, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn time_series_data_result(ptr: *const TimeSeries, row: c_int) -> u32 {
|
||||||
|
(&*ptr).result(row).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, v)
|
||||||
|
}
|
|
@ -0,0 +1,104 @@
|
||||||
|
/* generated by rust_qt_binding_generator */
|
||||||
|
#![allow(dead_code)]
|
||||||
|
use std::slice;
|
||||||
|
use libc::{c_int, uint8_t, uint16_t};
|
||||||
|
|
||||||
|
#[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 {
|
||||||
|
pub 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 String> for QString {
|
||||||
|
fn from(string: &'a String) -> QString {
|
||||||
|
QString {
|
||||||
|
len: string.len() as c_int,
|
||||||
|
data: string.as_ptr(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct QByteArray {
|
||||||
|
data: *const uint8_t,
|
||||||
|
len: c_int,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl QByteArray {
|
||||||
|
pub fn convert(&self) -> Vec<u8> {
|
||||||
|
let data = unsafe { slice::from_raw_parts(self.data, self.len as usize) };
|
||||||
|
Vec::from(data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> From<&'a Vec<u8>> for QByteArray {
|
||||||
|
fn from(value: &'a Vec<u8>) -> QByteArray {
|
||||||
|
QByteArray {
|
||||||
|
len: value.len() as c_int,
|
||||||
|
data: value.as_ptr(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct QModelIndex {
|
||||||
|
row: c_int,
|
||||||
|
internal_id: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl QModelIndex {
|
||||||
|
pub fn invalid() -> QModelIndex {
|
||||||
|
QModelIndex {
|
||||||
|
row: -1,
|
||||||
|
internal_id: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn create(row: c_int, id: usize) -> QModelIndex {
|
||||||
|
QModelIndex {
|
||||||
|
row: row,
|
||||||
|
internal_id: id,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
pub enum SortOrder {
|
||||||
|
Ascending = 0,
|
||||||
|
Descending = 1
|
||||||
|
}
|
||||||
|
|
|
@ -150,8 +150,8 @@ int FibonacciList::rowCount(const QModelIndex &parent) const
|
||||||
|
|
||||||
QModelIndex FibonacciList::index(int row, int column, const QModelIndex &parent) const
|
QModelIndex FibonacciList::index(int row, int column, const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
if (!parent.isValid() && column == 0) {
|
if (!parent.isValid() && row >= 0 && row < rowCount(parent) && column >= 0 && column < 1) {
|
||||||
return createIndex(row, 0, (quintptr)0);
|
return createIndex(row, column, (quintptr)0);
|
||||||
}
|
}
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
}
|
}
|
||||||
|
@ -190,7 +190,8 @@ QVariant FibonacciList::data(const QModelIndex &index, int role) const
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 0:
|
case 0:
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::DisplayRole:
|
case 256:
|
||||||
|
case 0:
|
||||||
v = fibonacci_list_data_result(d, index.row());
|
v = fibonacci_list_data_result(d, index.row());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -199,8 +200,8 @@ QVariant FibonacciList::data(const QModelIndex &index, int role) const
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
QHash<int, QByteArray> FibonacciList::roleNames() const {
|
QHash<int, QByteArray> FibonacciList::roleNames() const {
|
||||||
QHash<int, QByteArray> names;
|
QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
|
||||||
names.insert(Qt::DisplayRole, "result");
|
names.insert(256, "result");
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
bool FibonacciList::setData(const QModelIndex &index, const QVariant &value, int role)
|
bool FibonacciList::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
|
|
|
@ -0,0 +1,231 @@
|
||||||
|
/* generated by rust_qt_binding_generator */
|
||||||
|
#include "TimeSeries.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
template <typename T>
|
||||||
|
struct option {
|
||||||
|
private:
|
||||||
|
T value;
|
||||||
|
bool some;
|
||||||
|
public:
|
||||||
|
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" {
|
||||||
|
TimeSeries::Private* time_series_new(TimeSeries*,
|
||||||
|
void (*)(const TimeSeries*),
|
||||||
|
void (*)(TimeSeries*),
|
||||||
|
void (*)(TimeSeries*),
|
||||||
|
void (*)(TimeSeries*, int, int),
|
||||||
|
void (*)(TimeSeries*),
|
||||||
|
void (*)(TimeSeries*, int, int),
|
||||||
|
void (*)(TimeSeries*));
|
||||||
|
void time_series_free(TimeSeries::Private*);
|
||||||
|
};
|
||||||
|
TimeSeries::TimeSeries(QObject *parent):
|
||||||
|
QAbstractItemModel(parent),
|
||||||
|
d(time_series_new(this,
|
||||||
|
[](const TimeSeries* o) {
|
||||||
|
emit o->newDataReady(QModelIndex());
|
||||||
|
},
|
||||||
|
[](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();
|
||||||
|
}
|
||||||
|
)) {
|
||||||
|
connect(this, &TimeSeries::newDataReady, this, [this](const QModelIndex& i) {
|
||||||
|
fetchMore(i);
|
||||||
|
}, Qt::QueuedConnection);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TimeSeries::~TimeSeries() {
|
||||||
|
time_series_free(d);
|
||||||
|
}
|
||||||
|
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*, int 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(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)0);
|
||||||
|
}
|
||||||
|
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(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TimeSeries::fetchMore(const QModelIndex &parent)
|
||||||
|
{
|
||||||
|
if (!parent.isValid()) {
|
||||||
|
time_series_fetch_more(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TimeSeries::sort(int column, Qt::SortOrder order)
|
||||||
|
{
|
||||||
|
time_series_sort(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;
|
||||||
|
QString s;
|
||||||
|
QByteArray b;
|
||||||
|
switch (index.column()) {
|
||||||
|
case 0:
|
||||||
|
switch (role) {
|
||||||
|
case 256:
|
||||||
|
case 0:
|
||||||
|
case 2:
|
||||||
|
v = time_series_data_input(d, index.row());
|
||||||
|
break;
|
||||||
|
case 257:
|
||||||
|
v = time_series_data_result(d, index.row());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
switch (role) {
|
||||||
|
case 256:
|
||||||
|
v = time_series_data_input(d, index.row());
|
||||||
|
break;
|
||||||
|
case 257:
|
||||||
|
case 0:
|
||||||
|
case 2:
|
||||||
|
v = time_series_data_result(d, index.row());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
QHash<int, QByteArray> TimeSeries::roleNames() const {
|
||||||
|
QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
|
||||||
|
names.insert(256, "input");
|
||||||
|
names.insert(257, "result");
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
bool TimeSeries::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
|
{
|
||||||
|
bool set = false;
|
||||||
|
if (index.column() == 0) {
|
||||||
|
if (role == 256 || role == 0 || role == 2) {
|
||||||
|
set = time_series_set_data_input(d, index.row(), value.value<quint32>());
|
||||||
|
}
|
||||||
|
if (role == 257) {
|
||||||
|
set = time_series_set_data_result(d, index.row(), value.value<quint32>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (index.column() == 1) {
|
||||||
|
if (role == 256) {
|
||||||
|
set = time_series_set_data_input(d, index.row(), value.value<quint32>());
|
||||||
|
}
|
||||||
|
if (role == 257 || role == 0 || role == 2) {
|
||||||
|
set = time_series_set_data_result(d, index.row(), value.value<quint32>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (set) {
|
||||||
|
emit dataChanged(index, index, QVector<int>() << role);
|
||||||
|
}
|
||||||
|
return set;
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
/* generated by rust_qt_binding_generator */
|
||||||
|
#ifndef TIMESERIES_H
|
||||||
|
#define TIMESERIES_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QAbstractItemModel>
|
||||||
|
|
||||||
|
class TimeSeries : public QAbstractItemModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
class Private;
|
||||||
|
private:
|
||||||
|
Private * const d;
|
||||||
|
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:
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
#endif // TIMESERIES_H
|
|
@ -118,17 +118,12 @@ void Tree::setPath(const QString& v) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
void tree_data_file_name(const Tree::Private*, int, quintptr, QString*, qstring_set);
|
|
||||||
bool tree_set_data_file_name(Tree::Private*, int, quintptr, qstring_t);
|
|
||||||
void tree_data_file_icon(const Tree::Private*, int, quintptr, QByteArray*, qbytearray_set);
|
void tree_data_file_icon(const Tree::Private*, int, quintptr, QByteArray*, qbytearray_set);
|
||||||
|
void tree_data_file_name(const Tree::Private*, int, quintptr, QString*, qstring_set);
|
||||||
void tree_data_file_path(const Tree::Private*, int, quintptr, QString*, qstring_set);
|
void tree_data_file_path(const Tree::Private*, int, quintptr, QString*, qstring_set);
|
||||||
bool tree_set_data_file_path(Tree::Private*, int, quintptr, qstring_t);
|
|
||||||
bool tree_set_data_file_path_none(Tree::Private*, int, quintptr);
|
|
||||||
qint32 tree_data_file_permissions(const Tree::Private*, int, quintptr);
|
qint32 tree_data_file_permissions(const Tree::Private*, int, quintptr);
|
||||||
qint32 tree_data_file_type(const Tree::Private*, int, quintptr);
|
|
||||||
option<quint64> tree_data_file_size(const Tree::Private*, int, quintptr);
|
option<quint64> tree_data_file_size(const Tree::Private*, int, quintptr);
|
||||||
bool tree_set_data_file_size(Tree::Private*, int, quintptr, quint64);
|
qint32 tree_data_file_type(const Tree::Private*, int, quintptr);
|
||||||
bool tree_set_data_file_size_none(Tree::Private*, int, quintptr);
|
|
||||||
void tree_sort(Tree::Private*, int column, Qt::SortOrder order = Qt::AscendingOrder);
|
void tree_sort(Tree::Private*, int column, Qt::SortOrder order = Qt::AscendingOrder);
|
||||||
|
|
||||||
int tree_row_count(const Tree::Private*, int, quintptr);
|
int tree_row_count(const Tree::Private*, int, quintptr);
|
||||||
|
@ -196,15 +191,6 @@ void Tree::sort(int column, Qt::SortOrder order)
|
||||||
Qt::ItemFlags Tree::flags(const QModelIndex &i) const
|
Qt::ItemFlags Tree::flags(const QModelIndex &i) const
|
||||||
{
|
{
|
||||||
auto flags = QAbstractItemModel::flags(i);
|
auto flags = QAbstractItemModel::flags(i);
|
||||||
if (i.column() == 0) {
|
|
||||||
flags |= Qt::ItemIsEditable;
|
|
||||||
}
|
|
||||||
if (i.column() == 1) {
|
|
||||||
flags |= Qt::ItemIsEditable;
|
|
||||||
}
|
|
||||||
if (i.column() == 4) {
|
|
||||||
flags |= Qt::ItemIsEditable;
|
|
||||||
}
|
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
QVariant Tree::data(const QModelIndex &index, int role) const
|
QVariant Tree::data(const QModelIndex &index, int role) const
|
||||||
|
@ -215,122 +201,151 @@ QVariant Tree::data(const QModelIndex &index, int role) const
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 0:
|
case 0:
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::DisplayRole:
|
case 256:
|
||||||
tree_data_file_name(d, index.row(), index.internalId(), &s, set_qstring);
|
case 1:
|
||||||
if (!s.isNull()) v.setValue<QString>(s);
|
|
||||||
break;
|
|
||||||
case Qt::EditRole:
|
|
||||||
tree_data_file_name(d, index.row(), index.internalId(), &s, set_qstring);
|
|
||||||
if (!s.isNull()) v.setValue<QString>(s);
|
|
||||||
break;
|
|
||||||
case Qt::DecorationRole:
|
|
||||||
tree_data_file_icon(d, index.row(), index.internalId(), &b, set_qbytearray);
|
tree_data_file_icon(d, index.row(), index.internalId(), &b, set_qbytearray);
|
||||||
if (!b.isNull()) v.setValue<QByteArray>(b);
|
if (!b.isNull()) v.setValue<QByteArray>(b);
|
||||||
break;
|
break;
|
||||||
case Qt::UserRole + 1:
|
case 257:
|
||||||
tree_data_file_path(d, index.row(), index.internalId(), &s, set_qstring);
|
case 0:
|
||||||
if (!s.isNull()) v.setValue<QString>(s);
|
|
||||||
break;
|
|
||||||
case Qt::UserRole + 2:
|
|
||||||
tree_data_file_name(d, index.row(), index.internalId(), &s, set_qstring);
|
tree_data_file_name(d, index.row(), index.internalId(), &s, set_qstring);
|
||||||
if (!s.isNull()) v.setValue<QString>(s);
|
if (!s.isNull()) v.setValue<QString>(s);
|
||||||
break;
|
break;
|
||||||
case Qt::UserRole + 3:
|
case 258:
|
||||||
|
tree_data_file_path(d, index.row(), index.internalId(), &s, set_qstring);
|
||||||
|
if (!s.isNull()) v.setValue<QString>(s);
|
||||||
|
break;
|
||||||
|
case 259:
|
||||||
v = tree_data_file_permissions(d, index.row(), index.internalId());
|
v = tree_data_file_permissions(d, index.row(), index.internalId());
|
||||||
break;
|
break;
|
||||||
case Qt::UserRole + 4:
|
case 260:
|
||||||
v = tree_data_file_type(d, index.row(), index.internalId());
|
|
||||||
break;
|
|
||||||
case Qt::UserRole + 5:
|
|
||||||
v = tree_data_file_size(d, index.row(), index.internalId());
|
v = tree_data_file_size(d, index.row(), index.internalId());
|
||||||
break;
|
break;
|
||||||
|
case 261:
|
||||||
|
v = tree_data_file_type(d, index.row(), index.internalId());
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::DisplayRole:
|
case 256:
|
||||||
|
tree_data_file_icon(d, index.row(), index.internalId(), &b, set_qbytearray);
|
||||||
|
if (!b.isNull()) v.setValue<QByteArray>(b);
|
||||||
|
break;
|
||||||
|
case 257:
|
||||||
|
tree_data_file_name(d, index.row(), index.internalId(), &s, set_qstring);
|
||||||
|
if (!s.isNull()) v.setValue<QString>(s);
|
||||||
|
break;
|
||||||
|
case 258:
|
||||||
tree_data_file_path(d, index.row(), index.internalId(), &s, set_qstring);
|
tree_data_file_path(d, index.row(), index.internalId(), &s, set_qstring);
|
||||||
if (!s.isNull()) v.setValue<QString>(s);
|
if (!s.isNull()) v.setValue<QString>(s);
|
||||||
break;
|
break;
|
||||||
case Qt::EditRole:
|
case 259:
|
||||||
tree_data_file_path(d, index.row(), index.internalId(), &s, set_qstring);
|
v = tree_data_file_permissions(d, index.row(), index.internalId());
|
||||||
if (!s.isNull()) v.setValue<QString>(s);
|
break;
|
||||||
|
case 260:
|
||||||
|
case 0:
|
||||||
|
v = tree_data_file_size(d, index.row(), index.internalId());
|
||||||
|
break;
|
||||||
|
case 261:
|
||||||
|
v = tree_data_file_type(d, index.row(), index.internalId());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::DisplayRole:
|
case 256:
|
||||||
|
tree_data_file_icon(d, index.row(), index.internalId(), &b, set_qbytearray);
|
||||||
|
if (!b.isNull()) v.setValue<QByteArray>(b);
|
||||||
|
break;
|
||||||
|
case 257:
|
||||||
|
tree_data_file_name(d, index.row(), index.internalId(), &s, set_qstring);
|
||||||
|
if (!s.isNull()) v.setValue<QString>(s);
|
||||||
|
break;
|
||||||
|
case 258:
|
||||||
|
case 0:
|
||||||
|
tree_data_file_path(d, index.row(), index.internalId(), &s, set_qstring);
|
||||||
|
if (!s.isNull()) v.setValue<QString>(s);
|
||||||
|
break;
|
||||||
|
case 259:
|
||||||
v = tree_data_file_permissions(d, index.row(), index.internalId());
|
v = tree_data_file_permissions(d, index.row(), index.internalId());
|
||||||
break;
|
break;
|
||||||
|
case 260:
|
||||||
|
v = tree_data_file_size(d, index.row(), index.internalId());
|
||||||
|
break;
|
||||||
|
case 261:
|
||||||
|
v = tree_data_file_type(d, index.row(), index.internalId());
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::DisplayRole:
|
case 256:
|
||||||
|
tree_data_file_icon(d, index.row(), index.internalId(), &b, set_qbytearray);
|
||||||
|
if (!b.isNull()) v.setValue<QByteArray>(b);
|
||||||
|
break;
|
||||||
|
case 257:
|
||||||
|
tree_data_file_name(d, index.row(), index.internalId(), &s, set_qstring);
|
||||||
|
if (!s.isNull()) v.setValue<QString>(s);
|
||||||
|
break;
|
||||||
|
case 258:
|
||||||
|
tree_data_file_path(d, index.row(), index.internalId(), &s, set_qstring);
|
||||||
|
if (!s.isNull()) v.setValue<QString>(s);
|
||||||
|
break;
|
||||||
|
case 259:
|
||||||
|
case 0:
|
||||||
|
v = tree_data_file_permissions(d, index.row(), index.internalId());
|
||||||
|
break;
|
||||||
|
case 260:
|
||||||
|
v = tree_data_file_size(d, index.row(), index.internalId());
|
||||||
|
break;
|
||||||
|
case 261:
|
||||||
v = tree_data_file_type(d, index.row(), index.internalId());
|
v = tree_data_file_type(d, index.row(), index.internalId());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::DisplayRole:
|
case 256:
|
||||||
|
tree_data_file_icon(d, index.row(), index.internalId(), &b, set_qbytearray);
|
||||||
|
if (!b.isNull()) v.setValue<QByteArray>(b);
|
||||||
|
break;
|
||||||
|
case 257:
|
||||||
|
tree_data_file_name(d, index.row(), index.internalId(), &s, set_qstring);
|
||||||
|
if (!s.isNull()) v.setValue<QString>(s);
|
||||||
|
break;
|
||||||
|
case 258:
|
||||||
|
tree_data_file_path(d, index.row(), index.internalId(), &s, set_qstring);
|
||||||
|
if (!s.isNull()) v.setValue<QString>(s);
|
||||||
|
break;
|
||||||
|
case 259:
|
||||||
|
v = tree_data_file_permissions(d, index.row(), index.internalId());
|
||||||
|
break;
|
||||||
|
case 260:
|
||||||
v = tree_data_file_size(d, index.row(), index.internalId());
|
v = tree_data_file_size(d, index.row(), index.internalId());
|
||||||
break;
|
break;
|
||||||
|
case 261:
|
||||||
|
case 0:
|
||||||
|
v = tree_data_file_type(d, index.row(), index.internalId());
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
QHash<int, QByteArray> Tree::roleNames() const {
|
QHash<int, QByteArray> Tree::roleNames() const {
|
||||||
QHash<int, QByteArray> names;
|
QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
|
||||||
names.insert(Qt::DisplayRole, "fileName");
|
names.insert(256, "fileIcon");
|
||||||
names.insert(Qt::DecorationRole, "fileIcon");
|
names.insert(257, "fileName");
|
||||||
names.insert(Qt::UserRole + 1, "filePath");
|
names.insert(258, "filePath");
|
||||||
names.insert(Qt::UserRole + 3, "filePermissions");
|
names.insert(259, "filePermissions");
|
||||||
names.insert(Qt::UserRole + 4, "fileType");
|
names.insert(260, "fileSize");
|
||||||
names.insert(Qt::UserRole + 5, "fileSize");
|
names.insert(261, "fileType");
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
bool Tree::setData(const QModelIndex &index, const QVariant &value, int role)
|
bool Tree::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
{
|
{
|
||||||
bool set = false;
|
bool set = false;
|
||||||
if (index.column() == 0) {
|
|
||||||
if (role == Qt::DisplayRole) {
|
|
||||||
set = tree_set_data_file_name(d, index.row(), index.internalId(), value.value<QString>());
|
|
||||||
}
|
|
||||||
if (role == Qt::EditRole) {
|
|
||||||
set = tree_set_data_file_name(d, index.row(), index.internalId(), value.value<QString>());
|
|
||||||
}
|
|
||||||
if (role == Qt::UserRole + 1) {
|
|
||||||
if (!value.isValid() || value.isNull()) {
|
|
||||||
set = tree_set_data_file_path_none(d, index.row(), index.internalId());
|
|
||||||
} else
|
|
||||||
set = tree_set_data_file_path(d, index.row(), index.internalId(), value.value<QString>());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (index.column() == 1) {
|
|
||||||
if (role == Qt::DisplayRole) {
|
|
||||||
if (!value.isValid() || value.isNull()) {
|
|
||||||
set = tree_set_data_file_path_none(d, index.row(), index.internalId());
|
|
||||||
} else
|
|
||||||
set = tree_set_data_file_path(d, index.row(), index.internalId(), value.value<QString>());
|
|
||||||
}
|
|
||||||
if (role == Qt::EditRole) {
|
|
||||||
if (!value.isValid() || value.isNull()) {
|
|
||||||
set = tree_set_data_file_path_none(d, index.row(), index.internalId());
|
|
||||||
} else
|
|
||||||
set = tree_set_data_file_path(d, index.row(), index.internalId(), value.value<QString>());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (index.column() == 4) {
|
|
||||||
if (role == Qt::DisplayRole) {
|
|
||||||
if (!value.isValid()) {
|
|
||||||
set = tree_set_data_file_size_none(d, index.row(), index.internalId());
|
|
||||||
} else
|
|
||||||
set = tree_set_data_file_size(d, index.row(), index.internalId(), value.value<quint64>());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (set) {
|
if (set) {
|
||||||
emit dataChanged(index, index, QVector<int>() << role);
|
emit dataChanged(index, index, QVector<int>() << role);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
#include "Tree.h"
|
#include "Tree.h"
|
||||||
#include "Fibonacci.h"
|
#include "Fibonacci.h"
|
||||||
|
#include "TimeSeries.h"
|
||||||
|
|
||||||
#ifdef QTQUICK
|
#ifdef QT_CHARTS_LIB
|
||||||
|
#include <QtCharts>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef QT_QUICK_LIB
|
||||||
#include <QQmlApplicationEngine>
|
#include <QQmlApplicationEngine>
|
||||||
#include <QtQml/qqml.h>
|
#include <QtQml/qqml.h>
|
||||||
#include <QQmlContext>
|
#include <QQmlContext>
|
||||||
|
@ -19,21 +24,24 @@
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QListView>
|
#include <QListView>
|
||||||
|
#include <QTableView>
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
#include <QStringListModel>
|
#include <QStringListModel>
|
||||||
#include <QStyleFactory>
|
#include <QStyleFactory>
|
||||||
#include <QTabWidget>
|
#include <QTabWidget>
|
||||||
#include <QTreeView>
|
#include <QTreeView>
|
||||||
|
#include <QVBoxLayout>
|
||||||
#include <QWindow>
|
#include <QWindow>
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
struct Models {
|
struct Models {
|
||||||
Tree tree;
|
QStringListModel styles;
|
||||||
QSortFilterProxyModel sortedTree;
|
|
||||||
Fibonacci fibonacci;
|
Fibonacci fibonacci;
|
||||||
FibonacciList fibonacciList;
|
FibonacciList fibonacciList;
|
||||||
QStringListModel styles;
|
Tree tree;
|
||||||
|
QSortFilterProxyModel sortedTree;
|
||||||
|
TimeSeries timeSeries;
|
||||||
};
|
};
|
||||||
|
|
||||||
void setStyle(QWidget* w, QStyle* style) {
|
void setStyle(QWidget* w, QStyle* style) {
|
||||||
|
@ -54,7 +62,7 @@ QWindow* getWindow(QWidget* w) {
|
||||||
return top->windowHandle();
|
return top->windowHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef QTQUICK
|
#ifdef QT_QUICK_LIB
|
||||||
|
|
||||||
void copyWindowGeometry(QWidget* w, QQmlContext* c) {
|
void copyWindowGeometry(QWidget* w, QQmlContext* c) {
|
||||||
QWindow* window = getWindow(w);
|
QWindow* window = getWindow(w);
|
||||||
|
@ -94,7 +102,7 @@ QComboBox* createStyleComboBox(Models* models) {
|
||||||
box->setCurrentText(v);
|
box->setCurrentText(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef QTQUICK
|
#ifdef QT_QUICK_LIB
|
||||||
box->addItem("QtQuick");
|
box->addItem("QtQuick");
|
||||||
#endif
|
#endif
|
||||||
#ifdef QTQUICKCONTROLS2
|
#ifdef QTQUICKCONTROLS2
|
||||||
|
@ -118,7 +126,7 @@ QWidget* createStyleTab(Models* models, QWidget* tabs) {
|
||||||
window->setHeight(windowRect.height());
|
window->setHeight(windowRect.height());
|
||||||
}
|
}
|
||||||
setStyle(tabs, QStyleFactory::create(text.mid(9)));
|
setStyle(tabs, QStyleFactory::create(text.mid(9)));
|
||||||
#ifdef QTQUICK
|
#ifdef QT_QUICK_LIB
|
||||||
} else {
|
} else {
|
||||||
if (window) {
|
if (window) {
|
||||||
windowRect.setX(window->x());
|
windowRect.setX(window->x());
|
||||||
|
@ -188,6 +196,47 @@ QWidget* createTreeTab(Models* models) {
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef QT_CHARTS_LIB
|
||||||
|
|
||||||
|
using namespace QtCharts;
|
||||||
|
|
||||||
|
QWidget* createChartTab(Models* models) {
|
||||||
|
QLineSeries *series = new QLineSeries();
|
||||||
|
series->setName("Line 1");
|
||||||
|
QVXYModelMapper *mapper = new QVXYModelMapper(series);
|
||||||
|
mapper->setXColumn(0);
|
||||||
|
mapper->setYColumn(1);
|
||||||
|
mapper->setSeries(series);
|
||||||
|
mapper->setModel(&models->timeSeries);
|
||||||
|
|
||||||
|
QChart* chart = new QChart;
|
||||||
|
chart->addSeries(series);
|
||||||
|
QDateTimeAxis *axisX = new QDateTimeAxis;
|
||||||
|
axisX->setTickCount(10);
|
||||||
|
axisX->setFormat("MMM yyyy");
|
||||||
|
axisX->setTitleText("Date");
|
||||||
|
chart->addAxis(axisX, Qt::AlignBottom);
|
||||||
|
series->attachAxis(axisX);
|
||||||
|
|
||||||
|
QValueAxis *axisY = new QValueAxis;
|
||||||
|
axisY->setLabelFormat("%i");
|
||||||
|
axisY->setTitleText("Sunspots count");
|
||||||
|
chart->addAxis(axisY, Qt::AlignLeft);
|
||||||
|
series->attachAxis(axisY);
|
||||||
|
|
||||||
|
QWidget* view = new QWidget;
|
||||||
|
QTableView* data = new QTableView;
|
||||||
|
data->setModel(&models->timeSeries);
|
||||||
|
QChartView *chartView = new QChartView(chart);
|
||||||
|
|
||||||
|
QHBoxLayout *layout = new QHBoxLayout;
|
||||||
|
layout->addWidget(data);
|
||||||
|
layout->addWidget(chartView);
|
||||||
|
view->setLayout(layout);
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void createWidgets(Models* models) {
|
void createWidgets(Models* models) {
|
||||||
QTabWidget* tabs = new QTabWidget();
|
QTabWidget* tabs = new QTabWidget();
|
||||||
|
|
||||||
|
@ -195,6 +244,9 @@ void createWidgets(Models* models) {
|
||||||
tabs->addTab(createObjectTab(models), "object");
|
tabs->addTab(createObjectTab(models), "object");
|
||||||
tabs->addTab(createListTab(models), "list");
|
tabs->addTab(createListTab(models), "list");
|
||||||
tabs->addTab(createTreeTab(models), "tree");
|
tabs->addTab(createTreeTab(models), "tree");
|
||||||
|
#ifdef QT_CHARTS_LIB
|
||||||
|
tabs->addTab(createChartTab(models), "chart");
|
||||||
|
#endif
|
||||||
tabs->setMinimumSize(QSize(500, 500));
|
tabs->setMinimumSize(QSize(500, 500));
|
||||||
tabs->show();
|
tabs->show();
|
||||||
}
|
}
|
||||||
|
@ -203,7 +255,7 @@ int main (int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
#ifdef QTQUICK
|
#ifdef QT_QUICK_LIB
|
||||||
|
|
||||||
qmlRegisterType<QSortFilterProxyModel>("org.qtproject.example", 1, 0, "SortFilterProxyModel");
|
qmlRegisterType<QSortFilterProxyModel>("org.qtproject.example", 1, 0, "SortFilterProxyModel");
|
||||||
qmlRegisterType<Fibonacci>("rust", 1, 0, "Fibonacci");
|
qmlRegisterType<Fibonacci>("rust", 1, 0, "Fibonacci");
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
{
|
||||||
|
"cppFile": "src/TimeSeries.cpp",
|
||||||
|
"rust": {
|
||||||
|
"dir": "rust",
|
||||||
|
"interfaceModule": "time_series_interface",
|
||||||
|
"implementationModule": "time_series_implementation",
|
||||||
|
"typesModule": "time_series_types"
|
||||||
|
},
|
||||||
|
"objects": {
|
||||||
|
"TimeSeries": {
|
||||||
|
"type": "List",
|
||||||
|
"itemProperties": {
|
||||||
|
"input": {
|
||||||
|
"type": "quint32",
|
||||||
|
"write": true,
|
||||||
|
"roles": [ [ "display", "edit" ] ]
|
||||||
|
},
|
||||||
|
"result": {
|
||||||
|
"type": "quint32",
|
||||||
|
"write": true,
|
||||||
|
"roles": [ [], [ "display", "edit" ] ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
120
demo/tree.json
120
demo/tree.json
|
@ -6,84 +6,44 @@
|
||||||
"implementationModule": "implementation",
|
"implementationModule": "implementation",
|
||||||
"typesModule": "types"
|
"typesModule": "types"
|
||||||
},
|
},
|
||||||
"objects": [{
|
"objects": {
|
||||||
"name": "Tree",
|
"Tree": {
|
||||||
"type": "UniformTree",
|
"type": "UniformTree",
|
||||||
"properties": [{
|
"properties": {
|
||||||
"name": "path",
|
"path": {
|
||||||
"type": "QString",
|
"type": "QString",
|
||||||
"write": true,
|
"write": true,
|
||||||
"optional": true
|
"optional": true
|
||||||
}],
|
}
|
||||||
"roles": [
|
},
|
||||||
[{
|
"itemProperties": {
|
||||||
"name": "fileName",
|
"fileName": {
|
||||||
"value": "Qt::DisplayRole",
|
"type": "QString",
|
||||||
"type": "QString",
|
"roles": [ ["display"] ]
|
||||||
"write": true
|
},
|
||||||
}, {
|
"fileIcon": {
|
||||||
"name": "fileName",
|
"type": "QByteArray",
|
||||||
"value": "Qt::EditRole",
|
"roles": [ ["decoration"] ]
|
||||||
"type": "QString",
|
},
|
||||||
"write": true
|
"fileSize": {
|
||||||
}, {
|
"type": "quint64",
|
||||||
"name": "fileIcon",
|
"optional": true,
|
||||||
"value": "Qt::DecorationRole",
|
"roles": [ [], ["display"] ]
|
||||||
"type": "QByteArray"
|
},
|
||||||
}, {
|
"filePath": {
|
||||||
"name": "filePath",
|
"type": "QString",
|
||||||
"value": "Qt::UserRole + 1",
|
"optional": true,
|
||||||
"type": "QString",
|
"roles": [ [], [], ["display"] ]
|
||||||
"write": true,
|
},
|
||||||
"optional": true
|
"filePermissions": {
|
||||||
}, {
|
"type": "qint32",
|
||||||
"name": "fileName",
|
"roles": [ [], [], [], ["display"] ]
|
||||||
"value": "Qt::UserRole + 2",
|
},
|
||||||
"type": "QString"
|
"fileType": {
|
||||||
}, {
|
"type": "qint32",
|
||||||
"name": "filePermissions",
|
"roles": [ [], [], [], [],["display"] ]
|
||||||
"value": "Qt::UserRole + 3",
|
}
|
||||||
"type": "qint32"
|
}
|
||||||
}, {
|
}
|
||||||
"name": "fileType",
|
}
|
||||||
"value": "Qt::UserRole + 4",
|
|
||||||
"type": "qint32"
|
|
||||||
}, {
|
|
||||||
"name": "fileSize",
|
|
||||||
"value": "Qt::UserRole + 5",
|
|
||||||
"type": "quint64",
|
|
||||||
"optional": true
|
|
||||||
}],
|
|
||||||
[{
|
|
||||||
"name": "filePath",
|
|
||||||
"value": "Qt::DisplayRole",
|
|
||||||
"type": "QString",
|
|
||||||
"write": true,
|
|
||||||
"optional": true
|
|
||||||
}, {
|
|
||||||
"name": "filePath",
|
|
||||||
"value": "Qt::EditRole",
|
|
||||||
"type": "QString",
|
|
||||||
"write": true,
|
|
||||||
"optional": true
|
|
||||||
}],
|
|
||||||
[{
|
|
||||||
"name": "filePermissions",
|
|
||||||
"value": "Qt::DisplayRole",
|
|
||||||
"type": "qint32"
|
|
||||||
}],
|
|
||||||
[{
|
|
||||||
"name": "fileType",
|
|
||||||
"value": "Qt::DisplayRole",
|
|
||||||
"type": "qint32"
|
|
||||||
}],
|
|
||||||
[{
|
|
||||||
"name": "fileSize",
|
|
||||||
"value": "Qt::DisplayRole",
|
|
||||||
"type": "quint64",
|
|
||||||
"write": true,
|
|
||||||
"optional": true
|
|
||||||
}]
|
|
||||||
]
|
|
||||||
}]
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <QCommandLineParser>
|
#include <QCommandLineParser>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QMetaEnum>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
@ -99,20 +100,21 @@ struct Property {
|
||||||
bool optional;
|
bool optional;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Role {
|
struct ItemProperty {
|
||||||
QString name;
|
QString name;
|
||||||
QString value;
|
|
||||||
BindingTypeProperties type;
|
BindingTypeProperties type;
|
||||||
bool write;
|
bool write;
|
||||||
bool optional;
|
bool optional;
|
||||||
|
int userRole;
|
||||||
|
QList<QList<Qt::ItemDataRole>> roles;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Object {
|
struct Object {
|
||||||
QString name;
|
QString name;
|
||||||
ObjectType type;
|
ObjectType type;
|
||||||
QList<Property> properties;
|
QList<Property> properties;
|
||||||
QList<QList<Role>> columnRoles;
|
QList<ItemProperty> itemProperties;
|
||||||
QList<Role> allRoles;
|
int columnCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Configuration {
|
struct Configuration {
|
||||||
|
@ -180,56 +182,51 @@ QString rustTypeInit(const T& p)
|
||||||
}
|
}
|
||||||
|
|
||||||
Property
|
Property
|
||||||
parseProperty(const QJsonObject& json) {
|
parseProperty(const QString& name, const QJsonObject& json) {
|
||||||
Property p;
|
Property p;
|
||||||
p.name = json.value("name").toString();
|
p.name = name;
|
||||||
p.type = parseBindingType(json.value("type").toString());
|
p.type = parseBindingType(json.value("type").toString());
|
||||||
p.write = json.value("write").toBool();
|
p.write = json.value("write").toBool();
|
||||||
p.optional = json.value("optional").toBool();
|
p.optional = json.value("optional").toBool();
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
Role
|
Qt::ItemDataRole parseItemDataRole(const QString& s) {
|
||||||
parseRole(const QJsonObject& json) {
|
const QString name = s.left(1).toUpper() + s.mid(1) + "Role";
|
||||||
Role r;
|
int v = QMetaEnum::fromType<Qt::ItemDataRole>()
|
||||||
r.name = json.value("name").toString();
|
.keyToValue(name.toUtf8());
|
||||||
r.value = json.value("value").toString();
|
if (v >= 0) {
|
||||||
r.type = parseBindingType(json.value("type").toString());
|
return (Qt::ItemDataRole)v;
|
||||||
r.write = json.value("write").toBool();
|
}
|
||||||
r.optional = json.value("optional").toBool();
|
err << QCoreApplication::translate("main",
|
||||||
return r;
|
"%1 is not a valid role name.\n").arg(s);
|
||||||
|
err.flush();
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Role> parseRoles(const QJsonArray& roles, QList<Role>& all) {
|
ItemProperty
|
||||||
QList<Role> r;
|
parseItemProperty(const QString& name, const QJsonObject& json, int userRole) {
|
||||||
for (const QJsonValue& val: roles) {
|
ItemProperty ip;
|
||||||
const Role role = parseRole(val.toObject());
|
ip.name = name;
|
||||||
r.append(role);
|
ip.type = parseBindingType(json.value("type").toString());
|
||||||
bool found = false;
|
ip.write = json.value("write").toBool();
|
||||||
for (Role& ar: all) {
|
ip.optional = json.value("optional").toBool();
|
||||||
if (ar.name == role.name) {
|
ip.userRole = userRole;
|
||||||
found = true;
|
QJsonArray roles = json.value("roles").toArray();
|
||||||
ar.write |= role.write;
|
for (auto r: roles) {
|
||||||
if (ar.type.name != role.type.name) {
|
QList<Qt::ItemDataRole> l;
|
||||||
err << QCoreApplication::translate("main",
|
for (auto v: r.toArray()) {
|
||||||
"Role %1 has two different types: %2 and %3.\n")
|
l.append(parseItemDataRole(v.toString()));
|
||||||
.arg(ar.name, ar.type.name, role.type.name);
|
|
||||||
err.flush();
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found) {
|
|
||||||
all.append(role);
|
|
||||||
}
|
}
|
||||||
|
ip.roles.append(l);
|
||||||
}
|
}
|
||||||
return r;
|
return ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object
|
Object
|
||||||
parseObject(const QJsonObject& json) {
|
parseObject(const QString& name, const QJsonObject& json) {
|
||||||
Object o;
|
Object o;
|
||||||
o.name = json.value("name").toString();
|
o.name = name;
|
||||||
QString type = json.value("type").toString();
|
QString type = json.value("type").toString();
|
||||||
if (type == "List") {
|
if (type == "List") {
|
||||||
o.type = ObjectType::List;
|
o.type = ObjectType::List;
|
||||||
|
@ -238,22 +235,28 @@ parseObject(const QJsonObject& json) {
|
||||||
} else {
|
} else {
|
||||||
o.type = ObjectType::Object;
|
o.type = ObjectType::Object;
|
||||||
}
|
}
|
||||||
for (const QJsonValue& val: json.value("properties").toArray()) {
|
const QJsonObject& properties = json.value("properties").toObject();
|
||||||
o.properties.append(parseProperty(val.toObject()));
|
for (const QString& key: properties.keys()) {
|
||||||
|
o.properties.append(parseProperty(key, properties[key].toObject()));
|
||||||
}
|
}
|
||||||
QJsonArray roles = json.value("roles").toArray();
|
const QJsonObject& itemProperties = json.value("itemProperties").toObject();
|
||||||
if (o.type != ObjectType::Object && roles.size() == 0) {
|
if (o.type != ObjectType::Object && itemProperties.size() == 0) {
|
||||||
err << QCoreApplication::translate("main",
|
err << QCoreApplication::translate("main",
|
||||||
"No roles are defined for %1.\n").arg(o.name);
|
"No item properties are defined for %1.\n").arg(o.name);
|
||||||
|
err.flush();
|
||||||
|
exit(1);
|
||||||
|
} else if (o.type == ObjectType::Object && itemProperties.size() > 0) {
|
||||||
|
err << QCoreApplication::translate("main",
|
||||||
|
"%1 is an Object and should not have itemProperties.").arg(o.name);
|
||||||
err.flush();
|
err.flush();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (roles.at(0).isArray()) {
|
o.columnCount = 0;
|
||||||
for (const QJsonValue& val: roles) {
|
for (const QString& key: itemProperties.keys()) {
|
||||||
o.columnRoles.append(parseRoles(val.toArray(), o.allRoles));
|
ItemProperty p = parseItemProperty(key, itemProperties[key].toObject(),
|
||||||
}
|
Qt::UserRole + o.itemProperties.size());
|
||||||
} else {
|
o.columnCount = qMax(o.columnCount, p.roles.size());
|
||||||
o.columnRoles.append(parseRoles(roles, o.allRoles));
|
o.itemProperties.append(p);
|
||||||
}
|
}
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
@ -281,8 +284,9 @@ parseConfiguration(const QString& path) {
|
||||||
c.cppFile = QFileInfo(base, o.value("cppFile").toString());
|
c.cppFile = QFileInfo(base, o.value("cppFile").toString());
|
||||||
QDir(c.cppFile.dir()).mkpath(".");
|
QDir(c.cppFile.dir()).mkpath(".");
|
||||||
c.hFile = QFileInfo(c.cppFile.dir(), c.cppFile.completeBaseName() + ".h");
|
c.hFile = QFileInfo(c.cppFile.dir(), c.cppFile.completeBaseName() + ".h");
|
||||||
for (const QJsonValue& val: o.value("objects").toArray()) {
|
const QJsonObject& object = o.value("objects").toObject();
|
||||||
c.objects.append(parseObject(val.toObject()));
|
for (const QString& key: object.keys()) {
|
||||||
|
c.objects.append(parseObject(key, object[key].toObject()));
|
||||||
}
|
}
|
||||||
const QJsonObject rust = o.value("rust").toObject();
|
const QJsonObject rust = o.value("rust").toObject();
|
||||||
c.rustdir = QDir(base.filePath(rust.value("dir").toString()));
|
c.rustdir = QDir(base.filePath(rust.value("dir").toString()));
|
||||||
|
@ -336,12 +340,13 @@ signals:
|
||||||
)");
|
)");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isWrite(const QList<Role>& roles) {
|
bool isColumnWrite(const Object& o, int col) {
|
||||||
bool write = false;
|
for (auto ip: o.itemProperties) {
|
||||||
for (auto role: roles) {
|
if (ip.write && ip.roles.size() > col && ip.roles[col].size() > 0) {
|
||||||
write = write | role.write;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return write;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeCppModel(QTextStream& cpp, const Object& o) {
|
void writeCppModel(QTextStream& cpp, const Object& o) {
|
||||||
|
@ -354,20 +359,20 @@ void writeCppModel(QTextStream& cpp, const Object& o) {
|
||||||
}
|
}
|
||||||
|
|
||||||
cpp << "extern \"C\" {\n";
|
cpp << "extern \"C\" {\n";
|
||||||
for (auto role: o.allRoles) {
|
for (auto ip: o.itemProperties) {
|
||||||
if (role.type.isComplex()) {
|
if (ip.type.isComplex()) {
|
||||||
cpp << QString(" void %2_data_%3(const %1::Private*%5, %4);\n")
|
cpp << QString(" void %2_data_%3(const %1::Private*%5, %4);\n")
|
||||||
.arg(o.name, lcname, snakeCase(role.name), cGetType(role.type), indexDecl);
|
.arg(o.name, lcname, snakeCase(ip.name), cGetType(ip.type), indexDecl);
|
||||||
} else {
|
} else {
|
||||||
cpp << QString(" %4 %2_data_%3(const %1::Private*%5);\n")
|
cpp << QString(" %4 %2_data_%3(const %1::Private*%5);\n")
|
||||||
.arg(o.name, lcname, snakeCase(role.name), cppSetType(role), indexDecl);
|
.arg(o.name, lcname, snakeCase(ip.name), cppSetType(ip), indexDecl);
|
||||||
}
|
}
|
||||||
if (role.write) {
|
if (ip.write) {
|
||||||
cpp << QString(" bool %2_set_data_%3(%1::Private*%5, %4);")
|
cpp << QString(" bool %2_set_data_%3(%1::Private*%5, %4);")
|
||||||
.arg(o.name, lcname, snakeCase(role.name), role.type.cSetType, indexDecl) << endl;
|
.arg(o.name, lcname, snakeCase(ip.name), ip.type.cSetType, indexDecl) << endl;
|
||||||
if (role.optional) {
|
if (ip.optional) {
|
||||||
cpp << QString(" bool %2_set_data_%3_none(%1::Private*%4);")
|
cpp << QString(" bool %2_set_data_%3_none(%1::Private*%4);")
|
||||||
.arg(o.name, lcname, snakeCase(role.name), indexDecl) << endl;
|
.arg(o.name, lcname, snakeCase(ip.name), indexDecl) << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -395,8 +400,8 @@ int %1::rowCount(const QModelIndex &parent) const
|
||||||
|
|
||||||
QModelIndex %1::index(int row, int column, const QModelIndex &parent) const
|
QModelIndex %1::index(int row, int column, const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
if (!parent.isValid() && column == 0) {
|
if (!parent.isValid() && row >= 0 && row < rowCount(parent) && column >= 0 && column < %3) {
|
||||||
return createIndex(row, 0, (quintptr)0);
|
return createIndex(row, column, (quintptr)0);
|
||||||
}
|
}
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
}
|
}
|
||||||
|
@ -417,7 +422,7 @@ void %1::fetchMore(const QModelIndex &parent)
|
||||||
%2_fetch_more(d);
|
%2_fetch_more(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)").arg(o.name, lcname, QString::number(o.columnRoles.size()));
|
)").arg(o.name, lcname, QString::number(o.columnCount));
|
||||||
} else {
|
} else {
|
||||||
cpp << QString(R"(
|
cpp << QString(R"(
|
||||||
int %2_row_count(const %1::Private*, int, quintptr);
|
int %2_row_count(const %1::Private*, int, quintptr);
|
||||||
|
@ -477,7 +482,7 @@ void %1::fetchMore(const QModelIndex &parent)
|
||||||
{
|
{
|
||||||
%2_fetch_more(d, parent.row(), parent.internalId());
|
%2_fetch_more(d, parent.row(), parent.internalId());
|
||||||
}
|
}
|
||||||
)").arg(o.name, lcname, QString::number(o.columnRoles.size()));
|
)").arg(o.name, lcname, QString::number(o.columnCount));
|
||||||
}
|
}
|
||||||
|
|
||||||
cpp << QString(R"(
|
cpp << QString(R"(
|
||||||
|
@ -489,8 +494,8 @@ Qt::ItemFlags %1::flags(const QModelIndex &i) const
|
||||||
{
|
{
|
||||||
auto flags = QAbstractItemModel::flags(i);
|
auto flags = QAbstractItemModel::flags(i);
|
||||||
)").arg(o.name, lcname);
|
)").arg(o.name, lcname);
|
||||||
for (int col = 0; col < o.columnRoles.size(); ++col) {
|
for (int col = 0; col < o.columnCount; ++col) {
|
||||||
if (isWrite(o.columnRoles[col])) {
|
if (isColumnWrite(o, col)) {
|
||||||
cpp << " if (i.column() == " << col << ") {\n";
|
cpp << " if (i.column() == " << col << ") {\n";
|
||||||
cpp << " flags |= Qt::ItemIsEditable;\n }\n";
|
cpp << " flags |= Qt::ItemIsEditable;\n }\n";
|
||||||
}
|
}
|
||||||
|
@ -505,23 +510,25 @@ QVariant %1::data(const QModelIndex &index, int role) const
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
)").arg(o.name);
|
)").arg(o.name);
|
||||||
|
|
||||||
for (int col = 0; col < o.columnRoles.size(); ++col) {
|
for (int col = 0; col < o.columnCount; ++col) {
|
||||||
auto roles = o.columnRoles[col];
|
|
||||||
cpp << QString(" case %1:\n").arg(col);
|
cpp << QString(" case %1:\n").arg(col);
|
||||||
cpp << QString(" switch (role) {\n");
|
cpp << QString(" switch (role) {\n");
|
||||||
for (auto role: roles) {
|
for (auto ip: o.itemProperties) {
|
||||||
cpp << QString(" case %1:\n").arg(role.value);
|
cpp << QString(" case %1:\n").arg(ip.userRole);
|
||||||
if (role.type.name == "QString") {
|
for (auto r: ip.roles.value(col)) {
|
||||||
|
cpp << QString(" case %1:\n").arg(r);
|
||||||
|
}
|
||||||
|
if (ip.type.name == "QString") {
|
||||||
cpp << QString(" %1_data_%2(d%4, &s, set_%3);\n")
|
cpp << QString(" %1_data_%2(d%4, &s, set_%3);\n")
|
||||||
.arg(lcname, snakeCase(role.name), role.type.name.toLower(), index);
|
.arg(lcname, snakeCase(ip.name), ip.type.name.toLower(), index);
|
||||||
cpp << " if (!s.isNull()) v.setValue<QString>(s);\n";
|
cpp << " if (!s.isNull()) v.setValue<QString>(s);\n";
|
||||||
} else if (role.type.name == "QByteArray") {
|
} else if (ip.type.name == "QByteArray") {
|
||||||
cpp << QString(" %1_data_%2(d%4, &b, set_%3);\n")
|
cpp << QString(" %1_data_%2(d%4, &b, set_%3);\n")
|
||||||
.arg(lcname, snakeCase(role.name), role.type.name.toLower(), index);
|
.arg(lcname, snakeCase(ip.name), ip.type.name.toLower(), index);
|
||||||
cpp << " if (!b.isNull()) v.setValue<QByteArray>(b);\n";
|
cpp << " if (!b.isNull()) v.setValue<QByteArray>(b);\n";
|
||||||
} else {
|
} else {
|
||||||
cpp << QString(" v = %1_data_%2(d%3);\n")
|
cpp << QString(" v = %1_data_%2(d%3);\n")
|
||||||
.arg(lcname, snakeCase(role.name), index);
|
.arg(lcname, snakeCase(ip.name), index);
|
||||||
}
|
}
|
||||||
cpp << " break;\n";
|
cpp << " break;\n";
|
||||||
}
|
}
|
||||||
|
@ -530,9 +537,9 @@ QVariant %1::data(const QModelIndex &index, int role) const
|
||||||
}
|
}
|
||||||
cpp << " }\n return v;\n}\n";
|
cpp << " }\n return v;\n}\n";
|
||||||
cpp << "QHash<int, QByteArray> " << o.name << "::roleNames() const {\n";
|
cpp << "QHash<int, QByteArray> " << o.name << "::roleNames() const {\n";
|
||||||
cpp << " QHash<int, QByteArray> names;\n";
|
cpp << " QHash<int, QByteArray> names = QAbstractItemModel::roleNames();\n";
|
||||||
for (auto role: o.allRoles) {
|
for (auto ip: o.itemProperties) {
|
||||||
cpp << " names.insert(" << role.value << ", \"" << role.name << "\");\n";
|
cpp << " names.insert(" << ip.userRole << ", \"" << ip.name << "\");\n";
|
||||||
}
|
}
|
||||||
cpp << " return names;\n";
|
cpp << " return names;\n";
|
||||||
cpp << QString(R"(}
|
cpp << QString(R"(}
|
||||||
|
@ -540,30 +547,33 @@ bool %1::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
{
|
{
|
||||||
)").arg(o.name);
|
)").arg(o.name);
|
||||||
cpp << " bool set = false;\n";
|
cpp << " bool set = false;\n";
|
||||||
for (int col = 0; col < o.columnRoles.size(); ++col) {
|
for (int col = 0; col < o.columnCount; ++col) {
|
||||||
if (!isWrite(o.columnRoles[col])) {
|
if (!isColumnWrite(o, col)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
cpp << " if (index.column() == " << col << ") {\n";
|
cpp << " if (index.column() == " << col << ") {\n";
|
||||||
auto roles = o.columnRoles[col];
|
for (auto ip: o.itemProperties) {
|
||||||
for (auto role: roles) {
|
if (!ip.write) {
|
||||||
if (!role.write) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
cpp << " if (role == " << role.value << ") {\n";
|
cpp << " if (role == " << ip.userRole;
|
||||||
if (role.optional) {
|
for (auto r: ip.roles.value(col)) {
|
||||||
|
cpp << QString(" || role == %1").arg(r);
|
||||||
|
}
|
||||||
|
cpp << ") {\n";
|
||||||
|
if (ip.optional) {
|
||||||
QString test = "!value.isValid()";
|
QString test = "!value.isValid()";
|
||||||
if (role.type.isComplex()) {
|
if (ip.type.isComplex()) {
|
||||||
test += " || value.isNull()";
|
test += " || value.isNull()";
|
||||||
}
|
}
|
||||||
cpp << " if (" << test << ") {\n";
|
cpp << " if (" << test << ") {\n";
|
||||||
cpp << QString(" set = %1_set_data_%2_none(d%3);")
|
cpp << QString(" set = %1_set_data_%2_none(d%3);")
|
||||||
.arg(lcname, snakeCase(role.name), index) << endl;
|
.arg(lcname, snakeCase(ip.name), index) << endl;
|
||||||
cpp << " } else\n";
|
cpp << " } else\n";
|
||||||
}
|
}
|
||||||
QString val = QString("value.value<%1>()").arg(role.type.name);
|
QString val = QString("value.value<%1>()").arg(ip.type.name);
|
||||||
cpp << QString(" set = %1_set_data_%2(d%3, %4);")
|
cpp << QString(" set = %1_set_data_%2(d%3, %4);")
|
||||||
.arg(lcname, snakeCase(role.name), index, val) << endl;
|
.arg(lcname, snakeCase(ip.name), index, val) << endl;
|
||||||
cpp << " }\n";
|
cpp << " }\n";
|
||||||
}
|
}
|
||||||
cpp << " }\n";
|
cpp << " }\n";
|
||||||
|
@ -1032,12 +1042,12 @@ pub trait %1Trait {
|
||||||
} else if (o.type == ObjectType::UniformTree) {
|
} else if (o.type == ObjectType::UniformTree) {
|
||||||
index = ", row: c_int, parent: usize";
|
index = ", row: c_int, parent: usize";
|
||||||
}
|
}
|
||||||
for (auto role: o.allRoles) {
|
for (auto ip: o.itemProperties) {
|
||||||
r << QString(" fn %1(&self%3) -> %2;\n")
|
r << QString(" fn %1(&self%3) -> %2;\n")
|
||||||
.arg(snakeCase(role.name), rustType(role), index);
|
.arg(snakeCase(ip.name), rustType(ip), index);
|
||||||
if (role.write) {
|
if (ip.write) {
|
||||||
r << QString(" fn set_%1(&mut self%3, %2) -> bool;\n")
|
r << QString(" fn set_%1(&mut self%3, %2) -> bool;\n")
|
||||||
.arg(snakeCase(role.name), rustType(role), index);
|
.arg(snakeCase(ip.name), rustType(ip), index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1207,8 +1217,8 @@ pub unsafe extern "C" fn %2_sort(ptr: *mut %1, column: c_int, order: SortOrder)
|
||||||
indexDecl = ", parent: usize";
|
indexDecl = ", parent: usize";
|
||||||
index = ", parent";
|
index = ", parent";
|
||||||
}
|
}
|
||||||
for (auto role: o.allRoles) {
|
for (auto ip: o.itemProperties) {
|
||||||
if (role.type.isComplex() && !role.optional) {
|
if (ip.type.isComplex() && !ip.optional) {
|
||||||
r << QString(R"(
|
r << QString(R"(
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn %2_data_%3(ptr: *const %1,
|
pub unsafe extern "C" fn %2_data_%3(ptr: *const %1,
|
||||||
|
@ -1218,8 +1228,8 @@ pub unsafe extern "C" fn %2_data_%3(ptr: *const %1,
|
||||||
let data = (&*ptr).%3(row%6);
|
let data = (&*ptr).%3(row%6);
|
||||||
set(d, %4::from(&data));
|
set(d, %4::from(&data));
|
||||||
}
|
}
|
||||||
)").arg(o.name, lcname, snakeCase(role.name), role.type.name, indexDecl, index);
|
)").arg(o.name, lcname, snakeCase(ip.name), ip.type.name, indexDecl, index);
|
||||||
} else if (role.type.isComplex()) {
|
} else if (ip.type.isComplex()) {
|
||||||
r << QString(R"(
|
r << QString(R"(
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn %2_data_%3(ptr: *const %1,
|
pub unsafe extern "C" fn %2_data_%3(ptr: *const %1,
|
||||||
|
@ -1231,23 +1241,23 @@ pub unsafe extern "C" fn %2_data_%3(ptr: *const %1,
|
||||||
set(d, %4::from(&data));
|
set(d, %4::from(&data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)").arg(o.name, lcname, snakeCase(role.name), role.type.name, indexDecl, index);
|
)").arg(o.name, lcname, snakeCase(ip.name), ip.type.name, indexDecl, index);
|
||||||
} else {
|
} else {
|
||||||
r << QString(R"(
|
r << QString(R"(
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn %2_data_%3(ptr: *const %1, row: c_int%5) -> %4 {
|
pub unsafe extern "C" fn %2_data_%3(ptr: *const %1, row: c_int%5) -> %4 {
|
||||||
(&*ptr).%3(row%6).into()
|
(&*ptr).%3(row%6).into()
|
||||||
}
|
}
|
||||||
)").arg(o.name, lcname, snakeCase(role.name), rustCType(role), indexDecl, index);
|
)").arg(o.name, lcname, snakeCase(ip.name), rustCType(ip), indexDecl, index);
|
||||||
}
|
}
|
||||||
if (role.write) {
|
if (ip.write) {
|
||||||
QString val = "v";
|
QString val = "v";
|
||||||
QString type = role.type.rustType;
|
QString type = ip.type.rustType;
|
||||||
if (role.type.isComplex()) {
|
if (ip.type.isComplex()) {
|
||||||
val = val + ".convert()";
|
val = val + ".convert()";
|
||||||
type = role.type.name == "QString" ? "QStringIn" : role.type.name;
|
type = ip.type.name == "QString" ? "QStringIn" : ip.type.name;
|
||||||
}
|
}
|
||||||
if (role.optional) {
|
if (ip.optional) {
|
||||||
val = "Some(" + val + ")";
|
val = "Some(" + val + ")";
|
||||||
}
|
}
|
||||||
r << QString(R"(
|
r << QString(R"(
|
||||||
|
@ -1255,15 +1265,15 @@ pub unsafe extern "C" fn %2_data_%3(ptr: *const %1, row: c_int%5) -> %4 {
|
||||||
pub unsafe extern "C" fn %2_set_data_%3(ptr: *mut %1, row: c_int%4, v: %6) -> bool {
|
pub unsafe extern "C" fn %2_set_data_%3(ptr: *mut %1, row: c_int%4, v: %6) -> bool {
|
||||||
(&mut *ptr).set_%3(row%5, %7)
|
(&mut *ptr).set_%3(row%5, %7)
|
||||||
}
|
}
|
||||||
)").arg(o.name, lcname, snakeCase(role.name), indexDecl, index, type, val);
|
)").arg(o.name, lcname, snakeCase(ip.name), indexDecl, index, type, val);
|
||||||
}
|
}
|
||||||
if (role.write && role.optional) {
|
if (ip.write && ip.optional) {
|
||||||
r << QString(R"(
|
r << QString(R"(
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn %2_set_data_%3_none(ptr: *mut %1, row: c_int%4) -> bool {
|
pub unsafe extern "C" fn %2_set_data_%3_none(ptr: *mut %1, row: c_int%4) -> bool {
|
||||||
(&mut *ptr).set_%3(row%5, None)
|
(&mut *ptr).set_%3(row%5, None)
|
||||||
}
|
}
|
||||||
)").arg(o.name, lcname, snakeCase(role.name), indexDecl, index);
|
)").arg(o.name, lcname, snakeCase(ip.name), indexDecl, index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1313,9 +1323,9 @@ void writeRustImplementationObject(QTextStream& r, const Object& o) {
|
||||||
if (o.type != ObjectType::Object) {
|
if (o.type != ObjectType::Object) {
|
||||||
r << "#[derive (Default, Clone)]\n";
|
r << "#[derive (Default, Clone)]\n";
|
||||||
r << QString("struct %1Item {\n").arg(o.name);
|
r << QString("struct %1Item {\n").arg(o.name);
|
||||||
for (auto role: o.allRoles) {
|
for (auto ip: o.itemProperties) {
|
||||||
const QString lc(snakeCase(role.name));
|
const QString lc(snakeCase(ip.name));
|
||||||
r << QString(" %1: %2,\n").arg(lc, role.type.rustType);
|
r << QString(" %1: %2,\n").arg(lc, ip.type.rustType);
|
||||||
}
|
}
|
||||||
r << "}\n\n";
|
r << "}\n\n";
|
||||||
}
|
}
|
||||||
|
@ -1384,15 +1394,15 @@ void writeRustImplementationObject(QTextStream& r, const Object& o) {
|
||||||
if (o.type == ObjectType::UniformTree) {
|
if (o.type == ObjectType::UniformTree) {
|
||||||
index = ", parent: usize";
|
index = ", parent: usize";
|
||||||
}
|
}
|
||||||
for (auto role: o.allRoles) {
|
for (auto ip: o.itemProperties) {
|
||||||
const QString lc(snakeCase(role.name));
|
const QString lc(snakeCase(ip.name));
|
||||||
r << QString(" fn %1(&self, row: c_int%3) -> %2 {\n")
|
r << QString(" fn %1(&self, row: c_int%3) -> %2 {\n")
|
||||||
.arg(lc, rustType(role), index);
|
.arg(lc, rustType(ip), index);
|
||||||
r << " self.list[row as usize]." << lc << ".clone()\n";
|
r << " self.list[row as usize]." << lc << ".clone()\n";
|
||||||
r << " }\n";
|
r << " }\n";
|
||||||
if (role.write) {
|
if (ip.write) {
|
||||||
r << QString(" fn set_%1(&mut self, row: c_int%3, v: %2) -> bool {\n")
|
r << QString(" fn set_%1(&mut self, row: c_int%3, v: %2) -> bool {\n")
|
||||||
.arg(snakeCase(role.name), rustType(role), index);
|
.arg(snakeCase(ip.name), rustType(ip), index);
|
||||||
r << " self.list[row as usize]." << lc << " = v;\n";
|
r << " self.list[row as usize]." << lc << " = v;\n";
|
||||||
r << " true\n";
|
r << " true\n";
|
||||||
r << " }\n";
|
r << " }\n";
|
||||||
|
|
|
@ -9,13 +9,13 @@ use interface::*;
|
||||||
pub struct Object {
|
pub struct Object {
|
||||||
emit: ObjectEmitter,
|
emit: ObjectEmitter,
|
||||||
boolean: bool,
|
boolean: bool,
|
||||||
integer: i32,
|
|
||||||
uinteger: u32,
|
|
||||||
u64: u64,
|
|
||||||
string: String,
|
|
||||||
optional_string: Option<String>,
|
|
||||||
bytearray: Vec<u8>,
|
bytearray: Vec<u8>,
|
||||||
|
integer: i32,
|
||||||
optional_bytearray: Option<Vec<u8>>,
|
optional_bytearray: Option<Vec<u8>>,
|
||||||
|
optional_string: Option<String>,
|
||||||
|
string: String,
|
||||||
|
u64: u64,
|
||||||
|
uinteger: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ObjectTrait for Object {
|
impl ObjectTrait for Object {
|
||||||
|
@ -23,13 +23,13 @@ impl ObjectTrait for Object {
|
||||||
Object {
|
Object {
|
||||||
emit: emit,
|
emit: emit,
|
||||||
boolean: true,
|
boolean: true,
|
||||||
integer: 0,
|
|
||||||
uinteger: 0,
|
|
||||||
u64: 0,
|
|
||||||
string: String::new(),
|
|
||||||
optional_string: None,
|
|
||||||
bytearray: Vec::new(),
|
bytearray: Vec::new(),
|
||||||
|
integer: 0,
|
||||||
optional_bytearray: None,
|
optional_bytearray: None,
|
||||||
|
optional_string: None,
|
||||||
|
string: String::new(),
|
||||||
|
u64: 0,
|
||||||
|
uinteger: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn emit(&self) -> &ObjectEmitter {
|
fn emit(&self) -> &ObjectEmitter {
|
||||||
|
@ -42,41 +42,6 @@ impl ObjectTrait for Object {
|
||||||
self.boolean = value;
|
self.boolean = value;
|
||||||
self.emit.boolean_changed();
|
self.emit.boolean_changed();
|
||||||
}
|
}
|
||||||
fn get_integer(&self) -> i32 {
|
|
||||||
self.integer
|
|
||||||
}
|
|
||||||
fn set_integer(&mut self, value: i32) {
|
|
||||||
self.integer = value;
|
|
||||||
self.emit.integer_changed();
|
|
||||||
}
|
|
||||||
fn get_uinteger(&self) -> u32 {
|
|
||||||
self.uinteger
|
|
||||||
}
|
|
||||||
fn set_uinteger(&mut self, value: u32) {
|
|
||||||
self.uinteger = value;
|
|
||||||
self.emit.uinteger_changed();
|
|
||||||
}
|
|
||||||
fn get_u64(&self) -> u64 {
|
|
||||||
self.u64
|
|
||||||
}
|
|
||||||
fn set_u64(&mut self, value: u64) {
|
|
||||||
self.u64 = value;
|
|
||||||
self.emit.u64_changed();
|
|
||||||
}
|
|
||||||
fn get_string(&self) -> String {
|
|
||||||
self.string.clone()
|
|
||||||
}
|
|
||||||
fn set_string(&mut self, value: String) {
|
|
||||||
self.string = value;
|
|
||||||
self.emit.string_changed();
|
|
||||||
}
|
|
||||||
fn get_optional_string(&self) -> Option<String> {
|
|
||||||
self.optional_string.clone()
|
|
||||||
}
|
|
||||||
fn set_optional_string(&mut self, value: Option<String>) {
|
|
||||||
self.optional_string = value;
|
|
||||||
self.emit.optional_string_changed();
|
|
||||||
}
|
|
||||||
fn get_bytearray(&self) -> Vec<u8> {
|
fn get_bytearray(&self) -> Vec<u8> {
|
||||||
self.bytearray.clone()
|
self.bytearray.clone()
|
||||||
}
|
}
|
||||||
|
@ -84,6 +49,13 @@ impl ObjectTrait for Object {
|
||||||
self.bytearray = value;
|
self.bytearray = value;
|
||||||
self.emit.bytearray_changed();
|
self.emit.bytearray_changed();
|
||||||
}
|
}
|
||||||
|
fn get_integer(&self) -> i32 {
|
||||||
|
self.integer
|
||||||
|
}
|
||||||
|
fn set_integer(&mut self, value: i32) {
|
||||||
|
self.integer = value;
|
||||||
|
self.emit.integer_changed();
|
||||||
|
}
|
||||||
fn get_optional_bytearray(&self) -> Option<Vec<u8>> {
|
fn get_optional_bytearray(&self) -> Option<Vec<u8>> {
|
||||||
self.optional_bytearray.clone()
|
self.optional_bytearray.clone()
|
||||||
}
|
}
|
||||||
|
@ -91,4 +63,32 @@ impl ObjectTrait for Object {
|
||||||
self.optional_bytearray = value;
|
self.optional_bytearray = value;
|
||||||
self.emit.optional_bytearray_changed();
|
self.emit.optional_bytearray_changed();
|
||||||
}
|
}
|
||||||
|
fn get_optional_string(&self) -> Option<String> {
|
||||||
|
self.optional_string.clone()
|
||||||
|
}
|
||||||
|
fn set_optional_string(&mut self, value: Option<String>) {
|
||||||
|
self.optional_string = value;
|
||||||
|
self.emit.optional_string_changed();
|
||||||
|
}
|
||||||
|
fn get_string(&self) -> String {
|
||||||
|
self.string.clone()
|
||||||
|
}
|
||||||
|
fn set_string(&mut self, value: String) {
|
||||||
|
self.string = value;
|
||||||
|
self.emit.string_changed();
|
||||||
|
}
|
||||||
|
fn get_u64(&self) -> u64 {
|
||||||
|
self.u64
|
||||||
|
}
|
||||||
|
fn set_u64(&mut self, value: u64) {
|
||||||
|
self.u64 = value;
|
||||||
|
self.emit.u64_changed();
|
||||||
|
}
|
||||||
|
fn get_uinteger(&self) -> u32 {
|
||||||
|
self.uinteger
|
||||||
|
}
|
||||||
|
fn set_uinteger(&mut self, value: u32) {
|
||||||
|
self.uinteger = value;
|
||||||
|
self.emit.uinteger_changed();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,13 +15,13 @@ pub struct ObjectQObject {}
|
||||||
pub struct ObjectEmitter {
|
pub struct ObjectEmitter {
|
||||||
qobject: Arc<Mutex<*const ObjectQObject>>,
|
qobject: Arc<Mutex<*const ObjectQObject>>,
|
||||||
boolean_changed: fn(*const ObjectQObject),
|
boolean_changed: fn(*const ObjectQObject),
|
||||||
integer_changed: fn(*const ObjectQObject),
|
|
||||||
uinteger_changed: fn(*const ObjectQObject),
|
|
||||||
u64_changed: fn(*const ObjectQObject),
|
|
||||||
string_changed: fn(*const ObjectQObject),
|
|
||||||
optional_string_changed: fn(*const ObjectQObject),
|
|
||||||
bytearray_changed: fn(*const ObjectQObject),
|
bytearray_changed: fn(*const ObjectQObject),
|
||||||
|
integer_changed: fn(*const ObjectQObject),
|
||||||
optional_bytearray_changed: fn(*const ObjectQObject),
|
optional_bytearray_changed: fn(*const ObjectQObject),
|
||||||
|
optional_string_changed: fn(*const ObjectQObject),
|
||||||
|
string_changed: fn(*const ObjectQObject),
|
||||||
|
u64_changed: fn(*const ObjectQObject),
|
||||||
|
uinteger_changed: fn(*const ObjectQObject),
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl Send for ObjectEmitter {}
|
unsafe impl Send for ObjectEmitter {}
|
||||||
|
@ -36,28 +36,22 @@ impl ObjectEmitter {
|
||||||
(self.boolean_changed)(ptr);
|
(self.boolean_changed)(ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn bytearray_changed(&self) {
|
||||||
|
let ptr = *self.qobject.lock().unwrap();
|
||||||
|
if !ptr.is_null() {
|
||||||
|
(self.bytearray_changed)(ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
pub fn integer_changed(&self) {
|
pub fn integer_changed(&self) {
|
||||||
let ptr = *self.qobject.lock().unwrap();
|
let ptr = *self.qobject.lock().unwrap();
|
||||||
if !ptr.is_null() {
|
if !ptr.is_null() {
|
||||||
(self.integer_changed)(ptr);
|
(self.integer_changed)(ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn uinteger_changed(&self) {
|
pub fn optional_bytearray_changed(&self) {
|
||||||
let ptr = *self.qobject.lock().unwrap();
|
let ptr = *self.qobject.lock().unwrap();
|
||||||
if !ptr.is_null() {
|
if !ptr.is_null() {
|
||||||
(self.uinteger_changed)(ptr);
|
(self.optional_bytearray_changed)(ptr);
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn u64_changed(&self) {
|
|
||||||
let ptr = *self.qobject.lock().unwrap();
|
|
||||||
if !ptr.is_null() {
|
|
||||||
(self.u64_changed)(ptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn string_changed(&self) {
|
|
||||||
let ptr = *self.qobject.lock().unwrap();
|
|
||||||
if !ptr.is_null() {
|
|
||||||
(self.string_changed)(ptr);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn optional_string_changed(&self) {
|
pub fn optional_string_changed(&self) {
|
||||||
|
@ -66,16 +60,22 @@ impl ObjectEmitter {
|
||||||
(self.optional_string_changed)(ptr);
|
(self.optional_string_changed)(ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn bytearray_changed(&self) {
|
pub fn string_changed(&self) {
|
||||||
let ptr = *self.qobject.lock().unwrap();
|
let ptr = *self.qobject.lock().unwrap();
|
||||||
if !ptr.is_null() {
|
if !ptr.is_null() {
|
||||||
(self.bytearray_changed)(ptr);
|
(self.string_changed)(ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn optional_bytearray_changed(&self) {
|
pub fn u64_changed(&self) {
|
||||||
let ptr = *self.qobject.lock().unwrap();
|
let ptr = *self.qobject.lock().unwrap();
|
||||||
if !ptr.is_null() {
|
if !ptr.is_null() {
|
||||||
(self.optional_bytearray_changed)(ptr);
|
(self.u64_changed)(ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn uinteger_changed(&self) {
|
||||||
|
let ptr = *self.qobject.lock().unwrap();
|
||||||
|
if !ptr.is_null() {
|
||||||
|
(self.uinteger_changed)(ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,43 +85,43 @@ pub trait ObjectTrait {
|
||||||
fn emit(&self) -> &ObjectEmitter;
|
fn emit(&self) -> &ObjectEmitter;
|
||||||
fn get_boolean(&self) -> bool;
|
fn get_boolean(&self) -> bool;
|
||||||
fn set_boolean(&mut self, value: bool);
|
fn set_boolean(&mut self, value: bool);
|
||||||
fn get_integer(&self) -> i32;
|
|
||||||
fn set_integer(&mut self, value: i32);
|
|
||||||
fn get_uinteger(&self) -> u32;
|
|
||||||
fn set_uinteger(&mut self, value: u32);
|
|
||||||
fn get_u64(&self) -> u64;
|
|
||||||
fn set_u64(&mut self, value: u64);
|
|
||||||
fn get_string(&self) -> String;
|
|
||||||
fn set_string(&mut self, value: String);
|
|
||||||
fn get_optional_string(&self) -> Option<String>;
|
|
||||||
fn set_optional_string(&mut self, value: Option<String>);
|
|
||||||
fn get_bytearray(&self) -> Vec<u8>;
|
fn get_bytearray(&self) -> Vec<u8>;
|
||||||
fn set_bytearray(&mut self, value: Vec<u8>);
|
fn set_bytearray(&mut self, value: Vec<u8>);
|
||||||
|
fn get_integer(&self) -> i32;
|
||||||
|
fn set_integer(&mut self, value: i32);
|
||||||
fn get_optional_bytearray(&self) -> Option<Vec<u8>>;
|
fn get_optional_bytearray(&self) -> Option<Vec<u8>>;
|
||||||
fn set_optional_bytearray(&mut self, value: Option<Vec<u8>>);
|
fn set_optional_bytearray(&mut self, value: Option<Vec<u8>>);
|
||||||
|
fn get_optional_string(&self) -> Option<String>;
|
||||||
|
fn set_optional_string(&mut self, value: Option<String>);
|
||||||
|
fn get_string(&self) -> String;
|
||||||
|
fn set_string(&mut self, value: String);
|
||||||
|
fn get_u64(&self) -> u64;
|
||||||
|
fn set_u64(&mut self, value: u64);
|
||||||
|
fn get_uinteger(&self) -> u32;
|
||||||
|
fn set_uinteger(&mut self, value: u32);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn object_new(qobject: *const ObjectQObject,
|
pub extern "C" fn object_new(qobject: *const ObjectQObject,
|
||||||
boolean_changed: fn(*const ObjectQObject),
|
boolean_changed: fn(*const ObjectQObject),
|
||||||
integer_changed: fn(*const ObjectQObject),
|
|
||||||
uinteger_changed: fn(*const ObjectQObject),
|
|
||||||
u64_changed: fn(*const ObjectQObject),
|
|
||||||
string_changed: fn(*const ObjectQObject),
|
|
||||||
optional_string_changed: fn(*const ObjectQObject),
|
|
||||||
bytearray_changed: fn(*const ObjectQObject),
|
bytearray_changed: fn(*const ObjectQObject),
|
||||||
optional_bytearray_changed: fn(*const ObjectQObject))
|
integer_changed: fn(*const ObjectQObject),
|
||||||
|
optional_bytearray_changed: fn(*const ObjectQObject),
|
||||||
|
optional_string_changed: fn(*const ObjectQObject),
|
||||||
|
string_changed: fn(*const ObjectQObject),
|
||||||
|
u64_changed: fn(*const ObjectQObject),
|
||||||
|
uinteger_changed: fn(*const ObjectQObject))
|
||||||
-> *mut Object {
|
-> *mut Object {
|
||||||
let emit = ObjectEmitter {
|
let emit = ObjectEmitter {
|
||||||
qobject: Arc::new(Mutex::new(qobject)),
|
qobject: Arc::new(Mutex::new(qobject)),
|
||||||
boolean_changed: boolean_changed,
|
boolean_changed: boolean_changed,
|
||||||
integer_changed: integer_changed,
|
|
||||||
uinteger_changed: uinteger_changed,
|
|
||||||
u64_changed: u64_changed,
|
|
||||||
string_changed: string_changed,
|
|
||||||
optional_string_changed: optional_string_changed,
|
|
||||||
bytearray_changed: bytearray_changed,
|
bytearray_changed: bytearray_changed,
|
||||||
|
integer_changed: integer_changed,
|
||||||
optional_bytearray_changed: optional_bytearray_changed,
|
optional_bytearray_changed: optional_bytearray_changed,
|
||||||
|
optional_string_changed: optional_string_changed,
|
||||||
|
string_changed: string_changed,
|
||||||
|
u64_changed: u64_changed,
|
||||||
|
uinteger_changed: uinteger_changed,
|
||||||
};
|
};
|
||||||
let d = Object::create(emit);
|
let d = Object::create(emit);
|
||||||
Box::into_raw(Box::new(d))
|
Box::into_raw(Box::new(d))
|
||||||
|
@ -142,6 +142,19 @@ pub unsafe extern "C" fn object_boolean_set(ptr: *mut Object, v: bool) {
|
||||||
(&mut *ptr).set_boolean(v);
|
(&mut *ptr).set_boolean(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn object_bytearray_get(ptr: *const Object,
|
||||||
|
p: *mut c_void,
|
||||||
|
set: fn(*mut c_void, QByteArray)) {
|
||||||
|
let data = (&*ptr).get_bytearray();
|
||||||
|
set(p, QByteArray::from(&data));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn object_bytearray_set(ptr: *mut Object, v: QByteArray) {
|
||||||
|
(&mut *ptr).set_bytearray(v.convert());
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn object_integer_get(ptr: *const Object) -> i32 {
|
pub unsafe extern "C" fn object_integer_get(ptr: *const Object) -> i32 {
|
||||||
(&*ptr).get_integer()
|
(&*ptr).get_integer()
|
||||||
|
@ -153,36 +166,22 @@ pub unsafe extern "C" fn object_integer_set(ptr: *mut Object, v: i32) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn object_uinteger_get(ptr: *const Object) -> u32 {
|
pub unsafe extern "C" fn object_optional_bytearray_get(ptr: *const Object,
|
||||||
(&*ptr).get_uinteger()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn object_uinteger_set(ptr: *mut Object, v: u32) {
|
|
||||||
(&mut *ptr).set_uinteger(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn object_u64_get(ptr: *const Object) -> u64 {
|
|
||||||
(&*ptr).get_u64()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn object_u64_set(ptr: *mut Object, v: u64) {
|
|
||||||
(&mut *ptr).set_u64(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn object_string_get(ptr: *const Object,
|
|
||||||
p: *mut c_void,
|
p: *mut c_void,
|
||||||
set: fn(*mut c_void, QString)) {
|
set: fn(*mut c_void, QByteArray)) {
|
||||||
let data = (&*ptr).get_string();
|
let data = (&*ptr).get_optional_bytearray();
|
||||||
set(p, QString::from(&data));
|
if let Some(data) = data {
|
||||||
|
set(p, QByteArray::from(&data));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn object_string_set(ptr: *mut Object, v: QStringIn) {
|
pub unsafe extern "C" fn object_optional_bytearray_set(ptr: *mut Object, v: QByteArray) {
|
||||||
(&mut *ptr).set_string(v.convert());
|
(&mut *ptr).set_optional_bytearray(Some(v.convert()));
|
||||||
|
}
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn object_optional_bytearray_set_none(ptr: *mut Object) {
|
||||||
|
(&mut *ptr).set_optional_bytearray(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -205,33 +204,34 @@ pub unsafe extern "C" fn object_optional_string_set_none(ptr: *mut Object) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn object_bytearray_get(ptr: *const Object,
|
pub unsafe extern "C" fn object_string_get(ptr: *const Object,
|
||||||
p: *mut c_void,
|
p: *mut c_void,
|
||||||
set: fn(*mut c_void, QByteArray)) {
|
set: fn(*mut c_void, QString)) {
|
||||||
let data = (&*ptr).get_bytearray();
|
let data = (&*ptr).get_string();
|
||||||
set(p, QByteArray::from(&data));
|
set(p, QString::from(&data));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn object_bytearray_set(ptr: *mut Object, v: QByteArray) {
|
pub unsafe extern "C" fn object_string_set(ptr: *mut Object, v: QStringIn) {
|
||||||
(&mut *ptr).set_bytearray(v.convert());
|
(&mut *ptr).set_string(v.convert());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn object_optional_bytearray_get(ptr: *const Object,
|
pub unsafe extern "C" fn object_u64_get(ptr: *const Object) -> u64 {
|
||||||
p: *mut c_void,
|
(&*ptr).get_u64()
|
||||||
set: fn(*mut c_void, QByteArray)) {
|
|
||||||
let data = (&*ptr).get_optional_bytearray();
|
|
||||||
if let Some(data) = data {
|
|
||||||
set(p, QByteArray::from(&data));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn object_optional_bytearray_set(ptr: *mut Object, v: QByteArray) {
|
pub unsafe extern "C" fn object_u64_set(ptr: *mut Object, v: u64) {
|
||||||
(&mut *ptr).set_optional_bytearray(Some(v.convert()));
|
(&mut *ptr).set_u64(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn object_optional_bytearray_set_none(ptr: *mut Object) {
|
pub unsafe extern "C" fn object_uinteger_get(ptr: *const Object) -> u32 {
|
||||||
(&mut *ptr).set_optional_bytearray(None);
|
(&*ptr).get_uinteger()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn object_uinteger_set(ptr: *mut Object, v: u32) {
|
||||||
|
(&mut *ptr).set_uinteger(v);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,18 +6,16 @@
|
||||||
"implementationModule": "implementation",
|
"implementationModule": "implementation",
|
||||||
"typesModule": "types"
|
"typesModule": "types"
|
||||||
},
|
},
|
||||||
"objects": [{
|
"objects": {
|
||||||
"name": "Persons",
|
"Persons": {
|
||||||
"type": "List",
|
"type": "List",
|
||||||
"roles": [{
|
"itemProperties": {
|
||||||
"name": "userName",
|
"userName": {
|
||||||
"value": "Qt::DisplayRole",
|
"type": "QString",
|
||||||
"type": "QString"
|
"write": true,
|
||||||
}, {
|
"roles": [ [ "display", "edit" ] ]
|
||||||
"name": "userName",
|
}
|
||||||
"value": "Qt::EditRole",
|
}
|
||||||
"type": "QString",
|
}
|
||||||
"write": true
|
}
|
||||||
}]
|
|
||||||
}]
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,8 +126,8 @@ int Persons::rowCount(const QModelIndex &parent) const
|
||||||
|
|
||||||
QModelIndex Persons::index(int row, int column, const QModelIndex &parent) const
|
QModelIndex Persons::index(int row, int column, const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
if (!parent.isValid() && column == 0) {
|
if (!parent.isValid() && row >= 0 && row < rowCount(parent) && column >= 0 && column < 1) {
|
||||||
return createIndex(row, 0, (quintptr)0);
|
return createIndex(row, column, (quintptr)0);
|
||||||
}
|
}
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
}
|
}
|
||||||
|
@ -169,11 +169,9 @@ QVariant Persons::data(const QModelIndex &index, int role) const
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 0:
|
case 0:
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::DisplayRole:
|
case 256:
|
||||||
persons_data_user_name(d, index.row(), &s, set_qstring);
|
case 0:
|
||||||
if (!s.isNull()) v.setValue<QString>(s);
|
case 2:
|
||||||
break;
|
|
||||||
case Qt::EditRole:
|
|
||||||
persons_data_user_name(d, index.row(), &s, set_qstring);
|
persons_data_user_name(d, index.row(), &s, set_qstring);
|
||||||
if (!s.isNull()) v.setValue<QString>(s);
|
if (!s.isNull()) v.setValue<QString>(s);
|
||||||
break;
|
break;
|
||||||
|
@ -183,15 +181,15 @@ QVariant Persons::data(const QModelIndex &index, int role) const
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
QHash<int, QByteArray> Persons::roleNames() const {
|
QHash<int, QByteArray> Persons::roleNames() const {
|
||||||
QHash<int, QByteArray> names;
|
QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
|
||||||
names.insert(Qt::DisplayRole, "userName");
|
names.insert(256, "userName");
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
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;
|
||||||
if (index.column() == 0) {
|
if (index.column() == 0) {
|
||||||
if (role == Qt::EditRole) {
|
if (role == 256 || role == 0 || role == 2) {
|
||||||
set = persons_set_data_user_name(d, index.row(), value.value<QString>());
|
set = persons_set_data_user_name(d, index.row(), value.value<QString>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,13 +6,15 @@
|
||||||
"implementationModule": "implementation",
|
"implementationModule": "implementation",
|
||||||
"typesModule": "types"
|
"typesModule": "types"
|
||||||
},
|
},
|
||||||
"objects": [{
|
"objects": {
|
||||||
"name": "Person",
|
"Person": {
|
||||||
"type": "Object",
|
"type": "Object",
|
||||||
"properties": [{
|
"properties": {
|
||||||
"name": "userName",
|
"userName": {
|
||||||
"type": "QString",
|
"type": "QString",
|
||||||
"write": true
|
"write": true
|
||||||
}]
|
}
|
||||||
}]
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,44 +6,45 @@
|
||||||
"implementationModule": "implementation",
|
"implementationModule": "implementation",
|
||||||
"typesModule": "types"
|
"typesModule": "types"
|
||||||
},
|
},
|
||||||
"objects": [{
|
"objects": {
|
||||||
"name": "Object",
|
"Object": {
|
||||||
"type": "Object",
|
"type": "Object",
|
||||||
"properties": [{
|
"properties": {
|
||||||
"name": "boolean",
|
"boolean": {
|
||||||
"type": "bool",
|
"type": "bool",
|
||||||
"write": true
|
"write": true
|
||||||
}, {
|
},
|
||||||
"name": "integer",
|
"integer": {
|
||||||
"type": "qint32",
|
"type": "qint32",
|
||||||
"write": true
|
"write": true
|
||||||
}, {
|
},
|
||||||
"name": "uinteger",
|
"uinteger": {
|
||||||
"type": "quint32",
|
"type": "quint32",
|
||||||
"write": true
|
"write": true
|
||||||
}, {
|
},
|
||||||
"name": "u64",
|
"u64": {
|
||||||
"type": "quint64",
|
"type": "quint64",
|
||||||
"write": true
|
"write": true
|
||||||
}, {
|
},
|
||||||
"name": "string",
|
"string": {
|
||||||
"type": "QString",
|
"type": "QString",
|
||||||
"write": true,
|
"write": true
|
||||||
"nullable": true
|
},
|
||||||
}, {
|
"optionalString": {
|
||||||
"name": "optionalString",
|
"type": "QString",
|
||||||
"type": "QString",
|
"write": true,
|
||||||
"write": true,
|
"optional": true
|
||||||
"optional": true
|
},
|
||||||
}, {
|
"bytearray": {
|
||||||
"name": "bytearray",
|
"type": "QByteArray",
|
||||||
"type": "QByteArray",
|
"write": true
|
||||||
"write": true
|
},
|
||||||
}, {
|
"optionalBytearray": {
|
||||||
"name": "optionalBytearray",
|
"type": "QByteArray",
|
||||||
"type": "QByteArray",
|
"write": true,
|
||||||
"write": true,
|
"optional": true
|
||||||
"optional": true
|
}
|
||||||
}]
|
}
|
||||||
}]
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,34 +60,34 @@ extern "C" {
|
||||||
void object_free(Object::Private*);
|
void object_free(Object::Private*);
|
||||||
bool object_boolean_get(const Object::Private*);
|
bool object_boolean_get(const Object::Private*);
|
||||||
void object_boolean_set(Object::Private*, bool);
|
void object_boolean_set(Object::Private*, bool);
|
||||||
qint32 object_integer_get(const Object::Private*);
|
|
||||||
void object_integer_set(Object::Private*, qint32);
|
|
||||||
quint32 object_uinteger_get(const Object::Private*);
|
|
||||||
void object_uinteger_set(Object::Private*, uint);
|
|
||||||
quint64 object_u64_get(const Object::Private*);
|
|
||||||
void object_u64_set(Object::Private*, quint64);
|
|
||||||
void object_string_get(const Object::Private*, QString*, qstring_set);
|
|
||||||
void object_string_set(Object::Private*, qstring_t);
|
|
||||||
void object_optional_string_get(const Object::Private*, QString*, qstring_set);
|
|
||||||
void object_optional_string_set(Object::Private*, qstring_t);
|
|
||||||
void object_optional_string_set_none(Object::Private*);
|
|
||||||
void object_bytearray_get(const Object::Private*, QByteArray*, qbytearray_set);
|
void object_bytearray_get(const Object::Private*, QByteArray*, qbytearray_set);
|
||||||
void object_bytearray_set(Object::Private*, qbytearray_t);
|
void object_bytearray_set(Object::Private*, qbytearray_t);
|
||||||
|
qint32 object_integer_get(const Object::Private*);
|
||||||
|
void object_integer_set(Object::Private*, qint32);
|
||||||
void object_optional_bytearray_get(const Object::Private*, QByteArray*, qbytearray_set);
|
void object_optional_bytearray_get(const Object::Private*, QByteArray*, qbytearray_set);
|
||||||
void object_optional_bytearray_set(Object::Private*, qbytearray_t);
|
void object_optional_bytearray_set(Object::Private*, qbytearray_t);
|
||||||
void object_optional_bytearray_set_none(Object::Private*);
|
void object_optional_bytearray_set_none(Object::Private*);
|
||||||
|
void object_optional_string_get(const Object::Private*, QString*, qstring_set);
|
||||||
|
void object_optional_string_set(Object::Private*, qstring_t);
|
||||||
|
void object_optional_string_set_none(Object::Private*);
|
||||||
|
void object_string_get(const Object::Private*, QString*, qstring_set);
|
||||||
|
void object_string_set(Object::Private*, qstring_t);
|
||||||
|
quint64 object_u64_get(const Object::Private*);
|
||||||
|
void object_u64_set(Object::Private*, quint64);
|
||||||
|
quint32 object_uinteger_get(const Object::Private*);
|
||||||
|
void object_uinteger_set(Object::Private*, uint);
|
||||||
};
|
};
|
||||||
Object::Object(QObject *parent):
|
Object::Object(QObject *parent):
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
d(object_new(this,
|
d(object_new(this,
|
||||||
[](Object* o) { emit o->booleanChanged(); },
|
[](Object* o) { emit o->booleanChanged(); },
|
||||||
[](Object* o) { emit o->integerChanged(); },
|
|
||||||
[](Object* o) { emit o->uintegerChanged(); },
|
|
||||||
[](Object* o) { emit o->u64Changed(); },
|
|
||||||
[](Object* o) { emit o->stringChanged(); },
|
|
||||||
[](Object* o) { emit o->optionalStringChanged(); },
|
|
||||||
[](Object* o) { emit o->bytearrayChanged(); },
|
[](Object* o) { emit o->bytearrayChanged(); },
|
||||||
[](Object* o) { emit o->optionalBytearrayChanged(); })) {}
|
[](Object* o) { emit o->integerChanged(); },
|
||||||
|
[](Object* o) { emit o->optionalBytearrayChanged(); },
|
||||||
|
[](Object* o) { emit o->optionalStringChanged(); },
|
||||||
|
[](Object* o) { emit o->stringChanged(); },
|
||||||
|
[](Object* o) { emit o->u64Changed(); },
|
||||||
|
[](Object* o) { emit o->uintegerChanged(); })) {}
|
||||||
|
|
||||||
Object::~Object() {
|
Object::~Object() {
|
||||||
object_free(d);
|
object_free(d);
|
||||||
|
@ -99,49 +99,6 @@ bool Object::boolean() const
|
||||||
void Object::setBoolean(bool v) {
|
void Object::setBoolean(bool v) {
|
||||||
object_boolean_set(d, v);
|
object_boolean_set(d, v);
|
||||||
}
|
}
|
||||||
qint32 Object::integer() const
|
|
||||||
{
|
|
||||||
return object_integer_get(d);
|
|
||||||
}
|
|
||||||
void Object::setInteger(qint32 v) {
|
|
||||||
object_integer_set(d, v);
|
|
||||||
}
|
|
||||||
quint32 Object::uinteger() const
|
|
||||||
{
|
|
||||||
return object_uinteger_get(d);
|
|
||||||
}
|
|
||||||
void Object::setUinteger(uint v) {
|
|
||||||
object_uinteger_set(d, v);
|
|
||||||
}
|
|
||||||
quint64 Object::u64() const
|
|
||||||
{
|
|
||||||
return object_u64_get(d);
|
|
||||||
}
|
|
||||||
void Object::setU64(quint64 v) {
|
|
||||||
object_u64_set(d, v);
|
|
||||||
}
|
|
||||||
QString Object::string() const
|
|
||||||
{
|
|
||||||
QString v;
|
|
||||||
object_string_get(d, &v, set_qstring);
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
void Object::setString(const QString& v) {
|
|
||||||
object_string_set(d, v);
|
|
||||||
}
|
|
||||||
QString Object::optionalString() const
|
|
||||||
{
|
|
||||||
QString v;
|
|
||||||
object_optional_string_get(d, &v, set_qstring);
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
void Object::setOptionalString(const QString& v) {
|
|
||||||
if (v.isNull()) {
|
|
||||||
object_optional_string_set_none(d);
|
|
||||||
} else {
|
|
||||||
object_optional_string_set(d, v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
QByteArray Object::bytearray() const
|
QByteArray Object::bytearray() const
|
||||||
{
|
{
|
||||||
QByteArray v;
|
QByteArray v;
|
||||||
|
@ -151,6 +108,13 @@ QByteArray Object::bytearray() const
|
||||||
void Object::setBytearray(const QByteArray& v) {
|
void Object::setBytearray(const QByteArray& v) {
|
||||||
object_bytearray_set(d, v);
|
object_bytearray_set(d, v);
|
||||||
}
|
}
|
||||||
|
qint32 Object::integer() const
|
||||||
|
{
|
||||||
|
return object_integer_get(d);
|
||||||
|
}
|
||||||
|
void Object::setInteger(qint32 v) {
|
||||||
|
object_integer_set(d, v);
|
||||||
|
}
|
||||||
QByteArray Object::optionalBytearray() const
|
QByteArray Object::optionalBytearray() const
|
||||||
{
|
{
|
||||||
QByteArray v;
|
QByteArray v;
|
||||||
|
@ -164,3 +128,39 @@ void Object::setOptionalBytearray(const QByteArray& v) {
|
||||||
object_optional_bytearray_set(d, v);
|
object_optional_bytearray_set(d, v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
QString Object::optionalString() const
|
||||||
|
{
|
||||||
|
QString v;
|
||||||
|
object_optional_string_get(d, &v, set_qstring);
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
void Object::setOptionalString(const QString& v) {
|
||||||
|
if (v.isNull()) {
|
||||||
|
object_optional_string_set_none(d);
|
||||||
|
} else {
|
||||||
|
object_optional_string_set(d, v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QString Object::string() const
|
||||||
|
{
|
||||||
|
QString v;
|
||||||
|
object_string_get(d, &v, set_qstring);
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
void Object::setString(const QString& v) {
|
||||||
|
object_string_set(d, v);
|
||||||
|
}
|
||||||
|
quint64 Object::u64() const
|
||||||
|
{
|
||||||
|
return object_u64_get(d);
|
||||||
|
}
|
||||||
|
void Object::setU64(quint64 v) {
|
||||||
|
object_u64_set(d, v);
|
||||||
|
}
|
||||||
|
quint32 Object::uinteger() const
|
||||||
|
{
|
||||||
|
return object_uinteger_get(d);
|
||||||
|
}
|
||||||
|
void Object::setUinteger(uint v) {
|
||||||
|
object_uinteger_set(d, v);
|
||||||
|
}
|
||||||
|
|
|
@ -13,49 +13,49 @@ public:
|
||||||
private:
|
private:
|
||||||
Private * const d;
|
Private * const d;
|
||||||
Q_PROPERTY(bool boolean READ boolean WRITE setBoolean NOTIFY booleanChanged FINAL)
|
Q_PROPERTY(bool boolean READ boolean WRITE setBoolean NOTIFY booleanChanged FINAL)
|
||||||
Q_PROPERTY(qint32 integer READ integer WRITE setInteger NOTIFY integerChanged FINAL)
|
|
||||||
Q_PROPERTY(quint32 uinteger READ uinteger WRITE setUinteger NOTIFY uintegerChanged FINAL)
|
|
||||||
Q_PROPERTY(quint64 u64 READ u64 WRITE setU64 NOTIFY u64Changed FINAL)
|
|
||||||
Q_PROPERTY(QString string READ string WRITE setString NOTIFY stringChanged FINAL)
|
|
||||||
Q_PROPERTY(QString optionalString READ optionalString WRITE setOptionalString NOTIFY optionalStringChanged FINAL)
|
|
||||||
Q_PROPERTY(QByteArray bytearray READ bytearray WRITE setBytearray NOTIFY bytearrayChanged FINAL)
|
Q_PROPERTY(QByteArray bytearray READ bytearray WRITE setBytearray NOTIFY bytearrayChanged FINAL)
|
||||||
|
Q_PROPERTY(qint32 integer READ integer WRITE setInteger NOTIFY integerChanged FINAL)
|
||||||
Q_PROPERTY(QByteArray optionalBytearray READ optionalBytearray WRITE setOptionalBytearray NOTIFY optionalBytearrayChanged FINAL)
|
Q_PROPERTY(QByteArray optionalBytearray READ optionalBytearray WRITE setOptionalBytearray NOTIFY optionalBytearrayChanged FINAL)
|
||||||
|
Q_PROPERTY(QString optionalString READ optionalString WRITE setOptionalString NOTIFY optionalStringChanged FINAL)
|
||||||
|
Q_PROPERTY(QString string READ string WRITE setString NOTIFY stringChanged FINAL)
|
||||||
|
Q_PROPERTY(quint64 u64 READ u64 WRITE setU64 NOTIFY u64Changed FINAL)
|
||||||
|
Q_PROPERTY(quint32 uinteger READ uinteger WRITE setUinteger NOTIFY uintegerChanged FINAL)
|
||||||
public:
|
public:
|
||||||
explicit Object(QObject *parent = nullptr);
|
explicit Object(QObject *parent = nullptr);
|
||||||
~Object();
|
~Object();
|
||||||
bool boolean() const;
|
bool boolean() const;
|
||||||
void setBoolean(bool v);
|
void setBoolean(bool v);
|
||||||
qint32 integer() const;
|
|
||||||
void setInteger(qint32 v);
|
|
||||||
quint32 uinteger() const;
|
|
||||||
void setUinteger(uint v);
|
|
||||||
quint64 u64() const;
|
|
||||||
void setU64(quint64 v);
|
|
||||||
QString string() const;
|
|
||||||
void setString(const QString& v);
|
|
||||||
QString optionalString() const;
|
|
||||||
void setOptionalString(const QString& v);
|
|
||||||
QByteArray bytearray() const;
|
QByteArray bytearray() const;
|
||||||
void setBytearray(const QByteArray& v);
|
void setBytearray(const QByteArray& v);
|
||||||
|
qint32 integer() const;
|
||||||
|
void setInteger(qint32 v);
|
||||||
QByteArray optionalBytearray() const;
|
QByteArray optionalBytearray() const;
|
||||||
void setOptionalBytearray(const QByteArray& v);
|
void setOptionalBytearray(const QByteArray& v);
|
||||||
|
QString optionalString() const;
|
||||||
|
void setOptionalString(const QString& v);
|
||||||
|
QString string() const;
|
||||||
|
void setString(const QString& v);
|
||||||
|
quint64 u64() const;
|
||||||
|
void setU64(quint64 v);
|
||||||
|
quint32 uinteger() const;
|
||||||
|
void setUinteger(uint v);
|
||||||
signals:
|
signals:
|
||||||
void booleanChanged();
|
void booleanChanged();
|
||||||
void integerChanged();
|
|
||||||
void uintegerChanged();
|
|
||||||
void u64Changed();
|
|
||||||
void stringChanged();
|
|
||||||
void optionalStringChanged();
|
|
||||||
void bytearrayChanged();
|
void bytearrayChanged();
|
||||||
|
void integerChanged();
|
||||||
void optionalBytearrayChanged();
|
void optionalBytearrayChanged();
|
||||||
|
void optionalStringChanged();
|
||||||
|
void stringChanged();
|
||||||
|
void u64Changed();
|
||||||
|
void uintegerChanged();
|
||||||
private:
|
private:
|
||||||
bool m_boolean;
|
bool m_boolean;
|
||||||
qint32 m_integer;
|
|
||||||
quint32 m_uinteger;
|
|
||||||
quint64 m_u64;
|
|
||||||
QString m_string;
|
|
||||||
QString m_optionalString;
|
|
||||||
QByteArray m_bytearray;
|
QByteArray m_bytearray;
|
||||||
|
qint32 m_integer;
|
||||||
QByteArray m_optionalBytearray;
|
QByteArray m_optionalBytearray;
|
||||||
|
QString m_optionalString;
|
||||||
|
QString m_string;
|
||||||
|
quint64 m_u64;
|
||||||
|
quint32 m_uinteger;
|
||||||
};
|
};
|
||||||
#endif // TEST_OBJECT_TYPES_RUST_H
|
#endif // TEST_OBJECT_TYPES_RUST_H
|
||||||
|
|
|
@ -6,18 +6,16 @@
|
||||||
"implementationModule": "implementation",
|
"implementationModule": "implementation",
|
||||||
"typesModule": "types"
|
"typesModule": "types"
|
||||||
},
|
},
|
||||||
"objects": [{
|
"objects": {
|
||||||
"name": "Persons",
|
"Persons": {
|
||||||
"type": "UniformTree",
|
"type": "UniformTree",
|
||||||
"roles": [{
|
"itemProperties": {
|
||||||
"name": "userName",
|
"userName": {
|
||||||
"value": "Qt::DisplayRole",
|
"type": "QString",
|
||||||
"type": "QString"
|
"write": true,
|
||||||
}, {
|
"roles": [ [ "display", "edit" ] ]
|
||||||
"name": "userName",
|
}
|
||||||
"value": "Qt::EditRole",
|
}
|
||||||
"type": "QString",
|
}
|
||||||
"write": true
|
}
|
||||||
}]
|
|
||||||
}]
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -183,11 +183,9 @@ QVariant Persons::data(const QModelIndex &index, int role) const
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case 0:
|
case 0:
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::DisplayRole:
|
case 256:
|
||||||
persons_data_user_name(d, index.row(), index.internalId(), &s, set_qstring);
|
case 0:
|
||||||
if (!s.isNull()) v.setValue<QString>(s);
|
case 2:
|
||||||
break;
|
|
||||||
case Qt::EditRole:
|
|
||||||
persons_data_user_name(d, index.row(), index.internalId(), &s, set_qstring);
|
persons_data_user_name(d, index.row(), index.internalId(), &s, set_qstring);
|
||||||
if (!s.isNull()) v.setValue<QString>(s);
|
if (!s.isNull()) v.setValue<QString>(s);
|
||||||
break;
|
break;
|
||||||
|
@ -197,15 +195,15 @@ QVariant Persons::data(const QModelIndex &index, int role) const
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
QHash<int, QByteArray> Persons::roleNames() const {
|
QHash<int, QByteArray> Persons::roleNames() const {
|
||||||
QHash<int, QByteArray> names;
|
QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
|
||||||
names.insert(Qt::DisplayRole, "userName");
|
names.insert(256, "userName");
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
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;
|
||||||
if (index.column() == 0) {
|
if (index.column() == 0) {
|
||||||
if (role == Qt::EditRole) {
|
if (role == 256 || role == 0 || role == 2) {
|
||||||
set = persons_set_data_user_name(d, index.row(), index.internalId(), value.value<QString>());
|
set = persons_set_data_user_name(d, index.row(), index.internalId(), value.value<QString>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue