Skip to content
Permalink
Browse files

Added python bindings for symbol levels.

git-svn-id: http://svn.osgeo.org/qgis/branches/symbology-ng-branch@11060 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Jul 13, 2009
1 parent 74015a6 commit 0668a8100fa47ae3d8d604e95cbba64c0e7d8bf6
Showing with 116 additions and 8 deletions.
  1. +80 −0 python/core/conversions.sip
  2. +3 −0 python/core/qgsvectorlayer.sip
  3. +33 −8 python/core/symbology-ng-core.sip
@@ -3,6 +3,7 @@ This file contains code for conversion between various (often nested) mapped typ
which are not wrapped by PyQt:
- QVector< QVector<TYPE> >
- QVector< QVector< QVector<TYPE> > >
- QList< QList<TYPE> >
- QSet<int>
- QSet<TYPE>
- QMap<int, QMap<int, TYPE> >
@@ -173,6 +174,85 @@ template <TYPE>
};



template <TYPE>
%MappedType QList< QList<TYPE> >
{
%TypeHeaderCode
#include <QList>
%End

%ConvertFromTypeCode
// Create the list.
PyObject *l;

if ((l = PyList_New(sipCpp->size())) == NULL)
return NULL;

const sipMappedType* qlist_type = sipFindMappedType("QList<TYPE>");

// Set the list elements.
for (int i = 0; i < sipCpp->size(); ++i)
{
QList<TYPE>* t = new QList<TYPE>(sipCpp->at(i));
PyObject *tobj;

if ((tobj = sipConvertFromMappedType(t, qlist_type, sipTransferObj)) == NULL)
{
Py_DECREF(l);
delete t;
return NULL;
}
PyList_SET_ITEM(l, i, tobj);
}

return l;
%End

%ConvertToTypeCode
const sipMappedType* qlist_type = sipFindMappedType("QList<TYPE>");

// Check the type if that is all that is required.
if (sipIsErr == NULL)
{
if (!PyList_Check(sipPy))
return 0;

for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
if (!sipCanConvertToMappedType(PyList_GET_ITEM(sipPy, i), qlist_type, SIP_NOT_NONE))
return 0;

return 1;
}


QList< QList<TYPE> > *ql = new QList< QList<TYPE> >;

for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
{
int state;
//TYPE *t = reinterpret_cast<TYPE *>(sipConvertToInstance(PyList_GET_ITEM(sipPy, i), sipClass_TYPE, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
QList<TYPE> * t = reinterpret_cast< QList<TYPE> * >(sipConvertToMappedType(PyList_GET_ITEM(sipPy, i), qlist_type, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));

if (*sipIsErr)
{
sipReleaseInstance(t, sipClass_TYPE, state);
delete ql;
return 0;
}
ql->append(*t);
sipReleaseInstance(t, sipClass_TYPE, state);
}

*sipCppPtr = ql;
return sipGetState(sipTransferObj);
%End

};




%MappedType QSet<int>
{
%TypeHeaderCode
@@ -106,6 +106,9 @@ public:
/** set whether to use renderer V2 for drawing. Added in QGIS 1.2 */
void setUsingRendererV2(bool usingRendererV2);

void drawRendererV2( QgsRenderContext& rendererContext, bool labeling );
void drawRendererV2Levels( QgsRenderContext& rendererContext, bool labeling );

/** Returns point, line or polygon */
QGis::GeometryType geometryType() const;

@@ -1,6 +1,28 @@

///////////////


class QgsSymbolV2LevelItem
{
%TypeHeaderCode
#include <qgsrendererv2.h>
%End

public:
QgsSymbolV2LevelItem( QgsSymbolV2* symbol, int layer );
QgsSymbolV2* symbol();
int layer();
};

// every level has list of items: symbol + symbol layer num
typedef QList< QgsSymbolV2LevelItem > QgsSymbolV2Level;

// this is a list of levels
typedef QList< QgsSymbolV2Level > QgsSymbolV2LevelOrder;

///////////////


class QgsFeatureRendererV2
{
%TypeHeaderCode
@@ -32,8 +54,11 @@ public:
virtual QString dump();


void renderFeature(QgsFeature& feature, QgsRenderContext& context);

void renderFeature(QgsFeature& feature, QgsRenderContext& context, int layer = -1);

QgsSymbolV2LevelOrder& symbolLevels();
void setSymbolLevels(const QgsSymbolV2LevelOrder& levelOrder);

protected:
QgsFeatureRendererV2(RendererType type);

@@ -191,7 +216,7 @@ class QgsMarkerSymbolLayerV2 : QgsSymbolLayerV2
%End

public:
virtual void renderPoint(const QPointF& point, QgsRenderContext& context) = 0;
virtual void renderPoint(const QPointF& point, QgsRenderContext& context) = 0;

void drawPreviewIcon(QPainter* painter, QSize size);

@@ -213,7 +238,7 @@ class QgsLineSymbolLayerV2 : QgsSymbolLayerV2
%End

public:
virtual void renderPolyline(const QPolygonF& points, QgsRenderContext& context) = 0;
virtual void renderPolyline(const QPolygonF& points, QgsRenderContext& context) = 0;

void setWidth(int width);
int width() const;
@@ -232,7 +257,7 @@ class QgsFillSymbolLayerV2 : QgsSymbolLayerV2
%End

public:
virtual void renderPolygon(const QPolygonF& points, QList<QPolygonF>* rings, QgsRenderContext& context) = 0;
virtual void renderPolygon(const QPolygonF& points, QList<QPolygonF>* rings, QgsRenderContext& context) = 0;

void drawPreviewIcon(QPainter* painter, QSize size);

@@ -334,7 +359,7 @@ public:
void setSize(double size);
double size();

void renderPoint(const QPointF& point, QgsRenderContext& context);
void renderPoint(const QPointF& point, QgsRenderContext& context, int layer = -1);

virtual QgsSymbolV2* clone() const /Factory/;
};
@@ -353,7 +378,7 @@ public:
void setWidth(int width);
int width();

void renderPolyline(const QPolygonF& points, QgsRenderContext& context);
void renderPolyline(const QPolygonF& points, QgsRenderContext& context, int layer = -1);

virtual QgsSymbolV2* clone() const /Factory/;
};
@@ -369,7 +394,7 @@ class QgsFillSymbolV2 : QgsSymbolV2
public:
QgsFillSymbolV2(QgsSymbolLayerV2List layers /Transfer/ = QgsSymbolLayerV2List());

void renderPolygon(const QPolygonF& points, QList<QPolygonF>* rings, QgsRenderContext& context);
void renderPolygon(const QPolygonF& points, QList<QPolygonF>* rings, QgsRenderContext& context, int layer = -1);

virtual QgsSymbolV2* clone() const /Factory/;
};

0 comments on commit 0668a81

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