diff --git a/src/core/map.cpp b/src/core/map.cpp index b37e4ea24..43de34754 100644 --- a/src/core/map.cpp +++ b/src/core/map.cpp @@ -971,6 +971,7 @@ QHash Map::importMap( // Import parts like this: // - if the other map has only one part, import it into the current part // - else check if there is already a part with an equal name for every part to import and import into this part if found, else create a new part + auto* undo_step = new CombinedUndoStep(this); for (const auto* part_to_import : imported_map.parts) { MapPart* dest_part = nullptr; @@ -993,7 +994,7 @@ QHash Map::importMap( // Import as new part dest_part = new MapPart(part_to_import->getName(), this); addPart(dest_part, 0); - push(new MapPartUndoStep(this, MapPartUndoStep::RemoveMapPart, 0)); + undo_step->push(new MapPartUndoStep(this, MapPartUndoStep::RemoveMapPart, 0)); } } @@ -1002,12 +1003,16 @@ QHash Map::importMap( current_part_index = std::size_t(findPartIndex(dest_part)); bool select_and_center_objects = dest_part == temp_current_part; - dest_part->importPart(part_to_import, symbol_map, transform, select_and_center_objects); - if (select_and_center_objects) - ensureVisibilityOfSelectedObjects(Map::FullVisibility); + if (auto import_undo = dest_part->importPart(part_to_import, symbol_map, transform, select_and_center_objects)) + { + undo_step->push(import_undo.release()); + if (select_and_center_objects) + ensureVisibilityOfSelectedObjects(Map::FullVisibility); + } current_part_index = std::size_t(findPartIndex(temp_current_part)); } + push(undo_step); } } diff --git a/src/core/map_part.cpp b/src/core/map_part.cpp index 7341233da..13e05cfec 100644 --- a/src/core/map_part.cpp +++ b/src/core/map_part.cpp @@ -215,10 +215,10 @@ bool MapPart::deleteObject(Object* object, bool remove_only) return false; } -void MapPart::importPart(const MapPart* other, const QHash& symbol_map, const QTransform& transform, bool select_new_objects) +std::unique_ptr MapPart::importPart(const MapPart* other, const QHash& symbol_map, const QTransform& transform, bool select_new_objects) { if (other->getNumObjects() == 0) - return; + return {}; bool first_objects = map->getNumObjects() == 0; auto undo_step = new DeleteObjectsUndoStep(map); @@ -242,7 +242,6 @@ void MapPart::importPart(const MapPart* other, const QHashaddObjectToSelection(new_object, false); } - map->push(undo_step); map->setObjectsDirty(); if (select_new_objects) { @@ -252,6 +251,8 @@ void MapPart::importPart(const MapPart* other, const QHashupdateAllMapWidgets(); + + return std::unique_ptr{undo_step}; } void MapPart::findObjectsAt( diff --git a/src/core/map_part.h b/src/core/map_part.h index fe2e5aeff..ce3163206 100644 --- a/src/core/map_part.h +++ b/src/core/map_part.h @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -44,6 +45,7 @@ class MapCoordF; class Object; class Symbol; using SymbolDictionary = QHash; // from symbol.h +class UndoStep; using SelectionInfoVector = std::vector> ; @@ -180,7 +182,7 @@ friend class OCAD8FileImport; * Uses symbol_map to replace all symbols contained there. * No replacement is done for symbols which are not in the symbol_map. */ - void importPart(const MapPart* other, const QHash& symbol_map, + std::unique_ptr importPart(const MapPart* other, const QHash& symbol_map, const QTransform& transform, bool select_new_objects);