File indexing completed on 2022-10-04 15:37:25

0001 /*
0002     SPDX-FileCopyrightText: 2017 Nicolas Carion
0003     SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 */
0005 
0006 #include "undohelper.hpp"
0007 #ifdef CRASH_AUTO_TEST
0008 #include "logger.hpp"
0009 #endif
0010 #include <QDebug>
0011 #include <utility>
0012 FunctionalUndoCommand::FunctionalUndoCommand(Fun undo, Fun redo, const QString &text, QUndoCommand *parent)
0013     : QUndoCommand(parent)
0014     , m_undo(std::move(undo))
0015     , m_redo(std::move(redo))
0016     , m_undone(false)
0017 {
0018     setText(text);
0019 }
0020 
0021 void FunctionalUndoCommand::undo()
0022 {
0023     // qDebug() << "UNDOING " <<text();
0024 #ifdef CRASH_AUTO_TEST
0025     Logger::log_undo(true);
0026 #endif
0027     m_undone = true;
0028     bool res = m_undo();
0029     Q_ASSERT(res);
0030 }
0031 
0032 void FunctionalUndoCommand::redo()
0033 {
0034     if (m_undone) {
0035         // qDebug() << "REDOING " <<text();
0036 #ifdef CRASH_AUTO_TEST
0037         Logger::log_undo(false);
0038 #endif
0039         bool res = m_redo();
0040         Q_ASSERT(res);
0041     }
0042 }