mirror of
https://github.com/status-im/dotherside.git
synced 2025-02-12 12:46:24 +00:00
Add wrapping of the QModelIndex data type
This commit is contained in:
parent
12479b928f
commit
733266b362
@ -7,6 +7,7 @@
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtQml/QQmlApplicationEngine>
|
||||
#include <QtCore/QModelIndex>
|
||||
|
||||
#include "DynamicQObject.h"
|
||||
|
||||
@ -356,3 +357,61 @@ void dos_qobject_property_create(void* vptr,
|
||||
QString(writeSlot),
|
||||
QString(notifySignal));
|
||||
}
|
||||
|
||||
void dos_qmodelindex_create(void** vptr)
|
||||
{
|
||||
auto index = new QModelIndex();
|
||||
*vptr = index;
|
||||
}
|
||||
|
||||
void dos_qmodelindex_delete(void* vptr)
|
||||
{
|
||||
auto index = reinterpret_cast<QModelIndex*>(vptr);
|
||||
delete index;
|
||||
}
|
||||
|
||||
void dos_qmodelindex_row(void* vptr, int& row)
|
||||
{
|
||||
auto index = reinterpret_cast<QModelIndex*>(vptr);
|
||||
row = index->row();
|
||||
}
|
||||
|
||||
void dos_qmodelindex_column(void* vptr, int& column)
|
||||
{
|
||||
auto index = reinterpret_cast<QModelIndex*>(vptr);
|
||||
column = index->column();
|
||||
}
|
||||
|
||||
void dos_qmodelindex_isValid(void* vptr, bool& isValid)
|
||||
{
|
||||
auto index = reinterpret_cast<QModelIndex*>(vptr);
|
||||
isValid = index->isValid();
|
||||
}
|
||||
|
||||
void dos_qmodelindex_data(void* vptr, int role, void* data)
|
||||
{
|
||||
auto index = reinterpret_cast<QModelIndex*>(vptr);
|
||||
auto result = reinterpret_cast<QVariant*>(data);
|
||||
*result = index->data(role);
|
||||
}
|
||||
|
||||
void dos_qmodelindex_parent(void* vptr, void* parent)
|
||||
{
|
||||
auto index = reinterpret_cast<QModelIndex*>(vptr);
|
||||
auto parentIndex = reinterpret_cast<QModelIndex*>(parent);
|
||||
*parentIndex = index->parent();
|
||||
}
|
||||
|
||||
void dos_qmodelindex_child(void* vptr, int row, int column, void* child)
|
||||
{
|
||||
auto index = reinterpret_cast<QModelIndex*>(vptr);
|
||||
auto childIndex = reinterpret_cast<QModelIndex*>(child);
|
||||
*childIndex = index->child(row, column);
|
||||
}
|
||||
|
||||
void dos_qmodelindex_sibling(void* vptr, int row, int column, void* sibling)
|
||||
{
|
||||
auto index = reinterpret_cast<QModelIndex*>(vptr);
|
||||
auto siblingIndex = reinterpret_cast<QModelIndex*>(sibling);
|
||||
*siblingIndex = index->sibling(row, column);
|
||||
}
|
||||
|
@ -98,6 +98,17 @@ extern "C"
|
||||
const char* notifySignal);
|
||||
void dos_qobject_delete(void *vptr);
|
||||
|
||||
// QModelIndex
|
||||
void dos_qmodelindex_create(void** vptr);
|
||||
void dos_qmodelindex_delete(void* vptr);
|
||||
void dos_qmodelindex_row(void* vptr, int& row);
|
||||
void dos_qmodelindex_column(void* vptr, int& column);
|
||||
void dos_qmodelindex_isValid(void* vptr, bool& isValid);
|
||||
void dos_qmodelindex_data(void* vptr, int role, void* data);
|
||||
void dos_qmodelindex_parent(void* vptr, void* parent);
|
||||
void dos_qmodelindex_child(void* vptr, int row, int column, void* child);
|
||||
void dos_qmodelindex_sibling(void* vptr, int row, int column, void* sibling);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -491,3 +491,64 @@ proc newQQuickView*(): QQuickView =
|
||||
## Return a new QQuickView
|
||||
newWithCondFinalizer(result, delete)
|
||||
result.create()
|
||||
|
||||
# QModelIndex
|
||||
proc dos_qmodelindex_create(modelIndex: var RawQModelIndex) {.cdecl, dynlib:"libDOtherSide.so", importc.}
|
||||
proc dos_qmodelindex_delete(modelIndex: RawQModelIndex) {.cdecl, dynlib:"libDOtherSide.so", importc.}
|
||||
proc dos_qmodelindex_row(modelIndex: RawQModelIndex, row: var cint) {.cdecl, dynlib:"libDOtherSide.so", importc.}
|
||||
proc dos_qmodelindex_column(modelIndex: RawQModelIndex, column: var cint) {.cdecl, dynlib:"libDOtherSide.so", importc.}
|
||||
proc dos_qmodelindex_isValid(modelIndex: RawQModelIndex, column: var bool) {.cdecl, dynlib:"libDOtherSide.so", importc.}
|
||||
proc dos_qmodelindex_data(modelIndex: RawQModelIndex, role: cint, data: RawQVariant) {.cdecl, dynlib:"libDOtherSide.so", importc.}
|
||||
proc dos_qmodelindex_parent(modelIndex: RawQModelIndex, parent: RawQModelIndex) {.cdecl, dynlib:"libDOtherSide.so", importc.}
|
||||
proc dos_qmodelindex_child(modelIndex: RawQModelIndex, row: cint, column: cint, parent: RawQModelIndex) {.cdecl, dynlib:"libDOtherSide.so", importc.}
|
||||
proc dos_qmodelindex_sibling(modelIndex: RawQModelIndex, row: cint, column: cint, sibling: RawQModelIndex) {.cdecl, dynlib:"libDOtherSide.so", importc.}
|
||||
|
||||
proc create(modelIndex: var QModelIndex) =
|
||||
## Create a new QModelIndex
|
||||
dos_qmodelindex_create(modelIndex.data)
|
||||
modelIndex.deleted = false
|
||||
|
||||
proc delete(modelIndex: QModelIndex) =
|
||||
## Delete the given QModelIndex
|
||||
if not modelIndex.deleted:
|
||||
debugMsg("QModelIndex", "delete")
|
||||
dos_qmodelindex_delete(modelIndex.data)
|
||||
modelIndex.data = nil.RawQModelIndex
|
||||
modelIndex.deleted = true
|
||||
|
||||
proc newQModelIndex*(): QModelIndex =
|
||||
## Return a new QModelIndex
|
||||
newWithCondFinalizer(result, delete)
|
||||
result.create()
|
||||
|
||||
proc row(modelIndex: QModelIndex): cint =
|
||||
## Return the index row
|
||||
dos_qmodelindex_row(modelIndex.data, result)
|
||||
|
||||
proc column(modelIndex: QModelIndex): cint =
|
||||
## Return the index column
|
||||
dos_qmodelindex_column(modelIndex.data, result)
|
||||
|
||||
proc isValid(modelIndex: QModelIndex): bool =
|
||||
## Return true if the index is valid, false otherwise
|
||||
dos_qmodelindex_isValid(modelIndex.data, result)
|
||||
|
||||
proc data(modelIndex: QModelIndex, role: cint): QVariant =
|
||||
## Return the model data associated to the given role
|
||||
result = newQVariant()
|
||||
dos_qmodelindex_data(modelIndex.data, role, result.data)
|
||||
|
||||
proc parent(modelIndex: QModelIndex): QModelIndex =
|
||||
## Return the parent index
|
||||
result = newQModelIndex()
|
||||
dos_qmodelindex_parent(modelIndex.data, result.data)
|
||||
|
||||
proc child(modelIndex: QModelIndex, row: cint, column: cint): QModelIndex =
|
||||
## Return the child index associated to the given row and column
|
||||
result = newQModelIndex()
|
||||
dos_qmodelindex_child(modelIndex.data, row, column, result.data)
|
||||
|
||||
proc sibling(modelIndex: QModelIndex, row: cint, column: cint): QModelIndex =
|
||||
## Return the sibling index associated to the given row and column
|
||||
result = newQModelIndex()
|
||||
dos_qmodelindex_sibling(modelIndex.data, row, column, result.data)
|
||||
|
@ -33,3 +33,7 @@ type
|
||||
|
||||
QQmlContext* = distinct pointer ## A QQmlContext
|
||||
|
||||
RawQModelIndex = distinct pointer
|
||||
QModelIndex = ref object of RootObj ## A QModelIndex
|
||||
data: RawQModelIndex
|
||||
deleted: bool
|
||||
|
Loading…
x
Reference in New Issue
Block a user