// Copyright (C) 2008 Lukas Lalinsky // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with this program; if not, write to the Free Software Foundation, Inc., // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. #include #include "commands.h" #include "databasetable.h" #include "column.h" ChangeColumnPropertyCommand::ChangeColumnPropertyCommand(Column *column, Column::Property property, const QVariant &value, QUndoCommand *parent) : QUndoCommand(parent) { m_column = column; m_property = property; m_oldValue = column->property(property); m_newValue = value; } void ChangeColumnPropertyCommand::redo() { m_column->setProperty(m_property, m_newValue); } void ChangeColumnPropertyCommand::undo() { m_column->setProperty(m_property, m_oldValue); } int ChangeColumnPropertyCommand::id() const { return COMMAND_CHANGE_COLUMN_PROPERTY; } bool ChangeColumnPropertyCommand::mergeWith(const QUndoCommand *o) { return false; Q_ASSERT(id() == o->id()); const ChangeColumnPropertyCommand *other = static_cast(o); if (m_column != other->m_column || m_property != other->m_property) return false; m_newValue = other->m_newValue; return true; } SetObjectPropertyCommand::SetObjectPropertyCommand(QObject *object, const char *name, const QVariant &value, QUndoCommand *parent) : QUndoCommand(parent), m_object(object), m_name(name), m_newValue(value) { m_oldValue = object->property(name); } void SetObjectPropertyCommand::redo() { m_object->setProperty(m_name.latin1(), m_newValue); } void SetObjectPropertyCommand::undo() { m_object->setProperty(m_name.latin1(), m_oldValue); } int SetObjectPropertyCommand::id() const { return COMMAND_SET_OBJECT_PROPERTY; } bool SetObjectPropertyCommand::mergeWith(const QUndoCommand *o) { return false; Q_ASSERT(id() == o->id()); const SetObjectPropertyCommand *other = static_cast(o); if (m_object != other->m_object || m_name != other->m_name) return false; m_newValue = other->m_newValue; return true; }