File indexing completed on 2024-06-09 04:21:53
0001 /* 0002 * SPDX-FileCopyrightText: 2019 Boudewijn Rempt <boud@valdyas.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "KisNodeRenameCommand.h" 0008 0009 #include <klocalizedstring.h> 0010 #include "kis_node.h" 0011 #include "commands/kis_node_commands.h" 0012 #include "kis_command_ids.h" 0013 0014 KisNodeRenameCommand::KisNodeRenameCommand(KisNodeSP node, const QString &oldName, const QString &newName) 0015 : KisNodeCommand(kundo2_i18n("Node Rename"), node) 0016 { 0017 m_oldName = oldName; 0018 m_newName = newName; 0019 } 0020 0021 void KisNodeRenameCommand::redo() 0022 { 0023 m_node->setName(m_newName); 0024 } 0025 0026 void KisNodeRenameCommand::undo() 0027 { 0028 m_node->setName(m_oldName); 0029 } 0030 0031 int KisNodeRenameCommand::id() const 0032 { 0033 return KisCommandUtils::ChangeNodeNameId; 0034 } 0035 0036 bool KisNodeRenameCommand::mergeWith(const KUndo2Command *command) 0037 { 0038 const KisNodeRenameCommand *other = 0039 dynamic_cast<const KisNodeRenameCommand*>(command); 0040 0041 if (other && other->m_node == m_node) { 0042 KIS_SAFE_ASSERT_RECOVER_NOOP(m_newName == other->m_oldName); 0043 m_newName = other->m_newName; 0044 return true; 0045 } 0046 0047 return false; 0048 } 0049 0050 bool KisNodeRenameCommand::canMergeWith(const KUndo2Command *command) const 0051 { 0052 const KisNodeRenameCommand *other = 0053 dynamic_cast<const KisNodeRenameCommand*>(command); 0054 0055 return other && other->m_node == m_node; 0056 }