Skip to content
Permalink
Browse files

Use QImage for map and QPicture for composer

  • Loading branch information
Marco Hugentobler
Marco Hugentobler committed Jun 25, 2011
1 parent aa2ad45 commit e1122045d34580b40233a086814b14bd4ece7077
@@ -534,12 +534,18 @@ void QgsSvgMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Re
if ( mAngle != 0 )
p->rotate( mAngle );

const QPicture& pct = QgsSvgCache::instance()->svgAsPicture( mPath, mSize, QColor( Qt::black )/*const QColor& fill*/, QColor( Qt::black ) /*const QColor& outline*/,
1.0 /*outline width*/, context.renderContext().scaleFactor(), context.renderContext().rasterScaleFactor() );
p->drawPicture( 0, 0, pct );

/*QPicture &pct = context.selected() ? mSelPicture : mPicture;
p->drawPicture( 0, 0, pct );*/
if( doubleNear( context.renderContext().rasterScaleFactor(), 1.0 ) )
{
const QImage& img = QgsSvgCache::instance()->svgAsImage( mPath, mSize, QColor( Qt::black )/*const QColor& fill*/, QColor( Qt::black ) /*const QColor& outline*/,
1.0 /*outline width*/, context.renderContext().scaleFactor(), context.renderContext().rasterScaleFactor() );
p->drawImage( -img.width() / 2.0, -img.width() / 2.0, img );
}
else
{
const QPicture& pct = QgsSvgCache::instance()->svgAsPicture( mPath, mSize, QColor( Qt::black )/*const QColor& fill*/, QColor( Qt::black ) /*const QColor& outline*/,
1.0 /*outline width*/, context.renderContext().scaleFactor(), context.renderContext().rasterScaleFactor() );
p->drawPicture( 0, 0, pct );
}

p->restore();
}
@@ -17,6 +17,7 @@

#include "qgssvgcache.h"
#include <QDomDocument>
#include <QDomElement>
#include <QFile>
#include <QImage>
#include <QPainter>
@@ -145,7 +146,9 @@ void QgsSvgCache::replaceParamsAndCacheSvg( QgsSvgCacheEntry* entry )
return;
}

//todo: replace params here
//replace fill color, outline color, outline with in all nodes
QDomElement docElem = svgDoc.documentElement();
replaceElemParams( docElem, entry->fill, entry->outline, entry->outlineWidth );

entry->svgContent = svgDoc.toByteArray();
}
@@ -164,7 +167,6 @@ void QgsSvgCache::cacheImage( QgsSvgCacheEntry* entry )
QImage* image = new QImage( imageSize, imageSize, QImage::Format_ARGB32_Premultiplied );
image->fill( 0 ); // transparent background

//rasterise byte array to image
QPainter p( image );
QSvgRenderer r( entry->svgContent );
r.render( &p );
@@ -224,3 +226,40 @@ QgsSvgCacheEntry* QgsSvgCache::cacheEntry( const QString& file, double size, con
return currentEntry;
}

void QgsSvgCache::replaceElemParams( QDomElement& elem, const QColor& fill, const QColor& outline, double outlineWidth )
{
if( elem.isNull() )
{
return;
}

//go through attributes
QDomNamedNodeMap attributes = elem.attributes();
int nAttributes = attributes.count();
for( int i = 0; i < nAttributes; ++i )
{
QDomAttr attribute = attributes.item( i ).toAttr();
QString value = attribute.value();
if( value.startsWith("params(fill)") )
{
elem.setAttribute( attribute.name(), fill.name() );
}
else if( value.startsWith("params(outline)") )
{
elem.setAttribute( attribute.name(), outline.name() );
}
else if( value.startsWith("params(outline-width)") )
{
elem.setAttribute( attribute.name(), QString::number( outlineWidth ) );
}
}

QDomNodeList childList = elem.childNodes();
int nChildren = childList.count();
for( int i = 0; i < nChildren; ++i )
{
QDomElement childElem = childList.at( i ).toElement();
replaceElemParams( childElem, fill, outline, outlineWidth );
}
}

@@ -24,6 +24,7 @@
#include <QMultiHash>
#include <QString>

class QDomElement;
class QImage;
class QPicture;

@@ -88,6 +89,8 @@ class QgsSvgCache
QMultiHash< QString, QgsSvgCacheEntry* > mEntryLookup;
/**Estimated total size of all images and pictures*/
double mTotalSize;
/**Replaces parameters in elements of a dom node and calls method for all child nodes*/
void replaceElemParams( QDomElement& elem, const QColor& fill, const QColor& outline, double outlineWidth );
};

#endif // QGSSVGCACHE_H

0 comments on commit e112204

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