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

#include <KoMarkerCollection.h>

+ Inheritance diagram for KoMarkerCollection:

Public Member Functions

KoMarkeraddMarker (KoMarker *marker)
 
 KoMarkerCollection (QObject *parent=0)
 
void loadMarkersFromFile (const QString &svgFile)
 
QList< KoMarker * > markers () const
 
 ~KoMarkerCollection () override
 
 ~Private ()
 

Public Attributes

QList< QExplicitlySharedDataPointer< KoMarker > > markers
 

Private Member Functions

void loadDefaultMarkers ()
 load the markers that are available per default.
 
- Private Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Private Attributes

Private *const d
 
- Private Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Detailed Description

Definition at line 26 of file KoMarkerCollection.cpp.

Constructor & Destructor Documentation

◆ ~Private()

KoMarkerCollection::~Private ( )
inline

Definition at line 29 of file KoMarkerCollection.cpp.

30 {
31 }

◆ KoMarkerCollection()

KoMarkerCollection::KoMarkerCollection ( QObject * parent = 0)
explicit

Definition at line 36 of file KoMarkerCollection.cpp.

37: QObject(parent)
38, d(new Private)
39{
40 // Add no marker so the user can remove a marker from the line.
41 d->markers.append(QExplicitlySharedDataPointer<KoMarker>(0));
42 // Add default markers
44}
void loadDefaultMarkers()
load the markers that are available per default.

References d, and loadDefaultMarkers().

◆ ~KoMarkerCollection()

KoMarkerCollection::~KoMarkerCollection ( )
override

Definition at line 46 of file KoMarkerCollection.cpp.

47{
48 delete d;
49}

References d.

Member Function Documentation

◆ addMarker()

KoMarker * KoMarkerCollection::addMarker ( KoMarker * marker)

Add marker to collection

The collection checks if a marker with the same content exists and if so deletes the passed marker and returns a pointer to an existing marker. If no such marker exists it adds the marker and return the same pointer as passed. Calling that function passes ownership of the marker to this class.

Parameters
markerMarker to add
Returns
pointer to marker that should be used. This might be different to the marker passed

Definition at line 110 of file KoMarkerCollection.cpp.

111{
112 foreach (const QExplicitlySharedDataPointer<KoMarker>& m, d->markers) {
113 if (marker == m.data()) {
114 return marker;
115 }
116 if (m && *marker == *m) {
117 debugFlake << "marker is the same as other";
118 return m.data();
119 }
120 }
121 d->markers.append(QExplicitlySharedDataPointer<KoMarker>(marker));
122 return marker;
123}
#define debugFlake
Definition FlakeDebug.h:15

References d, and debugFlake.

◆ loadDefaultMarkers()

void KoMarkerCollection::loadDefaultMarkers ( )
private

load the markers that are available per default.

Definition at line 95 of file KoMarkerCollection.cpp.

96{
97 QString filePath = KoResourcePaths::findAsset("markers", "markers.svg");
98 loadMarkersFromFile(filePath);
99}
void loadMarkersFromFile(const QString &svgFile)
static QString findAsset(const QString &type, const QString &fileName)

References KoResourcePaths::findAsset(), and loadMarkersFromFile().

◆ loadMarkersFromFile()

void KoMarkerCollection::loadMarkersFromFile ( const QString & svgFile)

Definition at line 51 of file KoMarkerCollection.cpp.

52{
53 QFile file(svgFile);
54 if (!file.exists()) return;
55
56 if (!file.open(QIODevice::ReadOnly)) return;
57
58 QString errorMsg;
59 int errorLine = 0;
60 int errorColumn;
61
62 QDomDocument doc = SvgParser::createDocumentFromSvg(&file, &errorMsg, &errorLine, &errorColumn);
63 if (doc.isNull()) {
64 errKrita << "Parsing error in " << svgFile << "! Aborting!" << Qt::endl
65 << " In line: " << errorLine << ", column: " << errorColumn << Qt::endl
66 << " Error message: " << errorMsg << Qt::endl;
67 errKrita << i18n("Parsing error in the main document at line %1, column %2\nError message: %3"
68 , errorLine , errorColumn , errorMsg);
69 return;
70 }
71
73 SvgParser parser(&manager);
74 parser.setResolution(QRectF(0,0,100,100), 72); // initialize with default values
75 parser.setXmlBaseDir(QFileInfo(svgFile).absolutePath());
76
77 parser.setFileFetcher(
78 [](const QString &fileName) {
79 QFile file(fileName);
80 if (!file.exists()) return QByteArray();
81
82 file.open(QIODevice::ReadOnly);
83 return file.readAll();
84 });
85
86 QSizeF fragmentSize;
87 QList<KoShape*> shapes = parser.parseSvg(doc.documentElement(), &fragmentSize);
88 qDeleteAll(shapes);
89
90 Q_FOREACH (const QExplicitlySharedDataPointer<KoMarker> &marker, parser.knownMarkers()) {
91 addMarker(marker.data());
92 }
93}
KoMarker * addMarker(KoMarker *marker)
static QDomDocument createDocumentFromSvg(QIODevice *device, QString *errorMsg=0, int *errorLine=0, int *errorColumn=0)
#define errKrita
Definition kis_debug.h:107

References addMarker(), SvgParser::createDocumentFromSvg(), errKrita, SvgParser::knownMarkers(), SvgParser::parseSvg(), SvgParser::setFileFetcher(), SvgParser::setResolution(), and SvgParser::setXmlBaseDir().

◆ markers()

QList< KoMarker * > KoMarkerCollection::markers ( ) const

Member Data Documentation

◆ d

Private* const KoMarkerCollection::d
private

Definition at line 49 of file KoMarkerCollection.h.

◆ markers

QList< KoMarker * > KoMarkerCollection::markers

Definition at line 33 of file KoMarkerCollection.cpp.


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