Quantum GIS API Documentation  1.8
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 
00059     QgsLegendSymbolList legendSymbolItems();
00060 
00061     void setLabelAttributeName( const QString& name ) { mLabelAttributeName = name; }
00062     QString labelAttributeName() const { return mLabelAttributeName; }
00063 
00065     void setEmbeddedRenderer( QgsFeatureRendererV2* r );
00066     QgsFeatureRendererV2* embeddedRenderer() { return mRenderer;}
00067 
00068     void setDisplacementGroups( const QList<QMap<QgsFeatureId, QgsFeature> >& list );
00069 
00070     void setLabelFont( const QFont& f ) { mLabelFont = f; }
00071     QFont labelFont() const { return mLabelFont;}
00072 
00073     void setCircleWidth( double w ) { mCircleWidth = w; }
00074     double circleWidth() const { return mCircleWidth; }
00075 
00076     void setCircleColor( const QColor& c ) { mCircleColor = c; }
00077     QColor circleColor() const { return mCircleColor; }
00078 
00079     void setLabelColor( const QColor& c ) { mLabelColor = c;}
00080     QColor labelColor() const { return mLabelColor; }
00081 
00082     void setCircleRadiusAddition( double d ) { mCircleRadiusAddition = d; }
00083     double circleRadiusAddition() const { return mCircleRadiusAddition; }
00084 
00085     void setMaxLabelScaleDenominator( double d ) { mMaxLabelScaleDenominator = d; }
00086     double maxLabelScaleDenominator() const { return mMaxLabelScaleDenominator; }
00087 
00089     QgsMarkerSymbolV2* centerSymbol() { return mCenterSymbol;}
00091     void setCenterSymbol( QgsMarkerSymbolV2* symbol );
00092 
00093     void setTolerance( double t ) { mTolerance = t; }
00094     double tolerance() const { return mTolerance; }
00095 
00096   private:
00097 
00099     QgsFeatureRendererV2* mRenderer;
00100 
00102     QString mLabelAttributeName;
00104     int mLabelIndex;
00105 
00107     QgsMarkerSymbolV2* mCenterSymbol;
00108 
00110     double mTolerance;
00111 
00113     QFont mLabelFont;
00114     QColor mLabelColor;
00116     double mCircleWidth;
00118     QColor mCircleColor;
00120     double mCircleRadiusAddition;
00122     bool mDrawLabels;
00124     double mMaxLabelScaleDenominator;
00125 
00127     QList<QMap<QgsFeatureId, QgsFeature> > mDisplacementGroups;
00129     QSet<QgsFeatureId> mDisplacementIds;
00130 
00132     void createDisplacementGroups( QgsVectorLayer *vlayer, const QgsRectangle& viewExtent );
00134     QgsRectangle searchRect( const QgsPoint& p ) const;
00136     void printInfoDisplacementGroups();
00137 
00139     QString getLabel( const QgsFeature& f );
00140 
00141     //rendering methods
00142     void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context, const QList<QgsMarkerSymbolV2*>& symbols,
00143                       const QStringList& labels );
00144 
00145     //helper functions
00146     void calculateSymbolAndLabelPositions( const QPointF& centerPoint, int nPosition, double radius, double symbolDiagonal, QList<QPointF>& symbolPositions, QList<QPointF>& labelShifts ) const;
00147     void drawCircle( double radiusPainterUnits, QgsSymbolV2RenderContext& context, const QPointF& centerPoint, int nSymbols );
00148     void drawSymbols( QgsFeature& f, QgsRenderContext& context, const QList<QgsMarkerSymbolV2*>& symbolList, const QList<QPointF>& symbolPositions, bool selected = false );
00149     void drawLabels( const QPointF& centerPoint, QgsSymbolV2RenderContext& context, const QList<QPointF>& labelShifts, const QStringList& labelList );
00151     QgsSymbolV2* firstSymbolForFeature( QgsFeatureRendererV2* r, QgsFeature& f );
00152 };
00153 
00154 #endif // QGSPOINTDISPLACEMENTRENDERER_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines