Args.qml 18 KB

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