添加duilib xml布局格式生成c++控件绑定的代码
parent
04eaad4b99
commit
4a81fb706f
|
@ -107,8 +107,15 @@ func RangeWidget(p *Widget ) string{
|
|||
return ret
|
||||
}
|
||||
|
||||
type Controller struct{
|
||||
Type string
|
||||
Name string
|
||||
Parent *Controller
|
||||
}
|
||||
|
||||
func GetUifrom(path io.Reader) string{
|
||||
list := list.List{}
|
||||
|
||||
decoder := xml.NewDecoder(path)
|
||||
for {
|
||||
token, _ := decoder.Token()
|
||||
|
@ -117,24 +124,25 @@ func GetUifrom(path io.Reader) string{
|
|||
}
|
||||
switch startElement := token.(type) {
|
||||
case xml.StartElement:
|
||||
if(startElement.Name.Local == "widget"){
|
||||
if(list.Len() == 0){
|
||||
ins := new(Widget)
|
||||
ins.Class = getAttr("class",startElement.Attr)
|
||||
ins.Name = getAttr("name",startElement.Attr)
|
||||
ins.Parent = nil
|
||||
list.PushBack(ins)
|
||||
}else{
|
||||
ins := new(Widget)
|
||||
ins.Class = getAttr("class",startElement.Attr)
|
||||
ins.Name = getAttr("name",startElement.Attr)
|
||||
ins.Parent = list.Back().Value.(*Widget)
|
||||
list.Back().Value.(*Widget).Childs.PushBack(ins)
|
||||
list.PushBack(ins)
|
||||
}
|
||||
log.Print(0,startElement.Name)
|
||||
if(list.Len() == 0){
|
||||
ins := new(Controller)
|
||||
ins.Name = getAttr("name",startElement.Attr)
|
||||
log.Print(ins.Name)
|
||||
ins.Parent = nil
|
||||
list.PushBack(ins)
|
||||
}else{
|
||||
ins := new(Controller)
|
||||
ins.Type = startElement.Name.Local
|
||||
ins.Name = getAttr("name",startElement.Attr)
|
||||
log.Print(ins.Name)
|
||||
ins.Parent = list.Back().Value.(*Controller)
|
||||
list.Back().Value.(*Widget).Childs.PushBack(ins)
|
||||
list.PushBack(ins)
|
||||
}
|
||||
break
|
||||
case xml.EndElement:
|
||||
log.Print(1,startElement.Name)
|
||||
if(startElement.Name.Local == "widget"){
|
||||
if(list.Len() > 0){
|
||||
if(list.Back().Value.(*Widget).Parent != nil){
|
||||
|
@ -145,7 +153,6 @@ func GetUifrom(path io.Reader) string{
|
|||
break
|
||||
}
|
||||
}
|
||||
|
||||
p := list.Back().Value.(*Widget)
|
||||
ret := RangeWidget(p)
|
||||
log.Print(ret)
|
||||
|
@ -192,3 +199,19 @@ func (this *OpenApiController) UI2CSS(c *gin.Context) {
|
|||
ret := GetUifrom(file)
|
||||
c.String(200,ret)
|
||||
}
|
||||
|
||||
|
||||
func (this *OpenApiController) DuilibXml2Cpp(c *gin.Context) {
|
||||
f, err := c.FormFile("xml") //根据name返回给第一个文件
|
||||
if err != nil {
|
||||
c.String(200,"上传文件错误")
|
||||
return
|
||||
}
|
||||
file,e := f.Open()
|
||||
if nil != e{
|
||||
c.String(200,"上传文件错误")
|
||||
return
|
||||
}
|
||||
ret := GetUifrom(file)
|
||||
c.String(200,ret)
|
||||
}
|
||||
|
|
2
main.go
2
main.go
|
@ -230,8 +230,8 @@ func main() {
|
|||
openapi.POST("/ddl2orm", openapiController.DDL2ORM) // sql ddl转gorm 结构体
|
||||
openapi.POST("/ddl2markdown", openapiController.DDL2Markdown) // sql ddl转markdown 文档
|
||||
openapi.POST("/ui2css", openapiController.UI2CSS) // qt ui文件转css文档
|
||||
openapi.POST("/duilib_xml2cpp", openapiController.DuilibXml2Cpp) // duilib to cpp
|
||||
}
|
||||
|
||||
e := r.Run(":" + strconv.Itoa(config.GetPort()))
|
||||
if nil != e {
|
||||
log.Print(e.Error())
|
||||
|
|
Loading…
Reference in New Issue