kexi

action.cpp
1/***************************************************************************
2 * This file is part of the KDE project
3 * copyright (C) 2005 by Sebastian Sauer (mail@dipe.org)
4 * copyright (C) 2005 by Tobi Krebs (tobi.krebs@gmail.com)
5 * copyright (C) 2006 by Sascha Kupper (kusato@kfnv.de)
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this program; see the file COPYING. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 ***************************************************************************/
20
21#include "action.h"
22
23#include <kdebug.h>
24
25using namespace KoMacro;
26
27namespace KoMacro {
28
33 class Action::Private
34 {
35 public:
36
40 TQString name;
41
45 TQString text;
46
50 TQString comment;
51
56 Variable::Map varmap;
57
63 TQStringList varnames;
64
65 };
66
67}
68
69Action::Action(const TQString& name, const TQString& text)
70 : TQObject()
71 , TDEShared()
72 , d( new Private() ) // create the private d-pointer instance.
73{
74 kdDebug() << "Action::Action() name=" << name << endl;
75 d->name = name;
77
78 // Publish this action.
79 KoMacro::Manager::self()->publishAction( TDESharedPtr<Action>(this) );
80}
81
83{
84 //kdDebug() << TQString("Action::~Action() name=\"%1\"").arg(name()) << endl;
85
86 // destroy the private d-pointer instance.
87 delete d;
88}
89
90const TQString Action::toString() const
91{
92 return TQString("Action:%1").arg(name());
93}
94
95const TQString Action::name() const
96{
97 return d->name;
98}
99
100void Action::setName(const TQString& name)
101{
102 d->name = name;
103}
104
105const TQString Action::text() const
106{
107 return d->text;
108}
109
110void Action::setText(const TQString& text)
111{
112 d->text = text;
113}
114
115const TQString Action::comment() const
116{
117 return d->comment;
118}
119
120void Action::setComment(const TQString& comment)
121{
122 d->comment = comment;
123}
124
125bool Action::hasVariable(const TQString& name) const
126{
127 return d->varmap.contains(name);
128}
129
130TDESharedPtr<Variable> Action::variable(const TQString& name) const
131{
132 return d->varmap.contains(name) ? d->varmap[name] : TDESharedPtr<Variable>(0);
133}
134
136{
137 return d->varmap;
138}
139
140TQStringList Action::variableNames() const
141{
142 return d->varnames;
143}
144
145void Action::setVariable(TDESharedPtr<Variable> variable)
146{
147 const TQString name = variable->name();
148 if(! d->varmap.contains(name)) {
149 d->varnames.append(name);
150 }
151 d->varmap.replace(name, variable);
152}
153
154void Action::setVariable(const TQString& name, const TQString& text, const TQVariant& variant)
155{
156 Variable* variable = new Variable(variant);
157 variable->setName(name);
158 variable->setText(text);
159 setVariable( TDESharedPtr<Variable>(variable) );
160}
161
162void Action::removeVariable(const TQString& name)
163{
164 if(d->varmap.contains(name)) {
165 d->varmap.remove(name);
166 d->varnames.remove(name);
167 }
168}
169
170#include "action.moc"
void setComment(const TQString &comment)
Set the comment associated with this action.
Definition action.cpp:120
const TQString comment() const
Definition action.cpp:115
void setText(const TQString &text)
Set the i18n-caption text this Action has.
Definition action.cpp:110
TDESharedPtr< Variable > variable(const TQString &name) const
Definition action.cpp:130
Action(const TQString &name, const TQString &text=TQString())
Constructor.
Definition action.cpp:69
virtual const TQString toString() const
Definition action.cpp:90
void removeVariable(const TQString &name)
Remove the variable defined with name .
Definition action.cpp:162
const TQString name() const
The name this Action has.
Definition action.cpp:95
Variable::Map variables() const
Definition action.cpp:135
void setName(const TQString &name)
Set the name of the Action to name .
Definition action.cpp:100
TQStringList variableNames() const
Definition action.cpp:140
void setVariable(TDESharedPtr< Variable > variable)
Append the Variable variable to list of variables this Action provides.
Definition action.cpp:145
bool hasVariable(const TQString &name) const
Definition action.cpp:125
virtual ~Action()
Destructor.
Definition action.cpp:82
const TQString text() const
Definition action.cpp:105
static Manager * self()
Definition manager.cpp:76
void publishAction(TDESharedPtr< Action > action)
Publish the Action action .
Definition manager.cpp:147
A variable value used to provide abstract access to variables.
Definition variable.h:39
TQMap< TQString, TDESharedPtr< Variable > > Map
A map of variables.
Definition variable.h:66