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

Method importClicked

src/gui/widgets/template_list_widget.cpp:860–968  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

858}
859
860void TemplateListWidget::importClicked()
861{
862 auto* prototype = qobject_cast<const TemplateMap*>(currentTemplate());
863 if (!prototype)
864 return;
865
866 TemplateTransform transform;
867 if (!prototype->isTemplateGeoreferenced())
868 prototype->getTransform(transform);
869
870 Map template_map;
871 bool ok = true;
872 if (qstrcmp(prototype->getTemplateType(), "OgrTemplate") == 0)
873 {
874 template_map.importMap(*prototype->templateMap(), Map::MinimalObjectImport);
875 if (!prototype->isTemplateGeoreferenced())
876 {
877 template_map.applyOnAllObjects(transform.makeObjectTransform());
878 template_map.setGeoreferencing(map.getGeoreferencing());
879 }
880 auto template_scale = (transform.template_scale_x + transform.template_scale_y) / 2;
881 template_scale *= double(prototype->templateMap()->getScaleDenominator()) / map.getScaleDenominator();
882 if (!qFuzzyCompare(template_scale, 1))
883 {
884 template_map.scaleAllSymbols(template_scale);
885 }
886 }
887 else if (qstrcmp(prototype->getTemplateType(), "TemplateMap") == 0)
888 {
889 auto importer = FileFormats.makeImporter(prototype->getTemplatePath(), template_map, nullptr);
890 if (!importer)
891 {
892 QMessageBox::warning(this, tr("Error"), tr("Cannot load map file, aborting."));
893 return;
894 }
895 if (!importer->doImport())
896 {
897 QMessageBox::warning(this, tr("Error"), importer->warnings().back());
898 return;
899 }
900 if (!importer->warnings().empty())
901 {
902 MainWindow::showMessageBox(this, tr("Warning"), tr("The map import generated warnings."), importer->warnings());
903 }
904
905 if (!prototype->isTemplateGeoreferenced())
906 template_map.applyOnAllObjects(transform.makeObjectTransform());
907
908 auto nominal_scale = double(template_map.getScaleDenominator()) / map.getScaleDenominator();
909 auto current_scale = 0.5 * (transform.template_scale_x + transform.template_scale_y);
910 auto scale = 1.0;
911 QStringList scale_options;
912 if (qAbs(nominal_scale - 1.0) > 0.009)
913 scale_options.append(tr("Scale by nominal map scale ratio (%1 %)").arg(locale().toString(nominal_scale * 100.0, 'f', 1)));
914 if (qAbs(current_scale - 1.0) > 0.009 && qAbs(current_scale - nominal_scale) > 0.009)
915 scale_options.append(tr("Scale by current template scaling (%1 %)").arg(locale().toString(current_scale * 100.0, 'f', 1)));
916 if (!scale_options.isEmpty())
917 {

Callers

nothing calls this directly

Calls 15

getTransformMethod · 0.80
templateMapMethod · 0.80
makeObjectTransformMethod · 0.80
setGeoreferencingMethod · 0.80
scaleAllSymbolsMethod · 0.80
doImportMethod · 0.80
backMethod · 0.80
hasSpotColorsMethod · 0.80
getActionMethod · 0.80
getMapVisibilityMethod · 0.80

Tested by

no test coverage detected