Skip to content

Commit 94e76d8

Browse files
author
mhugent
committedSep 16, 2009
[FEATURE]: add tool to graphically rotate points (by changing the value of the rotation field). Needs some more beautifying, perhaps a nicer arrow
git-svn-id: http://svn.osgeo.org/qgis/trunk@11671 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 1669b15 commit 94e76d8

File tree

8 files changed

+501
-1
lines changed

8 files changed

+501
-1
lines changed
 
Loading

‎src/app/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ SET(QGIS_APP_SRCS
4040
qgsmaptoolmovevertex.cpp
4141
qgsmaptoolnodetool.cpp
4242
qgsmaptoolreshape.cpp
43+
qgsmaptoolrotatepointsymbols.cpp
4344
qgsmaptoolselect.cpp
4445
qgsmaptoolsimplify.cpp
4546
qgsmaptoolsplitfeatures.cpp
@@ -52,6 +53,7 @@ SET(QGIS_APP_SRCS
5253
qgsogrsublayersdialog.cpp
5354
qgsoptions.cpp
5455
qgspastetransformations.cpp
56+
qgspointrotationitem.cpp
5557
qgspluginitem.cpp
5658
qgspluginmanager.cpp
5759
qgspluginmetadata.cpp

‎src/app/qgisapp.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@
172172
#include "qgsmaptoolpan.h"
173173
#include "qgsmaptoolselect.h"
174174
#include "qgsmaptoolreshape.h"
175+
#include "qgsmaptoolrotatepointsymbols.h"
175176
#include "qgsmaptoolsplitfeatures.h"
176177
#include "qgsmaptoolvertexedit.h"
177178
#include "qgsmaptoolzoom.h"
@@ -740,6 +741,12 @@ void QgisApp::createActions()
740741
connect( mActionNodeTool, SIGNAL( triggered() ), this, SLOT( nodeTool() ) );
741742
mActionNodeTool->setEnabled( false );
742743

744+
mActionRotatePointSymbols = new QAction( getThemeIcon( "mActionRotatePointSymbols.png" ), tr( "Rotate Point Symbols" ), this );
745+
shortcuts->registerAction( mActionRotatePointSymbols );
746+
mActionRotatePointSymbols->setStatusTip( tr( "Rotate Point Symbols" ) );
747+
connect( mActionRotatePointSymbols, SIGNAL( triggered() ), this, SLOT( rotatePointSymbols() ) );
748+
mActionRotatePointSymbols->setEnabled( false );
749+
743750
// View Menu Items
744751

745752
mActionPan = new QAction( getThemeIcon( "mActionPan.png" ), tr( "Pan Map" ), this );
@@ -1094,7 +1101,8 @@ void QgisApp::createActionGroups()
10941101
mMapToolGroup->addAction( mActionMergeFeatures );
10951102
mActionNodeTool->setCheckable( true );
10961103
mMapToolGroup->addAction( mActionNodeTool );
1097-
1104+
mActionRotatePointSymbols->setCheckable( true );
1105+
mMapToolGroup->addAction( mActionRotatePointSymbols );
10981106
}
10991107

11001108
void QgisApp::createMenus()
@@ -1189,6 +1197,7 @@ void QgisApp::createMenus()
11891197
mEditMenu->addAction( mActionSplitFeatures );
11901198
mEditMenu->addAction( mActionMergeFeatures );
11911199
mEditMenu->addAction( mActionNodeTool );
1200+
mEditMenu->addAction( mActionRotatePointSymbols );
11921201

11931202
if ( layout == QDialogButtonBox::GnomeLayout || layout == QDialogButtonBox::MacLayout )
11941203
{
@@ -1398,6 +1407,7 @@ void QgisApp::createToolBars()
13981407
mAdvancedDigitizeToolBar->addAction( mActionSplitFeatures );
13991408
mAdvancedDigitizeToolBar->addAction( mActionMergeFeatures );
14001409
mAdvancedDigitizeToolBar->addAction( mActionNodeTool );
1410+
mAdvancedDigitizeToolBar->addAction( mActionRotatePointSymbols );
14011411
mToolbarMenu->addAction( mAdvancedDigitizeToolBar->toggleViewAction() );
14021412

14031413

@@ -1788,6 +1798,8 @@ void QgisApp::createCanvas()
17881798
mMapTools.mDeletePart->setAction( mActionDeletePart );
17891799
mMapTools.mNodeTool = new QgsMapToolNodeTool( mMapCanvas );
17901800
mMapTools.mNodeTool->setAction( mActionNodeTool );
1801+
mMapTools.mRotatePointSymbolsTool = new QgsMapToolRotatePointSymbols( mMapCanvas );
1802+
mMapTools.mRotatePointSymbolsTool->setAction( mActionRotatePointSymbols );
17911803
//ensure that non edit tool is initialised or we will get crashes in some situations
17921804
mNonEditMapTool = mMapTools.mPan;
17931805
}
@@ -4298,6 +4310,11 @@ void QgisApp::nodeTool()
42984310
mMapCanvas->setMapTool( mMapTools.mNodeTool );
42994311
}
43004312

4313+
void QgisApp::rotatePointSymbols()
4314+
{
4315+
mMapCanvas->setMapTool( mMapTools.mRotatePointSymbolsTool );
4316+
}
4317+
43014318
void QgisApp::splitFeatures()
43024319
{
43034320
mMapCanvas->setMapTool( mMapTools.mSplitFeatures );
@@ -5639,11 +5656,19 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
56395656
mActionSplitFeatures->setEnabled( false );
56405657
mActionSimplifyFeature->setEnabled( false );
56415658
mActionDeleteRing->setEnabled( false );
5659+
mActionRotatePointSymbols->setEnabled( false );
56425660

56435661
if ( vlayer->isEditable() && dprovider->capabilities() & QgsVectorDataProvider::ChangeGeometries )
56445662
{
56455663
mActionMoveVertex->setEnabled( true );
56465664
}
5665+
if ( vlayer->isEditable() && dprovider->capabilities() & QgsVectorDataProvider::ChangeAttributeValues )
5666+
{
5667+
if ( QgsMapToolRotatePointSymbols::layerIsRotatable( vlayer ) )
5668+
{
5669+
mActionRotatePointSymbols->setEnabled( true );
5670+
}
5671+
}
56475672
return;
56485673
}
56495674
else if ( vlayer->geometryType() == QGis::Line )
@@ -5752,6 +5777,9 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
57525777
mActionCopyFeatures->setEnabled( false );
57535778
mActionCutFeatures->setEnabled( false );
57545779
mActionPasteFeatures->setEnabled( false );
5780+
mActionRotatePointSymbols->setEnabled( false );
5781+
mActionNodeTool->setEnabled( false );
5782+
mActionDeletePart->setEnabled( false );
57555783

57565784
//NOTE: This check does not really add any protection, as it is called on load not on layer select/activate
57575785
//If you load a layer with a provider and idenitfy ability then load another without, the tool would be disabled for both

‎src/app/qgisapp.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,8 @@ class QgisApp : public QMainWindow
523523
void mergeSelectedFeatures();
524524
//! provides operations with nodes
525525
void nodeTool();
526+
//! activates the rotate points tool
527+
void rotatePointSymbols();
526528

527529
//! activates the selection tool
528530
void select();
@@ -742,6 +744,7 @@ class QgisApp : public QMainWindow
742744
QAction *mActionDeletePart;
743745
QAction *mActionMergeFeatures;
744746
QAction *mActionNodeTool;
747+
QAction *mActionRotatePointSymbols;
745748
QAction *mActionEditSeparator3;
746749

747750
QAction *mActionPan;
@@ -864,6 +867,7 @@ class QgisApp : public QMainWindow
864867
QgsMapTool* mDeleteRing;
865868
QgsMapTool* mDeletePart;
866869
QgsMapTool* mNodeTool;
870+
QgsMapTool* mRotatePointSymbolsTool;
867871
} mMapTools;
868872

869873
QgsMapTool *mNonEditMapTool;
Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
/***************************************************************************
2+
qgsmaptoolrotatepointsymbols.cpp
3+
--------------------------------
4+
begin : September 2009
5+
copyright : (C) 2009 by Marco Hugentobler
6+
email : marco at hugis dot net
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include "qgsmaptoolrotatepointsymbols.h"
17+
#include "qgsapplication.h"
18+
#include "qgsmapcanvas.h"
19+
#include "qgspointrotationitem.h"
20+
#include "qgsrenderer.h"
21+
#include "qgssymbol.h"
22+
#include "qgsvectorlayer.h"
23+
#include <QGraphicsPixmapItem>
24+
#include <QMessageBox>
25+
#include <QMouseEvent>
26+
27+
QgsMapToolRotatePointSymbols::QgsMapToolRotatePointSymbols( QgsMapCanvas* canvas ): QgsMapToolEdit( canvas ), \
28+
mActiveLayer( 0 ), mFeatureNumber( 0 ), mCurrentMouseAzimut( 0.0 ), mCurrentRotationFeature( 0.0 ), mRotating( false ), mRotationItem( 0 )
29+
{
30+
31+
}
32+
33+
QgsMapToolRotatePointSymbols::~QgsMapToolRotatePointSymbols()
34+
{
35+
delete mRotationItem;
36+
}
37+
38+
bool QgsMapToolRotatePointSymbols::layerIsRotatable( QgsMapLayer* ml )
39+
{
40+
if ( !ml )
41+
{
42+
return false;
43+
}
44+
45+
//a vector layer
46+
QgsVectorLayer* vLayer = dynamic_cast<QgsVectorLayer*>( ml );
47+
if ( !vLayer )
48+
{
49+
return false;
50+
}
51+
52+
//does it have point or multipoint type?
53+
if ( vLayer->geometryType() != QGis::Point )
54+
{
55+
return false;
56+
}
57+
58+
//does it have a least one rotation attribute?
59+
QList<int> rotationAttributes;
60+
layerRotationAttributes( vLayer, rotationAttributes );
61+
if ( rotationAttributes.size() < 1 )
62+
{
63+
return false;
64+
}
65+
return true;
66+
}
67+
68+
void QgsMapToolRotatePointSymbols::canvasPressEvent( QMouseEvent * e )
69+
{
70+
if ( !mCanvas )
71+
{
72+
return;
73+
}
74+
75+
mActiveLayer = currentVectorLayer();
76+
if ( !mActiveLayer )
77+
{
78+
return;
79+
}
80+
81+
if ( mActiveLayer->geometryType() != QGis::Point || !mActiveLayer->isEditable() )
82+
{
83+
return;
84+
}
85+
86+
//find the closest feature to the pressed position
87+
QgsMapCanvasSnapper canvasSnapper( mCanvas );
88+
QList<QgsSnappingResult> snapResults;
89+
if ( canvasSnapper.snapToCurrentLayer( e->pos(), snapResults, QgsSnapper::SnapToVertex, -1 ) != 0 || snapResults.size() < 1 )
90+
{
91+
QMessageBox::critical( 0, tr( "No point feature" ), tr( "No point feature was detected at the clicked position. Please click closer to the feature or enhance the search tolerance under Settings->Options->Digitizing->Serch radius for vertex edits" ) );
92+
return; //error during snapping
93+
}
94+
95+
mFeatureNumber = snapResults.at( 0 ).snappedAtGeometry;
96+
97+
//get list with renderer rotation attributes
98+
if ( layerRotationAttributes( mActiveLayer, mCurrentRotationAttributes ) != 0 )
99+
{
100+
return;
101+
}
102+
103+
if ( mCurrentRotationAttributes.size() < 1 )
104+
{
105+
QMessageBox::critical( 0, tr( "No rotation Attributes" ), tr( "The active point layer does not have a rotation attribute" ) );
106+
return;
107+
}
108+
109+
mSnappedPoint = toCanvasCoordinates( snapResults.at( 0 ).snappedVertex );
110+
111+
//find out initial arrow direction
112+
QgsFeature pointFeature;
113+
if ( !mActiveLayer->featureAtId( mFeatureNumber, pointFeature, false, true ) )
114+
{
115+
return;
116+
}
117+
const QgsAttributeMap pointFeatureAttributes = pointFeature.attributeMap();
118+
const QgsAttributeMap::const_iterator attIt = pointFeatureAttributes.find( mCurrentRotationAttributes.at( 0 ) );
119+
if ( attIt == pointFeatureAttributes.constEnd() )
120+
{
121+
return;
122+
}
123+
124+
mCurrentRotationFeature = attIt.value().toDouble();
125+
createPixmapItem();
126+
if ( mRotationItem )
127+
{
128+
mRotationItem->setPointLocation( snapResults.at( 0 ).snappedVertex );
129+
}
130+
mCurrentMouseAzimut = calculateAzimut( e->pos() );
131+
setPixmapItemRotation( mCurrentMouseAzimut );
132+
mRotating = true;
133+
}
134+
135+
void QgsMapToolRotatePointSymbols::canvasMoveEvent( QMouseEvent * e )
136+
{
137+
if ( !mRotating )
138+
{
139+
return;
140+
}
141+
142+
double azimut = calculateAzimut( e->pos() );
143+
double azimutDiff = azimut - mCurrentMouseAzimut;
144+
145+
//assign new feature rotation, making sure to respect the 0 - 360 degree range
146+
mCurrentRotationFeature += azimutDiff;
147+
if ( mCurrentRotationFeature < 0 )
148+
{
149+
mCurrentRotationFeature = 360 - mCurrentRotationFeature;
150+
}
151+
else if ( mCurrentRotationFeature >= 360 )
152+
{
153+
mCurrentRotationFeature -= 360;
154+
}
155+
mCurrentMouseAzimut = azimut;
156+
if ( mCurrentMouseAzimut < 0 )
157+
{
158+
mCurrentMouseAzimut = 360 - mCurrentMouseAzimut;
159+
}
160+
else if ( mCurrentMouseAzimut >= 360 )
161+
{
162+
mCurrentMouseAzimut -= 360;
163+
}
164+
setPixmapItemRotation( mCurrentRotationFeature );
165+
}
166+
167+
void QgsMapToolRotatePointSymbols::canvasReleaseEvent( QMouseEvent * e )
168+
{
169+
if ( mRotating && mActiveLayer )
170+
{
171+
mActiveLayer->beginEditCommand( tr( "Rotate symbol" ) );
172+
bool rotateSuccess = true;
173+
174+
//write mCurrentRotationFeature to all rotation attributes of feature (mFeatureNumber)
175+
QList<int>::const_iterator it = mCurrentRotationAttributes.constBegin();
176+
for ( ; it != mCurrentRotationAttributes.constEnd(); ++it )
177+
{
178+
if ( !mActiveLayer->changeAttributeValue( mFeatureNumber, *it, mCurrentRotationFeature, true ) )
179+
{
180+
rotateSuccess = false;
181+
}
182+
}
183+
184+
if ( rotateSuccess )
185+
{
186+
mActiveLayer->endEditCommand();
187+
}
188+
else
189+
{
190+
mActiveLayer->destroyEditCommand();
191+
}
192+
}
193+
mRotating = false;
194+
delete mRotationItem;
195+
mRotationItem = 0;
196+
mCanvas->refresh();
197+
}
198+
199+
int QgsMapToolRotatePointSymbols::layerRotationAttributes( const QgsVectorLayer* vl, QList<int>& attList )
200+
{
201+
attList.clear();
202+
if ( !vl )
203+
{
204+
return 1;
205+
}
206+
207+
//get renderer
208+
const QgsRenderer* layerRenderer = vl->renderer();
209+
if ( !layerRenderer )
210+
{
211+
return 2;
212+
}
213+
214+
//get renderer symbols
215+
const QList<QgsSymbol*> rendererSymbols = layerRenderer->symbols();
216+
int currentRotationAttribute;
217+
218+
QList<QgsSymbol*>::const_iterator symbolIt = rendererSymbols.constBegin();
219+
for ( ; symbolIt != rendererSymbols.constEnd(); ++symbolIt )
220+
{
221+
currentRotationAttribute = ( *symbolIt )->rotationClassificationField();
222+
if ( currentRotationAttribute >= 0 )
223+
{
224+
attList.push_back( currentRotationAttribute );
225+
}
226+
}
227+
return 0;
228+
}
229+
230+
double QgsMapToolRotatePointSymbols::calculateAzimut( const QPoint& mousePos )
231+
{
232+
int dx = mousePos.x() - mSnappedPoint.x();
233+
int dy = mousePos.y() - mSnappedPoint.y();
234+
return 180 - atan2( dx, dy ) * 180.0 / M_PI;
235+
}
236+
237+
void QgsMapToolRotatePointSymbols::createPixmapItem()
238+
{
239+
delete mRotationItem;
240+
mRotationItem = new QgsPointRotationItem( mCanvas );
241+
mRotationItem->setSymbol( QgsApplication::defaultThemePath() + "mActionArrowUp.png" );
242+
mCanvas->scene()->addItem( mRotationItem );
243+
}
244+
245+
void QgsMapToolRotatePointSymbols::setPixmapItemRotation( double rotation )
246+
{
247+
mRotationItem->setSymbolRotation( rotation );
248+
mRotationItem->update();
249+
}
250+
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/***************************************************************************
2+
qgsmaptoolrotatepointsymbols.h
3+
---------------------
4+
begin : September 2009
5+
copyright : (C) 2009 by Marco Hugentobler
6+
email : marco at hugis dot net
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#ifndef QGSMAPTOOLROTATEPOINTSYMBOLS_H
17+
#define QGSMAPTOOLROTATEPOINTSYMBOLS_H
18+
19+
#include "qgsmaptooledit.h"
20+
21+
class QgsPointRotationItem;
22+
23+
/**A class that allows to interactively manipulate the value of the rotation field(s) for point layers*/
24+
class QgsMapToolRotatePointSymbols: public QgsMapToolEdit
25+
{
26+
public:
27+
QgsMapToolRotatePointSymbols( QgsMapCanvas* canvas );
28+
~QgsMapToolRotatePointSymbols();
29+
30+
void canvasPressEvent( QMouseEvent * e );
31+
void canvasMoveEvent( QMouseEvent * e );
32+
void canvasReleaseEvent( QMouseEvent * e );
33+
34+
bool isEditTool() {return true;}
35+
36+
/**Returns true if the symbols of a maplayer can be rotated. This means the layer \
37+
is a vector layer, has type point or multipoint and has at least one rotation attribute in the renderer*/
38+
static bool layerIsRotatable( QgsMapLayer* ml );
39+
40+
private:
41+
QgsVectorLayer* mActiveLayer;
42+
int mFeatureNumber;
43+
/**Last azimut between mouse and edited point*/
44+
double mCurrentMouseAzimut;
45+
/**Last feature rotation*/
46+
double mCurrentRotationFeature;
47+
bool mRotating;
48+
QList<int> mCurrentRotationAttributes;
49+
/**Screen coordinate of the snaped feature*/
50+
QPoint mSnappedPoint;
51+
/**Item that displays rotation during mouse move*/
52+
QgsPointRotationItem* mRotationItem;
53+
54+
/**Finds out the rotation attributes of mActiveLayers
55+
@param vl the point vector layer
56+
@param attList out: the list containing the rotation indices
57+
@return 0 in case of success*/
58+
static int layerRotationAttributes( const QgsVectorLayer* vl, QList<int>& attList );
59+
void drawArrow( double azimut ) const;
60+
/**Calculates the azimut between mousePos and mSnappedPoint*/
61+
double calculateAzimut( const QPoint& mousePos );
62+
/**Create item that shows rotation to the user*/
63+
void createPixmapItem();
64+
/**Sets the rotation of the pixmap item*/
65+
void setPixmapItemRotation( double rotation );
66+
};
67+
68+
#endif // QGSMAPTOOLROTATEPOINTSYMBOLS_H

‎src/app/qgspointrotationitem.cpp

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/***************************************************************************
2+
qgspointrotationitem.cpp
3+
------------------------
4+
begin : September 2009
5+
copyright : (C) 2009 by Marco Hugentobler
6+
email : marco at hugis dot net
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include "qgspointrotationitem.h"
17+
#include <QPainter>
18+
19+
#ifndef Q_OS_MACX
20+
#include <cmath>
21+
#else
22+
#include <math.h>
23+
#endif
24+
25+
QgsPointRotationItem::QgsPointRotationItem( QgsMapCanvas* canvas ): QgsMapCanvasItem( canvas ), mRotation( 0.0 )
26+
{
27+
//setup font
28+
mFont.setPointSize( 12 );
29+
mFont.setBold( true );
30+
}
31+
32+
QgsPointRotationItem::QgsPointRotationItem(): QgsMapCanvasItem( 0 ), mRotation( 0.0 )
33+
{
34+
35+
}
36+
37+
QgsPointRotationItem::~QgsPointRotationItem()
38+
{
39+
40+
}
41+
42+
void QgsPointRotationItem::paint( QPainter * painter )
43+
{
44+
if ( !painter )
45+
{
46+
return;
47+
}
48+
painter->save();
49+
50+
//do a bit of trigonometry to find out how to transform a rotated item such that the center point is at the point feature
51+
double x = 0;
52+
double y = 0;
53+
double h, dAngel;
54+
if ( mPixmap.width() > 0 && mPixmap.height() > 0 )
55+
{
56+
h = sqrt( mPixmap.width() * mPixmap.width() + mPixmap.height() * mPixmap.height() ) / 2; //the half of the item diagonal
57+
dAngel = acos( mPixmap.width() / ( h * 2 ) ) * 180 / M_PI; //the diagonal angel of the original rect
58+
x = h * cos(( mRotation - dAngel ) * M_PI / 180 );
59+
y = h * sin(( mRotation - dAngel ) * M_PI / 180 );
60+
}
61+
62+
//painter->translate(-mPixmap.width() / 2.0, -mPixmap.width() / 2.0);
63+
painter->rotate( mRotation );
64+
painter->translate( x - mPixmap.width() / 2.0, -y - mPixmap.height() / 2.0 );
65+
painter->drawPixmap( 0, 0, mPixmap );
66+
67+
//draw numeric value beside the symbol
68+
painter->restore();
69+
QFontMetricsF fm( mFont );
70+
painter->fillRect( mPixmap.width(), 0, mItemSize.width() - mPixmap.width(), mItemSize.height(), QColor( Qt::white ) );
71+
painter->setFont( mFont );
72+
painter->drawText( mPixmap.width(), mPixmap.height() / 2.0 + fm.height() / 2.0, QString::number( mRotation, 'f', 2 ) );
73+
}
74+
75+
void QgsPointRotationItem::setPointLocation( const QgsPoint& p )
76+
{
77+
QPointF transformedPoint = toCanvasCoordinates( p );
78+
setPos( transformedPoint.x() - mPixmap.width() / 2.0, transformedPoint.y() - mPixmap.height() / 2.0 );
79+
}
80+
81+
void QgsPointRotationItem::setSymbol( const QString& symbolPath )
82+
{
83+
mPixmap = QPixmap( symbolPath );
84+
QFontMetricsF fm( mFont );
85+
mItemSize.setWidth( mPixmap.width() + fm.width( "360.99" ) );
86+
double pixmapHeight = mPixmap.height();
87+
double fontHeight = fm.height();
88+
if ( pixmapHeight >= fontHeight )
89+
{
90+
mItemSize.setHeight( mPixmap.height() );
91+
}
92+
else
93+
{
94+
mItemSize.setHeight( fm.height() );
95+
}
96+
}
97+

‎src/app/qgspointrotationitem.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/***************************************************************************
2+
qgspointrotationitem.h
3+
----------------------
4+
begin : September 2009
5+
copyright : (C) 2009 by Marco Hugentobler
6+
email : marco at hugis dot net
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#ifndef QGSPOINTROTATIONITEM_H
17+
#define QGSPOINTROTATIONITEM_H
18+
19+
#include "qgsmapcanvasitem.h"
20+
#include <QFontMetricsF>
21+
#include <QPixmap>
22+
23+
/**An item that shows a rotated point symbol (e.g. arrow) centered to a map location together with a text displaying the rotation value*/
24+
class QgsPointRotationItem: public QgsMapCanvasItem
25+
{
26+
public:
27+
QgsPointRotationItem( QgsMapCanvas* canvas );
28+
~QgsPointRotationItem();
29+
30+
void paint( QPainter * painter );
31+
32+
/**Sets the center point of the rotation symbol (in map coordinates)*/
33+
void setPointLocation( const QgsPoint& p );
34+
35+
/**Sets the rotation of the symbol and displays the new rotation number. \
36+
Units are degrees, starting from north direction, clockwise direction*/
37+
void setSymbolRotation( double r ) {mRotation = r;}
38+
39+
/**Sets a symbol from image file*/
40+
void setSymbol( const QString& symbolPath );
41+
42+
private:
43+
QgsPointRotationItem();
44+
/**Font to display the numerical rotation values*/
45+
QFont mFont;
46+
/**Symboll pixmap*/
47+
QPixmap mPixmap;
48+
double mRotation;
49+
};
50+
51+
#endif // QGSPOINTROTATIONITEM_H

0 commit comments

Comments
 (0)
Please sign in to comment.