|
QGIS API Documentation
master-59fd5e0
|
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 <QDomDocument> 00024 00025 #include "qgsfeature.h" 00026 00027 class QgsDiagram; 00028 class QgsDiagramRendererV2; 00029 class QgsFeature; 00030 class QgsRenderContext; 00031 class QDomElement; 00032 class QgsPalGeometry; 00033 class QgsCoordinateTransform; 00034 class QgsMapToPixel; 00035 class QgsVectorLayer; 00036 00037 namespace pal { class Layer; } 00038 00039 class CORE_EXPORT QgsDiagramLayerSettings 00040 { 00041 public: 00042 //avoid inclusion of QgsPalLabeling 00043 enum Placement 00044 { 00045 AroundPoint = 0, // Point / Polygon 00046 OverPoint, // Point / Polygon 00047 Line, // Line / Polygon 00048 Curved, // Line 00049 Horizontal, // Polygon 00050 Free // Polygon 00051 }; 00052 00053 enum LinePlacementFlags 00054 { 00055 OnLine = 1, 00056 AboveLine = 2, 00057 BelowLine = 4, 00058 MapOrientation = 8 00059 }; 00060 00061 QgsDiagramLayerSettings() 00062 : placement( AroundPoint ) 00063 , placementFlags( OnLine ) 00064 , priority( 5 ) 00065 , obstacle( false ) 00066 , dist( 0.0 ) 00067 , renderer( 0 ) 00068 , palLayer( 0 ) 00069 , ct( 0 ) 00070 , xform( 0 ) 00071 , xPosColumn( -1 ) 00072 , yPosColumn( -1 ) 00073 { 00074 } 00075 00076 //pal placement properties 00077 Placement placement; 00078 LinePlacementFlags placementFlags; 00079 int priority; // 0 = low, 10 = high 00080 bool obstacle; // whether it's an obstacle 00081 double dist; // distance from the feature (in mm) 00082 QgsDiagramRendererV2* renderer; 00083 00084 //assigned when layer gets prepared 00085 pal::Layer* palLayer; 00086 const QgsCoordinateTransform* ct; 00087 const QgsMapToPixel* xform; 00088 QList<QgsPalGeometry*> geometries; 00089 00090 int xPosColumn; //attribute index for x coordinate (or -1 if position not data defined) 00091 int yPosColumn;//attribute index for y coordinate (or -1 if position not data defined) 00092 00093 void readXML( const QDomElement& elem, const QgsVectorLayer* layer ); 00094 void writeXML( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const; 00095 }; 00096 00097 //diagram settings for rendering 00098 class CORE_EXPORT QgsDiagramSettings 00099 { 00100 public: 00101 enum SizeType 00102 { 00103 MM, 00104 MapUnits 00105 }; 00106 00107 enum LabelPlacementMethod 00108 { 00109 Height, 00110 XHeight 00111 }; 00112 00114 enum DiagramOrientation 00115 { 00116 Up, 00117 Down, 00118 Left, 00119 Right 00120 }; 00121 00122 QgsDiagramSettings(): sizeType( MM ), minScaleDenominator( -1 ), maxScaleDenominator( -1 ) 00123 {} 00124 QFont font; 00125 QList< QColor > categoryColors; 00126 QList< int > categoryIndices; 00127 QSizeF size; //size 00128 SizeType sizeType; //mm or map units 00129 QColor backgroundColor; 00130 QColor penColor; 00131 double penWidth; 00132 LabelPlacementMethod labelPlacementMethod; 00133 DiagramOrientation diagramOrientation; 00134 double barWidth; 00135 int transparency; // 0 - 100 00136 bool scaleByArea; 00137 int angleOffset; 00138 00139 //scale range (-1 if no lower / upper bound ) 00140 double minScaleDenominator; 00141 double maxScaleDenominator; 00142 00144 double minimumSize; 00145 00146 void readXML( const QDomElement& elem, const QgsVectorLayer* layer ); 00147 void writeXML( QDomElement& rendererElem, QDomDocument& doc, const QgsVectorLayer* layer ) const; 00148 }; 00149 00150 //additional diagram settings for interpolated size rendering 00151 class CORE_EXPORT QgsDiagramInterpolationSettings 00152 { 00153 public: 00154 QSizeF lowerSize; 00155 QSizeF upperSize; 00156 double lowerValue; 00157 double upperValue; 00159 int classificationAttribute; 00160 }; 00161 00163 class CORE_EXPORT QgsDiagramRendererV2 00164 { 00165 public: 00166 00167 QgsDiagramRendererV2(); 00168 virtual ~QgsDiagramRendererV2(); 00169 00171 virtual QSizeF sizeMapUnits( const QgsAttributes& attributes, const QgsRenderContext& c ); 00172 00173 virtual QString rendererName() const = 0; 00174 00176 virtual QList<int> diagramAttributes() const = 0; 00177 00178 void renderDiagram( const QgsAttributes& att, QgsRenderContext& c, const QPointF& pos ); 00179 00180 void setDiagram( QgsDiagram* d ); 00181 const QgsDiagram* diagram() const { return mDiagram; } 00182 00184 virtual QList<QgsDiagramSettings> diagramSettings() const = 0; 00185 00186 virtual void readXML( const QDomElement& elem, const QgsVectorLayer* layer ) = 0; 00187 virtual void writeXML( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const = 0; 00188 00189 protected: 00190 00196 virtual bool diagramSettings( const QgsAttributes& att, const QgsRenderContext& c, QgsDiagramSettings& s ) = 0; 00197 00199 virtual QSizeF diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c ) = 0; 00200 00202 void convertSizeToMapUnits( QSizeF& size, const QgsRenderContext& context ) const; 00203 00205 static int dpiPaintDevice( const QPainter* ); 00206 00207 //read / write diagram 00208 void _readXML( const QDomElement& elem, const QgsVectorLayer* layer ); 00209 void _writeXML( QDomElement& rendererElem, QDomDocument& doc, const QgsVectorLayer* layer ) const; 00210 00212 QgsDiagram* mDiagram; 00213 }; 00214 00216 class CORE_EXPORT QgsSingleCategoryDiagramRenderer : public QgsDiagramRendererV2 00217 { 00218 public: 00219 QgsSingleCategoryDiagramRenderer(); 00220 ~QgsSingleCategoryDiagramRenderer(); 00221 00222 QString rendererName() const { return "SingleCategory"; } 00223 00224 QList<int> diagramAttributes() const { return mSettings.categoryIndices; } 00225 00226 void setDiagramSettings( const QgsDiagramSettings& s ) { mSettings = s; } 00227 00228 QList<QgsDiagramSettings> diagramSettings() const; 00229 00230 void readXML( const QDomElement& elem, const QgsVectorLayer* layer ); 00231 void writeXML( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const; 00232 00233 protected: 00234 bool diagramSettings( const QgsAttributes&, const QgsRenderContext& c, QgsDiagramSettings& s ); 00235 00236 QSizeF diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c ); 00237 00238 private: 00239 QgsDiagramSettings mSettings; 00240 }; 00241 00242 class CORE_EXPORT QgsLinearlyInterpolatedDiagramRenderer : public QgsDiagramRendererV2 00243 { 00244 public: 00245 QgsLinearlyInterpolatedDiagramRenderer(); 00246 ~QgsLinearlyInterpolatedDiagramRenderer(); 00247 00249 QList<QgsDiagramSettings> diagramSettings() const; 00250 00251 void setDiagramSettings( const QgsDiagramSettings& s ) { mSettings = s; } 00252 00253 QList<int> diagramAttributes() const; 00254 00255 QString rendererName() const { return "LinearlyInterpolated"; } 00256 00257 void setLowerValue( double val ) { mInterpolationSettings.lowerValue = val; } 00258 double lowerValue() const { return mInterpolationSettings.lowerValue; } 00259 00260 void setUpperValue( double val ) { mInterpolationSettings.upperValue = val; } 00261 double upperValue() const { return mInterpolationSettings.upperValue; } 00262 00263 void setLowerSize( QSizeF s ) { mInterpolationSettings.lowerSize = s; } 00264 QSizeF lowerSize() const { return mInterpolationSettings.lowerSize; } 00265 00266 void setUpperSize( QSizeF s ) { mInterpolationSettings.upperSize = s; } 00267 QSizeF upperSize() const { return mInterpolationSettings.upperSize; } 00268 00269 int classificationAttribute() const { return mInterpolationSettings.classificationAttribute; } 00270 void setClassificationAttribute( int index ) { mInterpolationSettings.classificationAttribute = index; } 00271 00272 void readXML( const QDomElement& elem, const QgsVectorLayer* layer ); 00273 void writeXML( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const; 00274 00275 protected: 00276 bool diagramSettings( const QgsAttributes&, const QgsRenderContext& c, QgsDiagramSettings& s ); 00277 00278 QSizeF diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c ); 00279 00280 private: 00281 QgsDiagramSettings mSettings; 00282 QgsDiagramInterpolationSettings mInterpolationSettings; 00283 }; 00284 00285 #endif // QGSDIAGRAMRENDERERV2_H