mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-18 00:03:05 -04:00
make annotations aware of crs (fixes #3618)
This commit is contained in:
parent
62f90d0c5e
commit
66a83bd205
@ -44,6 +44,12 @@ class QgsAnnotationItem: QgsMapCanvasItem
|
|||||||
virtual void setMapPosition( const QgsPoint& pos );
|
virtual void setMapPosition( const QgsPoint& pos );
|
||||||
QgsPoint mapPosition() const;
|
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 );
|
void setFrameSize( const QSizeF& size );
|
||||||
QSizeF frameSize() const;
|
QSizeF frameSize() const;
|
||||||
|
|
||||||
|
@ -2316,6 +2316,9 @@ void QgisApp::setupConnections()
|
|||||||
connect( mRenderSuppressionCBox, SIGNAL( toggled( bool ) ),
|
connect( mRenderSuppressionCBox, SIGNAL( toggled( bool ) ),
|
||||||
mMapCanvas, SLOT( setRenderFlag( 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 MapCanvas keyPress event so we can check if selected feature collection must be deleted
|
||||||
connect( mMapCanvas, SIGNAL( keyPressed( QKeyEvent * ) ),
|
connect( mMapCanvas, SIGNAL( keyPressed( QKeyEvent * ) ),
|
||||||
this, SLOT( mapCanvas_keyPressed( QKeyEvent * ) ) );
|
this, SLOT( mapCanvas_keyPressed( QKeyEvent * ) ) );
|
||||||
@ -5161,6 +5164,14 @@ void QgisApp::modifyAnnotation()
|
|||||||
mMapCanvas->setMapTool( mMapTools.mAnnotation );
|
mMapCanvas->setMapTool( mMapTools.mAnnotation );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QgisApp::reprojectAnnotations()
|
||||||
|
{
|
||||||
|
Q_FOREACH ( QgsAnnotationItem * annotation, annotationItems() )
|
||||||
|
{
|
||||||
|
annotation->updatePosition();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void QgisApp::labelingFontNotFound( QgsVectorLayer* vlayer, const QString& fontfamily )
|
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
|
// 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 addHtmlAnnotation();
|
||||||
void addSvgAnnotation();
|
void addSvgAnnotation();
|
||||||
void modifyAnnotation();
|
void modifyAnnotation();
|
||||||
|
void reprojectAnnotations();
|
||||||
|
|
||||||
/** Alerts user when labeling font for layer has not been found on system */
|
/** Alerts user when labeling font for layer has not been found on system */
|
||||||
void labelingFontNotFound( QgsVectorLayer *vlayer, const QString& fontfamily );
|
void labelingFontNotFound( QgsVectorLayer *vlayer, const QString& fontfamily );
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
QgsAnnotationItem::QgsAnnotationItem( QgsMapCanvas* mapCanvas )
|
QgsAnnotationItem::QgsAnnotationItem( QgsMapCanvas* mapCanvas )
|
||||||
: QgsMapCanvasItem( mapCanvas )
|
: QgsMapCanvasItem( mapCanvas )
|
||||||
, mMapPositionFixed( true )
|
, mMapPositionFixed( true )
|
||||||
|
, mMapPositionCrs( QgsCoordinateReferenceSystem() )
|
||||||
, mOffsetFromReferencePoint( QPointF( 50, -50 ) )
|
, mOffsetFromReferencePoint( QPointF( 50, -50 ) )
|
||||||
, mBalloonSegment( -1 )
|
, mBalloonSegment( -1 )
|
||||||
{
|
{
|
||||||
@ -53,6 +54,12 @@ void QgsAnnotationItem::setMapPosition( const QgsPoint& pos )
|
|||||||
{
|
{
|
||||||
mMapPosition = pos;
|
mMapPosition = pos;
|
||||||
setPos( toCanvasCoordinates( mMapPosition ) );
|
setPos( toCanvasCoordinates( mMapPosition ) );
|
||||||
|
mMapPositionCrs = mMapCanvas->mapSettings().destinationCrs();
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgsAnnotationItem::setMapPositionCrs( const QgsCoordinateReferenceSystem& crs )
|
||||||
|
{
|
||||||
|
mMapPositionCrs = crs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsAnnotationItem::setOffsetFromReferencePoint( const QPointF& offset )
|
void QgsAnnotationItem::setOffsetFromReferencePoint( const QPointF& offset )
|
||||||
@ -85,7 +92,8 @@ void QgsAnnotationItem::updatePosition()
|
|||||||
{
|
{
|
||||||
if ( mMapPositionFixed )
|
if ( mMapPositionFixed )
|
||||||
{
|
{
|
||||||
setPos( toCanvasCoordinates( mMapPosition ) );
|
QgsCoordinateTransform t( mMapPositionCrs, mMapCanvas->mapSettings().destinationCrs() );
|
||||||
|
setPos( toCanvasCoordinates( t.transform( mMapPosition ) ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -392,6 +400,8 @@ void QgsAnnotationItem::_writeXML( QDomDocument& doc, QDomElement& itemElem ) co
|
|||||||
annotationElem.setAttribute( "mapPositionFixed", mMapPositionFixed );
|
annotationElem.setAttribute( "mapPositionFixed", mMapPositionFixed );
|
||||||
annotationElem.setAttribute( "mapPosX", qgsDoubleToString( mMapPosition.x() ) );
|
annotationElem.setAttribute( "mapPosX", qgsDoubleToString( mMapPosition.x() ) );
|
||||||
annotationElem.setAttribute( "mapPosY", qgsDoubleToString( mMapPosition.y() ) );
|
annotationElem.setAttribute( "mapPosY", qgsDoubleToString( mMapPosition.y() ) );
|
||||||
|
if ( mMapPositionCrs.isValid() )
|
||||||
|
mMapPositionCrs.writeXML( annotationElem, doc );
|
||||||
annotationElem.setAttribute( "offsetX", qgsDoubleToString( mOffsetFromReferencePoint.x() ) );
|
annotationElem.setAttribute( "offsetX", qgsDoubleToString( mOffsetFromReferencePoint.x() ) );
|
||||||
annotationElem.setAttribute( "offsetY", qgsDoubleToString( mOffsetFromReferencePoint.y() ) );
|
annotationElem.setAttribute( "offsetY", qgsDoubleToString( mOffsetFromReferencePoint.y() ) );
|
||||||
annotationElem.setAttribute( "frameWidth", QString::number( mFrameSize.width() ) );
|
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.setX( annotationElem.attribute( "mapPosX", "0" ).toDouble() );
|
||||||
mapPos.setY( annotationElem.attribute( "mapPosY", "0" ).toDouble() );
|
mapPos.setY( annotationElem.attribute( "mapPosY", "0" ).toDouble() );
|
||||||
mMapPosition = mapPos;
|
mMapPosition = mapPos;
|
||||||
|
if ( !mMapPositionCrs.readXML( annotationElem ) )
|
||||||
|
mMapPositionCrs = mMapCanvas->mapSettings().destinationCrs();
|
||||||
mFrameBorderWidth = annotationElem.attribute( "frameBorderWidth", "0.5" ).toDouble();
|
mFrameBorderWidth = annotationElem.attribute( "frameBorderWidth", "0.5" ).toDouble();
|
||||||
mFrameColor.setNamedColor( annotationElem.attribute( "frameColor", "#000000" ) );
|
mFrameColor.setNamedColor( annotationElem.attribute( "frameColor", "#000000" ) );
|
||||||
mFrameColor.setAlpha( annotationElem.attribute( "frameColorAlpha", "255" ).toInt() );
|
mFrameColor.setAlpha( annotationElem.attribute( "frameColorAlpha", "255" ).toInt() );
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#define QGSANNOTATIONITEM_H
|
#define QGSANNOTATIONITEM_H
|
||||||
|
|
||||||
#include "qgsmapcanvasitem.h"
|
#include "qgsmapcanvasitem.h"
|
||||||
|
#include "qgscoordinatereferencesystem.h"
|
||||||
|
|
||||||
class QDomDocument;
|
class QDomDocument;
|
||||||
class QDomElement;
|
class QDomElement;
|
||||||
@ -68,6 +69,12 @@ class GUI_EXPORT QgsAnnotationItem: public QgsMapCanvasItem
|
|||||||
virtual void setMapPosition( const QgsPoint& pos );
|
virtual void setMapPosition( const QgsPoint& pos );
|
||||||
QgsPoint mapPosition() const { return mMapPosition; }
|
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 );
|
void setFrameSize( const QSizeF& size );
|
||||||
QSizeF frameSize() const { return mFrameSize; }
|
QSizeF frameSize() const { return mFrameSize; }
|
||||||
|
|
||||||
@ -98,6 +105,9 @@ class GUI_EXPORT QgsAnnotationItem: public QgsMapCanvasItem
|
|||||||
bool mMapPositionFixed;
|
bool mMapPositionFixed;
|
||||||
/** Map position (in case mMapPositionFixed is true)*/
|
/** Map position (in case mMapPositionFixed is true)*/
|
||||||
QgsPoint mMapPosition;
|
QgsPoint mMapPosition;
|
||||||
|
/** CRS of the map position */
|
||||||
|
QgsCoordinateReferenceSystem mMapPositionCrs;
|
||||||
|
|
||||||
/** Describes the shift of the item content box to the reference point*/
|
/** Describes the shift of the item content box to the reference point*/
|
||||||
QPointF mOffsetFromReferencePoint;
|
QPointF mOffsetFromReferencePoint;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user