summaryrefslogtreecommitdiff
path: root/commands.cpp
diff options
context:
space:
mode:
authorLukáš Lalinský <lalinsky@gmail.com>2008-12-03 10:28:24 +0100
committerLukáš Lalinský <lalinsky@gmail.com>2008-12-03 10:28:24 +0100
commitc722028fd1d333e185e11baf41519f51b93df2ae (patch)
treee4ff81efd98e42af991280bb7eb1377962085b6c /commands.cpp
parent12f465eb8ad1fe6f6c0d2c3e261fe1bb88f33d10 (diff)
downloaddbmodel-c722028fd1d333e185e11baf41519f51b93df2ae.tar.xz
Convert EditTableNameCommand to more generic SetObjectPropertyCommand
Diffstat (limited to 'commands.cpp')
-rw-r--r--commands.cpp57
1 files changed, 28 insertions, 29 deletions
diff --git a/commands.cpp b/commands.cpp
index 70b1487..57a8b6e 100644
--- a/commands.cpp
+++ b/commands.cpp
@@ -19,77 +19,76 @@
#include "databasetable.h"
#include "column.h"
-EditTableNameCommand::EditTableNameCommand(DatabaseTable *table, const QString &name, QUndoCommand *parent)
+ChangeColumnPropertyCommand::ChangeColumnPropertyCommand(Column *column, Column::Property property, const QVariant &value, QUndoCommand *parent)
: QUndoCommand(parent)
{
- m_table = table;
- m_oldName = table->name();
- m_newName = name;
+ m_column = column;
+ m_property = property;
+ m_oldValue = column->property(property);
+ m_newValue = value;
}
void
-EditTableNameCommand::redo()
+ChangeColumnPropertyCommand::redo()
{
- m_table->setName(m_newName);
+ m_column->setProperty(m_property, m_newValue);
}
void
-EditTableNameCommand::undo()
+ChangeColumnPropertyCommand::undo()
{
- m_table->setName(m_oldName);
+ m_column->setProperty(m_property, m_oldValue);
}
int
-EditTableNameCommand::id() const
+ChangeColumnPropertyCommand::id() const
{
- return COMMAND_EDIT_TABLE_NAME;
+ return COMMAND_CHANGE_COLUMN_PROPERTY;
}
bool
-EditTableNameCommand::mergeWith(const QUndoCommand *o)
+ChangeColumnPropertyCommand::mergeWith(const QUndoCommand *o)
{
+ return false;
Q_ASSERT(id() == o->id());
- const EditTableNameCommand *other = static_cast<const EditTableNameCommand *>(o);
- if (m_table != other->m_table)
+ const ChangeColumnPropertyCommand *other = static_cast<const ChangeColumnPropertyCommand *>(o);
+ if (m_column != other->m_column || m_property != other->m_property)
return false;
- m_newName = other->m_newName;
+ m_newValue = other->m_newValue;
return true;
}
-ChangeColumnPropertyCommand::ChangeColumnPropertyCommand(Column *column, Column::Property property, const QVariant &value, QUndoCommand *parent)
- : QUndoCommand(parent)
+SetObjectPropertyCommand::SetObjectPropertyCommand(QObject *object, const char *name, const QVariant &value, QUndoCommand *parent)
+ : QUndoCommand(parent), m_object(object), m_name(name), m_newValue(value)
{
- m_column = column;
- m_property = property;
- m_oldValue = column->property(property);
- m_newValue = value;
+ m_oldValue = object->property(name);
}
void
-ChangeColumnPropertyCommand::redo()
+SetObjectPropertyCommand::redo()
{
- m_column->setProperty(m_property, m_newValue);
+ m_object->setProperty(m_name.latin1(), m_newValue);
}
void
-ChangeColumnPropertyCommand::undo()
+SetObjectPropertyCommand::undo()
{
- m_column->setProperty(m_property, m_oldValue);
+ m_object->setProperty(m_name.latin1(), m_oldValue);
}
int
-ChangeColumnPropertyCommand::id() const
+SetObjectPropertyCommand::id() const
{
- return COMMAND_CHANGE_COLUMN_PROPERTY;
+ return COMMAND_SET_OBJECT_PROPERTY;
}
bool
-ChangeColumnPropertyCommand::mergeWith(const QUndoCommand *o)
+SetObjectPropertyCommand::mergeWith(const QUndoCommand *o)
{
return false;
Q_ASSERT(id() == o->id());
- const ChangeColumnPropertyCommand *other = static_cast<const ChangeColumnPropertyCommand *>(o);
- if (m_column != other->m_column || m_property != other->m_property)
+ const SetObjectPropertyCommand *other = static_cast<const SetObjectPropertyCommand *>(o);
+ if (m_object != other->m_object || m_name != other->m_name)
return false;
m_newValue = other->m_newValue;
return true;