Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remove all use of oversampling
Enable antialiasing for marker symbols
Show larger marker previews in vector props marker combo
NOTE: There is still an issue with markes being placed at incorrect offset that I need to resolve.


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@4723 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Jan 23, 2006
1 parent 1ad16d6 commit 5f2fb16
Show file tree
Hide file tree
Showing 21 changed files with 90 additions and 243 deletions.
2 changes: 1 addition & 1 deletion src/composer/qgscomposermap.cpp
Expand Up @@ -122,7 +122,7 @@ void QgsComposerMap::draw ( QPainter *painter, QgsRect *extent, QgsMapToPixel *t
widthScale *= mComposition->viewScale();
}
double symbolScale = mSymbolScale * mComposition->scale();
vector->draw( painter, extent, transform, device, widthScale, symbolScale, 0 );
vector->draw( painter, extent, transform, device, widthScale, symbolScale);

} else {
// raster
Expand Down
56 changes: 5 additions & 51 deletions src/core/qgsmarkercatalogue.cpp
Expand Up @@ -84,23 +84,23 @@ QgsMarkerCatalogue *QgsMarkerCatalogue::instance()
return QgsMarkerCatalogue::mMarkerCatalogue;
}

QPixmap QgsMarkerCatalogue::marker ( QString fullName, int size, QPen pen, QBrush brush, int oversampling, bool qtBug )
QPixmap QgsMarkerCatalogue::marker ( QString fullName, int size, QPen pen, QBrush brush, bool qtBug )
{
//std::cerr << "QgsMarkerCatalogue::marker" << std::endl;
if ( fullName.left(5) == "hard:" ) {
QPicture myPicture = hardMarker ( fullName.mid(5), size, pen, brush, oversampling, qtBug );
QPicture myPicture = hardMarker ( fullName.mid(5), size, pen, brush, qtBug );
QPixmap myPixmap = QPixmap (myPicture.width(),myPicture.height());
QPainter myPainter(&myPixmap);
myPainter.drawPicture(0,0,myPicture);
return myPixmap;
} else if ( fullName.left(4) == "svg:" ) {
return svgMarker ( fullName.mid(4), size, oversampling );
return svgMarker ( fullName.mid(4), size );
}

return QPixmap(); // empty
}

QPixmap QgsMarkerCatalogue::svgMarker ( QString name, int s, int oversampling )
QPixmap QgsMarkerCatalogue::svgMarker ( QString name, int s)
{
QPixmap pixmap = QgsSVGCache::instance().getPixmap(name,1.);

Expand All @@ -111,7 +111,7 @@ QPixmap QgsMarkerCatalogue::svgMarker ( QString name, int s, int oversampling )
return pixmap;
}

QPicture QgsMarkerCatalogue::hardMarker ( QString name, int s, QPen pen, QBrush brush, int oversampling, bool qtBug )
QPicture QgsMarkerCatalogue::hardMarker ( QString name, int s, QPen pen, QBrush brush, bool qtBug )
{
// Size of polygon symbols is calculated so that the area is equal to circle with
// diameter mPointSize
Expand Down Expand Up @@ -195,52 +195,6 @@ QPicture QgsMarkerCatalogue::hardMarker ( QString name, int s, QPen pen, QBrush
picture.setBoundingRect ( box );
}

// If oversampling > 1 create pixmap

// Hardcoded symbols are not oversampled at present, because the problem is especially
// with SVG markers (I am not sure why)
/*
if ( oversampling > 1 ) {
QRect br = picture.boundingRect();
QPixmap pixmap ( oversampling * br.width(), oversampling * br.height() );
// Find bg color (must differ from line and fill)
QColor transparent;
for ( int i = 0; i < 255; i++ ) {
if ( pen.color().red() != i && brush.color().red() != i ) {
transparent = QColor ( i, 0, 0 );
break;
}
}
pixmap.fill( transparent );
QPainter pixpainter;
pixpainter.begin(&pixmap);
pixpainter.scale ( oversampling, oversampling );
pixpainter.drawPicture ( -br.x(), -br.y(), picture );
pixpainter.end();
QImage img = pixmap.convertToImage();
img.setAlphaBuffer(true);
for ( int i = 0; i < img.width(); i++ ) {
for ( int j = 0; j < img.height(); j++ ) {
QRgb pixel = img.pixel(i, j);
int alpha = 255;
if ( qRed(pixel) == transparent.red() ) {
alpha = 0;
}
img.setPixel ( i, j, qRgba(qRed(pixel), qGreen(pixel), qBlue(pixel), alpha) );
}
}
img = img.smoothScale( br.width(), br.height());
pixmap.convertFromImage ( img );
picpainter.begin(&picture);
picpainter.drawPixmap ( 0, 0, pixmap );
picpainter.end();
}
*/

return picture;
}

6 changes: 3 additions & 3 deletions src/core/qgsmarkercatalogue.h
Expand Up @@ -43,7 +43,7 @@ class QgsMarkerCatalogue{
/** Returns picture of the marker
* \param fullName full name, e.g. hard:circle, svg:/home/usr1/marker1.svg
*/
QPixmap marker ( QString fullName, int size, QPen pen, QBrush brush, int oversampling = 1, bool qtBug = true );
QPixmap marker ( QString fullName, int size, QPen pen, QBrush brush, bool qtBug = true );

private:

Expand All @@ -56,10 +56,10 @@ class QgsMarkerCatalogue{
QStringList mList;

/** Hard coded */
QPicture hardMarker ( QString name, int size, QPen pen, QBrush brush, int oversampling = 1, bool qtBug = true );
QPicture hardMarker ( QString name, int size, QPen pen, QBrush brush, bool qtBug = true );

/** Hard coded */
QPixmap svgMarker ( QString name, int size, int oversampling = 1 );
QPixmap svgMarker ( QString name, int size );
};

#endif // QGSMARKERCATALOGUE_H
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsrenderer.h
Expand Up @@ -53,7 +53,7 @@ class QgsRenderer
@param f a pointer to the feature to be rendered
@param pic pointer to a marker from SVG (is only used by marker renderers)
@param scalefactor pointer to the scale factor for the marker image*/
virtual void renderFeature(QPainter* p, QgsFeature* f,QPixmap* pic, double* scalefactor, bool selected, int oversampling = 1, double widthScale = 1.)=0;
virtual void renderFeature(QPainter* p, QgsFeature* f,QPixmap* pic, double* scalefactor, bool selected, double widthScale = 1.)=0;
/**Reads the renderer configuration from an XML file
@param rnode the DOM node to read
@param vl the vector layer which will be associated with the renderer*/
Expand Down
10 changes: 1 addition & 9 deletions src/core/qgssvgcache.cpp
Expand Up @@ -32,7 +32,6 @@

QgsSVGCache::QgsSVGCache() {
QSettings settings;
oversampling = settings.readNumEntry("/qgis/svgoversampling", 4);
pixelLimit = settings.readNumEntry("/qgis/svgcachesize", 200000);
totalPixels = 0;
}
Expand Down Expand Up @@ -98,6 +97,7 @@ QPixmap QgsSVGCache::getPixmap(QString filename, double scaleFactor)
QPixmap myPixmap = QPixmap(width,height);
myPixmap.fill(QColor(255,255,255,0)); //transparent
QPainter myPainter(&myPixmap);
myPainter.setRenderHint(QPainter::Antialiasing);
mySVG.render(&myPainter);
pixmapMap[std::pair<QString, double>(filename, scaleFactor)] = myPixmap;
return myPixmap;
Expand All @@ -111,11 +111,3 @@ void QgsSVGCache::clear() {
}


void QgsSVGCache::setOversampling(int oversamplingFactor) {
oversampling = oversamplingFactor;
}


int QgsSVGCache::getOversampling() const {
return oversampling;
}
18 changes: 0 additions & 18 deletions src/core/qgssvgcache.h
Expand Up @@ -51,23 +51,6 @@ class QgsSVGCache {
has changed and you want to get rid of cached lower-quality pixmaps. */
void clear();

/** When a pixmap is requested and it is not in the cache, it will be
loaded using a QPicture and rendered to a QPixmap. Since Qt does not do
any kind of anti-aliasing or smoothing, the QPicture is first rendered
to a pixmap that is larger than the requested size, and then it's scaled
down using QImage::smoothScale() to smooth out sharp edges and lines.
The oversampling factor determins how much larger the first pixmap is -
the larger this factor is the smoother the final pixmap will look, but
it will also take longer time to render and scale the image. This
function sets the oversampling factor. It should be larger than or equal
to 1.
*/
void setOversampling(int oversamplingFactor);

/** This function returns the oversampling factor.
@see setOversampling()
*/
int getOversampling() const;

/** This function returns a reference to the singleton object. */
static inline QgsSVGCache& instance();
Expand All @@ -78,7 +61,6 @@ class QgsSVGCache {
PictureMap pictureMap;
typedef std::map<std::pair<QString, double>,QPixmap> PixmapMap;
PixmapMap pixmapMap;
int oversampling;
std::queue<std::pair<QString, double> > fifo;
int pixelLimit;
int totalPixels;
Expand Down
43 changes: 9 additions & 34 deletions src/core/qgssymbol.cpp
Expand Up @@ -40,7 +40,6 @@ QgsSymbol::QgsSymbol(QGis::VectorType t, QString lvalue, QString uvalue, QString
mType(t),
mPointSymbolName( "hard:circle" ),
mPointSize( 6 ),
mOversampling(1),
mPointSymbolPixmap(1,1),
mWidthScale(1.0),
mCacheUpToDate( false ),
Expand All @@ -57,7 +56,6 @@ QgsSymbol::QgsSymbol(QGis::VectorType t, QString lvalue, QString uvalue, QString
mBrush( c ),
mPointSymbolName( "hard:circle" ),
mPointSize( 6 ),
mOversampling(1),
mPointSymbolPixmap(1,1),
mWidthScale(1.0),
mCacheUpToDate( false ),
Expand All @@ -67,7 +65,6 @@ QgsSymbol::QgsSymbol(QGis::VectorType t, QString lvalue, QString uvalue, QString
QgsSymbol::QgsSymbol()
: mPointSymbolName( "hard:circle" ),
mPointSize( 6 ),
mOversampling(1),
mPointSymbolPixmap(1,1),
mWidthScale(1.0),
mCacheUpToDate( false ),
Expand All @@ -80,7 +77,6 @@ QgsSymbol::QgsSymbol(QColor c)
mBrush( c ),
mPointSymbolName( "hard:circle" ),
mPointSize( 6 ),
mOversampling(1),
mPointSymbolPixmap(1,1),
mWidthScale(1.0),
mCacheUpToDate( false ),
Expand Down Expand Up @@ -186,59 +182,39 @@ QPixmap QgsSymbol::getPolygonSymbolAsPixmap()
return pix; //this is ok because of qts sharing mechanism
}

QPixmap QgsSymbol::getPointSymbolAsPixmap( int oversampling, double widthScale,
QPixmap QgsSymbol::getPointSymbolAsPixmap( double widthScale,
bool selected, QColor selectionColor )
{
//std::cerr << "QgsSymbol::getPointSymbolAsPixmap oversampling = " << oversampling <<
// " widthScale = " << widthScale << std::endl;

if ( oversampling >= 1 ) // called for canvas -> mPointSymbolPixmap
{
if ( !mCacheUpToDate || oversampling != mOversampling
if ( !mCacheUpToDate
|| ( selected && mSelectionColor != selectionColor ) )
{
if ( selected ) {
cache( oversampling, selectionColor );
cache( selectionColor );
} else {
cache( oversampling, mSelectionColor );
cache( mSelectionColor );
}
}
if ( selected ) {
return mPointSymbolPixmapSelected;
}
return mPointSymbolPixmap;
}

// called by composer -> mPointSymbolPixmap2
if ( !mCacheUpToDate2 || widthScale != mWidthScale
|| ( selected && mSelectionColor2 != selectionColor ) )
{
if ( selected ) {
cache2( widthScale, selectionColor );
} else {
cache2( widthScale, mSelectionColor );
}
}
if ( selected ) {
return mPointSymbolPixmapSelected2;
}
return mPointSymbolPixmap2;
}

void QgsSymbol::cache( int oversampling, QColor selectionColor )
void QgsSymbol::cache( QColor selectionColor )
{
QPen pen = mPen;
pen.setColor ( selectionColor );
QBrush brush = mBrush;
brush.setColor ( selectionColor );

mPointSymbolPixmap = QgsMarkerCatalogue::instance()->marker ( mPointSymbolName, mPointSize,
mPen, mBrush, oversampling );
mPen, mBrush );

mPointSymbolPixmapSelected = QgsMarkerCatalogue::instance()->marker (
mPointSymbolName, mPointSize, pen, brush, oversampling );
mPointSymbolName, mPointSize, pen, brush );

mOversampling = oversampling;
mSelectionColor = selectionColor;
mCacheUpToDate = true;
}
Expand All @@ -247,20 +223,19 @@ void QgsSymbol::cache2( double widthScale, QColor selectionColor )
{
//std::cerr << "QgsSymbol::cache2 widthScale = " << widthScale << std::endl;

// Vector without oversampling with width scale */
QPen pen = mPen;
pen.setWidth ( (int) ( widthScale * pen.width() ) );


mPointSymbolPixmap2 = QgsMarkerCatalogue::instance()->marker ( mPointSymbolName, mPointSize,
pen, mBrush, 1, false );
pen, mBrush, false );

QBrush brush = mBrush;
brush.setColor ( selectionColor );
pen.setColor ( selectionColor );

mPointSymbolPixmapSelected2 = QgsMarkerCatalogue::instance()->marker (
mPointSymbolName, mPointSize, pen, brush, 1, false );
mPointSymbolName, mPointSize, pen, brush, false );

mSelectionColor2 = selectionColor;

Expand Down
25 changes: 14 additions & 11 deletions src/core/qgssymbol.h
Expand Up @@ -91,11 +91,8 @@ class QgsSymbol{
virtual QPixmap getPolygonSymbolAsPixmap();

/** Get QPixmap representation of point symbol with current settings
* \param oversampling oversampling factor
* >= 1 -> returns mPointSymbolPixmap, widthScale ignored
* 0 -> returns mPointSymbolPixmap2, with widthScale
*/
virtual QPixmap getPointSymbolAsPixmap(int oversampling = 1, double widthScale = 1.,
virtual QPixmap getPointSymbolAsPixmap( double widthScale = 1.,
bool selected = false, QColor selectionColor = Qt::yellow );

/**Writes the contents of the symbol to a configuration file
Expand Down Expand Up @@ -126,24 +123,30 @@ class QgsSymbol{
/* TODO Because for printing we always need a symbol without oversampling but with line width scale,
* we keep also separate picture with line width scale */

/* Oversampling used for current mPointSymbolPixmap and mPointSymbolPixmap */
int mOversampling;

/* Point symbol cache with oversampling mOversampling */
//
//
// NOTE THE LOGIC OF THESE MEMBER VARS NEED TO BE REVISITED NOW THAT
// I HAVE REMOVED SVG OVERSAMPLING (NEEDED IN QT3 WITH POOR SVG SUPPORT)
// Tim Sutton 2006 XXX FIXME
//
//


/* Point symbol cache */
QPixmap mPointSymbolPixmap;

/* Point symbol cache with oversampling mOversampling (but vector if mOversampling == 1) */
/* Point symbol cache */
QPixmap mPointSymbolPixmapSelected;

/* Current line width scale used by mPointSymbolVectorPixmap */
double mWidthScale;

/* Point symbol cache without oversampling (always vector picture) but with line width scale mWidthScale */
/* Point symbol cache but with line width scale mWidthScale */
QPixmap mPointSymbolPixmap2;
QPixmap mPointSymbolPixmapSelected2;

/* Create point symbol mPointSymbolPixmap/mPointSymbolPixmap cache */
void cache( int oversampling, QColor selectionColor );
void cache( QColor selectionColor );

/* Create point symbol mPointSymbolPixmap2 cache */
void cache2( double widthScale, QColor selectionColor );
Expand Down
5 changes: 2 additions & 3 deletions src/gui/qgscontinuouscolrenderer.cpp
Expand Up @@ -73,7 +73,7 @@ void QgsContinuousColRenderer::setMaximumSymbol(QgsSymbol* sy)
}

void QgsContinuousColRenderer::renderFeature(QPainter * p, QgsFeature * f, QPixmap* pic,
double* scalefactor, bool selected, int oversampling, double widthScale)
double* scalefactor, bool selected, double widthScale)
{
if ((mMinimumSymbol && mMaximumSymbol))
{
Expand Down Expand Up @@ -135,9 +135,8 @@ void QgsContinuousColRenderer::renderFeature(QPainter * p, QgsFeature * f, QPixm
}
brush.setStyle ( Qt::SolidPattern );

// Always with oversampling 0
*pic = QgsMarkerCatalogue::instance()->marker ( mMinimumSymbol->pointSymbolName(), mMinimumSymbol->pointSize(),
pen, brush, 0 );
pen, brush);

if ( scalefactor ) *scalefactor = 1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgscontinuouscolrenderer.h
Expand Up @@ -37,7 +37,7 @@ class QgsContinuousColRenderer: public QgsRenderer
QgsContinuousColRenderer& operator=(const QgsContinuousColRenderer& other);
virtual ~QgsContinuousColRenderer();
/**Renders the feature using the minimum and maximum value of the classification field*/
void renderFeature(QPainter* p, QgsFeature* f, QPixmap* pic, double* scalefactor, bool selected, int oversampling = 1, double widthScale = 1.);
void renderFeature(QPainter* p, QgsFeature* f, QPixmap* pic, double* scalefactor, bool selected, double widthScale = 1.);
/**Returns the number of the classification field*/
int classificationField() const;
/**Sets the id of the classification field*/
Expand Down

0 comments on commit 5f2fb16

Please sign in to comment.