diff --git a/src/core/control/Control.cpp b/src/core/control/Control.cpp index 5d4360ad9208..3e4383fdb685 100644 --- a/src/core/control/Control.cpp +++ b/src/core/control/Control.cpp @@ -2182,9 +2182,7 @@ void Control::changeColorOfSelection() { if (this->win && toolHandler->hasCapability(TOOL_CAP_COLOR)) { EditSelection* sel = this->win->getXournal()->getSelection(); if (sel) { - UndoAction* undo = sel->setColor(toolHandler->getColor()); - // move into selection - undoRedo->addUndoAction(UndoActionPtr(undo)); + undoRedo->addUndoAction(sel->setColor(toolHandler->getColor())); } TextEditor* edit = getTextEditor(); diff --git a/src/core/control/tools/EditSelection.cpp b/src/core/control/tools/EditSelection.cpp index 1268cf771b58..e868e3b0cc87 100644 --- a/src/core/control/tools/EditSelection.cpp +++ b/src/core/control/tools/EditSelection.cpp @@ -324,7 +324,7 @@ auto EditSelection::getYOnViewAbsolute() -> int { * (or nullptr if nothing is done) */ auto EditSelection::setSize(ToolSize size, const double* thicknessPen, const double* thicknessHighlighter, - const double* thicknessEraser) -> UndoAction* { + const double* thicknessEraser) -> UndoActionPtr { return this->contents->setSize(size, thicknessPen, thicknessHighlighter, thicknessEraser); } @@ -332,7 +332,7 @@ auto EditSelection::setSize(ToolSize size, const double* thicknessPen, const dou * Fills the stroke, return an undo action * (Or nullptr if nothing done, e.g. because there is only an image) */ -auto EditSelection::setFill(int alphaPen, int alphaHighligther) -> UndoAction* { +auto EditSelection::setFill(int alphaPen, int alphaHighligther) -> UndoActionPtr { return this->contents->setFill(alphaPen, alphaHighligther); } @@ -346,13 +346,13 @@ auto EditSelection::setLineStyle(LineStyle style) -> UndoActionPtr { return this * Set the color of all elements, return an undo action * (Or nullptr if nothing done, e.g. because there is only an image) */ -auto EditSelection::setColor(Color color) -> UndoAction* { return this->contents->setColor(color); } +auto EditSelection::setColor(Color color) -> UndoActionPtr { return this->contents->setColor(color); } /** * Sets the font of all containing text elements, return an undo action * (or nullptr if there are no Text elements) */ -auto EditSelection::setFont(XojFont& font) -> UndoAction* { return this->contents->setFont(font); } +auto EditSelection::setFont(XojFont& font) -> UndoActionPtr { return this->contents->setFont(font); } /** * Fills de undo item if the selection is deleted diff --git a/src/core/control/tools/EditSelection.h b/src/core/control/tools/EditSelection.h index c02adc43d504..38b30d229fa2 100644 --- a/src/core/control/tools/EditSelection.h +++ b/src/core/control/tools/EditSelection.h @@ -147,8 +147,8 @@ class EditSelection: public ElementContainer, public Serializable { * Sets the tool size for pen or eraser, returns an undo action * (or nullptr if nothing is done) */ - UndoAction* setSize(ToolSize size, const double* thicknessPen, const double* thicknessHighlighter, - const double* thicknessEraser); + UndoActionPtr setSize(ToolSize size, const double* thicknessPen, const double* thicknessHighlighter, + const double* thicknessEraser); /** * Set the line style of all strokes, return an undo action @@ -160,13 +160,13 @@ class EditSelection: public ElementContainer, public Serializable { * Set the color of all elements, return an undo action * (Or nullptr if nothing done, e.g. because there is only an image) */ - UndoAction* setColor(Color color); + UndoActionPtr setColor(Color color); /** * Sets the font of all containing text elements, return an undo action * (or nullptr if there are no Text elements) */ - UndoAction* setFont(XojFont& font); + UndoActionPtr setFont(XojFont& font); /** * Fills the undo item if the selection is deleted @@ -178,7 +178,7 @@ class EditSelection: public ElementContainer, public Serializable { * Fills the stroke, return an undo action * (Or nullptr if nothing done, e.g. because there is only an image) */ - UndoAction* setFill(int alphaPen, int alphaHighligther); + UndoActionPtr setFill(int alphaPen, int alphaHighligther); public: /** diff --git a/src/core/control/tools/EditSelectionContents.cpp b/src/core/control/tools/EditSelectionContents.cpp index 890dad6012a2..7d759e7b7739 100644 --- a/src/core/control/tools/EditSelectionContents.cpp +++ b/src/core/control/tools/EditSelectionContents.cpp @@ -99,8 +99,8 @@ auto EditSelectionContents::getInsertOrder() const -> std::deque UndoAction* { - auto* undo = new SizeUndoAction(this->sourcePage, this->sourceLayer); + const double* thicknessEraser) -> UndoActionPtr { + auto undo = std::make_unique(this->sourcePage, this->sourceLayer); bool found = false; @@ -141,8 +141,6 @@ auto EditSelectionContents::setSize(ToolSize size, const double* thicknessPen, c return undo; } - - delete undo; return nullptr; } @@ -150,8 +148,8 @@ auto EditSelectionContents::setSize(ToolSize size, const double* thicknessPen, c * Fills the stroke, return an undo action * (Or nullptr if nothing done, e.g. because there is only an image) */ -auto EditSelectionContents::setFill(int alphaPen, int alphaHighligther) -> UndoAction* { - auto* undo = new FillUndoAction(this->sourcePage, this->sourceLayer); +auto EditSelectionContents::setFill(int alphaPen, int alphaHighligther) -> UndoActionPtr { + auto undo = std::make_unique(this->sourcePage, this->sourceLayer); bool found = false; @@ -188,8 +186,6 @@ auto EditSelectionContents::setFill(int alphaPen, int alphaHighligther) -> UndoA return undo; } - - delete undo; return nullptr; } @@ -197,13 +193,13 @@ auto EditSelectionContents::setFill(int alphaPen, int alphaHighligther) -> UndoA * Sets the font of all containing text elements, return an undo action * (or nullptr if there are no Text elements) */ -auto EditSelectionContents::setFont(XojFont& font) -> UndoAction* { +auto EditSelectionContents::setFont(XojFont& font) -> UndoActionPtr { double x1 = 0.0 / 0.0; double x2 = 0.0 / 0.0; double y1 = 0.0 / 0.0; double y2 = 0.0 / 0.0; - auto* undo = new FontUndoAction(this->sourcePage, this->sourceLayer); + auto undo = std::make_unique(this->sourcePage, this->sourceLayer); for (Element* e: this->selected) { if (e->getType() == ELEMENT_TEXT) { @@ -240,7 +236,7 @@ auto EditSelectionContents::setFont(XojFont& font) -> UndoAction* { this->sourceView->getXournal()->repaintSelection(); return undo; } - delete undo; + return nullptr; } @@ -271,16 +267,15 @@ auto EditSelectionContents::setLineStyle(LineStyle style) -> UndoActionPtr { return undo; } - - return {}; + return nullptr; } /** * Set the color of all elements, return an undo action * (Or nullptr if nothing done, e.g. because there is only an image) */ -auto EditSelectionContents::setColor(Color color) -> UndoAction* { - auto* undo = new ColorUndoAction(this->sourcePage, this->sourceLayer); +auto EditSelectionContents::setColor(Color color) -> UndoActionPtr { + auto undo = std::make_unique(this->sourcePage, this->sourceLayer); bool found = false; @@ -301,8 +296,6 @@ auto EditSelectionContents::setColor(Color color) -> UndoAction* { return undo; } - - delete undo; return nullptr; } diff --git a/src/core/control/tools/EditSelectionContents.h b/src/core/control/tools/EditSelectionContents.h index 600f20e992cc..bb50fda089c4 100644 --- a/src/core/control/tools/EditSelectionContents.h +++ b/src/core/control/tools/EditSelectionContents.h @@ -45,29 +45,29 @@ class EditSelectionContents: public ElementContainer, public Serializable { public: /** - * Sets the line style for all strokes, returs an undo action + * Sets the line style for all strokes, returns an undo action * (or nullptr if nothing is done) */ UndoActionPtr setLineStyle(LineStyle style); /** - * Sets the tool size for pen or eraser, returs an undo action + * Sets the tool size for pen or eraser, returns an undo action * (or nullptr if nothing is done) */ - UndoAction* setSize(ToolSize size, const double* thicknessPen, const double* thicknessHighlighter, - const double* thicknessEraser); + UndoActionPtr setSize(ToolSize size, const double* thicknessPen, const double* thicknessHighlighter, + const double* thicknessEraser); /** * Set the color of all elements, return an undo action * (Or nullptr if nothing done, e.g. because there is only an image) */ - UndoAction* setColor(Color color); + UndoActionPtr setColor(Color color); /** * Sets the font of all containing text elements, return an undo action * (or nullptr if there are no Text elements) */ - UndoAction* setFont(XojFont& font); + UndoActionPtr setFont(XojFont& font); /** * Fills the undo item if the selection is deleted @@ -79,7 +79,7 @@ class EditSelectionContents: public ElementContainer, public Serializable { * Fills the stroke, return an undo action * (Or nullptr if nothing done, e.g. because there is only an image) */ - UndoAction* setFill(int alphaPen, int alphaHighligther); + UndoActionPtr setFill(int alphaPen, int alphaHighligther); public: /** @@ -168,7 +168,7 @@ class EditSelectionContents: public ElementContainer, public Serializable { private: /** - * The original dimensions to calculate the zoom factor for reascaling the items and the offset for moving the + * The original dimensions to calculate the zoom factor for rescaling the items and the offset for moving the * selection */ xoj::util::Rectangle originalBounds;