Args.qml 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  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 + 20
  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. else if(arg.type === "multi_line"){
  107. object = multi_line_item.createObject(group_column)
  108. if(object === null){
  109. console.error("can not create component multi_line_item", arg.title)
  110. return
  111. }
  112. }
  113. if(object === null){
  114. console.error("can not create component ", arg.title)
  115. return
  116. }
  117. object.modelData = arg
  118. group_column.data.push(object)
  119. }
  120. }
  121. }
  122. Component{
  123. id: string_item
  124. Item{
  125. id: stringItem
  126. property var modelData: null
  127. property bool isDateTime: false
  128. width: parent.width
  129. implicitHeight: string_title.implicitHeight + string_description.implicitHeight
  130. Layout.fillHeight: true
  131. FluTextBox{
  132. id: string_text
  133. anchors{
  134. top: parent.top
  135. topMargin: 2
  136. right: parent.right
  137. }
  138. placeholderText: ""
  139. onEditingFinished: {
  140. if(stringItem.isDateTime){
  141. if(string_text.text === ""){
  142. string_text.text = utils.current_datetime()
  143. }
  144. }
  145. if(set_task(stringItem.parent.parent.parent.groupName, modelData.name, text)){
  146. showSuccess( qsTr("Successful setting"))
  147. }
  148. }
  149. }
  150. FluText{
  151. id: string_title
  152. anchors{
  153. top: parent.top
  154. left: parent.left
  155. right: string_text.left
  156. }
  157. text: ""
  158. font: FluTextStyle.BodyStrong
  159. wrapMode: Text.WrapAnywhere
  160. topPadding: 6
  161. }
  162. FluText{
  163. id: string_description
  164. anchors{
  165. top: string_title.bottom
  166. left: parent.left
  167. }
  168. width: string_title.width
  169. text: ""
  170. font: FluTextStyle.Caption
  171. wrapMode: Text.WordWrap
  172. // textFormat: Text.PlainText
  173. topPadding: 6
  174. rightPadding: 6
  175. }
  176. onModelDataChanged: {
  177. if(modelData === null){
  178. console.error("string model is null")
  179. return
  180. }
  181. string_text.text = modelData.value
  182. string_text.placeholderText = modelData["default"]
  183. if(string_text.placeholderText.startsWith("2023-01-01")){
  184. //判断是不是时间类型的变量2023-01-01
  185. stringItem.isDateTime = true
  186. }
  187. string_title.text = qsTr(modelData.title)
  188. if( typeof modelData.description === 'undefined'){
  189. return
  190. }
  191. string_description.text = qsTr(modelData.description.replace("\\n","\n"))
  192. }
  193. }
  194. }
  195. Component{
  196. id: int_item
  197. Item{
  198. id: itemArg
  199. property var modelData: null
  200. width: parent.width
  201. implicitHeight: itemArg_title.implicitHeight + itemArg_description.implicitHeight
  202. Layout.fillHeight: true
  203. FluTextBox{
  204. id: itemArg_text
  205. anchors{
  206. top: parent.top
  207. topMargin: 2
  208. right: parent.right
  209. }
  210. validator: IntValidator {}
  211. placeholderText: ""
  212. onEditingFinished: {
  213. if(set_task(itemArg.parent.parent.parent.groupName, modelData.name, parseInt(text))){
  214. showSuccess( qsTr("Successful setting"))
  215. }
  216. }
  217. }
  218. FluText{
  219. id: itemArg_title
  220. anchors{
  221. top: parent.top
  222. left: parent.left
  223. right: itemArg_text.left
  224. }
  225. text: ""
  226. font: FluTextStyle.BodyStrong
  227. wrapMode: Text.WrapAnywhere
  228. topPadding: 6
  229. }
  230. FluText{
  231. id: itemArg_description
  232. anchors{
  233. top: itemArg_title.bottom
  234. left: parent.left
  235. }
  236. width: itemArg_title.width
  237. text: ""
  238. font: FluTextStyle.Caption
  239. wrapMode: Text.WrapAnywhere
  240. // textFormat: Text.PlainText
  241. topPadding: 6
  242. rightPadding: 6
  243. }
  244. onModelDataChanged: {
  245. if(modelData === null){
  246. console.error("int model is null")
  247. return
  248. }
  249. itemArg_text.text = modelData.value
  250. itemArg_text.placeholderText = modelData["default"]
  251. itemArg_title.text = qsTr(modelData.title)
  252. if( typeof modelData.description === 'undefined'){
  253. return
  254. }
  255. itemArg_description.text = qsTr(modelData.description)
  256. }
  257. }
  258. }
  259. Component{
  260. id: float_item
  261. Item{
  262. id: itemArg
  263. property var modelData: null
  264. width: parent.width
  265. implicitHeight: itemArg_title.implicitHeight + itemArg_description.implicitHeight
  266. Layout.fillHeight: true
  267. FluTextBox{
  268. id: itemArg_text
  269. anchors{
  270. top: parent.top
  271. topMargin: 2
  272. right: parent.right
  273. }
  274. validator: DoubleValidator {}
  275. placeholderText: ""
  276. onEditingFinished: {
  277. if(set_task(itemArg.parent.parent.parent.groupName, modelData.name, parseFloat(text))){
  278. showSuccess( qsTr("Successful setting"))
  279. }
  280. }
  281. }
  282. FluText{
  283. id: itemArg_title
  284. anchors{
  285. top: parent.top
  286. left: parent.left
  287. right: itemArg_text.left
  288. }
  289. text: ""
  290. font: FluTextStyle.BodyStrong
  291. wrapMode: Text.WrapAnywhere
  292. topPadding: 6
  293. }
  294. FluText{
  295. id: itemArg_description
  296. anchors{
  297. top: itemArg_title.bottom
  298. left: parent.left
  299. }
  300. width: itemArg_title.width
  301. text: ""
  302. font: FluTextStyle.Caption
  303. wrapMode: Text.WrapAnywhere
  304. // textFormat: Text.PlainText
  305. topPadding: 6
  306. rightPadding: 6
  307. }
  308. onModelDataChanged: {
  309. if(modelData === null){
  310. console.error("float model is null")
  311. return
  312. }
  313. itemArg_text.text = modelData.value
  314. itemArg_text.placeholderText = modelData["default"]
  315. itemArg_title.text = qsTr(modelData.title)
  316. if( typeof modelData.description === 'undefined'){
  317. return
  318. }
  319. itemArg_description.text = qsTr(modelData.description)
  320. }
  321. }
  322. }
  323. Component{
  324. id: bool_item
  325. Item{
  326. id: itemArg
  327. property var modelData: null
  328. width: parent.width
  329. implicitHeight: itemArg_title.implicitHeight + itemArg_description.implicitHeight
  330. Layout.fillHeight: true
  331. FluCheckBox{
  332. id: itemArg_text
  333. anchors{
  334. top: parent.top
  335. topMargin: 2
  336. right: parent.right
  337. rightMargin: 300 - 24
  338. }
  339. selected: true
  340. clickFunc: function click_func(){
  341. selected = !selected
  342. if(set_task(itemArg.parent.parent.parent.groupName, modelData.name, selected)){
  343. showSuccess( qsTr("Successful setting"))
  344. }
  345. }
  346. }
  347. FluText{
  348. id: itemArg_title
  349. anchors{
  350. top: parent.top
  351. left: parent.left
  352. right: itemArg_text.left
  353. }
  354. text: ""
  355. font: FluTextStyle.BodyStrong
  356. wrapMode: Text.WrapAnywhere
  357. topPadding: 6
  358. }
  359. FluText{
  360. id: itemArg_description
  361. anchors{
  362. top: itemArg_title.bottom
  363. left: parent.left
  364. }
  365. width: itemArg_title.width
  366. text: ""
  367. font: FluTextStyle.Caption
  368. wrapMode: Text.WrapAnywhere
  369. topPadding: 6
  370. rightPadding: 6
  371. }
  372. onModelDataChanged: {
  373. if(modelData === null){
  374. console.error("bool model is null")
  375. return
  376. }
  377. itemArg_text.selected = modelData.value
  378. itemArg_title.text = qsTr(modelData.title)
  379. if( typeof modelData.description === 'undefined'){
  380. return
  381. }
  382. itemArg_description.text = qsTr(modelData.description)
  383. }
  384. }
  385. }
  386. Component{
  387. id: enum_item
  388. Item{
  389. id: itemArg
  390. property var modelData: null
  391. width: parent.width
  392. implicitHeight: itemArg_title.implicitHeight + itemArg_description.implicitHeight
  393. Layout.fillHeight: true
  394. FComboBox{
  395. id: itemArg_text
  396. width: 300
  397. anchors{
  398. top: parent.top
  399. topMargin: 2
  400. right: parent.right
  401. }
  402. model: ["0", "1", "2"]
  403. onActivated: {
  404. if(set_task(itemArg.parent.parent.parent.groupName, modelData.name, currentText)){
  405. showSuccess( qsTr("Successful setting"))
  406. }
  407. }
  408. }
  409. FluText{
  410. id: itemArg_title
  411. anchors{
  412. top: parent.top
  413. left: parent.left
  414. right: itemArg_text.left
  415. }
  416. text: ""
  417. font: FluTextStyle.BodyStrong
  418. wrapMode: Text.WrapAnywhere
  419. topPadding: 6
  420. }
  421. FluText{
  422. id: itemArg_description
  423. anchors{
  424. top: itemArg_title.bottom
  425. left: parent.left
  426. }
  427. width: itemArg_title.width
  428. text: ""
  429. font: FluTextStyle.Caption
  430. wrapMode: Text.WrapAnywhere
  431. // textFormat: Text.PlainText
  432. topPadding: 6
  433. rightPadding: 6
  434. }
  435. onModelDataChanged: {
  436. if(modelData === null){
  437. console.error("enum model is null")
  438. return
  439. }
  440. itemArg_text.model = modelData.options
  441. itemArg_text.show(modelData.value)
  442. itemArg_title.text = qsTr(modelData.title)
  443. if( typeof modelData.description === 'undefined'){
  444. return
  445. }
  446. itemArg_description.text = qsTr(modelData.description)
  447. }
  448. }
  449. }
  450. Component{
  451. id: multi_line_item
  452. Item{
  453. id: multiLineItem
  454. property var modelData: null
  455. width: parent.width
  456. implicitHeight: string_title.implicitHeight + string_description.implicitHeight
  457. height: if(string_text.height > (string_title.implicitHeight + string_description.implicitHeight)){
  458. return string_text.height
  459. }else{
  460. return string_title.implicitHeight + string_description.implicitHeight
  461. }
  462. Layout.fillHeight: true
  463. FluMultilineTextBox{
  464. id: string_text
  465. anchors{
  466. top: parent.top
  467. topMargin: 2
  468. right: parent.right
  469. }
  470. placeholderText: ""
  471. onEditingFinished: {
  472. if(set_task(multiLineItem.parent.parent.parent.groupName, modelData.name, text)){
  473. showSuccess( qsTr("Successful setting"))
  474. }
  475. }
  476. // onTextChanged: {
  477. // if(set_task(multiLineItem.parent.parent.parent.groupName, modelData.name, text)){
  478. // showSuccess( qsTr("Successful setting"))
  479. // }
  480. // }
  481. }
  482. FluText{
  483. // 设置的名称
  484. id: string_title
  485. anchors{
  486. top: parent.top
  487. left: parent.left
  488. right: string_text.left
  489. }
  490. text: ""
  491. font: FluTextStyle.BodyStrong
  492. wrapMode: Text.WrapAnywhere
  493. topPadding: 6
  494. }
  495. FluText{
  496. //描述
  497. id: string_description
  498. anchors{
  499. top: string_title.bottom
  500. left: parent.left
  501. }
  502. width: string_title.width
  503. text: ""
  504. font: FluTextStyle.Caption
  505. wrapMode: Text.WordWrap
  506. topPadding: 6
  507. rightPadding: 6
  508. }
  509. onModelDataChanged: {
  510. if(modelData === null){
  511. console.error("string model is null")
  512. return
  513. }
  514. string_text.text = modelData.value
  515. string_text.placeholderText = modelData["default"]
  516. string_title.text = qsTr(modelData.title)
  517. if( typeof modelData.description === 'undefined'){
  518. return
  519. }
  520. string_description.text = qsTr(modelData.description.replace("\\n","\n"))
  521. }
  522. }
  523. }
  524. onArgsDataChanged: {
  525. }
  526. onValueDataChanged: {
  527. }
  528. onUpdataData: {
  529. if(argsData === ""){
  530. console.error("解析 顺序出问题了")
  531. return
  532. }
  533. if(valueData === ""){
  534. console.debug("没有数据")
  535. }
  536. const args = JSON.parse(argsData)
  537. const values = JSON.parse(valueData)
  538. const group = MP.parseGroup(args["properties"])
  539. const groups = MP.parseGroups(args["properties"])
  540. for(let task in group){
  541. const argument = MP.parseArgument(args.definitions, group[task])
  542. const groupLetter = groups[group[task]]
  543. const argumentVuale = MP.mergeArgument(argument, values[groupLetter])
  544. // console.debug(JSON.stringify( argumentVuale ))
  545. // console.debug("---------------------------------------------------------------")
  546. createGroup(groupLetter, group[task], argumentVuale)
  547. }
  548. }
  549. /**
  550. * 创建某个组 的显示组件并显示
  551. * @param {Object} groupName 变量的名字 是小写的
  552. * @param {Object} groupTitle 用于向用户显示的名字 大写的
  553. * @param {Object} argumentVaule 总的显示的参数
  554. * @returns {Object}
  555. */
  556. function createGroup(groupName, groupTitle, argumentValue){
  557. if(!groupName){
  558. console.error("no group name")
  559. return
  560. }
  561. if(!groupTitle){
  562. console.error("no group title")
  563. return
  564. }
  565. const object = group_item.createObject(contentScrollable)
  566. if(object !== null){
  567. object.groupName = groupName
  568. object.groupTitle = qsTr(groupTitle)
  569. object.argumentValue = argumentValue
  570. contentScrollable.content.push(object)
  571. }
  572. else{
  573. console.error('create group item failed!')
  574. }
  575. }
  576. function set_task(group, arg, value){
  577. //如果是字符串
  578. if( typeof value == "string" ){
  579. if(process_manager.gui_set_task(configName, taskName, group, arg, value)){
  580. return true
  581. }
  582. else{
  583. return false
  584. }}
  585. //如果是整形的
  586. else if(typeof value == "number"){
  587. if(process_manager.gui_set_task_number(configName, taskName, group, arg, value)){
  588. return true
  589. }
  590. else{
  591. return false
  592. }}
  593. //如果是bool的
  594. else if(typeof value == "boolean"){
  595. if(process_manager.gui_set_task_bool(configName, taskName, group, arg, value)){
  596. return true
  597. }
  598. else{
  599. return false
  600. }}
  601. }
  602. }