Skip to content

Commit

Permalink
Revived labeling and diagrams for vector layers
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Nov 20, 2013
1 parent fe0596f commit 5b6393f
Show file tree
Hide file tree
Showing 16 changed files with 149 additions and 111 deletions.
3 changes: 3 additions & 0 deletions src/core/diagram/qgsdiagram.h
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/core/diagram/qgshistogramdiagram.cpp
Expand Up @@ -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 );
Expand Down
2 changes: 2 additions & 0 deletions src/core/diagram/qgshistogramdiagram.h
Expand Up @@ -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 );
Expand Down
5 changes: 5 additions & 0 deletions src/core/diagram/qgspiediagram.cpp
Expand Up @@ -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 );
Expand Down
2 changes: 2 additions & 0 deletions src/core/diagram/qgspiediagram.h
Expand Up @@ -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 );
Expand Down
5 changes: 5 additions & 0 deletions src/core/diagram/qgstextdiagram.cpp
Expand Up @@ -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 );
Expand Down
3 changes: 3 additions & 0 deletions src/core/diagram/qgstextdiagram.h
Expand Up @@ -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 );
Expand Down
20 changes: 20 additions & 0 deletions src/core/qgsdiagramrendererv2.cpp
Expand Up @@ -22,6 +22,11 @@
#include <QPainter>


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

void QgsDiagramLayerSettings::readXML( const QDomElement& elem, const QgsVectorLayer* layer )
{
Q_UNUSED( layer )
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -408,6 +423,11 @@ QgsLinearlyInterpolatedDiagramRenderer::~QgsLinearlyInterpolatedDiagramRenderer(
{
}

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

QList<QgsDiagramSettings> QgsLinearlyInterpolatedDiagramRenderer::diagramSettings() const
{
QList<QgsDiagramSettings> settingsList;
Expand Down
13 changes: 12 additions & 1 deletion src/core/qgsdiagramrendererv2.h
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );

Expand All @@ -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
Expand Down Expand Up @@ -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; }
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsfeaturerequest.cpp
Expand Up @@ -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 );
}

Expand Down
10 changes: 5 additions & 5 deletions src/core/qgsmaprenderer.h
Expand Up @@ -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
Expand Down

0 comments on commit 5b6393f

Please sign in to comment.