[Qgis-developer] Shields for Labels

Marco Hugentobler marco.hugentobler at sourcepole.ch
Tue Aug 9 09:54:08 EDT 2011


Hi Tim

+1 for bringing the shield code into core. I agree with the comments about 
enhancements with marker symbols or scaled svg symbols. These would be great 
additions for the future.

The scaling works for me as follows (It does not need the consideration of the 
raster compress factor, because we are not dealing with the oversized fonts):

if ( drawShield )
    {
      painter->save();

      painter->translate( QPointF( outPt.x(), outPt.y() ) );
      painter->rotate( -label->getAlpha() * 180 / M_PI );
      double scaledSize = lyr.vectorScaleFactor * shieldSize;
      double yMultiLineOffset = ( multiLineList.size() - 1 - i ) * 
lyr.fontMetrics->height();
      painter->translate( QPointF( 0, - lyr.fontMetrics->descent() - 
yMultiLineOffset ) );
      QgsPoint rectPt = xform->transform( label->getX(), label->getY() );
      QgsPoint rectPt2 = xform->transform( label->getX() + label->getWidth(), 
label->getY() + label->getHeight() );
      QPointF origin( double( - scaledSize ), scaledSize + lyr.fontMetrics-
>descent() );
      QPointF corner( double( rectPt2.x()  - rectPt.x() + ( scaledSize * 2 ) 
), double( rectPt2.y() - rectPt.y() - scaledSize + lyr.fontMetrics->descent()) 
);
      
	  if ( mShowingCandidates )
	  {
        painter->setBrush( Qt::red );
        painter->drawEllipse( origin, 3, 3 );
        painter->setBrush( Qt::green );
        painter->drawEllipse( corner, 3, 3 );
	  }
      // draw the shield
      QRectF rect( origin, corner );
      painter->setPen( Qt::NoPen );
      painter->setBrush( shieldColor );
      painter->drawRoundedRect( rect, shieldCornerRounding, 
shieldCornerRounding );
     
      painter->restore();
    }
      

Regards,
Marco
	

Am Montag, 8. August 2011, 17.46:08 schrieb Marco Hugentobler:
> Hi Tim
> 
> Cool, shields for labels are very usefull, both with rectangles or with svg
> background (probably in future).
> Rectangular shields are also well suited as a (computationally) fast
> alternative to font buffers.
> 
> I didn't yet look into the details of the code. From first tries of the
> label- shield branch, it seems to me the shields currently don't appear
> nicely in composer printouts. Probably it needs the consideration of the
> output device resolution.
> 
> Regards,
> Marco
> 
> Am Sonntag, 7. August 2011, 23.47:07 schrieb Tim Sutton:
> > Hi Folks
> > 
> > Is anyone else interested in being able to have shields for labels
> > (e.g. to mark highways etc.). I've made an initial stab at it - you
> > can see an example and git details in case you want to try it in the
> > link below. Is there any interest in getting this into trunk? Maybe a
> > better way of doing things? I thought of using SVG shields but I think
> > it might be a performance killer if you have many labels and each
> > needs scaling.
> > 
> > http://linfiniti.com/2011/08/shield-labels-for-qgis/
> > 
> > Regards
> > 
> > Tim


-- 
Dr. Marco Hugentobler
Sourcepole -  Linux & Open Source Solutions
Churerstrasse 22, CH-8808 Pfäffikon SZ, Switzerland
marco.hugentobler at sourcepole.ch http://www.sourcepole.ch
Technical Advisor QGIS Project Steering Committee


More information about the Qgis-developer mailing list