lib

KoSetPropCommand.h
1/* This file is part of the KDE project
2 Copyright (C) 2000 Werner Trobin <trobin@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#ifndef KOGENCOMMAND_H
21#define KOGENCOMMAND_H
22
23#include <kcommand.h>
24
29template<class Property, class Object, void (Object::* Function) (Property)> class KoSetBasicPropCommand : public KNamedCommand {
30
31public:
32 KoSetBasicPropCommand(Object *object, const TQString &name) : KNamedCommand(name), m_object(object) {}
33 KoSetBasicPropCommand(Object *object, const TQString &name,
34 const Property &oldProperty, const Property &newProperty) : KNamedCommand(name),
35 m_object(object), m_oldProperty(oldProperty), m_newProperty(newProperty) {}
36 virtual ~KoSetBasicPropCommand() {}
37
38 virtual void execute() { if(m_object) (m_object->*Function)(m_newProperty); }
39 virtual void unexecute() { if(m_object) (m_object->*Function)(m_oldProperty); }
40
41 void setOldProperty(const Property &oldProperty) { m_oldProperty=oldProperty; }
42 const Property &oldProperty() const { return m_oldProperty; }
43 void setNewProperty(const Property &newProperty) { m_newProperty=newProperty; }
44 const Property &newProperty() const { return m_newProperty; }
45
46private:
47 // Don't copy or assign this stuff
48 KoSetBasicPropCommand(const KoSetBasicPropCommand<Property, Object, Function> &rhs);
49 KoSetBasicPropCommand &operator=(const KoSetBasicPropCommand<Property, Object, Function> &rhs);
50
51 Object *m_object;
52 Property m_oldProperty, m_newProperty;
53};
54
59template<class Property, class Object, void (Object::* Function) (const Property &)> class KoSetPropCommand : public KNamedCommand {
60
61public:
62 KoSetPropCommand(Object *object, const TQString &name) : KNamedCommand(name), m_object(object) {}
63 KoSetPropCommand(Object *object, const TQString &name,
64 const Property &oldProperty, const Property &newProperty) : KNamedCommand(name),
65 m_object(object), m_oldProperty(oldProperty), m_newProperty(newProperty) {}
66 virtual ~KoSetPropCommand() {}
67
68 virtual void execute() { if(m_object) (m_object->*Function)(m_newProperty); }
69 virtual void unexecute() { if(m_object) (m_object->*Function)(m_oldProperty); }
70
71 void setOldProperty(const Property &oldProperty) { m_oldProperty=oldProperty; }
72 const Property &oldProperty() const { return m_oldProperty; }
73 void setNewProperty(const Property &newProperty) { m_newProperty=newProperty; }
74 const Property &newProperty() const { return m_newProperty; }
75
76private:
77 // Don't copy or assign this stuff
78 KoSetPropCommand(const KoSetPropCommand<Property, Object, Function> &rhs);
79 KoSetPropCommand &operator=(const KoSetPropCommand<Property, Object, Function> &rhs);
80
81 Object *m_object;
82 Property m_oldProperty, m_newProperty;
83};
84
85#endif /* KOGENCOMMAND_H */
86
virtual void unexecute()=0
virtual void execute()=0
virtual TQString name() const
KNamedCommand(const TQString &name)