Skip to content
Permalink
Browse files

make annotations aware of crs (fixes #3618)

  • Loading branch information
SebDieBln committed Dec 1, 2015
1 parent 62f90d0 commit 66a83bd205989e4ebd74a9a5c80acf19e7fa58eb
Showing with 41 additions and 1 deletion.
  1. +6 −0 python/gui/qgsannotationitem.sip
  2. +11 −0 src/app/qgisapp.cpp
  3. +1 −0 src/app/qgisapp.h
  4. +13 −1 src/gui/qgsannotationitem.cpp
  5. +10 −0 src/gui/qgsannotationitem.h
@@ -44,6 +44,12 @@ class QgsAnnotationItem: QgsMapCanvasItem
virtual void setMapPosition( const QgsPoint& pos );
QgsPoint mapPosition() const;

/** Sets the CRS of the map position.
@param crs the CRS to set */
virtual void setMapPositionCrs( const QgsCoordinateReferenceSystem& crs );
/** Returns the CRS of the map position.*/
QgsCoordinateReferenceSystem mapPositionCrs() const;

void setFrameSize( const QSizeF& size );
QSizeF frameSize() const;

@@ -2316,6 +2316,9 @@ void QgisApp::setupConnections()
connect( mRenderSuppressionCBox, SIGNAL( toggled( bool ) ),
mMapCanvas, SLOT( setRenderFlag( bool ) ) );

connect( mMapCanvas, SIGNAL( destinationCrsChanged() ),
this, SLOT( reprojectAnnotations() ) );

// connect MapCanvas keyPress event so we can check if selected feature collection must be deleted
connect( mMapCanvas, SIGNAL( keyPressed( QKeyEvent * ) ),
this, SLOT( mapCanvas_keyPressed( QKeyEvent * ) ) );
@@ -5161,6 +5164,14 @@ void QgisApp::modifyAnnotation()
mMapCanvas->setMapTool( mMapTools.mAnnotation );
}

void QgisApp::reprojectAnnotations()
{
Q_FOREACH ( QgsAnnotationItem * annotation, annotationItems() )
{
annotation->updatePosition();
}
}

void QgisApp::labelingFontNotFound( QgsVectorLayer* vlayer, const QString& fontfamily )
{
// TODO: update when pref for how to resolve missing family (use matching algorithm or just default font) is implemented
@@ -1128,6 +1128,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
void addHtmlAnnotation();
void addSvgAnnotation();
void modifyAnnotation();
void reprojectAnnotations();

/** Alerts user when labeling font for layer has not been found on system */
void labelingFontNotFound( QgsVectorLayer *vlayer, const QString& fontfamily );
@@ -26,6 +26,7 @@
QgsAnnotationItem::QgsAnnotationItem( QgsMapCanvas* mapCanvas )
: QgsMapCanvasItem( mapCanvas )
, mMapPositionFixed( true )
, mMapPositionCrs( QgsCoordinateReferenceSystem() )
, mOffsetFromReferencePoint( QPointF( 50, -50 ) )
, mBalloonSegment( -1 )
{
@@ -53,6 +54,12 @@ void QgsAnnotationItem::setMapPosition( const QgsPoint& pos )
{
mMapPosition = pos;
setPos( toCanvasCoordinates( mMapPosition ) );
mMapPositionCrs = mMapCanvas->mapSettings().destinationCrs();
}

void QgsAnnotationItem::setMapPositionCrs( const QgsCoordinateReferenceSystem& crs )
{
mMapPositionCrs = crs;
}

void QgsAnnotationItem::setOffsetFromReferencePoint( const QPointF& offset )
@@ -85,7 +92,8 @@ void QgsAnnotationItem::updatePosition()
{
if ( mMapPositionFixed )
{
setPos( toCanvasCoordinates( mMapPosition ) );
QgsCoordinateTransform t( mMapPositionCrs, mMapCanvas->mapSettings().destinationCrs() );
setPos( toCanvasCoordinates( t.transform( mMapPosition ) ) );
}
else
{
@@ -392,6 +400,8 @@ void QgsAnnotationItem::_writeXML( QDomDocument& doc, QDomElement& itemElem ) co
annotationElem.setAttribute( "mapPositionFixed", mMapPositionFixed );
annotationElem.setAttribute( "mapPosX", qgsDoubleToString( mMapPosition.x() ) );
annotationElem.setAttribute( "mapPosY", qgsDoubleToString( mMapPosition.y() ) );
if ( mMapPositionCrs.isValid() )
mMapPositionCrs.writeXML( annotationElem, doc );
annotationElem.setAttribute( "offsetX", qgsDoubleToString( mOffsetFromReferencePoint.x() ) );
annotationElem.setAttribute( "offsetY", qgsDoubleToString( mOffsetFromReferencePoint.y() ) );
annotationElem.setAttribute( "frameWidth", QString::number( mFrameSize.width() ) );
@@ -431,6 +441,8 @@ void QgsAnnotationItem::_readXML( const QDomDocument& doc, const QDomElement& an
mapPos.setX( annotationElem.attribute( "mapPosX", "0" ).toDouble() );
mapPos.setY( annotationElem.attribute( "mapPosY", "0" ).toDouble() );
mMapPosition = mapPos;
if ( !mMapPositionCrs.readXML( annotationElem ) )
mMapPositionCrs = mMapCanvas->mapSettings().destinationCrs();
mFrameBorderWidth = annotationElem.attribute( "frameBorderWidth", "0.5" ).toDouble();
mFrameColor.setNamedColor( annotationElem.attribute( "frameColor", "#000000" ) );
mFrameColor.setAlpha( annotationElem.attribute( "frameColorAlpha", "255" ).toInt() );
@@ -19,6 +19,7 @@
#define QGSANNOTATIONITEM_H

#include "qgsmapcanvasitem.h"
#include "qgscoordinatereferencesystem.h"

class QDomDocument;
class QDomElement;
@@ -68,6 +69,12 @@ class GUI_EXPORT QgsAnnotationItem: public QgsMapCanvasItem
virtual void setMapPosition( const QgsPoint& pos );
QgsPoint mapPosition() const { return mMapPosition; }

/** Sets the CRS of the map position.
@param crs the CRS to set */
virtual void setMapPositionCrs( const QgsCoordinateReferenceSystem& crs );
/** Returns the CRS of the map position.*/
QgsCoordinateReferenceSystem mapPositionCrs() const { return mMapPositionCrs; }

void setFrameSize( const QSizeF& size );
QSizeF frameSize() const { return mFrameSize; }

@@ -98,6 +105,9 @@ class GUI_EXPORT QgsAnnotationItem: public QgsMapCanvasItem
bool mMapPositionFixed;
/** Map position (in case mMapPositionFixed is true)*/
QgsPoint mMapPosition;
/** CRS of the map position */
QgsCoordinateReferenceSystem mMapPositionCrs;

/** Describes the shift of the item content box to the reference point*/
QPointF mOffsetFromReferencePoint;

0 comments on commit 66a83bd

Please sign in to comment.
You can’t perform that action at this time.