Skip to content

Commit

Permalink
Change in overlay classes such that pal object and geos geometry don'…
Browse files Browse the repository at this point in the history
…t appear in the public interfaces (important for python bindings)

git-svn-id: http://svn.osgeo.org/qgis/trunk@10791 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed May 14, 2009
1 parent d796bbc commit 749390f
Show file tree
Hide file tree
Showing 13 changed files with 259 additions and 69 deletions.
79 changes: 79 additions & 0 deletions python/core/conversions.sip
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ which are not wrapped by PyQt:
- QMap<QString, QVariant::Type>
- QMap<TYPE1, TYPE2*>
- QMultiMap<double, TYPE2>
- QMap<int, QgsOverlayObject*>*
*/

%ModuleHeaderCode
Expand All @@ -21,6 +22,7 @@ typedef int Py_ssize_t;
%End



template <TYPE>
%MappedType QVector< QVector<TYPE> >
{
Expand Down Expand Up @@ -737,3 +739,80 @@ template<double, TYPE2>
return sipGetState(sipTransferObj);
%End
};

%MappedType QMap<int, QgsOverlayObject*>
{
%TypeHeaderCode
#include <QMap>
%End

%ConvertFromTypeCode

//convert map to a python dictionary
PyObject *d;

if ((d = PyDict_New()) == NULL)
return NULL;

for (QMap<int, QgsOverlayObject*>::iterator it = sipCpp->begin(); it != sipCpp->end(); ++it)
{
QgsOverlayObject* oobj = new QgsOverlayObject(*it.value());

PyObject* keyobj = PyInt_FromLong(it.key());
PyObject* pyOobj = sipConvertFromInstance(oobj, sipClass_QgsOverlayObject, sipTransferObj);
PyDict_SetItem(d, keyobj, pyOobj);

if(pyOobj == NULL || keyobj == NULL || PyDict_SetItem(d, keyobj, pyOobj) < 0)
{
Py_DECREF(d);

if (pyOobj)
{
Py_DECREF(pyOobj);
}

if (keyobj)
{
Py_DECREF(keyobj);
}
return NULL;
}
Py_DECREF(pyOobj);
Py_DECREF(keyobj);
}
return d;

%End
%ConvertToTypeCode
PyObject *t1obj, *t2obj;
#if PY_VERSION_HEX >= 0x02050000
Py_ssize_t i = 0;
#else
int i = 0;
#endif

QMap<int, QgsOverlayObject*> *qm = new QMap<int, QgsOverlayObject*>;

while (PyDict_Next(sipPy, &i, &t1obj, &t2obj))
{
int state;
int t1 = (int)(PyFloat_AsDouble(t1obj));
QgsOverlayObject* t2 = reinterpret_cast<QgsOverlayObject*>(sipConvertToInstance(t2obj, sipClass_QgsOverlayObject, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));

if (*sipIsErr)
{
sipReleaseInstance(t2, sipClass_QgsOverlayObject, state);
delete qm;
return 0;
}

qm->insert(t1, t2);

sipReleaseInstance(t2, sipClass_QgsOverlayObject, state);
}

*sipCppPtr = qm;

return sipGetState(sipTransferObj);
%End
};
2 changes: 2 additions & 0 deletions python/core/core.sip
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
%Include qgsmaptopixel.sip
%Include qgsmarkercatalogue.sip
%Include qgsmessageoutput.sip
%Include qgsoverlayobject.sip
%Include qgspoint.sip
%Include qgsproject.sip
%Include qgsprovidermetadata.sip
Expand Down Expand Up @@ -70,4 +71,5 @@
%Include qgsvectordataprovider.sip
%Include qgsvectorfilewriter.sip
%Include qgsvectorlayer.sip
%Include qgsvectoroverlay.sip

51 changes: 17 additions & 34 deletions python/core/qgsoverlayobject.sip
Original file line number Diff line number Diff line change
@@ -1,56 +1,39 @@
class CORE_EXPORT QgsOverlayObject: public pal::PalGeometry
class QgsOverlayObject
{
%TypeHeaderCode
#include "qgsoverlayobject.h"
%End
public:
public:
QgsOverlayObject( int width = 0, int height = 0, double rotation = 0, QgsGeometry* geometry = 0 );
virtual ~QgsOverlayObject();

//copy constructor and assignment operator necessary because of mGeometry
QgsOverlayObject( const QgsOverlayObject& other );
QgsOverlayObject& operator=( const QgsOverlayObject& other );


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

//getters
int width() const {return mWidth;}
int height() const {return mHeight;}
double rotation() const {return mRotation;}
QgsGeometry* geometry() {return mGeometry;}
const QgsGeometry* geometry() const {return mGeometry;}
int width() const;
int height() const;
double rotation() const;
QgsGeometry* geometry();
//const QgsGeometry* geometry() const;
QgsPoint position() const;
QList<QgsPoint> positions() const {return mPositions;}
QList<QgsPoint> positions() const;

//setters
void setHeight( int height ) {mHeight = height;}
void setWidth( int width ) {mWidth = width;}
void setRotation( double rotation ) {mRotation = rotation;}
void setHeight( int height );
void setWidth( int width );
void setRotation( double rotation );
/**Set geometry. This class takes ownership of the object*/
void setGeometry( QgsGeometry* g );
/**Adds a position in map coordinates*/
void addPosition( const QgsPoint& position );


private:

/**Width of the bounding box in pixels*/
int mWidth;
/**Height of the bounding box in pixels*/
int mHeight;
/**Position of the object in map coordinates. Note that it is possible that an object
has several positions, e.g. a multiobject or an object that is split into multiple parts
by the edge of the view extent*/
QList<QgsPoint> mPositions;
/**Rotation of the object*/
double mRotation;
/**Copy of the feature geometry. A copy is necessary because in QGIS geometries are deleted
after drawing*/
QgsGeometry* mGeometry;

};
29 changes: 6 additions & 23 deletions python/core/qgsvectoroverlay.sip
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CORE_EXPORT QgsVectorOverlay
class QgsVectorOverlay
{
%TypeHeaderCode
#include "qgsvectoroverlay.h"
Expand All @@ -7,7 +7,7 @@ class CORE_EXPORT QgsVectorOverlay
QgsVectorOverlay( QgsVectorLayer* vl );
virtual ~QgsVectorOverlay();

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

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

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

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

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

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

bool displayFlag() const {return mDisplayFlag;}
bool displayFlag() const;

/**Display yes/no*/
void setDisplayFlag( bool flag ) {mDisplayFlag = flag;}
void setDisplayFlag( bool flag );

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

/**Save to project file*/
virtual bool writeXML( QDomNode& layer_node, QDomDocument& doc ) const = 0;

protected:
/**Pointer to the vector layer for this overlay*/
QgsVectorLayer* mVectorLayer;

/**True if overlay should be displayed*/
bool mDisplayFlag;

/**A list with attribute indexes that are needed for overlay rendering*/
QgsAttributeList mAttributes;

/**Key: feature ids, value: the corresponding overlay objects. Normally, they are created for each redraw and deleted before the next redraw*/
QMap<int, QgsOverlayObject*> mOverlayObjects;

/**Position constraints that may be set to be persistent after redraws. Key is the feature id, value the map point
where the feature should be placed*/
QMap<int, QgsPoint> mPositionConstraints;
};
1 change: 1 addition & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ SET(QGIS_CORE_SRCS
qgsmaptopixel.cpp
qgsmessageoutput.cpp
qgsoverlayobject.cpp
qgspalgeometry.cpp
qgspalobjectpositionmanager.cpp
qgspoint.cpp
qgsproject.cpp
Expand Down
12 changes: 7 additions & 5 deletions src/core/qgsoverlayobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#ifndef QGSOVERLAYOBJECT_H
#define QGSOVERLAYOBJECT_H

#include "qgsgeometry.h"
#include "qgspoint.h"
#include "palgeometry.h"
#include <QList>

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


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

//getters
Expand Down Expand Up @@ -73,7 +74,8 @@ class CORE_EXPORT QgsOverlayObject: public pal::PalGeometry
int mHeight;
/**Position of the object in map coordinates. Note that it is possible that an object
has several positions, e.g. a multiobject or an object that is split into multiple parts
by the edge of the view extent*/
by the edge of the view extent. It is also possible that there is no position (e.g. geometry too small). In
that case*/
QList<QgsPoint> mPositions;
/**Rotation of the object*/
double mRotation;
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsoverlayobjectpositionmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class QgsVectorOverlay;
class QgsOverlayObjectPositionManager
{
public:

//virtual destructor needed for proper memory management
virtual ~QgsOverlayObjectPositionManager(){}
/**Adds a layer that may contain * overlays to the position manager. The overlay objects contained in the
overlays will then be considered in label placement*/
virtual void addLayer( QgsVectorLayer* vl, QList<QgsVectorOverlay*>& overlays ) = 0;
Expand Down
46 changes: 46 additions & 0 deletions src/core/qgspalgeometry.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/***************************************************************************
qgspalgeometry.cpp - description
---------------------------------
begin : May 2009
copyright : (C) 2009 by Marco Hugentobler
email : marco dot hugentobler at karto dot baug dot ethz dot ch
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgspalgeometry.h"
#include "qgsgeometry.h"
#include "qgsoverlayobject.h"
#include <geos_c.h>

QgsPALGeometry::QgsPALGeometry(QgsOverlayObject* op): mOverlayObjectPtr(op)
{
}

QgsPALGeometry::QgsPALGeometry(): mOverlayObjectPtr(0)
{
}

QgsPALGeometry::~QgsPALGeometry()
{
}

GEOSGeometry* QgsPALGeometry::getGeosGeometry()
{
if(mOverlayObjectPtr)
{
if(mOverlayObjectPtr->geometry())
{
return mOverlayObjectPtr->geometry()->asGeos();
}
}
return 0;
}

Loading

0 comments on commit 749390f

Please sign in to comment.