Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
give correct layer to QgsHighlight in QgsIdentifyResultsDialog, fixes #…
  • Loading branch information
blazek committed Oct 1, 2013
1 parent 968c321 commit 96bd7e7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/app/qgsidentifyresultsdialog.cpp
Expand Up @@ -1143,10 +1143,13 @@ void QgsIdentifyResultsDialog::attributeValueChanged( QgsFeatureId fid, int idx,

void QgsIdentifyResultsDialog::highlightFeature( QTreeWidgetItem *item )
{
QgsVectorLayer *layer = vectorLayer( item );
QgsMapLayer *layer;
QgsVectorLayer *vlayer = vectorLayer( item );
QgsRasterLayer *rlayer = rasterLayer( item );
if ( !layer && !rlayer )
return;

layer = vlayer ? static_cast<QgsMapLayer *>( vlayer ) : static_cast<QgsMapLayer *>( rlayer );

if ( !layer ) return;

QgsIdentifyResultsFeatureItem *featItem = dynamic_cast<QgsIdentifyResultsFeatureItem *>( featureItem( item ) );
if ( !featItem )
Expand Down
20 changes: 17 additions & 3 deletions src/gui/qgshighlight.cpp
Expand Up @@ -16,6 +16,7 @@
#include "qgshighlight.h"
#include "qgsgeometry.h"
#include "qgsmapcanvas.h"
#include "qgsmaplayer.h"
#include "qgsmaprenderer.h"
#include "qgscoordinatetransform.h"
#include "qgsvectorlayer.h"
Expand All @@ -25,14 +26,27 @@
\brief The QgsHighlight class provides a transparent overlay widget
for highlightng features on the map.
*/
QgsHighlight::QgsHighlight( QgsMapCanvas* mapCanvas, QgsGeometry *geom, QgsVectorLayer *layer )
QgsHighlight::QgsHighlight( QgsMapCanvas* mapCanvas, QgsGeometry *geom, QgsMapLayer *layer )
: QgsMapCanvasItem( mapCanvas )
, mLayer( layer )
{
mGeometry = geom ? new QgsGeometry( *geom ) : 0;
if ( mapCanvas->mapRenderer()->hasCrsTransformEnabled() )
init();
}

QgsHighlight::QgsHighlight( QgsMapCanvas* mapCanvas, QgsGeometry *geom, QgsVectorLayer *layer )
: QgsMapCanvasItem( mapCanvas )
, mLayer( static_cast<QgsMapLayer *>( layer ) )
{
mGeometry = geom ? new QgsGeometry( *geom ) : 0;
init();
}

void QgsHighlight::init()
{
if ( mMapCanvas->mapRenderer()->hasCrsTransformEnabled() )
{
QgsCoordinateTransform transform( mLayer->crs(), mapCanvas->mapRenderer()->destinationCrs() );
QgsCoordinateTransform transform( mLayer->crs(), mMapCanvas->mapRenderer()->destinationCrs() );
mGeometry->transform( transform );
}
updateRect();
Expand Down
5 changes: 4 additions & 1 deletion src/gui/qgshighlight.h
Expand Up @@ -23,13 +23,15 @@
#include <QPainter>
#include <QPainterPath>

class QgsMapLayer;
class QgsVectorLayer;

/** A class for highlight features on the map.
*/
class GUI_EXPORT QgsHighlight: public QgsMapCanvasItem
{
public:
QgsHighlight( QgsMapCanvas *mapCanvas, QgsGeometry *geom, QgsMapLayer *layer );
QgsHighlight( QgsMapCanvas *mapCanvas, QgsGeometry *geom, QgsVectorLayer *layer );
~QgsHighlight();

Expand All @@ -43,6 +45,7 @@ class GUI_EXPORT QgsHighlight: public QgsMapCanvasItem
void updateRect();

private:
void init();
void paintPoint( QPainter *p, QgsPoint point );
void paintLine( QPainter *p, QgsPolyline line );
void paintPolygon( QPainter *p, QgsPolygon polygon );
Expand All @@ -52,7 +55,7 @@ class GUI_EXPORT QgsHighlight: public QgsMapCanvasItem
QBrush mBrush;
QPen mPen;
QgsGeometry *mGeometry;
QgsVectorLayer *mLayer;
QgsMapLayer *mLayer;
};

#endif

0 comments on commit 96bd7e7

Please sign in to comment.