std::string BaseLink::CreateStringPath(Base* dest, Base* from) { if (!dest || dest == from) return std::string("[]"); BaseObject* o = dest->toBaseObject(); BaseObject* f = from->toBaseObject(); BaseContext* ctx = from->toBaseContext(); if (!ctx && f) ctx = f->getContext(); if (o) { std::string objectPath = o->getName(); BaseObject* master = o->getMaster(); while (master) { objectPath = master->getName() + std::string("/") + objectPath; master = master->getMaster(); } BaseNode* n = o->getContext()->toBaseNode(); if (f && o->getContext() == ctx) return objectPath; else if (n) return n->getPathName() + std::string("/") + objectPath; // TODO: compute relative path else return objectPath; // we could not determine destination path, specifying simply its name might be enough to find it back } else // dest is a context { if (f && ctx == dest) return std::string("./"); BaseNode* n = dest->toBaseNode(); if (n) return n->getPathName(); // TODO: compute relative path else return dest->getName(); // we could not determine destination path, specifying simply its name might be enough to find it back } }
/// Traverse the item tree and retrive the item that are expanded. The path of the node /// that are expanded are stored in the the pathes std::vector::std::string>. void QSofaListView::getExpandedNodes(QTreeWidgetItem* item, std::vector<std::string>& pathes) { if(!item) return; /// We have reached a leaf of the hierarchy or it is closed...so we save the path if( !item->isExpanded() && graphListener_->findObject(item)->toBaseNode() != nullptr ) return; BaseNode* parentNode = graphListener_->findObject(item)->toBaseNode() ; if(parentNode == nullptr) return; std::string path = parentNode->getPathName(); pathes.push_back(path); for(int i=0 ; i<item->childCount() ; i++) { QTreeWidgetItem* child = item->child(i); BaseNode* childNode = graphListener_->findObject(child)->toBaseNode() ; if(childNode==nullptr) continue; if( childNode->getParents()[0] == parentNode ) getExpandedNodes(child, pathes) ; } return ; }