mirror of https://github.com/status-im/nimqml.git
Aligned implementation with DOtherSide qaim branch
This commit is contained in:
parent
f022545f03
commit
a2e56c07cc
|
@ -6,20 +6,23 @@ type
|
|||
|
||||
QtObject:
|
||||
type
|
||||
MyListModel* = ref object of QAbstractListModel
|
||||
MyListModel* = ref object of QAbstractItemModel
|
||||
names*: seq[string]
|
||||
|
||||
proc delete(self: MyListModel) =
|
||||
self.QAbstractListModel.delete
|
||||
self.QAbstractItemModel.delete
|
||||
|
||||
proc setup(self: MyListModel) =
|
||||
self.QAbstractListModel.setup
|
||||
self.QAbstractItemModel.setup
|
||||
|
||||
proc newMyListModel*(): MyListModel =
|
||||
new(result, delete)
|
||||
result.names = @["John", "Max", "Paul", "Anna"]
|
||||
result.setup
|
||||
|
||||
method columnCount(self: MyListModel, index: QModelIndex = nil): int =
|
||||
return 1
|
||||
|
||||
method rowCount(self: MyListModel, index: QModelIndex = nil): int =
|
||||
return self.names.len
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
## NimQml aims to provide binding to the QML for the Nim programming language
|
||||
|
||||
template debugMsg(message: string) =
|
||||
when defined(debug):
|
||||
echo "NimQml: ", message
|
||||
echo "NimQml: ", message
|
||||
|
||||
template debugMsg(typeName: string, procName: string) =
|
||||
when defined(debug):
|
||||
|
@ -24,7 +23,7 @@ include private/qurl.nim
|
|||
include private/qquickview.nim
|
||||
include private/qhashintbytearray.nim
|
||||
include private/qmodelindex.nim
|
||||
include private/qabstractlistmodel.nim
|
||||
include private/qabstractitemmodel.nim
|
||||
include private/qresource.nim
|
||||
include private/qdeclarative.nim
|
||||
include private/nimqmlmacros.nim
|
||||
|
|
|
@ -11,7 +11,7 @@ proc getDllName: string =
|
|||
|
||||
type
|
||||
NimQObject = pointer
|
||||
NimQAbstractListModel = pointer
|
||||
NimQAbstractItemModel = pointer
|
||||
DosQMetaObject = distinct pointer
|
||||
DosQObject = distinct pointer
|
||||
DosQObjectWrapper = distinct pointer
|
||||
|
@ -25,12 +25,16 @@ type
|
|||
DosQQuickView = distinct pointer
|
||||
DosQHashIntByteArray = distinct pointer
|
||||
DosQModelIndex = distinct pointer
|
||||
DosQAbstractListModel = distinct pointer
|
||||
DosQAbstractItemModel = distinct pointer
|
||||
|
||||
DosParameterDefinition = object
|
||||
name: cstring
|
||||
metaType: cint
|
||||
|
||||
DosSignalDefinition = object
|
||||
name: cstring
|
||||
parametersCount: cint
|
||||
parametersMetaTypes: pointer
|
||||
parameters: pointer
|
||||
|
||||
DosSignalDefinitions = object
|
||||
count: cint
|
||||
|
@ -40,7 +44,7 @@ type
|
|||
name: cstring
|
||||
returnMetaType: cint
|
||||
parametersCount: cint
|
||||
parametersMetaTypes: pointer
|
||||
parameters: pointer
|
||||
|
||||
DosSlotDefinitions = object
|
||||
count: cint
|
||||
|
@ -71,13 +75,15 @@ type
|
|||
|
||||
DosQObjectCallBack = proc(nimobject: NimQObject, slotName: DosQVariant, numArguments: cint, arguments: ptr DosQVariantArray) {.cdecl.}
|
||||
|
||||
DosRowCountCallback = proc(nimmodel: NimQAbstractListModel, rawIndex: DosQModelIndex, result: var cint) {.cdecl.}
|
||||
DosColumnCountCallback = proc(nimmodel: NimQAbstractListModel, rawIndex: DosQModelIndex, result: var cint) {.cdecl.}
|
||||
DosDataCallback = proc(nimmodel: NimQAbstractListModel, rawIndex: DosQModelIndex, role: cint, result: DosQVariant) {.cdecl.}
|
||||
DosSetDataCallback = proc(nimmodel: NimQAbstractListModel, rawIndex: DosQModelIndex, value: DosQVariant, role: cint, result: var bool) {.cdecl.}
|
||||
DosRoleNamesCallback = proc(nimmodel: NimQAbstractListModel, result: DosQHashIntByteArray) {.cdecl.}
|
||||
DosFlagsCallback = proc(nimmodel: NimQAbstractListModel, index: DosQModelIndex, result: var cint) {.cdecl.}
|
||||
DosHeaderDataCallback = proc(nimmodel: NimQAbstractListModel, section: cint, orientation: cint, role: cint, result: DosQVariant) {.cdecl.}
|
||||
DosRowCountCallback = proc(nimmodel: NimQAbstractItemModel, rawIndex: DosQModelIndex, result: var cint) {.cdecl.}
|
||||
DosColumnCountCallback = proc(nimmodel: NimQAbstractItemModel, rawIndex: DosQModelIndex, result: var cint) {.cdecl.}
|
||||
DosDataCallback = proc(nimmodel: NimQAbstractItemModel, rawIndex: DosQModelIndex, role: cint, result: DosQVariant) {.cdecl.}
|
||||
DosSetDataCallback = proc(nimmodel: NimQAbstractItemModel, rawIndex: DosQModelIndex, value: DosQVariant, role: cint, result: var bool) {.cdecl.}
|
||||
DosRoleNamesCallback = proc(nimmodel: NimQAbstractItemModel, result: DosQHashIntByteArray) {.cdecl.}
|
||||
DosFlagsCallback = proc(nimmodel: NimQAbstractItemModel, index: DosQModelIndex, result: var cint) {.cdecl.}
|
||||
DosHeaderDataCallback = proc(nimmodel: NimQAbstractItemModel, section: cint, orientation: cint, role: cint, result: DosQVariant) {.cdecl.}
|
||||
DosIndexCallback = proc(nimmodel: NimQAbstractItemModel, row: cint, column: cint, parent: DosQModelIndex, result: DosQModelIndex) {.cdecl.}
|
||||
DosParentCallback = proc(nimmodel: NimQAbstractItemModel, child: DosQModelIndex, result: DosQModelIndex) {.cdecl.}
|
||||
|
||||
# Conversion
|
||||
proc resetToNil[T](x: var T) = x = nil.pointer.T
|
||||
|
@ -152,8 +158,8 @@ proc dos_qobject_setObjectName(qobject: DosQObject, name: cstring) {.cdecl, dynl
|
|||
proc dos_qobject_signal_emit(qobject: DosQObject, signalName: cstring, argumentsCount: cint, arguments: ptr DosQVariantArray) {.cdecl, dynlib: getDllName(), importc.}
|
||||
proc dos_qobject_delete(qobject: DosQObject) {.cdecl, dynlib: getDllName(), importc.}
|
||||
|
||||
# QAbstractListModel
|
||||
proc dos_qabstractlistmodel_qmetaobject(): DosQMetaObject {.cdecl dynlib: getDllName(), importc.}
|
||||
# QAbstractItemModel
|
||||
proc dos_qabstractitemmodel_qmetaobject(): DosQMetaObject {.cdecl dynlib: getDllName(), importc.}
|
||||
|
||||
# QMetaObject
|
||||
proc dos_qmetaobject_create(superclassMetaObject: DosQMetaObject,
|
||||
|
@ -194,8 +200,8 @@ proc dos_qmodelindex_child(modelIndex: DosQModelIndex, row: cint, column: cint):
|
|||
proc dos_qmodelindex_sibling(modelIndex: DosQModelIndex, row: cint, column: cint): DosQModelIndex {.cdecl, dynlib: getDllName(), importc.}
|
||||
proc dos_qmodelindex_assign(leftSide: DosQModelIndex, rightSide: DosQModelIndex) {.cdecl, dynlib: getDllName(), importc.}
|
||||
|
||||
# QAbstractListModel
|
||||
proc dos_qabstractlistmodel_create(modelPtr: NimQAbstractListModel,
|
||||
# QAbstractItemModel
|
||||
proc dos_qabstractitemmodel_create(modelPtr: NimQAbstractItemModel,
|
||||
metaObject: DosQMetaObject,
|
||||
qobjectCallback: DosQObjectCallBack,
|
||||
rowCountCallback: DosRowCountCallback,
|
||||
|
@ -204,25 +210,38 @@ proc dos_qabstractlistmodel_create(modelPtr: NimQAbstractListModel,
|
|||
setDataCallback: DosSetDataCallBack,
|
||||
roleNamesCallback: DosRoleNamesCallback,
|
||||
flagsCallback: DosFlagsCallback,
|
||||
headerDataCallback: DosHeaderDataCallback): DosQAbstractListModel {.cdecl, dynlib: getDllName(), importc.}
|
||||
headerDataCallback: DosHeaderDataCallback,
|
||||
indexCallback: DosIndexCallback,
|
||||
parentCallback: DosParentCallback): DosQAbstractItemModel {.cdecl, dynlib: getDllName(), importc.}
|
||||
|
||||
proc dos_qabstractlistmodel_beginInsertRows(model: DosQAbstractListModel,
|
||||
proc dos_qabstractitemmodel_beginInsertRows(model: DosQAbstractItemModel,
|
||||
parentIndex: DosQModelIndex,
|
||||
first: cint,
|
||||
last: cint) {.cdecl, dynlib: getDllName(), importc.}
|
||||
proc dos_qabstractlistmodel_endInsertRows(model: DosQAbstractListModel) {.cdecl, dynlib: getDllName(), importc.}
|
||||
proc dos_qabstractlistmodel_beginRemoveRows(model: DosQAbstractListModel,
|
||||
proc dos_qabstractitemmodel_endInsertRows(model: DosQAbstractItemModel) {.cdecl, dynlib: getDllName(), importc.}
|
||||
proc dos_qabstractitemmodel_beginRemoveRows(model: DosQAbstractItemModel,
|
||||
parentIndex: DosQModelIndex,
|
||||
first: cint,
|
||||
last: cint) {.cdecl, dynlib: getDllName(), importc.}
|
||||
proc dos_qabstractlistmodel_endRemoveRows(model: DosQAbstractListModel) {.cdecl, dynlib: getDllName(), importc.}
|
||||
proc dos_qabstractlistmodel_beginResetModel(model: DosQAbstractListModel) {.cdecl, dynlib: getDllName(), importc.}
|
||||
proc dos_qabstractlistmodel_endResetModel(model: DosQAbstractListModel) {.cdecl, dynlib: getDllName(), importc.}
|
||||
proc dos_qabstractlistmodel_dataChanged(model: DosQAbstractListModel,
|
||||
proc dos_qabstractitemmodel_endRemoveRows(model: DosQAbstractItemModel) {.cdecl, dynlib: getDllName(), importc.}
|
||||
proc dos_qabstractitemmodel_beginInsertColumns(model: DosQAbstractItemModel,
|
||||
parentIndex: DosQModelIndex,
|
||||
first: cint,
|
||||
last: cint) {.cdecl, dynlib: getDllName(), importc.}
|
||||
proc dos_qabstractitemmodel_endInsertColumns(model: DosQAbstractItemModel) {.cdecl, dynlib: getDllName(), importc.}
|
||||
proc dos_qabstractitemmodel_beginRemoveColumns(model: DosQAbstractItemModel,
|
||||
parentIndex: DosQModelIndex,
|
||||
first: cint,
|
||||
last: cint) {.cdecl, dynlib: getDllName(), importc.}
|
||||
proc dos_qabstractitemmodel_endRemoveColumns(model: DosQAbstractItemModel) {.cdecl, dynlib: getDllName(), importc.}
|
||||
proc dos_qabstractitemmodel_beginResetModel(model: DosQAbstractItemModel) {.cdecl, dynlib: getDllName(), importc.}
|
||||
proc dos_qabstractitemmodel_endResetModel(model: DosQAbstractItemModel) {.cdecl, dynlib: getDllName(), importc.}
|
||||
proc dos_qabstractitemmodel_dataChanged(model: DosQAbstractItemModel,
|
||||
parentLeft: DosQModelIndex,
|
||||
bottomRight: DosQModelIndex,
|
||||
rolesArrayPtr: ptr cint,
|
||||
rolesArrayLength: cint) {.cdecl, dynlib: getDllName(), importc.}
|
||||
proc dos_qabstractitemmodel_createIndex(model: DosQAbstractItemModel, row: cint, column: cint, data: pointer): DosQModelIndex {.cdecl, dynlib: getDllName(), importc.}
|
||||
|
||||
# QResource
|
||||
proc dos_qresource_register(filename: cstring) {.cdecl, dynlib: getDllName(), importc.}
|
||||
|
|
|
@ -4,8 +4,8 @@ type
|
|||
vptr: DosQObject
|
||||
owner: bool
|
||||
|
||||
QAbstractListModel* = ref object of QObject ## \
|
||||
## A QAbstractListModel
|
||||
QAbstractItemModel* = ref object of QObject ## \
|
||||
## A QAbstractItemModel
|
||||
|
||||
QVariant* = ref object of RootObj ## \
|
||||
## A QVariant
|
||||
|
@ -74,14 +74,18 @@ type
|
|||
QVariant = 41.cint,
|
||||
Void = 43.cint,
|
||||
|
||||
ParameterDefinition* = object
|
||||
name*: string
|
||||
metaType*: QMetaType
|
||||
|
||||
SignalDefinition* = object
|
||||
name*: string
|
||||
parametersTypes*: seq[QMetaType]
|
||||
parameters*: seq[ParameterDefinition]
|
||||
|
||||
SlotDefinition* = object
|
||||
name*: string
|
||||
returnMetaType*: QMetaType
|
||||
parametersTypes*: seq[QMetaType]
|
||||
parameters*: seq[ParameterDefinition]
|
||||
|
||||
PropertyDefinition* = object
|
||||
name*: string
|
||||
|
|
|
@ -0,0 +1,200 @@
|
|||
import tables
|
||||
|
||||
let qAbstractItemModelStaticMetaObjectInstance = newQAbstractItemModelMetaObject()
|
||||
|
||||
proc staticMetaObject*(c: type QAbstractItemModel): QMetaObject =
|
||||
## Return the metaObject of QAbstractItemModel
|
||||
qAbstractItemModelStaticMetaObjectInstance
|
||||
|
||||
proc staticMetaObject*(self: QAbstractItemModel): QMetaObject =
|
||||
## Return the metaObject of QAbstractItemModel
|
||||
qAbstractItemModelStaticMetaObjectInstance
|
||||
|
||||
method metaObject*(self: QAbstractItemModel): QMetaObject =
|
||||
# Return the metaObject
|
||||
QAbstractItemModel.staticMetaObject
|
||||
|
||||
method rowCount*(self: QAbstractItemModel, index: QModelIndex): int {.base.} =
|
||||
## Return the model's row count
|
||||
0
|
||||
|
||||
proc rowCountCallback(modelPtr: pointer, rawIndex: DosQModelIndex, result: var cint) {.cdecl, exportc.} =
|
||||
debugMsg("QAbstractItemModel", "rowCountCallback")
|
||||
let model = cast[QAbstractItemModel](modelPtr)
|
||||
let index = newQModelIndex(rawIndex, Ownership.Clone)
|
||||
result = model.rowCount(index).cint
|
||||
|
||||
method columnCount*(self: QAbstractItemModel, index: QModelIndex): int {.base.} =
|
||||
## Return the model's column count
|
||||
1
|
||||
|
||||
proc columnCountCallback(modelPtr: pointer, rawIndex: DosQModelIndex, result: var cint) {.cdecl, exportc.} =
|
||||
debugMsg("QAbstractItemModel", "columnCountCallback")
|
||||
let model = cast[QAbstractItemModel](modelPtr)
|
||||
let index = newQModelIndex(rawIndex, Ownership.Clone)
|
||||
result = model.columnCount(index).cint
|
||||
|
||||
method data*(self: QAbstractItemModel, index: QModelIndex, role: int): QVariant {.base.} =
|
||||
## Return the data at the given model index and role
|
||||
nil
|
||||
|
||||
proc dataCallback(modelPtr: pointer, rawIndex: DosQModelIndex, role: cint, result: DosQVariant) {.cdecl, exportc.} =
|
||||
debugMsg("QAbstractItemModel", "dataCallback")
|
||||
let model = cast[QAbstractItemModel](modelPtr)
|
||||
let index = newQModelIndex(rawIndex, Ownership.Clone)
|
||||
let variant = data(model, index, role.int)
|
||||
if variant != nil:
|
||||
dos_qvariant_assign(result, variant.vptr)
|
||||
variant.delete
|
||||
|
||||
method setData*(self: QAbstractItemModel, index: QModelIndex, value: QVariant, role: int): bool {.base.} =
|
||||
## Sets the data at the given index and role. Return true on success, false otherwise
|
||||
false
|
||||
|
||||
proc setDataCallback(modelPtr: pointer, rawIndex: DosQModelIndex, rawQVariant: DosQVariant, role: cint, result: var bool) {.cdecl, exportc.} =
|
||||
debugMsg("QAbstractItemModel", "setDataCallback")
|
||||
let model = cast[QAbstractItemModel](modelPtr)
|
||||
let index = newQModelIndex(rawIndex, Ownership.Clone)
|
||||
let variant = newQVariant(rawQVariant, Ownership.Clone)
|
||||
result = model.setData(index, variant, role.int)
|
||||
|
||||
method roleNames*(self: QAbstractItemModel): Table[int,string] {.base.} =
|
||||
## Return the model role names
|
||||
nil
|
||||
|
||||
proc roleNamesCallback(modelPtr: pointer, hash: DosQHashIntByteArray) {.cdecl, exportc.} =
|
||||
debugMsg("QAbstractItemModel", "roleNamesCallback")
|
||||
let model = cast[QAbstractItemModel](modelPtr)
|
||||
let table = model.roleNames()
|
||||
for key, val in table.pairs:
|
||||
dos_qhash_int_qbytearray_insert(hash, key.cint, val.cstring)
|
||||
|
||||
method flags*(self: QAbstractItemModel, index: QModelIndex): QtItemFlag {.base.} =
|
||||
## Return the item flags and the given index
|
||||
return QtItemFlag.None
|
||||
|
||||
proc flagsCallback(modelPtr: pointer, rawIndex: DosQModelIndex, result: var cint) {.cdecl, exportc.} =
|
||||
debugMsg("QAbstractItemModel", "flagsCallback")
|
||||
let model = cast[QAbstractItemModel](modelPtr)
|
||||
let index = newQModelIndex(rawIndex, Ownership.Clone)
|
||||
result = model.flags(index).cint
|
||||
|
||||
method headerData*(self: QAbstractItemModel, section: int, orientation: QtOrientation, role: int): QVariant {.base.} =
|
||||
## Returns the data for the given role and section in the header with the specified orientation
|
||||
nil
|
||||
|
||||
proc headerDataCallback(modelPtr: pointer, section: cint, orientation: cint, role: cint, result: DosQVariant) {.cdecl, exportc.} =
|
||||
debugMsg("QAbstractItemModel", "headerDataCallback")
|
||||
let model = cast[QAbstractItemModel](modelPtr)
|
||||
let variant = model.headerData(section.int, orientation.QtOrientation, role.int)
|
||||
if variant != nil:
|
||||
dos_qvariant_assign(result, variant.vptr)
|
||||
variant.delete
|
||||
|
||||
proc createIndex*(self: QAbstractItemModel, row: int, column: int, data: pointer): QModelIndex =
|
||||
## Create a new QModelIndex
|
||||
debugMsg("QAbstractItemModel", "createIndex")
|
||||
let result = dos_qabstractitemmodel_createIndex(self.vptr.DosQAbstractItemModel, row.cint, column.cint, data)
|
||||
return newQModelIndex(result, Ownership.Take)
|
||||
|
||||
method index*(self: QAbstractItemModel, row: int, column: int, parent: QModelIndex): QModelIndex {.base.} =
|
||||
return self.createIndex(row, column, nil)
|
||||
|
||||
proc indexCallback(modelPtr: pointer, row: cint, column: cint, parent: DosQModelIndex, result: DosQModelIndex) {.cdecl, exportc.} =
|
||||
debugMsg("QAbstractItemModel", "indexCallback")
|
||||
let model = cast[QAbstractItemModel](modelPtr)
|
||||
let index = model.index(row.int, column.int, newQModelIndex(parent, Ownership.Clone))
|
||||
dos_qmodelindex_assign(result, index.vptr)
|
||||
|
||||
method parent(self: QAbstractItemModel, child: QModelIndex): QModelIndex {.base.} =
|
||||
return newQModelIndex()
|
||||
|
||||
proc parentCallback(modelPtr: pointer, child: DosQModelIndex, result: DosQModelIndex) {.cdecl, exportc.} =
|
||||
debugMsg("QAbstractItemModel", "parentCallback")
|
||||
let model = cast[QAbstractItemModel](modelPtr)
|
||||
let index = model.parent(newQModelIndex(child, Ownership.Clone))
|
||||
dos_qmodelindex_assign(result, index.vptr)
|
||||
|
||||
method onSlotCalled*(self: QAbstractItemModel, slotName: string, arguments: openarray[QVariant]) =
|
||||
## Called from the dotherside library when a slot is called from Qml.
|
||||
|
||||
proc setup*(self: QAbstractItemModel) =
|
||||
## Setup a new QAbstractItemModel
|
||||
debugMsg("QAbstractItemModel", "setup")
|
||||
self.vptr = dos_qabstractitemmodel_create(addr(self[]), self.metaObject.vptr,
|
||||
qobjectCallback, rowCountCallback, columnCountCallback,
|
||||
dataCallback, setDataCallback, roleNamesCallback,
|
||||
flagsCallback, headerDataCallback, indexCallback, parentCallback).DosQObject
|
||||
|
||||
proc delete*(self: QAbstractItemModel) =
|
||||
## Delete the given QAbstractItemModel
|
||||
debugMsg("QAbstractItemModel", "delete")
|
||||
self.QObject.delete()
|
||||
|
||||
proc newQAbstractItemModel*(): QAbstractItemModel =
|
||||
## Return a new QAbstractItemModel
|
||||
debugMsg("QAbstractItemModel", "new")
|
||||
new(result, delete)
|
||||
result.setup()
|
||||
|
||||
proc beginInsertRows*(self: QAbstractItemModel, parentIndex: QModelIndex, first: int, last: int) =
|
||||
## Notify the view that the model is about to inserting the given number of rows
|
||||
debugMsg("QAbstractItemModel", "beginInsertRows")
|
||||
dos_qabstractitemmodel_beginInsertRows(self.vptr.DosQAbstractItemModel, parentIndex.vptr, first.cint, last.cint)
|
||||
|
||||
proc endInsertRows*(self: QAbstractItemModel) =
|
||||
## Notify the view that the rows have been inserted
|
||||
debugMsg("QAbstractItemModel", "endInsertRows")
|
||||
dos_qabstractitemmodel_endInsertRows(self.vptr.DosQAbstractItemModel)
|
||||
|
||||
proc beginRemoveRows*(self: QAbstractItemModel, parentIndex: QModelIndex, first: int, last: int) =
|
||||
## Notify the view that the model is about to remove the given number of rows
|
||||
debugMsg("QAbstractItemModel", "beginRemoveRows")
|
||||
dos_qabstractitemmodel_beginRemoveRows(self.vptr.DosQAbstractItemModel, parentIndex.vptr, first.cint, last.cint)
|
||||
|
||||
proc endRemoveRows*(self: QAbstractItemModel) =
|
||||
## Notify the view that the rows have been removed
|
||||
debugMsg("QAbstractItemModel", "endRemoveRows")
|
||||
dos_qabstractitemmodel_endRemoveRows(self.vptr.DosQAbstractItemModel)
|
||||
|
||||
proc beginInsertColumns*(self: QAbstractItemModel, parentIndex: QModelIndex, first: int, last: int) =
|
||||
## Notify the view that the model is about to inserting the given number of columns
|
||||
debugMsg("QAbstractItemModel", "beginInsertColumns")
|
||||
dos_qabstractitemmodel_beginInsertColumns(self.vptr.DosQAbstractItemModel, parentIndex.vptr, first.cint, last.cint)
|
||||
|
||||
proc endInsertColumns*(self: QAbstractItemModel) =
|
||||
## Notify the view that the rows have been inserted
|
||||
debugMsg("QAbstractItemModel", "endInsertColumns")
|
||||
dos_qabstractitemmodel_endInsertColumns(self.vptr.DosQAbstractItemModel)
|
||||
|
||||
proc beginRemoveColumns*(self: QAbstractItemModel, parentIndex: QModelIndex, first: int, last: int) =
|
||||
## Notify the view that the model is about to remove the given number of columns
|
||||
debugMsg("QAbstractItemModel", "beginRemoveColumns")
|
||||
dos_qabstractitemmodel_beginRemoveColumns(self.vptr.DosQAbstractItemModel, parentIndex.vptr, first.cint, last.cint)
|
||||
|
||||
proc endRemoveColumns*(self: QAbstractItemModel) =
|
||||
## Notify the view that the columns have been removed
|
||||
debugMsg("QAbstractItemModel", "endRemoveColumns")
|
||||
dos_qabstractitemmodel_endRemoveColumns(self.vptr.DosQAbstractItemModel)
|
||||
|
||||
proc beginResetModel*(self: QAbstractItemModel) =
|
||||
## Notify the view that the model is about to resetting
|
||||
debugMsg("QAbstractItemModel", "beginResetModel")
|
||||
dos_qabstractitemmodel_beginResetModel(self.vptr.DosQAbstractItemModel)
|
||||
|
||||
proc endResetModel*(self: QAbstractItemModel) =
|
||||
## Notify the view that model has finished resetting
|
||||
debugMsg("QAbstractItemModel", "endResetModel")
|
||||
dos_qabstractitemmodel_endResetModel(self.vptr.DosQAbstractItemModel)
|
||||
|
||||
proc dataChanged*(self: QAbstractItemModel,
|
||||
topLeft: QModelIndex,
|
||||
bottomRight: QModelIndex,
|
||||
roles: openArray[int]) =
|
||||
## Notify the view that the model data changed
|
||||
debugMsg("QAbstractItemModel", "dataChanged")
|
||||
var copy: seq[cint]
|
||||
for i in roles:
|
||||
copy.add(i.cint)
|
||||
dos_qabstractitemmodel_dataChanged(self.vptr.DosQAbstractItemModel, topLeft.vptr,
|
||||
bottomRight.vptr, copy[0].addr, copy.len.cint)
|
|
@ -1,156 +0,0 @@
|
|||
import tables
|
||||
|
||||
let qAbstractListModelStaticMetaObjectInstance = newQAbstractListModelMetaObject()
|
||||
|
||||
proc staticMetaObject*(c: type QAbstractListModel): QMetaObject =
|
||||
## Return the metaObject of QAbstractListModel
|
||||
qAbstractListModelStaticMetaObjectInstance
|
||||
|
||||
proc staticMetaObject*(self: QAbstractListModel): QMetaObject =
|
||||
## Return the metaObject of QAbstractListModel
|
||||
qAbstractListModelStaticMetaObjectInstance
|
||||
|
||||
method metaObject*(self: QAbstractListModel): QMetaObject =
|
||||
# Return the metaObject
|
||||
QAbstractListModel.staticMetaObject
|
||||
|
||||
method rowCount*(self: QAbstractListModel, index: QModelIndex): int {.base.} =
|
||||
## Return the model's row count
|
||||
0
|
||||
|
||||
proc rowCountCallback(modelPtr: pointer, rawIndex: DosQModelIndex, result: var cint) {.cdecl, exportc.} =
|
||||
debugMsg("QAbstractListModel", "rowCountCallback")
|
||||
let model = cast[QAbstractListModel](modelPtr)
|
||||
let index = newQModelIndex(rawIndex, Ownership.Clone)
|
||||
result = model.rowCount(index).cint
|
||||
|
||||
method columnCount*(self: QAbstractListModel, index: QModelIndex): int {.base.} =
|
||||
## Return the model's column count
|
||||
1
|
||||
|
||||
proc columnCountCallback(modelPtr: pointer, rawIndex: DosQModelIndex, result: var cint) {.cdecl, exportc.} =
|
||||
debugMsg("QAbstractListModel", "columnCountCallback")
|
||||
let model = cast[QAbstractListModel](modelPtr)
|
||||
let index = newQModelIndex(rawIndex, Ownership.Clone)
|
||||
result = model.columnCount(index).cint
|
||||
|
||||
method data*(self: QAbstractListModel, index: QModelIndex, role: int): QVariant {.base.} =
|
||||
## Return the data at the given model index and role
|
||||
nil
|
||||
|
||||
proc dataCallback(modelPtr: pointer, rawIndex: DosQModelIndex, role: cint, result: DosQVariant) {.cdecl, exportc.} =
|
||||
debugMsg("QAbstractListModel", "dataCallback")
|
||||
let model = cast[QAbstractListModel](modelPtr)
|
||||
let index = newQModelIndex(rawIndex, Ownership.Clone)
|
||||
let variant = data(model, index, role.int)
|
||||
if variant != nil:
|
||||
dos_qvariant_assign(result, variant.vptr)
|
||||
variant.delete
|
||||
|
||||
method setData*(self: QAbstractListModel, index: QModelIndex, value: QVariant, role: int): bool {.base.} =
|
||||
## Sets the data at the given index and role. Return true on success, false otherwise
|
||||
false
|
||||
|
||||
proc setDataCallback(modelPtr: pointer, rawIndex: DosQModelIndex, rawQVariant: DosQVariant, role: cint, result: var bool) {.cdecl, exportc.} =
|
||||
debugMsg("QAbstractListModel", "setDataCallback")
|
||||
let model = cast[QAbstractListModel](modelPtr)
|
||||
let index = newQModelIndex(rawIndex, Ownership.Clone)
|
||||
let variant = newQVariant(rawQVariant, Ownership.Clone)
|
||||
result = model.setData(index, variant, role.int)
|
||||
|
||||
method roleNames*(self: QAbstractListModel): Table[int,string] {.base.} =
|
||||
## Return the model role names
|
||||
nil
|
||||
|
||||
proc roleNamesCallback(modelPtr: pointer, hash: DosQHashIntByteArray) {.cdecl, exportc.} =
|
||||
debugMsg("QAbstractListModel", "roleNamesCallback")
|
||||
let model = cast[QAbstractListModel](modelPtr)
|
||||
let table = model.roleNames()
|
||||
for key, val in table.pairs:
|
||||
dos_qhash_int_qbytearray_insert(hash, key.cint, val.cstring)
|
||||
|
||||
method flags*(self: QAbstractListModel, index: QModelIndex): QtItemFlag {.base.} =
|
||||
## Return the item flags and the given index
|
||||
return QtItemFlag.None
|
||||
|
||||
proc flagsCallback(modelPtr: pointer, rawIndex: DosQModelIndex, result: var cint) {.cdecl, exportc.} =
|
||||
debugMsg("QAbstractListModel", "flagsCallback")
|
||||
let model = cast[QAbstractListModel](modelPtr)
|
||||
let index = newQModelIndex(rawIndex, Ownership.Clone)
|
||||
result = model.flags(index).cint
|
||||
|
||||
method headerData*(self: QAbstractListModel, section: int, orientation: QtOrientation, role: int): QVariant {.base.} =
|
||||
## Returns the data for the given role and section in the header with the specified orientation
|
||||
nil
|
||||
|
||||
proc headerDataCallback(modelPtr: pointer, section: cint, orientation: cint, role: cint, result: DosQVariant) {.cdecl, exportc.} =
|
||||
debugMsg("QAbstractListModel", "headerDataCallback")
|
||||
let model = cast[QAbstractListModel](modelPtr)
|
||||
let variant = model.headerData(section.int, orientation.QtOrientation, role.int)
|
||||
if variant != nil:
|
||||
dos_qvariant_assign(result, variant.vptr)
|
||||
variant.delete
|
||||
|
||||
method onSlotCalled*(self: QAbstractListModel, slotName: string, arguments: openarray[QVariant]) =
|
||||
## Called from the dotherside library when a slot is called from Qml.
|
||||
|
||||
proc setup*(self: QAbstractListModel) =
|
||||
## Setup a new QAbstractListModel
|
||||
debugMsg("QAbstractListModel", "setup")
|
||||
self.vptr = dos_qabstractlistmodel_create(addr(self[]), self.metaObject.vptr,
|
||||
qobjectCallback, rowCountCallback, columnCountCallback,
|
||||
dataCallback, setDataCallback, roleNamesCallback,
|
||||
flagsCallback, headerDataCallback).DosQObject
|
||||
|
||||
proc delete*(self: QAbstractListModel) =
|
||||
## Delete the given QAbstractListModel
|
||||
debugMsg("QAbstractListModel", "delete")
|
||||
self.QObject.delete()
|
||||
|
||||
proc newQAbstractListModel*(): QAbstractListModel =
|
||||
## Return a new QAbstractListModel
|
||||
debugMsg("QAbstractListModel", "new")
|
||||
new(result, delete)
|
||||
result.setup()
|
||||
|
||||
proc beginInsertRows*(self: QAbstractListModel, parentIndex: QModelIndex, first: int, last: int) =
|
||||
## Notify the view that the model is about to inserting the given number of rows
|
||||
debugMsg("QAbstractListModel", "beginInsertRows")
|
||||
dos_qabstractlistmodel_beginInsertRows(self.vptr.DosQAbstractListModel, parentIndex.vptr, first.cint, last.cint)
|
||||
|
||||
proc endInsertRows*(self: QAbstractListModel) =
|
||||
## Notify the view that the rows have been inserted
|
||||
debugMsg("QAbstractListModel", "endInsertRows")
|
||||
dos_qabstractlistmodel_endInsertRows(self.vptr.DosQAbstractListModel)
|
||||
|
||||
proc beginRemoveRows*(self: QAbstractListModel, parentIndex: QModelIndex, first: int, last: int) =
|
||||
## Notify the view that the model is about to remove the given number of rows
|
||||
debugMsg("QAbstractListModel", "beginRemoveRows")
|
||||
dos_qabstractlistmodel_beginRemoveRows(self.vptr.DosQAbstractListModel, parentIndex.vptr, first.cint, last.cint)
|
||||
|
||||
proc endRemoveRows*(self: QAbstractListModel) =
|
||||
## Notify the view that the rows have been removed
|
||||
debugMsg("QAbstractListModel", "endRemoveRows")
|
||||
dos_qabstractlistmodel_endRemoveRows(self.vptr.DosQAbstractListModel)
|
||||
|
||||
proc beginResetModel*(self: QAbstractListModel) =
|
||||
## Notify the view that the model is about to resetting
|
||||
debugMsg("QAbstractListModel", "beginResetModel")
|
||||
dos_qabstractlistmodel_beginResetModel(self.vptr.DosQAbstractListModel)
|
||||
|
||||
proc endResetModel*(self: QAbstractListModel) =
|
||||
## Notify the view that model has finished resetting
|
||||
debugMsg("QAbstractListModel", "endResetModel")
|
||||
dos_qabstractlistmodel_endResetModel(self.vptr.DosQAbstractListModel)
|
||||
|
||||
proc dataChanged*(self: QAbstractListModel,
|
||||
topLeft: QModelIndex,
|
||||
bottomRight: QModelIndex,
|
||||
roles: openArray[int]) =
|
||||
## Notify the view that the model data changed
|
||||
debugMsg("QAbstractListModel", "dataChanged")
|
||||
var copy: seq[cint]
|
||||
for i in roles:
|
||||
copy.add(i.cint)
|
||||
dos_qabstractlistmodel_dataChanged(self.vptr.DosQAbstractListModel, topLeft.vptr,
|
||||
bottomRight.vptr, copy[0].addr, copy.len.cint)
|
|
@ -12,11 +12,11 @@ proc newQObjectMetaObject*(): QMetaObject =
|
|||
new(result, delete)
|
||||
result.vptr = dos_qobject_qmetaobject()
|
||||
|
||||
proc newQAbstractListModelMetaObject*(): QMetaObject =
|
||||
## Create the QMetaObject of QAbstractListModel
|
||||
debugMsg("QMetaObject", "newQAbstractListModelMetaObject")
|
||||
proc newQAbstractItemModelMetaObject*(): QMetaObject =
|
||||
## Create the QMetaObject of QAbstractItemModel
|
||||
debugMsg("QMetaObject", "newQAbstractItemModelMetaObject")
|
||||
new(result, delete)
|
||||
result.vptr = dos_qabstractlistmodel_qmetaobject()
|
||||
result.vptr = dos_qabstractitemmodel_qmetaobject()
|
||||
|
||||
proc newQMetaObject*(superClass: QMetaObject, className: string,
|
||||
signals: seq[SignalDefinition],
|
||||
|
@ -32,19 +32,19 @@ proc newQMetaObject*(superClass: QMetaObject, className: string,
|
|||
var dosSignals: seq[DosSignalDefinition] = @[]
|
||||
for i in 0..<signals.len:
|
||||
let name = signals[i].name.cstring
|
||||
let parametersCount = signals[i].parametersTypes.len.cint
|
||||
let parametersMetaTypes = if parametersCount > 0: signals[i].parametersTypes[0].unsafeAddr else: nil
|
||||
let dosSignal = DosSignalDefinition(name: name, parametersCount: parametersCount, parametersMetaTypes: parametersMetaTypes)
|
||||
let parametersCount = signals[i].parameters.len.cint
|
||||
let parameters = if parametersCount > 0: signals[i].parameters[0].unsafeAddr else: nil
|
||||
let dosSignal = DosSignalDefinition(name: name, parametersCount: parametersCount, parameters: parameters)
|
||||
dosSignals.add(dosSignal)
|
||||
|
||||
var dosSlots: seq[DosSlotDefinition] = @[]
|
||||
for i in 0..<slots.len:
|
||||
let name = slots[i].name.cstring
|
||||
let returnMetaType = slots[i].returnMetaType.cint
|
||||
let parametersCount = slots[i].parametersTypes.len.cint
|
||||
let parametersMetaTypes = if parametersCount > 0: slots[i].parametersTypes[0].unsafeAddr else: nil
|
||||
let parametersCount = slots[i].parameters.len.cint
|
||||
let parameters = if parametersCount > 0: slots[i].parameters[0].unsafeAddr else: nil
|
||||
let dosSlot = DosSlotDefinition(name: name, returnMetaType: returnMetaType,
|
||||
parametersCount: parametersCount, parametersMetaTypes: parametersMetaTypes)
|
||||
parametersCount: parametersCount, parameters: parameters)
|
||||
dosSlots.add(dosSlot)
|
||||
|
||||
var dosProperties: seq[DosPropertyDefinition] = @[]
|
||||
|
|
Loading…
Reference in New Issue