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