Debian Codegraph @

src/libs/kernel/commands/MacroCommand.cpp

raw
1 /* This file is part of the KDE project
2 * SPDX-FileCopyrightText: 2019 Dag Andersen <[email protected]>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7 // clazy:excludeall=qstring-arg
8 #include "MacroCommand.h"
9 #include "kptdebug.h"
10
11 #include <QApplication>
12
13
14 using namespace KPlato;
15
16 MacroCommand::~MacroCommand()
17 {
18 while (! cmds.isEmpty()) {
19 delete cmds.takeLast();
20 }
21 }
22
23 void MacroCommand::addCommand(KUndo2Command *cmd)
24 {
25 cmds.append(cmd);
26 }
27
28 void MacroCommand::execute()
29 {
30 if (m_busyCursorEnabled) {
31 QApplication::setOverrideCursor(Qt::BusyCursor);
32 }
33 for (KUndo2Command *c : std::as_const(cmds)) {
34 c->redo();
35 }
36 if (m_busyCursorEnabled) {
37 QApplication::restoreOverrideCursor();
38 }
39 }
40
41 void MacroCommand::unexecute()
42 {
43 if (m_busyCursorEnabled) {
44 QApplication::setOverrideCursor(Qt::BusyCursor);
45 }
46 for (int i = cmds.count() - 1; i >= 0; --i) {
47 cmds.at(i)->undo();
48 }
49 if (m_busyCursorEnabled) {
50 QApplication::restoreOverrideCursor();
51 }
52 }