Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_set_global_selection_command.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2007 Sven Langkamp <sven.langkamp@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9#include <klocalizedstring.h>
10
11#include "kis_image.h"
12#include "kis_default_bounds.h"
14#include "kis_selection.h"
15#include "kis_undo_adapter.h"
16#include "kis_selection_mask.h"
17#include "kis_pixel_selection.h"
19#include "kis_group_layer.h"
20
23#include "kis_selection_mask.h"
28
29
31 : m_image(image)
32{
33 KisImageSP imageSP = m_image.toStrongRef();
34 if (!image) {
35 return;
36 }
38 m_newSelection = selection;
39}
40
42{
45
47
48 KisSelectionMaskSP selectionMask = image->rootLayer()->selectionMask();
49 if (selectionMask) {
50 addCommand(new KisImageLayerRemoveCommand(image, selectionMask, false, false));
51 }
52
53 if (m_newSelection) {
54 selectionMask = new KisSelectionMask(image, i18n("Selection Mask"));
55 selectionMask->initSelection(image->rootLayer());
56
57 // If we do not set the selection now, the setActive call coming next
58 // can be very, very expensive, depending on the size of the image.
59 selectionMask->setSelection(m_newSelection);
60
61 addCommand(new KisImageLayerAddCommand(image, selectionMask,
62 image->root(), image->root()->lastChild(),
63 false, false));
64 addCommand(new KisActivateSelectionMaskCommand(selectionMask, true));
65
66 }
67
68
71}
72
The command for adding a layer.
KisGroupLayerSP rootLayer() const
KisSelectionSP globalSelection() const
Definition kis_image.cc:695
KisSetGlobalSelectionCommand(KisImageWSP image, KisSelectionSP selection)
KisSharedPtr< T > toStrongRef() const
toStrongRef returns a KisSharedPtr which may be dereferenced.
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
QSharedPointer< T > toQShared(T *ptr)
void addCommand(KUndo2Command *cmd)
virtual KisSelectionMaskSP selectionMask() const
Definition kis_layer.cc:498
void initSelection(KisSelectionSP copyFrom, KisLayerSP parentLayer)
initSelection initializes the selection for the mask from the given selection's projection.
Definition kis_mask.cc:157
KisNodeSP lastChild() const
Definition kis_node.cpp:367
void setSelection(KisSelectionSP selection)
Set the selection of this adjustment layer to a copy of selection.