Skip to content

Commit

Permalink
Added python bindings for symbol levels.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/branches/symbology-ng-branch@11060 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Jul 13, 2009
1 parent 74015a6 commit 0668a81
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 8 deletions.
80 changes: 80 additions & 0 deletions python/core/conversions.sip
Expand Up @@ -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> >
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -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;

Expand Down
41 changes: 33 additions & 8 deletions python/core/symbology-ng-core.sip
@@ -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
Expand Down Expand Up @@ -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);

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

Expand All @@ -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;
Expand All @@ -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);

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

0 comments on commit 0668a81

Please sign in to comment.