Add minimal QAbstractItemModel binding

master
Jos van den Oever 2017-08-03 21:27:32 +02:00
parent 4ebce1251a
commit b56d1faf9b
6 changed files with 95 additions and 15 deletions

View File

@ -1,5 +1,4 @@
use interface::HelloNotifier;
use interface::HelloTrait;
use interface::*;
pub struct Hello {
notifier: HelloNotifier,
@ -26,3 +25,15 @@ impl Drop for Hello {
fn drop(&mut self) {
}
}
pub struct RItemModel {
notifier: RItemModelNotifier
}
impl RItemModelTrait for RItemModel {
fn create(notifier: RItemModelNotifier) -> Self {
RItemModel {
notifier: notifier
}
}
}

View File

@ -2,6 +2,7 @@ use std::slice;
use libc::{uint8_t, uint16_t, size_t};
use implementation::Hello;
use implementation::RItemModel;
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))
}
#[no_mangle]
pub extern fn hello_free(ptr: *mut Hello) {
if ptr.is_null() { return }
unsafe { Box::from_raw(ptr); }
}
#[no_mangle]
pub extern fn hello_set(ptr: *mut Hello, s: *const uint16_t, len: size_t) {
let (hello, data) = unsafe {
@ -56,8 +63,30 @@ pub extern fn hello_get(ptr: *mut Hello) -> *const uint8_t {
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]
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 }
unsafe { Box::from_raw(ptr); }
}

1
dev
View File

@ -1,2 +1,3 @@
#!/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

View File

@ -4,10 +4,13 @@
extern "C" {
RMailObjectInterface* hello_new(void*, void (*)(RMailObject*));
void hello_free(RMailObjectInterface*);
void hello_set(RMailObjectInterface*, const uint16_t *, size_t);
size_t hello_size(RMailObjectInterface*);
const char* hello_get(RMailObjectInterface*);
void hello_free(RMailObjectInterface*);
RItemModelInterface* ritemmodel_new(void*);
void ritemmodel_free(RItemModelInterface*);
}
RMailObject::RMailObject(QObject *parent):
@ -42,3 +45,34 @@ RMailObject::setTree(const QVariantMap& tree) {
m_tree = tree;
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;
}

View File

@ -4,6 +4,7 @@
#include <QObject>
#include <QString>
#include <QVariantMap>
#include <QAbstractItemModel>
class RMailObjectInterface;
class RMailObject : public QObject
@ -31,4 +32,19 @@ private:
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

View File

@ -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 *);
}