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

0001 /*
0002  *  SPDX-FileCopyrightText: 2024 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "KisChangeDeselectedMaskCommand.h"
0008 #include "KisImageGlobalSelectionManagementInterface.h"
0009 #include "kis_selection_mask.h"
0010 #include "kis_image.h"
0011 
0012 KisChangeDeselectedMaskCommand::KisChangeDeselectedMaskCommand(KisImageWSP image)
0013     : m_image(image)
0014 {}
0015 
0016 KisChangeDeselectedMaskCommand::KisChangeDeselectedMaskCommand(KisImageWSP image, KisSelectionMaskSP newDeselectedMask)
0017     : m_image(image)
0018     , m_newDeselectedMask(newDeselectedMask)
0019 {}
0020 
0021 void KisChangeDeselectedMaskCommand::undo() {
0022     KisImageSP image = m_image.toStrongRef();
0023     KIS_SAFE_ASSERT_RECOVER_RETURN(image);
0024 
0025     KisImageGlobalSelectionManagementInterface *iface = image->globalSelectionManagementInterface();
0026 
0027     iface->setDeselectedGlobalSelection(m_oldDeselectedMask);
0028     m_oldDeselectedMask.clear();
0029 }
0030 
0031 void KisChangeDeselectedMaskCommand::redo() {
0032     KisImageSP image = m_image.toStrongRef();
0033     KIS_SAFE_ASSERT_RECOVER_RETURN(image);
0034 
0035     KisImageGlobalSelectionManagementInterface *iface = image->globalSelectionManagementInterface();
0036 
0037     m_oldDeselectedMask = iface->deselectedGlobalSelection();
0038     iface->setDeselectedGlobalSelection(m_newDeselectedMask);
0039 }