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

Method loadFolder

src/backend/datasources/projects/OriginProjectParser.cpp:517–670  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

515}
516
517bool OriginProjectParser::loadFolder(Folder* folder, tree<Origin::ProjectNode>::iterator baseIt, bool preview) {
518 DEBUG(Q_FUNC_INFO)
519 const auto* projectTree = m_originFile->project();
520
521 // do not skip anything if pathesToLoad() contains only root folder
522 bool containsRootFolder = (folder->pathesToLoad().size() == 1 && folder->pathesToLoad().contains(folder->path()));
523 if (containsRootFolder) {
524 DEBUG(" pathesToLoad contains only folder path \"" << STDSTRING(folder->path()) << "\". Clearing pathes to load.")
525 folder->setPathesToLoad(QStringList());
526 }
527
528 // load folder's children: logic for reading the selected objects only is similar to Folder::readChildAspectElement
529 for (auto it = projectTree->begin(baseIt); it != projectTree->end(baseIt); ++it) {
530 QString name(QString::fromLatin1(it->name.c_str())); // name of the current child
531 DEBUG(Q_FUNC_INFO << ", folder item name = " << STDSTRING(name))
532
533 // check whether we need to skip the loading of the current child
534 if (!folder->pathesToLoad().isEmpty()) {
535 // child's path is not available yet (child not added yet) -> construct the path manually
536 const QString childPath = folder->path() + QLatin1Char('/') + name;
537 DEBUG(" path = " << STDSTRING(childPath))
538
539 // skip the current child aspect it is not in the list of aspects to be loaded
540 if (folder->pathesToLoad().indexOf(childPath) == -1) {
541 DEBUG(" skip it!")
542 continue;
543 }
544 }
545
546 // load top-level children.
547 // use 'preview' as 'loading'-parameter in the constructors to skip the init() calls in Worksheet, Spreadsheet and Matrix:
548 //* when doing the preview of the project we don't want to initialize the objects and skip init()'s
549 //* when loading the project, 'preview' is false and we initialize all objects with our default values
550 // and set all possible properties from Origin additionally
551 AbstractAspect* aspect = nullptr;
552 switch (it->type) {
553 case Origin::ProjectNode::Folder: {
554 DEBUG(Q_FUNC_INFO << ", top level FOLDER");
555 Folder* f = new Folder(name);
556
557 if (!folder->pathesToLoad().isEmpty()) {
558 // a child folder to be read -> provide the list of aspects to be loaded to the child folder, too.
559 // since the child folder and all its children are not added yet (path() returns empty string),
560 // we need to remove the path of the current child folder from the full pathes provided in pathesToLoad.
561 // E.g. we want to import the path "Project/Folder/Spreadsheet" in the following project
562 // Project
563 // \Spreadsheet
564 // \Folder
565 // \Spreadsheet
566 //
567 // Here, we remove the part "Project/Folder/" and proceed for this child folder with "Spreadsheet" only.
568 // With this the logic above where it is determined whether to import the child aspect or not works out.
569
570 // manually construct the path of the child folder to be read
571 const QString& curFolderPath = folder->path() + QLatin1Char('/') + name;
572
573 // remove the path of the current child folder
574 QStringList pathesToLoadNew;

Callers

nothing calls this directly

Calls 15

setPathesToLoadMethod · 0.80
lengthMethod · 0.80
setIsLoadingMethod · 0.80
addChildFastMethod · 0.80
setCreationTimeMethod · 0.80
resultsLogStringMethod · 0.80
QStringClass · 0.70
projectMethod · 0.45
sizeMethod · 0.45
containsMethod · 0.45
pathMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected