diff --git a/gui/stacksupport.h b/gui/stacksupport.h index 844a4dd..0e5b25b 100644 --- a/gui/stacksupport.h +++ b/gui/stacksupport.h @@ -5,6 +5,8 @@ #include +#include + namespace QtGui { class StackAbsorper; @@ -17,7 +19,7 @@ public: protected: QUndoStack *undoStack(); - bool push(CustomUndoCommand *command); + bool push(std::unique_ptr command); void clearUndoStack(); private: @@ -35,7 +37,7 @@ inline QUndoStack *StackSupport::undoStack() /*! * \brief Pushes the specified custom undo \a command to the undo stack and returns whether the redo action was successful. */ -inline bool StackSupport::push(CustomUndoCommand *command) +inline bool StackSupport::push(std::unique_ptr command) { if (!m_undoStack) { return false; @@ -43,7 +45,7 @@ inline bool StackSupport::push(CustomUndoCommand *command) if (command->isNoop()) { return true; // doing nothing can never fail } - m_undoStack->push(command); + m_undoStack->push(command.release()); return command->redoResult(); } diff --git a/model/entrymodel.cpp b/model/entrymodel.cpp index 88ab466..7706ad6 100644 --- a/model/entrymodel.cpp +++ b/model/entrymodel.cpp @@ -13,6 +13,7 @@ #include #include +#include #include using namespace std; @@ -266,7 +267,7 @@ bool EntryModel::setData(const QModelIndex &index, const QVariant &value, int ro { #ifdef PASSWORD_MANAGER_GUI_QTWIDGETS if (undoStack()) { - return push(new EntryModelSetValueCommand(this, index, value, role)); + return push(make_unique(this, index, value, role)); } #endif if (!index.isValid()) { @@ -388,7 +389,7 @@ bool EntryModel::insertRows(int row, int count, const QModelIndex &parent) { #ifdef PASSWORD_MANAGER_GUI_QTWIDGETS if (undoStack()) { - return push(new EntryModelInsertRowsCommand(this, row, count, parent)); + return push(make_unique(this, row, count, parent)); } #endif if (!parent.isValid()) { @@ -421,7 +422,7 @@ bool EntryModel::removeRows(int row, int count, const QModelIndex &parent) { #ifdef PASSWORD_MANAGER_GUI_QTWIDGETS if (undoStack()) { - return push(new EntryModelRemoveRowsCommand(this, row, count, parent)); + return push(make_unique(this, row, count, parent)); } #endif if (!parent.isValid() || count <= 0) { @@ -441,7 +442,7 @@ bool EntryModel::moveRows(const QModelIndex &sourceParent, int sourceRow, int co { #ifdef PASSWORD_MANAGER_GUI_QTWIDGETS if (undoStack()) { - return push(new EntryModelMoveRowsCommand(this, sourceParent, sourceRow, count, destinationParent, destinationChild)); + return push(make_unique(this, sourceParent, sourceRow, count, destinationParent, destinationChild)); } #endif // check validation of specified arguments diff --git a/model/fieldmodel.cpp b/model/fieldmodel.cpp index 325e991..85e2694 100644 --- a/model/fieldmodel.cpp +++ b/model/fieldmodel.cpp @@ -9,6 +9,8 @@ #include #include +#include + using namespace std; using namespace Io; @@ -153,7 +155,7 @@ bool FieldModel::setData(const QModelIndex &index, const QVariant &value, int ro { #if PASSWORD_MANAGER_GUI_QTWIDGETS if (undoStack()) { - return push(new FieldModelSetValueCommand(this, index, value, role)); + return push(make_unique(this, index, value, role)); } #endif if (!index.isValid() || !m_fields || index.row() < 0) { @@ -294,7 +296,7 @@ bool FieldModel::insertRows(int row, int count, const QModelIndex &parent) { #ifdef PASSWORD_MANAGER_GUI_QTWIDGETS if (undoStack()) { - return push(new FieldModelInsertRowsCommand(this, row, count)); + return push(make_unique(this, row, count)); } #endif if (parent.isValid() || row < 0 || count <= 0 || static_cast(row) > m_fields->size()) { @@ -310,7 +312,7 @@ bool FieldModel::removeRows(int row, int count, const QModelIndex &parent) { #ifdef PASSWORD_MANAGER_GUI_QTWIDGETS if (undoStack()) { - return push(new FieldModelRemoveRowsCommand(this, row, count)); + return push(make_unique(this, row, count)); } #endif if (parent.isValid() || row < 0 || count <= 0 || static_cast(row + count) > m_fields->size()) {