Args.qml 18 KB

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