therecipe / qt

Qt binding for Go (Golang) with support for Windows / macOS / Linux / FreeBSD / Android / iOS / Sailfish OS / Raspberry Pi / AsteroidOS / Ubuntu Touch / JavaScript / WebAssembly
GNU Lesser General Public License v3.0
10.41k stars 741 forks source link

Charts and Chart models ported already? #957

Open amlwwalker opened 5 years ago

amlwwalker commented 5 years ago

Have chart models been implemented? I did a search through this repo for QPieSeries and came up with nothing, however I see there is a /charts directory mentioned in a couple of issues.

Trying to dynamically create the model for a PieChart according to HPieModelMapper and the QPieSeries however digging for the implementation is giving me no results

therecipe commented 5 years ago

Hey

Yeah, it seems like QPieModelMapper is missing somehow, QPieSeries should be there though. I will look into this.

amlwwalker commented 5 years ago

Thanks

therecipe commented 5 years ago

I looked into this again and it seems like QPieModelMapper isn't available, because it's an abstract class and not meant to be used directly. You should be able to use QVPieModelMapper and QHPieModelMapper though.

I tried to find an official example that makes use of QVPieModelMapper, but only found one that made use of QVXYModelMapper so I ported that one instead. You can find it here

amlwwalker commented 5 years ago

Ok cool I'll have a look at that, yeah basically just wanted to be able to populate pie charts based on backend data (and update it if it changes). I'll see your example. Thanks!

amlwwalker commented 5 years ago

@therecipe Silly question..... How do you use both widgets and Qml together? I see in the example here you are doing this with widgets, and I am more of a fan of Qml (settles in my brain easier to have the layout done seperately) but I see the benefit of having both, so if I wanted to use your example with Qml, or utilise QVXYModelMapper in Qml how do you do that?

I guess this would also be useful for another question I asked about a plugin framework. Having modules that could be plugged in at run time, is possibly easier if they are widgets than if they are Qml?

therecipe commented 5 years ago

IIRC using the Qml chartview together with Go is a bit complicated, because you will need to create the initial chart series in Qml: https://github.com/therecipe/qt/issues/638#issuecomment-404267040 To get this working you will probably need to do something similar and then also create the Model + the ModelMapper either in Go or in Qml.

About the plugins, it's probably easier to get Qml plugins working since you can simply instantiate Qml types at runtime from a string like shown in this example here, or by loading *.qml files over the network like shown here.

amlwwalker commented 5 years ago

OK thanks, I might have to come back to charts a little later, they don't seem the most straight forward to implement with data coming from the Go side of things.

With regard to the examples/quick/dynamic example, on compilation I get

dynamic.go:18:22: undefined: qml.NewQQmlComponent2

Which seems odd, as using VSCode I can click through to the NewQQmlComponent2 function. I've never had this before where it cant find the function in the "github.com/therecipe/qt/qml" import, could this be a change in the Qt 5.13 breaking changes? does it run for you?

therecipe commented 5 years ago

Yeah, sorry it seems like the overload number changed with 5.13 If you use 5.12, then you will need to change it to qml.NewQQmlComponent

amlwwalker commented 5 years ago

Hmm, thanks, however I seem to be going through this alot. How can I guarantee that I'm compiling with 5.13? When I do:

 ✘  /usr/local/opt/qt5/bin  ./qmake --version
QMake version 3.1
Using Qt version 5.13.0 in /usr/local/Cellar/qt/5.13.0/lib
 /usr/local/opt/qt5/bin  cd ../../
 /usr/local/opt  cd qt
 /usr/local/opt/qt  cd bin
 /usr/local/opt/qt/bin  ./qmake --version
QMake version 3.1
Using Qt version 5.13.0 in /usr/local/Cellar/qt/5.13.0/lib
 /usr/local/opt/qt/bin 

I.e there are two versions of Qt installed, but both are using 5.13 I always export export QT_DIR=/usr/local/opt/qt but for some reason your comment suggests I am using 5.12 (and so does the fact that I have to change it to qml.NewQQmlComponent

therecipe commented 4 years ago

Maybe try to run $(go env GOPATH)/bin/qtsetup check and check which version QT_API reports, maybe you set it to 5.12.0 some time ago or something.

Then either unset QT_API or export QT_API=5.13.0

amlwwalker commented 4 years ago

Hmm I get

INFO[0000] QT_API:                      ''
INFO[0000] QT_VERSION:                  '5.13.0'
INFO[0000] QT_DIR:                      '/Users/alex/Qt'
therecipe commented 4 years ago

Mh, maybe try re-running the full setup. Or try to export QT_NOT_CACHED=true before running qtdeploy, it could be that there is some problem with the cache validation.