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