QGIS API Documentation  master-6164ace
src/core/symbology-ng/qgspointdisplacementrenderer.h
Go to the documentation of this file.
00001 /***************************************************************************
00002                               qgspointdisplacementrenderer.cpp
00003                               --------------------------------
00004   begin                : January 26, 2010
00005   copyright            : (C) 2010 by Marco Hugentobler
00006   email                : marco at hugis dot net
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef QGSPOINTDISPLACEMENTRENDERER_H
00019 #define QGSPOINTDISPLACEMENTRENDERER_H
00020 
00021 #include "qgsfeature.h"
00022 #include "qgssymbolv2.h"
00023 #include "qgspoint.h"
00024 #include "qgsrendererv2.h"
00025 #include <QFont>
00026 #include <QSet>
00027 
00028 class QgsVectorLayer;
00029 
00031 class CORE_EXPORT QgsPointDisplacementRenderer: public QgsFeatureRendererV2
00032 {
00033   public:
00034     QgsPointDisplacementRenderer( const QString& labelAttributeName = "" );
00035     ~QgsPointDisplacementRenderer();
00036 
00037     QgsFeatureRendererV2* clone();
00038 
00039     virtual void toSld( QDomDocument& doc, QDomElement &element ) const;
00040 
00042     bool renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false );
00043 
00044     QgsSymbolV2* symbolForFeature( QgsFeature& feature );
00045 
00046     void startRender( QgsRenderContext& context, const QgsVectorLayer *vlayer );
00047 
00048     void stopRender( QgsRenderContext& context );
00049 
00050     QList<QString> usedAttributes();
00051     QgsSymbolV2List symbols();
00052 
00054     static QgsFeatureRendererV2* create( QDomElement& symbologyElem );
00055     QDomElement save( QDomDocument& doc );
00056 
00057     QgsLegendSymbologyList legendSymbologyItems( QSize iconSize );
00058 
00060     QgsLegendSymbolList legendSymbolItems();
00061 
00062     void setLabelAttributeName( const QString& name ) { mLabelAttributeName = name; }
00063     QString labelAttributeName() const { return mLabelAttributeName; }
00064 
00066     void setEmbeddedRenderer( QgsFeatureRendererV2* r );
00067     QgsFeatureRendererV2* embeddedRenderer() { return mRenderer;}
00068 
00070     void setDisplacementGroups( const QList<QMap<QgsFeatureId, QgsFeature> >& list );
00071 
00072     void setLabelFont( const QFont& f ) { mLabelFont = f; }
00073     QFont labelFont() const { return mLabelFont;}
00074 
00075     void setCircleWidth( double w ) { mCircleWidth = w; }
00076     double circleWidth() const { return mCircleWidth; }
00077 
00078     void setCircleColor( const QColor& c ) { mCircleColor = c; }
00079     QColor circleColor() const { return mCircleColor; }
00080 
00081     void setLabelColor( const QColor& c ) { mLabelColor = c;}
00082     QColor labelColor() const { return mLabelColor; }
00083 
00084     void setCircleRadiusAddition( double d ) { mCircleRadiusAddition = d; }
00085     double circleRadiusAddition() const { return mCircleRadiusAddition; }
00086 
00087     void setMaxLabelScaleDenominator( double d ) { mMaxLabelScaleDenominator = d; }
00088     double maxLabelScaleDenominator() const { return mMaxLabelScaleDenominator; }
00089 
00091     QgsMarkerSymbolV2* centerSymbol() { return mCenterSymbol;}
00093     void setCenterSymbol( QgsMarkerSymbolV2* symbol );
00094 
00095     void setTolerance( double t ) { mTolerance = t; }
00096     double tolerance() const { return mTolerance; }
00097 
00098   private:
00099 
00101     QgsFeatureRendererV2* mRenderer;
00102 
00104     QString mLabelAttributeName;
00106     int mLabelIndex;
00107 
00109     QgsMarkerSymbolV2* mCenterSymbol;
00110 
00112     double mTolerance;
00113 
00115     QFont mLabelFont;
00116     QColor mLabelColor;
00118     double mCircleWidth;
00120     QColor mCircleColor;
00122     double mCircleRadiusAddition;
00124     bool mDrawLabels;
00126     double mMaxLabelScaleDenominator;
00127 
00129     QList<QMap<QgsFeatureId, QgsFeature> > mDisplacementGroups;
00131     QSet<QgsFeatureId> mDisplacementIds;
00132 
00134     void createDisplacementGroups( QgsVectorLayer *vlayer, const QgsRectangle& viewExtent );
00136     QgsRectangle searchRect( const QgsPoint& p ) const;
00138     void printInfoDisplacementGroups();
00139 
00141     QString getLabel( const QgsFeature& f );
00142 
00143     //rendering methods
00144     void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context, const QList<QgsMarkerSymbolV2*>& symbols,
00145                       const QStringList& labels );
00146 
00147     //helper functions
00148     void calculateSymbolAndLabelPositions( const QPointF& centerPoint, int nPosition, double radius, double symbolDiagonal, QList<QPointF>& symbolPositions, QList<QPointF>& labelShifts ) const;
00149     void drawCircle( double radiusPainterUnits, QgsSymbolV2RenderContext& context, const QPointF& centerPoint, int nSymbols );
00150     void drawSymbols( QgsFeature& f, QgsRenderContext& context, const QList<QgsMarkerSymbolV2*>& symbolList, const QList<QPointF>& symbolPositions, bool selected = false );
00151     void drawLabels( const QPointF& centerPoint, QgsSymbolV2RenderContext& context, const QList<QPointF>& labelShifts, const QStringList& labelList );
00153     QgsSymbolV2* firstSymbolForFeature( QgsFeatureRendererV2* r, QgsFeature& f );
00154 };
00155 
00156 #endif // QGSPOINTDISPLACEMENTRENDERER_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines