| 139 | } |
| 140 | |
| 141 | bool TemplateMap::loadTemplateFileImpl() |
| 142 | { |
| 143 | // Prevent unbounded recursive template loading |
| 144 | if (locked_maps.contains(template_path)) |
| 145 | return true; |
| 146 | |
| 147 | auto new_template_map = std::make_unique<Map>(); |
| 148 | auto importer = FileFormats.makeImporter(template_path, *new_template_map, nullptr); |
| 149 | locked_maps.append(template_path); /// \todo Convert to RAII |
| 150 | auto new_template_valid = importer && importer->doImport(); |
| 151 | locked_maps.removeAll(template_path); |
| 152 | |
| 153 | if (new_template_valid) |
| 154 | { |
| 155 | template_map = std::move(new_template_map); |
| 156 | |
| 157 | if (property(ocdTransformProperty()).toBool()) |
| 158 | { |
| 159 | // Update the transformation without signalling dirty state. |
| 160 | is_georeferenced = false; |
| 161 | transform = transformForOcd(); |
| 162 | updateTransformationMatrices(); |
| 163 | setProperty(ocdTransformProperty(), false); |
| 164 | } |
| 165 | else if (is_georeferenced) |
| 166 | { |
| 167 | QTransform q_transform; |
| 168 | if (!calculateTransformation(q_transform)) |
| 169 | { |
| 170 | setErrorString(tr("Failed to transform the coordinates.")); |
| 171 | return false; |
| 172 | } |
| 173 | |
| 174 | transform = TemplateTransform::fromQTransform(q_transform); |
| 175 | if (georeferencedStateSupported()) |
| 176 | { |
| 177 | transformMap(*template_map, *map, transform); |
| 178 | transform = {}; |
| 179 | } |
| 180 | else |
| 181 | { |
| 182 | // Owning map or template not georeferenced, or georeferencing |
| 183 | // blocked, so we must change the state now, using the |
| 184 | // calculated transformation. |
| 185 | is_georeferenced = false; |
| 186 | } |
| 187 | updateTransformationMatrices(); |
| 188 | block_georeferencing = false; |
| 189 | } |
| 190 | } |
| 191 | else if (importer) |
| 192 | { |
| 193 | setErrorString(importer->warnings().back()); |
| 194 | } |
| 195 | else |
| 196 | { |
| 197 | setErrorString(tr("Cannot load map file, aborting.")); |
| 198 | } |
no test coverage detected