fix qtmoc + fix readme (links + example)

This commit is contained in:
therecipe 2017-04-14 20:31:39 +02:00
parent a7ba89f218
commit 0216427884
5 changed files with 130 additions and 98 deletions

View file

@ -751,7 +751,7 @@ You can call Java functions directly from Go with the help of the [androidextras
Callbacks into Go code from Java are also possible (with some manual labor).
Take a look at the [examples](internal/examples/androidextras) to see how it works.
Take a look at the [examples](https://github.com/therecipe/qt/blob/master/internal/examples/androidextras) to see how it works.
</details>
@ -1064,7 +1064,7 @@ func main() {
//create a button and add it to the layout
button := widgets.NewQPushButton2("2. click me", nil)
button.ConnectClicked(func(checked bool) {
widgets.QMessageBox_infos(nil, "OK", input.Text(), widgets.QMessageBox__Ok, widgets.QMessageBox__Ok)
widgets.QMessageBox_Information(nil, "OK", input.Text(), widgets.QMessageBox__Ok, widgets.QMessageBox__Ok)
})
layout.AddWidget(button, 0, 0)
@ -1382,7 +1382,7 @@ There are a few possible ways how you can integrate this dependency into your CI
- You could use the minimal setup, which only depends on Docker + Go and then use `qtdeploy -docker build ...`
- You could look into the [CI](internal/ci) folder and the `*.yml` files in the root folder of this repo.
- You could look into the [CI](https://github.com/therecipe/qt/blob/master/internal/ci) folder and the `*.yml` files in the root folder of this repo.
Misc
----
@ -1397,7 +1397,7 @@ Misc
- For the desktop widgets: https://doc.qt.io/qtcreator/creator-using-qt-designer.html
[Here](internal/example/uitools) is an example how to load the created `*.ui` files.
[Here](https://github.com/therecipe/qt/blob/master/internal/example/uitools) is an example how to load the created `*.ui` files.
- For the qml/quick widgets: https://doc.qt.io/qtcreator/creator-using-qt-quick-designer.html

View file

@ -390,21 +390,39 @@ func SortedClassNamesForModule(module string, template bool) []string {
}
tmpOutput := make([]string, 0)
for item, dep := range items {
depClass, ok := State.ClassMap[dep]
if !ok {
delete(items, item)
continue
}
//filter out everything that has no moc dep
if !(depClass.Module == MOC || strings.HasPrefix(depClass.Module, "custom_")) {
tmpOutput = append(tmpOutput, item)
delete(items, item)
continue
}
}
for len(items) > 0 {
for item, dep := range items {
cd, ok := State.ClassMap[dep]
depClass, ok := State.ClassMap[dep]
if !ok {
delete(items, item)
continue
}
if ok && !(cd.Module == MOC || strings.HasPrefix(cd.Module, "custom_")) || cd.Name == mostBase(items) {
//filter out everything that has the fewest dependencies
if hasFewestDeps(items, depClass.Name) {
tmpOutput = append(tmpOutput, item)
delete(items, item)
continue
}
//filter out everything that has resolved dep
for _, key := range tmpOutput {
if key == dep {
tmpOutput = append(tmpOutput, item)
@ -421,7 +439,7 @@ func SortedClassNamesForModule(module string, template bool) []string {
return output
}
func mostBase(i map[string]string) string {
func hasFewestDeps(i map[string]string, check string) bool {
dif := 100
var base string
for _, v := range i {
@ -434,7 +452,7 @@ func mostBase(i map[string]string) string {
base = v
}
}
return base
return base == check
}
func SortedClassesForModule(module string, template bool) []*Class {

View file

@ -411,56 +411,58 @@ func preambleCpp(module string, input []byte, mode int) []byte {
fmt.Fprint(bb, "\n")
if mode == MOC {
var libs []string
libsm := make(map[string]struct{}, 0)
for _, c := range parser.State.ClassMap {
if c.Pkg != "" {
libs = append(libs, c.Module)
if c.Pkg != "" && c.IsSubClassOfQObject() {
libsm[c.Module] = struct{}{}
}
}
var libs []string
for k := range libsm {
libs = append(libs, k)
}
for _, c := range parser.SortedClassesForModule(strings.Join(libs, ","), true) {
if c.Pkg != "" && strings.Contains(string(input), c.Name) {
if !c.HasConstructor() {
if c.Pkg == "" || !strings.Contains(string(input), c.Name) /*|| !c.HasConstructor()*/ {
continue
}
fmt.Fprintf(bb, "class %v: public %v{\npublic:\n", c.Name, c.GetBases()[0])
for _, function := range c.Functions {
if function.Meta != parser.CONSTRUCTOR || !function.IsSupported() {
continue
}
fmt.Fprintf(bb, "class %v: public %v{\npublic:\n", c.Name, c.GetBases()[0])
for _, function := range c.Functions {
if function.Meta != parser.CONSTRUCTOR || !function.IsSupported() {
continue
}
var input = make([]string, len(function.Parameters))
for i, p := range function.Parameters {
input[i] = p.Name
}
fmt.Fprintf(bb, "\t%v%v(%v) : %v(%v) {};\n",
func() string {
if mode == MOC {
return ""
}
return "My"
}(),
function.ClassName(),
strings.Split(strings.Split(function.Signature, "(")[1], ")")[0],
func() string {
if mode == MOC {
return c.GetBases()[0]
}
return function.ClassName()
}(),
strings.Join(input, ", "),
)
var input = make([]string, len(function.Parameters))
for i, p := range function.Parameters {
input[i] = p.Name
}
fmt.Fprint(bb, "\n};\n")
fmt.Fprintf(bb, "\t%v%v(%v) : %v(%v) {};\n",
func() string {
if mode == MOC {
return ""
}
return "My"
}(),
function.ClassName(),
strings.Split(strings.Split(function.Signature, "(")[1], ")")[0],
func() string {
if mode == MOC {
return c.GetBases()[0]
}
return function.ClassName()
}(),
strings.Join(input, ", "),
)
}
fmt.Fprint(bb, "\n};\n")
}
fmt.Fprint(bb, "\n")

View file

@ -192,7 +192,7 @@ func Moc(path, target string, fast bool) {
//copy constructor and destructor
utils.Log.Debug("start copy structors")
for _ = range append(m.Namespace.Classes, otherclasses...) {
for !hasStructors(m) {
for _, c := range append(m.Namespace.Classes, otherclasses...) {
bc, ok := parser.State.ClassMap[c.Bases]
if !ok {
@ -465,3 +465,15 @@ func cppTypeFromGoType(f *parser.Function, t string) string {
return "void"
}
func hasStructors(m *parser.Module) bool {
for _, c := range m.Namespace.Classes {
if c.Bases == "" {
continue
}
if !c.HasConstructor() /*|| !c.HasDestructor()*/ {
return false
}
}
return true
}

View file

@ -1,120 +1,120 @@
macOS
-----
![](internal/screenshots/darwin_1.png)
![](https://github.com/therecipe/qt/blob/master/internal/screenshots/darwin_1.png)
[source](internal/examples/qml/application)
[source](https://github.com/therecipe/qt/blob/master/internal/examples/qml/application)
![](internal/screenshots/darwin_2.png)
![](https://github.com/therecipe/qt/blob/master/internal/screenshots/darwin_2.png)
[source](internal/examples/widgets/textedit)
[source](https://github.com/therecipe/qt/blob/master/internal/examples/widgets/textedit)
![](internal/screenshots/darwin_3.png)
![](https://github.com/therecipe/qt/blob/master/internal/screenshots/darwin_3.png)
[source](internal/examples/quick/calc)
[source](https://github.com/therecipe/qt/blob/master/internal/examples/quick/calc)
![](internal/screenshots/darwin_4.png)
![](https://github.com/therecipe/qt/blob/master/internal/screenshots/darwin_4.png)
[source](internal/examples/qml/drawer_nav_x)
[source](https://github.com/therecipe/qt/blob/master/internal/examples/qml/drawer_nav_x)
![](internal/screenshots/darwin_5.png)
![](https://github.com/therecipe/qt/blob/master/internal/screenshots/darwin_5.png)
[source](internal/examples/qml/gallery)
[source](https://github.com/therecipe/qt/blob/master/internal/examples/qml/gallery)
![](internal/screenshots/darwin_6.png)
![](https://github.com/therecipe/qt/blob/master/internal/screenshots/darwin_6.png)
[source](internal/examples/widgets/pixel_editor)
[source](https://github.com/therecipe/qt/blob/master/internal/examples/widgets/pixel_editor)
![](internal/screenshots/darwin_7.png)
![](https://github.com/therecipe/qt/blob/master/internal/screenshots/darwin_7.png)
[source](internal/examples/widgets/line_edits)
[source](https://github.com/therecipe/qt/blob/master/internal/examples/widgets/line_edits)
Windows
-------
![](internal/screenshots/windows_1.png)
![](https://github.com/therecipe/qt/blob/master/internal/screenshots/windows_1.png)
[source](internal/examples/qml/application)
[source](https://github.com/therecipe/qt/blob/master/internal/examples/qml/application)
![](internal/screenshots/windows_2.png)
![](https://github.com/therecipe/qt/blob/master/internal/screenshots/windows_2.png)
[source](internal/examples/widgets/textedit)
[source](https://github.com/therecipe/qt/blob/master/internal/examples/widgets/textedit)
![](internal/screenshots/windows_3.png)
![](https://github.com/therecipe/qt/blob/master/internal/screenshots/windows_3.png)
[source](internal/examples/quick/calc)
[source](https://github.com/therecipe/qt/blob/master/internal/examples/quick/calc)
![](internal/screenshots/windows_4.png)
![](https://github.com/therecipe/qt/blob/master/internal/screenshots/windows_4.png)
[source](internal/examples/qml/drawer_nav_x)
[source](https://github.com/therecipe/qt/blob/master/internal/examples/qml/drawer_nav_x)
![](internal/screenshots/windows_5.png)
![](https://github.com/therecipe/qt/blob/master/internal/screenshots/windows_5.png)
[source](internal/examples/qml/gallery)
[source](https://github.com/therecipe/qt/blob/master/internal/examples/qml/gallery)
![](internal/screenshots/windows_6.png)
![](https://github.com/therecipe/qt/blob/master/internal/screenshots/windows_6.png)
[source](internal/examples/widgets/pixel_editor)
[source](https://github.com/therecipe/qt/blob/master/internal/examples/widgets/pixel_editor)
![](internal/screenshots/windows_7.png)
![](https://github.com/therecipe/qt/blob/master/internal/screenshots/windows_7.png)
[source](internal/examples/widgets/line_edits)
[source](https://github.com/therecipe/qt/blob/master/internal/examples/widgets/line_edits)
Linux
-----
![](internal/screenshots/linux_1.png)
![](https://github.com/therecipe/qt/blob/master/internal/screenshots/linux_1.png)
[source](internal/examples/qml/application)
[source](https://github.com/therecipe/qt/blob/master/internal/examples/qml/application)
![](internal/screenshots/linux_2.png)
![](https://github.com/therecipe/qt/blob/master/internal/screenshots/linux_2.png)
[source](internal/examples/widgets/textedit)
[source](https://github.com/therecipe/qt/blob/master/internal/examples/widgets/textedit)
![](internal/screenshots/linux_3.png)
![](https://github.com/therecipe/qt/blob/master/internal/screenshots/linux_3.png)
[source](internal/examples/quick/calc)
[source](https://github.com/therecipe/qt/blob/master/internal/examples/quick/calc)
![](internal/screenshots/linux_4.png)
![](https://github.com/therecipe/qt/blob/master/internal/screenshots/linux_4.png)
[source](internal/examples/qml/drawer_nav_x)
[source](https://github.com/therecipe/qt/blob/master/internal/examples/qml/drawer_nav_x)
![](internal/screenshots/linux_5.png)
![](https://github.com/therecipe/qt/blob/master/internal/screenshots/linux_5.png)
[source](internal/examples/qml/gallery)
[source](https://github.com/therecipe/qt/blob/master/internal/examples/qml/gallery)
![](internal/screenshots/linux_6.png)
![](https://github.com/therecipe/qt/blob/master/internal/screenshots/linux_6.png)
[source](internal/examples/widgets/pixel_editor)
[source](https://github.com/therecipe/qt/blob/master/internal/examples/widgets/pixel_editor)
![](internal/screenshots/linux_7.png)
![](https://github.com/therecipe/qt/blob/master/internal/screenshots/linux_7.png)
[source](internal/examples/widgets/line_edits)
[source](https://github.com/therecipe/qt/blob/master/internal/examples/widgets/line_edits)
Android
-------
![](internal/screenshots/android_portrait.png)
![](https://github.com/therecipe/qt/blob/master/internal/screenshots/android_portrait.png)
![](internal/screenshots/android_landscape.png)
![](https://github.com/therecipe/qt/blob/master/internal/screenshots/android_landscape.png)
[source](internal/examples/qml/gallery)
[source](https://github.com/therecipe/qt/blob/master/internal/examples/qml/gallery)
iOS
---
![](internal/screenshots/ios_portrait.png)
![](https://github.com/therecipe/qt/blob/master/internal/screenshots/ios_portrait.png)
![](internal/screenshots/ios_landscape.png)
![](https://github.com/therecipe/qt/blob/master/internal/screenshots/ios_landscape.png)
[source](internal/examples/qml/gallery)
[source](https://github.com/therecipe/qt/blob/master/internal/examples/qml/gallery)
SailfishOS
----------
![](internal/screenshots/sailfish_portrait.png)
![](https://github.com/therecipe/qt/blob/master/internal/screenshots/sailfish_portrait.png)
[source](internal/examples/quick/sailfish)
[source](https://github.com/therecipe/qt/blob/master/internal/examples/quick/sailfish)
---