mirror of
https://github.com/bluszcz/cutego.git
synced 2024-09-28 21:25:16 +03:00
make qtminimal and qtmoc faster + integrate new examples
This commit is contained in:
parent
f327c7c17e
commit
980a9a09e6
6 changed files with 95 additions and 19 deletions
|
@ -456,6 +456,13 @@ And make sure your Project folder is in your **GOPATH**.
|
|||
-XX:+UseCompressedOops
|
||||
```
|
||||
|
||||
* Neovim
|
||||
|
||||
Update your neocomplete.vim
|
||||
```
|
||||
let g:neocomplete#skip_auto_completion_time = ""
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
1. Create a project folder `[GOPATH]/src/qtExample`
|
||||
|
|
|
@ -37,12 +37,13 @@ func main() {
|
|||
}
|
||||
|
||||
var (
|
||||
imported []string
|
||||
cached []string
|
||||
imported []string
|
||||
cached []string
|
||||
importedPkgMap = make(map[string]bool)
|
||||
)
|
||||
|
||||
var walkFuncImports = func(appPath string, info os.FileInfo, err error) error {
|
||||
if err == nil && !strings.HasPrefix(info.Name(), "moc") && strings.HasSuffix(info.Name(), ".go") && !info.IsDir() {
|
||||
if err == nil && !strings.HasPrefix(info.Name(), "moc") && !strings.HasPrefix(info.Name(), "rcc") && strings.HasSuffix(info.Name(), ".go") && !info.IsDir() {
|
||||
var pFile, errParse = goparser.ParseFile(token.NewFileSet(), appPath, nil, 0)
|
||||
if errParse != nil {
|
||||
utils.Log.WithError(errParse).Panicf("failed to parser file %v", appPath)
|
||||
|
@ -55,6 +56,23 @@ func main() {
|
|||
imported = append(imported, appPath)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if iPath := strings.Replace(i.Path.Value, "\"", "", -1); iPath != "github.com/therecipe/qt" {
|
||||
var pkg string
|
||||
for _, pkgs := range templater.Libs {
|
||||
if strings.ToLower(pkgs) == strings.TrimPrefix(iPath, "github.com/therecipe/qt/") {
|
||||
pkg = pkgs
|
||||
}
|
||||
}
|
||||
if _, exists := templater.LibDeps[pkg]; exists {
|
||||
importedPkgMap[pkg] = true
|
||||
for _, dep := range templater.LibDeps[pkg] {
|
||||
if _, exists := templater.LibDeps[dep]; exists {
|
||||
importedPkgMap[dep] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -66,8 +84,7 @@ func main() {
|
|||
if err == nil && strings.HasSuffix(info.Name(), ".go") && !info.IsDir() {
|
||||
|
||||
if file := utils.Load(appPath); strings.Contains(file, "github.com/therecipe/qt/") &&
|
||||
!(strings.Contains(file, "github.com/therecipe/qt/androidextras") &&
|
||||
strings.Count(file, "github.com/therecipe/qt/") == 1) {
|
||||
!(strings.Contains(file, "github.com/therecipe/qt/androidextras") && strings.Count(file, "github.com/therecipe/qt/") == 1) {
|
||||
cached = append(cached, file)
|
||||
}
|
||||
}
|
||||
|
@ -85,7 +102,15 @@ func main() {
|
|||
filepath.Walk(imp, walkFunc)
|
||||
}
|
||||
|
||||
for _, module := range templater.GetLibs() {
|
||||
var importedPkgs []string
|
||||
for _, dep := range templater.Libs {
|
||||
if _, exist := importedPkgMap[dep]; exist {
|
||||
importedPkgs = append(importedPkgs, dep)
|
||||
}
|
||||
}
|
||||
|
||||
for _, module := range importedPkgs {
|
||||
utils.Log.Debugf("loading qt/%v", strings.ToLower(module))
|
||||
if _, err := parser.GetModule(module); err != nil {
|
||||
utils.Log.WithError(err).Errorf("failed to load qt/%v", strings.ToLower(module))
|
||||
}
|
||||
|
@ -156,8 +181,9 @@ func main() {
|
|||
}
|
||||
|
||||
templater.Minimal = true
|
||||
for _, module := range templater.GetLibs() {
|
||||
templater.GenModule(module)
|
||||
for _, module := range importedPkgs {
|
||||
utils.Log.Debugf("generating minimal qt/%v", strings.ToLower(module))
|
||||
templater.GenModule(strings.Title(module))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,10 +22,7 @@ func init() {
|
|||
templater.UsedFromMoc = true
|
||||
}
|
||||
|
||||
var (
|
||||
modulesInited bool
|
||||
tmpFiles = make([]string, 0)
|
||||
)
|
||||
var tmpFiles = make([]string, 0)
|
||||
|
||||
func main() {
|
||||
var (
|
||||
|
@ -45,7 +42,6 @@ func main() {
|
|||
cleanup = len(os.Args) == 3
|
||||
}
|
||||
}
|
||||
|
||||
if !filepath.IsAbs(appPath) {
|
||||
appPath = utils.GetAbsPath(appPath)
|
||||
}
|
||||
|
@ -183,11 +179,50 @@ func moc(appPath string) {
|
|||
|
||||
if len(module.Namespace.Classes) > 0 {
|
||||
|
||||
if !modulesInited {
|
||||
for _, module := range templater.GetLibs() {
|
||||
parser.GetModule(module)
|
||||
var importedPkgMap = make(map[string]bool)
|
||||
|
||||
var walkFuncImports = func(appPath string, info os.FileInfo, err error) error {
|
||||
if err == nil && !strings.HasPrefix(info.Name(), "moc") && !strings.HasPrefix(info.Name(), "rcc") && strings.HasSuffix(info.Name(), ".go") && !info.IsDir() {
|
||||
var pFile, errParse = goparser.ParseFile(token.NewFileSet(), appPath, nil, 0)
|
||||
if errParse != nil {
|
||||
utils.Log.WithError(errParse).Panicf("failed to parser file %v", appPath)
|
||||
} else {
|
||||
for _, i := range pFile.Imports {
|
||||
if iPath := strings.Replace(i.Path.Value, "\"", "", -1); iPath != "github.com/therecipe/qt" {
|
||||
var pkg string
|
||||
for _, pkgs := range templater.Libs {
|
||||
if strings.ToLower(pkgs) == strings.TrimPrefix(iPath, "github.com/therecipe/qt/") {
|
||||
pkg = pkgs
|
||||
}
|
||||
}
|
||||
if _, exists := templater.LibDeps[pkg]; exists {
|
||||
importedPkgMap[pkg] = true
|
||||
for _, dep := range templater.LibDeps[pkg] {
|
||||
if _, exists := templater.LibDeps[dep]; exists {
|
||||
importedPkgMap[dep] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
filepath.Walk(appPath, walkFuncImports)
|
||||
|
||||
var importedPkgs []string
|
||||
for _, dep := range templater.Libs {
|
||||
if _, exist := importedPkgMap[dep]; exist {
|
||||
importedPkgs = append(importedPkgs, dep)
|
||||
}
|
||||
}
|
||||
|
||||
for _, module := range importedPkgs {
|
||||
utils.Log.Debugf("loading qt/%v", strings.ToLower(module))
|
||||
if _, err := parser.GetModule(strings.ToLower(module)); err != nil {
|
||||
utils.Log.WithError(err).Errorf("failed to load qt/%v", strings.ToLower(module))
|
||||
}
|
||||
modulesInited = true
|
||||
}
|
||||
|
||||
module.Prepare()
|
||||
|
@ -242,6 +277,7 @@ func moc(appPath string) {
|
|||
}
|
||||
|
||||
if classCount > 0 {
|
||||
utils.Log.Debugf("generating %v moc", parser.MOC)
|
||||
utils.SaveBytes(filepath.Join(appPath, "moc.cpp"), templater.CppTemplate(parser.MOC))
|
||||
utils.SaveBytes(filepath.Join(appPath, "moc.h"), templater.HTemplate(parser.MOC))
|
||||
utils.SaveBytes(filepath.Join(appPath, "moc.go"), templater.GoTemplate(parser.MOC, false))
|
||||
|
@ -289,6 +325,8 @@ func moc(appPath string) {
|
|||
templater.CopyCgo(parser.MOC)
|
||||
}
|
||||
}
|
||||
|
||||
parser.ClassMap = make(map[string]*parser.Class)
|
||||
}
|
||||
|
||||
func getParameters(tag string) []*parser.Parameter {
|
||||
|
|
|
@ -14,6 +14,7 @@ func test(buildTarget string) {
|
|||
|
||||
//TODO: cleanup
|
||||
for _, example := range []string{filepath.Join("widgets", "line_edits"), filepath.Join("widgets", "video_player"), filepath.Join("widgets", "graphicsscene"), filepath.Join("widgets", "dropsite"), filepath.Join("widgets", "table"),
|
||||
filepath.Join("widgets", "treeview", "treeview_dual"), filepath.Join("widgets", "treeview", "treeview_filelist"),
|
||||
filepath.Join("quick", "bridge"), filepath.Join("quick", "bridge2"), filepath.Join("quick", "calc"), filepath.Join("quick", "dialog"), filepath.Join("quick", "sailfish"), filepath.Join("quick", "translate"), filepath.Join("quick", "view"),
|
||||
filepath.Join("qml", "application"), filepath.Join("qml", "material"), filepath.Join("qml", "prop"),
|
||||
filepath.Join("uitools", "calculator")} {
|
||||
|
|
4
internal/examples/widgets/treeview/treeview_dual/treeview_dual.go
Normal file → Executable file
4
internal/examples/widgets/treeview/treeview_dual/treeview_dual.go
Normal file → Executable file
|
@ -1,3 +1,5 @@
|
|||
//author: https://github.com/5k3105
|
||||
|
||||
// Extended example for two treeviews and changed the listview to a treeview that only shows files.
|
||||
// This way you can now see file details, unlike previous example.
|
||||
|
||||
|
@ -43,7 +45,7 @@ func main() {
|
|||
SetupUi()
|
||||
|
||||
widgets.QApplication_SetStyle2("fusion")
|
||||
ap.Window.ShowMaximized()
|
||||
ap.Window.Show()
|
||||
widgets.QApplication_Exec()
|
||||
}
|
||||
|
||||
|
|
4
internal/examples/widgets/treeview/treeview_filelist/treeview_filelist.go
Normal file → Executable file
4
internal/examples/widgets/treeview/treeview_filelist/treeview_filelist.go
Normal file → Executable file
|
@ -1,3 +1,5 @@
|
|||
//author: https://github.com/5k3105
|
||||
|
||||
// This is a filesystem treeview with a listview for individual files on the right.
|
||||
// Approx translation from: http://www.bogotobogo.com/Qt/Qt5_QTreeView_QFileSystemModel_ModelView_MVC.php
|
||||
|
||||
|
@ -48,7 +50,7 @@ func main() {
|
|||
ap.Statusbar.ShowMessage("Application Path: "+core.QCoreApplication_ApplicationDirPath(), 0)
|
||||
|
||||
widgets.QApplication_SetStyle2("fusion")
|
||||
ap.Window.ShowMaximized()
|
||||
ap.Window.Show()
|
||||
widgets.QApplication_Exec()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue