Skip to content
Permalink
Browse files

Revived labeling and diagrams for vector layers

  • Loading branch information
wonder-sk committed Nov 20, 2013
1 parent fe0596f commit 5b6393f22f09dbf8c3046bdf2907b8ba6ce1a1d6
@@ -33,6 +33,9 @@ class CORE_EXPORT QgsDiagram
{
public:
virtual ~QgsDiagram() {}
/** Returns an instance that is equivalent to this one
* @note added in 2.1 */
virtual QgsDiagram* clone() const = 0;
/**Draws the diagram at the given position (in pixel coordinates)*/
virtual void renderDiagram( const QgsAttributes& att, QgsRenderContext& c, const QgsDiagramSettings& s, const QPointF& position ) = 0;
virtual QString diagramName() const = 0;
@@ -29,6 +29,11 @@ QgsHistogramDiagram::~QgsHistogramDiagram()
{
}

QgsDiagram* QgsHistogramDiagram::clone() const
{
return new QgsHistogramDiagram( *this );
}

QSizeF QgsHistogramDiagram::diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is )
{
Q_UNUSED( c );
@@ -37,6 +37,8 @@ class CORE_EXPORT QgsHistogramDiagram: public QgsDiagram
QgsHistogramDiagram();
~QgsHistogramDiagram();

virtual QgsDiagram* clone() const;

void renderDiagram( const QgsAttributes& att, QgsRenderContext& c, const QgsDiagramSettings& s, const QPointF& position );
QSizeF diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s );
QSizeF diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is );
@@ -29,6 +29,11 @@ QgsPieDiagram::~QgsPieDiagram()
{
}

QgsDiagram* QgsPieDiagram::clone() const
{
return new QgsPieDiagram( *this );
}

QSizeF QgsPieDiagram::diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is )
{
Q_UNUSED( c );
@@ -35,6 +35,8 @@ class CORE_EXPORT QgsPieDiagram: public QgsDiagram
QgsPieDiagram();
~QgsPieDiagram();

virtual QgsDiagram* clone() const;

void renderDiagram( const QgsAttributes& att, QgsRenderContext& c, const QgsDiagramSettings& s, const QPointF& position );
QSizeF diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s );
QSizeF diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is );
@@ -30,6 +30,11 @@ QgsTextDiagram::~QgsTextDiagram()
{
}

QgsDiagram* QgsTextDiagram::clone() const
{
return new QgsTextDiagram( *this );
}

QSizeF QgsTextDiagram::diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is )
{
Q_UNUSED( c );
@@ -48,6 +48,9 @@ class CORE_EXPORT QgsTextDiagram: public QgsDiagram

QgsTextDiagram();
~QgsTextDiagram();

virtual QgsDiagram* clone() const;

void renderDiagram( const QgsAttributes& att, QgsRenderContext& c, const QgsDiagramSettings& s, const QPointF& position );
QSizeF diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s );
QSizeF diagramSize( const QgsAttributes& attributes, const QgsRenderContext& c, const QgsDiagramSettings& s, const QgsDiagramInterpolationSettings& is );
@@ -22,6 +22,11 @@
#include <QPainter>


QgsDiagramLayerSettings::~QgsDiagramLayerSettings()
{
delete renderer;
}

void QgsDiagramLayerSettings::readXML( const QDomElement& elem, const QgsVectorLayer* layer )
{
Q_UNUSED( layer )
@@ -260,6 +265,11 @@ void QgsDiagramRendererV2::setDiagram( QgsDiagram* d )
mDiagram = d;
}

QgsDiagramRendererV2::QgsDiagramRendererV2(const QgsDiagramRendererV2& other)
: mDiagram( other.mDiagram ? other.mDiagram->clone() : 0 )
{
}

void QgsDiagramRendererV2::renderDiagram( const QgsAttributes& att, QgsRenderContext& c, const QPointF& pos )
{
if ( !mDiagram )
@@ -360,6 +370,11 @@ QgsSingleCategoryDiagramRenderer::~QgsSingleCategoryDiagramRenderer()
{
}

QgsDiagramRendererV2* QgsSingleCategoryDiagramRenderer::clone() const
{
return new QgsSingleCategoryDiagramRenderer( *this );
}

bool QgsSingleCategoryDiagramRenderer::diagramSettings( const QgsAttributes&, const QgsRenderContext& c, QgsDiagramSettings& s )
{
Q_UNUSED( c );
@@ -408,6 +423,11 @@ QgsLinearlyInterpolatedDiagramRenderer::~QgsLinearlyInterpolatedDiagramRenderer(
{
}

QgsDiagramRendererV2 *QgsLinearlyInterpolatedDiagramRenderer::clone() const
{
return new QgsLinearlyInterpolatedDiagramRenderer( *this );
}

QList<QgsDiagramSettings> QgsLinearlyInterpolatedDiagramRenderer::diagramSettings() const
{
QList<QgsDiagramSettings> settingsList;
@@ -73,13 +73,15 @@ class CORE_EXPORT QgsDiagramLayerSettings
{
}

~QgsDiagramLayerSettings();

//pal placement properties
Placement placement;
LinePlacementFlags placementFlags;
int priority; // 0 = low, 10 = high
bool obstacle; // whether it's an obstacle
double dist; // distance from the feature (in mm)
QgsDiagramRendererV2* renderer;
QgsDiagramRendererV2* renderer; // if any renderer is assigned, it is owned by this class

//assigned when layer gets prepared
pal::Layer* palLayer;
@@ -167,6 +169,10 @@ class CORE_EXPORT QgsDiagramRendererV2
QgsDiagramRendererV2();
virtual ~QgsDiagramRendererV2();

/** Returns new instance that is equivalent to this one
* @note added in 2.1 */
virtual QgsDiagramRendererV2* clone() const = 0;

/**Returns size of the diagram for feature f in map units. Returns an invalid QSizeF in case of error*/
virtual QSizeF sizeMapUnits( const QgsAttributes& attributes, const QgsRenderContext& c );

@@ -187,6 +193,7 @@ class CORE_EXPORT QgsDiagramRendererV2
virtual void writeXML( QDomElement& layerElem, QDomDocument& doc, const QgsVectorLayer* layer ) const = 0;

protected:
QgsDiagramRendererV2( const QgsDiagramRendererV2& other );

/**Returns diagram settings for a feature (or false if the diagram for the feature is not to be rendered). Used internally within renderDiagram()
* @param att attribute map
@@ -219,6 +226,8 @@ class CORE_EXPORT QgsSingleCategoryDiagramRenderer : public QgsDiagramRendererV2
QgsSingleCategoryDiagramRenderer();
~QgsSingleCategoryDiagramRenderer();

QgsDiagramRendererV2* clone() const;

QString rendererName() const { return "SingleCategory"; }

QList<int> diagramAttributes() const { return mSettings.categoryIndices; }
@@ -245,6 +254,8 @@ class CORE_EXPORT QgsLinearlyInterpolatedDiagramRenderer : public QgsDiagramRend
QgsLinearlyInterpolatedDiagramRenderer();
~QgsLinearlyInterpolatedDiagramRenderer();

QgsDiagramRendererV2* clone() const;

/**Returns list with all diagram settings in the renderer*/
QList<QgsDiagramSettings> diagramSettings() const;

@@ -122,7 +122,7 @@ QgsFeatureRequest& QgsFeatureRequest::setSubsetOfAttributes( const QStringList&
foreach ( const QString& attrName, attrNames )
{
int attrNum = fields.fieldNameIndex( attrName );
if ( attrNum != -1 )
if ( attrNum != -1 && !mAttrs.contains( attrNum ) )
mAttrs.append( attrNum );
}

@@ -84,21 +84,21 @@ class CORE_EXPORT QgsLabelingEngineInterface
virtual void clearActiveLayers() = 0;
//! clears data defined objects from PAL layer settings for a registered layer
//! @note: this method was added in version 1.9
virtual void clearActiveLayer( QgsVectorLayer* layer ) = 0;
virtual void clearActiveLayer( const QString& layerID ) = 0;
//! called when starting rendering of a layer
//! @note: this method was added in version 1.6
virtual int prepareLayer( QgsVectorLayer* layer, QSet<int>& attrIndices, QgsRenderContext& ctx ) = 0;
virtual int prepareLayer( QgsVectorLayer* layer, QStringList& attrNames, QgsRenderContext& ctx ) = 0;
//! returns PAL layer settings for a registered layer
//! @note: this method was added in version 1.9
virtual QgsPalLayerSettings& layer( const QString& layerName ) = 0;
//! adds a diagram layer to the labeling engine
virtual int addDiagramLayer( QgsVectorLayer* layer, QgsDiagramLayerSettings* s )
{ Q_UNUSED( layer ); Q_UNUSED( s ); return 0; }
//! called for every feature
virtual void registerFeature( QgsVectorLayer* layer, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() ) = 0;
virtual void registerFeature( const QString& layerID, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() ) = 0;
//! called for every diagram feature
virtual void registerDiagramFeature( QgsVectorLayer* layer, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() )
{ Q_UNUSED( layer ); Q_UNUSED( feat ); Q_UNUSED( context ); }
virtual void registerDiagramFeature( const QString& layerID, QgsFeature& feat, const QgsRenderContext& context = QgsRenderContext() )
{ Q_UNUSED( layerID ); Q_UNUSED( feat ); Q_UNUSED( context ); }
//! called when the map is drawn and labels should be placed
virtual void drawLabeling( QgsRenderContext& context ) = 0;
//! called when we're done with rendering

0 comments on commit 5b6393f

Please sign in to comment.
You can’t perform that action at this time.