Skip to content
Permalink
Browse files
fix crash when removing layers with highlighed features
  • Loading branch information
jef-n committed Apr 6, 2014
1 parent 8e8019a commit c91d470f53dd7129df7a47367077f60ff7342e9a
Showing with 35 additions and 19 deletions.
  1. +10 −0 python/gui/qgshighlight.sip
  2. +4 −10 src/gui/qgshighlight.cpp
  3. +2 −4 src/gui/qgshighlight.h
  4. +18 −5 src/gui/qgsmaptoolidentify.cpp
  5. +1 −0 src/gui/qgsmaptoolidentify.h
@@ -7,17 +7,27 @@ class QgsHighlight : QgsMapCanvasItem
QgsHighlight( QgsMapCanvas *mapCanvas, QgsGeometry *geom, QgsVectorLayer *layer );
~QgsHighlight();

/** Set line/outline to color, polygon fill to color with alpha = 63.
* This is legacy function, use setFillColor() after setColor() if different fill color is required. */
void setColor( const QColor & color );

/** Set polygons fill color.
* @note: added in version 2.3 */
void setFillColor( const QColor & fillColor );

/** Set width. Ignored in feature mode. */
void setWidth( int width );

/** Set line / outline buffer in millimeters.
* @note: added in version 2.3 */
void setBuffer( double buffer );

/** Set minimum line / outline width in millimeters.
* @note: added in version 2.3 */
void setMinWidth( double width );

const QgsMapLayer *layer() const;

protected:
virtual void paint( QPainter* p );

@@ -13,8 +13,6 @@
* *
***************************************************************************/

#include <typeinfo>

#include <QImage>

#include "qgsmarkersymbollayerv2.h"
@@ -134,7 +132,7 @@ void QgsHighlight::setFillColor( const QColor & fillColor )
QgsFeatureRendererV2 * QgsHighlight::getRenderer( const QgsRenderContext & context, const QColor & color, const QColor & fillColor )
{
QgsFeatureRendererV2 *renderer = 0;
QgsVectorLayer *layer = vectorLayer();
QgsVectorLayer *layer = qobject_cast<QgsVectorLayer*>( mLayer );
if ( layer && layer->rendererV2() )
{
renderer = layer->rendererV2()->clone();
@@ -345,7 +343,9 @@ void QgsHighlight::paint( QPainter* p )
}
else if ( mFeature.geometry() )
{
QgsVectorLayer *layer = vectorLayer();
QgsVectorLayer *layer = qobject_cast<QgsVectorLayer*>( mLayer );
if( !layer )
return;
QgsMapSettings mapSettings = mMapCanvas->mapSettings();
QgsRenderContext context = QgsRenderContext::fromMapSettings( mapSettings );

@@ -438,9 +438,3 @@ void QgsHighlight::updateRect()
setRect( QgsRectangle() );
}
}

QgsVectorLayer * QgsHighlight::vectorLayer()
{
return dynamic_cast<QgsVectorLayer *>( mLayer );
}

@@ -66,6 +66,8 @@ class GUI_EXPORT QgsHighlight: public QgsMapCanvasItem
* @note: added in version 2.3 */
void setMinWidth( double width ) { mMinWidth = width; }

const QgsMapLayer *layer() const { return mLayer; }

protected:
virtual void paint( QPainter* p );

@@ -82,10 +84,6 @@ class GUI_EXPORT QgsHighlight: public QgsMapCanvasItem
void paintLine( QPainter *p, QgsPolyline line );
void paintPolygon( QPainter *p, QgsPolygon polygon );

QgsVectorLayer *vectorLayer();

QgsHighlight();

QBrush mBrush;
QPen mPen;
QgsGeometry *mGeometry;
@@ -650,10 +650,11 @@ void QgsMapToolIdentify::handleMenuHover()
QList<IdentifyResult>::const_iterator idListIt = idList.constBegin();
for ( ; idListIt != idList.constEnd(); ++idListIt )
{
QgsHighlight* hl = new QgsHighlight( mCanvas, idListIt->mFeature.geometry(), vl );
QgsHighlight *hl = new QgsHighlight( mCanvas, idListIt->mFeature.geometry(), vl );
hl->setColor( QColor( 255, 0, 0 ) );
hl->setWidth( 2 );
mRubberBands.append( hl );
connect( vl, SIGNAL( destroyed() ), this, SLOT( layerDestroyed() ) );
}
}
}
@@ -662,10 +663,22 @@ void QgsMapToolIdentify::handleMenuHover()

void QgsMapToolIdentify::deleteRubberBands()
{
QList<QgsHighlight*>::const_iterator it = mRubberBands.constBegin();
for ( ; it != mRubberBands.constEnd(); ++it )
qDeleteAll( mRubberBands );
}

void QgsMapToolIdentify::layerDestroyed()
{
QList<QgsHighlight*>::iterator it = mRubberBands.begin();
while ( it != mRubberBands.end() )
{
delete *it;
if (( *it )->layer() == sender() )
{
delete *it;
it = mRubberBands.erase( it );
}
else
{
++it;
}
}
mRubberBands.clear();
}
@@ -127,6 +127,7 @@ class GUI_EXPORT QgsMapToolIdentify : public QgsMapTool

public slots:
void formatChanged( QgsRasterLayer *layer );
void layerDestroyed();

signals:
void identifyProgress( int, int );

0 comments on commit c91d470

Please sign in to comment.