Merge pull request #14 from cowboy-coders/onslotcalled_super
Support signals/slots with inheritance
This commit is contained in:
commit
7049988479
|
@ -228,10 +228,14 @@ proc addSignalBody(signal: PNimrodNode): PNimrodNode {.compileTime.} =
|
|||
args.add getArgName params[i]
|
||||
result.add newCall("emit", args)
|
||||
|
||||
#FIXME: changed typ from typedesc to expr to workaround Nim issue #1874
|
||||
template declareOnSlotCalled(typ: expr): stmt =
|
||||
#FIXME: changed typ from typedesc to expr to workaround Nim issue #1874
|
||||
# This is declared dirty so that identifers are not bound to symbols.
|
||||
# The alternative is to use `removeOpenSym` as we did for `prototypeCreate`.
|
||||
# We should decide which method is preferable.
|
||||
template prototypeOnSlotCalled(typ: expr): stmt {.dirty.} =
|
||||
method onSlotCalled(myQObject: typ, slotName: string, args: openarray[QVariant]) =
|
||||
discard
|
||||
var super = (typ.superType())(myQObject)
|
||||
procCall onSlotCalled(super, slotName, args)
|
||||
|
||||
#FIXME: changed parent, typ from typedesc to expr to workaround Nim issue #1874
|
||||
template prototypeCreate(typ: expr): stmt =
|
||||
|
@ -365,7 +369,7 @@ macro QtObject*(qtDecl: stmt): stmt {.immediate.} =
|
|||
let typeName = typ.getTypeName()
|
||||
|
||||
## define onSlotCalled
|
||||
var slotProto = (getAst declareOnSlotCalled(typeName))[0]
|
||||
var slotProto = (getAst prototypeOnSlotCalled(typeName))[0]
|
||||
var caseStmt = newNimNode(nnkCaseStmt)
|
||||
caseStmt.add ident("slotName")
|
||||
for slot in slots:
|
||||
|
@ -412,7 +416,7 @@ macro QtObject*(qtDecl: stmt): stmt {.immediate.} =
|
|||
# add else: discard
|
||||
caseStmt.add newNimNode(nnkElse)
|
||||
.add newStmtList().add newNimNode(nnkDiscardStmt).add newNimNode(nnkEmpty)
|
||||
slotProto.body = newStmtList().add caseStmt
|
||||
slotProto.body.add caseStmt
|
||||
result.add slotProto
|
||||
|
||||
# generate create method
|
||||
|
|
Loading…
Reference in New Issue