kexi

action.cpp

00001 /***************************************************************************
00002  * This file is part of the KDE project
00003  * copyright (C) 2005 by Sebastian Sauer (mail@dipe.org)
00004  * copyright (C) 2005 by Tobi Krebs (tobi.krebs@gmail.com)
00005  * copyright (C) 2006 by Sascha Kupper (kusato@kfnv.de)
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Library General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2 of the License, or (at your option) any later version.
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Library General Public License for more details.
00015  * You should have received a copy of the GNU Library General Public License
00016  * along with this program; see the file COPYING.  If not, write to
00017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019  ***************************************************************************/
00020 
00021 #include "action.h"
00022 
00023 #include <kdebug.h>
00024 
00025 using namespace KoMacro;
00026 
00027 namespace KoMacro {
00028 
00033     class Action::Private
00034     {
00035         public:
00036 
00040             QString name;
00041 
00045             QString text;
00046 
00050             QString comment;
00051 
00056             Variable::Map varmap;
00057 
00063             QStringList varnames;
00064 
00065     };
00066 
00067 }
00068 
00069 Action::Action(const QString& name, const QString& text)
00070     : QObject()
00071     , KShared()
00072     , d( new Private() ) // create the private d-pointer instance.
00073 {
00074     kdDebug() << "Action::Action() name=" << name << endl;
00075     d->name = name;
00076     setText(text);
00077 
00078     // Publish this action.
00079     KoMacro::Manager::self()->publishAction( KSharedPtr<Action>(this) );
00080 }
00081 
00082 Action::~Action()
00083 {
00084     //kdDebug() << QString("Action::~Action() name=\"%1\"").arg(name()) << endl;
00085 
00086     // destroy the private d-pointer instance.
00087     delete d;
00088 }
00089 
00090 const QString Action::toString() const
00091 {
00092     return QString("Action:%1").arg(name());
00093 }
00094 
00095 const QString Action::name() const
00096 {
00097     return d->name;
00098 }
00099 
00100 void Action::setName(const QString& name)
00101 {
00102     d->name = name;
00103 }
00104 
00105 const QString Action::text() const
00106 {
00107     return d->text;
00108 }
00109 
00110 void Action::setText(const QString& text)
00111 {
00112     d->text = text;
00113 }
00114 
00115 const QString Action::comment() const
00116 {
00117     return d->comment;
00118 }
00119 
00120 void Action::setComment(const QString& comment)
00121 {
00122     d->comment = comment;
00123 }
00124 
00125 bool Action::hasVariable(const QString& name) const
00126 {
00127     return d->varmap.contains(name);
00128 }
00129 
00130 KSharedPtr<Variable> Action::variable(const QString& name) const
00131 {
00132     return d->varmap.contains(name) ? d->varmap[name] : KSharedPtr<Variable>(0);
00133 }
00134 
00135 Variable::Map Action::variables() const
00136 {
00137     return d->varmap;
00138 }
00139 
00140 QStringList Action::variableNames() const
00141 {
00142     return d->varnames;
00143 }
00144 
00145 void Action::setVariable(KSharedPtr<Variable> variable)
00146 {
00147     const QString name = variable->name();
00148     if(! d->varmap.contains(name)) {
00149         d->varnames.append(name);
00150     }
00151     d->varmap.replace(name, variable);
00152 }
00153 
00154 void Action::setVariable(const QString& name, const QString& text, const QVariant& variant)
00155 {
00156     Variable* variable = new Variable(variant);
00157     variable->setName(name);
00158     variable->setText(text);
00159     setVariable( KSharedPtr<Variable>(variable) );
00160 }
00161 
00162 void Action::removeVariable(const QString& name)
00163 {
00164     if(d->varmap.contains(name)) {
00165         d->varmap.remove(name);
00166         d->varnames.remove(name);
00167     }
00168 }
00169 
00170 #include "action.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys