Skip to content
Permalink
Browse files

Add support for new symbology for rotate point tool

  • Loading branch information
mhugent committed Feb 7, 2012
1 parent 6878bf1 commit ebd300fe75cce7cd056803954ae31e2bb2d389d2
@@ -98,6 +98,13 @@ public:
//! set type and size of editing vertex markers for subsequent rendering
void setVertexMarkerAppearance( int type, int size );

//! return rotation field name (or empty string if not set or not supported by renderer)
//! @note added in 1.9
virtual QString rotationField() const;
//! sets rotation field of renderer (if supported by the renderer)
//! @note added in 1.9
virtual void setRotationField( QString fieldName );

protected:
QgsFeatureRendererV2(QString type);

@@ -18,7 +18,9 @@
#include "qgsmapcanvas.h"
#include "qgspointrotationitem.h"
#include "qgsrenderer.h"
#include "qgsrendererv2.h"
#include "qgssymbol.h"
#include "qgssymbolv2.h"
#include "qgsvectorlayer.h"
#include <QGraphicsPixmapItem>
#include <QMessageBox>
@@ -222,37 +224,54 @@ void QgsMapToolRotatePointSymbols::canvasReleaseEvent( QMouseEvent *e )
mCanvas->refresh();
}

int QgsMapToolRotatePointSymbols::layerRotationAttributes( const QgsVectorLayer* vl, QList<int>& attList )
int QgsMapToolRotatePointSymbols::layerRotationAttributes( QgsVectorLayer* vl, QList<int>& attList )
{
attList.clear();
if ( !vl )
{
return 1;
}

//get renderer
//old symbology
const QgsRenderer* layerRenderer = vl->renderer();
if ( !layerRenderer )
if ( layerRenderer )
{
return 2;
}
//get renderer symbols
const QList<QgsSymbol*> rendererSymbols = layerRenderer->symbols();
int currentRotationAttribute;

//get renderer symbols
const QList<QgsSymbol*> rendererSymbols = layerRenderer->symbols();
int currentRotationAttribute;
QList<QgsSymbol*>::const_iterator symbolIt = rendererSymbols.constBegin();
for ( ; symbolIt != rendererSymbols.constEnd(); ++symbolIt )
{
currentRotationAttribute = ( *symbolIt )->rotationClassificationField();
if ( currentRotationAttribute >= 0 )
{
attList.push_back( currentRotationAttribute );
}
}
return 0;
}

QList<QgsSymbol*>::const_iterator symbolIt = rendererSymbols.constBegin();
for ( ; symbolIt != rendererSymbols.constEnd(); ++symbolIt )
//new symbology
const QgsFeatureRendererV2* symbologyNgRenderer = vl->rendererV2();
if ( symbologyNgRenderer )
{
currentRotationAttribute = ( *symbolIt )->rotationClassificationField();
if ( currentRotationAttribute >= 0 )
//rotation field is supported for QgsSingleSymbolRendererV2, QgsCategorizedRendererV2, QgsUniqueCategorizedRendererV2
QString rotationFieldName = symbologyNgRenderer->rotationField();

if ( !rotationFieldName.isEmpty() )
{
attList.push_back( currentRotationAttribute );
attList.push_back( vl->fieldNameIndex( rotationFieldName ) );
}
return 0;
}
return 0;

//no renderer
return 2;
}



double QgsMapToolRotatePointSymbols::calculateAzimut( const QPoint& mousePos )
{
int dx = mousePos.x() - mSnappedPoint.x();
@@ -267,10 +286,20 @@ void QgsMapToolRotatePointSymbols::createPixmapItem( QgsFeature& f )
return;
}

if ( mActiveLayer && mActiveLayer->renderer() )
//get reference to current render context
QgsMapRenderer* mapRenderer = mCanvas->mapRenderer();
if ( !mapRenderer )
{
return;
}

//get the image that is used for that symbol, but without point rotation
QImage pointImage;
QgsRenderer* r = 0;
QgsFeatureRendererV2* rv2 = 0;

if ( mActiveLayer && mActiveLayer->renderer() ) //old symbology
{
//get the image that is used for that symbol, but without point rotation
QImage pointImage;
//copy renderer
QgsRenderer* r = mActiveLayer->renderer()->clone();

@@ -282,14 +311,6 @@ void QgsMapToolRotatePointSymbols::createPixmapItem( QgsFeature& f )
( *it )->setRotationClassificationField( -1 );
}


//get reference to current render context
QgsMapRenderer* mapRenderer = mCanvas->mapRenderer();
if ( !mapRenderer )
{
delete r;
return;
}
QgsRenderContext* renderContext = mCanvas->mapRenderer()->rendererContext(); //todo: check if pointers are not 0
if ( !renderContext )
{
@@ -298,16 +319,32 @@ void QgsMapToolRotatePointSymbols::createPixmapItem( QgsFeature& f )
}

r->renderFeature( *renderContext, f, &pointImage, false );
mRotationItem = new QgsPointRotationItem( mCanvas );
mRotationItem->setSymbol( pointImage );
delete r;
}
else if ( mActiveLayer && mActiveLayer->rendererV2() ) //symbology-ng
{
rv2 = mActiveLayer->rendererV2()->clone();
rv2->setRotationField( "" );

QgsSymbolV2* symbolV2 = rv2->symbolForFeature( f );
if ( symbolV2 )
{
pointImage = symbolV2->bigSymbolPreviewImage();
}
}

mRotationItem = new QgsPointRotationItem( mCanvas );
mRotationItem->setSymbol( pointImage );
delete r;
delete rv2;
}

void QgsMapToolRotatePointSymbols::setPixmapItemRotation( double rotation )
{
mRotationItem->setSymbolRotation( rotation );
mRotationItem->update();
if ( mRotationItem )
{
mRotationItem->setSymbolRotation( rotation );
mRotationItem->update();
}
}

int QgsMapToolRotatePointSymbols::roundTo15Degrees( double n )
@@ -60,7 +60,7 @@ class QgsMapToolRotatePointSymbols: public QgsMapToolEdit
@param vl the point vector layer
@param attList out: the list containing the rotation indices
@return 0 in case of success*/
static int layerRotationAttributes( const QgsVectorLayer* vl, QList<int>& attList );
static int layerRotationAttributes( QgsVectorLayer* vl, QList<int>& attList );
void drawArrow( double azimut ) const;
/**Calculates the azimut between mousePos and mSnappedPoint*/
double calculateAzimut( const QPoint& mousePos );
@@ -62,7 +62,7 @@ class CORE_EXPORT QgsCategorizedSymbolRendererV2 : public QgsFeatureRendererV2

//! returns bitwise OR-ed capabilities of the renderer
//! \note added in 2.0
virtual int capabilities() { return SymbolLevels; }
virtual int capabilities() { return SymbolLevels | RotationField; }

virtual QgsSymbolV2List symbols();

@@ -57,7 +57,7 @@ class CORE_EXPORT QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2

//! returns bitwise OR-ed capabilities of the renderer
//! \note added in 2.0
virtual int capabilities() { return SymbolLevels; }
virtual int capabilities() { return SymbolLevels | RotationField; }

virtual QgsSymbolV2List symbols();

@@ -80,7 +80,8 @@ class CORE_EXPORT QgsFeatureRendererV2

enum Capabilities
{
SymbolLevels = 1 // rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
SymbolLevels = 1, // rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
RotationField = 1 << 1 // rotate symbols by attribute value
};

//! returns bitwise OR-ed capabilities of the renderer
@@ -109,6 +110,15 @@ class CORE_EXPORT QgsFeatureRendererV2
//! set type and size of editing vertex markers for subsequent rendering
void setVertexMarkerAppearance( int type, int size );

//! return rotation field name (or empty string if not set or not supported by renderer)
//! @note added in 1.9
virtual QString rotationField() const { return ""; }
//! sets rotation field of renderer (if supported by the renderer)
//! @note added in 1.9
virtual void setRotationField( QString fieldName ) { Q_UNUSED( fieldName ); }



protected:
QgsFeatureRendererV2( QString type );

@@ -38,7 +38,7 @@ class CORE_EXPORT QgsSingleSymbolRendererV2 : public QgsFeatureRendererV2

//! returns bitwise OR-ed capabilities of the renderer
//! \note added in 2.0
virtual int capabilities() { return SymbolLevels; }
virtual int capabilities() { return SymbolLevels | RotationField; }

virtual QgsSymbolV2List symbols();

0 comments on commit ebd300f

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