File indexing completed on 2024-12-22 04:12:33

0001 /*
0002  *  SPDX-FileCopyrightText: 2013 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "kis_take_all_shapes_command.h"
0008 
0009 #include <klocalizedstring.h>
0010 #include "kis_shape_selection.h"
0011 #include <kis_image.h>
0012 
0013 
0014 KisTakeAllShapesCommand::KisTakeAllShapesCommand(KisShapeSelection *shapeSelection, bool takeSilently, bool restoreSilently)
0015     : KUndo2Command(kundo2_i18n("Clear Vector Selection")),
0016       m_shapeSelection(shapeSelection),
0017       m_takeSilently(takeSilently),
0018       m_restoreSilently(restoreSilently)
0019 {
0020 }
0021 
0022 KisTakeAllShapesCommand::~KisTakeAllShapesCommand()
0023 {
0024     Q_FOREACH (KoShape *shape, m_shapes) {
0025         delete shape;
0026     }
0027 }
0028 
0029 void KisTakeAllShapesCommand::redo()
0030 {
0031     if (m_takeSilently) {
0032         m_shapeSelection->setUpdatesEnabled(false);
0033     }
0034 
0035     m_shapes = m_shapeSelection->shapes();
0036 
0037     Q_FOREACH (KoShape *shape, m_shapes) {
0038         m_shapeSelection->removeShape(shape);
0039     }
0040 
0041     if (m_takeSilently) {
0042         m_shapeSelection->setUpdatesEnabled(true);
0043     }
0044 }
0045 
0046 void KisTakeAllShapesCommand::undo()
0047 {
0048     if (m_restoreSilently) {
0049         m_shapeSelection->setUpdatesEnabled(false);
0050     }
0051 
0052     Q_FOREACH (KoShape *shape, m_shapes) {
0053         m_shapeSelection->addShape(shape);
0054     }
0055 
0056     m_shapes.clear();
0057 
0058     if (m_restoreSilently) {
0059         m_shapeSelection->setUpdatesEnabled(true);
0060     }
0061 }
0062