kexitabledesignercommands.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2006 Jaroslaw Staniek <js@iidea.pl>
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#include <tqdom.h>
20#include <tqwidget.h>
21#include <tqlayout.h>
22#include <tqlabel.h>
23#include <tqsplitter.h>
24#include <tqmetaobject.h>
25
26#include <kdebug.h>
27#include <tdelocale.h>
28#include <tdepopupmenu.h>
29#include <tdemessagebox.h>
30#include <tdeaccelmanager.h>
31
32#include <koproperty/property.h>
33
34#include "kexitabledesignercommands.h"
35
36using namespace KexiTableDesignerCommands;
37
38
39Command::Command(KexiTableDesignerView* view)
40 : KCommand()
41 , m_view(view)
42{
43}
44
45Command::~Command()
46{
47}
48
49//--------------------------------------------------------
50
52 const KoProperty::Set& set, const TQCString& propertyName, const TQVariant& oldValue, const TQVariant& newValue,
53 KoProperty::Property::ListData* const oldListData, KoProperty::Property::ListData* const newListData)
54 : Command(view)
55 , m_alterTableAction(
56 propertyName=="name" ? oldValue.toString() : set.property("name").value().toString(),
57 propertyName, newValue, set["uid"].value().toInt())
58 , m_oldValue(oldValue)
59// , m_fieldUID(set["uid"].value().toInt())
60 , m_oldListData( oldListData ? new KoProperty::Property::ListData(*oldListData) : 0 )
61 , m_listData( newListData ? new KoProperty::Property::ListData(*newListData) : 0 )
62{
63 kexipluginsdbg << "ChangeFieldPropertyCommand: " << debugString() << endl;
64}
65
66ChangeFieldPropertyCommand::~ChangeFieldPropertyCommand()
67{
68 delete m_oldListData;
69 delete m_listData;
70}
71
72TQString ChangeFieldPropertyCommand::name() const
73{
74 return i18n("Change \"%1\" property for table field from \"%2\" to \"%3\"")
75 .arg(m_alterTableAction.propertyName()).arg(m_oldValue.toString())
76 .arg(m_alterTableAction.newValue().toString());
77}
78
79TQString ChangeFieldPropertyCommand::debugString()
80{
81 TQString s( name() );
82 if (m_oldListData || m_listData)
83 s += TQString("\nAnd list data from [%1]\n to [%2]")
84 .arg( m_oldListData ?
85 TQString("%1 -> %2")
86 .arg(m_oldListData->keysAsStringList().join(",")).arg(m_oldListData->names.join(","))
87 : TQString("<NONE>"))
88 .arg( m_listData ?
89 TQString("%1 -> %2")
90 .arg(m_listData->keysAsStringList().join(",")).arg(m_listData->names.join(","))
91 : TQString("<NONE>"));
92 return s + TQString(" (UID=%1)").arg(m_alterTableAction.uid());
93}
94
95void ChangeFieldPropertyCommand::execute()
96{
97 m_view->changeFieldProperty(
98 m_alterTableAction.uid(),
99 m_alterTableAction.propertyName().latin1(),
100 m_alterTableAction.newValue(), m_listData );
101}
102
103void ChangeFieldPropertyCommand::unexecute()
104{
105 m_view->changeFieldProperty(
106 m_alterTableAction.uid(),
107 m_alterTableAction.propertyName().latin1(),
108 m_oldValue, m_oldListData );
109}
110
112{
113 if (m_alterTableAction.propertyName()=="subType") {//skip these properties
114 return 0;
115 }
116 return new KexiDB::AlterTableHandler::ChangeFieldPropertyAction( m_alterTableAction );
117}
118
119//--------------------------------------------------------
120
122 const KoProperty::Set* set)
123 : Command(view)
124 , m_alterTableAction( set ? (*set)["name"].value().toString() : TQString(),
125 set ? (*set)["uid"].value().toInt() : -1 )
126 , m_set( set ? new KoProperty::Set(*set /*deep copy*/) : 0 )
127 , m_fieldIndex(fieldIndex)
128{
129}
130
131RemoveFieldCommand::~RemoveFieldCommand()
132{
133 delete m_set;
134}
135
136TQString RemoveFieldCommand::name() const
137{
138 if (m_set)
139 return i18n("Remove table field \"%1\"").arg(m_alterTableAction.fieldName());
140
141 return TQString("Remove empty row at position %1").arg(m_fieldIndex);
142}
143
144void RemoveFieldCommand::execute()
145{
146// m_view->deleteField( m_fieldIndex );
147 m_view->deleteRow( m_fieldIndex );
148}
149
150void RemoveFieldCommand::unexecute()
151{
152 m_view->insertEmptyRow(m_fieldIndex);
153 if (m_set)
154 m_view->insertField( m_fieldIndex, *m_set );
155}
156
157TQString RemoveFieldCommand::debugString()
158{
159 if (!m_set)
160 return name();
161
162 return name() + "\nAT ROW " + TQString::number(m_fieldIndex)
163 + ", FIELD: " + (*m_set)["caption"].value().toString()
164 + TQString(" (UID=%1)").arg(m_alterTableAction.uid());
165}
166
171
172//--------------------------------------------------------
173
174InsertFieldCommand::InsertFieldCommand( KexiTableDesignerView* view,
175 int fieldIndex/*, const KexiDB::Field& field*/, const KoProperty::Set& set )
176 : Command(view)
177 , m_alterTableAction(0) //fieldIndex, new KexiDB::Field(field) /*deep copy*/)
178 , m_set( set ) //? new KoProperty::Set(*set) : 0 )
179{
180 KexiDB::Field *f = view->buildField( m_set );
181 if (f)
182 m_alterTableAction = new KexiDB::AlterTableHandler::InsertFieldAction(
183 fieldIndex, f, set["uid"].value().toInt());
184 else //null action
185 m_alterTableAction = new KexiDB::AlterTableHandler::InsertFieldAction(true);
186}
187
188InsertFieldCommand::~InsertFieldCommand()
189{
190 delete m_alterTableAction;
191}
192
193TQString InsertFieldCommand::name() const
194{
195 return i18n("Insert table field \"%1\"").arg(m_set["caption"].value().toString());
196}
197
198void InsertFieldCommand::execute()
199{
200 m_view->insertField( m_alterTableAction->index(), /*m_alterTableAction.field(),*/ m_set );
201}
202
203void InsertFieldCommand::unexecute()
204{
205 m_view->clearRow( m_alterTableAction->index() );//m_alterTableAction.index() );
206}
207
212
213//--------------------------------------------------------
214
216 const KoProperty::Set& set, const TQCString& propertyName, bool visible)
217 : Command(view)
218 , m_alterTableAction(set.property("name").value().toString(), propertyName, visible, set["uid"].value().toInt())
219// , m_fieldUID(set["uid"].value().toInt())
220 , m_oldVisibility( set.property(propertyName).isVisible() )
221{
222 kexipluginsdbg << "ChangePropertyVisibilityCommand: " << debugString() << endl;
223}
224
225ChangePropertyVisibilityCommand::~ChangePropertyVisibilityCommand()
226{
227}
228
229TQString ChangePropertyVisibilityCommand::name() const
230{
231 return TQString("[internal] Change \"%1\" visibility from \"%2\" to \"%3\"")
232 .arg(m_alterTableAction.propertyName())
233 .arg(m_oldVisibility ? "true" : "false")
234 .arg(m_alterTableAction.newValue().toBool() ? "true" : "false");
235}
236
237void ChangePropertyVisibilityCommand::execute()
238{
239 m_view->changePropertyVisibility(
240 m_alterTableAction.uid(),
241 m_alterTableAction.propertyName().latin1(),
242 m_alterTableAction.newValue().toBool() );
243}
244
245void ChangePropertyVisibilityCommand::unexecute()
246{
247 m_view->changePropertyVisibility(
248 m_alterTableAction.uid(),
249 m_alterTableAction.propertyName().latin1(),
250 m_oldVisibility );
251}
252
253//--------------------------------------------------------
254
256 : Command(view)
257 , m_alterTableAction(true) //unused, null action
258 , m_row(row)
259{
260}
261
262InsertEmptyRowCommand::~InsertEmptyRowCommand()
263{
264}
265
266TQString InsertEmptyRowCommand::name() const
267{
268 return TQString("Insert empty row at position %1").arg(m_row);
269}
270
271void InsertEmptyRowCommand::execute()
272{
273 m_view->insertEmptyRow( m_row );
274}
275
276void InsertEmptyRowCommand::unexecute()
277{
278 // let's assume the row is empty...
279 m_view->deleteRow( m_row );
280}
281
Abstract base class used for implementing all the AlterTable actions.
Definition alter.h:157
Defines an action for inserting a single table field.
Definition alter.h:322
Defines an action for removing a single table field.
Definition alter.h:301
Meta-data for a field.
Definition field.h:73
ChangeFieldPropertyCommand(KexiTableDesignerView *view, const KoProperty::Set &set, const TQCString &propertyName, const TQVariant &oldValue, const TQVariant &newValue, KoProperty::Property::ListData *const oldListData=0, KoProperty::Property::ListData *const newListData=0)
virtual KexiDB::AlterTableHandler::ActionBase * createAction()
Used to collect actions data for AlterTableHandler Can return 0 if the action should not be passed to...
ChangePropertyVisibilityCommand(KexiTableDesignerView *view, const KoProperty::Set &set, const TQCString &propertyName, bool visible)
Base class for all Table Designer's commands.
InsertEmptyRowCommand(KexiTableDesignerView *view, int row)
virtual KexiDB::AlterTableHandler::ActionBase * createAction()
Used to collect actions data for AlterTableHandler Can return 0 if the action should not be passed to...
RemoveFieldCommand(KexiTableDesignerView *view, int fieldIndex, const KoProperty::Set *set)
virtual KexiDB::AlterTableHandler::ActionBase * createAction()
Used to collect actions data for AlterTableHandler Can return 0 if the action should not be passed to...
Design view of the Table Designer.
KexiDB::Field * buildField(const KoProperty::Set &set) const