update
[kdegraphics.git] / kolourpaint / commands / kpMacroCommand.cpp
blob902c103bb1b70dfa63af40fa95c4d1775e652df4
2 /*
3 Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
4 All rights reserved.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
10 1. Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #define DEBUG_KP_COMMAND_HISTORY 0
32 #include <kpMacroCommand.h>
34 #include <climits>
36 #include <QtAlgorithms>
39 struct kpMacroCommandPrivate
44 kpMacroCommand::kpMacroCommand (const QString &name, kpCommandEnvironment *environ)
45 : kpNamedCommand (name, environ),
46 d (new kpMacroCommandPrivate ())
50 kpMacroCommand::~kpMacroCommand ()
52 qDeleteAll (m_commandList.begin (), m_commandList.end ());
53 delete d;
57 // public virtual [base kpCommand]
58 kpCommandSize::SizeType kpMacroCommand::size () const
60 #if DEBUG_KP_COMMAND_HISTORY && 0
61 kDebug () << "kpMacroCommand::size()";
62 #endif
63 SizeType s = 0;
65 #if DEBUG_KP_COMMAND_HISTORY && 0
66 kDebug () << "\tcalculating:";
67 #endif
68 foreach (kpCommand *cmd, m_commandList)
70 #if DEBUG_KP_COMMAND_HISTORY && 0
71 kDebug () << "\t\tcurrentSize=" << s << " + "
72 << cmd->name () << ".size=" << cmd->size ()
73 << endl;
74 #endif
75 s += cmd->size ();
78 #if DEBUG_KP_COMMAND_HISTORY && 0
79 kDebug () << "\treturning " << s;
80 #endif
81 return s;
85 // public virtual [base kpCommand]
86 void kpMacroCommand::execute ()
88 #if DEBUG_KP_COMMAND_HISTORY
89 kDebug () << "kpMacroCommand::execute()";
90 #endif
91 for (QLinkedList <kpCommand *>::const_iterator it = m_commandList.begin ();
92 it != m_commandList.end ();
93 it++)
95 #if DEBUG_KP_COMMAND_HISTORY
96 kDebug () << "\texecuting " << (*it)->name ();
97 #endif
98 (*it)->execute ();
102 // public virtual [base kpCommand]
103 void kpMacroCommand::unexecute ()
105 #if DEBUG_KP_COMMAND_HISTORY
106 kDebug () << "kpMacroCommand::unexecute()";
107 #endif
108 QLinkedList <kpCommand *>::const_iterator it = m_commandList.end ();
109 it--;
111 while (it != m_commandList.end ())
113 #if DEBUG_KP_COMMAND_HISTORY
114 kDebug () << "\tunexecuting " << (*it)->name ();
115 #endif
116 (*it)->unexecute ();
118 it--;
123 // public
124 void kpMacroCommand::addCommand (kpCommand *command)
126 m_commandList.push_back (command);