ADTF  3.13.0
EditorPluginBase.qml
Go to the documentation of this file.
1 
9 import QtQuick 2.7
10 import QtQuick.Controls 1.4
11 import QtQuick.Layouts 1.1
12 import QtGraphicalEffects 1.0
13 import QtQuick.Dialogs 1.2
14 import Helpers 1.0
15 import Utils 1.0
16 
23 Item {
24 
27  property var filenameHelper: FilenameHelper
28 
30  property var targetModel
32  property var commandCallback
34  property var editorDescription
36  property var dialogManager
37 
38 
40  signal execute()
41 
42 
43  property var getPropertyDescriptions: function(component) {
44 
45  if(!component) {
46  console.log("Component is null");
47  console.trace()
48  }
49  else if (!component.base_properties) {
50  console.log("Component dosn't contains a property set");
51  console.trace()
52  }
53  else if (!component.base_properties.property_set_description) {
54  console.log("Component dosn't contains a property set description");
55  console.trace()
56  }
57  else {
58  return component.base_properties.property_set_description.property_descriptions;
59  }
60  }
61 
62  property var getProperties: function(component) {
63 
64  if(!component) {
65  console.log("Component is null");
66  console.trace()
67  }
68  else if (!component.base_properties) {
69  console.log("Component dosn't contains a property set");
70  console.trace()
71  }
72  else {
73  return component.base_properties.properties;
74  }
75  }
77 
83  function findService(name) {
84  var result = null
85  Utils.each(modelmanager.system.services, function(service) {
86  if(service.name === name) {
87  result = service
88  }
89  })
90  return result;
91  }
92 
100  function findProperty(component, name) {
101  var properties = getProperties(component)
102  var result = null
103 
104  Utils.each(properties, function(prop) {
105  if (prop.name === name) {
106  result = prop
107  }
108  })
109  return result
110  }
111 
119  function findPropertyDescription(component, name) {
120  var propertyDescs = getPropertyDescriptions(component)
121  var result = null
122 
123  Utils.each(propertyDescs, function(prop) {
124  if (prop.name === name) {
125  result = prop
126  }
127  })
128  return result
129  }
130 
140  function createProperty(component, name, value, type, link) {
141  var description = findPropertyDescription(component, name)
142 
143  if (link === undefined) {
144  link = ""
145  }
146 
147  if(!description) {
148  if (type !== undefined) {
149  commandCallback(function(options) {
150  return component.base_properties.createDynamicProperty(name, value, type, link, options)
151  })
152  return
153  }
154  else {
155  console.error("Could not find Plugindescription for property " + name)
156  }
157  }
158 
159  commandCallback(function(options) {
160  return component.base_properties.createProperty(description, value, link, options)
161  })
162  }
163 
170  function setProperty(component, name, value) {
171  console.assert(commandCallback, "Command callback not found")
172  console.assert(component, "Component not set")
173 
174  var property = findProperty(component, name)
175  if(property) {
176  commandCallback(function(options) {
177  return property.changeValue(value, options)
178  })
179  }
180  else {
181  createProperty(component, name, value)
182  }
183  }
184 
191  function getPropertyValue(component, name) {
192  console.assert(component, "Component not set")
193 
194  const property = findProperty(component, name)
195  if(property) {
196  return property.value
197  }
198 
199  const description = findPropertyDescription(component, name)
200  if(description) {
201  return description.value
202  }
203 
204  console.error("Property not found")
205  return ""
206  }
207 
213  function findInputPin(name) {
214  let result = null
215  Utils.each(targetModel.input_pins, function(pin) {
216  if (pin.name === name) {
217  result = pin
218  }
219  })
220  return result
221  }
222 
227  function createInputPin(name) {
228  const pin = findInputPin(name)
229  if(!pin) {
230  commandCallback(function(options) {
231  return targetModel.addInputPin(name, options)
232  })
233  }
234  }
235 
240  function listInputPins() {
241  let names = []
242  Utils.each(targetModel.input_pins, function(pin) {
243  names.push(pin.name)
244  })
245  return names
246  }
247 
252  function removeInputPin(pin) {
253  commandCallback(function(options) {
254  return targetModel.removeInputPin(pin, options)
255  })
256  }
257 
263  function findOutputPin(name) {
264  let result = null
265  Utils.each(targetModel.output_pins, function(pin) {
266  if (pin.name === name) {
267  result = pin
268  }
269  })
270  return result
271  }
272 
277  function createOutputPin(name) {
278  const pin = findOutputPin(name)
279  if(!pin) {
280  commandCallback(function(options) {
281  return targetModel.addOutputPin(name, options)
282  })
283  }
284  }
285 
290  function listOutputPins() {
291  let names = []
292  Utils.each(targetModel.output_pins, function(pin) {
293  names.push(pin.name)
294  })
295  return names
296  }
297 
302  function removeOutputPin(pin) {
303  commandCallback(function(options) {
304  return targetModel.removeOutputPin(pin, options)
305  })
306  }
307 
312  function listRunner()
313  {
314  let names = []
315  Utils.each(targetModel.runners, function(runner) {
316  names.push(runner.name)
317  })
318  return names
319  }
320 
326  function findRunner(runnerName) {
327  let result = null
328  Utils.each(targetModel.runners, function(runner) {
329  if (runner.name === runnerName) {
330  result = runner
331  }
332  })
333  return result
334  }
335 
340  function createRunner(name) {
341  const runner = findRunner(name)
342  if(!runner) {
343  commandCallback(function(options) {
344  return targetModel.addRunner(name, options)
345  })
346  }
347  }
348 
353  function removeRunner(runner) {
354  commandCallback(function(options) {
355  return targetModel.removeRunner(runner, options)
356  })
357  }
358 
367  function resolveAndGetAbsoluteUrl(path, basePath) {
368  if(!basePath){
369  basePath = "."
370  }
371  return editorDescription.GetAbsoluteUrl(path, basePath)
372  }
373 
378  function getPropertyFile() {
379  return targetModel.base_properties.getPropertyFileUrl()
380  }
381 
390  function launch(command, args, workingDirectory) {
391  return editorDescription.Launch(command, args, workingDirectory)
392  }
393 
401  function parseJsonResult(result)
402  {
403  console.log("result: " + result)
404  var regex = /json_result:([\s\S]*):end/i
405 
406  var match = regex.exec(result);
407  if(match.length < 2) {
408  throw "Couldn't find Json string"
409  }
410 
411  var json_result = match[1]
412  json_result = json_result.replace(/(\r\n|\n|\r)/gm,"")
413 
414  console.log("json_result: " + json_result)
415 
416  return JSON.parse(json_result)
417  }
418 
424  function forEach(array, callback) {
425  Utils.each(array, callback)
426  }
427 
433  function removeFromArray(array, callback) {
434  var newArray = []
435  forEach(array, function(item) {
436  if(!callback(item))
437  {
438  newArray.push(item)
439  }
440  });
441  return newArray
442  }
443 
451  function contains(array, value, compare_callback) {
452  var found = false;
453  forEach(array, function(item) {
454  if(compare_callback && compare_callback(item, value)) {
455  found = true
456  }
457  else if(item === value) {
458  found = true
459  }
460  })
461  return found;
462  }
463 
464  Component.onCompleted: {
465  execute()
466  }
467 }
468 

Copyright © Audi Electronics Venture GmbH. All rights reserved. (Generated on Tue Sep 28 2021 by doxygen 1.8.14)