fix crash when removing layers with highlighed features

This commit is contained in:
Juergen E. Fischer 2014-04-06 16:17:58 +02:00
parent 8e8019a5d0
commit c91d470f53
5 changed files with 37 additions and 21 deletions

View File

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

View File

@ -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 );
}

View File

@ -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;

View File

@ -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 )
{
delete *it;
}
mRubberBands.clear();
qDeleteAll( mRubberBands );
}
void QgsMapToolIdentify::layerDestroyed()
{
QList<QgsHighlight*>::iterator it = mRubberBands.begin();
while ( it != mRubberBands.end() )
{
if (( *it )->layer() == sender() )
{
delete *it;
it = mRubberBands.erase( it );
}
else
{
++it;
}
}
}

View File

@ -127,6 +127,7 @@ class GUI_EXPORT QgsMapToolIdentify : public QgsMapTool
public slots:
void formatChanged( QgsRasterLayer *layer );
void layerDestroyed();
signals:
void identifyProgress( int, int );