MCPcopy Create free account
hub / github.com/OpenOrienteering/mapper / loadFrom

Method loadFrom

src/gui/map/map_editor.cpp:639–699  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

637
638
639bool MapEditorController::loadFrom(const QString& path, const FileFormat& format, QWidget* dialog_parent)
640{
641 if (!dialog_parent)
642 dialog_parent = window;
643
644 if (!map)
645 {
646 map = new Map();
647 main_view = new MapView(this, map);
648 }
649#ifdef __clang_analyzer__
650 // clang-analyzer-core.CallAndMessage seems to be unable to realize
651 // that map != null from the previous block.
652 if (!map) { return false; }
653#endif
654
655 auto importer = format.makeImporter(path, map, main_view);
656 if (!importer)
657 {
658 QMessageBox::warning(dialog_parent, tr("Error"),
659 ::OpenOrienteering::MainWindow::tr("Cannot open file:\n%1\n\n%2")
660 .arg(path, ::OpenOrienteering::MainWindow::tr("Invalid file type.")));
661 return false;
662 }
663
664 if (!importer->doImport())
665 {
666 delete map;
667 map = nullptr;
668 main_view = nullptr;
669
670 Q_ASSERT(!importer->warnings().empty());
671 QMessageBox::warning(dialog_parent, tr("Error"), importer->warnings().back());
672 return false;
673 }
674
675 map->loadTemplateFilesAsync(*main_view, [controller = QPointer<MapEditorController>(this)](const QString& message) {
676 auto* window = controller ? controller->getWindow() : nullptr;
677 if (!window)
678 return;
679 if (message.isEmpty())
680 window->clearStatusBarMessage();
681 else
682 window->showStatusBarMessageImmediately(message);
683 });
684 setMapAndView(map, main_view);
685 map->setHasUnsavedChanges(false);
686 if (!importer->warnings().empty())
687 {
688 // Display warnings asynchronously, so that map and templates get visible.
689 auto warnings = importer->warnings();
690 auto show_warnings = [dialog_parent, warnings]() {
691 MainWindow::showMessageBox(dialog_parent,
692 tr("Warning"),
693 tr("The map import generated warnings."),
694 warnings);
695 };
696 QTimer::singleShot(0, dialog_parent, show_warnings);

Callers 3

openPathMethod · 0.45
switchActualPathMethod · 0.45

Calls 10

doImportMethod · 0.80
backMethod · 0.80
getWindowMethod · 0.80
clearStatusBarMessageMethod · 0.80
makeImporterMethod · 0.45
emptyMethod · 0.45
isEmptyMethod · 0.45
setHasUnsavedChangesMethod · 0.45

Tested by

no test coverage detected