26
26
27
27
QgsMapToolRotatePointSymbols::QgsMapToolRotatePointSymbols ( QgsMapCanvas* canvas ): QgsMapToolEdit( canvas ), \
28
28
mActiveLayer( 0 ), mFeatureNumber( 0 ), mCurrentMouseAzimut( 0.0 ), mCurrentRotationFeature( 0.0 ), \
29
- mRotating( false ), mRotationItem( 0 ), mCtrlPressed(false )
29
+ mRotating( false ), mRotationItem( 0 ), mCtrlPressed( false )
30
30
{
31
31
32
32
}
@@ -123,13 +123,13 @@ void QgsMapToolRotatePointSymbols::canvasPressEvent( QMouseEvent * e )
123
123
}
124
124
125
125
mCurrentRotationFeature = attIt.value ().toDouble ();
126
- createPixmapItem ();
126
+ createPixmapItem ( pointFeature );
127
127
if ( mRotationItem )
128
128
{
129
129
mRotationItem ->setPointLocation ( snapResults.at ( 0 ).snappedVertex );
130
130
}
131
131
mCurrentMouseAzimut = calculateAzimut ( e->pos () );
132
- setPixmapItemRotation ( ( int )( mCurrentMouseAzimut ) );
132
+ setPixmapItemRotation (( int )( mCurrentMouseAzimut ) );
133
133
mRotating = true ;
134
134
}
135
135
@@ -165,17 +165,17 @@ void QgsMapToolRotatePointSymbols::canvasMoveEvent( QMouseEvent * e )
165
165
166
166
// if shift-modifier is pressed, round to 15 degrees
167
167
int displayValue;
168
- if ( e->modifiers () & Qt::ControlModifier)
168
+ if ( e->modifiers () & Qt::ControlModifier )
169
169
{
170
- displayValue = roundTo15Degrees (mCurrentRotationFeature );
170
+ displayValue = roundTo15Degrees ( mCurrentRotationFeature );
171
171
mCtrlPressed = true ;
172
172
}
173
173
else
174
174
{
175
- displayValue = (int )( mCurrentRotationFeature );
175
+ displayValue = ( int )( mCurrentRotationFeature );
176
176
mCtrlPressed = false ;
177
177
}
178
- setPixmapItemRotation (displayValue);
178
+ setPixmapItemRotation ( displayValue );
179
179
}
180
180
181
181
void QgsMapToolRotatePointSymbols::canvasReleaseEvent ( QMouseEvent * e )
@@ -187,13 +187,13 @@ void QgsMapToolRotatePointSymbols::canvasReleaseEvent( QMouseEvent * e )
187
187
188
188
// write mCurrentRotationFeature to all rotation attributes of feature (mFeatureNumber)
189
189
int rotation;
190
- if ( mCtrlPressed ) // round to 15 degrees
190
+ if ( mCtrlPressed ) // round to 15 degrees
191
191
{
192
- rotation = roundTo15Degrees (mCurrentRotationFeature );
192
+ rotation = roundTo15Degrees ( mCurrentRotationFeature );
193
193
}
194
194
else
195
195
{
196
- rotation = (int )mCurrentRotationFeature ;
196
+ rotation = ( int )mCurrentRotationFeature ;
197
197
}
198
198
199
199
QList<int >::const_iterator it = mCurrentRotationAttributes .constBegin ();
@@ -255,15 +255,51 @@ double QgsMapToolRotatePointSymbols::calculateAzimut( const QPoint& mousePos )
255
255
{
256
256
int dx = mousePos.x () - mSnappedPoint .x ();
257
257
int dy = mousePos.y () - mSnappedPoint .y ();
258
- return 180 - atan2 ( ( double ) dx, (double ) dy ) * 180.0 / M_PI;
258
+ return 180 - atan2 (( double ) dx, ( double ) dy ) * 180.0 / M_PI;
259
259
}
260
260
261
- void QgsMapToolRotatePointSymbols::createPixmapItem ()
261
+ void QgsMapToolRotatePointSymbols::createPixmapItem ( QgsFeature& f )
262
262
{
263
- delete mRotationItem ;
264
- mRotationItem = new QgsPointRotationItem ( mCanvas );
265
- mRotationItem ->setSymbol ( QgsApplication::defaultThemePath () + " mActionArrowUp.png" );
266
- mCanvas ->scene ()->addItem ( mRotationItem );
263
+ if ( !mCanvas )
264
+ {
265
+ return ;
266
+ }
267
+
268
+ if ( mActiveLayer && mActiveLayer ->renderer () )
269
+ {
270
+ // get the image that is used for that symbol, but without point rotation
271
+ QImage pointImage;
272
+ // copy renderer
273
+ QgsRenderer* r = mActiveLayer ->renderer ()->clone ();
274
+
275
+ // set all symbol fields of the cloned renderer to -1. Very ugly but necessary
276
+ QList<QgsSymbol*> symbolList ( r->symbols () );
277
+ QList<QgsSymbol*>::iterator it = symbolList.begin ();
278
+ for ( ; it != symbolList.end (); ++it )
279
+ {
280
+ ( *it )->setRotationClassificationField ( -1 );
281
+ }
282
+
283
+
284
+ // get reference to current render context
285
+ QgsMapRenderer* mapRenderer = mCanvas ->mapRenderer ();
286
+ if ( !mapRenderer )
287
+ {
288
+ delete r;
289
+ return ;
290
+ }
291
+ QgsRenderContext* renderContext = mCanvas ->mapRenderer ()->rendererContext (); // todo: check if pointers are not 0
292
+ if ( !renderContext )
293
+ {
294
+ delete r;
295
+ return ;
296
+ }
297
+
298
+ r->renderFeature ( *renderContext, f, &pointImage, false );
299
+ mRotationItem = new QgsPointRotationItem ( mCanvas );
300
+ mRotationItem ->setSymbol ( pointImage );
301
+ delete r;
302
+ }
267
303
}
268
304
269
305
void QgsMapToolRotatePointSymbols::setPixmapItemRotation ( double rotation )
@@ -272,9 +308,9 @@ void QgsMapToolRotatePointSymbols::setPixmapItemRotation( double rotation )
272
308
mRotationItem ->update ();
273
309
}
274
310
275
- int QgsMapToolRotatePointSymbols::roundTo15Degrees (double n)
311
+ int QgsMapToolRotatePointSymbols::roundTo15Degrees ( double n )
276
312
{
277
- int m = (int )( n / 15.0 + 0.5 );
278
- return (m * 15 );
313
+ int m = ( int )( n / 15.0 + 0.5 );
314
+ return ( m * 15 );
279
315
}
280
316
0 commit comments