MCPcopy Create free account
hub / github.com/KDE/labplot / importTo

Method importTo

src/backend/datasources/projects/ProjectParser.cpp:70–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68}
69
70void ProjectParser::importTo(Folder* targetFolder, const QStringList& selectedPathes) {
71 DEBUG(Q_FUNC_INFO << ", starting import of " << STDSTRING(m_projectFileName));
72 QDEBUG(Q_FUNC_INFO << ", selected pathes: " << selectedPathes);
73
74 // import the selected objects into a temporary project
75 auto* project = new Project();
76 project->setPathesToLoad(selectedPathes);
77 bool rc = load(project, false);
78 if (!rc) {
79 delete project;
80 DEBUG(Q_FUNC_INFO << ", ERROR: import of " << STDSTRING(m_projectFileName) << " failed.");
81 return;
82 }
83
84 // determine the first child of the last top level child in the list of the imported objects
85 // we want to navigate to in the project explorer after the import
86 auto* lastTopLevelChild = project->child<AbstractAspect>(project->childCount<AbstractAspect>() - 1);
87 AbstractAspect* childToNavigate = nullptr;
88 if (lastTopLevelChild && lastTopLevelChild->childCount<AbstractAspect>() > 0) {
89 childToNavigate = lastTopLevelChild->child<AbstractAspect>(0);
90
91 // we don't want to select columns, select rather their parent spreadsheet
92 if (dynamic_cast<const Column*>(childToNavigate))
93 childToNavigate = lastTopLevelChild;
94 } else {
95 childToNavigate = lastTopLevelChild;
96 }
97
98 // move all children from the temp project to the target folder
99 targetFolder->beginMacro(i18n("%1: Import from %2", targetFolder->name(), m_projectFileName));
100 for (auto* child : project->children<AbstractAspect>()) {
101 auto* folder = dynamic_cast<Folder*>(child);
102 if (folder)
103 moveFolder(targetFolder, folder);
104 else if (child) {
105 project->removeChild(child);
106
107 // remove the object to be imported in the target folder if it already exists
108 auto* targetChild = targetFolder->child<AbstractAspect>(child->name());
109 if (targetChild)
110 targetFolder->removeChild(targetChild);
111
112 targetFolder->addChild(child);
113 }
114 }
115 targetFolder->setName(project->name());
116 targetFolder->endMacro();
117
118 Project::restorePointers(targetFolder);
119 Project::retransformElements(targetFolder);
120
121 delete project;
122
123 if (childToNavigate != nullptr)
124 targetFolder->project()->navigateTo(childToNavigate->path());
125
126 DEBUG(Q_FUNC_INFO << ", import of " << STDSTRING(m_projectFileName) << " DONE");
127}

Callers

nothing calls this directly

Calls 10

setPathesToLoadMethod · 0.80
beginMacroMethod · 0.80
endMacroMethod · 0.80
nameMethod · 0.45
removeChildMethod · 0.45
addChildMethod · 0.45
setNameMethod · 0.45
navigateToMethod · 0.45
projectMethod · 0.45
pathMethod · 0.45

Tested by

no test coverage detected