MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / _data

Method _data

src/Gui/ExpressionCompleter.cpp:317–537  ·  view source on GitHub ↗

The completion tree structure created takes into account the current document and object It is done as such: root (-1,-1) | |----- documents |----- current documents' objects [externally set] |----- current objects' props [externally set] This complicates the decoding schema for the root, where the childcount will be doc.size() + current_doc.Objects.size() + current_obj.Props.size(). this func

Source from the content-addressed store, hash-verified

315 // - obtain the count of a node identified by Info,row => count != nullptr, v==nullptr
316 // - get the text of an item. This text will contain separators but NO full path
317 void _data(const Info& info, int row, QVariant* v, int* count, bool sep = false) const
318 {
319 int idx;
320 // identify the document index. For any children of the root, it is given by traversing
321 // the flat list and identified by [row]
322 idx = info.doc < 0 ? row : info.doc;
323 const auto& docs = App::GetApplication().getDocuments();
324 int docSize = (int)docs.size() * 2;
325 int objSize = 0;
326 int propSize = 0;
327 App::Document* doc = nullptr;
328 App::DocumentObject* obj = nullptr;
329 const char* propName = nullptr;
330 App::Property* prop = nullptr;
331 // check if the document is uniquely identified: either the correct index in info.doc
332 // OR if, the node is a descendant of the root, its row lands within 0...docsize
333 if (idx >= 0 && idx < docSize) {
334 doc = docs[idx / 2];
335 }
336 else {
337 // if we're looking at the ROOT, or the row identifies one of the other ROOT elements
338 // |----- current documents' objects, rows: docs.size ... docs.size +
339 // objs.size
340 // |----- current objects' props, rows: docs.size + objs.size ... docs.size +
341 // objs.size+ props.size
342 //
343 // We need to process the ROOT so we get the correct count for its children
344 doc = App::GetApplication().getDocument(currentDoc.c_str());
345 if (!doc) { // no current, there are no additional objects
346 return;
347 }
348
349 // move to the current documents' objects' range
350 idx -= docSize;
351 if (info.doc < 0) {
352 row = idx;
353 }
354
355 const auto& objs = doc->getObjects();
356 objSize = (int)objs.size() * 2;
357 // if this is a valid object, we found our object and break.
358 // if not, this may be the root or one of current object's properties
359 if (idx >= 0 && idx < objSize) {
360 obj = objs[idx / 2];
361 // if they are in the ignore list skip
362 if (inList.contains(obj)) {
363 return;
364 }
365 }
366 else if (!noProperty) {
367 // need to check the current object's props range, or we're parsing the ROOT
368 auto cobj = doc->getObject(currentObj.c_str());
369 if (cobj) {
370 // move to the props range of the current object
371 idx -= objSize;
372 if (info.doc < 0) {
373 row = idx;
374 }

Callers

nothing calls this directly

Calls 14

quoteFunction · 0.85
getDocumentsMethod · 0.80
getSubPathStrMethod · 0.80
substrMethod · 0.80
sizeMethod · 0.45
getDocumentMethod · 0.45
c_strMethod · 0.45
getObjectsMethod · 0.45
containsMethod · 0.45
getObjectMethod · 0.45
emptyMethod · 0.45
getNameInDocumentMethod · 0.45

Tested by

no test coverage detected