Quantum GIS API Documentation  1.7.4
src/core/qgsdiagramrendererv2.h
Go to the documentation of this file.
00001 #ifndef QGSDIAGRAMRENDERERV2_H
00002 #define QGSDIAGRAMRENDERERV2_H
00003 
00004 #include <QColor>
00005 #include <QFont>
00006 #include <QList>
00007 #include <QPointF>
00008 #include <QSizeF>
00009 #include "qgsfeature.h"
00010 #include "qgspallabeling.h"
00011 
00012 class QgsDiagram;
00013 class QgsDiagramRendererV2;
00014 class QgsFeature;
00015 class QgsRenderContext;
00016 class QDomElement;
00017 namespace pal { class Layer; }
00018 
00019 struct CORE_EXPORT QgsDiagramLayerSettings
00020 {
00021   //avoid inclusion of QgsPalLabeling
00022   enum Placement
00023   {
00024     AroundPoint, // Point / Polygon
00025     OverPoint, // Point / Polygon
00026     Line, // Line / Polygon
00027     Curved, // Line
00028     Horizontal, // Polygon
00029     Free // Polygon
00030   };
00031 
00032   enum LinePlacementFlags
00033   {
00034     OnLine    = 1,
00035     AboveLine = 2,
00036     BelowLine = 4,
00037     MapOrientation = 8
00038   };
00039 
00040   QgsDiagramLayerSettings(): placement( AroundPoint ), placementFlags( OnLine ), priority( 5 ), obstacle( false ), dist( 0.0 ), renderer( 0 ),
00041       palLayer( 0 ), ct( 0 ), xform( 0 ), xPosColumn( -1 ), yPosColumn( -1 )
00042   {
00043   }
00044 
00045   //pal placement properties
00046   Placement placement;
00047   LinePlacementFlags placementFlags;
00048   int priority; // 0 = low, 10 = high
00049   bool obstacle; // whether it's an obstacle
00050   double dist; // distance from the feature (in mm)
00051   QgsDiagramRendererV2* renderer;
00052 
00053   //assigned when layer gets prepared
00054   pal::Layer* palLayer;
00055   const QgsCoordinateTransform* ct;
00056   const QgsMapToPixel* xform;
00057   QList<QgsPalGeometry*> geometries;
00058 
00059   int xPosColumn; //attribute index for x coordinate (or -1 if position not data defined)
00060   int yPosColumn;//attribute index for y coordinate (or -1 if position not data defined)
00061 
00062   void readXML( const QDomElement& elem );
00063   void writeXML( QDomElement& layerElem, QDomDocument& doc ) const;
00064 };
00065 
00066 //diagram settings for rendering
00067 struct CORE_EXPORT QgsDiagramSettings
00068 {
00069   enum SizeType
00070   {
00071     MM,
00072     MapUnits
00073   };
00074 
00075   QgsDiagramSettings(): sizeType( MM ), minScaleDenominator( -1 ), maxScaleDenominator( -1 )
00076   {}
00077   QFont font;
00078   QList< QColor > categoryColors;
00079   QList< int > categoryIndices;
00080   QSizeF size; //size
00081   SizeType sizeType; //mm or map units
00082   QColor backgroundColor;
00083   QColor penColor;
00084   double penWidth;
00085 
00086   //scale range (-1 if no lower / upper bound )
00087   double minScaleDenominator;
00088   double maxScaleDenominator;
00089 
00090   void readXML( const QDomElement& elem );
00091   void writeXML( QDomElement& rendererElem, QDomDocument& doc ) const;
00092 };
00093 
00095 class CORE_EXPORT QgsDiagramRendererV2
00096 {
00097   public:
00098 
00099     QgsDiagramRendererV2();
00100     virtual ~QgsDiagramRendererV2();
00101 
00103     virtual QSizeF sizeMapUnits( const QgsAttributeMap& attributes, const QgsRenderContext& c );
00104 
00105     virtual QString rendererName() const = 0;
00106 
00108     virtual QList<int> diagramAttributes() const = 0;
00109 
00110     void renderDiagram( const QgsAttributeMap& att, QgsRenderContext& c, const QPointF& pos );
00111 
00112     void setDiagram( QgsDiagram* d );
00113     const QgsDiagram* diagram() const { return mDiagram; }
00114 
00116     virtual QList<QgsDiagramSettings> diagramSettings() const = 0;
00117 
00118     virtual void readXML( const QDomElement& elem ) = 0;
00119     virtual void writeXML( QDomElement& layerElem, QDomDocument& doc ) const = 0;
00120 
00121   protected:
00122 
00128     virtual bool diagramSettings( const QgsAttributeMap& att, const QgsRenderContext& c, QgsDiagramSettings& s ) = 0;
00129 
00131     virtual QSizeF diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c ) = 0;
00132 
00134     void convertSizeToMapUnits( QSizeF& size, const QgsRenderContext& context ) const;
00135 
00137     static int dpiPaintDevice( const QPainter* );
00138 
00139     //read / write diagram
00140     void _readXML( const QDomElement& elem );
00141     void _writeXML( QDomElement& rendererElem, QDomDocument& doc ) const;
00142 
00144     QgsDiagram* mDiagram;
00145 };
00146 
00148 class CORE_EXPORT QgsSingleCategoryDiagramRenderer: public QgsDiagramRendererV2
00149 {
00150   public:
00151     QgsSingleCategoryDiagramRenderer();
00152     ~QgsSingleCategoryDiagramRenderer();
00153 
00154     QString rendererName() const { return "SingleCategory"; }
00155 
00156     QList<int> diagramAttributes() const { return mSettings.categoryIndices; }
00157 
00158     void setDiagramSettings( const QgsDiagramSettings& s ) { mSettings = s; }
00159 
00160     QList<QgsDiagramSettings> diagramSettings() const;
00161 
00162     void readXML( const QDomElement& elem );
00163     void writeXML( QDomElement& layerElem, QDomDocument& doc ) const;
00164 
00165   protected:
00166     bool diagramSettings( const QgsAttributeMap&, const QgsRenderContext& c, QgsDiagramSettings& s );
00167 
00168     QSizeF diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c ) { return mSettings.size; }
00169 
00170   private:
00171     QgsDiagramSettings mSettings;
00172 };
00173 
00174 class CORE_EXPORT QgsLinearlyInterpolatedDiagramRenderer: public QgsDiagramRendererV2
00175 {
00176   public:
00177     QgsLinearlyInterpolatedDiagramRenderer();
00178     ~QgsLinearlyInterpolatedDiagramRenderer();
00179 
00181     QList<QgsDiagramSettings> diagramSettings() const;
00182 
00183     void setDiagramSettings( const QgsDiagramSettings& s ) { mSettings = s; }
00184 
00185     QList<int> diagramAttributes() const;
00186 
00187     QString rendererName() const { return "LinearlyInterpolated"; }
00188 
00189     void setLowerValue( double val ) { mLowerValue = val; }
00190     double lowerValue() const { return mLowerValue; }
00191 
00192     void setUpperValue( double val ) { mUpperValue = val; }
00193     double upperValue() const { return mUpperValue; }
00194 
00195     void setLowerSize( QSizeF s ) { mLowerSize = s; }
00196     QSizeF lowerSize() const { return mLowerSize; }
00197 
00198     void setUpperSize( QSizeF s ) { mUpperSize = s; }
00199     QSizeF upperSize() const { return mUpperSize; }
00200 
00201     int classificationAttribute() const { return mClassificationAttribute; }
00202     void setClassificationAttribute( int index ) { mClassificationAttribute = index; }
00203 
00204     void readXML( const QDomElement& elem );
00205     void writeXML( QDomElement& layerElem, QDomDocument& doc ) const;
00206 
00207   protected:
00208     bool diagramSettings( const QgsAttributeMap&, const QgsRenderContext& c, QgsDiagramSettings& s );
00209 
00210     QSizeF diagramSize( const QgsAttributeMap& attributes, const QgsRenderContext& c );
00211 
00212   private:
00213     QgsDiagramSettings mSettings;
00214     QSizeF mLowerSize;
00215     QSizeF mUpperSize;
00216     double mLowerValue;
00217     double mUpperValue;
00219     int mClassificationAttribute;
00220 };
00221 
00222 #endif // QGSDIAGRAMRENDERERV2_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines