mirror of
https://github.com/mappu/miqt.git
synced 2025-03-11 18:10:22 +00:00
uic: support for spacers
This commit is contained in:
parent
0ba1f0f6fa
commit
2c05d876f9
@ -7,7 +7,10 @@ import (
|
|||||||
type UiLayoutItem struct {
|
type UiLayoutItem struct {
|
||||||
Row *int `xml:"row,attr"`
|
Row *int `xml:"row,attr"`
|
||||||
Column *int `xml:"column,attr"`
|
Column *int `xml:"column,attr"`
|
||||||
Widget UiWidget `xml:"widget"`
|
|
||||||
|
// A layout item either has a widget, or a spacer
|
||||||
|
Widget *UiWidget `xml:"widget"`
|
||||||
|
Spacer *UiSpacer `xml:"spacer"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UiLayout struct {
|
type UiLayout struct {
|
||||||
@ -20,6 +23,11 @@ type UiPropertyContainer struct {
|
|||||||
Properties []UiProperty `xml:"property"`
|
Properties []UiProperty `xml:"property"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UiSpacer struct {
|
||||||
|
Name string `xml:"name,attr"`
|
||||||
|
Properties []UiProperty `xml:"property"`
|
||||||
|
}
|
||||||
|
|
||||||
type UiWidget struct {
|
type UiWidget struct {
|
||||||
Class string `xml:"class,attr"`
|
Class string `xml:"class,attr"`
|
||||||
Name string `xml:"name,attr"`
|
Name string `xml:"name,attr"`
|
||||||
|
@ -7,19 +7,24 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func collectClassNames_Widget(u UiWidget) []string {
|
func collectClassNames_Widget(u *UiWidget) []string {
|
||||||
var ret []string
|
var ret []string
|
||||||
if u.Name != "" {
|
if u.Name != "" {
|
||||||
ret = append(ret, u.Name+" *qt."+u.Class)
|
ret = append(ret, u.Name+" *qt."+u.Class)
|
||||||
}
|
}
|
||||||
for _, w := range u.Widgets {
|
for _, w := range u.Widgets {
|
||||||
ret = append(ret, collectClassNames_Widget(w)...)
|
ret = append(ret, collectClassNames_Widget(&w)...)
|
||||||
}
|
}
|
||||||
if u.Layout != nil {
|
if u.Layout != nil {
|
||||||
ret = append(ret, u.Layout.Name+" *qt."+u.Layout.Class)
|
ret = append(ret, u.Layout.Name+" *qt."+u.Layout.Class)
|
||||||
for _, li := range u.Layout.Items {
|
for _, li := range u.Layout.Items {
|
||||||
|
if li.Widget != nil {
|
||||||
ret = append(ret, collectClassNames_Widget(li.Widget)...)
|
ret = append(ret, collectClassNames_Widget(li.Widget)...)
|
||||||
}
|
}
|
||||||
|
if li.Spacer != nil {
|
||||||
|
ret = append(ret, li.Spacer.Name+" *qt.QSpacerItem")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for _, a := range u.Actions {
|
for _, a := range u.Actions {
|
||||||
ret = append(ret, a.Name+" *qt.QAction")
|
ret = append(ret, a.Name+" *qt.QAction")
|
||||||
@ -127,14 +132,22 @@ func generateWidget(w UiWidget, parentName string, parentClass string) (string,
|
|||||||
ui.` + w.Layout.Name + `.SetObjectName(` + strconv.Quote(w.Layout.Name) + `)
|
ui.` + w.Layout.Name + `.SetObjectName(` + strconv.Quote(w.Layout.Name) + `)
|
||||||
`)
|
`)
|
||||||
|
|
||||||
for _, child := range w.Layout.Items {
|
for i, child := range w.Layout.Items {
|
||||||
|
|
||||||
|
// A layout item is either a widget, or a spacer
|
||||||
|
|
||||||
|
if child.Spacer != nil {
|
||||||
|
ret.WriteString("/* miqt-uic: no handler for spacer */\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
if child.Widget != nil {
|
||||||
|
|
||||||
// Layout items have the parent as the real QWidget parent and are
|
// Layout items have the parent as the real QWidget parent and are
|
||||||
// separately assigned to the layout afterwards
|
// 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)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf(w.Name+": %w", err)
|
return "", fmt.Errorf(w.Name+"/Layout/Item[%d]: %w", i, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.WriteString(nest)
|
ret.WriteString(nest)
|
||||||
@ -180,6 +193,7 @@ func generateWidget(w UiWidget, parentName string, parentClass string) (string,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
|
|
||||||
@ -301,7 +315,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ` + u.Class + `Ui struct {
|
type ` + u.Class + `Ui struct {
|
||||||
` + strings.Join(collectClassNames_Widget(u.Widget), "\n") + `
|
` + strings.Join(collectClassNames_Widget(&u.Widget), "\n") + `
|
||||||
}
|
}
|
||||||
|
|
||||||
// New` + u.Class + `Ui creates all Qt widget classes for ` + u.Class + `.
|
// New` + u.Class + `Ui creates all Qt widget classes for ` + u.Class + `.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user