From 95aeef5db0eedcee5a07601fbaa5b212ea04f944 Mon Sep 17 00:00:00 2001 From: Filippo Cucchetto Date: Sat, 31 Jan 2015 12:50:14 +0100 Subject: [PATCH] Started adding support for RoleNames --- .../DOtherSide/BaseQAbstractListModel.cpp | 7 +++++ .../DOtherSide/BaseQAbstractListModel.h | 3 ++ DOtherSide/DOtherSide/DOtherSide.cpp | 28 +++++++++++++++---- DOtherSide/DOtherSide/DOtherSide.h | 5 ++++ Nim/Examples/AbstractItemModel/main.nim | 2 +- Nim/NimQml/NimQml.nim | 21 ++++++++++++++ Nim/NimQml/NimQmlTypes.nim | 6 ++++ 7 files changed, 66 insertions(+), 6 deletions(-) diff --git a/DOtherSide/DOtherSide/BaseQAbstractListModel.cpp b/DOtherSide/DOtherSide/BaseQAbstractListModel.cpp index c461d9d..b86d01d 100644 --- a/DOtherSide/DOtherSide/BaseQAbstractListModel.cpp +++ b/DOtherSide/DOtherSide/BaseQAbstractListModel.cpp @@ -31,3 +31,10 @@ void* BaseQAbstractListModel::modelObject() { return m_modelObject; } + +QHash BaseQAbstractListModel::roleNames() const +{ + QHash result; + return result; +} + diff --git a/DOtherSide/DOtherSide/BaseQAbstractListModel.h b/DOtherSide/DOtherSide/BaseQAbstractListModel.h index 13a40b7..c14dfc3 100644 --- a/DOtherSide/DOtherSide/BaseQAbstractListModel.h +++ b/DOtherSide/DOtherSide/BaseQAbstractListModel.h @@ -21,6 +21,9 @@ class BaseQAbstractListModel : public QAbstractListModel /// Return the dModelPointer void* modelObject(); + /// Return the roleNames + virtual QHash roleNames() const override; + private: void* m_modelObject; RowCountCallback m_rowCountCallback; diff --git a/DOtherSide/DOtherSide/DOtherSide.cpp b/DOtherSide/DOtherSide/DOtherSide.cpp index 1ba3006..f5d49a8 100644 --- a/DOtherSide/DOtherSide/DOtherSide.cpp +++ b/DOtherSide/DOtherSide/DOtherSide.cpp @@ -1,13 +1,13 @@ #include "DOtherSide.h" -#include -#include -#include -#include #include #include -#include #include +#include +#include +#include +#include +#include #include "DynamicQObject.h" #include "BaseQAbstractListModel.h" @@ -446,3 +446,21 @@ void dos_qabstractlistmodel_delete(void* vptr) auto model = reinterpret_cast(vptr); delete model; } + +void dos_qhash_int_qbytearray_create(QHashIntQByteArrayVoidPtr* vptr) +{ + *vptr = new QHash(); +} + +void dos_qhash_int_qbytearray_delete(QHashIntQByteArrayVoidPtr vptr) +{ + auto qHash = reinterpret_cast*>(vptr); + delete qHash; +} + +void dos_qhash_int_qbytearray_insert(QHashIntQByteArrayVoidPtr vptr, int key, ConstCharPtr value) +{ + auto qHash = reinterpret_cast*>(vptr); + qHash->insert(key, QByteArray(value)); +} + diff --git a/DOtherSide/DOtherSide/DOtherSide.h b/DOtherSide/DOtherSide/DOtherSide.h index 158406c..83224ff 100644 --- a/DOtherSide/DOtherSide/DOtherSide.h +++ b/DOtherSide/DOtherSide/DOtherSide.h @@ -113,6 +113,11 @@ extern "C" void dos_qmodelindex_child(void* vptr, int row, int column, void* child); void dos_qmodelindex_sibling(void* vptr, int row, int column, void* sibling); + // QHash + 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 void dos_qabstractlistmodel_create(void** vptr, void* callbackObject, diff --git a/Nim/Examples/AbstractItemModel/main.nim b/Nim/Examples/AbstractItemModel/main.nim index a426a2a..b9279da 100644 --- a/Nim/Examples/AbstractItemModel/main.nim +++ b/Nim/Examples/AbstractItemModel/main.nim @@ -3,7 +3,6 @@ import macros import typeinfo type MyQAbstractListModel = ref object of QAbstractListModel - m_name: string proc create(self: MyQAbstractListModel) = var qAbstractListModel = self.QAbstractListModel @@ -22,6 +21,7 @@ method rowCount(self: MyQAbstractListModel, index: QModelIndex): cint = return 3 method data(self: MyQAbstractListModel, index: QModelIndex, role: cint): QVariant = + echo "index valid: " & $index.isValid & " row: " & $index.row & " column: " & $index.column return nil proc mainProc() = diff --git a/Nim/NimQml/NimQml.nim b/Nim/NimQml/NimQml.nim index 2444eee..50a3a1b 100644 --- a/Nim/NimQml/NimQml.nim +++ b/Nim/NimQml/NimQml.nim @@ -630,3 +630,24 @@ proc newQAbstractListModel*(): QAbstractListModel = ## Return a new QAbstractListModel newWithCondFinalizer(result, delete) 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() diff --git a/Nim/NimQml/NimQmlTypes.nim b/Nim/NimQml/NimQmlTypes.nim index 9b72844..231b0a3 100644 --- a/Nim/NimQml/NimQmlTypes.nim +++ b/Nim/NimQml/NimQmlTypes.nim @@ -43,3 +43,9 @@ type data: RawQAbstractListModel deleted: bool QAbstractListModel* = ref QAbstractListModelObj ## A QAbstractListModel + + RawQHashIntByteArray = distinct pointer + QHashIntByteArrayObj = object of RootObj + data: RawQHashIntByteArray + deleted: bool + QHashIntByteArray = ref QHashIntByteArrayObj ## A QHash