00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <qdom.h>
00020 #include <qwidget.h>
00021 #include <qlayout.h>
00022 #include <qlabel.h>
00023 #include <qsplitter.h>
00024 #include <qmetaobject.h>
00025
00026 #include <kdebug.h>
00027 #include <klocale.h>
00028 #include <kpopupmenu.h>
00029 #include <kmessagebox.h>
00030 #include <kaccelmanager.h>
00031
00032 #include <koproperty/property.h>
00033
00034 #include "kexitabledesignercommands.h"
00035
00036 using namespace KexiTableDesignerCommands;
00037
00038
00039 Command::Command(KexiTableDesignerView* view)
00040 : KCommand()
00041 , m_view(view)
00042 {
00043 }
00044
00045 Command::~Command()
00046 {
00047 }
00048
00049
00050
00051 ChangeFieldPropertyCommand::ChangeFieldPropertyCommand( KexiTableDesignerView* view,
00052 const KoProperty::Set& set, const QCString& propertyName, const QVariant& oldValue, const QVariant& newValue,
00053 KoProperty::Property::ListData* const oldListData, KoProperty::Property::ListData* const newListData)
00054 : Command(view)
00055 , m_alterTableAction(
00056 propertyName=="name" ? oldValue.toString() : set.property("name").value().toString(),
00057 propertyName, newValue, set["uid"].value().toInt())
00058 , m_oldValue(oldValue)
00059
00060 , m_oldListData( oldListData ? new KoProperty::Property::ListData(*oldListData) : 0 )
00061 , m_listData( newListData ? new KoProperty::Property::ListData(*newListData) : 0 )
00062 {
00063 kexipluginsdbg << "ChangeFieldPropertyCommand: " << debugString() << endl;
00064 }
00065
00066 ChangeFieldPropertyCommand::~ChangeFieldPropertyCommand()
00067 {
00068 delete m_oldListData;
00069 delete m_listData;
00070 }
00071
00072 QString ChangeFieldPropertyCommand::name() const
00073 {
00074 return i18n("Change \"%1\" property for table field from \"%2\" to \"%3\"")
00075 .arg(m_alterTableAction.propertyName()).arg(m_oldValue.toString())
00076 .arg(m_alterTableAction.newValue().toString());
00077 }
00078
00079 QString ChangeFieldPropertyCommand::debugString()
00080 {
00081 QString s( name() );
00082 if (m_oldListData || m_listData)
00083 s += QString("\nAnd list data from [%1]\n to [%2]")
00084 .arg( m_oldListData ?
00085 QString("%1 -> %2")
00086 .arg(m_oldListData->keysAsStringList().join(",")).arg(m_oldListData->names.join(","))
00087 : QString("<NONE>"))
00088 .arg( m_listData ?
00089 QString("%1 -> %2")
00090 .arg(m_listData->keysAsStringList().join(",")).arg(m_listData->names.join(","))
00091 : QString("<NONE>"));
00092 return s + QString(" (UID=%1)").arg(m_alterTableAction.uid());
00093 }
00094
00095 void ChangeFieldPropertyCommand::execute()
00096 {
00097 m_view->changeFieldProperty(
00098 m_alterTableAction.uid(),
00099 m_alterTableAction.propertyName().latin1(),
00100 m_alterTableAction.newValue(), m_listData );
00101 }
00102
00103 void ChangeFieldPropertyCommand::unexecute()
00104 {
00105 m_view->changeFieldProperty(
00106 m_alterTableAction.uid(),
00107 m_alterTableAction.propertyName().latin1(),
00108 m_oldValue, m_oldListData );
00109 }
00110
00111 KexiDB::AlterTableHandler::ActionBase* ChangeFieldPropertyCommand::createAction()
00112 {
00113 if (m_alterTableAction.propertyName()=="subType") {
00114 return 0;
00115 }
00116 return new KexiDB::AlterTableHandler::ChangeFieldPropertyAction( m_alterTableAction );
00117 }
00118
00119
00120
00121 RemoveFieldCommand::RemoveFieldCommand( KexiTableDesignerView* view, int fieldIndex,
00122 const KoProperty::Set* set)
00123 : Command(view)
00124 , m_alterTableAction( set ? (*set)["name"].value().toString() : QString::null,
00125 set ? (*set)["uid"].value().toInt() : -1 )
00126 , m_set( set ? new KoProperty::Set(*set ) : 0 )
00127 , m_fieldIndex(fieldIndex)
00128 {
00129 }
00130
00131 RemoveFieldCommand::~RemoveFieldCommand()
00132 {
00133 delete m_set;
00134 }
00135
00136 QString RemoveFieldCommand::name() const
00137 {
00138 if (m_set)
00139 return i18n("Remove table field \"%1\"").arg(m_alterTableAction.fieldName());
00140
00141 return QString("Remove empty row at position %1").arg(m_fieldIndex);
00142 }
00143
00144 void RemoveFieldCommand::execute()
00145 {
00146
00147 m_view->deleteRow( m_fieldIndex );
00148 }
00149
00150 void RemoveFieldCommand::unexecute()
00151 {
00152 m_view->insertEmptyRow(m_fieldIndex);
00153 if (m_set)
00154 m_view->insertField( m_fieldIndex, *m_set );
00155 }
00156
00157 QString RemoveFieldCommand::debugString()
00158 {
00159 if (!m_set)
00160 return name();
00161
00162 return name() + "\nAT ROW " + QString::number(m_fieldIndex)
00163 + ", FIELD: " + (*m_set)["caption"].value().toString()
00164 + QString(" (UID=%1)").arg(m_alterTableAction.uid());
00165 }
00166
00167 KexiDB::AlterTableHandler::ActionBase* RemoveFieldCommand::createAction()
00168 {
00169 return new KexiDB::AlterTableHandler::RemoveFieldAction( m_alterTableAction );
00170 }
00171
00172
00173
00174 InsertFieldCommand::InsertFieldCommand( KexiTableDesignerView* view,
00175 int fieldIndex, const KoProperty::Set& set )
00176 : Command(view)
00177 , m_alterTableAction(0)
00178 , m_set( set )
00179 {
00180 KexiDB::Field *f = view->buildField( m_set );
00181 if (f)
00182 m_alterTableAction = new KexiDB::AlterTableHandler::InsertFieldAction(
00183 fieldIndex, f, set["uid"].value().toInt());
00184 else
00185 m_alterTableAction = new KexiDB::AlterTableHandler::InsertFieldAction(true);
00186 }
00187
00188 InsertFieldCommand::~InsertFieldCommand()
00189 {
00190 delete m_alterTableAction;
00191 }
00192
00193 QString InsertFieldCommand::name() const
00194 {
00195 return i18n("Insert table field \"%1\"").arg(m_set["caption"].value().toString());
00196 }
00197
00198 void InsertFieldCommand::execute()
00199 {
00200 m_view->insertField( m_alterTableAction->index(), m_set );
00201 }
00202
00203 void InsertFieldCommand::unexecute()
00204 {
00205 m_view->clearRow( m_alterTableAction->index() );
00206 }
00207
00208 KexiDB::AlterTableHandler::ActionBase* InsertFieldCommand::createAction()
00209 {
00210 return new KexiDB::AlterTableHandler::InsertFieldAction(*m_alterTableAction);
00211 }
00212
00213
00214
00215 ChangePropertyVisibilityCommand::ChangePropertyVisibilityCommand( KexiTableDesignerView* view,
00216 const KoProperty::Set& set, const QCString& propertyName, bool visible)
00217 : Command(view)
00218 , m_alterTableAction(set.property("name").value().toString(), propertyName, visible, set["uid"].value().toInt())
00219
00220 , m_oldVisibility( set.property(propertyName).isVisible() )
00221 {
00222 kexipluginsdbg << "ChangePropertyVisibilityCommand: " << debugString() << endl;
00223 }
00224
00225 ChangePropertyVisibilityCommand::~ChangePropertyVisibilityCommand()
00226 {
00227 }
00228
00229 QString ChangePropertyVisibilityCommand::name() const
00230 {
00231 return QString("[internal] Change \"%1\" visibility from \"%2\" to \"%3\"")
00232 .arg(m_alterTableAction.propertyName())
00233 .arg(m_oldVisibility ? "true" : "false")
00234 .arg(m_alterTableAction.newValue().toBool() ? "true" : "false");
00235 }
00236
00237 void ChangePropertyVisibilityCommand::execute()
00238 {
00239 m_view->changePropertyVisibility(
00240 m_alterTableAction.uid(),
00241 m_alterTableAction.propertyName().latin1(),
00242 m_alterTableAction.newValue().toBool() );
00243 }
00244
00245 void ChangePropertyVisibilityCommand::unexecute()
00246 {
00247 m_view->changePropertyVisibility(
00248 m_alterTableAction.uid(),
00249 m_alterTableAction.propertyName().latin1(),
00250 m_oldVisibility );
00251 }
00252
00253
00254
00255 InsertEmptyRowCommand::InsertEmptyRowCommand( KexiTableDesignerView* view, int row )
00256 : Command(view)
00257 , m_alterTableAction(true)
00258 , m_row(row)
00259 {
00260 }
00261
00262 InsertEmptyRowCommand::~InsertEmptyRowCommand()
00263 {
00264 }
00265
00266 QString InsertEmptyRowCommand::name() const
00267 {
00268 return QString("Insert empty row at position %1").arg(m_row);
00269 }
00270
00271 void InsertEmptyRowCommand::execute()
00272 {
00273 m_view->insertEmptyRow( m_row );
00274 }
00275
00276 void InsertEmptyRowCommand::unexecute()
00277 {
00278
00279 m_view->deleteRow( m_row );
00280 }
00281