Skip to content

Commit

Permalink
Added python bindings for QgsSymbol and all renderer classes.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@6864 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Apr 2, 2007
1 parent b9fba82 commit 0afae5d
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 2 deletions.
5 changes: 5 additions & 0 deletions python/core/core.sip
Expand Up @@ -11,6 +11,7 @@
%Include qgsapplication.sip
%Include qgscolortable.sip
%Include qgscontexthelp.sip
%Include qgscontinuouscolorrenderer.sip
%Include qgscoordinatetransform.sip
%Include qgsdataprovider.sip
%Include qgsdatasourceuri.sip
Expand All @@ -19,6 +20,7 @@
%Include qgsfield.sip
%Include qgsgeometry.sip
%Include qgsgeometryvertexindex.sip
%Include qgsgraduatedsymbolrenderer.sip
%Include qgslabel.sip
%Include qgslabelattributes.sip
%Include qgslogger.sip
Expand All @@ -39,8 +41,11 @@
%Include qgsrect.sip
%Include qgsrenderer.sip
%Include qgsscalecalculator.sip
%Include qgssinglesymbolrenderer.sip
%Include qgsspatialindex.sip
%Include qgsspatialrefsys.sip
%Include qgssymbol.sip
%Include qgsuniquevaluerenderer.sip
%Include qgsvectordataprovider.sip
%Include qgsvectorlayer.sip

48 changes: 48 additions & 0 deletions python/core/qgscontinuouscolorrenderer.sip
@@ -0,0 +1,48 @@

/**Renderer class which interpolates rgb values linear between the minimum and maximum value of the classification field*/
class QgsContinuousColorRenderer : QgsRenderer
{
%TypeHeaderCode
#include <qgscontinuouscolorrenderer.h>
%End

public:
QgsContinuousColorRenderer(QGis::VectorType type);
QgsContinuousColorRenderer(const QgsContinuousColorRenderer& other);
virtual ~QgsContinuousColorRenderer();
/**Renders the feature using the minimum and maximum value of the classification field*/
void renderFeature(QPainter* p, QgsFeature& f, QImage* img, double* scalefactor, bool selected, double widthScale = 1);
/**Returns the number of the classification field*/
int classificationField() const;
/**Sets the id of the classification field*/
void setClassificationField(int id);
/**Sets the symbol for the minimum value. The symbol has to be created using the new operator and is automatically deleted when inserting a new symbol or when the instance is destroyed*/
void setMinimumSymbol(QgsSymbol* sy);
/**Sets the symbol for the maximum value. The symbol has to be created using the new operator and is automatically deleted when inserting a new symbol or when the instance is destroyed*/
void setMaximumSymbol(QgsSymbol* sy);
/** Sets whether to draw the polygon outline*/
void setDrawPolygonOutline(bool draw);
/**Returns the symbol for the minimum value*/
const QgsSymbol* minimumSymbol() const;
/**Returns the symbol for the maximum value*/
const QgsSymbol* maximumSymbol() const;
/** whether to draw a polygon outline*/
bool drawPolygonOutline() const;
/**Reads the renderer configuration from an XML file
@param rnode the DOM node to read
@param vl the vector layer which will be associated with the renderer*/
virtual void readXML(const QDomNode& rnode, QgsVectorLayer& vl);
/**Writes the contents of the renderer to a configuration file
@ return true in case of success*/
virtual bool writeXML( QDomNode & layer_node, QDomDocument & document ) const;
/** Returns true*/
bool needsAttributes() const;
/**Returns a list with the index of the classification attribute*/
QList<int> classificationAttributes() const;
/**Returns the renderers name*/
QString name() const;
/**Return symbology items*/
const QList<QgsSymbol*> symbols() const;
QgsRenderer* clone() const;
};

48 changes: 48 additions & 0 deletions python/core/qgsgraduatedsymbolrenderer.sip
@@ -0,0 +1,48 @@
/**This class contains the information for graduate symbol rendering*/
class QgsGraduatedSymbolRenderer : QgsRenderer
{
%TypeHeaderCode
#include <qgsgraduatedsymbolrenderer.h>
%End

public:
QgsGraduatedSymbolRenderer(QGis::VectorType type);
QgsGraduatedSymbolRenderer(const QgsGraduatedSymbolRenderer& other);
virtual ~QgsGraduatedSymbolRenderer();
/**Adds a new item
\param sy a pointer to the QgsSymbol to be inserted. It has to be created using the new operator and is automatically destroyed when 'removeItems' is called or when this object is destroyed*/
void addSymbol(QgsSymbol* sy);
/**Returns the number of the classification field*/
int classificationField() const;
/**Removes all symbols*/
void removeSymbols();
/** Determines if a feature will be rendered or not
@param f a pointer to the feature to determine if rendering will happen*/
bool willRenderFeature(QgsFeature *f);
/**Renders an OGRFeature
\param p a painter (usually the one from the current map canvas)
\param f a pointer to a feature to render
\param t the transform object containing the information how to transform the map coordinates to screen coordinates*/
void renderFeature(QPainter* p, QgsFeature& f, QImage* img, double* scalefactor, bool selected, double widthScale = 1);
/**Sets the number of the classicifation field
\param field the number of the field to classify*/
void setClassificationField(int field);
/**Reads the renderer configuration from an XML file
@param rnode the DOM node to read
@param vl the vector layer which will be associated with the renderer*/
virtual void readXML(const QDomNode& rnode, QgsVectorLayer& vl);
/**Writes the contents of the renderer to a configuration file
@ return true in case of success*/
virtual bool writeXML( QDomNode & layer_node, QDomDocument & document ) const;
/** Returns true*/
bool needsAttributes() const;
/**Returns a list with the index to the classification field*/
QList<int> classificationAttributes() const;
/**Returns the renderers name*/
QString name() const;
/**Returns the symbols of the items*/
const QList<QgsSymbol*> symbols() const;
/**Returns a copy of the renderer (a deep copy on the heap)*/
QgsRenderer* clone() const;
};

3 changes: 1 addition & 2 deletions python/core/qgsrenderer.sip
Expand Up @@ -31,8 +31,7 @@ class QgsRenderer /Abstract/
/**Returns the renderers name*/
virtual QString name() const=0;
/**Return symbology items*/
// TODO: wrap
//virtual const std::list<QgsSymbol*> symbols() const=0;
virtual const QList<QgsSymbol*> symbols() const=0;
/**Returns a copy of the renderer (a deep copy on the heap)*/
virtual QgsRenderer* clone() const=0;
/** Change selection color */
Expand Down
38 changes: 38 additions & 0 deletions python/core/qgssinglesymbolrenderer.sip
@@ -0,0 +1,38 @@
/**Render class to display all the features with a single QgsSymbol*/
class QgsSingleSymbolRenderer : QgsRenderer
{
%TypeHeaderCode
#include <qgssinglesymbolrenderer.h>
%End

public:
QgsSingleSymbolRenderer(QGis::VectorType type);
QgsSingleSymbolRenderer(const QgsSingleSymbolRenderer& other);
virtual ~QgsSingleSymbolRenderer();
/**Replaces the current mSymbol by sy*/
void addSymbol(QgsSymbol* sy);
/*Returns a pointer to mSymbol*/
const QgsSymbol* symbol() const;
/**Renders an OGRFeature*/
void renderFeature(QPainter* p, QgsFeature& f, QImage* img, double* scalefactor, bool selected, double widthScale = 1);
/**Reads the renderer configuration from an XML file
@param rnode the DOM node to read
@param vl the vector layer which will be associated with the renderer*/
virtual void readXML(const QDomNode& rnode, QgsVectorLayer& vl);
/**Writes the contents of the renderer to a configuration file*/
/*virtual void writeXML(std::ostream& xml);*/
/**Writes the contents of the renderer to a configuration file
@ return true in case of success*/
virtual bool writeXML( QDomNode & layer_node, QDomDocument & document ) const;
/**Returns false, no attributes neede for single symbol*/
bool needsAttributes() const;
/**Returns an empty list, since no classification attributes are used*/
QList<int> classificationAttributes() const;
/**Returns the renderers name*/
virtual QString name() const;
/**Returns a list containing mSymbol*/
const QList<QgsSymbol*> symbols() const;
/**Returns a deep copy of this renderer*/
QgsRenderer* clone() const;
};

82 changes: 82 additions & 0 deletions python/core/qgssymbol.sip
@@ -0,0 +1,82 @@

class QgsSymbol
{
%TypeHeaderCode
#include <qgssymbol.h>
%End

public:
/**Constructor*/
QgsSymbol(QGis::VectorType t, QString lvalue="", QString uvalue="", QString label="");
/**Constructor*/
QgsSymbol(QGis::VectorType t, QString lvalue, QString uvalue, QString label, QColor c);
QgsSymbol(const QgsSymbol&);
/**old constructors*/
QgsSymbol();
QgsSymbol(QColor c);
/**Sets the brush*/
virtual void setBrush(QBrush b);
/**Gets a reference to m_brush, Don't use the brush to change color/style */
virtual const QBrush& brush() const;
/**Set the color*/
virtual void setColor(QColor c);
/**Get the current color*/
virtual QColor color() const;
/**Get the fill color*/
virtual QColor fillColor() const;
/**Sets the fill color*/
virtual void setFillColor(QColor c);
/**Get the line width*/
virtual int lineWidth() const;
/**Sets the line width*/
virtual void setLineWidth(int w);
/**Sets the pen*/
virtual void setPen(QPen p);
/**Gets a reference to m_pen. Don't use the pen to change color/style */
virtual const QPen& pen() const;

/**Set the line (pen) style*/
virtual void setLineStyle(Qt::PenStyle s);
/**Set the fill (brush) style*/
virtual void setFillStyle(Qt::BrushStyle s);
virtual void setLowerValue(QString value);
virtual QString lowerValue() const;
virtual void setUpperValue(QString value);
virtual QString upperValue() const;
virtual void setLabel(QString label);
virtual QString label() const;

/**Set point symbol from name*/
virtual void setNamedPointSymbol(QString name);
/**Get point symbol*/
virtual QString pointSymbolName() const;
/**Set size*/
virtual void setPointSize(int s);
/**Get size*/
virtual int pointSize() const;
//! Destructor
virtual ~QgsSymbol();

//! Get a little icon for the legend
virtual QImage getLineSymbolAsImage();

//! Get a little icon for the legend
virtual QImage getPolygonSymbolAsImage();

/** Get QImage representation of point symbol with current settings
*/
virtual QImage getPointSymbolAsImage( double widthScale = 1,
bool selected = false, QColor selectionColor = Qt::yellow );

/**Writes the contents of the symbol to a configuration file
@ return true in case of success*/
virtual bool writeXML( QDomNode & item, QDomDocument & document ) const;
/**Reads the contents of the symbol from a configuration file
@ return true in case of success*/
virtual bool readXML( QDomNode & symbol );
/**Returns if this symbol is point/ line or polygon*/
QGis::VectorType type() const;

};


40 changes: 40 additions & 0 deletions python/core/qgsuniquevaluerenderer.sip
@@ -0,0 +1,40 @@
class QgsUniqueValueRenderer : QgsRenderer
{
%TypeHeaderCode
#include <qgsuniquevaluerenderer.h>
%End

public:
QgsUniqueValueRenderer(QGis::VectorType type);
QgsUniqueValueRenderer(const QgsUniqueValueRenderer& other);
virtual ~QgsUniqueValueRenderer();
/** Determines if a feature will be rendered or not
@param f a pointer to the feature to determine if rendering will happen*/
bool willRenderFeature(QgsFeature *f);
void renderFeature(QPainter* p, QgsFeature& f,QImage* img, double* scalefactor, bool selected, double widthScale = 1);
/**Reads the renderer configuration from an XML file
@param rnode the DOM node to read
@param vl the vector layer which will be associated with the renderer*/
void readXML(const QDomNode& rnode, QgsVectorLayer& vl);
/**Writes the contents of the renderer to a configuration file
@ return true in case of success*/
virtual bool writeXML( QDomNode & layer_node, QDomDocument & document ) const;
/** Returns true, if attribute values are used by the renderer and false otherwise*/
bool needsAttributes() const;
/**Returns a list with indexes of classification attributes*/
QList<int> classificationAttributes() const;
/**Returns the renderers name*/
QString name() const;
/**Inserts an entry into mEntries. The render items have to be created with the new operator and are automatically destroyed if not needed anymore*/
void insertValue(QString name, QgsSymbol* symbol);
/**Removes all entries from mEntries*/
void clearValues();
/**Sets the Field index used for classification*/
void setClassificationField(int field);
/**Returns the index of the classification field*/
int classificationField();
/**Return symbology items*/
const QList<QgsSymbol*> symbols() const;
QgsRenderer* clone() const;
};

0 comments on commit 0afae5d

Please sign in to comment.