advotracker_qml: advotracker variant with Qt/Qml GUI

Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
2020-06-12 16:40:28 +02:00
parent 06cbce5c69
commit f41589263b
78 changed files with 13195 additions and 0 deletions

View File

@@ -0,0 +1 @@
// todo

View File

@@ -0,0 +1,83 @@
/* advotracker infrastructure.
*
* Copyright 2020 Ralf Zerres <ralf.zerres@networkx.de>
* SPDX-License-Identifier: (0BSD or MIT)
*
* Based on an example from https://github.com/woboq/qmetaobject-rs/tree/master/examples
* Copyright 2019 Olivier Goffart <ogoffart@woboq.com>
*
*/
use qmetaobject::*;
use std::collections::HashMap;
#[derive(Default, Clone)]
struct NumberHarmItem {
number_harm: String,
number_policyholder: String,
number_clerk_id: u32,
data_recorded: String,
completed: bool,
description: String,
}
impl NumberHarmItem {
// fn update_active_count(&mut self) {
// let ac = self.list.iter().filter(|i| !i.completed).count();
// if self.activeCount != ac {
// self.activeCount = ac;
// self.active_count_changed();
// }
// }
}
#[allow(non_snake_case)]
#[derive(Default, QObject)]
pub struct NumberHarm {
base: qt_base_class!(trait QAbstractListModel),
//base: qt_base_class!(trait SortFilterProxyModel),
count: qt_property!(i32; READ row_count NOTIFY count_changed),
count_changed: qt_signal!(),
list: Vec<NumberHarmItem>,
// activeCount: qt_property!(usize; NOTIFY active_count_changed),
// active_count_changed: qt_signal!(),
// setCompleted: qt_method!(fn(&mut self, item: usize, v: bool) -> bool),
// setDescription: qt_method!(fn(&mut self, item: usize, v: String) -> bool ),
// insert_rows: qt_method!(fn(&mut self, row: usize, count: usize) -> bool),
// remove_rows: qt_method!(fn(&mut self, row: usize, count: usize) -> bool),
// clearCompleted: qt_method!(fn(&mut self)),
// add: qt_method!(fn(&mut self, description: String)),
// remove: qt_method!(fn(&mut self, index: u64) -> bool),
// setAll: qt_method!(fn(&mut self, completed: bool)),
}
//impl QAbstractListModel for NumberHarm {
impl QSqlQueryModel for NumberHarm {
fn row_count(&self) -> i32 {
self.list.len() as i32
}
fn data(&self, index: QModelIndex, role: i32) -> QVariant {
let idx = index.row() as usize;
if idx < self.list.len() {
if role == USER_ROLE {
self.list[idx].completed.into()
} else if role == USER_ROLE + 1 {
QString::from(self.list[idx].description.clone()).into()
} else {
QVariant::default()
}
} else {
QVariant::default()
}
}
fn role_names(&self) -> HashMap<i32, QByteArray> {
let mut map = HashMap::new();
map.insert(USER_ROLE, "number_harm".into());
map.insert(USER_ROLE + 1, "number_policyholder".into());
map.insert(USER_ROLE + 2, "clerk_id".into());
map.insert(USER_ROLE + 1, "date_recorded".into());
map
}
}

View File

@@ -0,0 +1,7 @@
/// number_harm methods
/// List number_harm elements
mod list_number_harm;
/// Edit number_harm elements
mod edit_number_harm;