diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
commit | 8362bf63dea22bbf6736609b0f49c152f975eb63 (patch) | |
tree | 0eea3928e39e50fae91d4e68b21b1e6cbae25604 /lib/kofficecore/KoSetPropCommand.h | |
download | koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.tar.gz koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.zip |
Added old abandoned KDE3 version of koffice
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'lib/kofficecore/KoSetPropCommand.h')
-rw-r--r-- | lib/kofficecore/KoSetPropCommand.h | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/lib/kofficecore/KoSetPropCommand.h b/lib/kofficecore/KoSetPropCommand.h new file mode 100644 index 00000000..53ee73bf --- /dev/null +++ b/lib/kofficecore/KoSetPropCommand.h @@ -0,0 +1,86 @@ +/* This file is part of the KDE project + Copyright (C) 2000 Werner Trobin <[email protected]> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#ifndef KOGENCOMMAND_H +#define KOGENCOMMAND_H + +#include <kcommand.h> + +/** + * Generic command to set a property on an object. + * This variant is for simple types, where the setter method takes a value. + */ +template<class Property, class Object, void (Object::* Function) (Property)> class KoSetBasicPropCommand : public KNamedCommand { + +public: + KoSetBasicPropCommand(Object *object, const QString &name) : KNamedCommand(name), m_object(object) {} + KoSetBasicPropCommand(Object *object, const QString &name, + const Property &oldProperty, const Property &newProperty) : KNamedCommand(name), + m_object(object), m_oldProperty(oldProperty), m_newProperty(newProperty) {} + virtual ~KoSetBasicPropCommand() {} + + virtual void execute() { if(m_object) (m_object->*Function)(m_newProperty); } + virtual void unexecute() { if(m_object) (m_object->*Function)(m_oldProperty); } + + void setOldProperty(const Property &oldProperty) { m_oldProperty=oldProperty; } + const Property &oldProperty() const { return m_oldProperty; } + void setNewProperty(const Property &newProperty) { m_newProperty=newProperty; } + const Property &newProperty() const { return m_newProperty; } + +private: + // Don't copy or assign this stuff + KoSetBasicPropCommand(const KoSetBasicPropCommand<Property, Object, Function> &rhs); + KoSetBasicPropCommand &operator=(const KoSetBasicPropCommand<Property, Object, Function> &rhs); + + Object *m_object; + Property m_oldProperty, m_newProperty; +}; + +/** + * Generic command to set a property on an object. + * This variant is for non-trivial types, where the setter method takes a const reference. + */ +template<class Property, class Object, void (Object::* Function) (const Property &)> class KoSetPropCommand : public KNamedCommand { + +public: + KoSetPropCommand(Object *object, const QString &name) : KNamedCommand(name), m_object(object) {} + KoSetPropCommand(Object *object, const QString &name, + const Property &oldProperty, const Property &newProperty) : KNamedCommand(name), + m_object(object), m_oldProperty(oldProperty), m_newProperty(newProperty) {} + virtual ~KoSetPropCommand() {} + + virtual void execute() { if(m_object) (m_object->*Function)(m_newProperty); } + virtual void unexecute() { if(m_object) (m_object->*Function)(m_oldProperty); } + + void setOldProperty(const Property &oldProperty) { m_oldProperty=oldProperty; } + const Property &oldProperty() const { return m_oldProperty; } + void setNewProperty(const Property &newProperty) { m_newProperty=newProperty; } + const Property &newProperty() const { return m_newProperty; } + +private: + // Don't copy or assign this stuff + KoSetPropCommand(const KoSetPropCommand<Property, Object, Function> &rhs); + KoSetPropCommand &operator=(const KoSetPropCommand<Property, Object, Function> &rhs); + + Object *m_object; + Property m_oldProperty, m_newProperty; +}; + +#endif /* KOGENCOMMAND_H */ + |