Args.qml 17 KB

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