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

Method removeLastPointFromSelectedPath

src/tools/draw_path_tool.cpp:787–838  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

785}
786
787bool DrawPathTool::removeLastPointFromSelectedPath()
788{
789 if (editingInProgress() || map()->getNumSelectedObjects() != 1)
790 {
791 return false;
792 }
793
794 Object* object = map()->getFirstSelectedObject();
795 if (object->getType() != Object::Path)
796 {
797 return false;
798 }
799
800 PathObject* path = object->asPath();
801 if (path->parts().size() != 1)
802 {
803 return false;
804 }
805
806 int points_on_path = 0;
807 auto num_coords = path->getCoordinateCount();
808 for (MapCoordVector::size_type i = 0; i < num_coords && points_on_path < 3; ++i)
809 {
810 ++points_on_path;
811 if (path->getCoordinate(i).isCurveStart())
812 {
813 i += 2; // Skip the control points.
814 }
815 }
816
817 if (points_on_path < 3)
818 {
819 // Too few points after deleting the last: delete the whole object.
820 map()->deleteSelectedObjects();
821 return true;
822 }
823
824 auto undo_step = new ReplaceObjectsUndoStep(map());
825 auto undo_duplicate = object->duplicate();
826 undo_duplicate->setMap(map());
827 undo_step->addObject(object, undo_duplicate);
828 map()->push(undo_step);
829 updateDirtyRect();
830
831 path->parts().front().setClosed(false);
832 path->deleteCoordinate(num_coords - 1, false);
833
834 path->update();
835 map()->setObjectsDirty();
836 map()->emitSelectionEdited();
837 return true;
838}
839
840void DrawPathTool::closeDrawing()
841{

Callers

nothing calls this directly

Calls 15

getNumSelectedObjectsMethod · 0.80
asPathMethod · 0.80
getCoordinateCountMethod · 0.80
isCurveStartMethod · 0.80
getCoordinateMethod · 0.80
deleteCoordinateMethod · 0.80
setObjectsDirtyMethod · 0.80
emitSelectionEditedMethod · 0.80
getTypeMethod · 0.45
sizeMethod · 0.45
deleteSelectedObjectsMethod · 0.45

Tested by

no test coverage detected