Changed property syntax to filcuc's suggestion: e.g QtProperty name of string:
This commit is contained in:
parent
4f1da7957b
commit
e5888a989f
|
@ -246,16 +246,14 @@ macro QtType*(qtDecl: stmt): stmt {.immediate.} =
|
||||||
# allow simple types and type aliases
|
# allow simple types and type aliases
|
||||||
result.add it
|
result.add it
|
||||||
else:
|
else:
|
||||||
let superName = if superType.kind == nnkIdent: superType else: superType.getNodeOf(nnkIdent)
|
# may come in useful if we want to check objects inherit from QObject
|
||||||
if $superName != "QtProperty":
|
#let superName = if superType.kind == nnkIdent: superType else: superType.getNodeOf(nnkIdent)
|
||||||
if typ != nil:
|
if typ != nil:
|
||||||
error("only support one type declaration")
|
error("only support one type declaration")
|
||||||
|
else: # without this else, it fails to compile
|
||||||
typ = typeDecl.getTypeName
|
typ = typeDecl.getTypeName
|
||||||
result.add it
|
result.add it
|
||||||
result.add genSuperTemplate(typeDecl)
|
result.add genSuperTemplate(typeDecl)
|
||||||
else:
|
|
||||||
# process later
|
|
||||||
properties.add(it)
|
|
||||||
elif it.kind == nnkMethodDef:
|
elif it.kind == nnkMethodDef:
|
||||||
if it.hasPragma("slot"):
|
if it.hasPragma("slot"):
|
||||||
let pragma = it.pragma()
|
let pragma = it.pragma()
|
||||||
|
@ -272,6 +270,12 @@ macro QtType*(qtDecl: stmt): stmt {.immediate.} =
|
||||||
userDefined.add it
|
userDefined.add it
|
||||||
elif it.kind == nnkProcDef:
|
elif it.kind == nnkProcDef:
|
||||||
userDefined.add it
|
userDefined.add it
|
||||||
|
elif it.kind == nnkCommand:
|
||||||
|
let cmdIdent = it[0]
|
||||||
|
if cmdIdent == nil or cmdIdent.kind != nnkIdent or
|
||||||
|
($cmdIdent).toLower() != "qtproperty":
|
||||||
|
error("do not know how to handle: \n" & repr(it))
|
||||||
|
properties.add it
|
||||||
else:
|
else:
|
||||||
# everything else should pass through unchanged
|
# everything else should pass through unchanged
|
||||||
result.add it
|
result.add it
|
||||||
|
@ -339,36 +343,43 @@ macro QtType*(qtDecl: stmt): stmt {.immediate.} =
|
||||||
let call = newCall(regSigDot, newLit name, argTypesArray)
|
let call = newCall(regSigDot, newLit name, argTypesArray)
|
||||||
createBody.add call
|
createBody.add call
|
||||||
for property in properties:
|
for property in properties:
|
||||||
let inherit = property.getNodeOf(nnkOfInherit)
|
#echo treeRepr property
|
||||||
# OfInherit
|
let infix = property[1]
|
||||||
# BracketExpr
|
expectKind infix, nnkInfix
|
||||||
# Ident !"QtProperty"
|
# Infix
|
||||||
# Ident !"string"
|
# Ident !"of"
|
||||||
let nimPropType = inherit[0][1]
|
# Ident !"name"
|
||||||
|
# Ident !"string"
|
||||||
|
|
||||||
|
let nimPropType = infix[2]
|
||||||
let qtPropMeta = nim2QtMeta[$nimPropType]
|
let qtPropMeta = nim2QtMeta[$nimPropType]
|
||||||
if qtPropMeta == nil: error($nimPropType & " not supported")
|
if qtPropMeta == nil: error($nimPropType & " not supported")
|
||||||
let metaDot = newDotExpr(ident "QMetaType", ident qtPropMeta)
|
let metaDot = newDotExpr(ident "QMetaType", ident qtPropMeta)
|
||||||
let typeDef = property.getNodeOf(nnkTypeDef)
|
let propertyName = infix[1]
|
||||||
let typeName = typeDef.getTypeName()
|
|
||||||
var read, write, notify: PNimrodNode
|
var read, write, notify: PNimrodNode
|
||||||
|
let stmtList = property[2]
|
||||||
# fields
|
# fields
|
||||||
let recList = typeDef.getNodeof(nnkRecList)
|
# StmtList
|
||||||
for identDef in recList.children:
|
# Asgn
|
||||||
let name = identDef.getIdentDefName()
|
# Ident !"read"
|
||||||
|
# Ident !"getName
|
||||||
|
for asgn in stmtList.children:
|
||||||
|
echo treerepr asgn
|
||||||
|
let name = asgn[0]
|
||||||
case $name
|
case $name
|
||||||
of "read":
|
of "read":
|
||||||
read = identDef[2]
|
read = asgn[1]
|
||||||
of "write":
|
of "write":
|
||||||
write = identDef[2]
|
write = asgn[1]
|
||||||
of "notify":
|
of "notify":
|
||||||
notify = identDef[2]
|
notify = asgn[1]
|
||||||
else:
|
else:
|
||||||
error("unknown property field: " & $name)
|
error("unknown property field: " & $name)
|
||||||
let regPropDot = newDotExpr(ident "myQObject", ident "registerProperty")
|
let regPropDot = newDotExpr(ident "myQObject", ident "registerProperty")
|
||||||
let readArg = if read == nil: newNilLit() else: newLit($read)
|
let readArg = if read == nil: newNilLit() else: newLit($read)
|
||||||
let writeArg = if write == nil: newNilLit() else: newLit($write)
|
let writeArg = if write == nil: newNilLit() else: newLit($write)
|
||||||
let notifyArg = if notify == nil: newNilLit() else: newLit($notify)
|
let notifyArg = if notify == nil: newNilLit() else: newLit($notify)
|
||||||
let call = newCall(regPropDot, newLit($typeName), metaDot, readArg, writeArg, notifyArg)
|
let call = newCall(regPropDot, newLit($propertyName), metaDot, readArg, writeArg, notifyArg)
|
||||||
createBody.add call
|
createBody.add call
|
||||||
|
|
||||||
#echo repr createProto
|
#echo repr createProto
|
||||||
|
|
Loading…
Reference in New Issue