Open apocelipes opened 6 years ago
Hey
Yeah, sorry these tags aren't documented because I'm not fully done with them yet.
I will try to provide you some example code and more info later this week, but you can basically use them to (re-)route signals/slots/properties and connect them to other functions without the need to write *.Connect*(*)
functions again and again.
So if you write something like this:
_ func() `slot:"handleTimeout,<-(this.m_timer.timeout)"`
It will automatically connect the m_timer's timeout function (emited by "Start2" in this case) to your handleTimout function.
means this code would be generated and executed:
this.m_timer.ConnectTimeout(this.handleTimeout)
If the arrow points into the other direction:
_ func() `slot:"handleTimeout,->(this.m_timer.timeout)"`
The handleTimeout function would be connect to m_timer's timeout function and a call to *.HandleTimeout()
would therefore also call m_timer's timeout function.
means this code would be generated and executed:
this.ConnectHandleTimeout(this.m_timer.timeout)
So basically, "x,->(y)"
, means a call to (*yourClass) X()
will also call Y()
and in the case of, "x,<-(y)"
, a call to Y() will also call (*yourClass) x()
but you will need to pay special attention to differentiate between "x,<-(y)"
and "X,<-(y)"
because "x,<-(y)"
will call (*yourClass) x()
and "X,<-(y)"
will call (*yourClass) X()
Also as a sidenote, ->
and auto
have basically the same effect, so you could also write x,auto(y)
instead of x,->(y)
. But if you use <-
as well, it might be better to also use ->
instead, and only use the "naked" auto
tag to connect to functions from the same "class"
As "y" in x,->(y)
, x,<-(y)
or X,<-(y)
you can use:
pkg.GlobalVariable
which will then automatically be extended to pkg.GlobalVariable.X
(or you could use pkg.GlobalVariable.Z
directly should the function name differ from the target function)
or
GlobalVariable
which will then automatically be extended to GlobalVariable.x
(or you could use GlobalVariable.z
directly should the function name differ from the target function)
or
this.StructField
which will then automatically be extended to this.StructField.x
(or you could use this.StructField.z
directly should the function name differ from the target function)
or (not fully working yet)
this
which will then automatically be extended to this.x
(or you could use this.z
directly should the function name differ from the target function)
But "this" is not fully working yet and you may need to use this.Q*.z
in the meantime as a workaround like shown here
Also, why are these "->" and "<-" tags created at all?
Most of the time you won't need them, but there are situations were you can save yourself from writing a lot of *.Connect*(*)
functions by using them.
Take a look into the "showcase" example, there I encapsulated the "logic" part of the code into many small "controller" packages and needed a quick way to interconnect these controllers and also a way to quickly connect the QML signals and properties to them. And because of the heavy encapsulation it was necessary to pass those through 3 different layers most of the time which in the end looked like this:
[QML] <-> [Go/Qml Template] <-> [Go Controller] <-> [Go Model]
|
[QML] <-> [Go/Qml Template] <-> [Go Controller]
|
[QML] <-> [Go/Qml Template] <-> [Go Controller] <-> [Go Model]
For example try to follow the "locked" property and the "changed" function calls: QML <-> Go/Qml Template <-> Go Controller <-> Main Go Controller
Also the struct tags will work with "properties" as well, so that you can connect them to another property and you can also choose to only connect the "getter" and/or "setter" and/or "changed" functions automatically with something like this:
_ string `property:"someProperty1,auto,get,set"`
_ string `property:"someProperty2,auto,get,changed"`
_ string `property:"someProperty3,auto,get"`
_ string `property:"someProperty4,->(someProp),get,changed"`
_ string `property:"someProperty5,<-(someProp),set,changed"`
Hope this answers most of the questions you might have, it's been a while since I wrote the code for these struct tags and I hope that I didn't miss something crucial.
edit: also if you want to see what code the struct tags generated, then just look into the "moc.go" files and search for the "*_Constructor" function of your "class"
I have already understood the meaning of the "auto" tag for signal and slot, but I have also found some examples using "->" and "<-", e.g. showcases/sia/wallet/dialog/dialog.go
charts/dynamicspline/chart.go
I read the code, but I still can't understand the role and usage of these tags. So what exactly do these tags have and how should they be used? What is the difference between them and the "auto" tag? Is there a corresponding document or description for these tags?