uic: support more properties, support QToolBar actions

This commit is contained in:
mappu 2024-10-03 17:23:12 +13:00
parent 12b4e083ee
commit 693c9fc0b7
3 changed files with 17 additions and 1 deletions

View File

@ -60,6 +60,7 @@ type UiProperty struct {
Name string `xml:"name,attr"` Name string `xml:"name,attr"`
StringVal *UiString `xml:"string,omitempty"` StringVal *UiString `xml:"string,omitempty"`
NumberVal *string `xml:"number,omitempty"` // Preserve as string literal NumberVal *string `xml:"number,omitempty"` // Preserve as string literal
BoolVal *bool `xml:"bool,omitempty"` // "true" or "false"
EnumVal *string `xml:"enum,omitempty"` EnumVal *string `xml:"enum,omitempty"`
RectVal *UiRect `xml:"rect,omitempty"` RectVal *UiRect `xml:"rect,omitempty"`
} }

View File

@ -87,6 +87,14 @@ func generateWidget(w UiWidget, parentName string, parentClass string) (string,
// "windowTitle", "title", "text" // "windowTitle", "title", "text"
ret.WriteString(`ui.` + w.Name + setterFunc + `(` + generateString(prop.StringVal, parentClass) + ")\n") ret.WriteString(`ui.` + w.Name + setterFunc + `(` + generateString(prop.StringVal, parentClass) + ")\n")
} else if prop.NumberVal != nil {
// "currentIndex"
ret.WriteString(`ui.` + w.Name + setterFunc + `(` + *prop.NumberVal + ")\n")
} else if prop.BoolVal != nil {
// "childrenCollapsible"
ret.WriteString(`ui.` + w.Name + setterFunc + `(` + formatBool(*prop.BoolVal) + ")\n")
} else if prop.EnumVal != nil { } else if prop.EnumVal != nil {
// "frameShape" // "frameShape"
@ -281,7 +289,7 @@ func generateWidget(w UiWidget, parentName string, parentClass string) (string,
// If we are a menubar, then <addaction> refers to top-level QMenu instead of QAction // If we are a menubar, then <addaction> refers to top-level QMenu instead of QAction
if w.Class == "QMenuBar" { if w.Class == "QMenuBar" {
ret.WriteString("ui." + w.Name + ".AddMenu(ui." + a.Name + ")\n") ret.WriteString("ui." + w.Name + ".AddMenu(ui." + a.Name + ")\n")
} else if w.Class == "QMenu" { } else if w.Class == "QMenu" || w.Class == "QToolBar" {
// QMenu has its own .AddAction() implementation that takes plain string // QMenu has its own .AddAction() implementation that takes plain string
// That's convenient, but it shadows the AddAction version that takes a QAction* // That's convenient, but it shadows the AddAction version that takes a QAction*
// We need to use the underlying QWidget.AddAction explicitly // We need to use the underlying QWidget.AddAction explicitly

View File

@ -82,3 +82,10 @@ func propertyByName(check []UiProperty, search string) (UiProperty, bool) {
return UiProperty{}, false return UiProperty{}, false
} }
func formatBool(b bool) string {
if b {
return "true"
}
return "false"
}