1 /* 2 SPDX-FileCopyrightText: 2017 Nicolas Carion 3 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 4 */ 5 6 #include "undohelper.hpp" 7 #ifdef CRASH_AUTO_TEST 8 #include "logger.hpp" 9 #endif 10 #include <QDebug> 11 #include <utility> FunctionalUndoCommand(Fun undo,Fun redo,const QString & text,QUndoCommand * parent)12FunctionalUndoCommand::FunctionalUndoCommand(Fun undo, Fun redo, const QString &text, QUndoCommand *parent) 13 : QUndoCommand(parent) 14 , m_undo(std::move(undo)) 15 , m_redo(std::move(redo)) 16 , m_undone(false) 17 { 18 setText(text); 19 } 20 undo()21void FunctionalUndoCommand::undo() 22 { 23 // qDebug() << "UNDOING " <<text(); 24 #ifdef CRASH_AUTO_TEST 25 Logger::log_undo(true); 26 #endif 27 m_undone = true; 28 bool res = m_undo(); 29 Q_ASSERT(res); 30 } 31 redo()32void FunctionalUndoCommand::redo() 33 { 34 if (m_undone) { 35 // qDebug() << "REDOING " <<text(); 36 #ifdef CRASH_AUTO_TEST 37 Logger::log_undo(false); 38 #endif 39 bool res = m_redo(); 40 Q_ASSERT(res); 41 } 42 } 43