Skip to content

Commit

Permalink
Project file conversion for composer grid annotation position and dir…
Browse files Browse the repository at this point in the history
…ection
  • Loading branch information
mhugent committed Jul 4, 2012
1 parent 9cd59c9 commit aa39674
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 19 deletions.
27 changes: 19 additions & 8 deletions python/core/qgscomposermap.sip
Expand Up @@ -47,6 +47,15 @@ class QgsComposerMap : QgsComposerItem
BoundaryDirection
};

/**Enum for different frame borders*/
enum Border
{
Left,
Right,
Bottom,
Top
};

/**@deprecated*/
void draw( QPainter *painter, const QgsRectangle& extent, const QSize& size, int dpi );

Expand Down Expand Up @@ -195,20 +204,22 @@ class QgsComposerMap : QgsComposerItem
void setShowGridAnnotation( bool show );
bool showGridAnnotation() const;

/**Sets position of grid annotations. Possibilities are inside or outside of the map frame
@note this function was added in version 1.4*/
void setGridAnnotationPosition( GridAnnotationPosition p );
GridAnnotationPosition gridAnnotationPosition() const;
/**Sets position of grid annotations. Possibilities are inside / outside of the map frame or disabled
@note this function was added in version 1.9*/
void setGridAnnotationPosition( GridAnnotationPosition p, QgsComposerMap::Border border );
/**@note: this function was added in version 1.9*/
GridAnnotationPosition gridAnnotationPosition( QgsComposerMap::Border border ) const;

/**Sets distance between map frame and annotations
@note this function was added in version 1.4*/
void setAnnotationFrameDistance( double d );
double annotationFrameDistance() const;

/**Sets grid annotation direction. Can be horizontal, vertical, direction of axis and horizontal and vertical
@note this function was added in version 1.4*/
void setGridAnnotationDirection( GridAnnotationDirection d );
GridAnnotationDirection gridAnnotationDirection() const;
/**Sets grid annotation direction. Can be horizontal or vertical
@note this function was added in version 1.9*/
void setGridAnnotationDirection( GridAnnotationDirection d, QgsComposerMap::Border border );
/**@note: this function was added in version 1.9*/
GridAnnotationDirection gridAnnotationDirection( QgsComposerMap::Border border ) const;

/**In case of annotations, the bounding rectangle can be larger than the map item rectangle
@note this function was added in version 1.4*/
Expand Down
5 changes: 2 additions & 3 deletions src/core/composer/qgscomposermap.cpp
Expand Up @@ -827,9 +827,7 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
mRightGridAnnotationDirection = QgsComposerMap::GridAnnotationDirection( annotationElem.attribute( "rightDirection", "0" ).toInt() );
mTopGridAnnotationDirection = QgsComposerMap::GridAnnotationDirection( annotationElem.attribute( "topDirection", "0" ).toInt() );
mBottomGridAnnotationDirection = QgsComposerMap::GridAnnotationDirection( annotationElem.attribute( "bottomDirection", "0" ).toInt() );

mAnnotationFrameDistance = annotationElem.attribute( "frameDistance", "0" ).toDouble();
mGridAnnotationDirection = QgsComposerMap::GridAnnotationDirection( annotationElem.attribute( "direction", "0" ).toInt() );
mGridAnnotationFont.fromString( annotationElem.attribute( "font", "" ) );
mGridAnnotationPrecision = annotationElem.attribute( "precision", "3" ).toInt();
}
Expand Down Expand Up @@ -1352,7 +1350,8 @@ QPolygonF QgsComposerMap::transformedMapPolygon() const

double QgsComposerMap::maxExtension() const
{
if ( !mGridEnabled || !mShowGridAnnotation || mGridAnnotationPosition != OutsideMapFrame )
if ( !mGridEnabled || !mShowGridAnnotation || ( mLeftGridAnnotationPosition != OutsideMapFrame && mRightGridAnnotationPosition != OutsideMapFrame
&& mTopGridAnnotationPosition != OutsideMapFrame && mBottomGridAnnotationPosition != OutsideMapFrame ) )
{
return 0;
}
Expand Down
12 changes: 4 additions & 8 deletions src/core/composer/qgscomposermap.h
Expand Up @@ -239,8 +239,8 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem

/**Sets position of grid annotations. Possibilities are inside or outside of the map frame
@note this function was added in version 1.4*/
void setGridAnnotationPosition( GridAnnotationPosition p ) {mGridAnnotationPosition = p;}
GridAnnotationPosition gridAnnotationPosition() const {return mGridAnnotationPosition;}
//void setGridAnnotationPosition( GridAnnotationPosition p ) {mGridAnnotationPosition = p;}
//GridAnnotationPosition gridAnnotationPosition() const {return mGridAnnotationPosition;}

void setGridAnnotationPosition( GridAnnotationPosition p, QgsComposerMap::Border border );
GridAnnotationPosition gridAnnotationPosition( QgsComposerMap::Border border ) const;
Expand All @@ -252,8 +252,8 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem

/**Sets grid annotation direction. Can be horizontal, vertical, direction of axis and horizontal and vertical
@note this function was added in version 1.4*/
void setGridAnnotationDirection( GridAnnotationDirection d ) {mGridAnnotationDirection = d;}
GridAnnotationDirection gridAnnotationDirection() const {return mGridAnnotationDirection;}
//void setGridAnnotationDirection( GridAnnotationDirection d ) {mGridAnnotationDirection = d;}
//GridAnnotationDirection gridAnnotationDirection() const {return mGridAnnotationDirection;}

void setGridAnnotationDirection( GridAnnotationDirection d, QgsComposerMap::Border border );
GridAnnotationDirection gridAnnotationDirection( QgsComposerMap::Border border ) const;
Expand Down Expand Up @@ -359,8 +359,6 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
int mGridAnnotationPrecision;
/**True if coordinate values should be drawn*/
bool mShowGridAnnotation;
/**Annotation position inside or outside of map frame*/
GridAnnotationPosition mGridAnnotationPosition;

/**Annotation position for left map side (inside / outside / not shown)*/
GridAnnotationPosition mLeftGridAnnotationPosition;
Expand All @@ -373,8 +371,6 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem

/**Distance between map frame and annotation*/
double mAnnotationFrameDistance;
/**Annotation can be horizontal / vertical or different for axes*/
GridAnnotationDirection mGridAnnotationDirection;

/**Annotation direction on left side ( horizontal or vertical )*/
GridAnnotationDirection mLeftGridAnnotationDirection;
Expand Down
56 changes: 56 additions & 0 deletions src/core/qgsprojectfiletransform.cpp
Expand Up @@ -475,6 +475,62 @@ void QgsProjectFileTransform::transform1800to1900()
rasterLayer.readXML( layerNode );
convertRasterProperties( mDom, layerNode, rasterPropertiesElem, &rasterLayer );
}

//composer: replace mGridAnnotationPosition with mLeftGridAnnotationPosition & co.
// and mGridAnnotationDirection with mLeftGridAnnotationDirection & co.
QDomNodeList composerMapList = mDom.elementsByTagName( "ComposerMap" );
for ( int i = 0; i < composerMapList.size(); ++i )
{
QDomNodeList gridList = composerMapList.at( i ).toElement().elementsByTagName( "Grid" );
for ( int j = 0; j < gridList.size(); ++j )
{
QDomNodeList annotationList = gridList.at( j ).toElement().elementsByTagName( "Annotation" );
for ( int k = 0; k < annotationList.size(); ++k )
{
QDomElement annotationElem = annotationList.at( k ).toElement();

//position
if ( annotationElem.hasAttribute( "position" ) )
{
int pos = annotationElem.attribute( "position" ).toInt();
annotationElem.setAttribute( "leftPosition", pos );
annotationElem.setAttribute( "rightPosition", pos );
annotationElem.setAttribute( "topPosition", pos );
annotationElem.setAttribute( "bottomPosition", pos );
annotationElem.removeAttribute( "position" );
}

//direction
if ( annotationElem.hasAttribute( "direction" ) )
{
int dir = annotationElem.attribute( "direction" ).toInt();
if ( dir == 2 )
{
annotationElem.setAttribute( "leftDirection", 0 );
annotationElem.setAttribute( "rightDirection", 0 );
annotationElem.setAttribute( "topDirection", 1 );
annotationElem.setAttribute( "bottomDirection", 1 );
}
else if ( dir == 3 )
{
annotationElem.setAttribute( "leftDirection", 1 );
annotationElem.setAttribute( "rightDirection", 1 );
annotationElem.setAttribute( "topDirection", 0 );
annotationElem.setAttribute( "bottomDirection", 0 );
}
else
{
annotationElem.setAttribute( "leftDirection", dir );
annotationElem.setAttribute( "rightDirection", dir );
annotationElem.setAttribute( "topDirection", dir );
annotationElem.setAttribute( "bottomDirection", dir );
}
annotationElem.removeAttribute( "direction" );
}
}
}
}

QgsDebugMsg( mDom.toString() );
}

Expand Down

0 comments on commit aa39674

Please sign in to comment.