Skip to content

Commit 320daa3

Browse files
author
mhugent
committed
Change in overlay classes such that pal object and geos geometry don't appear in the public interfaces (important for python bindings)
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@10791 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent d444b65 commit 320daa3

13 files changed

+259
-69
lines changed

python/core/conversions.sip

+79
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ which are not wrapped by PyQt:
99
- QMap<QString, QVariant::Type>
1010
- QMap<TYPE1, TYPE2*>
1111
- QMultiMap<double, TYPE2>
12+
- QMap<int, QgsOverlayObject*>*
1213
*/
1314

1415
%ModuleHeaderCode
@@ -21,6 +22,7 @@ typedef int Py_ssize_t;
2122
%End
2223

2324

25+
2426
template <TYPE>
2527
%MappedType QVector< QVector<TYPE> >
2628
{
@@ -737,3 +739,80 @@ template<double, TYPE2>
737739
return sipGetState(sipTransferObj);
738740
%End
739741
};
742+
743+
%MappedType QMap<int, QgsOverlayObject*>
744+
{
745+
%TypeHeaderCode
746+
#include <QMap>
747+
%End
748+
749+
%ConvertFromTypeCode
750+
751+
//convert map to a python dictionary
752+
PyObject *d;
753+
754+
if ((d = PyDict_New()) == NULL)
755+
return NULL;
756+
757+
for (QMap<int, QgsOverlayObject*>::iterator it = sipCpp->begin(); it != sipCpp->end(); ++it)
758+
{
759+
QgsOverlayObject* oobj = new QgsOverlayObject(*it.value());
760+
761+
PyObject* keyobj = PyInt_FromLong(it.key());
762+
PyObject* pyOobj = sipConvertFromInstance(oobj, sipClass_QgsOverlayObject, sipTransferObj);
763+
PyDict_SetItem(d, keyobj, pyOobj);
764+
765+
if(pyOobj == NULL || keyobj == NULL || PyDict_SetItem(d, keyobj, pyOobj) < 0)
766+
{
767+
Py_DECREF(d);
768+
769+
if (pyOobj)
770+
{
771+
Py_DECREF(pyOobj);
772+
}
773+
774+
if (keyobj)
775+
{
776+
Py_DECREF(keyobj);
777+
}
778+
return NULL;
779+
}
780+
Py_DECREF(pyOobj);
781+
Py_DECREF(keyobj);
782+
}
783+
return d;
784+
785+
%End
786+
%ConvertToTypeCode
787+
PyObject *t1obj, *t2obj;
788+
#if PY_VERSION_HEX >= 0x02050000
789+
Py_ssize_t i = 0;
790+
#else
791+
int i = 0;
792+
#endif
793+
794+
QMap<int, QgsOverlayObject*> *qm = new QMap<int, QgsOverlayObject*>;
795+
796+
while (PyDict_Next(sipPy, &i, &t1obj, &t2obj))
797+
{
798+
int state;
799+
int t1 = (int)(PyFloat_AsDouble(t1obj));
800+
QgsOverlayObject* t2 = reinterpret_cast<QgsOverlayObject*>(sipConvertToInstance(t2obj, sipClass_QgsOverlayObject, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
801+
802+
if (*sipIsErr)
803+
{
804+
sipReleaseInstance(t2, sipClass_QgsOverlayObject, state);
805+
delete qm;
806+
return 0;
807+
}
808+
809+
qm->insert(t1, t2);
810+
811+
sipReleaseInstance(t2, sipClass_QgsOverlayObject, state);
812+
}
813+
814+
*sipCppPtr = qm;
815+
816+
return sipGetState(sipTransferObj);
817+
%End
818+
};

python/core/core.sip

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
%Include qgsmaptopixel.sip
4343
%Include qgsmarkercatalogue.sip
4444
%Include qgsmessageoutput.sip
45+
%Include qgsoverlayobject.sip
4546
%Include qgspoint.sip
4647
%Include qgsproject.sip
4748
%Include qgsprovidermetadata.sip
@@ -70,4 +71,5 @@
7071
%Include qgsvectordataprovider.sip
7172
%Include qgsvectorfilewriter.sip
7273
%Include qgsvectorlayer.sip
74+
%Include qgsvectoroverlay.sip
7375

python/core/qgsoverlayobject.sip

+17-34
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,39 @@
1-
class CORE_EXPORT QgsOverlayObject: public pal::PalGeometry
1+
class QgsOverlayObject
22
{
33
%TypeHeaderCode
44
#include "qgsoverlayobject.h"
55
%End
6-
public:
6+
public:
77
QgsOverlayObject( int width = 0, int height = 0, double rotation = 0, QgsGeometry* geometry = 0 );
88
virtual ~QgsOverlayObject();
99

1010
//copy constructor and assignment operator necessary because of mGeometry
1111
QgsOverlayObject( const QgsOverlayObject& other );
12-
QgsOverlayObject& operator=( const QgsOverlayObject& other );
1312

1413

14+
//this function fill not be wrapped to not depend on geos python bindings
1515
/**Returns the feature geometry in geos format. The calling function does _not_ take
16-
ownership of the generated object*/
17-
GEOSGeometry* getGeosGeometry();
18-
/**Feature geometry is released when object is destructed so this function is empty*/
19-
void releaseGeosGeometry( GEOSGeometry *the_geom ) {}
16+
ownership of the generated object. The geometry is in map coordinates
17+
@note: this function is deprecated. Please use geometry() and QgsGeometry::asGeos instead*/
18+
//GEOSGeometry* getGeosGeometry();
19+
/**Feature geometry is released when object is destructed so this function is empty. This function is deprecated and does nothing*/
20+
//void releaseGeosGeometry( GEOSGeometry *the_geom )
2021

2122
//getters
22-
int width() const {return mWidth;}
23-
int height() const {return mHeight;}
24-
double rotation() const {return mRotation;}
25-
QgsGeometry* geometry() {return mGeometry;}
26-
const QgsGeometry* geometry() const {return mGeometry;}
23+
int width() const;
24+
int height() const;
25+
double rotation() const;
26+
QgsGeometry* geometry();
27+
//const QgsGeometry* geometry() const;
2728
QgsPoint position() const;
28-
QList<QgsPoint> positions() const {return mPositions;}
29+
QList<QgsPoint> positions() const;
2930

3031
//setters
31-
void setHeight( int height ) {mHeight = height;}
32-
void setWidth( int width ) {mWidth = width;}
33-
void setRotation( double rotation ) {mRotation = rotation;}
32+
void setHeight( int height );
33+
void setWidth( int width );
34+
void setRotation( double rotation );
3435
/**Set geometry. This class takes ownership of the object*/
3536
void setGeometry( QgsGeometry* g );
3637
/**Adds a position in map coordinates*/
3738
void addPosition( const QgsPoint& position );
38-
39-
40-
private:
41-
42-
/**Width of the bounding box in pixels*/
43-
int mWidth;
44-
/**Height of the bounding box in pixels*/
45-
int mHeight;
46-
/**Position of the object in map coordinates. Note that it is possible that an object
47-
has several positions, e.g. a multiobject or an object that is split into multiple parts
48-
by the edge of the view extent*/
49-
QList<QgsPoint> mPositions;
50-
/**Rotation of the object*/
51-
double mRotation;
52-
/**Copy of the feature geometry. A copy is necessary because in QGIS geometries are deleted
53-
after drawing*/
54-
QgsGeometry* mGeometry;
55-
5639
};

python/core/qgsvectoroverlay.sip

+6-23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class CORE_EXPORT QgsVectorOverlay
1+
class QgsVectorOverlay
22
{
33
%TypeHeaderCode
44
#include "qgsvectoroverlay.h"
@@ -7,7 +7,7 @@ class CORE_EXPORT QgsVectorOverlay
77
QgsVectorOverlay( QgsVectorLayer* vl );
88
virtual ~QgsVectorOverlay();
99

10-
/**Create the overlay objects contained in a view extent. Subclasses need to implement this method and assign width/height information to the overlay ovbjects*/
10+
/**Create the overlay objects contained in a view extent. Subclasses need to implement this method and assign width/height information to the overlay objects*/
1111

1212
virtual void createOverlayObjects( const QgsRenderContext& renderContext ) = 0;
1313

@@ -18,39 +18,22 @@ class CORE_EXPORT QgsVectorOverlay
1818
virtual void drawOverlayObjects( QgsRenderContext& context ) const = 0;
1919

2020
/**Gives direct access to oberlay objects*/
21-
QMap<int, QgsOverlayObject*>* overlayObjects() {return &mOverlayObjects;}
21+
QMap<int, QgsOverlayObject*>* overlayObjects();
2222

2323
/**Describes the overlay type (e.g. "diagram" or "label")*/
2424
virtual QString typeName() const = 0;
2525

2626
/**Set attribute indices necessary to fetch*/
27-
void setAttributes( const QgsAttributeList& list ) {mAttributes = list;}
27+
void setAttributes( const QList<int>& list );
2828

29-
bool displayFlag() const {return mDisplayFlag;}
29+
bool displayFlag() const;
3030

3131
/**Display yes/no*/
32-
void setDisplayFlag( bool flag ) {mDisplayFlag = flag;}
32+
void setDisplayFlag( bool flag );
3333

3434
/**Restore from project file*/
3535
virtual bool readXML( const QDomNode& overlayNode ) = 0;
3636

3737
/**Save to project file*/
3838
virtual bool writeXML( QDomNode& layer_node, QDomDocument& doc ) const = 0;
39-
40-
protected:
41-
/**Pointer to the vector layer for this overlay*/
42-
QgsVectorLayer* mVectorLayer;
43-
44-
/**True if overlay should be displayed*/
45-
bool mDisplayFlag;
46-
47-
/**A list with attribute indexes that are needed for overlay rendering*/
48-
QgsAttributeList mAttributes;
49-
50-
/**Key: feature ids, value: the corresponding overlay objects. Normally, they are created for each redraw and deleted before the next redraw*/
51-
QMap<int, QgsOverlayObject*> mOverlayObjects;
52-
53-
/**Position constraints that may be set to be persistent after redraws. Key is the feature id, value the map point
54-
where the feature should be placed*/
55-
QMap<int, QgsPoint> mPositionConstraints;
5639
};

src/core/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ SET(QGIS_CORE_SRCS
2727
qgsmaptopixel.cpp
2828
qgsmessageoutput.cpp
2929
qgsoverlayobject.cpp
30+
qgspalgeometry.cpp
3031
qgspalobjectpositionmanager.cpp
3132
qgspoint.cpp
3233
qgsproject.cpp

src/core/qgsoverlayobject.h

+7-5
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
#ifndef QGSOVERLAYOBJECT_H
1919
#define QGSOVERLAYOBJECT_H
2020

21+
#include "qgsgeometry.h"
2122
#include "qgspoint.h"
22-
#include "palgeometry.h"
2323
#include <QList>
2424

2525
class QgsGeometry;
@@ -29,7 +29,7 @@ class QgsGeometry;
2929
* to calculate object placement
3030
* \note This class has been added in version 1.1
3131
*/
32-
class CORE_EXPORT QgsOverlayObject: public pal::PalGeometry
32+
class CORE_EXPORT QgsOverlayObject
3333
{
3434
public:
3535
QgsOverlayObject( int width = 0, int height = 0, double rotation = 0, QgsGeometry* geometry = 0 );
@@ -41,9 +41,10 @@ class CORE_EXPORT QgsOverlayObject: public pal::PalGeometry
4141

4242

4343
/**Returns the feature geometry in geos format. The calling function does _not_ take
44-
ownership of the generated object. The geometry is in map coordinates*/
44+
ownership of the generated object. The geometry is in map coordinates
45+
@note: this function is deprecated. Please use geometry() and QgsGeometry::asGeos instead*/
4546
GEOSGeometry* getGeosGeometry();
46-
/**Feature geometry is released when object is destructed so this function is empty*/
47+
/**Feature geometry is released when object is destructed so this function is empty. This function is deprecated and does nothing*/
4748
void releaseGeosGeometry( GEOSGeometry *the_geom ) {}
4849

4950
//getters
@@ -73,7 +74,8 @@ class CORE_EXPORT QgsOverlayObject: public pal::PalGeometry
7374
int mHeight;
7475
/**Position of the object in map coordinates. Note that it is possible that an object
7576
has several positions, e.g. a multiobject or an object that is split into multiple parts
76-
by the edge of the view extent*/
77+
by the edge of the view extent. It is also possible that there is no position (e.g. geometry too small). In
78+
that case*/
7779
QList<QgsPoint> mPositions;
7880
/**Rotation of the object*/
7981
double mRotation;

src/core/qgsoverlayobjectpositionmanager.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class QgsVectorOverlay;
3131
class QgsOverlayObjectPositionManager
3232
{
3333
public:
34-
34+
//virtual destructor needed for proper memory management
35+
virtual ~QgsOverlayObjectPositionManager(){}
3536
/**Adds a layer that may contain * overlays to the position manager. The overlay objects contained in the
3637
overlays will then be considered in label placement*/
3738
virtual void addLayer( QgsVectorLayer* vl, QList<QgsVectorOverlay*>& overlays ) = 0;

src/core/qgspalgeometry.cpp

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/***************************************************************************
2+
qgspalgeometry.cpp - description
3+
---------------------------------
4+
begin : May 2009
5+
copyright : (C) 2009 by Marco Hugentobler
6+
email : marco dot hugentobler at karto dot baug dot ethz dot ch
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+
18+
#include "qgspalgeometry.h"
19+
#include "qgsgeometry.h"
20+
#include "qgsoverlayobject.h"
21+
#include <geos_c.h>
22+
23+
QgsPALGeometry::QgsPALGeometry(QgsOverlayObject* op): mOverlayObjectPtr(op)
24+
{
25+
}
26+
27+
QgsPALGeometry::QgsPALGeometry(): mOverlayObjectPtr(0)
28+
{
29+
}
30+
31+
QgsPALGeometry::~QgsPALGeometry()
32+
{
33+
}
34+
35+
GEOSGeometry* QgsPALGeometry::getGeosGeometry()
36+
{
37+
if(mOverlayObjectPtr)
38+
{
39+
if(mOverlayObjectPtr->geometry())
40+
{
41+
return mOverlayObjectPtr->geometry()->asGeos();
42+
}
43+
}
44+
return 0;
45+
}
46+

0 commit comments

Comments
 (0)