Started adding support for RoleNames

This commit is contained in:
Filippo Cucchetto 2015-01-31 12:50:14 +01:00
parent df498cb64c
commit 95aeef5db0
7 changed files with 66 additions and 6 deletions

View File

@ -31,3 +31,10 @@ void* BaseQAbstractListModel::modelObject()
{ {
return m_modelObject; return m_modelObject;
} }
QHash<int,QByteArray> BaseQAbstractListModel::roleNames() const
{
QHash<int, QByteArray> result;
return result;
}

View File

@ -21,6 +21,9 @@ class BaseQAbstractListModel : public QAbstractListModel
/// Return the dModelPointer /// Return the dModelPointer
void* modelObject(); void* modelObject();
/// Return the roleNames
virtual QHash<int, QByteArray> roleNames() const override;
private: private:
void* m_modelObject; void* m_modelObject;
RowCountCallback m_rowCountCallback; RowCountCallback m_rowCountCallback;

View File

@ -1,13 +1,13 @@
#include "DOtherSide.h" #include "DOtherSide.h"
#include <QtWidgets/QApplication>
#include <QtGui/QGuiApplication>
#include <QtQuick/QQuickView>
#include <QtQml/QQmlContext>
#include <QtCore/QDir> #include <QtCore/QDir>
#include <QtCore/QDebug> #include <QtCore/QDebug>
#include <QtQml/QQmlApplicationEngine>
#include <QtCore/QModelIndex> #include <QtCore/QModelIndex>
#include <QtGui/QGuiApplication>
#include <QtQml/QQmlContext>
#include <QtQml/QQmlApplicationEngine>
#include <QtQuick/QQuickView>
#include <QtWidgets/QApplication>
#include "DynamicQObject.h" #include "DynamicQObject.h"
#include "BaseQAbstractListModel.h" #include "BaseQAbstractListModel.h"
@ -446,3 +446,21 @@ void dos_qabstractlistmodel_delete(void* vptr)
auto model = reinterpret_cast<BaseQAbstractListModel*>(vptr); auto model = reinterpret_cast<BaseQAbstractListModel*>(vptr);
delete model; delete model;
} }
void dos_qhash_int_qbytearray_create(QHashIntQByteArrayVoidPtr* vptr)
{
*vptr = new QHash<int, QByteArray>();
}
void dos_qhash_int_qbytearray_delete(QHashIntQByteArrayVoidPtr vptr)
{
auto qHash = reinterpret_cast<QHash<int,QByteArray>*>(vptr);
delete qHash;
}
void dos_qhash_int_qbytearray_insert(QHashIntQByteArrayVoidPtr vptr, int key, ConstCharPtr value)
{
auto qHash = reinterpret_cast<QHash<int, QByteArray>*>(vptr);
qHash->insert(key, QByteArray(value));
}

View File

@ -113,6 +113,11 @@ extern "C"
void dos_qmodelindex_child(void* vptr, int row, int column, void* child); void dos_qmodelindex_child(void* vptr, int row, int column, void* child);
void dos_qmodelindex_sibling(void* vptr, int row, int column, void* sibling); void dos_qmodelindex_sibling(void* vptr, int row, int column, void* sibling);
// QHash<int, QByteArray>
void dos_qhash_int_qbytearray_create(QHashIntQByteArrayVoidPtr* vptr);
void dos_qhash_int_qbytearray_delete(QHashIntQByteArrayVoidPtr vptr);
void dos_qhash_int_qbytearray_insert(QHashIntQByteArrayVoidPtr vptr, int key, ConstCharPtr value);
// QAbstractListModel // QAbstractListModel
void dos_qabstractlistmodel_create(void** vptr, void dos_qabstractlistmodel_create(void** vptr,
void* callbackObject, void* callbackObject,

View File

@ -3,7 +3,6 @@ import macros
import typeinfo import typeinfo
type MyQAbstractListModel = ref object of QAbstractListModel type MyQAbstractListModel = ref object of QAbstractListModel
m_name: string
proc create(self: MyQAbstractListModel) = proc create(self: MyQAbstractListModel) =
var qAbstractListModel = self.QAbstractListModel var qAbstractListModel = self.QAbstractListModel
@ -22,6 +21,7 @@ method rowCount(self: MyQAbstractListModel, index: QModelIndex): cint =
return 3 return 3
method data(self: MyQAbstractListModel, index: QModelIndex, role: cint): QVariant = method data(self: MyQAbstractListModel, index: QModelIndex, role: cint): QVariant =
echo "index valid: " & $index.isValid & " row: " & $index.row & " column: " & $index.column
return nil return nil
proc mainProc() = proc mainProc() =

View File

@ -630,3 +630,24 @@ proc newQAbstractListModel*(): QAbstractListModel =
## Return a new QAbstractListModel ## Return a new QAbstractListModel
newWithCondFinalizer(result, delete) newWithCondFinalizer(result, delete)
result.create() result.create()
# RoleNames QHash
proc dos_qhash_int_qbytearray_create(qHash: RawQHashIntByteArray) {.cdecl, dynlib:"libDOtherSide.so", importc.}
proc dos_qhash_int_qbytearray_delete(qHash: RawQHashIntByteArray) {.cdecl, dynlib:"libDOtherSide.so", importc.}
proc dos_qhash_int_qbytearray_insert(qHash: RawQHashIntByteArray, key: int, value: cstring) {.cdecl, dynlib:"libDOtherSide.so", importc.}
proc create(qHash: var QHashIntByteArray) =
debugMsg("QHashIntByteArray", "create")
dos_qhash_int_qbytearray_create(qHash.data)
qHash.deleted = false
proc delete(qHash: QHashIntByteArray) =
dos_qhash_int_qbytearray_delete(qHash.data)
qHash.deleted = true
proc insert(qHash: QHashIntByteArray, key: int, value: cstring) =
dos_qhash_int_qbytearray_insert(qHash.data, key, value)
proc newQHashIntQByteArray(): QHashIntByteArray =
newWithCondFinalizer(result, delete)
result.create()

View File

@ -43,3 +43,9 @@ type
data: RawQAbstractListModel data: RawQAbstractListModel
deleted: bool deleted: bool
QAbstractListModel* = ref QAbstractListModelObj ## A QAbstractListModel QAbstractListModel* = ref QAbstractListModelObj ## A QAbstractListModel
RawQHashIntByteArray = distinct pointer
QHashIntByteArrayObj = object of RootObj
data: RawQHashIntByteArray
deleted: bool
QHashIntByteArray = ref QHashIntByteArrayObj ## A QHash<int,QByteArray>