diff --git a/cmd/miqt-uic/ui2go.go b/cmd/miqt-uic/ui2go.go index b2827441..49e98a41 100644 --- a/cmd/miqt-uic/ui2go.go +++ b/cmd/miqt-uic/ui2go.go @@ -211,15 +211,29 @@ func renderProperties(properties []UiProperty, ret *strings.Builder, targetName, return nil } -func generateWidget(w UiWidget, parentName string, parentClass string) (string, error) { +func generateSetObjectName(target string, objectName string, useQt6 bool) string { + if useQt6 { + // return `ui.` + target + `.SetObjectName(*qt.NewQAnyStringView3(` + strconv.Quote(objectName) + "))\n" + spn := target + "__objectName" + ret := spn + `:= qt.NewQAnyStringView3(` + strconv.Quote(objectName) + ")\n" + ret += `ui.` + target + ".SetObjectName(*" + spn + ")\n" + ret += spn + ".Delete() // setter copied value\n" + return ret + + } else { + return `ui.` + target + `.SetObjectName(` + strconv.Quote(objectName) + ")\n" + } +} + +func generateWidget(w UiWidget, parentName string, parentClass string, useQt6 bool) (string, error) { ret := strings.Builder{} ctor := "New" + w.Class - ret.WriteString(` - ui.` + w.Name + ` = qt.` + ctor + `(` + qwidgetName(parentName, parentClass) + `) - ui.` + w.Name + `.SetObjectName(` + strconv.Quote(w.Name) + `) - `) + ret.WriteString(`ui.` + w.Name + ` = qt.` + ctor + `(` + qwidgetName(parentName, parentClass) + ")\n") + + ret.WriteString(generateSetObjectName(w.Name, w.Name, useQt6)) + if RootWindowName == "" { RootWindowName = `ui.` + w.Name } @@ -257,10 +271,8 @@ func generateWidget(w UiWidget, parentName string, parentClass string) (string, if w.Layout != nil { ctor := "New" + w.Layout.Class - ret.WriteString(` - ui.` + w.Layout.Name + ` = qt.` + ctor + `(` + qwidgetName("ui."+w.Name, w.Class) + `) - ui.` + w.Layout.Name + `.SetObjectName(` + strconv.Quote(w.Layout.Name) + `) - `) + ret.WriteString(`ui.` + w.Layout.Name + ` = qt.` + ctor + `(` + qwidgetName("ui."+w.Name, w.Class) + ")\n") + ret.WriteString(generateSetObjectName(w.Layout.Name, w.Layout.Name, useQt6)) // Layout->Properties @@ -284,7 +296,7 @@ func generateWidget(w UiWidget, parentName string, parentClass string) (string, // Layout items have the parent as the real QWidget parent and are // separately assigned to the layout afterwards - nest, err := generateWidget(*child.Widget, `ui.`+w.Name, w.Class) + nest, err := generateWidget(*child.Widget, `ui.`+w.Name, w.Class, useQt6) if err != nil { return "", fmt.Errorf(w.Name+"/Layout/Item[%d]: %w", i, err) } @@ -354,10 +366,8 @@ func generateWidget(w UiWidget, parentName string, parentClass string) (string, // Actions for _, a := range w.Actions { - ret.WriteString(` - ui.` + a.Name + ` = qt.NewQAction(` + parentName + `) - ui.` + a.Name + `.SetObjectName(` + strconv.Quote(a.Name) + `) - `) + ret.WriteString(`ui.` + a.Name + ` = qt.NewQAction(` + parentName + ")\n") + ret.WriteString(generateSetObjectName(a.Name, a.Name, useQt6)) // QActions are translated in the parent window's context if prop, ok := propertyByName(a.Properties, "text"); ok { @@ -414,7 +424,7 @@ func generateWidget(w UiWidget, parentName string, parentClass string) (string, ) for i, child := range w.Widgets { - nest, err := generateWidget(child, `ui.`+w.Name, w.Class) + nest, err := generateWidget(child, `ui.`+w.Name, w.Class, useQt6) if err != nil { return "", fmt.Errorf(w.Name+"/Widgets[%d]: %w", i, err) } @@ -543,7 +553,7 @@ func New` + u.Class + `Ui() *` + u.Class + `Ui { ui := &` + u.Class + `Ui{} `) - nest, err := generateWidget(u.Widget, "", "") + nest, err := generateWidget(u.Widget, "", "", useQt6) if err != nil { return nil, err }