summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--commands.cpp57
-rw-r--r--commands.h23
-rw-r--r--databasetable.h1
-rw-r--r--tableproperties.cpp2
4 files changed, 42 insertions, 41 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;
diff --git a/commands.h b/commands.h
index 753c119..4c223c4 100644
--- a/commands.h
+++ b/commands.h
@@ -19,43 +19,44 @@
#include <QUndoCommand>
#include <QVariant>
+#include <QLatin1String>
class DatabaseTable;
class Column;
#include "column.h"
enum {
- COMMAND_EDIT_TABLE_NAME = 1,
- COMMAND_CHANGE_COLUMN_PROPERTY
+ COMMAND_CHANGE_COLUMN_PROPERTY = 1,
+ COMMAND_SET_OBJECT_PROPERTY
};
-class EditTableNameCommand : public QUndoCommand
+class ChangeColumnPropertyCommand : public QUndoCommand
{
public:
- EditTableNameCommand(DatabaseTable *table, const QString &name, QUndoCommand *parent = 0);
+ ChangeColumnPropertyCommand(Column *column, Column::Property property, const QVariant &value, QUndoCommand *parent = 0);
void undo();
void redo();
int id() const;
bool mergeWith(const QUndoCommand *command);
private:
- DatabaseTable *m_table;
- QString m_oldName;
- QString m_newName;
+ Column *m_column;
+ Column::Property m_property;
+ QVariant m_oldValue, m_newValue;
};
-class ChangeColumnPropertyCommand : public QUndoCommand
+class SetObjectPropertyCommand : public QUndoCommand
{
public:
- ChangeColumnPropertyCommand(Column *column, Column::Property property, const QVariant &value, QUndoCommand *parent = 0);
+ SetObjectPropertyCommand(QObject *object, const char *name, const QVariant &value, QUndoCommand *parent = 0);
void undo();
void redo();
int id() const;
bool mergeWith(const QUndoCommand *command);
private:
- Column *m_column;
- Column::Property m_property;
+ QObject *m_object;
+ QLatin1String m_name;
QVariant m_oldValue, m_newValue;
};
diff --git a/databasetable.h b/databasetable.h
index 1d2ebcc..7b54cf7 100644
--- a/databasetable.h
+++ b/databasetable.h
@@ -27,6 +27,7 @@ class DatabaseModel;
class DatabaseTable : public QObject, public DatabaseModelItem
{
Q_OBJECT
+ Q_PROPERTY(QString name READ name WRITE setName)
public:
DatabaseTable(QGraphicsItem *parent = 0);
diff --git a/tableproperties.cpp b/tableproperties.cpp
index e319c04..cfa95f7 100644
--- a/tableproperties.cpp
+++ b/tableproperties.cpp
@@ -42,7 +42,7 @@ void
TableProperties::setSelectedTableName(const QString &name)
{
if (m_table) {
- m_window->currentUndoStack()->push(new EditTableNameCommand(m_table, name));
+ m_window->currentUndoStack()->push(new SetObjectPropertyCommand(m_table, "name", name));
}
}