~ubuntu-branches/ubuntu/trusty/qgis/trusty

« back to all changes in this revision

Viewing changes to src/core/renderer/qgsrenderer.h

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                         qgsrenderer.h  -  description
 
3
                             -------------------
 
4
    begin                : Sat Jan 4 2003
 
5
    copyright            : (C) 2003 by Gary E.Sherman
 
6
    email                : sherman at mrcc.com
 
7
 ***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
 *                                                                         *
 
11
 *   This program is free software; you can redistribute it and/or modify  *
 
12
 *   it under the terms of the GNU General Public License as published by  *
 
13
 *   the Free Software Foundation; either version 2 of the License, or     *
 
14
 *   (at your option) any later version.                                   *
 
15
 *                                                                         *
 
16
 ***************************************************************************/
 
17
/* $Id$ */
 
18
#ifndef QGSRENDERER_H
 
19
#define QGSRENDERER_H
 
20
 
 
21
class QgsFeature;
 
22
class QgsVectorLayer;
 
23
class QPainter;
 
24
class QImage;
 
25
class QDomNode;
 
26
class QDomDocument;
 
27
class QColor;
 
28
 
 
29
#include "qgis.h"
 
30
#include "qgsrendercontext.h"
 
31
#include <QList>
 
32
 
 
33
class QgsSymbol;
 
34
class QBrush;
 
35
 
 
36
typedef QList<int> QgsAttributeList;
 
37
 
 
38
 
 
39
/**Abstract base class for renderers. A renderer holds all the information necessary to draw the contents of a vector layer to a map canvas. The vector layer then passes each feature to paint to the renderer*/
 
40
class CORE_EXPORT QgsRenderer
 
41
{
 
42
  public:
 
43
    /** Default ctor sets up selection color from project properties */
 
44
    QgsRenderer();
 
45
    /** Virtual destructor because we have virtual methods... */
 
46
    virtual ~QgsRenderer();
 
47
    /** Determines if a feature will be rendered or not
 
48
    @param f a pointer to the feature to determine if rendering will happen*/
 
49
    virtual bool willRenderFeature( QgsFeature *f )
 
50
    {
 
51
      //prevent unused var warnings
 
52
      if ( !f )
 
53
      {
 
54
        return true;
 
55
      }
 
56
      return true;
 
57
    }
 
58
    /**A vector layer passes features to a renderer object to change the brush and pen of the qpainter
 
59
     @param p the painter storing brush and pen
 
60
     @param f a pointer to the feature to be rendered
 
61
     @param pic pointer to an image (used for point symbols)
 
62
     @param scalefactor pointer to the scale factor for the marker image
 
63
     @note deprecated */
 
64
    void renderFeature( QPainter* p, QgsFeature& f, QImage* img, bool selected, double widthScale = 1.0, double rasterScaleFactor = 1.0 )
 
65
    {
 
66
      QgsRenderContext r;
 
67
      r.setPainter( p );
 
68
      r.setScaleFactor( widthScale );
 
69
      r.setRasterScaleFactor( rasterScaleFactor );
 
70
      renderFeature( r, f, img, selected );
 
71
    }
 
72
 
 
73
    /**A vector layer passes features to a renderer object to change the brush and pen of the qpainter
 
74
      @note added in 1.2 */
 
75
    void renderFeature( QgsRenderContext &renderContext, QgsFeature& f, QImage* pic, bool selected )
 
76
    {
 
77
      renderFeature( renderContext, f, pic, selected, 1.0 );
 
78
    }
 
79
 
 
80
    virtual void renderFeature( QgsRenderContext &renderContext, QgsFeature& f, QImage* pic, bool selected, double opacity ) = 0;
 
81
 
 
82
    /**Reads the renderer configuration from an XML file
 
83
     @param rnode the Dom node to read
 
84
     @param vl the vector layer which will be associated with the renderer
 
85
    @return 0 in case of success, 1 if vector layer has no renderer, 2 if classification field not found*/
 
86
    virtual int readXML( const QDomNode& rnode, QgsVectorLayer& vl ) = 0;
 
87
    /**Writes the contents of the renderer to a configuration file*/
 
88
    // virtual void writeXML(std::ostream& xml)=0;
 
89
    /**Writes the contents of the renderer to a configuration file
 
90
     @ return true in case of success*/
 
91
    virtual bool writeXML( QDomNode & layer_node, QDomDocument & document, const QgsVectorLayer& vl ) const = 0;
 
92
    /** Returns true, if attribute values are used by the renderer and false otherwise*/
 
93
    virtual bool needsAttributes() const = 0;
 
94
    /**Returns a list with indexes of classification attributes*/
 
95
    virtual QgsAttributeList classificationAttributes() const = 0;
 
96
    /**Returns the renderers name*/
 
97
    virtual QString name() const = 0;
 
98
    /**Return symbology items*/
 
99
    virtual const QList<QgsSymbol*> symbols() const = 0;
 
100
    /**Returns a copy of the renderer (a deep copy on the heap)*/
 
101
    virtual QgsRenderer* clone() const = 0;
 
102
    /** Change selection color */
 
103
    static void setSelectionColor( QColor color );
 
104
    /** Get selection color. Added in QGIS v1.4 */
 
105
    static QColor selectionColor();
 
106
    /**Returns true if this renderer returns a pixmap in the render method (e.g. for point data or diagrams)*/
 
107
    virtual bool containsPixmap() const;
 
108
    /**Returns true if this renderer uses its own transparency settings, e.g. differentiated by classification.
 
109
     This is a hint for QgsVectorLayer to not use the transparency setting on layer level in this cases*/
 
110
    virtual bool usesTransparency() const {return false;}
 
111
 
 
112
    /**Scales a brush to a given raster scale factor (e.g. for printing)*/
 
113
    static void scaleBrush( QBrush& b, double rasterScaleFactor );
 
114
 
 
115
  protected:
 
116
    /**Color to draw selected features - static so we can change it in proj props and automatically
 
117
     all renderers are updated*/
 
118
    static QColor mSelectionColor;
 
119
 
 
120
    /**Layer type*/
 
121
    QGis::GeometryType mGeometryType;
 
122
};
 
123
 
 
124
#endif // QGSRENDERER_H