fix qtmoc + new quick/hotreload example

This commit is contained in:
therecipe 2016-12-24 00:45:53 +01:00
parent 11aa6b19de
commit 0b03390a53
5 changed files with 66 additions and 6 deletions

View file

@ -124,12 +124,14 @@ func (c *Class) IsSubClassOf(class string) bool {
func (c *Class) isSubClass() bool { return c.Fullname != "" }
func (c *Class) HasFunctionWithName(n string) bool {
for _, f := range c.Functions {
if strings.ToLower(f.Name) != strings.ToLower(n) {
continue
}
return c.HasFunctionWithNameAndOverloadNumber(n, "")
}
return true
func (c *Class) HasFunctionWithNameAndOverloadNumber(n string, num string) bool {
for _, f := range c.Functions {
if strings.ToLower(f.Name) == strings.ToLower(n) && f.OverloadNumber == num {
return true
}
}
return false

View file

@ -0,0 +1,43 @@
package main
import (
"os"
"path/filepath"
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/quick"
"github.com/therecipe/qt/widgets"
)
func initQQuickView(path string) *quick.QQuickView {
var view = quick.NewQQuickView(nil)
var watcher = core.NewQFileSystemWatcher2([]string{filepath.Dir(path)}, nil)
var reload = func(p string) {
println("changed:", p)
view.SetSource(core.NewQUrl())
view.Engine().ClearComponentCache()
view.SetSource(core.NewQUrl3(path, 0))
}
//watcher.ConnectFileChanged(reload)
watcher.ConnectDirectoryChanged(reload)
return view
}
func main() {
var path = filepath.Join(os.Getenv("GOPATH"), "src", "github.com", "therecipe", "qt", "internal", "examples", "quick", "hotreload", "qml", "hotreload.qml")
widgets.NewQApplication(len(os.Args), os.Args)
var view = initQQuickView(path)
view.SetSource(core.NewQUrl3(path, 0))
view.SetResizeMode(quick.QQuickView__SizeRootObjectToView)
view.Show()
widgets.QApplication_Exec()
}

View file

@ -0,0 +1,15 @@
import QtQuick 2.0
Rectangle {
id: page
width: 320; height: 480
color: "lightgray"
Text {
id: helloText
text: "Hello world!"
y: 30
anchors.horizontalCenter: page.horizontalCenter
font.pointSize: 24; font.bold: true
}
}

View file

@ -352,7 +352,7 @@ func (m *appMoc) generate() error {
f.Name = strings.Replace(f.Name, bcf.ClassName(), c.Name, -1)
f.Fullname = strings.Replace(f.Fullname, bcf.ClassName(), c.Name, -1)
if !c.HasFunctionWithName(f.Name) {
if !c.HasFunctionWithNameAndOverloadNumber(f.Name, f.OverloadNumber) {
c.Functions = append(c.Functions, &f)
}
}

0
internal/utils/walk.go Normal file → Executable file
View file