Started to implement svg cache

This commit is contained in:
Marco Hugentobler 2011-06-21 15:03:08 +02:00
parent a21e1db988
commit 651259a80c
3 changed files with 133 additions and 0 deletions

View File

@ -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

View File

@ -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 )
{
}

View File

@ -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