Skip to content

Commit a18b4a3

Browse files
committedJan 12, 2014
highlight identified feature using real feature shape
1 parent d59ab80 commit a18b4a3

15 files changed

+294
-62
lines changed
 

‎python/core/qgsfeaturestore.sip

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ class QgsFeatureStore
2828
/** Set crs */
2929
void setCrs( const QgsCoordinateReferenceSystem& crs );
3030

31+
/** Add feature. Feature's fields will be set to pointer to the store fields.
32+
* @param feature
33+
* @note added in 2.1
34+
*/
35+
void addFeature ( const QgsFeature& feature );
36+
3137
/** Get features list reference */
3238
QgsFeatureList& features();
3339

‎python/core/qgsrectangle.sip

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ class QgsRectangle
5858
QgsPoint center() const;
5959
//! Scale the rectangle around its center point
6060
void scale( double, const QgsPoint *c = 0 );
61+
void scale( double scaleFactor, double centerX, double centerY );
62+
/** Get rectangle enlarged by buffer.
63+
* @note added in 2.1 */
64+
QgsRectangle buffer( double width );
6165
//! Expand the rectangle to support zoom out scaling
6266
//! return the intersection with the given rectangle
6367
QgsRectangle intersect( const QgsRectangle *rect ) const;

‎python/core/symbology-ng/qgsfillsymbollayerv2.sip

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ class QgsSimpleFillSymbolLayerV2 : QgsFillSymbolLayerV2
4040
QColor borderColor() const;
4141
void setBorderColor( QColor borderColor );
4242

43+
virtual QColor outlineColor() const;
44+
virtual void setOutlineColor( const QColor& color );
45+
46+
virtual QColor fillColor() const;
47+
virtual void setFillColor( const QColor& color );
48+
4349
Qt::PenStyle borderStyle() const;
4450
void setBorderStyle( Qt::PenStyle borderStyle );
4551

‎python/core/symbology-ng/qgsmarkersymbollayerv2.sip

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ class QgsSimpleMarkerSymbolLayerV2 : QgsMarkerSymbolLayerV2
4242
double outlineWidth() const;
4343
void setOutlineWidth( double w );
4444

45+
virtual QColor outlineColor() const;
46+
virtual void setOutlineColor( const QColor& color );
47+
48+
virtual QColor fillColor() const;
49+
virtual void setFillColor( const QColor& color );
50+
4551
QgsSymbolV2::OutputUnit outlineWidthUnit() const;
4652
void setOutlineWidthUnit( QgsSymbolV2::OutputUnit u );
4753

‎python/core/symbology-ng/qgssymbollayerv2.sip

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ class QgsSymbolLayerV2
6363
// not necessarily supported by all symbol layers...
6464
virtual void setColor( const QColor& color );
6565
virtual QColor color() const;
66+
virtual void setOutlineColor( const QColor& color );
67+
virtual QColor outlineColor() const;
68+
virtual void setFillColor( const QColor& color );
69+
virtual QColor fillColor() const;
6670

6771
virtual ~QgsSymbolLayerV2();
6872

‎src/app/qgsidentifyresultsdialog.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,14 +1172,24 @@ void QgsIdentifyResultsDialog::highlightFeature( QTreeWidgetItem *item )
11721172
if ( !featItem->feature().geometry() || featItem->feature().geometry()->wkbType() == QGis::WKBUnknown )
11731173
return;
11741174

1175-
QgsHighlight *h = new QgsHighlight( mCanvas, featItem->feature().geometry(), layer );
1176-
if ( h )
1175+
if ( vlayer )
11771176
{
1178-
h->setWidth( 2 );
1177+
QgsHighlight *h = new QgsHighlight( mCanvas, featItem->feature(), vlayer );
11791178
h->setColor( Qt::red );
11801179
h->show();
11811180
mHighlights.insert( featItem, h );
11821181
}
1182+
else
1183+
{
1184+
QgsHighlight *h = new QgsHighlight( mCanvas, featItem->feature().geometry(), layer );
1185+
if ( h )
1186+
{
1187+
h->setWidth( 2 );
1188+
h->setColor( Qt::red );
1189+
h->show();
1190+
mHighlights.insert( featItem, h );
1191+
}
1192+
}
11831193
}
11841194

11851195
void QgsIdentifyResultsDialog::zoomToFeature()

‎src/core/qgsfeaturestore.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,18 @@ QgsFeatureStore::~QgsFeatureStore( )
3737
{
3838
}
3939

40+
void QgsFeatureStore::setFields( const QgsFields & fields )
41+
{
42+
mFields = fields;
43+
foreach ( QgsFeature feature, mFeatures )
44+
{
45+
feature.setFields( &mFields );
46+
}
47+
}
48+
49+
void QgsFeatureStore::addFeature( const QgsFeature& feature )
50+
{
51+
QgsFeature f( feature );
52+
f.setFields( &mFields );
53+
mFeatures.append( f );
54+
}

‎src/core/qgsfeaturestore.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,21 @@ class CORE_EXPORT QgsFeatureStore
4545
/** Get fields list */
4646
QgsFields& fields() { return mFields; }
4747

48-
/** Set fields */
49-
void setFields( const QgsFields & fields ) { mFields = fields; }
48+
/** Set fields. Resets feauters fields to pointer to new internal fields. */
49+
void setFields( const QgsFields & fields );
5050

5151
/** Get crs */
5252
QgsCoordinateReferenceSystem crs() const { return mCrs; }
5353

5454
/** Set crs */
5555
void setCrs( const QgsCoordinateReferenceSystem& crs ) { mCrs = crs; }
5656

57+
/** Add feature. Feature's fields will be set to pointer to the store fields.
58+
* @param feature
59+
* @note added in 2.1
60+
*/
61+
void addFeature( const QgsFeature& feature );
62+
5763
/** Get features list reference */
5864
QgsFeatureList& features() { return mFeatures; }
5965

‎src/core/qgsrectangle.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ void QgsRectangle::scale( double scaleFactor, double centerX, double centerY )
122122
ymax = centerY + newHeight / 2.0;
123123
}
124124

125+
QgsRectangle QgsRectangle::buffer( double width )
126+
{
127+
return QgsRectangle( xmin - width, ymin - width, xmax + width, ymax + width );
128+
}
129+
125130
QgsRectangle QgsRectangle::intersect( const QgsRectangle * rect ) const
126131
{
127132
QgsRectangle intersection = QgsRectangle();

‎src/core/qgsrectangle.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ class CORE_EXPORT QgsRectangle
8282
//! Scale the rectangle around its center point
8383
void scale( double scaleFactor, const QgsPoint *c = 0 );
8484
void scale( double scaleFactor, double centerX, double centerY );
85+
/** Get rectangle enlarged by buffer.
86+
* @note added in 2.1 */
87+
QgsRectangle buffer( double width );
8588
//! return the intersection with the given rectangle
8689
QgsRectangle intersect( const QgsRectangle *rect ) const;
8790
//! returns true when rectangle intersects with other rectangle

‎src/core/symbology-ng/qgsfillsymbollayerv2.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ class CORE_EXPORT QgsSimpleFillSymbolLayerV2 : public QgsFillSymbolLayerV2
6565
QColor borderColor() const { return mBorderColor; }
6666
void setBorderColor( QColor borderColor ) { mBorderColor = borderColor; }
6767

68+
/** Get outline color.
69+
* @note added in 2.1 */
70+
QColor outlineColor() const { return borderColor(); }
71+
/** Set outline color.
72+
* @note added in 2.1 */
73+
void setOutlineColor( const QColor& color ) { setBorderColor( color ); }
74+
75+
/** Get fill color.
76+
* @note added in 2.1 */
77+
QColor fillColor() const { return color(); }
78+
/** Set fill color.
79+
* @note added in 2.1 */
80+
void setFillColor( const QColor& color ) { setColor( color ); }
81+
6882
Qt::PenStyle borderStyle() const { return mBorderStyle; }
6983
void setBorderStyle( Qt::PenStyle borderStyle ) { mBorderStyle = borderStyle; }
7084

‎src/core/symbology-ng/qgsmarkersymbollayerv2.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ class CORE_EXPORT QgsSimpleMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
4848

4949
// implemented from base classes
5050

51+
52+
5153
QString layerType() const;
5254

5355
void startRender( QgsSymbolV2RenderContext& context );
@@ -73,6 +75,20 @@ class CORE_EXPORT QgsSimpleMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
7375
Qt::PenStyle outlineStyle() const { return mOutlineStyle; }
7476
void setOutlineStyle( Qt::PenStyle outlineStyle ) { mOutlineStyle = outlineStyle; }
7577

78+
/** Get outline color.
79+
* @note added in 2.1 */
80+
QColor outlineColor() const { return borderColor(); }
81+
/** Set outline color.
82+
* @note added in 2.1 */
83+
void setOutlineColor( const QColor& color ) { setBorderColor( color ); }
84+
85+
/** Get fill color.
86+
* @note added in 2.1 */
87+
QColor fillColor() const { return color(); }
88+
/** Set fill color.
89+
* @note added in 2.1 */
90+
void setFillColor( const QColor& color ) { setColor( color ); }
91+
7692
double outlineWidth() const { return mOutlineWidth; }
7793
void setOutlineWidth( double w ) { mOutlineWidth = w; }
7894

‎src/core/symbology-ng/qgssymbollayerv2.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,20 @@ class CORE_EXPORT QgsSymbolLayerV2
4747
public:
4848

4949
// not necessarily supported by all symbol layers...
50-
virtual void setColor( const QColor& color ) { mColor = color; }
5150
virtual QColor color() const { return mColor; }
51+
virtual void setColor( const QColor& color ) { mColor = color; }
52+
/** Set outline color. Supported by marker and fill layers.
53+
* @note added in 2.1 */
54+
virtual void setOutlineColor( const QColor& color ) { Q_UNUSED( color ); }
55+
/** Get outline color. Supported by marker and fill layers.
56+
* @note added in 2.1 */
57+
virtual QColor outlineColor() const { return QColor(); }
58+
/** Set fill color. Supported by marker and fill layers.
59+
* @note added in 2.1 */
60+
virtual void setFillColor( const QColor& color ) { Q_UNUSED( color ); }
61+
/** Get fill color. Supported by marker and fill layers.
62+
* @note added in 2.1 */
63+
virtual QColor fillColor() const { return QColor(); }
5264

5365
virtual ~QgsSymbolLayerV2() { removeDataDefinedProperties(); }
5466

‎src/gui/qgshighlight.cpp

Lines changed: 164 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,19 @@
1313
* *
1414
***************************************************************************/
1515

16-
#include "qgshighlight.h"
16+
#include <typeinfo>
17+
#include "qgsmarkersymbollayerv2.h"
18+
#include "qgslinesymbollayerv2.h"
19+
20+
#include "qgscoordinatetransform.h"
1721
#include "qgsgeometry.h"
22+
#include "qgshighlight.h"
1823
#include "qgsmapcanvas.h"
1924
#include "qgsmaplayer.h"
2025
#include "qgsmaprenderer.h"
21-
#include "qgscoordinatetransform.h"
26+
#include "qgsrendercontext.h"
27+
#include "qgssymbollayerv2.h"
28+
#include "qgssymbolv2.h"
2229
#include "qgsvectorlayer.h"
2330

2431
/*!
@@ -29,6 +36,7 @@
2936
QgsHighlight::QgsHighlight( QgsMapCanvas* mapCanvas, QgsGeometry *geom, QgsMapLayer *layer )
3037
: QgsMapCanvasItem( mapCanvas )
3138
, mLayer( layer )
39+
, mRenderer( 0 )
3240
{
3341
mGeometry = geom ? new QgsGeometry( *geom ) : 0;
3442
init();
@@ -37,19 +45,37 @@ QgsHighlight::QgsHighlight( QgsMapCanvas* mapCanvas, QgsGeometry *geom, QgsMapLa
3745
QgsHighlight::QgsHighlight( QgsMapCanvas* mapCanvas, QgsGeometry *geom, QgsVectorLayer *layer )
3846
: QgsMapCanvasItem( mapCanvas )
3947
, mLayer( static_cast<QgsMapLayer *>( layer ) )
48+
, mRenderer( 0 )
4049
{
4150
mGeometry = geom ? new QgsGeometry( *geom ) : 0;
4251
init();
4352
}
4453

54+
QgsHighlight::QgsHighlight( QgsMapCanvas* mapCanvas, const QgsFeature& feature, QgsVectorLayer *layer )
55+
: QgsMapCanvasItem( mapCanvas )
56+
, mGeometry( 0 )
57+
, mLayer( static_cast<QgsMapLayer *>( layer ) )
58+
, mFeature( feature )
59+
, mRenderer( 0 )
60+
{
61+
init();
62+
}
63+
4564
void QgsHighlight::init()
4665
{
4766
if ( mMapCanvas->mapRenderer()->hasCrsTransformEnabled() )
4867
{
4968
const QgsCoordinateTransform* ct = mMapCanvas->mapRenderer()->transformation( mLayer );
5069
if ( ct )
5170
{
52-
mGeometry->transform( *ct );
71+
if ( mGeometry )
72+
{
73+
mGeometry->transform( *ct );
74+
}
75+
else if ( mFeature.geometry() )
76+
{
77+
mFeature.geometry()->transform( *ct );
78+
}
5379
}
5480
}
5581
updateRect();
@@ -60,6 +86,7 @@ void QgsHighlight::init()
6086
QgsHighlight::~QgsHighlight()
6187
{
6288
delete mGeometry;
89+
delete mRenderer;
6390
}
6491

6592
/*!
@@ -71,6 +98,51 @@ void QgsHighlight::setColor( const QColor & color )
7198
QColor fillColor( color.red(), color.green(), color.blue(), 63 );
7299
mBrush.setColor( fillColor );
73100
mBrush.setStyle( Qt::SolidPattern );
101+
102+
delete mRenderer;
103+
mRenderer = 0;
104+
QgsVectorLayer *layer = vectorLayer();
105+
if ( layer && layer->rendererV2() )
106+
{
107+
mRenderer = layer->rendererV2()->clone();
108+
}
109+
if ( mRenderer )
110+
{
111+
foreach ( QgsSymbolV2* symbol, mRenderer->symbols() )
112+
{
113+
if ( !symbol ) continue;
114+
setSymbolColor( symbol, color );
115+
}
116+
}
117+
}
118+
119+
void QgsHighlight::setSymbolColor( QgsSymbolV2* symbol, const QColor & color )
120+
{
121+
if ( !symbol ) return;
122+
123+
QColor fillColor( color.red(), color.green(), color.blue(), 63 );
124+
125+
for ( int i = symbol->symbolLayerCount() - 1; i >= 0; i-- )
126+
{
127+
QgsSymbolLayerV2* symbolLayer = symbol->symbolLayer( i );
128+
if ( !symbolLayer ) continue;
129+
130+
if ( symbolLayer->subSymbol() )
131+
{
132+
setSymbolColor( symbolLayer->subSymbol(), color );
133+
}
134+
else
135+
{
136+
// We must insert additional highlight symbol layer above each original layer
137+
// otherwise lower layers would become visible through transparent fill color.
138+
QgsSymbolLayerV2* highlightLayer = symbolLayer->clone();
139+
140+
highlightLayer->setColor( color ); // line symbology layers
141+
highlightLayer->setOutlineColor( color ); // marker and fill symbology layers
142+
highlightLayer->setFillColor( fillColor ); // marker and fill symbology layers
143+
symbol->insertSymbolLayer( i + 1, highlightLayer );
144+
}
145+
}
74146
}
75147

76148
/*!
@@ -145,74 +217,96 @@ void QgsHighlight::paintPolygon( QPainter *p, QgsPolygon polygon )
145217
*/
146218
void QgsHighlight::paint( QPainter* p )
147219
{
148-
if ( !mGeometry )
149-
{
150-
return;
151-
}
152-
153-
p->setPen( mPen );
154-
p->setBrush( mBrush );
155-
156-
switch ( mGeometry->wkbType() )
220+
if ( mGeometry )
157221
{
158-
case QGis::WKBPoint:
159-
case QGis::WKBPoint25D:
160-
{
161-
paintPoint( p, mGeometry->asPoint() );
162-
}
163-
break;
222+
p->setPen( mPen );
223+
p->setBrush( mBrush );
164224

165-
case QGis::WKBMultiPoint:
166-
case QGis::WKBMultiPoint25D:
225+
switch ( mGeometry->wkbType() )
167226
{
168-
QgsMultiPoint m = mGeometry->asMultiPoint();
169-
for ( int i = 0; i < m.size(); i++ )
227+
case QGis::WKBPoint:
228+
case QGis::WKBPoint25D:
170229
{
171-
paintPoint( p, m[i] );
230+
paintPoint( p, mGeometry->asPoint() );
172231
}
173-
}
174-
break;
232+
break;
175233

176-
case QGis::WKBLineString:
177-
case QGis::WKBLineString25D:
178-
{
179-
paintLine( p, mGeometry->asPolyline() );
180-
}
181-
break;
234+
case QGis::WKBMultiPoint:
235+
case QGis::WKBMultiPoint25D:
236+
{
237+
QgsMultiPoint m = mGeometry->asMultiPoint();
238+
for ( int i = 0; i < m.size(); i++ )
239+
{
240+
paintPoint( p, m[i] );
241+
}
242+
}
243+
break;
182244

183-
case QGis::WKBMultiLineString:
184-
case QGis::WKBMultiLineString25D:
185-
{
186-
QgsMultiPolyline m = mGeometry->asMultiPolyline();
245+
case QGis::WKBLineString:
246+
case QGis::WKBLineString25D:
247+
{
248+
paintLine( p, mGeometry->asPolyline() );
249+
}
250+
break;
187251

188-
for ( int i = 0; i < m.size(); i++ )
252+
case QGis::WKBMultiLineString:
253+
case QGis::WKBMultiLineString25D:
189254
{
190-
paintLine( p, m[i] );
255+
QgsMultiPolyline m = mGeometry->asMultiPolyline();
256+
257+
for ( int i = 0; i < m.size(); i++ )
258+
{
259+
paintLine( p, m[i] );
260+
}
191261
}
192-
}
193-
break;
262+
break;
194263

195-
case QGis::WKBPolygon:
196-
case QGis::WKBPolygon25D:
197-
{
198-
paintPolygon( p, mGeometry->asPolygon() );
199-
}
200-
break;
264+
case QGis::WKBPolygon:
265+
case QGis::WKBPolygon25D:
266+
{
267+
paintPolygon( p, mGeometry->asPolygon() );
268+
}
269+
break;
201270

202-
case QGis::WKBMultiPolygon:
203-
case QGis::WKBMultiPolygon25D:
204-
{
205-
QgsMultiPolygon m = mGeometry->asMultiPolygon();
206-
for ( int i = 0; i < m.size(); i++ )
271+
case QGis::WKBMultiPolygon:
272+
case QGis::WKBMultiPolygon25D:
207273
{
208-
paintPolygon( p, m[i] );
274+
QgsMultiPolygon m = mGeometry->asMultiPolygon();
275+
for ( int i = 0; i < m.size(); i++ )
276+
{
277+
paintPolygon( p, m[i] );
278+
}
209279
}
210-
}
211-
break;
280+
break;
212281

213-
case QGis::WKBUnknown:
214-
default:
215-
return;
282+
case QGis::WKBUnknown:
283+
default:
284+
return;
285+
}
286+
}
287+
else if ( mFeature.geometry() && mRenderer )
288+
{
289+
QgsVectorLayer *layer = vectorLayer();
290+
if ( layer )
291+
{
292+
QgsRenderContext context = *( mMapCanvas->mapRenderer()->rendererContext() );
293+
294+
// The context is local rectangle of QgsHighlight we previously set.
295+
// Because QgsMapCanvasItem::setRect() adds 1 pixel on border we cannot simply
296+
// use boundingRect().height() for QgsMapToPixel height.
297+
QgsRectangle extent = rect();
298+
double height = toCanvasCoordinates( QgsPoint( extent.xMinimum(), extent.yMinimum() ) ).y() - toCanvasCoordinates( QgsPoint( extent.xMinimum(), extent.yMaximum() ) ).y();
299+
300+
QgsMapToPixel mapToPixel = QgsMapToPixel( mMapCanvas->mapUnitsPerPixel(),
301+
height, extent.yMinimum(), extent.xMinimum() );
302+
context.setMapToPixel( mapToPixel );
303+
context.setExtent( extent );
304+
context.setCoordinateTransform( 0 ); // we reprojected geometry in init()
305+
context.setPainter( p );
306+
mRenderer->startRender( context, layer );
307+
mRenderer->renderFeature( mFeature, context );
308+
mRenderer->stopRender( context );
309+
}
216310
}
217311
}
218312

@@ -234,8 +328,22 @@ void QgsHighlight::updateRect()
234328
setRect( r );
235329
setVisible( mGeometry );
236330
}
331+
else if ( mFeature.geometry() )
332+
{
333+
// We are currently using full map canvas extent for two reasons:
334+
// 1) currently there is no method in QgsFeatureRendererV2 to get rendered feature
335+
// bounding box
336+
// 2) using different extent would result in shifted fill patterns
337+
setRect( mMapCanvas->extent() );
338+
setVisible( true );
339+
}
237340
else
238341
{
239342
setRect( QgsRectangle() );
240343
}
241344
}
345+
346+
QgsVectorLayer * QgsHighlight::vectorLayer()
347+
{
348+
return dynamic_cast<QgsVectorLayer *>( mLayer );
349+
}

‎src/gui/qgshighlight.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
#define QGSHIGHLIGHT_H
1717

1818
#include "qgsmapcanvasitem.h"
19+
#include "qgsfeaturestore.h"
1920
#include "qgsgeometry.h"
21+
#include "qgsrendererv2.h"
2022
#include <QBrush>
2123
#include <QList>
2224
#include <QPen>
@@ -25,6 +27,7 @@
2527

2628
class QgsMapLayer;
2729
class QgsVectorLayer;
30+
class QgsSymbolV2;
2831

2932
/** A class for highlight features on the map.
3033
*/
@@ -33,9 +36,18 @@ class GUI_EXPORT QgsHighlight: public QgsMapCanvasItem
3336
public:
3437
QgsHighlight( QgsMapCanvas *mapCanvas, QgsGeometry *geom, QgsMapLayer *layer );
3538
QgsHighlight( QgsMapCanvas *mapCanvas, QgsGeometry *geom, QgsVectorLayer *layer );
39+
/** Constructor for highlighting true feature shape using feature attributes
40+
* and renderer.
41+
* @param mapCanvas map canvas
42+
* @param feature
43+
* @param layer vector layer
44+
*/
45+
QgsHighlight( QgsMapCanvas *mapCanvas, const QgsFeature& feature, QgsVectorLayer *layer );
3646
~QgsHighlight();
3747

3848
void setColor( const QColor & color );
49+
50+
/** Set width. Ignored in feature mode. */
3951
void setWidth( int width );
4052

4153
protected:
@@ -46,16 +58,21 @@ class GUI_EXPORT QgsHighlight: public QgsMapCanvasItem
4658

4759
private:
4860
void init();
61+
void setSymbolColor( QgsSymbolV2* symbol, const QColor & color );
4962
void paintPoint( QPainter *p, QgsPoint point );
5063
void paintLine( QPainter *p, QgsPolyline line );
5164
void paintPolygon( QPainter *p, QgsPolygon polygon );
5265

66+
QgsVectorLayer *vectorLayer();
67+
5368
QgsHighlight();
5469

5570
QBrush mBrush;
5671
QPen mPen;
5772
QgsGeometry *mGeometry;
5873
QgsMapLayer *mLayer;
74+
QgsFeature mFeature;
75+
QgsFeatureRendererV2 *mRenderer;
5976
};
6077

6178
#endif

11 commit comments

Comments
 (11)

haubourg commented on Jan 13, 2014

@haubourg
Member

Hi Radim, could you explain qhat the commit does? I remember we founded generalisation for identify highlight because it was extremely slow for big features and sometimes led to crash.. Could your commit reintroduce that?
Thanks for your lights
Régis

blazek commented on Jan 13, 2014

@blazek
MemberAuthor

The highlight was originally using a rectangle, simple line or simple polygon ignoring feature symbology. The commit renders highlighted features using current renderer with additional highlight symbol layer over each original symbol layer so that the whole current appearance of the feature including all markers, patterns etc. is highlighted.

"Real shape" in comment was meant for symbology not for geometry. It is true however, that original geometry simplification in QgsHighlight::paintPolygon() is not used anymore. OTOH, rendering is done using standard renderer with all its tricks (cut by extent, simplification...) so I believe that it may not crash (because the same methods are used to render the layer itself). It may be slower (of course, rendering of true symbology may be slower if it is complex) but it should not become so slow to make it unusable because, as said, the same algorithm is used to render the whole layer.

Could you please test with your data and computer?

timlinux commented on Jan 13, 2014

@timlinux
Member

For me the selection post Radim's patch is working very nice and quickly even for layers with quite complex polygons.

haubourg commented on Jan 13, 2014

@haubourg
Member

Thanks Radim, will test when osgeo4w builds gets it. I have some huge 400 000 vertices polygons full of rings and islands for that ( crazy dataset... )
Régis

haubourg commented on Jan 14, 2014

@haubourg
Member

Hi I tested today, and it works well and fast. Not sure if it is a problem, but I was amazed when I zoomed out.. identified object appears clipped to the old extent.. Not totally sure this is good from a user point of view the real object is not shown entirely. By myself, conscious of the performance gain, I do accept that behaviour. Maybe should we request user comments on this?

timlinux commented on Jan 14, 2014

@timlinux
Member

blazek commented on Jan 14, 2014

@blazek
MemberAuthor

Zoom out: I know about it. I'll fix that.

blazek commented on Jan 16, 2014

@blazek
MemberAuthor

I have fixed the clip on zoom out.

BTW, the highlight is painted 10 times when mouse enters or leaves map canvas, that may be additional source of possible slowness.

blazek commented on Jan 27, 2014

@blazek
MemberAuthor

As @slarosa pointed out, new highlight covers features in other layer. It is because the feature is rendered with all its symbol layers + highlight layer above each. That covers all other features. The reason for rendering all original symbol layers is that otherwise the lower symbol layers become visible if the highlight is only transparent (lower transparent highlight layers are visible).

I'll try to fix that using blending modes.

blazek commented on Feb 9, 2014

@blazek
MemberAuthor

It should be fixed in b05c93c.

slarosa commented on Feb 10, 2014

@slarosa
Member

thanks!

Please sign in to comment.