QGIS API Documentation
2.12.0-Lyon
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
src
core
symbology-ng
qgssvgcache.h
Go to the documentation of this file.
1
/***************************************************************************
2
qgssvgcache.h
3
------------------------------
4
begin : 2011
5
copyright : (C) 2011 by Marco Hugentobler
6
email : marco dot hugentobler at sourcepole dot ch
7
***************************************************************************/
8
9
/***************************************************************************
10
* *
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
15
* *
16
***************************************************************************/
17
18
#ifndef QGSSVGCACHE_H
19
#define QGSSVGCACHE_H
20
21
#include <QColor>
22
#include <QMap>
23
#include <QMultiHash>
24
#include <QMutex>
25
#include <QString>
26
#include <QUrl>
27
#include <QObject>
28
29
class
QDomElement
;
30
class
QImage
;
31
class
QPicture
;
32
33
class
CORE_EXPORT
QgsSvgCacheEntry
34
{
35
public
:
36
QgsSvgCacheEntry
();
47
QgsSvgCacheEntry
(
const
QString
& file,
double
size,
double
outlineWidth,
double
widthScaleFactor,
double
rasterScaleFactor,
const
QColor
& fill,
const
QColor
& outline,
const
QString
& lookupKey =
QString
() );
48
~
QgsSvgCacheEntry
();
49
51
QString
file
;
53
QString
lookupKey
;
54
double
size
;
//size in pixels (cast to int for QImage)
55
double
outlineWidth
;
56
double
widthScaleFactor
;
57
double
rasterScaleFactor
;
58
QColor
fill
;
59
QColor
outline
;
60
QImage
*
image
;
61
QPicture
*
picture
;
62
//content (with params replaced)
63
QByteArray
svgContent
;
64
65
//keep entries on a least, sorted by last access
66
QgsSvgCacheEntry
*
nextEntry
;
67
QgsSvgCacheEntry
*
previousEntry
;
68
70
bool
operator==
(
const
QgsSvgCacheEntry
& other )
const
;
72
int
dataSize()
const
;
73
};
74
78
class
CORE_EXPORT
QgsSvgCache
:
public
QObject
79
{
80
Q_OBJECT
81
82
public
:
83
84
static
QgsSvgCache
* instance();
85
~
QgsSvgCache
();
86
97
const
QImage
& svgAsImage(
const
QString
& file,
double
size,
const
QColor
& fill,
const
QColor
& outline,
double
outlineWidth,
98
double
widthScaleFactor,
double
rasterScaleFactor,
bool
& fitsInCache );
109
const
QPicture
& svgAsPicture(
const
QString
& file,
double
size,
const
QColor
& fill,
const
QColor
& outline,
double
outlineWidth,
110
double
widthScaleFactor,
double
rasterScaleFactor,
bool
forceVectorOutput =
false
);
111
114
void
containsParams(
const
QString
& path,
bool
& hasFillParam,
QColor
& defaultFillColor,
bool
& hasOutlineParam,
QColor
& defaultOutlineColor,
bool
& hasOutlineWidthParam,
115
double
& defaultOutlineWidth )
const
;
116
132
void
containsParams(
const
QString
& path,
bool
& hasFillParam,
bool
& hasDefaultFillParam,
QColor
& defaultFillColor,
133
bool
& hasOutlineParam,
bool
& hasDefaultOutlineColor,
QColor
& defaultOutlineColor,
134
bool
& hasOutlineWidthParam,
bool
& hasDefaultOutlineWidth,
double
& defaultOutlineWidth )
const
;
135
137
QByteArray
getImageData(
const
QString
&path )
const
;
138
140
const
QByteArray
& svgContent(
const
QString
& file,
double
size,
const
QColor
& fill,
const
QColor
& outline,
double
outlineWidth,
141
double
widthScaleFactor,
double
rasterScaleFactor );
142
143
signals:
145
void
statusChanged(
const
QString
& theStatusQString );
146
147
protected
:
149
QgsSvgCache
(
QObject
* parent = 0 );
150
161
QgsSvgCacheEntry
* insertSVG(
const
QString
& file,
double
size,
const
QColor
& fill,
const
QColor
& outline,
double
outlineWidth,
162
double
widthScaleFactor,
double
rasterScaleFactor );
163
164
void
replaceParamsAndCacheSvg(
QgsSvgCacheEntry
* entry );
165
void
cacheImage(
QgsSvgCacheEntry
* entry );
166
void
cachePicture(
QgsSvgCacheEntry
* entry,
bool
forceVectorOutput =
false
);
168
QgsSvgCacheEntry
* cacheEntry(
const
QString
& file,
double
size,
const
QColor
& fill,
const
QColor
& outline,
double
outlineWidth,
169
double
widthScaleFactor,
double
rasterScaleFactor );
170
172
void
trimToMaximumSize();
173
174
//Removes entry from the ordered list (but does not delete the entry itself)
175
void
takeEntryFromList(
QgsSvgCacheEntry
* entry );
176
177
private
slots:
178
void
downloadProgress( qint64, qint64 );
179
180
private
:
182
QMultiHash< QString, QgsSvgCacheEntry* >
mEntryLookup;
184
long
mTotalSize;
185
186
//The svg cache keeps the entries on a double connected list, moving the current entry to the front.
187
//That way, removing entries for more space can start with the least used objects.
188
QgsSvgCacheEntry
* mLeastRecentEntry;
189
QgsSvgCacheEntry
* mMostRecentEntry;
190
191
//Maximum cache size
192
static
const
long
mMaximumSize = 20000000;
193
195
void
replaceElemParams(
QDomElement
& elem,
const
QColor
& fill,
const
QColor
& outline,
double
outlineWidth );
196
197
void
containsElemParams(
const
QDomElement
& elem,
198
bool
& hasFillParam,
bool
& hasDefaultFill,
QColor
& defaultFill,
199
bool
& hasOutlineParam,
bool
& hasDefaultOutline,
QColor
& defaultOutline,
200
bool
& hasOutlineWidthParam,
bool
& hasDefaultOutlineWidth,
double
& defaultOutlineWidth )
const
;
201
203
double
calcSizeScaleFactor(
QgsSvgCacheEntry
* entry,
const
QDomElement
& docElem )
const
;
204
206
void
removeCacheEntry(
const
QString
& s,
QgsSvgCacheEntry
* entry );
207
209
void
printEntryList();
210
212
QByteArray
mMissingSvg;
213
215
QMutex
mMutex;
216
217
};
218
219
#endif // QGSSVGCACHE_H
QgsSvgCacheEntry
Definition:
qgssvgcache.h:33
QgsSvgCacheEntry::previousEntry
QgsSvgCacheEntry * previousEntry
Definition:
qgssvgcache.h:67
QMutex
QgsSvgCacheEntry::image
QImage * image
Definition:
qgssvgcache.h:60
QgsSvgCacheEntry::size
double size
Definition:
qgssvgcache.h:54
QByteArray
operator==
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Definition:
qgsfeatureiterator.h:214
QgsSvgCache
A cache for images / pictures derived from svg files.
Definition:
qgssvgcache.h:78
QgsSvgCacheEntry::picture
QPicture * picture
Definition:
qgssvgcache.h:61
QObject
QgsSvgCacheEntry::outline
QColor outline
Definition:
qgssvgcache.h:59
QString
QColor
QImage
QgsSvgCacheEntry::lookupKey
QString lookupKey
Lookup key used by QgsSvgCache's hashtable (relative or absolute path). Needed for removal from the h...
Definition:
qgssvgcache.h:53
QgsSvgCacheEntry::outlineWidth
double outlineWidth
Definition:
qgssvgcache.h:55
QPicture
QgsSvgCacheEntry::rasterScaleFactor
double rasterScaleFactor
Definition:
qgssvgcache.h:57
QgsSvgCacheEntry::fill
QColor fill
Definition:
qgssvgcache.h:58
QDomElement
QgsSvgCacheEntry::widthScaleFactor
double widthScaleFactor
Definition:
qgssvgcache.h:56
QgsSvgCacheEntry::file
QString file
Absolute path to SVG file.
Definition:
qgssvgcache.h:51
QMultiHash< QString, QgsSvgCacheEntry * >
QgsSvgCacheEntry::svgContent
QByteArray svgContent
Definition:
qgssvgcache.h:63
QgsSvgCacheEntry::nextEntry
QgsSvgCacheEntry * nextEntry
Definition:
qgssvgcache.h:66
Generated on Sat Oct 24 2015 04:11:25 for QGIS API Documentation by
1.8.9.1