Convert demo

master
Jos van den Oever 2018-05-02 22:18:37 +02:00
parent 5bcb96b561
commit af7b64b82d
8 changed files with 175 additions and 279 deletions

View File

@ -1,8 +1,9 @@
/* generated by rust_qt_binding_generator */ /* generated by rust_qt_binding_generator */
#![allow(unknown_lints)] #![allow(unknown_lints)]
#![allow(mutex_atomic, needless_pass_by_value)] #![allow(mutex_atomic, needless_pass_by_value)]
use libc::{c_int, c_void, uint8_t, uint16_t}; use libc::{c_char, c_ushort, c_int, c_void, uint8_t, uint16_t};
use std::slice; use std::slice;
use std::char::decode_utf16;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::ptr::null; use std::ptr::null;
@ -36,65 +37,20 @@ where
} }
#[repr(C)] pub enum QString {}
pub struct QString {
data: *const uint8_t,
len: c_int,
}
#[repr(C)] fn set_string_from_utf16(s: &mut String, str: *const c_ushort, len: c_int) {
pub struct QStringIn { let utf16 = unsafe { slice::from_raw_parts(str, len as usize) };
data: *const uint16_t, let characters = decode_utf16(utf16.iter().cloned())
len: c_int, .into_iter()
} .map(|r| r.unwrap());
s.clear();
impl QStringIn { s.extend(characters);
fn convert(&self) -> String {
let data = unsafe { slice::from_raw_parts(self.data, self.len as usize) };
String::from_utf16_lossy(data)
}
}
impl<'a> From<&'a str> for QString {
fn from(string: &'a str) -> QString {
QString {
len: string.len() as c_int,
data: string.as_ptr(),
}
}
}
impl<'a> From<&'a String> for QString {
fn from(string: &'a String) -> QString {
QString {
len: string.len() as c_int,
data: string.as_ptr(),
}
}
} }
#[repr(C)]
pub struct QByteArray {
data: *const uint8_t,
len: c_int,
}
impl QByteArray { pub enum QByteArray {}
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 [u8]> for QByteArray {
fn from(value: &'a [u8]) -> QByteArray {
QByteArray {
len: value.len() as c_int,
data: value.as_ptr(),
}
}
}
#[repr(C)] #[repr(C)]
@ -508,13 +464,15 @@ pub unsafe extern "C" fn fibonacci_list_sort(
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn fibonacci_list_data_fibonacci_number(ptr: *const FibonacciList, row: c_int) -> u64 { pub extern "C" fn fibonacci_list_data_fibonacci_number(ptr: *const FibonacciList, row: c_int) -> u64 {
(&*ptr).fibonacci_number(row as usize).into() let o = unsafe { &*ptr };
o.fibonacci_number(row as usize).into()
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn fibonacci_list_data_row(ptr: *const FibonacciList, row: c_int) -> u64 { pub extern "C" fn fibonacci_list_data_row(ptr: *const FibonacciList, row: c_int) -> u64 {
(&*ptr).row(row as usize).into() let o = unsafe { &*ptr };
o.row(row as usize).into()
} }
pub struct FileSystemTreeQObject {} pub struct FileSystemTreeQObject {}
@ -641,24 +599,30 @@ pub unsafe extern "C" fn file_system_tree_free(ptr: *mut FileSystemTree) {
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn file_system_tree_path_get( pub extern "C" fn file_system_tree_path_get(
ptr: *const FileSystemTree, ptr: *const FileSystemTree,
p: *mut c_void, p: *mut c_void,
set: fn(*mut c_void, QString), set: fn(*mut c_void, *const c_char, c_int),
) { ) {
let data = (&*ptr).path(); let o = unsafe { &*ptr };
if let Some(data) = data { let v = o.path();
set(p, data.into()); if let Some(v) = v {
let s: *const c_char = v.as_ptr() as (*const c_char);
set(p, s, v.len() as c_int);
} }
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn file_system_tree_path_set(ptr: *mut FileSystemTree, v: QStringIn) { pub extern "C" fn file_system_tree_path_set(ptr: *mut FileSystemTree, v: *const c_ushort, len: c_int) {
(&mut *ptr).set_path(Some(v.convert())); let o = unsafe { &mut *ptr };
let mut s = String::new();
set_string_from_utf16(&mut s, v, len);
o.set_path(Some(s));
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn file_system_tree_path_set_none(ptr: *mut FileSystemTree) { pub extern "C" fn file_system_tree_path_set_none(ptr: *mut FileSystemTree) {
(&mut *ptr).set_path(None); let o = unsafe { &mut *ptr };
o.set_path(None);
} }
#[no_mangle] #[no_mangle]
@ -734,50 +698,59 @@ pub unsafe extern "C" fn file_system_tree_row(ptr: *const FileSystemTree, item:
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn file_system_tree_data_file_icon( pub extern "C" fn file_system_tree_data_file_icon(
ptr: *const FileSystemTree, item: usize, ptr: *const FileSystemTree, item: usize,
d: *mut c_void, d: *mut QString,
set: fn(*mut c_void, QByteArray), set: fn(*mut QString, *const c_char, len: c_int),
) { ) {
let data = (&*ptr).file_icon(item); let o = unsafe { &*ptr };
set(d, (data).into()); let data = o.file_icon(item);
let s: *const c_char = data.as_ptr() as (*const c_char);
set(d, s, data.len() as c_int);
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn file_system_tree_data_file_name( pub extern "C" fn file_system_tree_data_file_name(
ptr: *const FileSystemTree, item: usize, ptr: *const FileSystemTree, item: usize,
d: *mut c_void, d: *mut QString,
set: fn(*mut c_void, QString), set: fn(*mut QString, *const c_char, len: c_int),
) { ) {
let data = (&*ptr).file_name(item); let o = unsafe { &*ptr };
set(d, (&data).into()); let data = o.file_name(item);
let s: *const c_char = data.as_ptr() as (*const c_char);
set(d, s, data.len() as c_int);
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn file_system_tree_data_file_path( pub extern "C" fn file_system_tree_data_file_path(
ptr: *const FileSystemTree, item: usize, ptr: *const FileSystemTree, item: usize,
d: *mut c_void, d: *mut QString,
set: fn(*mut c_void, QString), set: fn(*mut QString, *const c_char, len: c_int),
) { ) {
let data = (&*ptr).file_path(item); let o = unsafe { &*ptr };
let data = o.file_path(item);
if let Some(data) = data { if let Some(data) = data {
set(d, QString::from(&data)); let s: *const c_char = data.as_ptr() as (*const c_char);
set(d, s, data.len() as c_int);
} }
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn file_system_tree_data_file_permissions(ptr: *const FileSystemTree, item: usize) -> i32 { pub extern "C" fn file_system_tree_data_file_permissions(ptr: *const FileSystemTree, item: usize) -> i32 {
(&*ptr).file_permissions(item).into() let o = unsafe { &*ptr };
o.file_permissions(item).into()
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn file_system_tree_data_file_size(ptr: *const FileSystemTree, item: usize) -> COption<u64> { pub extern "C" fn file_system_tree_data_file_size(ptr: *const FileSystemTree, item: usize) -> COption<u64> {
(&*ptr).file_size(item).into() let o = unsafe { &*ptr };
o.file_size(item).into()
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn file_system_tree_data_file_type(ptr: *const FileSystemTree, item: usize) -> i32 { pub extern "C" fn file_system_tree_data_file_type(ptr: *const FileSystemTree, item: usize) -> i32 {
(&*ptr).file_type(item).into() let o = unsafe { &*ptr };
o.file_type(item).into()
} }
pub struct ProcessesQObject {} pub struct ProcessesQObject {}
@ -987,48 +960,57 @@ pub unsafe extern "C" fn processes_row(ptr: *const Processes, item: usize) -> c_
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn processes_data_cmd( pub extern "C" fn processes_data_cmd(
ptr: *const Processes, item: usize, ptr: *const Processes, item: usize,
d: *mut c_void, d: *mut QString,
set: fn(*mut c_void, QString), set: fn(*mut QString, *const c_char, len: c_int),
) { ) {
let data = (&*ptr).cmd(item); let o = unsafe { &*ptr };
set(d, (&data).into()); let data = o.cmd(item);
let s: *const c_char = data.as_ptr() as (*const c_char);
set(d, s, data.len() as c_int);
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn processes_data_cpu_percentage(ptr: *const Processes, item: usize) -> u8 { pub extern "C" fn processes_data_cpu_percentage(ptr: *const Processes, item: usize) -> u8 {
(&*ptr).cpu_percentage(item).into() let o = unsafe { &*ptr };
o.cpu_percentage(item).into()
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn processes_data_cpu_usage(ptr: *const Processes, item: usize) -> f32 { pub extern "C" fn processes_data_cpu_usage(ptr: *const Processes, item: usize) -> f32 {
(&*ptr).cpu_usage(item).into() let o = unsafe { &*ptr };
o.cpu_usage(item).into()
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn processes_data_memory(ptr: *const Processes, item: usize) -> u64 { pub extern "C" fn processes_data_memory(ptr: *const Processes, item: usize) -> u64 {
(&*ptr).memory(item).into() let o = unsafe { &*ptr };
o.memory(item).into()
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn processes_data_name( pub extern "C" fn processes_data_name(
ptr: *const Processes, item: usize, ptr: *const Processes, item: usize,
d: *mut c_void, d: *mut QString,
set: fn(*mut c_void, QString), set: fn(*mut QString, *const c_char, len: c_int),
) { ) {
let data = (&*ptr).name(item); let o = unsafe { &*ptr };
set(d, (data).into()); let data = o.name(item);
let s: *const c_char = data.as_ptr() as (*const c_char);
set(d, s, data.len() as c_int);
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn processes_data_pid(ptr: *const Processes, item: usize) -> u32 { pub extern "C" fn processes_data_pid(ptr: *const Processes, item: usize) -> u32 {
(&*ptr).pid(item).into() let o = unsafe { &*ptr };
o.pid(item).into()
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn processes_data_uid(ptr: *const Processes, item: usize) -> u32 { pub extern "C" fn processes_data_uid(ptr: *const Processes, item: usize) -> u32 {
(&*ptr).uid(item).into() let o = unsafe { &*ptr };
o.uid(item).into()
} }
pub struct TimeSeriesQObject {} pub struct TimeSeriesQObject {}
@ -1172,8 +1154,9 @@ pub unsafe extern "C" fn time_series_sort(
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn time_series_data_cos(ptr: *const TimeSeries, row: c_int) -> f32 { pub extern "C" fn time_series_data_cos(ptr: *const TimeSeries, row: c_int) -> f32 {
(&*ptr).cos(row as usize).into() let o = unsafe { &*ptr };
o.cos(row as usize).into()
} }
#[no_mangle] #[no_mangle]
@ -1185,8 +1168,9 @@ pub unsafe extern "C" fn time_series_set_data_cos(
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn time_series_data_sin(ptr: *const TimeSeries, row: c_int) -> f32 { pub extern "C" fn time_series_data_sin(ptr: *const TimeSeries, row: c_int) -> f32 {
(&*ptr).sin(row as usize).into() let o = unsafe { &*ptr };
o.sin(row as usize).into()
} }
#[no_mangle] #[no_mangle]
@ -1198,8 +1182,9 @@ pub unsafe extern "C" fn time_series_set_data_sin(
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn time_series_data_time(ptr: *const TimeSeries, row: c_int) -> f32 { pub extern "C" fn time_series_data_time(ptr: *const TimeSeries, row: c_int) -> f32 {
(&*ptr).time(row as usize).into() let o = unsafe { &*ptr };
o.time(row as usize).into()
} }
#[no_mangle] #[no_mangle]

View File

@ -39,40 +39,15 @@ namespace {
} }
}; };
struct qstring_t { typedef void (*qstring_set)(QString* val, const char* utf8, int nbytes);
private: void set_qstring(QString* val, const char* utf8, int nbytes) {
const void* data; *val = QString::fromUtf8(utf8, nbytes);
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);
}
};
typedef void (*qstring_set)(QString*, qstring_t*);
void set_qstring(QString* v, qstring_t* val) {
*v = *val;
} }
struct qbytearray_t { typedef void (*qbytearray_set)(QByteArray* val, const char* bytes, int nbytes);
private: void set_qbytearray(QByteArray* v, const char* bytes, int nbytes) {
const char* data; v->truncate(0);
int len; v->append(bytes, nbytes);
public:
qbytearray_t(const QByteArray& v):
data(v.data()),
len(v.size()) {
}
operator QByteArray() const {
return QByteArray(data, len);
}
};
typedef void (*qbytearray_set)(QByteArray*, qbytearray_t*);
void set_qbytearray(QByteArray* v, qbytearray_t* val) {
*v = *val;
} }
struct qmodelindex_t { struct qmodelindex_t {
@ -516,7 +491,7 @@ extern "C" {
void (*)(FileSystemTree*)); void (*)(FileSystemTree*));
void file_system_tree_free(FileSystemTree::Private*); void file_system_tree_free(FileSystemTree::Private*);
void file_system_tree_path_get(const FileSystemTree::Private*, QString*, qstring_set); void file_system_tree_path_get(const FileSystemTree::Private*, QString*, qstring_set);
void file_system_tree_path_set(FileSystemTree::Private*, qstring_t); void file_system_tree_path_set(FileSystemTree::Private*, const ushort *str, int len);
void file_system_tree_path_set_none(FileSystemTree::Private*); void file_system_tree_path_set_none(FileSystemTree::Private*);
}; };
@ -1380,7 +1355,7 @@ void FileSystemTree::setPath(const QString& v) {
if (v.isNull()) { if (v.isNull()) {
file_system_tree_path_set_none(m_d); file_system_tree_path_set_none(m_d);
} else { } else {
file_system_tree_path_set(m_d, v); file_system_tree_path_set(m_d, reinterpret_cast<const ushort*>(v.data()), v.size());
} }
} }
Processes::Processes(bool /*owned*/, QObject *parent): Processes::Processes(bool /*owned*/, QObject *parent):

View File

@ -607,33 +607,33 @@ pub extern "C" fn %2_data_%3(
d: *mut QString, d: *mut QString,
set: fn(*mut QString, *const c_char, len: c_int), set: fn(*mut QString, *const c_char, len: c_int),
) { ) {
let o = unsafe { & *ptr }; let o = unsafe { &*ptr };
let data = o.%3(%6); let data = o.%3(%6);
let s: *const c_char = data.as_ptr() as (*const c_char); let s: *const c_char = data.as_ptr() as (*const c_char);
set(d, s, data.len() as i32); set(d, s, data.len() as c_int);
} }
)").arg(o.name, lcname, snakeCase(ip.name), indexDecl, index); )").arg(o.name, lcname, snakeCase(ip.name), indexDecl, index);
} else if (ip.type.name == "QString") { } else if (ip.type.name == "QString") {
r << QString(R"( r << QString(R"(
#[no_mangle] #[no_mangle]
pub extern "C" fn %2_data_%3( pub extern "C" fn %2_data_%3(
ptr: *const %1%5, ptr: *const %1%4,
d: *mut QString, d: *mut QString,
set: fn(*mut QString, *const c_char, len: c_int), set: fn(*mut QString, *const c_char, len: c_int),
) { ) {
let o = unsafe { &mut *ptr }; let o = unsafe { &*ptr };
let data = o.%3(%6); let data = o.%3(%5);
if let Some(data) = data { if let Some(data) = data {
let s: *const c_char = data.as_ptr() as (*const c_char); let s: *const c_char = data.as_ptr() as (*const c_char);
set(d, s, data.len()); set(d, s, data.len() as c_int);
} }
} }
)").arg(o.name, lcname, snakeCase(ip.name), ip.type.name, indexDecl, index); )").arg(o.name, lcname, snakeCase(ip.name), indexDecl, index);
} else { } else {
r << QString(R"( r << QString(R"(
#[no_mangle] #[no_mangle]
pub extern "C" fn %2_data_%3(ptr: *const %1%5) -> %4 { pub extern "C" fn %2_data_%3(ptr: *const %1%5) -> %4 {
let o = unsafe { &mut *ptr }; let o = unsafe { &*ptr };
o.%3(%6).into() o.%3(%6).into()
} }
)").arg(o.name, lcname, snakeCase(ip.name), rustCType(ip), indexDecl, index); )").arg(o.name, lcname, snakeCase(ip.name), rustCType(ip), indexDecl, index);

View File

@ -204,10 +204,10 @@ pub extern "C" fn persons_data_user_name(
d: *mut QString, d: *mut QString,
set: fn(*mut QString, *const c_char, len: c_int), set: fn(*mut QString, *const c_char, len: c_int),
) { ) {
let o = unsafe { & *ptr }; let o = unsafe { &*ptr };
let data = o.user_name(row as usize); let data = o.user_name(row as usize);
let s: *const c_char = data.as_ptr() as (*const c_char); let s: *const c_char = data.as_ptr() as (*const c_char);
set(d, s, data.len() as i32); set(d, s, data.len() as c_int);
} }
#[no_mangle] #[no_mangle]

View File

@ -1,8 +1,9 @@
/* generated by rust_qt_binding_generator */ /* generated by rust_qt_binding_generator */
#![allow(unknown_lints)] #![allow(unknown_lints)]
#![allow(mutex_atomic, needless_pass_by_value)] #![allow(mutex_atomic, needless_pass_by_value)]
use libc::{c_int, c_void, uint8_t, uint16_t}; use libc::{c_char, c_ushort, c_int, c_void, uint8_t, uint16_t};
use std::slice; use std::slice;
use std::char::decode_utf16;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::ptr::null; use std::ptr::null;
@ -10,42 +11,17 @@ use std::ptr::null;
use implementation::*; use implementation::*;
#[repr(C)] pub enum QString {}
pub struct QString {
data: *const uint8_t, fn set_string_from_utf16(s: &mut String, str: *const c_ushort, len: c_int) {
len: c_int, let utf16 = unsafe { slice::from_raw_parts(str, len as usize) };
let characters = decode_utf16(utf16.iter().cloned())
.into_iter()
.map(|r| r.unwrap());
s.clear();
s.extend(characters);
} }
#[repr(C)]
pub struct QStringIn {
data: *const uint16_t,
len: c_int,
}
impl QStringIn {
fn convert(&self) -> String {
let data = unsafe { slice::from_raw_parts(self.data, self.len as usize) };
String::from_utf16_lossy(data)
}
}
impl<'a> From<&'a str> for QString {
fn from(string: &'a str) -> QString {
QString {
len: string.len() as c_int,
data: string.as_ptr(),
}
}
}
impl<'a> From<&'a String> for QString {
fn from(string: &'a String) -> QString {
QString {
len: string.len() as c_int,
data: string.as_ptr(),
}
}
}
pub struct GroupQObject {} pub struct GroupQObject {}
@ -153,18 +129,23 @@ pub unsafe extern "C" fn inner_object_free(ptr: *mut InnerObject) {
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn inner_object_description_get( pub extern "C" fn inner_object_description_get(
ptr: *const InnerObject, ptr: *const InnerObject,
p: *mut c_void, p: *mut c_void,
set: fn(*mut c_void, QString), set: fn(*mut c_void, *const c_char, c_int),
) { ) {
let data = (&*ptr).description(); let o = unsafe { &*ptr };
set(p, data.into()); let v = o.description();
let s: *const c_char = v.as_ptr() as (*const c_char);
set(p, s, v.len() as c_int);
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn inner_object_description_set(ptr: *mut InnerObject, v: QStringIn) { pub extern "C" fn inner_object_description_set(ptr: *mut InnerObject, v: *const c_ushort, len: c_int) {
(&mut *ptr).set_description(v.convert()); let o = unsafe { &mut *ptr };
let mut s = String::new();
set_string_from_utf16(&mut s, v, len);
o.set_description(s);
} }
pub struct PersonQObject {} pub struct PersonQObject {}

View File

@ -1,8 +1,9 @@
/* generated by rust_qt_binding_generator */ /* generated by rust_qt_binding_generator */
#![allow(unknown_lints)] #![allow(unknown_lints)]
#![allow(mutex_atomic, needless_pass_by_value)] #![allow(mutex_atomic, needless_pass_by_value)]
use libc::{c_int, c_void, uint8_t, uint16_t}; use libc::{c_char, c_ushort, c_int, c_void, uint8_t, uint16_t};
use std::slice; use std::slice;
use std::char::decode_utf16;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::ptr::null; use std::ptr::null;
@ -36,42 +37,17 @@ where
} }
#[repr(C)] pub enum QString {}
pub struct QString {
data: *const uint8_t, fn set_string_from_utf16(s: &mut String, str: *const c_ushort, len: c_int) {
len: c_int, let utf16 = unsafe { slice::from_raw_parts(str, len as usize) };
let characters = decode_utf16(utf16.iter().cloned())
.into_iter()
.map(|r| r.unwrap());
s.clear();
s.extend(characters);
} }
#[repr(C)]
pub struct QStringIn {
data: *const uint16_t,
len: c_int,
}
impl QStringIn {
fn convert(&self) -> String {
let data = unsafe { slice::from_raw_parts(self.data, self.len as usize) };
String::from_utf16_lossy(data)
}
}
impl<'a> From<&'a str> for QString {
fn from(string: &'a str) -> QString {
QString {
len: string.len() as c_int,
data: string.as_ptr(),
}
}
}
impl<'a> From<&'a String> for QString {
fn from(string: &'a String) -> QString {
QString {
len: string.len() as c_int,
data: string.as_ptr(),
}
}
}
#[repr(C)] #[repr(C)]
@ -267,19 +243,24 @@ pub unsafe extern "C" fn persons_row(ptr: *const Persons, item: usize) -> c_int
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn persons_data_user_name( pub extern "C" fn persons_data_user_name(
ptr: *const Persons, item: usize, ptr: *const Persons, item: usize,
d: *mut c_void, d: *mut QString,
set: fn(*mut c_void, QString), set: fn(*mut QString, *const c_char, len: c_int),
) { ) {
let data = (&*ptr).user_name(item); let o = unsafe { &*ptr };
set(d, (data).into()); let data = o.user_name(item);
let s: *const c_char = data.as_ptr() as (*const c_char);
set(d, s, data.len() as c_int);
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn persons_set_data_user_name( pub extern "C" fn persons_set_data_user_name(
ptr: *mut Persons, item: usize, ptr: *mut Persons, item: usize,
v: QStringIn, s: *const c_ushort, len: c_int,
) -> bool { ) -> bool {
(&mut *ptr).set_user_name(item, v.convert()) let o = unsafe { &mut *ptr };
let mut v = String::new();
set_string_from_utf16(&mut v, s, len);
o.set_user_name(item, v)
} }

View File

@ -3,22 +3,9 @@
namespace { namespace {
struct qstring_t { typedef void (*qstring_set)(QString* val, const char* utf8, int nbytes);
private: void set_qstring(QString* val, const char* utf8, int nbytes) {
const void* data; *val = QString::fromUtf8(utf8, nbytes);
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);
}
};
typedef void (*qstring_set)(QString*, qstring_t*);
void set_qstring(QString* v, qstring_t* val) {
*v = *val;
} }
inline void innerObjectDescriptionChanged(InnerObject* o) inline void innerObjectDescriptionChanged(InnerObject* o)
{ {
@ -35,7 +22,7 @@ extern "C" {
InnerObject::Private* inner_object_new(InnerObject*, void (*)(InnerObject*)); InnerObject::Private* inner_object_new(InnerObject*, void (*)(InnerObject*));
void inner_object_free(InnerObject::Private*); void inner_object_free(InnerObject::Private*);
void inner_object_description_get(const InnerObject::Private*, QString*, qstring_set); void inner_object_description_get(const InnerObject::Private*, QString*, qstring_set);
void inner_object_description_set(InnerObject::Private*, qstring_t); void inner_object_description_set(InnerObject::Private*, const ushort *str, int len);
}; };
extern "C" { extern "C" {
@ -103,7 +90,7 @@ QString InnerObject::description() const
return v; return v;
} }
void InnerObject::setDescription(const QString& v) { void InnerObject::setDescription(const QString& v) {
inner_object_description_set(m_d, v); inner_object_description_set(m_d, reinterpret_cast<const ushort*>(v.data()), v.size());
} }
Person::Person(bool /*owned*/, QObject *parent): Person::Person(bool /*owned*/, QObject *parent):
QObject(parent), QObject(parent),

View File

@ -15,22 +15,9 @@ namespace {
} }
}; };
struct qstring_t { typedef void (*qstring_set)(QString* val, const char* utf8, int nbytes);
private: void set_qstring(QString* val, const char* utf8, int nbytes) {
const void* data; *val = QString::fromUtf8(utf8, nbytes);
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);
}
};
typedef void (*qstring_set)(QString*, qstring_t*);
void set_qstring(QString* v, qstring_t* val) {
*v = *val;
} }
struct qmodelindex_t { struct qmodelindex_t {
@ -40,7 +27,7 @@ namespace {
} }
extern "C" { extern "C" {
void persons_data_user_name(const Persons::Private*, quintptr, QString*, qstring_set); void persons_data_user_name(const Persons::Private*, quintptr, QString*, qstring_set);
bool persons_set_data_user_name(Persons::Private*, quintptr, qstring_t); bool persons_set_data_user_name(Persons::Private*, quintptr, const ushort* s, int len);
void persons_sort(Persons::Private*, unsigned char column, Qt::SortOrder order = Qt::AscendingOrder); void persons_sort(Persons::Private*, unsigned char column, Qt::SortOrder order = Qt::AscendingOrder);
int persons_row_count(const Persons::Private*, quintptr, bool); int persons_row_count(const Persons::Private*, quintptr, bool);
@ -140,7 +127,7 @@ QVariant Persons::userName(const QModelIndex& index) const
bool Persons::setUserName(const QModelIndex& index, const QVariant& value) bool Persons::setUserName(const QModelIndex& index, const QVariant& value)
{ {
bool set = false; bool set = false;
set = persons_set_data_user_name(m_d, index.internalId(), value.value<QString>()); const QString s = value.value<QString>(); set = persons_set_data_user_name(m_d, index.internalId(), s.utf16(), s.length());
if (set) { if (set) {
emit dataChanged(index, index); emit dataChanged(index, index);
} }