Skip to content

Commit

Permalink
Use UndoActionPtr instead of UndoAction*
Browse files Browse the repository at this point in the history
  • Loading branch information
jhilmer authored and Febbe committed Mar 22, 2023
1 parent aeb8d31 commit da55a1a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 37 deletions.
4 changes: 1 addition & 3 deletions src/core/control/Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions src/core/control/tools/EditSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,15 +324,15 @@ 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);
}

/**
* 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);
}

Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/core/control/tools/EditSelection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
/**
Expand Down
27 changes: 10 additions & 17 deletions src/core/control/tools/EditSelectionContents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ auto EditSelectionContents::getInsertOrder() const -> std::deque<std::pair<Eleme
* (or nullptr if nothing is done)
*/
auto EditSelectionContents::setSize(ToolSize size, const double* thicknessPen, const double* thicknessHighlighter,
const double* thicknessEraser) -> UndoAction* {
auto* undo = new SizeUndoAction(this->sourcePage, this->sourceLayer);
const double* thicknessEraser) -> UndoActionPtr {
auto undo = std::make_unique<SizeUndoAction>(this->sourcePage, this->sourceLayer);

bool found = false;

Expand Down Expand Up @@ -141,17 +141,15 @@ auto EditSelectionContents::setSize(ToolSize size, const double* thicknessPen, c
return undo;
}


delete undo;
return nullptr;
}

/**
* 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<FillUndoAction>(this->sourcePage, this->sourceLayer);

bool found = false;

Expand Down Expand Up @@ -188,22 +186,20 @@ auto EditSelectionContents::setFill(int alphaPen, int alphaHighligther) -> UndoA
return undo;
}


delete undo;
return nullptr;
}

/**
* 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<FontUndoAction>(this->sourcePage, this->sourceLayer);

for (Element* e: this->selected) {
if (e->getType() == ELEMENT_TEXT) {
Expand Down Expand Up @@ -240,7 +236,7 @@ auto EditSelectionContents::setFont(XojFont& font) -> UndoAction* {
this->sourceView->getXournal()->repaintSelection();
return undo;
}
delete undo;

return nullptr;
}

Expand Down Expand Up @@ -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<ColorUndoAction>(this->sourcePage, this->sourceLayer);

bool found = false;

Expand All @@ -301,8 +296,6 @@ auto EditSelectionContents::setColor(Color color) -> UndoAction* {
return undo;
}


delete undo;
return nullptr;
}

Expand Down
16 changes: 8 additions & 8 deletions src/core/control/tools/EditSelectionContents.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
/**
Expand Down Expand Up @@ -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<double> originalBounds;
Expand Down

0 comments on commit da55a1a

Please sign in to comment.