Added initial support for qmlRegisterType

This commit is contained in:
Filippo Cucchetto 2016-02-21 18:15:49 +01:00
parent ac8c2422e0
commit cee83ba832
4 changed files with 78 additions and 42 deletions

View File

@ -25,5 +25,6 @@ include private/qhashintbytearray.nim
include private/qmodelindex.nim include private/qmodelindex.nim
include private/qabstractlistmodel.nim include private/qabstractlistmodel.nim
include private/qresource.nim include private/qresource.nim
include private/qdeclarative.nim
#var qobjectRegistry = initTable[ptr QObjectObj, bool]() #var qobjectRegistry = initTable[ptr QObjectObj, bool]()
#include private.nimqmlmacros #include private.nimqmlmacros

View File

@ -1,50 +1,61 @@
type type
NimQObject = pointer NimQObject = pointer
NimQAbstractListModel = pointer NimQAbstractListModel = pointer
DosQMetaObject* = distinct pointer DosQMetaObject = distinct pointer
DosQObject* = distinct pointer DosQObject = distinct pointer
DosQVariant* = distinct pointer DosQVariant = distinct pointer
DosQQmlContext* = distinct pointer DosQQmlContext = distinct pointer
DosQQmlApplicationEngine* = distinct pointer DosQQmlApplicationEngine = distinct pointer
DosQVariantArray* {.unchecked.} = array[0..0, DosQVariant] DosQVariantArray {.unchecked.} = array[0..0, DosQVariant]
DosQMetaType = cint DosQMetaType = cint
DosQMetaTypeArray* {.unchecked.} = array[0..0, DosQMetaType] DosQMetaTypeArray {.unchecked.} = array[0..0, DosQMetaType]
DosQUrl* = distinct pointer DosQUrl = distinct pointer
DosQQuickView* = distinct pointer DosQQuickView = distinct pointer
DosQHashIntByteArray* = distinct pointer DosQHashIntByteArray = distinct pointer
DosQModelIndex = distinct pointer DosQModelIndex = distinct pointer
DosQAbstractListModel = distinct pointer DosQAbstractListModel = distinct pointer
DosSignalDefinition = object
name: cstring
parametersCount: cint
parametersMetaTypes: pointer
DosSignalDefinition* = object DosSignalDefinitions = object
name*: cstring count: cint
parametersCount*: cint definitions: pointer
parametersMetaTypes*: pointer
DosSignalDefinitions* = object DosSlotDefinition = object
count*: cint name: cstring
definitions*: pointer returnMetaType: cint
parametersCount: cint
parametersMetaTypes: pointer
DosSlotDefinition* = object DosSlotDefinitions = object
name*: cstring count: cint
returnMetaType*: cint definitions: pointer
parametersCount*: cint
parametersMetaTypes*: pointer
DosSlotDefinitions* = object DosPropertyDefinition = object
count*: cint name: cstring
definitions*: pointer propertyMetaType: cint
readSlot: cstring
writeSlot: cstring
notifySignal: cstring
DosPropertyDefinition* = object DosPropertyDefinitions = object
name*: cstring count: cint
propertyMetaType*: cint definitions: pointer
readSlot*: cstring
writeSlot*: cstring
notifySignal*: cstring
DosPropertyDefinitions* = object DosCreateCallback = proc(id: cint, nimQObject: var NimQObject, dosQObject: var DosQObject) {.cdecl.}
count*: cint DosDeleteCallback = proc(id: cint, nimQObject: NimQObject) {.cdecl.}
definitions*: pointer
DosQmlRegisterType = object
major: cint
minor: cint
uri: cstring
qml: cstring
staticMetaObject: DosQMetaObject
createCallback: DosCreateCallback
deleteCallback: DosDeleteCallback
DosQObjectCallBack = proc(nimobject: NimQObject, slotName: DosQVariant, numArguments: cint, arguments: ptr DosQVariantArray) {.cdecl.} DosQObjectCallBack = proc(nimobject: NimQObject, slotName: DosQVariant, numArguments: cint, arguments: ptr DosQVariantArray) {.cdecl.}
@ -57,8 +68,8 @@ type
DosHeaderDataCallback = proc(nimmodel: NimQAbstractListModel, section: cint, orientation: cint, role: cint, result: DosQVariant) {.cdecl.} DosHeaderDataCallback = proc(nimmodel: NimQAbstractListModel, section: cint, orientation: cint, role: cint, result: DosQVariant) {.cdecl.}
# Conversion # Conversion
proc resetToNil*[T](x: var T) = x = nil.pointer.T proc resetToNil[T](x: var T) = x = nil.pointer.T
proc isNil*[T](x: T): bool = x.pointer == nil proc isNil[T](x: T): bool = x.pointer == nil
# QApplication # QApplication
proc dos_qapplication_create() {.cdecl, importc.} proc dos_qapplication_create() {.cdecl, importc.}
@ -109,7 +120,7 @@ proc dos_qvariant_setQObject(variant: DosQVariant, value: DosQObject) {.cdecl, i
proc dos_chararray_delete(str: cstring) {.cdecl, importc.} proc dos_chararray_delete(str: cstring) {.cdecl, importc.}
# QObject # QObject
proc dos_qobject_qmetaobject*(vptr: var DosQmetaObject) {.cdecl, importc.} proc dos_qobject_qmetaobject(vptr: var DosQmetaObject) {.cdecl, importc.}
proc dos_qobject_create(qobject: var DosQObject, nimobject: NimQObject, metaObject: DosQMetaObject, dosQObjectCallback: DosQObjectCallBack) {.cdecl, importc.} proc dos_qobject_create(qobject: var DosQObject, nimobject: NimQObject, metaObject: DosQMetaObject, dosQObjectCallback: DosQObjectCallBack) {.cdecl, importc.}
proc dos_qobject_objectName(qobject: DosQObject, result: var cstring) {.cdecl, importc.} proc dos_qobject_objectName(qobject: DosQObject, result: var cstring) {.cdecl, importc.}
proc dos_qobject_setObjectName(qobject: DosQObject, name: cstring) {.cdecl, importc.} proc dos_qobject_setObjectName(qobject: DosQObject, name: cstring) {.cdecl, importc.}
@ -117,16 +128,16 @@ proc dos_qobject_signal_emit(qobject: DosQObject, signalName: cstring, arguments
proc dos_qobject_delete(qobject: DosQObject) {.cdecl, importc.} proc dos_qobject_delete(qobject: DosQObject) {.cdecl, importc.}
# QAbstractListModel # QAbstractListModel
proc dos_qabstractlistmodel_qmetaobject*(vptr: var DosQmetaObject) {.cdecl importc.} proc dos_qabstractlistmodel_qmetaobject(vptr: var DosQmetaObject) {.cdecl importc.}
# QMetaObject # QMetaObject
proc dos_qmetaobject_create*(vptr: var DosQmetaObject, proc dos_qmetaobject_create(vptr: var DosQmetaObject,
superclassMetaObject: DosQMetaObject, superclassMetaObject: DosQMetaObject,
className: cstring, className: cstring,
signalDefinitions: DosSignalDefinitions, signalDefinitions: DosSignalDefinitions,
slotDefinitions: DosSlotDefinitions, slotDefinitions: DosSlotDefinitions,
propertyDefinitions: DosPropertyDefinitions) {.cdecl, importc.} propertyDefinitions: DosPropertyDefinitions) {.cdecl, importc.}
proc dos_qmetaobject_delete*(vptr: DosQmetaObject) {.cdecl, importc.} proc dos_qmetaobject_delete(vptr: DosQmetaObject) {.cdecl, importc.}
# QUrl # QUrl
proc dos_qurl_create(vptr: var DosQUrl, url: cstring, parsingMode: cint) {.cdecl, importc.} proc dos_qurl_create(vptr: var DosQUrl, url: cstring, parsingMode: cint) {.cdecl, importc.}
@ -192,3 +203,5 @@ proc dos_qabstractlistmodel_dataChanged(model: DosQAbstractListModel,
# QResource # QResource
proc dos_qresource_register(filename: cstring) {.cdecl, importc.} proc dos_qresource_register(filename: cstring) {.cdecl, importc.}
# QDeclarative
proc dos_qdeclarative_qmlregistertype(value: ptr DosQmlRegisterType, result: var cint) {.cdecl, importc.}

View File

@ -14,11 +14,11 @@ type
## A QQmlApplicationEngine ## A QQmlApplicationEngine
vptr: DosQQmlApplicationEngine vptr: DosQQmlApplicationEngine
QApplication = ref object of RootObj ## \ QApplication* = ref object of RootObj ## \
## A QApplication ## A QApplication
deleted: bool deleted: bool
QGuiApplication = ref object of RootObj ## \ QGuiApplication* = ref object of RootObj ## \
## A QGuiApplication ## A QGuiApplication
deleted: bool deleted: bool

View File

@ -0,0 +1,22 @@
import tables
var ctorTable = initTable[cint, proc():QObject]()
proc creator(id: cint, nimQObject:var NimQObject, dosQObject: var DosQObject) {.cdecl.} =
let qobject: QObject = ctorTable[id]()
GC_ref(qobject)
nimQObject = addr(qobject[])
dosQObject = qobject.vptr
proc deleter(id: cint, nimQObject: NimQObject) {.cdecl.} =
let qobject = cast[QObject](nimQObject)
GC_unref(qobject)
proc qmlRegisterType*[T](uri: string, major: int, minor: int, qmlName: string, ctor: proc(): T) {.cdecl.} =
var result: cint = 0
let metaObject: QMetaObject = T.staticMetaObject()
let dosQmlRegisterType = DosQmlRegisterType(major: major.cint, minor: minor.cint, uri: uri.cstring,
qml: qmlName.cstring, staticMetaObject: metaObject.vptr,
createCallback: creator, deleteCallback: deleter)
dos_qdeclarative_qmlregistertype(dosQmlRegisterType.unsafeAddr, result)
ctorTable[result] = proc(): QObject = ctor().QObject