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

The KisFileLayer class loads a particular file as a layer into the layer stack. More...

#include <kis_file_layer.h>

+ Inheritance diagram for KisFileLayer:

Public Types

enum  ScalingMethod { None , ToImageSize , ToImagePPI }
 
- Public Types inherited from KisNode
enum  PositionToFilthy { N_ABOVE_FILTHY = 0x08 , N_FILTHY_PROJECTION = 0x20 , N_FILTHY = 0x40 , N_BELOW_FILTHY = 0x80 }
 
- Public Types inherited from KisBaseNode
typedef QList< PropertyPropertyList
 

Signals

void sigRequestOpenFile ()
 
- Signals inherited from KisNode
void sigNodeChangedInternal ()
 
- Signals inherited from KisBaseNode
void keyframeChannelAdded (KisKeyframeChannel *channel)
 
void opacityChanged (quint8 value)
 

Public Member Functions

bool accept (KisNodeVisitor &) override
 
void accept (KisProcessingVisitor &visitor, KisUndoAdapter *undoAdapter) override
 
bool allowAsChild (KisNodeSP) const override
 
KisNodeSP clone () const override
 
KUndo2Commandcrop (const QRect &rect) override
 
QString fileName () const
 
QIcon icon () const override
 
 KisFileLayer (const KisFileLayer &rhs)
 
 KisFileLayer (KisImageWSP image, const QString &basePath, const QString &filename, ScalingMethod scalingMethod, QString scalingFilter, const QString &name, quint8 opacity, const KoColorSpace *fallbackColorSpace=0)
 KisFileLayer create a new file layer with the given file.
 
 KisFileLayer (KisImageWSP image, const QString &name, quint8 opacity)
 
KisPaintDeviceSP original () const override
 
KisPaintDeviceSP paintDevice () const override
 
QString path () const
 
void resetCache (const KoColorSpace *colorSpace=0) override
 
QString scalingFilter () const
 
ScalingMethod scalingMethod () const
 
KisBaseNode::PropertyList sectionModelProperties () const override
 
void setFileName (const QString &basePath, const QString &filename)
 setFileName replace the existing file with a new one
 
void setImage (KisImageWSP image) override
 
void setScalingFilter (QString method)
 
void setScalingMethod (ScalingMethod method)
 
void setSectionModelProperties (const KisBaseNode::PropertyList &properties) override
 
KUndo2Commandtransform (const QTransform &transform) override
 
 ~KisFileLayer () override
 
- Public Member Functions inherited from KisExternalLayer
virtual KUndo2CommandconvertTo (const KoColorSpace *dstColorSpace, KoColorConversionTransformation::Intent renderingIntent=KoColorConversionTransformation::internalRenderingIntent(), KoColorConversionTransformation::ConversionFlags conversionFlags=KoColorConversionTransformation::internalConversionFlags())
 
 KisExternalLayer (KisImageWSP image, const QString &name, quint8 opacity)
 
virtual KUndo2CommandsetProfile (const KoColorProfile *profile)
 
virtual bool supportsPerspectiveTransform () const
 
virtual QRect theoreticalBoundingRect () const
 
- Public Member Functions inherited from KisLayer
bool alphaChannelDisabled () const
 
void buildProjectionUpToNode (KisPaintDeviceSP projection, KisNodeSP lastNode, const QRect &rect)
 
QBitArray & channelFlags () const
 
KisFilterMaskSP colorOverlayMask () const
 
const KoColorSpacecolorSpace () const override
 returns the image's colorSpace or null, if there is no image
 
const KoCompositeOpcompositeOp () const override
 returns the layer's composite op for the colorspace of the layer's parent.
 
virtual KisLayerSP createMergedLayerTemplate (KisLayerSP prevLayer)
 
QImage createThumbnail (qint32 w, qint32 h, Qt::AspectRatioMode aspectRatioMode=Qt::IgnoreAspectRatio) override
 
QImage createThumbnailForFrame (qint32 w, qint32 h, int time, Qt::AspectRatioMode aspectRatioMode=Qt::IgnoreAspectRatio) override
 
void disableAlphaChannel (bool disable)
 
QList< KisEffectMaskSPeffectMasks () const
 
QList< KisEffectMaskSPeffectMasks (KisNodeSP lastNode) const
 
QRect exactBounds () const override
 
QRect extent () const override
 
virtual void fillMergedLayerTemplate (KisLayerSP dstLayer, KisLayerSP prevLayer, bool skipPaintingThisLayer=false)
 
bool hasClones () const
 
bool hasEffectMasks () const
 
virtual KisLayerProjectionPlaneSP internalProjectionPlane () const
 
 KisLayer (const KisLayer &rhs)
 
 KisLayer (KisImageWSP image, const QString &name, quint8 opacity)
 
KisPSDLayerStyleSP layerStyle () const
 
QRect looseUserVisibleBounds () const
 
KisMetaData::StoremetaData ()
 
virtual bool needProjection () const
 
void notifyChildMaskChanged ()
 
KisLayerSP parentLayer () const
 
QRect partialChangeRect (KisNodeSP lastNode, const QRect &rect)
 
 Private (KisLayer *q)
 
KisPaintDeviceSP projection () const override
 
KisAbstractProjectionPlaneSP projectionPlane () const override
 
void registerClone (KisCloneLayerWSP clone)
 
const QList< KisCloneLayerWSPregisteredClones () const
 
KisBaseNode::PropertyList sectionModelProperties () const override
 
virtual KisSelectionSP selection () const
 
virtual KisSelectionMaskSP selectionMask () const
 
virtual void setChannelFlags (const QBitArray &channelFlags)
 
void setImage (KisImageWSP image) override
 
void setLayerStyle (KisPSDLayerStyleSP layerStyle)
 
void setSectionModelProperties (const KisBaseNode::PropertyList &properties) override
 
void setTemporary (bool t)
 
void setX (qint32 x) override
 
void setY (qint32 y) override
 
bool temporary () const
 
int thumbnailSeqNo () const override
 
QRect tightUserVisibleBounds () const
 
void unregisterClone (KisCloneLayerWSP clone)
 
void updateClones (const QRect &rect, bool dontInvalidateFrames)
 
qint32 x () const override
 
qint32 y () const override
 
 ~KisLayer () override
 
- Public Member Functions inherited from Private
 Private (KisCanvas2 *c)
 
- Public Member Functions inherited from KisNode
bool accept (KisNodeVisitor &v) override
 
void accept (KisProcessingVisitor &visitor, KisUndoAdapter *undoAdapter) override
 
KisNodeSP at (quint32 index) const
 
KisBusyProgressIndicatorbusyProgressIndicator () const
 
quint32 childCount () const
 
QList< KisNodeSPchildNodes (const QStringList &nodeTypes, const KoProperties &properties) const
 
const KisNodefindSymmetricClone (const KisNode *srcRoot, const KisNode *dstRoot, const KisNode *srcTarget)
 
KisNodeSP firstChild () const
 
virtual KisPaintDeviceList getLodCapableDevices () const
 
KisNodeGraphListenergraphListener () const
 
int graphSequenceNumber () const
 
void handleKeyframeChannelFrameAboutToBeRemoved (const KisKeyframeChannel *channel, int time)
 
virtual void handleKeyframeChannelFrameAdded (const KisKeyframeChannel *channel, int time)
 
virtual void handleKeyframeChannelFrameChange (const KisKeyframeChannel *channel, int time)
 
void handleKeyframeChannelFrameHasBeenRemoved (const KisKeyframeChannel *channel, int time)
 
KisFrameChangeUpdateRecipe handleKeyframeChannelUpdateImpl (const KisKeyframeChannel *channel, int time)
 
int index (const KisNodeSP node) const
 
void invalidateFrames (const KisTimeSpan &range, const QRect &rect)
 
 KisNode (const KisNode &rhs)
 
 KisNode (KisImageWSP image)
 
KisNodeSP lastChild () const
 
KisNodeSP nextSibling () const
 
KisNodeProgressProxynodeProgressProxy () const
 
KisNodeSP parent () const
 
KisNodeSP prevSibling () const
 
 Private (KisNode *node)
 
void processDuplicatedClones (const KisNode *srcDuplicationRoot, const KisNode *dstDuplicationRoot, KisNode *node)
 
virtual KisProjectionLeafSP projectionLeaf () const
 
void requestTimeSwitch (int time)
 
virtual void setDirty ()
 
void setDirty (const KisRegion &region)
 
void setDirty (const QRect &rect)
 
virtual void setDirty (const QVector< QRect > &rects)
 
void setDirtyDontResetAnimationCache ()
 
void setDirtyDontResetAnimationCache (const QRect &rect)
 
void setDirtyDontResetAnimationCache (const QVector< QRect > &rects)
 setDirtyDontResetAnimationCache does almost the same thing as usual setDirty() call, but doesn't reset the animation cache (since onion skins are not used when rendering animation.
 
void setGraphListener (KisNodeGraphListener *graphListener)
 
void setImage (KisImageWSP newImage) override
 
virtual void syncLodCache ()
 
 ~KisNode () override
 
- Public Member Functions inherited from KisBaseNode
bool belongsToIsolatedGroup () const
 
bool check (const KoProperties &properties) const
 
bool collapsed () const
 
int colorLabelIndex () const
 
virtual KisPaintDeviceSP colorSampleSourceDevice () const
 
const QString & compositeOpId () const
 
void enableAnimation ()
 
KisKeyframeChannelgetKeyframeChannel (const QString &id) const
 
KisKeyframeChannelgetKeyframeChannel (const QString &id, bool create)
 
bool hasEditablePaintDevice () const
 
KisImageWSP image () const
 
bool isAnimated () const
 
bool isEditable (bool checkVisibility=true) const
 
virtual bool isFakeNode () const
 
bool isIsolatedRoot () const
 
bool isPinnedToTimeline () const
 
QMap< QString, KisKeyframeChannel * > keyframeChannels () const
 
 KisBaseNode (const KisBaseNode &rhs)
 
 KisBaseNode (KisImageWSP image)
 
void mergeNodeProperties (const KoProperties &properties)
 
QString name () const
 
const KoPropertiesnodeProperties () const
 
quint8 opacity () const
 
quint8 percentOpacity () const
 
 Private (const Private &rhs)
 
 Private (KisImageWSP p_image)
 
void setCollapsed (bool collapsed)
 
void setColorLabelIndex (int index)
 
void setCompositeOpId (const QString &compositeOpId)
 
void setName (const QString &name)
 
void setNodeProperty (const QString &name, const QVariant &value)
 
void setOpacity (quint8 val)
 
void setPercentOpacity (quint8 val)
 
void setPinnedToTimeline (bool pinned)
 
virtual void setUserLocked (bool l)
 
void setUuid (const QUuid &id)
 
virtual void setVisible (bool visible, bool loading=false)
 
virtual bool supportsKeyframeChannel (const QString &id)
 
bool supportsLodMoves () const
 
virtual bool supportsLodPainting () const
 
virtual void updateSettings ()
 
bool userLocked () const
 
QUuid uuid () const
 
virtual bool visible (bool recursive=false) const
 
 ~KisBaseNode () override
 
- Public Member Functions inherited from KisShared
bool deref ()
 
bool ref ()
 
int refCount ()
 
QAtomicInt * sharedWeakReference ()
 

Private Types

enum  State { FileLoaded , FileNotFound , FileLoadingFailed }
 

Private Slots

void openFile () const
 
void slotFileExistsStateChanged (bool exists)
 
void slotImageResolutionChanged ()
 
void slotImageSizeChanged ()
 
void slotLoadingFailed ()
 
void slotLoadingFinished (KisPaintDeviceSP projection, qreal xRes, qreal yRes, const QSize &size)
 

Private Member Functions

void changeState (State newState)
 

Private Attributes

QString m_basePath
 
QString m_filename
 
QSize m_generatedForImageSize
 
qreal m_generatedForXRes = 0.0
 
qreal m_generatedForYRes = 0.0
 
KisSignalAutoConnectionsStore m_imageConnections
 
KisSafeDocumentLoader m_loader
 
KisPaintDeviceSP m_paintDevice
 
QString m_scalingFilter
 
ScalingMethod m_scalingMethod {None}
 
State m_state = FileNotFound
 

Additional Inherited Members

- Public Attributes inherited from KisLayer
QBitArray channelFlags
 
KisCloneLayersList clonesList
 
KisPSDLayerStyleSP layerStyle
 
KisLayerStyleProjectionPlaneSP layerStyleProjectionPlane
 
KisLayerMasksCache masksCache
 
KisMetaData::StoremetaDataStore {nullptr}
 
KisLayerProjectionPlaneSP projectionPlane
 
KisSafeNodeProjectionStoreSP safeProjection
 
- Public Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 
- Public Attributes inherited from KisNode
KisBusyProgressIndicatorbusyProgressIndicator
 
std::optional< KisFrameChangeUpdateRecipeframeRemovalUpdateRecipe
 
KisNodeGraphListenergraphListener
 
KisNodeProgressProxynodeProgressProxy
 
KisSafeReadNodeList nodes
 
QReadWriteLock nodeSubgraphLock
 
KisNodeWSP parent
 
KisProjectionLeafSP projectionLeaf
 
- Public Attributes inherited from KisBaseNode
bool animated {false}
 
bool collapsed {false}
 
QString compositeOp
 
KisBaseNode::Property hack_visible
 
QUuid id
 
KisImageWSP image
 
QMap< QString, KisKeyframeChannel * > keyframeChannels
 
KisAnimatedOpacityProperty opacityProperty
 
bool pinnedToTimeline {false}
 
KoProperties properties
 
bool supportsLodMoves {false}
 
- Protected Member Functions inherited from KisLayer
virtual QRect amortizedProjectionRectForCleanupInChangePass () const
 
QRect applyMasks (const KisPaintDeviceSP source, KisPaintDeviceSP destination, const QRect &requestedRect, KisNodeSP filthyNode, KisNodeSP lastNode, KisRenderPassFlags flags) const
 
bool canMergeAndKeepBlendOptions (KisLayerSP otherLayer)
 
QRect changeRect (const QRect &rect, PositionToFilthy pos=N_FILTHY) const override
 
void childNodeChanged (KisNodeSP changedChildNode) override
 
virtual void copyOriginalToProjection (const KisPaintDeviceSP original, KisPaintDeviceSP projection, const QRect &rect) const
 
virtual QRect incomingChangeRect (const QRect &rect) const
 
QRect masksChangeRect (const QList< KisEffectMaskSP > &masks, const QRect &requestedRect, bool &rectVariesFlag) const
 
QRect masksNeedRect (const QList< KisEffectMaskSP > &masks, const QRect &changeRect, QStack< QRect > &applyRects, bool &rectVariesFlag) const
 
QRect needRectForOriginal (const QRect &rect) const
 
virtual QRect outgoingChangeRect (const QRect &rect) const
 
QList< KisEffectMaskSPsearchEffectMasks (KisNodeSP lastNode) const
 
QRect updateProjection (const QRect &rect, KisNodeSP filthyNode, KisRenderPassFlags flags)
 
- Protected Member Functions inherited from KisNode
virtual QRect accessRect (const QRect &rect, PositionToFilthy pos=N_FILTHY) const
 
void addKeyframeChannel (KisKeyframeChannel *channel) override
 
void baseNodeChangedCallback () override
 
void baseNodeCollapsedChangedCallback () override
 
void baseNodeInvalidateAllFramesCallback () override
 
virtual KisFrameChangeUpdateRecipe handleKeyframeChannelFrameAboutToBeRemovedImpl (const KisKeyframeChannel *channel, int time)
 
virtual QRect needRect (const QRect &rect, PositionToFilthy pos=N_FILTHY) const
 
void notifyParentVisibilityChanged (bool value) override
 
KisBaseNodeSP parentCallback () const override
 
- Protected Member Functions inherited from KisBaseNode
virtual KisKeyframeChannelrequestKeyframeChannel (const QString &id)
 
void setSupportsLodMoves (bool value)
 
- Protected Member Functions inherited from KisShared
 KisShared ()
 
 ~KisShared ()
 

Detailed Description

The KisFileLayer class loads a particular file as a layer into the layer stack.

Definition at line 18 of file kis_file_layer.h.

Member Enumeration Documentation

◆ ScalingMethod

Enumerator
None 
ToImageSize 
ToImagePPI 

Definition at line 23 of file kis_file_layer.h.

◆ State

enum KisFileLayer::State
private
Enumerator
FileLoaded 
FileNotFound 
FileLoadingFailed 

Definition at line 92 of file kis_file_layer.h.

Constructor & Destructor Documentation

◆ KisFileLayer() [1/3]

KisFileLayer::KisFileLayer ( KisImageWSP image,
const QString & name,
quint8 opacity )

Set default paint device for a layer. It will be used in case the file does not exist anymore. Or course, this can happen only in the failing execution path.

Definition at line 25 of file kis_file_layer.cpp.

27{
35
36 connect(&m_loader, SIGNAL(loadingFinished(KisPaintDeviceSP,qreal,qreal,QSize)), SLOT(slotLoadingFinished(KisPaintDeviceSP,qreal,qreal,QSize)));
37 connect(&m_loader, SIGNAL(loadingFailed()), SLOT(slotLoadingFailed()));
38 connect(&m_loader, SIGNAL(fileExistsStateChanged(bool)), SLOT(slotFileExistsStateChanged(bool)));
39 connect(this, SIGNAL(sigRequestOpenFile()), SLOT(openFile()));
40}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
KisExternalLayer(KisImageWSP image, const QString &name, quint8 opacity)
void slotFileExistsStateChanged(bool exists)
void sigRequestOpenFile()
KisPaintDeviceSP m_paintDevice
KisSafeDocumentLoader m_loader
void slotLoadingFinished(KisPaintDeviceSP projection, qreal xRes, qreal yRes, const QSize &size)
void openFile() const
const KoColorSpace * colorSpace() const
void setDefaultBounds(KisDefaultBoundsBaseSP bounds)
KisImageWSP image
QString name() const
quint8 opacity() const

References KisImage::colorSpace(), connect(), KisBaseNode::image, m_loader, m_paintDevice, openFile(), KisPaintDevice::setDefaultBounds(), sigRequestOpenFile(), slotFileExistsStateChanged(), slotLoadingFailed(), and slotLoadingFinished().

◆ KisFileLayer() [2/3]

KisFileLayer::KisFileLayer ( KisImageWSP image,
const QString & basePath,
const QString & filename,
ScalingMethod scalingMethod,
QString scalingFilter,
const QString & name,
quint8 opacity,
const KoColorSpace * fallbackColorSpace = 0 )

KisFileLayer create a new file layer with the given file.

Parameters
imagethe image the file layer will belong to
basePaththe path to the image, if it has been saved before.
filenamethe path to the file, relative to the basePath
scalingMethod
See also
ScalingMethod
Parameters
scalingFilterthe ID of the KisFilterStrategy to be used if scaling
namethe name of the layer
opacitythe opacity of the layer

Set default paint device for a layer. It will be used in case the file does not exist anymore. Or course, this can happen only in the failing execution path.

Definition at line 42 of file kis_file_layer.cpp.

44 , m_basePath(basePath)
45 , m_filename(filename)
46 , m_scalingMethod(scaleToImageResolution)
48{
54 m_paintDevice = new KisPaintDevice(fallbackColorSpace ? fallbackColorSpace : image->colorSpace());
56
57 connect(&m_loader, SIGNAL(loadingFinished(KisPaintDeviceSP,qreal,qreal,QSize)), SLOT(slotLoadingFinished(KisPaintDeviceSP,qreal,qreal,QSize)));
58 connect(&m_loader, SIGNAL(loadingFailed()), SLOT(slotLoadingFailed()));
59 connect(&m_loader, SIGNAL(fileExistsStateChanged(bool)), SLOT(slotFileExistsStateChanged(bool)));
60 connect(this, SIGNAL(sigRequestOpenFile()), SLOT(openFile()));
61
62 QFileInfo fi(path());
63 if (fi.exists()) {
66 }
67}
ScalingMethod m_scalingMethod
QString path() const
QString m_scalingFilter
QString scalingFilter() const
void setPath(const QString &path)
const KoColorSpace * colorSpace() const override
returns the image's colorSpace or null, if there is no image
Definition kis_layer.cc:225

References KisImage::colorSpace(), connect(), KisBaseNode::image, m_loader, m_paintDevice, openFile(), path(), KisSafeDocumentLoader::reloadImage(), KisPaintDevice::setDefaultBounds(), KisSafeDocumentLoader::setPath(), sigRequestOpenFile(), slotFileExistsStateChanged(), slotLoadingFailed(), and slotLoadingFinished().

◆ ~KisFileLayer()

KisFileLayer::~KisFileLayer ( )
override

Definition at line 69 of file kis_file_layer.cpp.

70{
71}

◆ KisFileLayer() [3/3]

Member Function Documentation

◆ accept() [1/2]

bool KisFileLayer::accept ( KisNodeVisitor & )
overridevirtual

Accept the KisNodeVisitor (for the Visitor design pattern), should call the correct function on the KisNodeVisitor for this node type, so you need to override it for all leaf classes in the node inheritance hierarchy.

return false if the visitor could not successfully act on this node instance.

Reimplemented from KisBaseNode.

Definition at line 335 of file kis_file_layer.cpp.

336{
337 return visitor.visit(this);
338}

References KisNodeVisitor::visit().

◆ accept() [2/2]

void KisFileLayer::accept ( KisProcessingVisitor & visitor,
KisUndoAdapter * undoAdapter )
overridevirtual

Accept the KisNodeVisitor (for the Visitor design pattern), should call the correct function on the KisProcessingVisitor for this node type, so you need to override it for all leaf classes in the node inheritance hierarchy.

The processing visitor differs from node visitor in the way that it accepts undo adapter, that allows the processing to be multithreaded

Reimplemented from KisBaseNode.

Definition at line 340 of file kis_file_layer.cpp.

341{
342 return visitor.visit(this, undoAdapter);
343}
virtual void visit(KisNode *node, KisUndoAdapter *undoAdapter)=0

References KisProcessingVisitor::visit().

◆ allowAsChild()

bool KisFileLayer::allowAsChild ( KisNodeSP ) const
overridevirtual

Re-implement this method to add constraints for the subclasses that can be added as children to this node

Returns
false if the given node is not allowed as a child to this node

Implements KisNode.

Definition at line 330 of file kis_file_layer.cpp.

331{
332 return node->inherits("KisMask");
333}

◆ changeState()

void KisFileLayer::changeState ( State newState)
private

Definition at line 230 of file kis_file_layer.cpp.

231{
232 const State oldState = m_state;
233 m_state = newState;
234 if (oldState != newState) {
236 }
237}
void baseNodeChangedCallback() override
Definition kis_node.cpp:329

References KisNode::baseNodeChangedCallback(), and m_state.

◆ clone()

KisNodeSP KisFileLayer::clone ( ) const
overridevirtual

Implements KisNode.

Definition at line 325 of file kis_file_layer.cpp.

326{
327 return KisNodeSP(new KisFileLayer(*this));
328}
KisFileLayer(KisImageWSP image, const QString &name, quint8 opacity)
KisSharedPtr< KisNode > KisNodeSP
Definition kis_types.h:86

References KisFileLayer().

◆ crop()

KUndo2Command * KisFileLayer::crop ( const QRect & rect)
overridevirtual

Reimplemented from KisExternalLayer.

Definition at line 345 of file kis_file_layer.cpp.

346{
347 QPoint oldPos(x(), y());
348 QPoint newPos = oldPos - rect.topLeft();
349
350 return new KisNodeMoveCommand2(this, oldPos, newPos);
351}
qint32 y() const override
Definition kis_layer.cc:978
qint32 x() const override
Definition kis_layer.cc:973

References KisLayer::x(), and KisLayer::y().

◆ fileName()

QString KisFileLayer::fileName ( ) const

Definition at line 165 of file kis_file_layer.cpp.

166{
167 return m_filename;
168}

References m_filename.

◆ icon()

QIcon KisFileLayer::icon ( ) const
overridevirtual
Returns
the icon used to represent the node type, for instance in the layerbox and in the menu.

Reimplemented from KisExternalLayer.

Definition at line 93 of file kis_file_layer.cpp.

94{
95 return KisIconUtils::loadIcon("fileLayer");
96}
QIcon loadIcon(const QString &name)

References KisIconUtils::loadIcon().

◆ openFile

void KisFileLayer::openFile ( ) const
privateslot

Definition at line 184 of file kis_file_layer.cpp.

185{
186 bool fileAlreadyOpen = false;
187 Q_FOREACH (KisDocument *doc, KisPart::instance()->documents()) {
188 if (doc->path()==path()){
189 fileAlreadyOpen = true;
190 }
191 }
192 if (qEnvironmentVariableIsSet("KRITA_ENABLE_ASSERT_TESTS")) {
194 if (m_filename.toLower() == "crash_me_with_safe_assert") {
195 KIS_SAFE_ASSERT_RECOVER_NOOP(0 && "safe assert for testing purposes");
196 }
197 if (m_filename.toLower() == "crash_me_with_normal_assert") {
198 KIS_ASSERT_RECOVER_NOOP(0 && "normal assert for testing purposes");
199 }
200 if (m_filename.toLower() == "crash_me_with_qfatal") {
201 qFatal("Testing fatal message");
202 }
203
204 if (m_filename.toLower() == "crash_me_with_asan") {
205#if defined(__has_feature)
206#if __has_feature(address_sanitizer)
215 int *array = new int[10];
216 qDebug() << "Reading past the end of the allocated array" << array[10];
217 delete[] array;
218#else
219 qDebug() << "ASAN is not enabled for this build!";
220#endif
221#endif
222 }
223 }
224
225 if (!fileAlreadyOpen && QFile::exists(QFileInfo(path()).absoluteFilePath())) {
226 KisPart::instance()->openExistingFile(QFileInfo(path()).absoluteFilePath());
227 }
228}
QString path() const
static KisPart * instance()
Definition KisPart.cpp:131
void openExistingFile(const QString &path)
Definition KisPart.cpp:537
#define KIS_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:97
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130
#define ENTER_FUNCTION()
Definition kis_debug.h:178
#define ppVar(var)
Definition kis_debug.h:155

References ENTER_FUNCTION, KisPart::instance(), KIS_ASSERT_RECOVER_NOOP, KIS_SAFE_ASSERT_RECOVER_NOOP, m_filename, KisPart::openExistingFile(), path(), KisDocument::path(), and ppVar.

◆ original()

KisPaintDeviceSP KisFileLayer::original ( ) const
overridevirtual

Return the layer data before the effect masks have had their go at it.

Implements KisLayer.

Definition at line 104 of file kis_file_layer.cpp.

105{
106 return m_paintDevice;
107}

References m_paintDevice.

◆ paintDevice()

KisPaintDeviceSP KisFileLayer::paintDevice ( ) const
overridevirtual

Return the paintdevice you can use to change pixels on. For a paint layer these will be paint pixels, for an adjustment layer or a mask the selection paint device.

Returns
the paint device to paint on. Can be 0 if the actual node type does not support painting.

Implements KisBaseNode.

Definition at line 109 of file kis_file_layer.cpp.

110{
111 return 0;
112}

◆ path()

QString KisFileLayer::path ( ) const

Definition at line 170 of file kis_file_layer.cpp.

171{
172 if (m_basePath.isEmpty()) {
173 return m_filename;
174 }
175 else {
176#ifndef Q_OS_ANDROID
177 return QDir(m_basePath).filePath(QDir::cleanPath(m_filename));
178#else
179 return m_filename;
180#endif
181 }
182}

References m_basePath, and m_filename.

◆ resetCache()

void KisFileLayer::resetCache ( const KoColorSpace * colorSpace = 0)
overridevirtual

Reimplemented from KisExternalLayer.

Definition at line 98 of file kis_file_layer.cpp.

99{
100 Q_UNUSED(colorSpace);
102}

References KisLayer::colorSpace(), m_loader, and KisSafeDocumentLoader::reloadImage().

◆ scalingFilter()

QString KisFileLayer::scalingFilter ( ) const

Definition at line 249 of file kis_file_layer.cpp.

250{
251 return m_scalingFilter;
252}

References m_scalingFilter.

◆ scalingMethod()

KisFileLayer::ScalingMethod KisFileLayer::scalingMethod ( ) const

Definition at line 239 of file kis_file_layer.cpp.

240{
241 return m_scalingMethod;
242}

References m_scalingMethod.

◆ sectionModelProperties()

KisBaseNode::PropertyList KisFileLayer::sectionModelProperties ( ) const
overridevirtual

Return a the properties of this base node (locked, visible etc, with the right icons for their representation and their state.

Subclasses can extend this list with new properties, like opacity for layers or visualized for masks.

The order of properties is, unfortunately, for now, important, so take care which properties superclasses of your class define.

KisBaseNode defines visible = 0, locked = 1 KisLayer defines opacity = 2, compositeOp = 3 KisMask defines active = 2 (KisMask does not inherit kislayer)

Reimplemented from KisBaseNode.

Definition at line 126 of file kis_file_layer.cpp.

127{
129 l << KisBaseNode::Property(KoID("sourcefile", i18n("File")), m_filename);
131
132 auto fileNameOrPlaceholder =
133 [this] () {
134 return !m_filename.isEmpty() ? m_filename : i18nc("placeholder test for a warning when not file is set in the file layer", "<No file name is set>");
135 };
136
137 if (m_state == FileNotFound) {
138 l << KisLayerPropertiesIcons::getErrorProperty(i18nc("a tooltip shown when a file layer cannot find its linked file",
139 "Linked file not found: %1", fileNameOrPlaceholder()));
140 } else if (m_state == FileLoadingFailed) {
141 l << KisLayerPropertiesIcons::getErrorProperty(i18nc("a tooltip shown when a file layer cannot load its linked file",
142 "Failed to load linked file: %1", fileNameOrPlaceholder()));
143 }
144
146 KisImageSP image = this->image();
147 if (image && *image->colorSpace() != *cs) {
149 }
150
151 return l;
152}
static KisBaseNode::Property getColorSpaceMismatchProperty(const KoColorSpace *cs)
static KisBaseNode::Property getErrorProperty(const QString &message)
static KisBaseNode::Property getProperty(const KoID &id, bool state)
const KoColorSpace * colorSpace() const
Definition KoID.h:30
KisBaseNode::PropertyList sectionModelProperties() const override
Definition kis_layer.cc:272

References KisImage::colorSpace(), KisPaintDevice::colorSpace(), FileLoadingFailed, FileNotFound, KisLayerPropertiesIcons::getColorSpaceMismatchProperty(), KisLayerPropertiesIcons::getErrorProperty(), KisLayerPropertiesIcons::getProperty(), KisBaseNode::image, m_filename, m_paintDevice, m_state, KisLayerPropertiesIcons::openFileLayerFile, and KisLayer::sectionModelProperties().

◆ setFileName()

void KisFileLayer::setFileName ( const QString & basePath,
const QString & filename )

setFileName replace the existing file with a new one

Parameters
basePaththe path to the image, if it has been saved before.
filenamethe path to the file, relative to the basePath

Definition at line 154 of file kis_file_layer.cpp.

155{
156 m_basePath = basePath;
157 m_filename = filename;
158 QFileInfo fi(path());
159 if (fi.exists()) {
162 }
163}

References m_basePath, m_filename, m_loader, path(), KisSafeDocumentLoader::reloadImage(), and KisSafeDocumentLoader::setPath().

◆ setImage()

void KisFileLayer::setImage ( KisImageWSP image)
overridevirtual

Reimplemented from KisBaseNode.

Definition at line 382 of file kis_file_layer.cpp.

383{
384 KisImageWSP oldImage = this->image();
386
389
390 if (image) {
391 m_imageConnections.addUniqueConnection(image, SIGNAL(sigSizeChanged(QPointF,QPointF)), this, SLOT(slotImageSizeChanged()));
392 m_imageConnections.addUniqueConnection(image, SIGNAL(sigResolutionChanged(double, double)), this, SLOT(slotImageResolutionChanged()));
393 }
394
395 if (m_scalingMethod != None && image && oldImage != image) {
396 bool canSkipReloading = false;
397
399 canSkipReloading = true;
400 }
401
402 if (m_scalingMethod == ToImagePPI && image &&
404 qFuzzyCompare(image->yRes(), m_generatedForYRes)) {
405
406 canSkipReloading = true;
407 }
408
409 if (!canSkipReloading) {
411 }
412 }
413}
void slotImageResolutionChanged()
void slotImageSizeChanged()
KisSignalAutoConnectionsStore m_imageConnections
QSize size() const
Definition kis_image.h:547
double xRes() const
double yRes() const
void addUniqueConnection(Sender sender, Signal signal, Receiver receiver, Method method)
static bool qFuzzyCompare(half p1, half p2)
virtual void setImage(KisImageWSP image)

References KisSignalAutoConnectionsStore::addUniqueConnection(), KisSignalAutoConnectionsStore::clear(), KisBaseNode::image, m_generatedForImageSize, m_generatedForXRes, m_generatedForYRes, m_imageConnections, m_loader, m_paintDevice, m_scalingMethod, None, qFuzzyCompare(), KisSafeDocumentLoader::reloadImage(), KisPaintDevice::setDefaultBounds(), KisBaseNode::setImage(), KisImage::size(), slotImageResolutionChanged(), slotImageSizeChanged(), ToImagePPI, ToImageSize, KisImage::xRes(), and KisImage::yRes().

◆ setScalingFilter()

void KisFileLayer::setScalingFilter ( QString method)

Definition at line 254 of file kis_file_layer.cpp.

255{
256 m_scalingFilter = filter;
257}

References m_scalingFilter.

◆ setScalingMethod()

void KisFileLayer::setScalingMethod ( ScalingMethod method)

Definition at line 244 of file kis_file_layer.cpp.

245{
246 m_scalingMethod = method;
247}

References m_scalingMethod.

◆ setSectionModelProperties()

void KisFileLayer::setSectionModelProperties ( const KisBaseNode::PropertyList & properties)
overridevirtual

Change the section model properties.

Reimplemented from KisBaseNode.

Definition at line 114 of file kis_file_layer.cpp.

115{
117 Q_FOREACH (const KisBaseNode::Property &property, properties) {
119 if (property.state.toBool() == false) {
120 Q_EMIT sigRequestOpenFile();
121 }
122 }
123 }
124}
QString id() const
Definition KoID.cpp:63
KoProperties properties
virtual void setSectionModelProperties(const PropertyList &properties)

References KoID::id(), KisBaseNode::Property::id, KisLayerPropertiesIcons::openFileLayerFile, KisBaseNode::properties, KisBaseNode::setSectionModelProperties(), sigRequestOpenFile(), and KisBaseNode::Property::state.

◆ sigRequestOpenFile

void KisFileLayer::sigRequestOpenFile ( )
signal

◆ slotFileExistsStateChanged

void KisFileLayer::slotFileExistsStateChanged ( bool exists)
privateslot

Definition at line 320 of file kis_file_layer.cpp.

321{
323}
void changeState(State newState)

References changeState(), FileLoaded, and FileNotFound.

◆ slotImageResolutionChanged

void KisFileLayer::slotImageResolutionChanged ( )
privateslot

◆ slotImageSizeChanged

void KisFileLayer::slotImageSizeChanged ( )
privateslot

◆ slotLoadingFailed

void KisFileLayer::slotLoadingFailed ( )
privateslot

Definition at line 315 of file kis_file_layer.cpp.

316{
318}

References changeState(), and FileLoadingFailed.

◆ slotLoadingFinished

void KisFileLayer::slotLoadingFinished ( KisPaintDeviceSP projection,
qreal xRes,
qreal yRes,
const QSize & size )
privateslot

This method can be transitively called from KisFileLayer::setImage(), which, in turn, can be called from the KisImage's copy-ctor. The shared pointer is, obviously, not initialized during construction, therefore upgrading our constructor to a strong pointer will cause a crash.

Therefore, we use a weak pointer here. It is extremely dangerous, but since this method is usually called from the GUI thread synchronously it should be "somewhat safe".

Definition at line 259 of file kis_file_layer.cpp.

262{
263 qint32 oldX = x();
264 qint32 oldY = y();
265 const QRect oldLayerExtent = m_paintDevice->extent();
266
267
270
281 KisImageWSP image = this->image();
282 if (image) {
284 (!qFuzzyCompare(image->xRes(), xRes) ||
285 !qFuzzyCompare(image->yRes(), yRes))) {
286
287 qreal xscale = image->xRes() / xRes;
288 qreal yscale = image->yRes() / yRes;
289
290 KisTransformWorker worker(m_paintDevice, xscale, yscale, 0.0, 0, 0, 0, 0, 0, KisFilterStrategyRegistry::instance()->get(m_scalingFilter));
291 worker.run();
292 }
293 else if (m_scalingMethod == ToImageSize && size != image->size()) {
294 QSize sz = size;
295 sz.scale(image->size(), Qt::KeepAspectRatio);
296 qreal xscale = (qreal)sz.width() / (qreal)size.width();
297 qreal yscale = (qreal)sz.height() / (qreal)size.height();
298
299 KisTransformWorker worker(m_paintDevice, xscale, yscale, 0.0, 0, 0, 0, 0, 0, KisFilterStrategyRegistry::instance()->get(m_scalingFilter));
300 worker.run();
301 }
302
306 }
307
308 m_paintDevice->setX(oldX);
309 m_paintDevice->setY(oldY);
310
312 setDirty(m_paintDevice->extent() | oldLayerExtent);
313}
VertexDescriptor get(PredecessorMap const &m, VertexDescriptor v)
static KisFilterStrategyRegistry * instance()
void setX(qint32 x)
QRect extent() const
void setY(qint32 y)
void makeCloneFrom(KisPaintDeviceSP src, const QRect &rect)
int size(const Forest< T > &forest)
Definition KisForest.h:1232
KisPaintDeviceSP projection() const override
Definition kis_layer.cc:820
virtual void setDirty()
Definition kis_node.cpp:577

References changeState(), KisPaintDevice::extent(), FileLoaded, get(), KisBaseNode::image, KisFilterStrategyRegistry::instance(), m_generatedForImageSize, m_generatedForXRes, m_generatedForYRes, m_paintDevice, m_scalingFilter, m_scalingMethod, KisPaintDevice::makeCloneFrom(), KisLayer::projection(), qFuzzyCompare(), KisTransformWorker::run(), KisPaintDevice::setDefaultBounds(), KisNode::setDirty(), KisPaintDevice::setX(), KisPaintDevice::setY(), KisImage::size(), ToImagePPI, ToImageSize, KisLayer::x(), KisImage::xRes(), KisLayer::y(), and KisImage::yRes().

◆ transform()

KUndo2Command * KisFileLayer::transform ( const QTransform & transform)
overridevirtual

Reimplemented from KisExternalLayer.

Definition at line 353 of file kis_file_layer.cpp.

354{
355 warnKrita << "WARNING: File Layer does not support transformations!" << name();
356 return 0;
357}
#define warnKrita
Definition kis_debug.h:87

References KisBaseNode::name(), and warnKrita.

Member Data Documentation

◆ m_basePath

QString KisFileLayer::m_basePath
private

Definition at line 101 of file kis_file_layer.h.

◆ m_filename

QString KisFileLayer::m_filename
private

Definition at line 102 of file kis_file_layer.h.

◆ m_generatedForImageSize

QSize KisFileLayer::m_generatedForImageSize
private

Definition at line 108 of file kis_file_layer.h.

◆ m_generatedForXRes

qreal KisFileLayer::m_generatedForXRes = 0.0
private

Definition at line 109 of file kis_file_layer.h.

◆ m_generatedForYRes

qreal KisFileLayer::m_generatedForYRes = 0.0
private

Definition at line 110 of file kis_file_layer.h.

◆ m_imageConnections

KisSignalAutoConnectionsStore KisFileLayer::m_imageConnections
private

Definition at line 114 of file kis_file_layer.h.

◆ m_loader

KisSafeDocumentLoader KisFileLayer::m_loader
private

Definition at line 107 of file kis_file_layer.h.

◆ m_paintDevice

KisPaintDeviceSP KisFileLayer::m_paintDevice
private

Definition at line 106 of file kis_file_layer.h.

◆ m_scalingFilter

QString KisFileLayer::m_scalingFilter
private

Definition at line 104 of file kis_file_layer.h.

◆ m_scalingMethod

ScalingMethod KisFileLayer::m_scalingMethod {None}
private

Definition at line 103 of file kis_file_layer.h.

103{None};

◆ m_state

State KisFileLayer::m_state = FileNotFound
private

Definition at line 112 of file kis_file_layer.h.


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