diff --git a/src/undo/AddUndoAction.cpp b/src/undo/AddUndoAction.cpp index b1a420a8..bc521f7d 100644 --- a/src/undo/AddUndoAction.cpp +++ b/src/undo/AddUndoAction.cpp @@ -9,7 +9,7 @@ #include -AddUndoAction::AddUndoAction(PageRef page, bool eraser) +AddUndoAction::AddUndoAction(const PageRef& page, bool eraser) : UndoAction("AddUndoAction") { XOJ_INIT_TYPE(AddUndoAction); @@ -22,9 +22,9 @@ AddUndoAction::~AddUndoAction() { XOJ_CHECK_TYPE(AddUndoAction); - for (GList* l = this->elements; l != NULL; l = l->next) + for (GList* l = this->elements; l != nullptr; l = l->next) { - PageLayerPosEntry* e = (PageLayerPosEntry*) l->data; + auto e = (PageLayerPosEntry*) l->data; if (!undone) { //The element will be deleted when the layer is removed. @@ -46,11 +46,11 @@ void AddUndoAction::addElement(Layer* layer, Element* e, int pos) (GCompareFunc) PageLayerPosEntry::cmp); } -bool AddUndoAction::redo(Control* control) +bool AddUndoAction::redo(Control*) { XOJ_CHECK_TYPE(AddUndoAction); - if (this->elements == NULL) + if (this->elements == nullptr) { g_warning("Could not undo AddUndoAction, there is nothing to undo"); @@ -58,9 +58,9 @@ bool AddUndoAction::redo(Control* control) return false; } - for (GList* l = this->elements; l != NULL; l = l->next) + for (GList* l = this->elements; l != nullptr; l = l->next) { - PageLayerPosEntry* e = (PageLayerPosEntry*) l->data; + auto e = (PageLayerPosEntry*) l->data; e->layer->insertElement(e->element, e->pos); this->page->fireElementChanged(e->element); } @@ -69,11 +69,11 @@ bool AddUndoAction::redo(Control* control) return true; } -bool AddUndoAction::undo(Control* control) +bool AddUndoAction::undo(Control*) { XOJ_CHECK_TYPE(AddUndoAction); - if (this->elements == NULL) + if (this->elements == nullptr) { g_warning("Could not redo AddUndoAction, there is nothing to redo"); @@ -81,9 +81,9 @@ bool AddUndoAction::undo(Control* control) return false; } - for (GList* l = this->elements; l != NULL; l = l->next) + for (GList* l = this->elements; l != nullptr; l = l->next) { - PageLayerPosEntry* e = (PageLayerPosEntry*) l->data; + auto e = (PageLayerPosEntry*) l->data; e->layer->removeElement(e->element, false); this->page->fireElementChanged(e->element); } @@ -107,35 +107,36 @@ string AddUndoAction::getText() { text = _("Paste"); - if (this->elements != NULL) + if (this->elements != nullptr) { ElementType type = ((PageLayerPosEntry*) this->elements->data)->element->getType(); - for (GList* l = this->elements->next; l != NULL; l = l->next) + for (GList* l = this->elements->next; l != nullptr; l = l->next) { - PageLayerPosEntry* e = (PageLayerPosEntry*) l->data; + auto e = (PageLayerPosEntry*) l->data; if (type != e->element->getType()) { - text += _(" elements"); + text += " "; + text += _("elements"); return text; } } - if (type == ELEMENT_STROKE) + text += " "; + switch (type) { - text += _(" stroke"); - } - else if (type == ELEMENT_TEXT) - { - text += _(" text"); - } - else if (type == ELEMENT_IMAGE) - { - text += _(" image"); - } - else if (type == ELEMENT_TEXIMAGE) - { - text += _(" latex"); + case ELEMENT_STROKE: + text += _("stroke"); + break; + case ELEMENT_IMAGE: + text += _("image"); + break; + case ELEMENT_TEXIMAGE: + text += _("latex"); + break; + case ELEMENT_TEXT: + text += _("text"); + break; } } } diff --git a/src/undo/AddUndoAction.h b/src/undo/AddUndoAction.h index 342a6b71..af548236 100644 --- a/src/undo/AddUndoAction.h +++ b/src/undo/AddUndoAction.h @@ -21,20 +21,20 @@ class Redrawable; class AddUndoAction : public UndoAction { public: - AddUndoAction(PageRef page, bool eraser); - virtual ~AddUndoAction(); + AddUndoAction(const PageRef& page, bool eraser); + ~AddUndoAction() override; public: - virtual bool undo(Control* control); - virtual bool redo(Control* control); + bool undo(Control*) override; + bool redo(Control*) override; void addElement(Layer* layer, Element* e, int pos); - virtual string getText(); + string getText() override; private: XOJ_TYPE_ATTRIB; - GList* elements = NULL; + GList* elements = nullptr; bool eraser = false; };