QGIS API Documentation  master-3f58142
src/core/diagram/qgsdiagram.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002     qgsdiagram.cpp
00003     ---------------------
00004     begin                : March 2011
00005     copyright            : (C) 2011 by Marco Hugentobler
00006     email                : marco dot hugentobler at sourcepole dot ch
00007  ***************************************************************************
00008  *                                                                         *
00009  *   This program is free software; you can redistribute it and/or modify  *
00010  *   it under the terms of the GNU General Public License as published by  *
00011  *   the Free Software Foundation; either version 2 of the License, or     *
00012  *   (at your option) any later version.                                   *
00013  *                                                                         *
00014  ***************************************************************************/
00015 #include "qgsdiagram.h"
00016 #include "qgsdiagramrendererv2.h"
00017 #include "qgsrendercontext.h"
00018 
00019 #include <QPainter>
00020 
00021 void QgsDiagram::setPenWidth( QPen& pen, const QgsDiagramSettings& s, const QgsRenderContext& c )
00022 {
00023   if ( s.sizeType == QgsDiagramSettings::MM )
00024   {
00025     pen.setWidthF( s.penWidth * c.scaleFactor() );
00026   }
00027   else
00028   {
00029     pen.setWidthF( s.penWidth / c.mapToPixel().mapUnitsPerPixel() );
00030   }
00031 }
00032 
00033 
00034 QSizeF QgsDiagram::sizePainterUnits( const QSizeF& size, const QgsDiagramSettings& s, const QgsRenderContext& c )
00035 {
00036   if ( s.sizeType == QgsDiagramSettings::MM )
00037   {
00038     return QSizeF( size.width() * c.scaleFactor(), size.height() * c.scaleFactor() );
00039   }
00040   else
00041   {
00042     return QSizeF( size.width() / c.mapToPixel().mapUnitsPerPixel(), size.height() / c.mapToPixel().mapUnitsPerPixel() );
00043   }
00044 }
00045 
00046 float QgsDiagram::sizePainterUnits( float l, const QgsDiagramSettings& s, const QgsRenderContext& c )
00047 {
00048   if ( s.sizeType == QgsDiagramSettings::MM )
00049   {
00050     return l * c.scaleFactor();
00051   }
00052   else
00053   {
00054     return l / c.mapToPixel().mapUnitsPerPixel();
00055   }
00056 }
00057 
00058 QFont QgsDiagram::scaledFont( const QgsDiagramSettings& s, const QgsRenderContext& c )
00059 {
00060   QFont f = s.font;
00061   if ( s.sizeType == QgsDiagramSettings::MM )
00062   {
00063     f.setPixelSize( s.font.pointSizeF() * 0.376 * c.scaleFactor() );
00064   }
00065   else
00066   {
00067     f.setPixelSize( s.font.pointSizeF() / c.mapToPixel().mapUnitsPerPixel() );
00068   }
00069 
00070   return f;
00071 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines