changed QtObject macro syntax

This commit is contained in:
Will Szumski 2015-01-06 00:47:38 +00:00 committed by Filippo Cucchetto
parent 9e91b25cda
commit 2d05bcf0a8
3 changed files with 19 additions and 13 deletions

View File

@ -231,5 +231,5 @@ In details:
The ``QtProperty`` macro has the following syntax The ``QtProperty`` macro has the following syntax
.. code-block:: nim .. code-block:: nim
QtProperty nameOfProperty of typeOfProperty QtProperty[typeOfProperty] nameOfProperty

View File

@ -21,7 +21,7 @@ QtObject:
contact.m_name = name contact.m_name = name
contact.nameChanged() contact.nameChanged()
QtProperty name of string: QtProperty[string] name:
read = getName read = getName
write = setName write = setName
notify = nameChanged notify = nameChanged

View File

@ -327,7 +327,13 @@ macro QtObject*(qtDecl: stmt): stmt {.immediate.} =
elif it.kind == nnkProcDef: elif it.kind == nnkProcDef:
userDefined.add it userDefined.add it
elif it.kind == nnkCommand: elif it.kind == nnkCommand:
let cmdIdent = it[0] let bracket = it[0]
if bracket.kind != nnkBracketExpr:
error("do not know how to handle: \n" & repr(it))
# BracketExpr
# Ident !"QtProperty"
# Ident !"string"
let cmdIdent = bracket[0]
if cmdIdent == nil or cmdIdent.kind != nnkIdent or if cmdIdent == nil or cmdIdent.kind != nnkIdent or
($cmdIdent).toLower() != "qtproperty": ($cmdIdent).toLower() != "qtproperty":
error("do not know how to handle: \n" & repr(it)) error("do not know how to handle: \n" & repr(it))
@ -406,19 +412,19 @@ macro QtObject*(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:
#echo treeRepr property let bracket = property[0]
let infix = property[1] expectKind bracket, nnkBracketExpr
expectKind infix, nnkInfix #Command
# Infix # BracketExpr
# Ident !"of" # Ident !"QtProperty"
# Ident !"name" # Ident !"string"
# Ident !"string" # Ident !"name"
# StmtList
let nimPropType = infix[2] let nimPropType = bracket[1]
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 propertyName = infix[1] let propertyName = property[1]
var read, write, notify: PNimrodNode var read, write, notify: PNimrodNode
let stmtList = property[2] let stmtList = property[2]
# fields # fields