Args.qml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. import QtQuick
  2. import QtQuick.Controls
  3. import FluentUI
  4. import QtQuick.Layouts
  5. import "./ModelParse.js" as MP
  6. Item {
  7. property string argsData: ""
  8. property string valueData: ""
  9. signal updataData
  10. FluScrollablePage{
  11. id: contentScrollable
  12. width: 700
  13. height: parent.height
  14. spacing: 12
  15. anchors.horizontalCenter: parent.horizontalCenter
  16. }
  17. Component{
  18. id: group_item
  19. FluExpander{
  20. id: expander
  21. property string groupName: ""
  22. property string groupTitle: ""
  23. property var argumentValue: {""}
  24. headerText: qsTr(groupTitle) +" "+ qsTr("Setting")
  25. width: contentScrollable.width
  26. contentHeight: group_column.height
  27. Column{
  28. id: group_column
  29. spacing: 4
  30. clip: true
  31. anchors{
  32. top: parent.top
  33. topMargin: 12
  34. left: parent.left
  35. leftMargin: 15
  36. right: parent.right
  37. rightMargin: 15
  38. bottomMargin: 12
  39. }
  40. }
  41. onArgumentValueChanged: {
  42. for(let index in argumentValue){
  43. const arg = argumentValue[index]
  44. createItem(arg)
  45. // expander.contentHeight = group_column.height
  46. }
  47. }
  48. /**
  49. * 创建某个具体的字段
  50. * @param {Object} arg 打包的变量大概长这样的:
  51. {
  52. "name": "handle_error",
  53. "title": "Handle Error",
  54. "description": "none",
  55. "default": false,
  56. "type": "boolean",
  57. "value": false
  58. }
  59. * @returns {Object}
  60. */
  61. function createItem(arg){
  62. if(arg === null){
  63. console.error("it is emtry when create arg")
  64. return
  65. }
  66. var object = null
  67. if(arg.type === "string"){
  68. object = string_item.createObject(group_column)
  69. if(object === null){
  70. console.error("can not create component string_item", arg.title)
  71. return
  72. }
  73. }
  74. else if(arg.type === "integer"){
  75. object = int_item.createObject(group_column)
  76. if(object === null){
  77. console.error("can not create component integer_item", arg.title)
  78. return
  79. }
  80. }
  81. else if(arg.type === "number"){
  82. object = float_item.createObject(group_column)
  83. if(object === null){
  84. console.error("can not create component float_item", arg.title)
  85. return
  86. }
  87. }
  88. else if(arg.type === "boolean"){
  89. object = bool_item.createObject(group_column)
  90. if(object === null){
  91. console.error("can not create component boolean_item", arg.title)
  92. return
  93. }
  94. }
  95. else if(arg.type === "enum"){
  96. object = enum_item.createObject(group_column)
  97. if(object === null){
  98. console.error("can not create component enum_item", arg.title)
  99. return
  100. }
  101. }
  102. if(object === null){
  103. console.error("can not create component ", arg.title)
  104. return
  105. }
  106. object.modelData = arg
  107. group_column.data.push(object)
  108. }
  109. }
  110. }
  111. Component{
  112. id: string_item
  113. Item{
  114. id: stringItem
  115. property var modelData: null
  116. width: parent.width
  117. implicitHeight: string_title.implicitHeight + string_description.implicitHeight
  118. Layout.fillHeight: true
  119. FluTextBox{
  120. id: string_text
  121. anchors{
  122. top: parent.top
  123. topMargin: 2
  124. right: parent.right
  125. }
  126. placeholderText: ""
  127. }
  128. FluText{
  129. id: string_title
  130. anchors{
  131. top: parent.top
  132. left: parent.left
  133. right: string_text.left
  134. }
  135. text: ""
  136. font: FluTextStyle.BodyStrong
  137. wrapMode: Text.WrapAnywhere
  138. topPadding: 6
  139. }
  140. FluText{
  141. id: string_description
  142. anchors{
  143. top: string_title.bottom
  144. left: parent.left
  145. }
  146. width: string_title.width
  147. text: ""
  148. font: FluTextStyle.Caption
  149. wrapMode: Text.WrapAnywhere
  150. topPadding: 6
  151. rightPadding: 6
  152. }
  153. onModelDataChanged: {
  154. if(modelData === null){
  155. console.error("string model is null")
  156. return
  157. }
  158. string_text.text = modelData.value
  159. string_text.placeholderText = modelData["default"]
  160. string_title.text = modelData.title
  161. if( typeof modelData.description === 'undefined'){
  162. return
  163. }
  164. string_description.text = modelData.description
  165. }
  166. }
  167. }
  168. Component{
  169. id: int_item
  170. Item{
  171. id: itemArg
  172. property var modelData: null
  173. width: parent.width
  174. implicitHeight: itemArg_title.implicitHeight + itemArg_description.implicitHeight
  175. Layout.fillHeight: true
  176. FluTextBox{
  177. id: itemArg_text
  178. anchors{
  179. top: parent.top
  180. topMargin: 2
  181. right: parent.right
  182. }
  183. placeholderText: ""
  184. }
  185. FluText{
  186. id: itemArg_title
  187. anchors{
  188. top: parent.top
  189. left: parent.left
  190. right: itemArg_text.left
  191. }
  192. text: ""
  193. font: FluTextStyle.BodyStrong
  194. wrapMode: Text.WrapAnywhere
  195. topPadding: 6
  196. }
  197. FluText{
  198. id: itemArg_description
  199. anchors{
  200. top: itemArg_title.bottom
  201. left: parent.left
  202. }
  203. width: itemArg_title.width
  204. text: ""
  205. font: FluTextStyle.Caption
  206. wrapMode: Text.WrapAnywhere
  207. topPadding: 6
  208. rightPadding: 6
  209. }
  210. onModelDataChanged: {
  211. if(modelData === null){
  212. console.error("int model is null")
  213. return
  214. }
  215. itemArg_text.text = modelData.value
  216. itemArg_text.placeholderText = modelData["default"]
  217. itemArg_title.text = modelData.title
  218. if( typeof modelData.description === 'undefined'){
  219. return
  220. }
  221. itemArg_description.text = modelData.description
  222. }
  223. }
  224. }
  225. Component{
  226. id: float_item
  227. Item{
  228. id: itemArg
  229. property var modelData: null
  230. width: parent.width
  231. implicitHeight: itemArg_title.implicitHeight + itemArg_description.implicitHeight
  232. Layout.fillHeight: true
  233. FluTextBox{
  234. id: itemArg_text
  235. anchors{
  236. top: parent.top
  237. topMargin: 2
  238. right: parent.right
  239. }
  240. placeholderText: ""
  241. }
  242. FluText{
  243. id: itemArg_title
  244. anchors{
  245. top: parent.top
  246. left: parent.left
  247. right: itemArg_text.left
  248. }
  249. text: ""
  250. font: FluTextStyle.BodyStrong
  251. wrapMode: Text.WrapAnywhere
  252. topPadding: 6
  253. }
  254. FluText{
  255. id: itemArg_description
  256. anchors{
  257. top: itemArg_title.bottom
  258. left: parent.left
  259. }
  260. width: itemArg_title.width
  261. text: ""
  262. font: FluTextStyle.Caption
  263. wrapMode: Text.WrapAnywhere
  264. topPadding: 6
  265. rightPadding: 6
  266. }
  267. onModelDataChanged: {
  268. if(modelData === null){
  269. console.error("float model is null")
  270. return
  271. }
  272. itemArg_text.text = modelData.value
  273. itemArg_text.placeholderText = modelData["default"]
  274. itemArg_title.text = modelData.title
  275. if( typeof modelData.description === 'undefined'){
  276. return
  277. }
  278. itemArg_description.text = modelData.description
  279. }
  280. }
  281. }
  282. Component{
  283. id: bool_item
  284. Item{
  285. id: itemArg
  286. property var modelData: null
  287. width: parent.width
  288. implicitHeight: itemArg_title.implicitHeight + itemArg_description.implicitHeight
  289. Layout.fillHeight: true
  290. FluCheckBox{
  291. id: itemArg_text
  292. anchors{
  293. top: parent.top
  294. topMargin: 2
  295. right: parent.right
  296. rightMargin: 300 - 24
  297. }
  298. selected: true
  299. }
  300. FluText{
  301. id: itemArg_title
  302. anchors{
  303. top: parent.top
  304. left: parent.left
  305. right: itemArg_text.left
  306. }
  307. text: ""
  308. font: FluTextStyle.BodyStrong
  309. wrapMode: Text.WrapAnywhere
  310. topPadding: 6
  311. }
  312. FluText{
  313. id: itemArg_description
  314. anchors{
  315. top: itemArg_title.bottom
  316. left: parent.left
  317. }
  318. width: itemArg_title.width
  319. text: ""
  320. font: FluTextStyle.Caption
  321. wrapMode: Text.WrapAnywhere
  322. topPadding: 6
  323. rightPadding: 6
  324. }
  325. onModelDataChanged: {
  326. if(modelData === null){
  327. console.error("bool model is null")
  328. return
  329. }
  330. itemArg_text.selected = modelData.value
  331. itemArg_title.text = modelData.title
  332. if( typeof modelData.description === 'undefined'){
  333. return
  334. }
  335. itemArg_description.text = modelData.description
  336. }
  337. }
  338. }
  339. Component{
  340. id: enum_item
  341. Item{
  342. id: itemArg
  343. property var modelData: null
  344. width: parent.width
  345. implicitHeight: itemArg_title.implicitHeight + itemArg_description.implicitHeight
  346. Layout.fillHeight: true
  347. FComboBox{
  348. id: itemArg_text
  349. width: 300
  350. anchors{
  351. top: parent.top
  352. topMargin: 2
  353. right: parent.right
  354. }
  355. model: ["0", "1", "2"]
  356. }
  357. FluText{
  358. id: itemArg_title
  359. anchors{
  360. top: parent.top
  361. left: parent.left
  362. right: itemArg_text.left
  363. }
  364. text: ""
  365. font: FluTextStyle.BodyStrong
  366. wrapMode: Text.WrapAnywhere
  367. topPadding: 6
  368. }
  369. FluText{
  370. id: itemArg_description
  371. anchors{
  372. top: itemArg_title.bottom
  373. left: parent.left
  374. }
  375. width: itemArg_title.width
  376. text: ""
  377. font: FluTextStyle.Caption
  378. wrapMode: Text.WrapAnywhere
  379. topPadding: 6
  380. rightPadding: 6
  381. }
  382. onModelDataChanged: {
  383. if(modelData === null){
  384. console.error("enum model is null")
  385. return
  386. }
  387. itemArg_text.model = modelData.options
  388. itemArg_text.show(modelData.value)
  389. itemArg_title.text = modelData.title
  390. if( typeof modelData.description === 'undefined'){
  391. return
  392. }
  393. itemArg_description.text = modelData.description
  394. }
  395. }
  396. }
  397. onArgsDataChanged: {
  398. }
  399. onValueDataChanged: {
  400. }
  401. onUpdataData: {
  402. if(argsData === ""){
  403. console.error("解析 顺序出问题了")
  404. return
  405. }
  406. if(valueData === ""){
  407. console.debug("没有数据")
  408. }
  409. var args = JSON.parse(argsData)
  410. var values = JSON.parse(valueData)
  411. var group = MP.parseGroup(args["properties"])
  412. var groups = MP.parseGroups(args["properties"])
  413. for(let task in group){
  414. var argument = MP.parseArgument(args.definitions, group[task])
  415. const groupLetter = groups[group[task]]
  416. var argumentVuale = MP.mergeArgument(argument, values[groupLetter])
  417. // console.debug(JSON.stringify( argumentVuale ))
  418. // console.debug("---------------------------------------------------------------")
  419. createGroup(groupLetter, group[task], argumentVuale)
  420. }
  421. }
  422. /**
  423. * 创建某个组 的显示组件并显示
  424. * @param {Object} groupName 变量的名字 是小写的
  425. * @param {Object} groupTitle 用于向用户显示的名字 大写的
  426. * @param {Object} argumentVaule 总的显示的参数
  427. * @returns {Object}
  428. */
  429. function createGroup(groupName, groupTitle, argumentValue){
  430. if(!groupName){
  431. console.error("no group name")
  432. return
  433. }
  434. if(!groupTitle){
  435. console.error("no group title")
  436. return
  437. }
  438. var object = group_item.createObject()
  439. if(object !== null){
  440. object.groupName = groupName
  441. object.groupTitle = groupTitle
  442. object.argumentValue = argumentValue
  443. contentScrollable.content.push(object)
  444. }
  445. else{
  446. console.error('create group item failed!')
  447. }
  448. }
  449. }