File indexing completed on 2024-12-22 04:10:01

0001 /*
0002  *  SPDX-FileCopyrightText: 2002 Patrick Julien <freak@codepimps.org>
0003  *  SPDX-FileCopyrightText: 2007 Sven Langkamp <sven.langkamp@gmail.com>
0004  *
0005  *  SPDX-License-Identifier: GPL-2.0-or-later
0006  */
0007 
0008 #include "kis_image_commands.h"
0009 #include "kis_image.h"
0010 #include "kis_group_layer.h"
0011 
0012 #include <klocalizedstring.h>
0013 
0014 
0015 KisImageChangeLayersCommand::KisImageChangeLayersCommand(KisImageWSP image, KisNodeSP oldRootLayer, KisNodeSP newRootLayer)
0016     : KisImageCommand(kundo2_noi18n("change-layer-command"), image)
0017 {
0018     m_oldRootLayer = oldRootLayer;
0019     m_newRootLayer = newRootLayer;
0020 }
0021 
0022 void KisImageChangeLayersCommand::redo()
0023 {
0024     KisImageSP image = m_image.toStrongRef();
0025     if (image) {
0026         image->setRootLayer(static_cast<KisGroupLayer*>(m_newRootLayer.data()));
0027         image->refreshGraphAsync();
0028         image->notifyLayersChanged();
0029     }
0030 }
0031 
0032 void KisImageChangeLayersCommand::undo()
0033 {
0034     KisImageSP image = m_image.toStrongRef();
0035     if (image) {
0036         image->setRootLayer(static_cast<KisGroupLayer*>(m_oldRootLayer.data()));
0037         image->refreshGraphAsync();
0038         image->notifyLayersChanged();
0039     }
0040 }