diff --git a/src/nimqml.nim b/src/nimqml.nim index 9631d2d..e034221 100644 --- a/src/nimqml.nim +++ b/src/nimqml.nim @@ -22,9 +22,7 @@ include private/qguiapplication.nim include private/qurl.nim include private/qquickview.nim include private/qhashintbytearray.nim -#include private.nimqmltypes +include private/qmodelindex.nim #var qobjectRegistry = initTable[ptr QObjectObj, bool]() -#include private/qguiapplication.nim -#include private/qmodelindex.nim #include private/qabstractlistmodel.nim #include private.nimqmlmacros diff --git a/src/private/dotherside.nim b/src/private/dotherside.nim index c7b0f34..94cc1e7 100644 --- a/src/private/dotherside.nim +++ b/src/private/dotherside.nim @@ -11,6 +11,7 @@ type DosQUrl* = distinct pointer DosQQuickView* = distinct pointer DosQHashIntByteArray* = distinct pointer + DosQModelIndex = distinct pointer DosSignalDefinition* = object name*: cstring @@ -135,3 +136,14 @@ proc dos_qhash_int_qbytearray_delete(qHash: DosQHashIntByteArray) {.cdecl, impor proc dos_qhash_int_qbytearray_insert(qHash: DosQHashIntByteArray, key: int, value: cstring) {.cdecl, importc.} proc dos_qhash_int_qbytearray_value(qHash: DosQHashIntByteArray, key: int, value: var cstring) {.cdecl, importc.} +# QModelIndex +proc dos_qmodelindex_create(modelIndex: var DosQModelIndex) {.cdecl, importc.} +proc dos_qmodelindex_delete(modelIndex: DosQModelIndex) {.cdecl, importc.} +proc dos_qmodelindex_row(modelIndex: DosQModelIndex, row: var cint) {.cdecl, importc.} +proc dos_qmodelindex_column(modelIndex: DosQModelIndex, column: var cint) {.cdecl, importc.} +proc dos_qmodelindex_isValid(modelIndex: DosQModelIndex, column: var bool) {.cdecl, importc.} +proc dos_qmodelindex_data(modelIndex: DosQModelIndex, role: cint, data: DosQVariant) {.cdecl, importc.} +proc dos_qmodelindex_parent(modelIndex: DosQModelIndex, parent: DosQModelIndex) {.cdecl, importc.} +proc dos_qmodelindex_child(modelIndex: DosQModelIndex, row: cint, column: cint, parent: DosQModelIndex) {.cdecl, importc.} +proc dos_qmodelindex_sibling(modelIndex: DosQModelIndex, row: cint, column: cint, sibling: DosQModelIndex) {.cdecl, importc.} + diff --git a/src/private/nimqmltypes.nim b/src/private/nimqmltypes.nim index dcd2669..20e5c2f 100644 --- a/src/private/nimqmltypes.nim +++ b/src/private/nimqmltypes.nim @@ -27,6 +27,10 @@ type # A QHash vptr: DosQHashIntByteArray + QModelIndex* = ref object of RootObj ## \ + # A QModelIndex + vptr: DosQModelIndex + QtItemFlag* {.pure.} = enum ## \ ## Item flags ## diff --git a/src/private/qmodelindex.nim b/src/private/qmodelindex.nim index 8a0b7d4..b2fd003 100644 --- a/src/private/qmodelindex.nim +++ b/src/private/qmodelindex.nim @@ -1,70 +1,57 @@ -# QModelIndex -proc dos_qmodelindex_create(modelIndex: var RawQModelIndex) {.cdecl, importc.} -proc dos_qmodelindex_delete(modelIndex: RawQModelIndex) {.cdecl, importc.} -proc dos_qmodelindex_row(modelIndex: RawQModelIndex, row: var cint) {.cdecl, importc.} -proc dos_qmodelindex_column(modelIndex: RawQModelIndex, column: var cint) {.cdecl, importc.} -proc dos_qmodelindex_isValid(modelIndex: RawQModelIndex, column: var bool) {.cdecl, importc.} -proc dos_qmodelindex_data(modelIndex: RawQModelIndex, role: cint, data: RawQVariant) {.cdecl, importc.} -proc dos_qmodelindex_parent(modelIndex: RawQModelIndex, parent: RawQModelIndex) {.cdecl, importc.} -proc dos_qmodelindex_child(modelIndex: RawQModelIndex, row: cint, column: cint, parent: RawQModelIndex) {.cdecl, importc.} -proc dos_qmodelindex_sibling(modelIndex: RawQModelIndex, row: cint, column: cint, sibling: RawQModelIndex) {.cdecl, importc.} +proc setup*(self: var QModelIndex) = + ## Setup a new QModelIndex + dos_qmodelindex_create(self.vptr) -proc create*(modelIndex: var QModelIndex) = - ## Create a new QModelIndex - dos_qmodelindex_create(modelIndex.data) - modelIndex.deleted = false +proc setup*(self: var QModelIndex, vptr: DosQModelIndex) = + ## Setup a new QModelIndex + self.vptr = vptr -proc create*(modelIndex: var QModelIndex, rawQModelIndex: RawQModelIndex) = - ## Create a new QModelIndex - modelIndex.data = rawQModelIndex - modelIndex.deleted = false - -proc delete*(modelIndex: QModelIndex) = +proc delete*(self: QModelIndex) = ## Delete the given QModelIndex - if not modelIndex.deleted: - debugMsg("QModelIndex", "delete") - dos_qmodelindex_delete(modelIndex.data) - modelIndex.data = nil.RawQModelIndex - modelIndex.deleted = true + if not self.vptr.isNil: + return + debugMsg("QModelIndex", "delete") + dos_qmodelindex_delete(self.vptr) + self.vptr.resetToNil proc newQModelIndex*(): QModelIndex = ## Return a new QModelIndex new(result, delete) - result.create() + result.setup() -proc newQModelIndex*(rawQModelIndex: RawQModelIndex): QModelIndex = +proc newQModelIndex*(vptr: DosQModelIndex): QModelIndex = ## Return a new QModelIndex given a raw index new(result, delete) - result.create(rawQModelIndex) + result.setup(vptr) -proc row*(modelIndex: QModelIndex): cint = +proc row*(self: QModelIndex): cint = ## Return the index row - dos_qmodelindex_row(modelIndex.data, result) + dos_qmodelindex_row(self.vptr, result) -proc column*(modelIndex: QModelIndex): cint = +proc column*(self: QModelIndex): cint = ## Return the index column - dos_qmodelindex_column(modelIndex.data, result) + dos_qmodelindex_column(self.vptr, result) -proc isValid*(modelIndex: QModelIndex): bool = +proc isValid*(self: QModelIndex): bool = ## Return true if the index is valid, false otherwise - dos_qmodelindex_isValid(modelIndex.data, result) + dos_qmodelindex_isValid(self.vptr, result) -proc data*(modelIndex: QModelIndex, role: cint): QVariant = +proc data*(self: QModelIndex, role: cint): QVariant = ## Return the model data associated to the given role result = newQVariant() - dos_qmodelindex_data(modelIndex.data, role, result.data) + dos_qmodelindex_data(self.vptr, role, result.vptr) -proc parent*(modelIndex: QModelIndex): QModelIndex = +proc parent*(self: QModelIndex): QModelIndex = ## Return the parent index result = newQModelIndex() - dos_qmodelindex_parent(modelIndex.data, result.data) + dos_qmodelindex_parent(self.vptr, result.vptr) -proc child*(modelIndex: QModelIndex, row: cint, column: cint): QModelIndex = +proc child*(self: 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) + dos_qmodelindex_child(self.vptr, row, column, result.vptr) -proc sibling*(modelIndex: QModelIndex, row: cint, column: cint): QModelIndex = +proc sibling*(self: 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) + dos_qmodelindex_sibling(self.vptr, row, column, result.vptr)