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

#include <kis_kra_load_visitor.h>

+ Inheritance diagram for KisKraLoadVisitor:

Public Member Functions

QStringList errorMessages () const
 
 KisKraLoadVisitor (KisImageSP image, KoStore *store, KoShapeControllerBase *shapeController, QMap< KisNode *, QString > &layerFilenames, QMap< KisNode *, QString > &keyframeFilenames, const QString &name, int syntaxVersion)
 
void setExternalUri (const QString &uri)
 
bool visit (KisAdjustmentLayer *layer) override
 
bool visit (KisCloneLayer *layer) override
 
bool visit (KisColorizeMask *mask) override
 
bool visit (KisExternalLayer *) override
 
bool visit (KisFilterMask *mask) override
 
bool visit (KisGeneratorLayer *layer) override
 
bool visit (KisGroupLayer *layer) override
 
bool visit (KisNode *) override
 
bool visit (KisPaintLayer *layer) override
 
bool visit (KisSelectionMask *mask) override
 
bool visit (KisTransformMask *mask) override
 
bool visit (KisTransparencyMask *mask) override
 
QStringList warningMessages () const
 
- Public Member Functions inherited from KisNodeVisitor
 KisNodeVisitor ()
 
virtual ~KisNodeVisitor ()
 

Private Member Functions

void fixOldFilterConfigurations (KisFilterConfigurationSP kfc)
 
QString getLocation (const QString &filename, const QString &suffix=QString())
 
QString getLocation (KisNode *node, const QString &suffix=QString())
 
void initSelectionForMask (KisMask *mask)
 
void loadDeprecatedFilter (KisFilterConfigurationSP cfg)
 
bool loadFilterConfiguration (KisFilterConfigurationSP kfc, const QString &location)
 
bool loadMetaData (KisNode *node)
 
void loadNodeKeyframes (KisNode *node)
 
bool loadPaintDevice (KisPaintDeviceSP device, const QString &location)
 
template<class DevicePolicy >
bool loadPaintDeviceFrame (KisPaintDeviceSP device, const QString &location, DevicePolicy policy)
 
const KoColorProfileloadProfile (const QString &location, const QString &colorModelId, const QString &colorDepthId)
 
bool loadProfile (KisPaintDeviceSP device, const QString &location)
 
bool loadSelection (const QString &location, KisSelectionSP dstSelection)
 

Private Attributes

QStringList m_errorMessages
 
bool m_external
 
KisImageSP m_image
 
QMap< KisNode *, QString > m_keyframeFilenames
 
QMap< KisNode *, QString > m_layerFilenames
 
QString m_name
 
QMap< QString, const KoColorProfile * > m_profileCache
 
KoShapeControllerBasem_shapeController
 
KoStorem_store
 
int m_syntaxVersion
 
QString m_uri
 
QStringList m_warningMessages
 

Additional Inherited Members

- Protected Member Functions inherited from KisNodeVisitor
bool visitAll (KisNode *node, bool breakOnFail=false)
 
bool visitAllInverse (KisNode *node, bool breakOnFail=false)
 

Detailed Description

Definition at line 25 of file kis_kra_load_visitor.h.

Constructor & Destructor Documentation

◆ KisKraLoadVisitor()

KisKraLoadVisitor::KisKraLoadVisitor ( KisImageSP image,
KoStore * store,
KoShapeControllerBase * shapeController,
QMap< KisNode *, QString > & layerFilenames,
QMap< KisNode *, QString > & keyframeFilenames,
const QString & name,
int syntaxVersion )

Definition at line 85 of file kis_kra_load_visitor.cpp.

93 , m_image(image)
94 , m_store(store)
95 , m_external(false)
96 , m_layerFilenames(layerFilenames)
97 , m_keyframeFilenames(keyframeFilenames)
98 , m_name(name)
99 , m_shapeController(shapeController)
100{
102
104 QStringList directories = m_store->directoryList();
105 dbgKrita << directories;
106 if (directories.size() > 0) {
107 dbgFile << "Could not locate the directory, maybe some encoding issue? Grab the first directory, that'll be the image one." << m_name << directories;
108 m_name = directories.first();
109 }
110 else {
111 dbgFile << "Could not enter directory" << m_name << ", probably an old-style file with 'part' added.";
113 }
114 }
115 else {
117 }
118 m_syntaxVersion = syntaxVersion;
119}
QMap< KisNode *, QString > m_keyframeFilenames
KoShapeControllerBase * m_shapeController
QMap< KisNode *, QString > m_layerFilenames
void pushDirectory()
Definition KoStore.cpp:294
void popDirectory()
Definition KoStore.cpp:300
virtual QStringList directoryList() const
Definition KoStore.cpp:426
virtual bool enterDirectory(const QString &directory)
Definition KoStore.cpp:253
#define dbgKrita
Definition kis_debug.h:45
#define dbgFile
Definition kis_debug.h:53
QString expandEncodedDirectory(const QString &_intern)

References dbgFile, dbgKrita, KoStore::directoryList(), KoStore::enterDirectory(), expandEncodedDirectory(), m_name, m_store, m_syntaxVersion, KoStore::popDirectory(), and KoStore::pushDirectory().

Member Function Documentation

◆ errorMessages()

QStringList KisKraLoadVisitor::errorMessages ( ) const

Definition at line 519 of file kis_kra_load_visitor.cpp.

520{
521 return m_errorMessages;
522}

References m_errorMessages.

◆ fixOldFilterConfigurations()

void KisKraLoadVisitor::fixOldFilterConfigurations ( KisFilterConfigurationSP kfc)
private

Definition at line 693 of file kis_kra_load_visitor.cpp.

694{
695 KisFilterSP filter = KisFilterRegistry::instance()->value(kfc->name());
697
698 if (!filter->configurationAllowedForMask(kfc)) {
700 }
701
703}
static KisFilterRegistry * instance()
virtual bool configurationAllowedForMask(KisFilterConfigurationSP config) const
virtual void fixLoadedFilterConfigurationForMasks(KisFilterConfigurationSP config) const
const T value(const QString &id) const
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130

References KisFilter::configurationAllowedForMask(), KisFilter::fixLoadedFilterConfigurationForMasks(), KisFilterRegistry::instance(), KIS_SAFE_ASSERT_RECOVER_NOOP, KIS_SAFE_ASSERT_RECOVER_RETURN, and KoGenericRegistry< T >::value().

◆ getLocation() [1/2]

QString KisKraLoadVisitor::getLocation ( const QString & filename,
const QString & suffix = QString() )
private

Definition at line 803 of file kis_kra_load_visitor.cpp.

804{
805 QString location = m_external ? QString() : m_uri;
806 location += m_name + LAYER_PATH + filename + suffix;
807 return location;
808}
const QString LAYER_PATH

References KRA::LAYER_PATH, m_external, m_name, and m_uri.

◆ getLocation() [2/2]

QString KisKraLoadVisitor::getLocation ( KisNode * node,
const QString & suffix = QString() )
private

Definition at line 798 of file kis_kra_load_visitor.cpp.

799{
800 return getLocation(m_layerFilenames[node], suffix);
801}
QString getLocation(KisNode *node, const QString &suffix=QString())

References getLocation(), and m_layerFilenames.

◆ initSelectionForMask()

void KisKraLoadVisitor::initSelectionForMask ( KisMask * mask)
private

Definition at line 330 of file kis_kra_load_visitor.cpp.

331{
332 KisLayer *cloneLayer = dynamic_cast<KisCloneLayer*>(mask->parent().data());
333 if (cloneLayer) {
334 // the clone layers should be initialized out of order
335 // and lazily, because their original() is still not
336 // initialized
337 cloneLayer->accept(*this);
338 }
339
340 KisLayer *parentLayer = qobject_cast<KisLayer*>(mask->parent().data());
341 // the KisKraLoader must have already set the parent for us
342 Q_ASSERT(parentLayer);
343 mask->initSelection(parentLayer);
344}
void initSelection(KisSelectionSP copyFrom, KisLayerSP parentLayer)
initSelection initializes the selection for the mask from the given selection's projection.
Definition kis_mask.cc:157
bool accept(KisNodeVisitor &v) override
Definition kis_node.cpp:269
KisNodeWSP parent
Definition kis_node.cpp:86

References KisNode::accept(), KisWeakSharedPtr< T >::data(), KisMask::initSelection(), and KisNode::parent.

◆ loadDeprecatedFilter()

void KisKraLoadVisitor::loadDeprecatedFilter ( KisFilterConfigurationSP cfg)
private

Load deprecated filters. Most deprecated filters can be handled by this, but the brightnesscontact to perchannels conversion needs to be handled in the perchannel class because those filters have their own xml loading functionality.

Definition at line 855 of file kis_kra_load_visitor.cpp.

856{
857 if (cfg->getString("legacy") == "left edge detections") {
858 cfg->setProperty("horizRadius", 1);
859 cfg->setProperty("vertRadius", 1);
860 cfg->setProperty("type", "prewitt");
861 cfg->setProperty("output", "yFall");
862 cfg->setProperty("lockAspect", true);
863 cfg->setProperty("transparency", false);
864 } else if (cfg->getString("legacy") == "right edge detections") {
865 cfg->setProperty("horizRadius", 1);
866 cfg->setProperty("vertRadius", 1);
867 cfg->setProperty("type", "prewitt");
868 cfg->setProperty("output", "yGrowth");
869 cfg->setProperty("lockAspect", true);
870 cfg->setProperty("transparency", false);
871 } else if (cfg->getString("legacy") == "top edge detections") {
872 cfg->setProperty("horizRadius", 1);
873 cfg->setProperty("vertRadius", 1);
874 cfg->setProperty("type", "prewitt");
875 cfg->setProperty("output", "xGrowth");
876 cfg->setProperty("lockAspect", true);
877 cfg->setProperty("transparency", false);
878 } else if (cfg->getString("legacy") == "bottom edge detections") {
879 cfg->setProperty("horizRadius", 1);
880 cfg->setProperty("vertRadius", 1);
881 cfg->setProperty("type", "prewitt");
882 cfg->setProperty("output", "xFall");
883 cfg->setProperty("lockAspect", true);
884 cfg->setProperty("transparency", false);
885 }
886}

◆ loadFilterConfiguration()

bool KisKraLoadVisitor::loadFilterConfiguration ( KisFilterConfigurationSP kfc,
const QString & location )
private

Definition at line 669 of file kis_kra_load_visitor.cpp.

670{
671 if (m_store->hasFile(location)) {
672 QByteArray data;
673 m_store->open(location);
674 data = m_store->read(m_store->size());
675 m_store->close();
676 if (!data.isEmpty()) {
677 QDomDocument doc;
678 doc.setContent(data);
679 QDomElement e = doc.documentElement();
680 if (e.tagName() == "filterconfig") {
681 kfc->fromLegacyXML(e);
682 } else {
683 kfc->fromXML(e);
684 }
686 return true;
687 }
688 }
689 m_warningMessages << i18n("Could not filter configuration %1.", location);
690 return true;
691}
void loadDeprecatedFilter(KisFilterConfigurationSP cfg)
bool close()
Definition KoStore.cpp:156
qint64 size() const
Definition KoStore.cpp:239
bool hasFile(const QString &fileName) const
Definition KoStore.cpp:384
bool open(const QString &name)
Definition KoStore.cpp:109
QByteArray read(qint64 max)
Definition KoStore.cpp:181

References KoStore::close(), KoStore::hasFile(), loadDeprecatedFilter(), m_store, m_warningMessages, KoStore::open(), KoStore::read(), and KoStore::size().

◆ loadMetaData()

bool KisKraLoadVisitor::loadMetaData ( KisNode * node)
private

Definition at line 705 of file kis_kra_load_visitor.cpp.

706{
707 KisLayer* layer = qobject_cast<KisLayer*>(node);
708 if (!layer) return true;
709
711
712 if (!backend || !backend->supportLoading()) {
713 if (backend)
714 dbgFile << "Backend " << backend->id() << " does not support loading.";
715 else
716 dbgFile << "Could not load the XMP backend at all";
717 return true;
718 }
719
720 QString location = getLocation(node, QString(".") + backend->id() + DOT_METADATA);
721 dbgFile << "going to load " << backend->id() << ", " << backend->name() << " from " << location;
722
723 if (m_store->hasFile(location)) {
724 QByteArray data;
725 m_store->open(location);
726 data = m_store->read(m_store->size());
727 m_store->close();
728 QBuffer buffer(&data);
729 if (!backend->loadFrom(layer->metaData(), &buffer)) {
730 m_warningMessages << i18n("Could not load metadata for layer %1.", layer->name());
731 }
732 }
733 return true;
734}
virtual QString name() const =0
virtual bool supportLoading() const =0
virtual bool loadFrom(Store *store, QIODevice *ioDevice) const =0
virtual QString id() const =0
static KisMetadataBackendRegistry * instance()
T get(const QString &id) const
const QString DOT_METADATA
QString name() const
KisMetaData::Store * metaData()

References KoStore::close(), dbgFile, KRA::DOT_METADATA, KoGenericRegistry< T >::get(), getLocation(), KoStore::hasFile(), KisMetaData::IOBackend::id(), KisMetadataBackendRegistry::instance(), KisMetaData::IOBackend::loadFrom(), m_store, m_warningMessages, KisLayer::metaData(), KisBaseNode::name(), KisMetaData::IOBackend::name(), KoStore::open(), KoStore::read(), KoStore::size(), and KisMetaData::IOBackend::supportLoading().

◆ loadNodeKeyframes()

void KisKraLoadVisitor::loadNodeKeyframes ( KisNode * node)
private

Definition at line 810 of file kis_kra_load_visitor.cpp.

811{
812 if (!m_keyframeFilenames.contains(node)) return;
813
814 node->enableAnimation();
815
816 const QString &location = getLocation(m_keyframeFilenames[node]);
817
818 if (!m_store->open(location)) {
819 m_errorMessages << i18n("Could not load keyframes from %1.", location);
820 return;
821 }
822
823 QString errorMsg;
824 int errorLine;
825 int errorColumn;
826
827 QDomDocument dom;
828 bool ok = dom.setContent(m_store->device(), &errorMsg, &errorLine, &errorColumn);
829 m_store->close();
830
831
832 if (!ok) {
833 m_errorMessages << i18n("parsing error in the keyframe file %1 at line %2, column %3\nError message: %4", location, errorLine, errorColumn, i18n(errorMsg.toUtf8()));
834 return;
835 }
836
837 QDomElement root = dom.firstChildElement();
838
839 for (QDomElement child = root.firstChildElement(); !child.isNull(); child = child.nextSiblingElement()) {
840 if (child.nodeName().toUpper() == "CHANNEL") {
841 QString id = child.attribute("name");
842
843 KisKeyframeChannel *channel = node->getKeyframeChannel(id, true);
844
845 if (!channel) {
846 m_warningMessages << i18n("unknown keyframe channel type: %1 in %2", id, location);
847 continue;
848 }
849
850 channel->loadXML(child);
851 }
852 }
853}
KisKeyframeChannel stores and manages KisKeyframes. Maps units of time to virtual keyframe values....
virtual void loadXML(const QDomElement &channelNode)
QIODevice * device() const
Definition KoStore.cpp:171
KisKeyframeChannel * getKeyframeChannel(const QString &id, bool create)
void enableAnimation()

References KoStore::close(), KoStore::device(), KisBaseNode::enableAnimation(), KisBaseNode::getKeyframeChannel(), getLocation(), KisKeyframeChannel::loadXML(), m_errorMessages, m_keyframeFilenames, m_store, m_warningMessages, and KoStore::open().

◆ loadPaintDevice()

bool KisKraLoadVisitor::loadPaintDevice ( KisPaintDeviceSP device,
const QString & location )
private

Definition at line 556 of file kis_kra_load_visitor.cpp.

557{
558 // Layer data
559 KisPaintDeviceFramesInterface *frameInterface = device->framesInterface();
560 QList<int> frames;
561
562 if (frameInterface) {
563 frames = device->framesInterface()->frames();
564 }
565
566 if (!frameInterface || frames.count() <= 1) {
567 return loadPaintDeviceFrame(device, location, SimpleDevicePolicy());
568 } else {
569 KisRasterKeyframeChannel *keyframeChannel = device->keyframeChannel();
570
571 for (int i = 0; i < frames.count(); i++) {
572 int id = frames[i];
573 if (keyframeChannel->frameFilename(id).isEmpty()) {
574 m_warningMessages << i18n("Could not find keyframe pixel data for frame %1 in %2.", id, location);
575 }
576 else {
577 Q_ASSERT(!keyframeChannel->frameFilename(id).isEmpty());
578 QString frameFilename = getLocation(keyframeChannel->frameFilename(id));
579 Q_ASSERT(!frameFilename.isEmpty());
580
581 if (!loadPaintDeviceFrame(device, frameFilename, FramedDevicePolicy(id))) {
582 m_warningMessages << i18n("Could not load keyframe pixel data for frame %1 in %2.", id, location);
583 }
584 }
585 }
586 }
587
588 return true;
589}
bool loadPaintDeviceFrame(KisPaintDeviceSP device, const QString &location, DevicePolicy policy)
KisRasterKeyframeChannel * keyframeChannel() const
KisPaintDeviceFramesInterface * framesInterface()
The KisRasterKeyframeChannel is a concrete KisKeyframeChannel subclass that stores and manages KisRas...
QString frameFilename(int frameId) const

References KisRasterKeyframeChannel::frameFilename(), KisPaintDeviceFramesInterface::frames(), KisPaintDevice::framesInterface(), getLocation(), KisPaintDevice::keyframeChannel(), loadPaintDeviceFrame(), and m_warningMessages.

◆ loadPaintDeviceFrame()

template<class DevicePolicy >
bool KisKraLoadVisitor::loadPaintDeviceFrame ( KisPaintDeviceSP device,
const QString & location,
DevicePolicy policy )
private

Definition at line 592 of file kis_kra_load_visitor.cpp.

593{
594 {
595 const int pixelSize = device->colorSpace()->pixelSize();
597
598 if (m_store->open(location + ".defaultpixel")) {
599 if (m_store->size() == pixelSize) {
600 m_store->read((char*)color.data(), pixelSize);
601 }
602
603 m_store->close();
604 }
605
606 policy.setDefaultPixel(device, color);
607 }
608
609 if (m_store->open(location)) {
610 if (!policy.read(device, m_store->device())) {
611 m_warningMessages << i18n("Could not read pixel data: %1.", location);
612 device->disconnect();
613 m_store->close();
614 return true;
615 }
616 m_store->close();
617 } else {
618 m_warningMessages << i18n("Could not load pixel data: %1.", location);
619 return true;
620 }
621
622 return true;
623}
const KoColorSpace * colorSpace() const
virtual quint32 pixelSize() const =0
static KoColor createTransparent(const KoColorSpace *cs)
Definition KoColor.cpp:681
quint8 * data()
Definition KoColor.h:144

References KoStore::close(), KisPaintDevice::colorSpace(), KoColor::createTransparent(), KoColor::data(), KoStore::device(), m_store, m_warningMessages, KoStore::open(), KoColorSpace::pixelSize(), KoStore::read(), and KoStore::size().

◆ loadProfile() [1/2]

const KoColorProfile * KisKraLoadVisitor::loadProfile ( const QString & location,
const QString & colorModelId,
const QString & colorDepthId )
private

Definition at line 640 of file kis_kra_load_visitor.cpp.

641{
642 const KoColorProfile *result = 0;
643
644 if (m_store->hasFile(location)) {
645 m_store->open(location);
646 QByteArray data;
647 data.resize(m_store->size());
648 dbgFile << "Data to load: " << m_store->size() << " from " << location << " with color space " << colorModelId << colorDepthId;
649 int read = m_store->read(data.data(), m_store->size());
650 dbgFile << "Profile size: " << data.size() << " " << m_store->atEnd() << " " << m_store->device()->bytesAvailable() << " " << read;
651 m_store->close();
652
653 QString hash = KoMD5Generator::generateHash(data);
654
655 if (m_profileCache.contains(hash)) {
656 result = m_profileCache[hash];
657 }
658 else {
659 // Create a colorspace with the embedded profile
660 const KoColorProfile *profile = KoColorSpaceRegistry::instance()->createColorProfile(colorModelId, colorDepthId, data);
661 m_profileCache[hash] = profile;
662 result = profile;
663 }
664 }
665
666 return result;
667}
QMap< QString, const KoColorProfile * > m_profileCache
static QString generateHash(const QString &filename)
generateHash reads the given file and generates a hex-encoded md5sum for the file.
bool atEnd() const
Definition KoStore.cpp:353
static KoColorSpaceRegistry * instance()
const KoColorProfile * createColorProfile(const QString &colorModelId, const QString &colorDepthId, const QByteArray &rawData)

References KoStore::atEnd(), KoStore::close(), KoColorSpaceRegistry::createColorProfile(), dbgFile, KoStore::device(), KoMD5Generator::generateHash(), KoStore::hasFile(), KoColorSpaceRegistry::instance(), m_profileCache, m_store, KoStore::open(), KoStore::read(), and KoStore::size().

◆ loadProfile() [2/2]

bool KisKraLoadVisitor::loadProfile ( KisPaintDeviceSP device,
const QString & location )
private

Definition at line 626 of file kis_kra_load_visitor.cpp.

627{
628 const KoColorProfile *profile = loadProfile(location, device->colorSpace()->colorModelId().id(), device->colorSpace()->colorDepthId().id());
629
630 if (profile) {
631 // TODO: check result!
632 device->setProfile(profile, 0);
633 } else {
634 m_warningMessages << i18n("Could not load profile: %1.", location);
635 }
636
637 return true;
638}
bool loadProfile(KisPaintDeviceSP device, const QString &location)
bool setProfile(const KoColorProfile *profile, KUndo2Command *parentCommand)
virtual KoID colorModelId() const =0
virtual KoID colorDepthId() const =0
QString id() const
Definition KoID.cpp:63

References KoColorSpace::colorDepthId(), KoColorSpace::colorModelId(), KisPaintDevice::colorSpace(), KoID::id(), loadProfile(), m_warningMessages, and KisPaintDevice::setProfile().

◆ loadSelection()

bool KisKraLoadVisitor::loadSelection ( const QString & location,
KisSelectionSP dstSelection )
private

We need to explicitly call updateProjection() here, because KisUpdateSelectionJob that is put into the queue will not update actual layers that own this selection. In normal situation, the setDirty() call is done explicitly while painting.

TODO: consider adding a proper setDirty() call to KisUpdateSelectionJob. Though it doesn't seem to be needed until we allow modifying vector selections on non-selection masks.

NOTE: since loading a vector selection discards all the contents of a raster projection by reincarnating the paint device, there is no need to load pixel selection in case any vector selection is present.

Definition at line 736 of file kis_kra_load_visitor.cpp.

737{
738 // by default the selection is expected to be fully transparent
739 {
740 KisPixelSelectionSP pixelSelection = dstSelection->pixelSelection();
741 KoColor transparent = KoColor::createTransparent(pixelSelection->colorSpace());
742 pixelSelection->setDefaultPixel(transparent);
743 }
744
745 bool result = true;
746
747 // Shape selection
748 QString shapeSelectionLocation = location + DOT_SHAPE_SELECTION;
749 if (m_store->hasFile(shapeSelectionLocation + "/content.svg") ||
750 m_store->hasFile(shapeSelectionLocation + "/content.xml")) {
751
753 m_store->enterDirectory(shapeSelectionLocation) ;
754
755 KisShapeSelection* shapeSelection = new KisShapeSelection(m_shapeController, dstSelection);
756 dstSelection->convertToVectorSelectionNoUndo(shapeSelection);
757 result = shapeSelection->loadSelection(m_store, m_image->bounds());
758
770 dstSelection->updateProjection();
772 if (!result) {
773 m_warningMessages << i18n("Could not load vector selection %1.", location);
774 }
775 } else {
783 // Pixel selection
784 QString pixelSelectionLocation = location + DOT_PIXEL_SELECTION;
785 if (m_store->hasFile(pixelSelectionLocation)) {
786 KisPixelSelectionSP pixelSelection = dstSelection->pixelSelection();
787 result = loadPaintDevice(pixelSelection, pixelSelectionLocation);
788 if (!result) {
789 m_warningMessages << i18n("Could not load raster selection %1.", location);
790 }
791 pixelSelection->invalidateOutlineCache();
792 }
793 }
794
795 return true;
796}
QRect bounds() const override
bool loadPaintDevice(KisPaintDeviceSP device, const QString &location)
void setDefaultPixel(const KoColor &defPixel)
bool loadSelection(KoStore *store, const QRect &imageRect)
const QString DOT_SHAPE_SELECTION
const QString DOT_PIXEL_SELECTION
void updateProjection(const QRect &rect)
KisPixelSelectionSP pixelSelection
void convertToVectorSelectionNoUndo(KisSelectionComponent *shapeSelection)

References KisImage::bounds(), KisPaintDevice::colorSpace(), KisSelection::convertToVectorSelectionNoUndo(), KoColor::createTransparent(), KRA::DOT_PIXEL_SELECTION, KRA::DOT_SHAPE_SELECTION, KoStore::enterDirectory(), KoStore::hasFile(), KisPixelSelection::invalidateOutlineCache(), loadPaintDevice(), KisShapeSelection::loadSelection(), m_image, m_shapeController, m_store, m_warningMessages, KisSelection::pixelSelection, KoStore::popDirectory(), KoStore::pushDirectory(), KisPaintDevice::setDefaultPixel(), and KisSelection::updateProjection().

◆ setExternalUri()

void KisKraLoadVisitor::setExternalUri ( const QString & uri)

Definition at line 121 of file kis_kra_load_visitor.cpp.

122{
123 m_external = true;
124 m_uri = uri;
125}

References m_external, and m_uri.

◆ visit() [1/12]

bool KisKraLoadVisitor::visit ( KisAdjustmentLayer * layer)
overridevirtual

Implements KisNodeVisitor.

Definition at line 237 of file kis_kra_load_visitor.cpp.

238{
239 loadNodeKeyframes(layer);
240
241 // Adjustmentlayers are tricky: there's the 1.x style and the 2.x
242 // style, which has selections with selection components
243 bool result = true;
244 if (m_syntaxVersion == 1) {
245 KisSelectionSP selection = new KisSelection();
246 KisPixelSelectionSP pixelSelection = selection->pixelSelection();
247 result = loadPaintDevice(pixelSelection, getLocation(layer, ".selection"));
248 layer->setInternalSelection(selection);
249 } else if (m_syntaxVersion == 2) {
250 result = loadSelection(getLocation(layer), layer->internalSelection());
251
252 } else {
253 // We use the default, empty selection
254 }
255
256 if (!result) {
257 m_warningMessages.append(i18nc("Warning during loading a kra file with a filter layer",
258 "Selection on layer %s couldn't be loaded. It will be replaced by an empty selection.", layer->name()));
259 // otherwise ignore and just use what is there already
260 // (most probably an empty selection)
261 }
262
263 if (!loadMetaData(layer)) {
264 return false;
265 }
266
267 KisFilterSP filter = KisFilterRegistry::instance()->value(layer->filter()->name());
269
272 kfc->createLocalResourcesSnapshot();
273
274 layer->setFilter(kfc);
275
276 result = visitAll(layer);
277 return result;
278}
void setFilter(KisFilterConfigurationSP filterConfig, bool checkCompareConfig=true) override
static KisResourcesInterfaceSP instance()
bool loadFilterConfiguration(KisFilterConfigurationSP kfc, const QString &location)
bool loadMetaData(KisNode *node)
void fixOldFilterConfigurations(KisFilterConfigurationSP kfc)
bool loadSelection(const QString &location, KisSelectionSP dstSelection)
void loadNodeKeyframes(KisNode *node)
virtual KisFilterConfigurationSP filter() const
bool visitAll(KisNode *node, bool breakOnFail=false)
const QString DOT_FILTERCONFIG
virtual KisFilterConfigurationSP factoryConfiguration(KisResourcesInterfaceSP resourcesInterface) const
void setInternalSelection(KisSelectionSP selection)
KisSelectionSP internalSelection() const

References KRA::DOT_FILTERCONFIG, KisBaseProcessor::factoryConfiguration(), KisNodeFilterInterface::filter(), fixOldFilterConfigurations(), getLocation(), KisFilterRegistry::instance(), KisGlobalResourcesInterface::instance(), KisSelectionBasedLayer::internalSelection(), loadFilterConfiguration(), loadMetaData(), loadNodeKeyframes(), loadPaintDevice(), loadSelection(), m_syntaxVersion, m_warningMessages, KisBaseNode::name(), KisSelection::pixelSelection, KisAdjustmentLayer::setFilter(), KisSelectionBasedLayer::setInternalSelection(), KoGenericRegistry< T >::value(), and KisNodeVisitor::visitAll().

◆ visit() [2/12]

bool KisKraLoadVisitor::visit ( KisCloneLayer * layer)
overridevirtual

Implements KisNodeVisitor.

Definition at line 302 of file kis_kra_load_visitor.cpp.

303{
304 if (!loadMetaData(layer)) {
305 return false;
306 }
307
308 // the layer might have already been lazily initialized
309 // from the mask loading code
310 if (layer->copyFrom()) {
311 return true;
312 }
313
314 KisNodeSP srcNode = layer->copyFromInfo().findNode(m_image->rootLayer());
315 if (!srcNode.isNull()) {
316 KisLayerSP srcLayer = qobject_cast<KisLayer*>(srcNode.data());
317 Q_ASSERT(srcLayer);
318
319 layer->setCopyFrom(srcLayer);
320 } else {
321 m_warningMessages.append(i18nc("Loading a .kra file", "The file contains a clone layer that has an incorrect source node id. "
322 "This layer will be converted into a paint layer."));
323 }
324
325 // Clone layers have no data except for their masks
326 bool result = visitAll(layer);
327 return result;
328}
KisGroupLayerSP rootLayer() const
KisNodeSP findNode(KisNodeSP rootNode)
bool isNull() const
void setCopyFrom(KisLayerSP layer)
KisLayerSP copyFrom
KisNodeUuidInfo copyFromInfo

References KisCloneLayer::copyFrom, KisCloneLayer::copyFromInfo, KisSharedPtr< T >::data(), KisNodeUuidInfo::findNode(), KisSharedPtr< T >::isNull(), loadMetaData(), m_image, m_warningMessages, KisImage::rootLayer(), KisCloneLayer::setCopyFrom(), and KisNodeVisitor::visitAll().

◆ visit() [3/12]

bool KisKraLoadVisitor::visit ( KisColorizeMask * mask)
overridevirtual

Implements KisNodeVisitor.

Definition at line 452 of file kis_kra_load_visitor.cpp.

453{
455 QString location = getLocation(mask, DOT_COLORIZE_MASK);
456 m_store->enterDirectory(location) ;
457
458 QByteArray data;
459 if (!m_store->extractFile("content.xml", data))
460 return false;
461
462 QDomDocument doc;
463 if (!doc.setContent(data))
464 return false;
465
467 if (!KisDomUtils::loadValue(doc.documentElement(),
469 &strokes,
470 mask->colorSpace(),
471 QPoint(mask->x(), mask->y()))) {
472 return false;
473 }
474
475 int i = 0;
476 Q_FOREACH (const KisLazyFillTools::KeyStroke &stroke, strokes) {
477 const QString fileName = QString("%1_%2").arg(COLORIZE_KEYSTROKE).arg(i++);
478 loadPaintDevice(stroke.dev, fileName);
479 }
480
482
484
485 const KoColorProfile *profile =
487
488 if (!profile) {
489 KisNodeSP parent = mask->parent();
491 parent = m_image->root();
492 }
493
494 if (parent->colorSpace()->colorModelId() == mask->colorSpace()->colorModelId() &&
495 parent->colorSpace()->colorDepthId() == mask->colorSpace()->colorDepthId()) {
496
497 profile = parent->colorSpace()->profile();
498 }
499 }
500
501 if (!profile) {
502 if (m_image->colorSpace()->colorModelId() == mask->colorSpace()->colorModelId() &&
504
505 profile = m_image->colorSpace()->profile();
506 }
507 }
508
509 if (profile) {
510 mask->setProfile(profile, 0);
511 }
512
513 mask->resetCache();
514
516 return true;
517}
void setKeyStrokesDirect(const QList< KisLazyFillTools::KeyStroke > &strokes)
const KoColorSpace * colorSpace() const override
void setProfile(const KoColorProfile *profile, KUndo2Command *parentCommand)
qint32 y() const override
KisPaintDeviceSP coloringProjection() const
qint32 x() const override
const KoColorSpace * colorSpace() const
virtual const KoColorProfile * profile() const =0
bool extractFile(const QString &sourceName, QByteArray &data)
Definition KoStore.cpp:308
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126
const QString DOT_ICC
const QString DOT_COLORIZE_MASK
const QString COLORIZE_KEYSTROKE
const QString COLORIZE_COLORING_DEVICE
const QString COLORIZE_KEYSTROKES_SECTION
ChildIterator< value_type, is_const > parent(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:327

References KoColorSpace::colorDepthId(), KisColorizeMask::coloringProjection(), KRA::COLORIZE_COLORING_DEVICE, KRA::COLORIZE_KEYSTROKE, KRA::COLORIZE_KEYSTROKES_SECTION, KoColorSpace::colorModelId(), KisImage::colorSpace(), KisColorizeMask::colorSpace(), KisLazyFillTools::KeyStroke::dev, KRA::DOT_COLORIZE_MASK, KRA::DOT_ICC, KoStore::enterDirectory(), KoStore::extractFile(), getLocation(), KoID::id(), KIS_SAFE_ASSERT_RECOVER, loadPaintDevice(), loadProfile(), m_image, m_store, KisNode::parent, KoStore::popDirectory(), KoColorSpace::profile(), KoStore::pushDirectory(), KisColorizeMask::resetCache(), KisNodeFacade::root, KisColorizeMask::setKeyStrokesDirect(), KisColorizeMask::setProfile(), KisColorizeMask::x(), and KisColorizeMask::y().

◆ visit() [4/12]

bool KisKraLoadVisitor::visit ( KisExternalLayer * layer)
overridevirtual

Implements KisNodeVisitor.

Definition at line 127 of file kis_kra_load_visitor.cpp.

128{
129 bool result = false;
130
131 if (auto *referencesLayer = dynamic_cast<KisReferenceImagesLayer*>(layer)) {
132 Q_FOREACH(KoShape *shape, referencesLayer->shapes()) {
133 auto *reference = dynamic_cast<KisReferenceImage*>(shape);
134 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(reference, false);
135
136 while (!reference->loadImage(m_store)) {
137 if (reference->embed()) {
138 m_errorMessages << i18n("Could not load embedded reference image %1 ", reference->internalFile());
139 break;
140 } else {
141 QString msg = i18nc(
142 "@info",
143 "A reference image linked to an external file could not be loaded.\n\n"
144 "Path: %1\n\n"
145 "Do you want to select another location?", reference->filename());
146
147 // qApp->activeWindow() doesn't work here
148 int locateManually = QMessageBox::warning(qApp->activeWindow(), i18nc("@title:window", "File not found"), msg, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
149
150 QString url;
151 if (locateManually == QMessageBox::Yes) {
152 KoFileDialog dialog(0, KoFileDialog::OpenFile, "OpenDocument");
154 url = dialog.filename();
155 }
156
157 if (url.isEmpty()) {
158 break;
159 } else {
160 reference->setFilename(url);
161 reference->setEmbed(false);
162 }
163 }
164 }
165 }
166 } else if (KisShapeLayer *shapeLayer = dynamic_cast<KisShapeLayer*>(layer)) {
167 loadNodeKeyframes(shapeLayer);
168
169 if (!loadMetaData(layer)) {
170 return false;
171 }
172
173 QStringList vectorWarnings;
174
177 result = shapeLayer->loadLayer(m_store, &vectorWarnings);
179
180 m_warningMessages << vectorWarnings;
181 }
182
183 result = visitAll(layer) && result;
184 return result;
185}
static QStringList supportedMimeTypes(Direction direction)
The KisReferenceImage class represents a single reference image.
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129
const QString DOT_SHAPE_LAYER

References KRA::DOT_SHAPE_LAYER, KoStore::enterDirectory(), getLocation(), KisImportExportManager::Import, KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, loadMetaData(), loadNodeKeyframes(), m_errorMessages, m_store, m_warningMessages, KoFileDialog::OpenFile, KoStore::popDirectory(), KoStore::pushDirectory(), KisImportExportManager::supportedMimeTypes(), and KisNodeVisitor::visitAll().

◆ visit() [5/12]

bool KisKraLoadVisitor::visit ( KisFilterMask * mask)
overridevirtual

Implements KisNodeVisitor.

Definition at line 346 of file kis_kra_load_visitor.cpp.

347{
349
350 loadNodeKeyframes(mask);
351
352 bool result = true;
353 result = loadSelection(getLocation(mask), mask->selection());
354
355 KisFilterSP filter = KisFilterRegistry::instance()->value(mask->filter()->name());
359 kfc->createLocalResourcesSnapshot();
360
361 mask->setFilter(kfc);
362
363 return result;
364}
void setFilter(KisFilterConfigurationSP filterConfig, bool checkCompareConfig=true) override
void initSelectionForMask(KisMask *mask)
KisSelectionSP selection
Definition kis_mask.cc:44

References KRA::DOT_FILTERCONFIG, KisBaseProcessor::factoryConfiguration(), KisNodeFilterInterface::filter(), fixOldFilterConfigurations(), getLocation(), initSelectionForMask(), KisFilterRegistry::instance(), KisGlobalResourcesInterface::instance(), loadFilterConfiguration(), loadNodeKeyframes(), loadSelection(), KisMask::selection, KisFilterMask::setFilter(), and KoGenericRegistry< T >::value().

◆ visit() [6/12]

bool KisKraLoadVisitor::visit ( KisGeneratorLayer * layer)
overridevirtual

Implements KisNodeVisitor.

Definition at line 280 of file kis_kra_load_visitor.cpp.

281{
282 if (!loadMetaData(layer)) {
283 return false;
284 }
285 bool result = true;
286
287 loadNodeKeyframes(layer);
288 result = loadSelection(getLocation(layer), layer->internalSelection());
289
290 KisGeneratorSP filter = KisGeneratorRegistry::instance()->value(layer->filter()->name());
292
294 kfc->createLocalResourcesSnapshot();
295
296 layer->setFilter(kfc);
297
298 result = visitAll(layer);
299 return result;
300}
static KisGeneratorRegistry * instance()
void setFilter(KisFilterConfigurationSP filterConfig, bool checkCompareConfig=true) override

References KRA::DOT_FILTERCONFIG, KisBaseProcessor::factoryConfiguration(), KisNodeFilterInterface::filter(), getLocation(), KisGeneratorRegistry::instance(), KisGlobalResourcesInterface::instance(), KisSelectionBasedLayer::internalSelection(), loadFilterConfiguration(), loadMetaData(), loadNodeKeyframes(), loadSelection(), KisGeneratorLayer::setFilter(), KoGenericRegistry< T >::value(), and KisNodeVisitor::visitAll().

◆ visit() [7/12]

bool KisKraLoadVisitor::visit ( KisGroupLayer * layer)
overridevirtual

Implements KisNodeVisitor.

Definition at line 225 of file kis_kra_load_visitor.cpp.

226{
227 loadNodeKeyframes(layer);
228
229 if (!loadMetaData(layer)) {
230 return false;
231 }
232
233 bool result = visitAll(layer);
234 return result;
235}

References loadMetaData(), loadNodeKeyframes(), and KisNodeVisitor::visitAll().

◆ visit() [8/12]

bool KisKraLoadVisitor::visit ( KisNode * )
inlineoverridevirtual

Implements KisNodeVisitor.

Definition at line 41 of file kis_kra_load_visitor.h.

41 {
42 return true;
43 }

◆ visit() [9/12]

bool KisKraLoadVisitor::visit ( KisPaintLayer * layer)
overridevirtual

Implements KisNodeVisitor.

Definition at line 187 of file kis_kra_load_visitor.cpp.

188{
189 loadNodeKeyframes(layer);
190
191 if (!loadPaintDevice(layer->paintDevice(), getLocation(layer))) {
192 return false;
193 }
194 if (!loadProfile(layer->paintDevice(), getLocation(layer, DOT_ICC))) {
195 return false;
196 }
197 if (!loadMetaData(layer)) {
198 return false;
199 }
200
201 if (m_syntaxVersion == 1) {
202 // Check whether there is a file with a .mask extension in the
203 // layer directory, if so, it's an old-style transparency mask
204 // that should be converted.
205 QString location = getLocation(layer, ".mask");
206
207 if (m_store->open(location)) {
208
209 KisSelectionSP selection = KisSelectionSP(new KisSelection());
210 KisPixelSelectionSP pixelSelection = selection->pixelSelection();
211 if (!pixelSelection->read(m_store->device())) {
212 pixelSelection->disconnect();
213 } else {
214 KisTransparencyMask* mask = new KisTransparencyMask(m_image, i18n("Transparency Mask"));
215 mask->setSelection(selection);
216 m_image->addNode(mask, layer, layer->firstChild());
217 }
218 m_store->close();
219 }
220 }
221 bool result = visitAll(layer);
222 return result;
223}
KisSharedPtr< KisSelection > KisSelectionSP
Definition kis_types.h:149
void setSelection(KisSelectionSP selection)
Definition kis_mask.cc:252
bool addNode(KisNodeSP node, KisNodeSP parent=KisNodeSP(), KisNodeAdditionFlags flags=KisNodeAdditionFlag::None)
KisNodeSP firstChild() const
Definition kis_node.cpp:361
KisPaintDeviceSP paintDevice
bool read(QIODevice *stream)

References KisNodeFacade::addNode(), KoStore::close(), KoStore::device(), KRA::DOT_ICC, KisNode::firstChild(), getLocation(), loadMetaData(), loadNodeKeyframes(), loadPaintDevice(), loadProfile(), m_image, m_store, m_syntaxVersion, KoStore::open(), KisPaintLayer::paintDevice, KisSelection::pixelSelection, KisPixelSelection::read(), KisMask::setSelection(), and KisNodeVisitor::visitAll().

◆ visit() [10/12]

bool KisKraLoadVisitor::visit ( KisSelectionMask * mask)
overridevirtual

Implements KisNodeVisitor.

Definition at line 446 of file kis_kra_load_visitor.cpp.

447{
449 return loadSelection(getLocation(mask), mask->selection());
450}

References getLocation(), initSelectionForMask(), loadSelection(), and KisMask::selection.

◆ visit() [11/12]

bool KisKraLoadVisitor::visit ( KisTransformMask * mask)
overridevirtual

Workaround for the dumbparams that we used in older versions of Krita for simple translations. The dumbparams were deprecated with the proper implementation of the param holder, so now we should convert the old definition into the new format somehow.

See: https://bugs.kde.org/show_bug.cgi?id=492320

Implements KisNodeVisitor.

Definition at line 366 of file kis_kra_load_visitor.cpp.

367{
368 QString location = getLocation(mask, DOT_TRANSFORMCONFIG);
369 if (m_store->hasFile(location)) {
370 QByteArray data;
371 m_store->open(location);
372 data = m_store->read(m_store->size());
373 m_store->close();
374 if (!data.isEmpty()) {
375 QDomDocument doc;
376 doc.setContent(data);
377
378 QDomElement rootElement = doc.documentElement();
379
380 QDomElement main;
381
382 if (!KisDomUtils::findOnlyElement(rootElement, "main", &main/*, &m_errorMessages*/)) {
383 return false;
384 }
385
386 QString id = main.attribute("id", "not-valid");
387
388 // backward compatibility
389 if (id == "animatedtransformparams") {
390 id = "tooltransformparams";
391 }
392 if (id == "not-valid") {
393 m_errorMessages << i18n("Could not load \"id\" of the transform mask");
394 return false;
395 }
396
397 QDomElement data;
398
399 if (!KisDomUtils::findOnlyElement(rootElement, "data", &data, &m_errorMessages)) {
400 m_errorMessages << i18n("Could not find transform mask XML element");
401 return false;
402 }
403
406
416 if (id == "dumbparams") {
417 const QPointF center = m_image->bounds().center();
418 params->transformSrcAndDst(QTransform::fromTranslate(center.x(), center.y()));
419 }
420
421 if (!params) {
422 m_errorMessages << i18n("Could not create transform mask params");
423 return false;
424 }
425
426 mask->setTransformParams(params);
427
428 loadNodeKeyframes(mask);
429
430 return true;
431 }
432 }
433
434 return false;
435}
static KisTransformMaskParamsFactoryRegistry * instance()
KisTransformMaskParamsInterfaceSP createParams(const QString &id, const QDomElement &e)
int main(int argc, char **argv)
Definition main.cpp:26
const QString DOT_TRANSFORMCONFIG
bool findOnlyElement(const QDomElement &parent, const QString &tag, QDomElement *el, QStringList *errorMessages)
void setTransformParams(KisTransformMaskParamsInterfaceSP params)

References KisImage::bounds(), KoStore::close(), KisTransformMaskParamsFactoryRegistry::createParams(), KRA::DOT_TRANSFORMCONFIG, KisDomUtils::findOnlyElement(), getLocation(), KoStore::hasFile(), KisTransformMaskParamsFactoryRegistry::instance(), loadNodeKeyframes(), m_errorMessages, m_image, m_store, main(), KoStore::open(), KoStore::read(), KisTransformMask::setTransformParams(), and KoStore::size().

◆ visit() [12/12]

bool KisKraLoadVisitor::visit ( KisTransparencyMask * mask)
overridevirtual

Implements KisNodeVisitor.

Definition at line 437 of file kis_kra_load_visitor.cpp.

438{
440
441 loadNodeKeyframes(mask);
442
443 return loadSelection(getLocation(mask), mask->selection());
444}

References getLocation(), initSelectionForMask(), loadNodeKeyframes(), loadSelection(), and KisMask::selection.

◆ warningMessages()

QStringList KisKraLoadVisitor::warningMessages ( ) const

Definition at line 524 of file kis_kra_load_visitor.cpp.

525{
526 return m_warningMessages;
527}

References m_warningMessages.

Member Data Documentation

◆ m_errorMessages

QStringList KisKraLoadVisitor::m_errorMessages
private

Definition at line 94 of file kis_kra_load_visitor.h.

◆ m_external

bool KisKraLoadVisitor::m_external
private

Definition at line 88 of file kis_kra_load_visitor.h.

◆ m_image

KisImageSP KisKraLoadVisitor::m_image
private

Definition at line 86 of file kis_kra_load_visitor.h.

◆ m_keyframeFilenames

QMap<KisNode *, QString> KisKraLoadVisitor::m_keyframeFilenames
private

Definition at line 91 of file kis_kra_load_visitor.h.

◆ m_layerFilenames

QMap<KisNode *, QString> KisKraLoadVisitor::m_layerFilenames
private

Definition at line 90 of file kis_kra_load_visitor.h.

◆ m_name

QString KisKraLoadVisitor::m_name
private

Definition at line 92 of file kis_kra_load_visitor.h.

◆ m_profileCache

QMap<QString, const KoColorProfile *> KisKraLoadVisitor::m_profileCache
private

Definition at line 97 of file kis_kra_load_visitor.h.

◆ m_shapeController

KoShapeControllerBase* KisKraLoadVisitor::m_shapeController
private

Definition at line 96 of file kis_kra_load_visitor.h.

◆ m_store

KoStore* KisKraLoadVisitor::m_store
private

Definition at line 87 of file kis_kra_load_visitor.h.

◆ m_syntaxVersion

int KisKraLoadVisitor::m_syntaxVersion
private

Definition at line 93 of file kis_kra_load_visitor.h.

◆ m_uri

QString KisKraLoadVisitor::m_uri
private

Definition at line 89 of file kis_kra_load_visitor.h.

◆ m_warningMessages

QStringList KisKraLoadVisitor::m_warningMessages
private

Definition at line 95 of file kis_kra_load_visitor.h.


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