Add minimal QAbstractItemModel binding
parent
4ebce1251a
commit
b56d1faf9b
|
@ -1,5 +1,4 @@
|
||||||
use interface::HelloNotifier;
|
use interface::*;
|
||||||
use interface::HelloTrait;
|
|
||||||
|
|
||||||
pub struct Hello {
|
pub struct Hello {
|
||||||
notifier: HelloNotifier,
|
notifier: HelloNotifier,
|
||||||
|
@ -26,3 +25,15 @@ impl Drop for Hello {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct RItemModel {
|
||||||
|
notifier: RItemModelNotifier
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RItemModelTrait for RItemModel {
|
||||||
|
fn create(notifier: RItemModelNotifier) -> Self {
|
||||||
|
RItemModel {
|
||||||
|
notifier: notifier
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ use std::slice;
|
||||||
use libc::{uint8_t, uint16_t, size_t};
|
use libc::{uint8_t, uint16_t, size_t};
|
||||||
|
|
||||||
use implementation::Hello;
|
use implementation::Hello;
|
||||||
|
use implementation::RItemModel;
|
||||||
|
|
||||||
pub struct HelloQObject {}
|
pub struct HelloQObject {}
|
||||||
|
|
||||||
|
@ -32,6 +33,12 @@ pub extern fn hello_new(qobject: *const HelloQObject, changed: fn(*const HelloQO
|
||||||
Box::into_raw(Box::new(hello))
|
Box::into_raw(Box::new(hello))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern fn hello_free(ptr: *mut Hello) {
|
||||||
|
if ptr.is_null() { return }
|
||||||
|
unsafe { Box::from_raw(ptr); }
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern fn hello_set(ptr: *mut Hello, s: *const uint16_t, len: size_t) {
|
pub extern fn hello_set(ptr: *mut Hello, s: *const uint16_t, len: size_t) {
|
||||||
let (hello, data) = unsafe {
|
let (hello, data) = unsafe {
|
||||||
|
@ -56,8 +63,30 @@ pub extern fn hello_get(ptr: *mut Hello) -> *const uint8_t {
|
||||||
hello.get_hello().as_ptr()
|
hello.get_hello().as_ptr()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct RItemModelQObject {}
|
||||||
|
|
||||||
|
pub struct RItemModelNotifier {
|
||||||
|
qobject: *const RItemModelQObject
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RItemModelNotifier {
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait RItemModelTrait {
|
||||||
|
fn create(notifier: RItemModelNotifier) -> Self;
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern fn hello_free(ptr: *mut Hello) {
|
pub extern fn ritemmodel_new(qobject: *const RItemModelQObject) -> *mut RItemModel {
|
||||||
|
let notifier = RItemModelNotifier {
|
||||||
|
qobject: qobject
|
||||||
|
};
|
||||||
|
let ritemmodel = RItemModel::create(notifier);
|
||||||
|
Box::into_raw(Box::new(ritemmodel))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern fn ritemmodel_free(ptr: *mut RItemModel) {
|
||||||
if ptr.is_null() { return }
|
if ptr.is_null() { return }
|
||||||
unsafe { Box::from_raw(ptr); }
|
unsafe { Box::from_raw(ptr); }
|
||||||
}
|
}
|
||||||
|
|
1
dev
1
dev
|
@ -1,2 +1,3 @@
|
||||||
#!/usr/bin/bash
|
#!/usr/bin/bash
|
||||||
|
rm -rf __nix_qt5__/
|
||||||
nix-shell -p qtcreator cmake ninja gcc rustc cargo qt5.full extra-cmake-modules kdeFrameworks.kwidgetsaddons kdeFrameworks.kcoreaddons kdeFrameworks.ki18n appstream
|
nix-shell -p qtcreator cmake ninja gcc rustc cargo qt5.full extra-cmake-modules kdeFrameworks.kwidgetsaddons kdeFrameworks.kcoreaddons kdeFrameworks.ki18n appstream
|
||||||
|
|
|
@ -4,10 +4,13 @@
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
RMailObjectInterface* hello_new(void*, void (*)(RMailObject*));
|
RMailObjectInterface* hello_new(void*, void (*)(RMailObject*));
|
||||||
|
void hello_free(RMailObjectInterface*);
|
||||||
void hello_set(RMailObjectInterface*, const uint16_t *, size_t);
|
void hello_set(RMailObjectInterface*, const uint16_t *, size_t);
|
||||||
size_t hello_size(RMailObjectInterface*);
|
size_t hello_size(RMailObjectInterface*);
|
||||||
const char* hello_get(RMailObjectInterface*);
|
const char* hello_get(RMailObjectInterface*);
|
||||||
void hello_free(RMailObjectInterface*);
|
|
||||||
|
RItemModelInterface* ritemmodel_new(void*);
|
||||||
|
void ritemmodel_free(RItemModelInterface*);
|
||||||
}
|
}
|
||||||
|
|
||||||
RMailObject::RMailObject(QObject *parent):
|
RMailObject::RMailObject(QObject *parent):
|
||||||
|
@ -42,3 +45,34 @@ RMailObject::setTree(const QVariantMap& tree) {
|
||||||
m_tree = tree;
|
m_tree = tree;
|
||||||
emit treeChanged();
|
emit treeChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RItemModel::RItemModel(QObject *parent):
|
||||||
|
QAbstractItemModel(parent),
|
||||||
|
d(ritemmodel_new(this))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
RItemModel::~RItemModel() {
|
||||||
|
ritemmodel_free(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
int RItemModel::columnCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
QVariant RItemModel::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
QModelIndex RItemModel::index(int row, int column, const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
return QModelIndex();
|
||||||
|
}
|
||||||
|
QModelIndex RItemModel::parent(const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
return QModelIndex();
|
||||||
|
}
|
||||||
|
int RItemModel::rowCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QVariantMap>
|
#include <QVariantMap>
|
||||||
|
#include <QAbstractItemModel>
|
||||||
|
|
||||||
class RMailObjectInterface;
|
class RMailObjectInterface;
|
||||||
class RMailObject : public QObject
|
class RMailObject : public QObject
|
||||||
|
@ -31,4 +32,19 @@ private:
|
||||||
QString m_userName;
|
QString m_userName;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class RItemModelInterface;
|
||||||
|
class RItemModel : public QAbstractItemModel {
|
||||||
|
Q_OBJECT
|
||||||
|
RItemModelInterface* d;
|
||||||
|
public:
|
||||||
|
explicit RItemModel(QObject *parent = nullptr);
|
||||||
|
~RItemModel();
|
||||||
|
|
||||||
|
int columnCount(const QModelIndex &parent) const;
|
||||||
|
QVariant data(const QModelIndex &index, int role) const;
|
||||||
|
QModelIndex index(int row, int column, const QModelIndex &parent) const;
|
||||||
|
QModelIndex parent(const QModelIndex &index) const;
|
||||||
|
int rowCount(const QModelIndex &parent) const;
|
||||||
|
};
|
||||||
|
|
||||||
#endif // RMAIL_OBJECT_H
|
#endif // RMAIL_OBJECT_H
|
||||||
|
|
11
src/rust.h
11
src/rust.h
|
@ -1,11 +0,0 @@
|
||||||
#include <cstdint>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
uint32_t add(uint32_t lhs, uint32_t rhs);
|
|
||||||
void* hello_new(void (*)(void*));
|
|
||||||
void hello_set(void*, const uint16_t *, size_t);
|
|
||||||
size_t hello_size(void*);
|
|
||||||
const char* hello_get(void*);
|
|
||||||
void hello_free(void *);
|
|
||||||
}
|
|
Loading…
Reference in New Issue