Skip to content
Permalink
Browse files

Started to implement svg cache

  • Loading branch information
mhugent committed Jun 21, 2011
1 parent a21e1db commit 651259a80ce9f822534f05b1a1d54c038cb100a9
Showing with 133 additions and 0 deletions.
  1. +1 −0 src/core/CMakeLists.txt
  2. +59 −0 src/core/symbology-ng/qgssvgcache.cpp
  3. +73 −0 src/core/symbology-ng/qgssvgcache.h
@@ -37,6 +37,7 @@ SET(QGIS_CORE_SRCS
symbology-ng/qgsvectorcolorrampv2.cpp
symbology-ng/qgsstylev2.cpp
symbology-ng/qgssymbologyv2conversion.cpp
symbology-ng/qgssvgcache.cpp

qgis.cpp
qgsapplication.cpp
@@ -0,0 +1,59 @@
/***************************************************************************
qgssvgcache.h
------------------------------
begin : 2011
copyright : (C) 2011 by Marco Hugentobler
email : marco dot hugentobler at sourcepole dot ch
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgssvgcache.h"

QgsSvgCache* QgsSvgCache::mInstance = 0;

QgsSvgCache* QgsSvgCache::instance()
{
if ( !mInstance )
{
mInstance = new QgsSvgCache();
}
return mInstance;
}

QgsSvgCache::QgsSvgCache()
{
}

QgsSvgCache::~QgsSvgCache()
{
}


const QImage& QgsSvgCache::svgAsImage( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth ) const
{
}

const QPicture& QgsSvgCache::svgAsPicture( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth ) const
{
}

void QgsSvgCache::insertSVG( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth )
{
}

void QgsSvgCache::cacheImage( QgsSvgCacheEntry )
{
}

void QgsSvgCache::cachePicture( QgsSvgCacheEntry )
{
}

@@ -0,0 +1,73 @@
/***************************************************************************
qgssvgcache.h
------------------------------
begin : 2011
copyright : (C) 2011 by Marco Hugentobler
email : marco dot hugentobler at sourcepole dot ch
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSSVGCACHE_H
#define QGSSVGCACHE_H

#include <QColor>
#include <QDateTime>
#include <QMap>
#include <QMultiHash>
#include <QString>

class QImage;
class QPicture;

struct QgsSvgCacheEntry
{
QString file;
double size;
double outlineWidth;
QColor fill;
QColor outline;
QImage* image;
QPicture* picture;
QDateTime lastUsed;
};

/**A cache for images / pictures derived from svg files. This class supports parameter replacement in svg files
according to the svg params specification (http://www.w3.org/TR/2009/WD-SVGParamPrimer-20090616/). Supported are
the parameters 'fill-color', 'pen-color', 'outline-width', 'stroke-width'. E.g. <circle fill="param(fill-color red)" stroke="param(pen-color black)" stroke-width="param(outline-width 1)"*/
class QgsSvgCache
{
public:

static QgsSvgCache* instance();
~QgsSvgCache();

const QImage& svgAsImage( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth ) const;
const QPicture& svgAsPicture( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth ) const;

protected:
QgsSvgCache();

void insertSVG( const QString& file, double size, const QColor& fill, const QColor& outline, double outlineWidth );
void cacheImage( QgsSvgCacheEntry );
void cachePicture( QgsSvgCacheEntry );

private:
static QgsSvgCache* mInstance;

/**Entries sorted by last used time*/
QMap< QDateTime, QgsSvgCacheEntry > mEntries;
/**Entry pointers accessible by file name*/
QMultiHash< QString, QgsSvgCacheEntry* > mEntryLookup;
/**Estimated total size of all images and pictures*/
double mTotalSize;
};

#endif // QGSSVGCACHE_H

0 comments on commit 651259a

Please sign in to comment.
You can’t perform that action at this time.