Skip to content

Commit 2558bce

Browse files
author
drswinghead
committed
Merge branch 'master' into v5.12.mrg
2 parents 38106fb + 7d74790 commit 2558bce

File tree

13 files changed

+335
-125
lines changed

13 files changed

+335
-125
lines changed

.travis.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ matrix:
88
fast_finish: true
99
include:
1010
# the actual compilin'
11+
- stage: Ubuntu14-go-master-tests
12+
os: linux
13+
env: JOB=tests-ubuntu14
14+
go: "master"
15+
- stage: Ubuntu14-go1.11-tests
16+
os: linux
17+
env: JOB=tests-ubuntu14
18+
go: "1.11.x"
1119
- stage: Ubuntu14-go1.10-tests
1220
os: linux
1321
env: JOB=tests-ubuntu14
@@ -51,9 +59,17 @@ matrix:
5159
- WINARCH=x32
5260
services:
5361
- docker
62+
- stage: MacOS-Xcode10.1-build
63+
os: osx
64+
osx_image: xcode10.1
65+
env: JOB=build-osx
66+
- stage: MacOS-Xcode9.4-build
67+
os: osx
68+
osx_image: xcode9.4
69+
env: JOB=build-osx
5470
- stage: MacOS-Xcode9.3-build
5571
os: osx
56-
osx_image: xcode9.3beta
72+
osx_image: xcode9.3
5773
env: JOB=build-osx
5874
- stage: MacOS-Xcode8.3-tests
5975
os: osx

Dockerfile.mingw

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM base/archlinux
1+
FROM archlinux/base
22

33
ADD run-mingw.sh /root/
44
RUN chmod +x /root/run-mingw.sh

cmd/cgo-rcc/main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"path"
1111
"strings"
1212

13-
"github.com/kitech/qt.go/qtrt"
13+
"github.com/kitech/qt.go/miscutil"
1414
"github.com/kitech/qt.go/toolutil"
1515
)
1616

@@ -42,11 +42,11 @@ func main() {
4242
file = flag.Arg(0)
4343
log.Println(flag.Arg(0))
4444
filep = path.Base(file)[0:strings.LastIndex(path.Base(file), ".")]
45-
filep = qtrt.IfElseStr(path.Dir(file) == "", filep, path.Dir(file)+"/"+filep)
45+
filep = miscutil.IfElseStr(path.Dir(file) == "", filep, path.Dir(file)+"/"+filep)
4646
log.Println(file, filep)
4747

4848
scc, err := toolutil.RunCmdOut("rcc", file)
49-
qtrt.ErrPrint(err, "rcc", file)
49+
miscutil.ErrPrint(err, "rcc", file)
5050
if err != nil {
5151
os.Exit(1)
5252
}
@@ -164,14 +164,14 @@ func saveCode() {
164164
code += cp.ExportAll()
165165
savefile := fmt.Sprintf("%s_rc.go", filep)
166166
err := ioutil.WriteFile(savefile, []byte(code), mod)
167-
qtrt.ErrPrint(err, savefile)
167+
miscutil.ErrPrint(err, savefile)
168168

169169
// gofmt the code
170170
gofmtPath, err := exec.LookPath("gofmt")
171-
qtrt.ErrPrint(err)
171+
miscutil.ErrPrint(err)
172172
cmd := exec.Command(gofmtPath, "-w", savefile)
173173
err = cmd.Run()
174-
qtrt.ErrPrint(err, cmd)
174+
miscutil.ErrPrint(err, cmd)
175175
}
176176

177177
func colon2uline(s string) string { return strings.Replace(s, ":", "_", -1) }

cmd/go-rcc/main.go

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"path"
1010
"strings"
1111

12-
"github.com/kitech/qt.go/qtrt"
1312
"github.com/kitech/qt.go/toolutil"
1413
)
1514

@@ -32,11 +31,11 @@ func main() {
3231
log.SetFlags(log.Flags() | log.Lshortfile)
3332
file = os.Args[1]
3433
filep = path.Base(file)[0:strings.LastIndex(path.Base(file), ".")]
35-
filep = qtrt.IfElseStr(path.Dir(file) == "", filep, path.Dir(file)+"/"+filep)
34+
filep = IfElseStr(path.Dir(file) == "", filep, path.Dir(file)+"/"+filep)
3635
log.Println(file, filep)
3736

3837
scc, err := toolutil.RunCmdOut("rcc", file)
39-
qtrt.ErrPrint(err, "rcc", file)
38+
ErrPrint(err, "rcc", file)
4039
if err != nil {
4140
os.Exit(1)
4241
}
@@ -106,8 +105,11 @@ func main() {
106105
}
107106

108107
func transformMember(line string) {
108+
109109
home := os.Getenv("HOME")
110-
line = strings.Replace(line, home, "/home/me", -1)
110+
if home != "" {
111+
line = strings.Replace(line, home, "/home/me", -1)
112+
}
111113
cp.APf("body", line)
112114
}
113115

@@ -145,15 +147,49 @@ func saveCode() {
145147
code += cp.ExportAll()
146148
savefile := fmt.Sprintf("%s_rc.go", filep)
147149
err := ioutil.WriteFile(savefile, []byte(code), mod)
148-
qtrt.ErrPrint(err, savefile)
150+
ErrPrint(err, savefile)
149151

150152
// gofmt the code
151153
gofmtPath, err := exec.LookPath("gofmt")
152-
qtrt.ErrPrint(err)
154+
ErrPrint(err)
153155
cmd := exec.Command(gofmtPath, "-w", savefile)
154156
err = cmd.Run()
155-
qtrt.ErrPrint(err, cmd)
157+
ErrPrint(err, cmd)
156158
}
157159

158160
func colon2uline(s string) string { return strings.Replace(s, ":", "_", -1) }
159161
func untitle(s string) string { return strings.ToLower(s[0:1]) + s[1:] }
162+
163+
///
164+
func printq(v interface{}, args ...interface{}) string {
165+
msg := fmt.Sprintf("%+v", v)
166+
for _, arg := range args {
167+
msg += fmt.Sprintf(" %+v", arg)
168+
}
169+
return msg
170+
}
171+
172+
func ErrPrint(err error, args ...interface{}) error {
173+
if err != nil {
174+
log.Output(2, printq(err, args...))
175+
}
176+
return err
177+
}
178+
179+
// TODO 要是侯选可以惰性求值就好了,否则在只能一个求值的场景则会有问题
180+
// 简单的三元去处模拟函数
181+
func IfElse(q bool, tv interface{}, fv interface{}) interface{} {
182+
if q == true {
183+
return tv
184+
} else {
185+
return fv
186+
}
187+
}
188+
189+
func IfElseInt(q bool, tv int, fv int) int {
190+
return IfElse(q, tv, fv).(int)
191+
}
192+
193+
func IfElseStr(q bool, tv string, fv string) string {
194+
return IfElse(q, tv, fv).(string)
195+
}

cmd/go-uic/main.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"regexp"
1111
"strings"
1212

13-
"github.com/kitech/qt.go/qtrt"
13+
"github.com/kitech/qt.go/miscutil"
1414
"github.com/kitech/qt.go/toolutil"
1515
)
1616

@@ -38,11 +38,11 @@ func main() {
3838
file = os.Args[1]
3939

4040
filep = "ui_" + path.Base(file)[0:strings.LastIndex(path.Base(file), ".")]
41-
filep = qtrt.IfElseStr(path.Dir(file) == "", filep, path.Dir(file)+"/"+filep)
41+
filep = miscutil.IfElseStr(path.Dir(file) == "", filep, path.Dir(file)+"/"+filep)
4242
log.Println(file, filep)
4343

4444
scc, err := toolutil.RunCmdOut("uic", "-g", "cpp", file)
45-
qtrt.ErrPrint(err)
45+
miscutil.ErrPrint(err)
4646
if err != nil {
4747
os.Exit(1)
4848
}
@@ -179,6 +179,7 @@ func onSetupUi(line string) {
179179
} else {
180180
reg1 := regexp.MustCompile(`(.*) = new (Q.+)\(([0-9A-Za-z_]*)?\);`)
181181
reg2 := regexp.MustCompile(`(.*)->setObjectName\(QStringLiteral\((.+)\)\);`)
182+
reg2_1 := regexp.MustCompile(`(.*)->setObjectName\(QString::fromUtf8\((.+)\)\)`)
182183
reg3 := regexp.MustCompile(`(.*)->(set.+Size)\(QSize\((.+)\)\);`)
183184
reg4 := regexp.MustCompile(`([^->]+)[->.]+set([^(]+)\((.+)\);`)
184185
reg5 := regexp.MustCompile(`([^->]+)[->.]+(add[^(]+)\((.+)\);`)
@@ -237,6 +238,13 @@ func onSetupUi(line string) {
237238
log.Println(mats)
238239
cp.APf("setupUi", "this.%s.SetObjectName(%s) // 112",
239240
strings.Title(mats[0][1]), strings.Title(mats[0][2]))
241+
} else if reg2_1.MatchString(line) {
242+
log.Println("reg2_1")
243+
mats := reg2_1.FindAllStringSubmatch(line, -1)
244+
log.Println(mats)
245+
log.Println(strings.Title(mats[0][2]))
246+
cp.APf("setupUi", "this.%s.SetObjectName(%s) // 112",
247+
strings.Title(mats[0][1]), strings.Title(mats[0][2]))
240248
} else if reg3.MatchString(line) {
241249
mats := reg3.FindAllStringSubmatch(line, -1)
242250
log.Println(mats)
@@ -498,14 +506,14 @@ func saveCode() {
498506
code += cp.ExportAll()
499507
savefile := fmt.Sprintf("%s.go", filep)
500508
err := ioutil.WriteFile(savefile, []byte(code), mod)
501-
qtrt.ErrPrint(err, savefile)
509+
miscutil.ErrPrint(err, savefile)
502510

503511
// gofmt the code
504512
gofmtPath, err := exec.LookPath("gofmt")
505-
qtrt.ErrPrint(err)
513+
miscutil.ErrPrint(err)
506514
cmd := exec.Command(gofmtPath, []string{"-w", savefile}...)
507515
err = cmd.Run()
508-
qtrt.ErrPrint(err, cmd)
516+
miscutil.ErrPrint(err, cmd)
509517
}
510518

511519
func colon2uline(s string) string { return strings.Replace(s, ":", "_", -1) }

docs/name-conversion.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
2+
C++ and Go have different name specific.
3+
4+
Although make effort similar to origin C++ name, but still some converts:
5+
6+
### Qt components
7+
8+
All Qt component names are converted to go package names with lowercase:
9+
10+
* QtCore => qtcore.
11+
* QtGui => qtgui.
12+
* QtWidgets => qtwidgets.
13+
14+
### class name
15+
16+
class name is the same.
17+
18+
### method name:
19+
* title the first charactor: `show() => Show()`
20+
21+
* overloaded methods
22+
23+
According to overload index, add a number suffix. The first `0` is omitted.
24+
25+
`arg() => Arg1()`
26+
27+
* has default arguments methods
28+
29+
First, qt.go use `pn` where `n` is a number suffix.
30+
And the `n` is omitted default arguments count. The first `0` is omitted.
31+
32+
For C++:
33+
34+
`void setShortcutEnabled(int id, bool enable = true);`
35+
36+
For Go, there will be two methods with different `pn` suffix:
37+
38+
`func (this *QWidget) SetShortcutEnabled(id int, enable bool)`
39+
`func (this *QWidget) SetShortcutEnabledp(id int)`
40+
41+
### static methods
42+
43+
qt.go use `class_method` as the full method name.
44+
45+
For convenient, the class instance has a `method` method. Such as:
46+
47+
```
48+
func (this *QCoreApplication) Flush()
49+
func QCoreApplication_Flush()
50+
```
51+
52+
### protected methods
53+
54+
qt.go use `Inherit` prefix with protected method name as override method.
55+
56+
Original method has sementic means: call parent corresponding method.
57+
58+
```
59+
func (this *QWidget) InheritEvent(func(evt *qtcore.Event) {
60+
this.Event(evt)
61+
})
62+
```
63+
64+
### class constructor
65+
66+
Add `New` prefix to class name: `NewQPushButton(...)`
67+
68+
### protected methods
69+
70+
Add `Inherit` prefix to method name: `InheritMouseMoveEvent(...)`
71+
72+
### class internal enums
73+
74+
qt.go use `class__enumname` as the full name.
75+
76+
For C++:
77+
78+
`QWidget::DrawWindowBackground`
79+
`QWidget::DrawChildren`
80+
81+
For Go:
82+
83+
`const QWidget__DrawWindowBackground = 1`
84+
`const QWidget__DrawChildren = 2`
85+
86+
### qt namespace enums
87+
88+
qt.go use `namespace__enumname` as the full name:
89+
90+
For C++:
91+
92+
`Qt::black`
93+
`Qt::white`
94+
95+
For Go:
96+
97+
`const Qt__black = 2`
98+
`const Qt__white = 3`
99+
100+
### QString
101+
102+
Except `QString` class wrapper itself, all other `QString` are replaced with go `string`.
103+
104+
### QObject and subclass type arguments
105+
106+
Since it can passby all subclass type, so qt.go use interface type to emulate this feature.
107+
108+
For every Qt class, there is a corresponding interface: `QWidget_ITF`
109+
110+
Such one can passby any `QWidget` subclass instance just like in C++.
111+

examples/eg00.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ package main
55
#include <stdint.h>
66
*/
77
import "C"
8-
import "qtcore"
8+
import "github.com/kitech/qt.go/qtcore"
99
import "fmt"
1010
import "reflect"
1111
import "time"
12-
import "qtrt"
12+
import "github.com/kitech/qt.go/qtrt"
1313

1414
func testResolve(args ...interface{}) {
1515
var vtys = make(map[int32]map[int32]reflect.Type)

0 commit comments

Comments
 (0)