Krita Source Code Documentation
Loading...
Searching...
No Matches
KisNodePropertyListCommand Class Reference

The command for changing the property list of a layer. More...

#include <kis_node_property_list_command.h>

+ Inheritance diagram for KisNodePropertyListCommand:

Public Types

typedef KisBaseNode::PropertyList PropertyList
 

Public Member Functions

bool canAnnihilateWith (const KUndo2Command *other) const override
 
bool canMergeWith (const KUndo2Command *command) const override
 
int id () const override
 
 KisNodePropertyListCommand (KisNodeSP node, KisBaseNode::PropertyList newPropertyList)
 
bool mergeWith (const KUndo2Command *command) override
 
void redo () override
 
void undo () override
 
- Public Member Functions inherited from KisNodeCommand
 KisNodeCommand (const KUndo2MagicString &name, KisNodeSP node)
 
 ~KisNodeCommand () override
 
- Public Member Functions inherited from KUndo2Command
QString actionText () const
 
const KUndo2Command * child (int index) const
 
int childCount () const
 
virtual QTime endTime () const
 
KUndo2CommandExtraData * extraData () const
 
bool hasParent () const
 
virtual bool isMerged () const
 
 KUndo2Command (const KUndo2MagicString &text, KUndo2Command *parent=0)
 
 KUndo2Command (KUndo2Command *parent=0)
 
virtual QVector< KUndo2Command * > mergeCommandsVector () const
 
virtual void redoMergedCommands ()
 
void setEndTime ()
 
virtual void setEndTime (const QTime &time)
 
void setExtraData (KUndo2CommandExtraData *data)
 
void setText (const KUndo2MagicString &text)
 
void setTime ()
 
virtual void setTime (const QTime &time)
 
virtual void setTimedID (int timedID)
 
KUndo2MagicString text () const
 
virtual QTime time () const
 
virtual int timedId () const
 
virtual bool timedMergeWith (KUndo2Command *other)
 
virtual void undoMergedCommands ()
 
virtual ~KUndo2Command ()
 
- Public Member Functions inherited from KisAsynchronouslyMergeableCommandInterface
virtual ~KisAsynchronouslyMergeableCommandInterface ()
 

Static Public Member Functions

static void setNodePropertiesAutoUndo (KisNodeSP node, KisImageSP image, PropertyList proplist)
 

Private Member Functions

void doUpdate (const KisBaseNode::PropertyList &oldPropertyList, const KisBaseNode::PropertyList &newPropertyList, const QRect &totalUpdateExtent)
 

Static Private Member Functions

static const QSet< QString > & propsWithNoUpdates ()
 

Private Attributes

KisBaseNode::PropertyList m_newPropertyList
 
KisBaseNode::PropertyList m_oldPropertyList
 

Additional Inherited Members

- Protected Attributes inherited from KisNodeCommand
KisNodeSP m_node
 

Detailed Description

The command for changing the property list of a layer.

Definition at line 16 of file kis_node_property_list_command.h.

Member Typedef Documentation

◆ PropertyList

Constructor & Destructor Documentation

◆ KisNodePropertyListCommand()

KisNodePropertyListCommand::KisNodePropertyListCommand ( KisNodeSP node,
KisBaseNode::PropertyList newPropertyList )

Constructor

Parameters
nodethe layer to add
newPropertyListthe property list to which the node to be added

TODO instead of "Property Changes" check which property has been changed and display either lock/unlock, visible/hidden or "Property Changes" (this require new strings)

Definition at line 60 of file kis_node_property_list_command.cpp.

61 : KisNodeCommand(kundo2_i18n("Property Changes"), node),
62 m_newPropertyList(newPropertyList),
69{
70}
KisNodeCommand(const KUndo2MagicString &name, KisNodeSP node)
KisBaseNode::PropertyList m_newPropertyList
KisBaseNode::PropertyList m_oldPropertyList
KUndo2MagicString kundo2_i18n(const char *text)
virtual PropertyList sectionModelProperties() const

Member Function Documentation

◆ canAnnihilateWith()

bool KisNodePropertyListCommand::canAnnihilateWith ( const KUndo2Command * other) const
overridevirtual

Attempts to merge this command with command and checks if the two commands compensate each other. If the function returns true, both commands are removed from the stack.

If this function returns true, calling this command's redo() followed by other redo() must have no effect.

The function itself shouldn't do any changes to the command, because after returning true, the command will be deleted as a "noop"

KUndo2QStack will only try to merge two commands if they have the same id, and the id is not -1.

The default implementation returns false.

See also
id() KUndo2QStack::push()

Reimplemented from KUndo2Command.

Definition at line 143 of file kis_node_property_list_command.cpp.

144{
145 const KisNodePropertyListCommand *other =
146 dynamic_cast<const KisNodePropertyListCommand*>(command);
147
148 return other && other->m_node == m_node &&
149 changedProperties(m_oldPropertyList, other->m_newPropertyList).isEmpty();
150}
The command for changing the property list of a layer.

References m_newPropertyList, KisNodeCommand::m_node, and m_oldPropertyList.

◆ canMergeWith()

bool KisNodePropertyListCommand::canMergeWith ( const KUndo2Command * command) const
overridevirtual
Returns
true if command can be merged with (*this) command using KUndo2Command::mergeWith() call.

WARNING: if canMergeWith() returned true, then mergeWith() must also return true. Otherwise KisSavedMacroCommand will be able to enter inconsistent state and assert.

Implements KisAsynchronouslyMergeableCommandInterface.

Definition at line 132 of file kis_node_property_list_command.cpp.

133{
134 const KisNodePropertyListCommand *other =
135 dynamic_cast<const KisNodePropertyListCommand*>(command);
136
137 return other && other->m_node == m_node &&
138 (changedProperties(m_oldPropertyList, m_newPropertyList).isEmpty() ||
139 changedProperties(m_oldPropertyList, m_newPropertyList) ==
140 changedProperties(other->m_oldPropertyList, other->m_newPropertyList));
141}

References m_newPropertyList, KisNodeCommand::m_node, and m_oldPropertyList.

◆ doUpdate()

void KisNodePropertyListCommand::doUpdate ( const KisBaseNode::PropertyList & oldPropertyList,
const KisBaseNode::PropertyList & newPropertyList,
const QRect & totalUpdateExtent )
private

Sometimes the node might refuse to change the property, e.g. needs-update for colorize mask. In this case we should avoid issuing the update and set-modified call.

Definition at line 159 of file kis_node_property_list_command.cpp.

162{
167 if (oldPropertyList == newPropertyList) {
168 return;
169 }
170
171 bool oldPassThroughValue = false;
172 bool newPassThroughValue = false;
173
174 bool oldVisibilityValue = false;
175 bool newVisibilityValue = false;
176
177 Q_FOREACH (const KisBaseNode::Property &prop, oldPropertyList) {
179 oldPassThroughValue = prop.state.toBool();
180 }
181 if (prop.id == KisLayerPropertiesIcons::visible.id()) {
182 oldVisibilityValue = prop.state.toBool();
183 }
184 }
185
186 Q_FOREACH (const KisBaseNode::Property &prop, newPropertyList) {
188 newPassThroughValue = prop.state.toBool();
189 }
190 if (prop.id == KisLayerPropertiesIcons::visible.id()) {
191 newVisibilityValue = prop.state.toBool();
192 }
193 }
194
195 if (oldPassThroughValue && !newPassThroughValue) {
196 KisLayerSP layer(qobject_cast<KisLayer*>(m_node.data()));
197 KisImageSP image = layer->image().toStrongRef();
198 if (image) {
199 image->refreshGraphAsync(layer);
200 }
201 } else if ((m_node->parent() && !oldPassThroughValue && newPassThroughValue) ||
202 (oldPassThroughValue && newPassThroughValue &&
203 !oldVisibilityValue && newVisibilityValue)) {
204
205 KisLayerSP layer(qobject_cast<KisLayer*>(m_node->parent().data()));
206 KisImageSP image = layer->image().toStrongRef();
207 if (image) {
208 image->refreshGraphAsync(layer);
209 }
210 } else if (checkOnionSkinChanged(oldPropertyList, newPropertyList)) {
211 m_node->setDirtyDontResetAnimationCache(totalUpdateExtent);
212 } else {
213 m_node->setDirty(totalUpdateExtent); // TODO check if visibility was actually changed or not
214 }
215}
void refreshGraphAsync(KisNodeSP root, const QVector< QRect > &rects, const QRect &cropRect, KisProjectionUpdateFlags flags=KisProjectionUpdateFlag::None) override
QString id() const
Definition KoID.cpp:63
bool checkOnionSkinChanged(const KisBaseNode::PropertyList &oldPropertyList, const KisBaseNode::PropertyList &newPropertyList)
void setDirtyDontResetAnimationCache()
Definition kis_node.cpp:599
KisNodeWSP parent
Definition kis_node.cpp:86
virtual void setDirty()
Definition kis_node.cpp:577

References checkOnionSkinChanged(), KisSharedPtr< T >::data(), KisWeakSharedPtr< T >::data(), KoID::id(), KisBaseNode::Property::id, KisBaseNode::image, KisNodeCommand::m_node, KisNode::parent, KisLayerPropertiesIcons::passThrough, KisImage::refreshGraphAsync(), KisNode::setDirty(), KisNode::setDirtyDontResetAnimationCache(), KisBaseNode::Property::state, KisWeakSharedPtr< T >::toStrongRef(), and KisLayerPropertiesIcons::visible.

◆ id()

int KisNodePropertyListCommand::id ( ) const
overridevirtual

Returns the ID of this command.

A command ID is used in command compression. It must be an integer unique to this command's class, or -1 if the command doesn't support compression.

If the command supports compression this function must be overridden in the derived class to return the correct ID. The base implementation returns -1.

KUndo2QStack::push() will only try to merge two commands if they have the same ID, and the ID is not -1.

See also
mergeWith(), KUndo2QStack::push()

Reimplemented from KUndo2Command.

Definition at line 100 of file kis_node_property_list_command.cpp.

References KisCommandUtils::NodePropertyListCommandId.

◆ mergeWith()

bool KisNodePropertyListCommand::mergeWith ( const KUndo2Command * command)
overridevirtual

Attempts to merge this command with command. Returns true on success; otherwise returns false.

If this function returns true, calling this command's redo() must have the same effect as redoing both this command and command. Similarly, calling this command's undo() must have the same effect as undoing command and this command.

KUndo2QStack will only try to merge two commands if they have the same id, and the id is not -1.

The default implementation returns false.

See also
id() KUndo2QStack::push()

Reimplemented from KUndo2Command.

Definition at line 105 of file kis_node_property_list_command.cpp.

106{
107 const KisNodePropertyListCommand *other =
108 dynamic_cast<const KisNodePropertyListCommand*>(command);
109
110 if (other && other->m_node == m_node &&
111 (changedProperties(m_oldPropertyList, m_newPropertyList).isEmpty() ||
112 changedProperties(m_oldPropertyList, m_newPropertyList) ==
113 changedProperties(other->m_oldPropertyList, other->m_newPropertyList))) {
114
115 const QSet<QString> changedInTheMeantime =
116 changedProperties(m_newPropertyList, other->m_oldPropertyList);
117
118 // stateless properties change without an undo command, so they may differ between two mergeable commands
119 bool onlyStatelessChanged = true;
120 Q_FOREACH (const QString &id, changedInTheMeantime) {
121 onlyStatelessChanged &= KisLayerPropertiesIcons::isStatelessProperty(id);
122 }
123 KIS_SAFE_ASSERT_RECOVER_NOOP(onlyStatelessChanged);
124
126 return true;
127 }
128
129 return false;
130}
static bool isStatelessProperty(const QString &id)
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130

References KisLayerPropertiesIcons::isStatelessProperty(), KIS_SAFE_ASSERT_RECOVER_NOOP, m_newPropertyList, KisNodeCommand::m_node, and m_oldPropertyList.

◆ propsWithNoUpdates()

const QSet< QString > & KisNodePropertyListCommand::propsWithNoUpdates ( )
staticprivate

Definition at line 217 of file kis_node_property_list_command.cpp.

References KisLayerPropertiesIcons::alphaLocked, KisLayerPropertiesIcons::colorizeNeedsUpdate, KisLayerPropertiesIcons::colorLabelIndex, KoID::id(), KisLayerPropertiesIcons::layerError, KisLayerPropertiesIcons::locked, KisLayerPropertiesIcons::openFileLayerFile, and KisLayerPropertiesIcons::selectionActive.

◆ redo()

void KisNodePropertyListCommand::redo ( )
overridevirtual

Applies a change to the document. This function must be implemented in the derived class. Calling KUndo2QStack::push(), KUndo2QStack::undo() or KUndo2QStack::redo() from this function leads to undefined behavior.

The default implementation calls redo() on all child commands.

See also
undo()

Reimplemented from KUndo2Command.

Definition at line 72 of file kis_node_property_list_command.cpp.

73{
75 const QSet<QString> changed = changedProperties(propsBefore, m_newPropertyList);
76 if (changed.isEmpty()) return;
77
78 const QRect oldExtent = m_node->projectionPlane()->tightUserVisibleBounds();
80
81 if (!propsWithNoUpdates().contains(changed)) {
82 doUpdate(propsBefore, m_node->sectionModelProperties(), oldExtent | m_node->projectionPlane()->tightUserVisibleBounds());
83 }
84}
void doUpdate(const KisBaseNode::PropertyList &oldPropertyList, const KisBaseNode::PropertyList &newPropertyList, const QRect &totalUpdateExtent)
static const QSet< QString > & propsWithNoUpdates()
virtual void setSectionModelProperties(const PropertyList &properties)
virtual KisAbstractProjectionPlaneSP projectionPlane() const
Definition kis_node.cpp:240

References doUpdate(), m_newPropertyList, KisNodeCommand::m_node, KisNode::projectionPlane(), propsWithNoUpdates(), KisBaseNode::sectionModelProperties(), and KisBaseNode::setSectionModelProperties().

◆ setNodePropertiesAutoUndo()

void KisNodePropertyListCommand::setNodePropertiesAutoUndo ( KisNodeSP node,
KisImageSP image,
PropertyList proplist )
static

HACK ALERT!

Here we start a fake legacy stroke, so that all the LoD planes would be invalidated. Ideally, we should refactor this method and avoid resetting LoD planes when node visibility changes, Instead there should be two commands executes: LoD agnostic one (which sets the properties themselves), and two LoD-specific update commands: one for lodN and another one for lod0.

Definition at line 231 of file kis_node_property_list_command.cpp.

232{
233 const QSet<QString> properties = changedProperties(node->sectionModelProperties(), proplist);
234
235 const bool undo = !properties.isEmpty() &&
236 (properties.size() != 1 ||
238
239 std::unique_ptr<KUndo2Command> cmd(new KisNodePropertyListCommand(node, proplist));
240
241 if (undo) {
242 image->undoAdapter()->addCommand(cmd.release());
243 }
244 else {
256 struct SimpleLodResettingStroke : public KisSimpleStrokeStrategy {
257 SimpleLodResettingStroke(KUndo2Command *cmd)
258 : KisSimpleStrokeStrategy(QLatin1String("SimpleLodResettingStroke")),
259 m_cmd(cmd)
260 {
261 setClearsRedoOnStart(false);
262 this->enableJob(JOB_INIT, true);
263 }
264
265 void initStrokeCallback() override {
266 m_cmd->redo();
267 // NOTE: we don't Q_EMIT imageModified signal here because this
268 // branch is only taken for the stasis changes, that do not
269 // change actual image representation.
270 }
271
272 private:
273 QScopedPointer<KUndo2Command> m_cmd;
274 };
275
276 KisStrokeId strokeId = image->startStroke(new SimpleLodResettingStroke(cmd.release()));
277 image->endStroke(strokeId);
278 }
279
280}
KisUndoAdapter * undoAdapter() const
KisStrokeId startStroke(KisStrokeStrategy *strokeStrategy) override
void endStroke(KisStrokeId id) override
KisNodePropertyListCommand(KisNodeSP node, KisBaseNode::PropertyList newPropertyList)
virtual void addCommand(KUndo2Command *cmd)=0

References KisUndoAdapter::addCommand(), KisImage::endStroke(), KisLayerPropertiesIcons::isStatelessProperty(), KisNodePropertyListCommand(), KisBaseNode::sectionModelProperties(), KisImage::startStroke(), undo(), and KisImage::undoAdapter().

◆ undo()

void KisNodePropertyListCommand::undo ( )
overridevirtual

Reverts a change to the document. After undo() is called, the state of the document should be the same as before redo() was called. This function must be implemented in the derived class. Calling KUndo2QStack::push(), KUndo2QStack::undo() or KUndo2QStack::redo() from this function leads to undefined behavior.

The default implementation calls undo() on all child commands in reverse order.

See also
redo()

Reimplemented from KUndo2Command.

Definition at line 86 of file kis_node_property_list_command.cpp.

87{
89 const QSet<QString> changed = changedProperties(propsBefore, m_oldPropertyList);
90 if (changed.isEmpty()) return;
91
92 const QRect oldExtent = m_node->projectionPlane()->tightUserVisibleBounds();
94
95 if (!propsWithNoUpdates().contains(changed)) {
96 doUpdate(propsBefore, m_node->sectionModelProperties(), oldExtent | m_node->projectionPlane()->tightUserVisibleBounds());
97 }
98}

References doUpdate(), KisNodeCommand::m_node, m_oldPropertyList, KisNode::projectionPlane(), propsWithNoUpdates(), KisBaseNode::sectionModelProperties(), and KisBaseNode::setSectionModelProperties().

Member Data Documentation

◆ m_newPropertyList

KisBaseNode::PropertyList KisNodePropertyListCommand::m_newPropertyList
private

Definition at line 43 of file kis_node_property_list_command.h.

◆ m_oldPropertyList

KisBaseNode::PropertyList KisNodePropertyListCommand::m_oldPropertyList
private

Definition at line 44 of file kis_node_property_list_command.h.


The documentation for this class was generated from the following files: