Started binding QQmlApplicationEngine

This commit is contained in:
Filippo Cucchetto 2016-02-09 00:45:54 +01:00
parent b3c8cbe336
commit 52205c42b5
5 changed files with 42 additions and 28 deletions

View File

@ -16,10 +16,10 @@ include private/nimqmltypes.nim
include private/qmetaobject.nim
include private/qvariant.nim
include private/qobject.nim
include private/qqmlapplicationengine.nim
#include private.nimqmltypes
#var qobjectRegistry = initTable[ptr QObjectObj, bool]()
#include private/qvariant.nim
#include private/qqmlapplicationengine.nim
#include private/qqmlcontext.nim
#include private/qapplication.nim
#include private/qguiapplication.nim

View File

@ -3,6 +3,8 @@ type
DosQMetaObject* = distinct pointer
DosQObject* = distinct pointer
DosQVariant* = distinct pointer
DosQQmlContext* = distinct pointer
DosQQmlApplicationEngine* = distinct pointer
DosQVariantArray* {.unchecked.} = array[0..0, DosQVariant]
DosQMetaType = cint
DosQMetaTypeArray* {.unchecked.} = array[0..0, DosQMetaType]
@ -44,6 +46,17 @@ type
proc resetToNil*[T](x: var T) = x = nil.pointer.T
proc isNil*[T](x: T): bool = x.pointer == nil
# QQmlContext
proc dos_qqmlcontext_setcontextproperty(context: DosQQmlContext, propertyName: cstring, propertyValue: DosQVariant) {.cdecl, importc.}
# QQmlApplicationEngine
proc dos_qqmlapplicationengine_create(engine: var DosQQmlApplicationEngine) {.cdecl, importc.}
proc dos_qqmlapplicationengine_load(engine: DosQQmlApplicationEngine, filename: cstring) {.cdecl, importc.}
proc dos_qqmlapplicationengine_load_data(engine: DosQQmlApplicationEngine, data: cstring) {.cdecl, importc.}
proc dos_qqmlapplicationengine_add_import_path(engine: DosQQmlApplicationEngine, path: cstring) {.cdecl, importc.}
proc dos_qqmlapplicationengine_context(engine: DosQQmlApplicationEngine, context: var DosQQmlContext) {.cdecl, importc.}
proc dos_qqmlapplicationengine_delete(engine: DosQQmlApplicationEngine) {.cdecl, importc.}
# QVariant
proc dos_qvariant_create(variant: var DosQVariant) {.cdecl, importc.}
proc dos_qvariant_create_int(variant: var DosQVariant, value: cint) {.cdecl, importc.}
@ -87,5 +100,4 @@ proc dos_qmetaobject_create*(vptr: var DosQmetaObject,
signalDefinitions: DosSignalDefinitions,
slotDefinitions: DosSlotDefinitions,
propertyDefinitions: DosPropertyDefinitions) {.cdecl, importc.}
proc dos_qmetaobject_delete*(vptr: DosQmetaObject) {.cdecl, importc.}

View File

@ -7,6 +7,10 @@ type
## A QVariant
vptr: DosQVariant
QQmlApplicationEngine* = ref object of RootObj ## \
## A QQmlApplicationEngine
vptr: DosQQmlApplicationEngine
QtItemFlag* {.pure.} = enum ## \
## Item flags
##

View File

@ -1,31 +1,34 @@
# QQmlApplicationEngine
proc dos_qqmlapplicationengine_create(engine: var RawQQmlApplicationEngine) {.cdecl, importc.}
proc dos_qqmlapplicationengine_load(engine: RawQQmlApplicationEngine, filename: cstring) {.cdecl, importc.}
proc dos_qqmlapplicationengine_context(engine: RawQQmlApplicationEngine, context: var QQmlContext) {.cdecl, importc.}
proc dos_qqmlapplicationengine_delete(engine: RawQQmlApplicationEngine) {.cdecl, importc.}
proc setup*(self: QQmlApplicationEngine) =
## Setup a QQmlApplicationEngine
dos_qqmlapplicationengine_create(self.vptr)
proc create*(engine: QQmlApplicationEngine) =
## Create an new QQmlApplicationEngine
dos_qqmlapplicationengine_create(engine.data)
engine.deleted = false
proc loadData(self:QQmlApplicationEngine, data: string) =
## Load the given data
dos_qqmlapplicationengine_load_data(self.vptr, data.cstring)
proc load*(engine: QQmlApplicationEngine, filename: cstring) =
proc load*(self: QQmlApplicationEngine, filename: string) =
## Load the given Qml file
dos_qqmlapplicationengine_load(engine.data, filename)
dos_qqmlapplicationengine_load(self.vptr, filename.cstring)
proc rootContext*(engine: QQmlApplicationEngine): QQmlContext =
## Return the engine root context
dos_qqmlapplicationengine_context(engine.data, result)
proc addImportPath*(self: QQmlApplicationEngine, path: string) =
## Add an import path
dos_qqmlapplicationengine_add_import_path(self.vptr, path.cstring)
proc delete*(engine: QQmlApplicationEngine) =
proc setRootContextProperty(self: QQmlApplicationEngine, name: string, value: QVariant) =
## Set a root context property
var context: DosQQmlContext
dos_qqmlapplicationengine_context(self.vptr, context)
dos_qqmlcontext_setcontextproperty(context, name.cstring, value.vptr)
proc delete*(self: QQmlApplicationEngine) =
## Delete the given QQmlApplicationEngine
if not engine.deleted:
debugMsg("QQmlApplicationEngine", "delete")
dos_qqmlapplicationengine_delete(engine.data)
engine.data = nil.RawQQmlApplicationEngine
engine.deleted = true
debugMsg("QQmlApplicationEngine", "delete")
if self.vptr.isNil:
return
dos_qqmlapplicationengine_delete(self.vptr)
self.vptr.resetToNil
proc newQQmlApplicationEngine*(): QQmlApplicationEngine =
## Return a new QQmlApplicationEngine
new(result, delete)
result.create()
result.setup()

View File

@ -1,5 +0,0 @@
proc dos_qqmlcontext_setcontextproperty(context: QQmlContext, propertyName: cstring, propertyValue: RawQVariant) {.cdecl, importc.}
proc setContextProperty*(context: QQmlContext, propertyName: string, propertyValue: QVariant) =
## Sets a new property with the given value
dos_qqmlcontext_setcontextproperty(context, propertyName, propertyValue.data)