Skip to content

Commit aa39674

Browse files
committedJul 4, 2012
Project file conversion for composer grid annotation position and direction
1 parent 9cd59c9 commit aa39674

File tree

4 files changed

+81
-19
lines changed

4 files changed

+81
-19
lines changed
 

‎python/core/qgscomposermap.sip

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ class QgsComposerMap : QgsComposerItem
4747
BoundaryDirection
4848
};
4949

50+
/**Enum for different frame borders*/
51+
enum Border
52+
{
53+
Left,
54+
Right,
55+
Bottom,
56+
Top
57+
};
58+
5059
/**@deprecated*/
5160
void draw( QPainter *painter, const QgsRectangle& extent, const QSize& size, int dpi );
5261

@@ -195,20 +204,22 @@ class QgsComposerMap : QgsComposerItem
195204
void setShowGridAnnotation( bool show );
196205
bool showGridAnnotation() const;
197206

198-
/**Sets position of grid annotations. Possibilities are inside or outside of the map frame
199-
@note this function was added in version 1.4*/
200-
void setGridAnnotationPosition( GridAnnotationPosition p );
201-
GridAnnotationPosition gridAnnotationPosition() const;
207+
/**Sets position of grid annotations. Possibilities are inside / outside of the map frame or disabled
208+
@note this function was added in version 1.9*/
209+
void setGridAnnotationPosition( GridAnnotationPosition p, QgsComposerMap::Border border );
210+
/**@note: this function was added in version 1.9*/
211+
GridAnnotationPosition gridAnnotationPosition( QgsComposerMap::Border border ) const;
202212

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

208-
/**Sets grid annotation direction. Can be horizontal, vertical, direction of axis and horizontal and vertical
209-
@note this function was added in version 1.4*/
210-
void setGridAnnotationDirection( GridAnnotationDirection d );
211-
GridAnnotationDirection gridAnnotationDirection() const;
218+
/**Sets grid annotation direction. Can be horizontal or vertical
219+
@note this function was added in version 1.9*/
220+
void setGridAnnotationDirection( GridAnnotationDirection d, QgsComposerMap::Border border );
221+
/**@note: this function was added in version 1.9*/
222+
GridAnnotationDirection gridAnnotationDirection( QgsComposerMap::Border border ) const;
212223

213224
/**In case of annotations, the bounding rectangle can be larger than the map item rectangle
214225
@note this function was added in version 1.4*/

‎src/core/composer/qgscomposermap.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -827,9 +827,7 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
827827
mRightGridAnnotationDirection = QgsComposerMap::GridAnnotationDirection( annotationElem.attribute( "rightDirection", "0" ).toInt() );
828828
mTopGridAnnotationDirection = QgsComposerMap::GridAnnotationDirection( annotationElem.attribute( "topDirection", "0" ).toInt() );
829829
mBottomGridAnnotationDirection = QgsComposerMap::GridAnnotationDirection( annotationElem.attribute( "bottomDirection", "0" ).toInt() );
830-
831830
mAnnotationFrameDistance = annotationElem.attribute( "frameDistance", "0" ).toDouble();
832-
mGridAnnotationDirection = QgsComposerMap::GridAnnotationDirection( annotationElem.attribute( "direction", "0" ).toInt() );
833831
mGridAnnotationFont.fromString( annotationElem.attribute( "font", "" ) );
834832
mGridAnnotationPrecision = annotationElem.attribute( "precision", "3" ).toInt();
835833
}
@@ -1352,7 +1350,8 @@ QPolygonF QgsComposerMap::transformedMapPolygon() const
13521350

13531351
double QgsComposerMap::maxExtension() const
13541352
{
1355-
if ( !mGridEnabled || !mShowGridAnnotation || mGridAnnotationPosition != OutsideMapFrame )
1353+
if ( !mGridEnabled || !mShowGridAnnotation || ( mLeftGridAnnotationPosition != OutsideMapFrame && mRightGridAnnotationPosition != OutsideMapFrame
1354+
&& mTopGridAnnotationPosition != OutsideMapFrame && mBottomGridAnnotationPosition != OutsideMapFrame ) )
13561355
{
13571356
return 0;
13581357
}

‎src/core/composer/qgscomposermap.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
239239

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

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

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

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

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

374372
/**Distance between map frame and annotation*/
375373
double mAnnotationFrameDistance;
376-
/**Annotation can be horizontal / vertical or different for axes*/
377-
GridAnnotationDirection mGridAnnotationDirection;
378374

379375
/**Annotation direction on left side ( horizontal or vertical )*/
380376
GridAnnotationDirection mLeftGridAnnotationDirection;

‎src/core/qgsprojectfiletransform.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,62 @@ void QgsProjectFileTransform::transform1800to1900()
475475
rasterLayer.readXML( layerNode );
476476
convertRasterProperties( mDom, layerNode, rasterPropertiesElem, &rasterLayer );
477477
}
478+
479+
//composer: replace mGridAnnotationPosition with mLeftGridAnnotationPosition & co.
480+
// and mGridAnnotationDirection with mLeftGridAnnotationDirection & co.
481+
QDomNodeList composerMapList = mDom.elementsByTagName( "ComposerMap" );
482+
for ( int i = 0; i < composerMapList.size(); ++i )
483+
{
484+
QDomNodeList gridList = composerMapList.at( i ).toElement().elementsByTagName( "Grid" );
485+
for ( int j = 0; j < gridList.size(); ++j )
486+
{
487+
QDomNodeList annotationList = gridList.at( j ).toElement().elementsByTagName( "Annotation" );
488+
for ( int k = 0; k < annotationList.size(); ++k )
489+
{
490+
QDomElement annotationElem = annotationList.at( k ).toElement();
491+
492+
//position
493+
if ( annotationElem.hasAttribute( "position" ) )
494+
{
495+
int pos = annotationElem.attribute( "position" ).toInt();
496+
annotationElem.setAttribute( "leftPosition", pos );
497+
annotationElem.setAttribute( "rightPosition", pos );
498+
annotationElem.setAttribute( "topPosition", pos );
499+
annotationElem.setAttribute( "bottomPosition", pos );
500+
annotationElem.removeAttribute( "position" );
501+
}
502+
503+
//direction
504+
if ( annotationElem.hasAttribute( "direction" ) )
505+
{
506+
int dir = annotationElem.attribute( "direction" ).toInt();
507+
if ( dir == 2 )
508+
{
509+
annotationElem.setAttribute( "leftDirection", 0 );
510+
annotationElem.setAttribute( "rightDirection", 0 );
511+
annotationElem.setAttribute( "topDirection", 1 );
512+
annotationElem.setAttribute( "bottomDirection", 1 );
513+
}
514+
else if ( dir == 3 )
515+
{
516+
annotationElem.setAttribute( "leftDirection", 1 );
517+
annotationElem.setAttribute( "rightDirection", 1 );
518+
annotationElem.setAttribute( "topDirection", 0 );
519+
annotationElem.setAttribute( "bottomDirection", 0 );
520+
}
521+
else
522+
{
523+
annotationElem.setAttribute( "leftDirection", dir );
524+
annotationElem.setAttribute( "rightDirection", dir );
525+
annotationElem.setAttribute( "topDirection", dir );
526+
annotationElem.setAttribute( "bottomDirection", dir );
527+
}
528+
annotationElem.removeAttribute( "direction" );
529+
}
530+
}
531+
}
532+
}
533+
478534
QgsDebugMsg( mDom.toString() );
479535
}
480536

0 commit comments

Comments
 (0)
Please sign in to comment.