Commit 43f89ce8 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Create an undo command for node renaming

This means that changing a node's name will now mark the document
modified so it can be saved, and it's possible to undo a node
rename.

BUG:380437
parent e7ac33be
......@@ -98,6 +98,7 @@ set(kritaimage_LIB_SRCS
commands/kis_reselect_global_selection_command.cpp
commands/KisReselectActiveSelectionCommand.cpp
commands/kis_set_global_selection_command.cpp
commands/KisNodeRenameCommand.cpp
commands_new/kis_saved_commands.cpp
commands_new/kis_processing_command.cpp
commands_new/kis_image_resize_command.cpp
......
/*
* Copyright (c) 2019 Boudewijn Rempt <boud@valdyas.org>
*
* 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 "KisNodeRenameCommand.h"
#include <klocalizedstring.h>
#include "kis_node.h"
#include "commands/kis_node_commands.h"
KisNodeRenameCommand::KisNodeRenameCommand(KisNodeSP node, const QString &oldName, const QString &newName)
: KisNodeCommand(kundo2_i18n("Node Rename"), node)
{
m_oldName = oldName;
m_newName = newName;
}
void KisNodeRenameCommand::redo()
{
m_node->setName(m_newName);
}
void KisNodeRenameCommand::undo()
{
m_node->setName(m_oldName);
}
/*
* Copyright (c) 2019 Boudewijn Rempt <boud@valdyas.org>
*
* 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.
*/
#ifndef KISNODERENAMECOMMAND_H
#define KISNODERENAMECOMMAND_H
#include "kis_node_command.h"
/// The command for setting the node's name
class KRITAIMAGE_EXPORT KisNodeRenameCommand : public KisNodeCommand
{
public:
KisNodeRenameCommand(KisNodeSP node,
const QString &oldName,
const QString &newName);
void redo() override;
void undo() override;
private:
QString m_oldName;
QString m_newName;
};
#endif // KISNODERENAMECOMMAND_H
......@@ -21,8 +21,6 @@
#include <KoCompositeOp.h>
#include "kis_node.h"
#include "commands/kis_node_commands.h"
#include "kis_paint_device.h"
KisNodeCompositeOpCommand::KisNodeCompositeOpCommand(KisNodeSP node, const QString& oldCompositeOp,
const QString& newCompositeOp) :
......
......@@ -24,6 +24,7 @@
#include "commands/kis_image_layer_add_command.h"
#include "commands/kis_image_layer_move_command.h"
#include "commands/kis_image_layer_remove_command.h"
#include "commands/KisNodeRenameCommand.h"
#include "commands/kis_node_commands.h"
#include "KisViewManager.h"
#include "kis_processing_applicator.h"
......@@ -127,6 +128,12 @@ void KisNodeCommandsAdapter::setCompositeOp(KisNodeSP node,
applyOneCommandAsync(cmd);
}
void KisNodeCommandsAdapter::setNodeName(KisNodeSP node, const QString &name)
{
KUndo2Command *cmd = new KisNodeRenameCommand(node, node->name(), name);
applyOneCommandAsync(cmd);
}
void KisNodeCommandsAdapter::undoLastCommand()
{
Q_ASSERT(m_view->image()->undoAdapter());
......
......@@ -66,6 +66,7 @@ public:
void removeNode(KisNodeSP node);
void setOpacity(KisNodeSP node, qint32 opacity);
void setCompositeOp(KisNodeSP node, const KoCompositeOp* compositeOp);
void setNodeName(KisNodeSP node, const QString &name);
void undoLastCommand();
private:
......
......@@ -776,6 +776,15 @@ qint32 KisNodeManager::convertOpacityToInt(qreal opacity)
return qMin(255, int(opacity * 2.55 + 0.5));
}
void KisNodeManager::setNodeName(KisNodeSP node, const QString &name)
{
if (!node) return;
if (node->name() == name) return;
m_d->commandsAdapter.setNodeName(node, name);
}
void KisNodeManager::setNodeOpacity(KisNodeSP node, qint32 opacity)
{
if (!node) return;
......
......@@ -93,6 +93,11 @@ public:
*/
const KoColorSpace* activeColorSpace();
/**
* Sets the name for the node in a universal way (masks/layers)
*/
void setNodeName(KisNodeSP node, const QString &name);
/**
* Sets opacity for the node in a universal way (masks/layers)
*/
......
......@@ -591,7 +591,7 @@ bool KisNodeModel::setData(const QModelIndex &index, const QVariant &value, int
switch (role) {
case Qt::DisplayRole:
case Qt::EditRole:
node->setName(value.toString());
m_d->nodeManager->setNodeName(node, value.toString());
break;
case KisNodeModel::PropertiesRole:
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment