Skip to content

Commit a6adecd

Browse files
committedJul 4, 2012
Merge branch 'graticule_labels'
2 parents 040b046 + 5a7cb21 commit a6adecd

File tree

7 files changed

+706
-323
lines changed

7 files changed

+706
-323
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/app/composer/qgscomposermapwidget.cpp

Lines changed: 145 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
#include "qgscomposermapwidget.h"
1919
#include "qgscomposeritemwidget.h"
20-
#include "qgscomposermap.h"
2120
#include "qgsmaprenderer.h"
2221
#include <QColorDialog>
2322
#include <QFontDialog>
@@ -47,13 +46,16 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap ): QWidg
4746
mGridTypeComboBox->insertItem( 0, tr( "Solid" ) );
4847
mGridTypeComboBox->insertItem( 1, tr( "Cross" ) );
4948

50-
mAnnotationPositionComboBox->insertItem( 0, tr( "Inside frame" ) );
51-
mAnnotationPositionComboBox->insertItem( 1, tr( "Outside frame" ) );
49+
insertAnnotationPositionEntries( mAnnotationPositionLeftComboBox );
50+
insertAnnotationPositionEntries( mAnnotationPositionRightComboBox );
51+
insertAnnotationPositionEntries( mAnnotationPositionTopComboBox );
52+
insertAnnotationPositionEntries( mAnnotationPositionBottomComboBox );
53+
54+
insertAnnotationDirectionEntries( mAnnotationDirectionComboBoxLeft );
55+
insertAnnotationDirectionEntries( mAnnotationDirectionComboBoxRight );
56+
insertAnnotationDirectionEntries( mAnnotationDirectionComboBoxTop );
57+
insertAnnotationDirectionEntries( mAnnotationDirectionComboBoxBottom );
5258

53-
mAnnotationDirectionComboBox->insertItem( 0, tr( "Horizontal" ) );
54-
mAnnotationDirectionComboBox->insertItem( 1, tr( "Vertical" ) );
55-
mAnnotationDirectionComboBox->insertItem( 2, tr( "Horizontal and Vertical" ) );
56-
mAnnotationDirectionComboBox->insertItem( 2, tr( "Boundary direction" ) );
5759
if ( composerMap )
5860
{
5961
connect( composerMap, SIGNAL( itemChanged() ), this, SLOT( setGuiElementValues() ) );
@@ -344,15 +346,17 @@ void QgsComposerMapWidget::updateGuiElements()
344346

345347
mCrossWidthSpinBox->setValue( mComposerMap->crossLength() );
346348

347-
QgsComposerMap::GridAnnotationPosition annotationPos = mComposerMap->gridAnnotationPosition();
348-
if ( annotationPos == QgsComposerMap::InsideMapFrame )
349-
{
350-
mAnnotationPositionComboBox->setCurrentIndex( mAnnotationPositionComboBox->findText( tr( "Inside frame" ) ) );
351-
}
352-
else
353-
{
354-
mAnnotationPositionComboBox->setCurrentIndex( mAnnotationPositionComboBox->findText( tr( "Outside frame" ) ) );
355-
}
349+
//grid annotation position
350+
initAnnotationPositionBox( mAnnotationPositionLeftComboBox, mComposerMap->gridAnnotationPosition( QgsComposerMap::Left ) );
351+
initAnnotationPositionBox( mAnnotationPositionRightComboBox, mComposerMap->gridAnnotationPosition( QgsComposerMap::Right ) );
352+
initAnnotationPositionBox( mAnnotationPositionTopComboBox, mComposerMap->gridAnnotationPosition( QgsComposerMap::Top ) );
353+
initAnnotationPositionBox( mAnnotationPositionBottomComboBox, mComposerMap->gridAnnotationPosition( QgsComposerMap::Bottom ) );
354+
355+
//grid annotation direction
356+
initAnnotationDirectionBox( mAnnotationDirectionComboBoxLeft, mComposerMap->gridAnnotationDirection( QgsComposerMap::Left ) );
357+
initAnnotationDirectionBox( mAnnotationDirectionComboBoxRight, mComposerMap->gridAnnotationDirection( QgsComposerMap::Right ) );
358+
initAnnotationDirectionBox( mAnnotationDirectionComboBoxTop, mComposerMap->gridAnnotationDirection( QgsComposerMap::Top ) );
359+
initAnnotationDirectionBox( mAnnotationDirectionComboBoxBottom, mComposerMap->gridAnnotationDirection( QgsComposerMap::Bottom ) );
356360

357361
mDistanceToMapFrameSpinBox->setValue( mComposerMap->annotationFrameDistance() );
358362

@@ -365,24 +369,6 @@ void QgsComposerMapWidget::updateGuiElements()
365369
mDrawAnnotationCheckBox->setCheckState( Qt::Unchecked );
366370
}
367371

368-
QgsComposerMap::GridAnnotationDirection dir = mComposerMap->gridAnnotationDirection();
369-
if ( dir == QgsComposerMap::Horizontal )
370-
{
371-
mAnnotationDirectionComboBox->setCurrentIndex( mAnnotationDirectionComboBox->findText( tr( "Horizontal" ) ) );
372-
}
373-
else if ( dir == QgsComposerMap::Vertical )
374-
{
375-
mAnnotationDirectionComboBox->setCurrentIndex( mAnnotationDirectionComboBox->findText( tr( "Vertical" ) ) );
376-
}
377-
else if ( dir == QgsComposerMap::HorizontalAndVertical )
378-
{
379-
mAnnotationDirectionComboBox->setCurrentIndex( mAnnotationDirectionComboBox->findText( tr( "Horizontal and Vertical" ) ) );
380-
}
381-
else //BoundaryDirection
382-
{
383-
mAnnotationDirectionComboBox->setCurrentIndex( mAnnotationDirectionComboBox->findText( tr( "Boundary direction" ) ) );
384-
}
385-
386372
mCoordinatePrecisionSpinBox->setValue( mComposerMap->gridAnnotationPrecision() );
387373

388374
QPen gridPen = mComposerMap->gridPen();
@@ -445,9 +431,15 @@ void QgsComposerMapWidget::blockAllSignals( bool b )
445431
mLineColorButton->blockSignals( b );
446432
mDrawAnnotationCheckBox->blockSignals( b );
447433
mAnnotationFontButton->blockSignals( b );
448-
mAnnotationPositionComboBox->blockSignals( b );
434+
mAnnotationPositionLeftComboBox->blockSignals( b );
435+
mAnnotationPositionRightComboBox->blockSignals( b );
436+
mAnnotationPositionTopComboBox->blockSignals( b );
437+
mAnnotationPositionBottomComboBox->blockSignals( b );
449438
mDistanceToMapFrameSpinBox->blockSignals( b );
450-
mAnnotationDirectionComboBox->blockSignals( b );
439+
mAnnotationDirectionComboBoxLeft->blockSignals( b );
440+
mAnnotationDirectionComboBoxRight->blockSignals( b );
441+
mAnnotationDirectionComboBoxTop->blockSignals( b );
442+
mAnnotationDirectionComboBoxBottom->blockSignals( b );
451443
mCoordinatePrecisionSpinBox->blockSignals( b );
452444
mDrawCanvasItemsCheckBox->blockSignals( b );
453445
}
@@ -683,49 +675,120 @@ void QgsComposerMapWidget::on_mDistanceToMapFrameSpinBox_valueChanged( double d
683675
mComposerMap->endCommand();
684676
}
685677

686-
void QgsComposerMapWidget::on_mAnnotationPositionComboBox_currentIndexChanged( const QString& text )
678+
void QgsComposerMapWidget::on_mAnnotationPositionLeftComboBox_currentIndexChanged( const QString& text )
679+
{
680+
handleChangedAnnotationPosition( QgsComposerMap::Left, text );
681+
}
682+
683+
void QgsComposerMapWidget::on_mAnnotationPositionRightComboBox_currentIndexChanged( const QString& text )
684+
{
685+
handleChangedAnnotationPosition( QgsComposerMap::Right, text );
686+
}
687+
688+
void QgsComposerMapWidget::on_mAnnotationPositionTopComboBox_currentIndexChanged( const QString& text )
689+
{
690+
handleChangedAnnotationPosition( QgsComposerMap::Top, text );
691+
}
692+
693+
void QgsComposerMapWidget::on_mAnnotationPositionBottomComboBox_currentIndexChanged( const QString& text )
694+
{
695+
handleChangedAnnotationPosition( QgsComposerMap::Bottom, text );
696+
}
697+
698+
void QgsComposerMapWidget::on_mDrawAnnotationCheckBox_stateChanged( int state )
687699
{
688700
if ( !mComposerMap )
689701
{
690702
return;
691703
}
692704

693-
mComposerMap->beginCommand( tr( "Annotation position changed" ) );
694-
if ( text == tr( "Inside frame" ) )
705+
mComposerMap->beginCommand( tr( "Annotation toggled" ) );
706+
if ( state == Qt::Checked )
695707
{
696-
mComposerMap->setGridAnnotationPosition( QgsComposerMap::InsideMapFrame );
708+
mComposerMap->setShowGridAnnotation( true );
697709
}
698710
else
699711
{
700-
mComposerMap->setGridAnnotationPosition( QgsComposerMap::OutsideMapFrame );
712+
mComposerMap->setShowGridAnnotation( false );
701713
}
702714
mComposerMap->updateBoundingRect();
703715
mComposerMap->update();
704716
mComposerMap->endCommand();
705717
}
706718

707-
void QgsComposerMapWidget::on_mDrawAnnotationCheckBox_stateChanged( int state )
719+
void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxLeft_currentIndexChanged( const QString& text )
720+
{
721+
handleChangedAnnotationDirection( QgsComposerMap::Left, text );
722+
}
723+
724+
void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxRight_currentIndexChanged( const QString& text )
725+
{
726+
handleChangedAnnotationDirection( QgsComposerMap::Right, text );
727+
}
728+
729+
void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxTop_currentIndexChanged( const QString& text )
730+
{
731+
handleChangedAnnotationDirection( QgsComposerMap::Top, text );
732+
}
733+
734+
void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxBottom_currentIndexChanged( const QString& text )
735+
{
736+
handleChangedAnnotationDirection( QgsComposerMap::Bottom, text );
737+
}
738+
739+
void QgsComposerMapWidget::on_mCoordinatePrecisionSpinBox_valueChanged( int value )
740+
{
741+
if ( !mComposerMap )
742+
{
743+
return;
744+
}
745+
mComposerMap->beginCommand( tr( "Changed annotation precision" ) );
746+
mComposerMap->setGridAnnotationPrecision( value );
747+
mComposerMap->updateBoundingRect();
748+
mComposerMap->update();
749+
mComposerMap->endCommand();
750+
}
751+
752+
void QgsComposerMapWidget::insertAnnotationPositionEntries( QComboBox* c )
753+
{
754+
c->insertItem( 0, tr( "Inside frame" ) );
755+
c->insertItem( 1, tr( "Outside frame" ) );
756+
c->insertItem( 2, tr( "Disabled" ) );
757+
}
758+
759+
void QgsComposerMapWidget::insertAnnotationDirectionEntries( QComboBox* c )
760+
{
761+
c->insertItem( 0, tr( "Horizontal" ) );
762+
c->insertItem( 1, tr( "Vertical" ) );
763+
}
764+
765+
void QgsComposerMapWidget::handleChangedAnnotationPosition( QgsComposerMap::Border border, const QString& text )
708766
{
709767
if ( !mComposerMap )
710768
{
711769
return;
712770
}
713771

714-
mComposerMap->beginCommand( tr( "Annotation toggled" ) );
715-
if ( state == Qt::Checked )
772+
mComposerMap->beginCommand( tr( "Annotation position changed" ) );
773+
if ( text == tr( "Inside frame" ) )
716774
{
717-
mComposerMap->setShowGridAnnotation( true );
775+
mComposerMap->setGridAnnotationPosition( QgsComposerMap::InsideMapFrame, border );
718776
}
719-
else
777+
else if ( text == tr( "Disabled" ) )
720778
{
721-
mComposerMap->setShowGridAnnotation( false );
779+
mComposerMap->setGridAnnotationPosition( QgsComposerMap::Disabled, border );
780+
}
781+
else //Outside frame
782+
{
783+
mComposerMap->setGridAnnotationPosition( QgsComposerMap::OutsideMapFrame, border );
722784
}
785+
723786
mComposerMap->updateBoundingRect();
724787
mComposerMap->update();
725788
mComposerMap->endCommand();
726789
}
727790

728-
void QgsComposerMapWidget::on_mAnnotationDirectionComboBox_currentIndexChanged( const QString& text )
791+
void QgsComposerMapWidget::handleChangedAnnotationDirection( QgsComposerMap::Border border, const QString& text )
729792
{
730793
if ( !mComposerMap )
731794
{
@@ -735,34 +798,51 @@ void QgsComposerMapWidget::on_mAnnotationDirectionComboBox_currentIndexChanged(
735798
mComposerMap->beginCommand( tr( "Changed annotation direction" ) );
736799
if ( text == tr( "Horizontal" ) )
737800
{
738-
mComposerMap->setGridAnnotationDirection( QgsComposerMap::Horizontal );
801+
mComposerMap->setGridAnnotationDirection( QgsComposerMap::Horizontal, border );
802+
}
803+
else //Vertical
804+
{
805+
mComposerMap->setGridAnnotationDirection( QgsComposerMap::Vertical, border );
739806
}
740-
else if ( text == tr( "Vertical" ) )
807+
mComposerMap->updateBoundingRect();
808+
mComposerMap->update();
809+
mComposerMap->endCommand();
810+
}
811+
812+
void QgsComposerMapWidget::initAnnotationPositionBox( QComboBox* c, QgsComposerMap::GridAnnotationPosition pos )
813+
{
814+
if ( !c )
741815
{
742-
mComposerMap->setGridAnnotationDirection( QgsComposerMap::Vertical );
816+
return;
743817
}
744-
else if ( text == tr( "Horizontal and Vertical" ) )
818+
819+
if ( pos == QgsComposerMap::InsideMapFrame )
745820
{
746-
mComposerMap->setGridAnnotationDirection( QgsComposerMap::HorizontalAndVertical );
821+
c->setCurrentIndex( c->findText( tr( "Inside frame" ) ) );
747822
}
748-
else //BoundaryDirection
823+
else if ( pos == QgsComposerMap::OutsideMapFrame )
749824
{
750-
mComposerMap->setGridAnnotationDirection( QgsComposerMap::BoundaryDirection );
825+
c->setCurrentIndex( c->findText( tr( "Outside frame" ) ) );
826+
}
827+
else //disabled
828+
{
829+
c->setCurrentIndex( c->findText( tr( "Disabled" ) ) );
751830
}
752-
mComposerMap->updateBoundingRect();
753-
mComposerMap->update();
754-
mComposerMap->endCommand();
755831
}
756832

757-
void QgsComposerMapWidget::on_mCoordinatePrecisionSpinBox_valueChanged( int value )
833+
void QgsComposerMapWidget::initAnnotationDirectionBox( QComboBox* c, QgsComposerMap::GridAnnotationDirection dir )
758834
{
759-
if ( !mComposerMap )
835+
if ( !c )
760836
{
761837
return;
762838
}
763-
mComposerMap->beginCommand( tr( "Changed annotation precision" ) );
764-
mComposerMap->setGridAnnotationPrecision( value );
765-
mComposerMap->updateBoundingRect();
766-
mComposerMap->update();
767-
mComposerMap->endCommand();
839+
840+
if ( dir == QgsComposerMap::Vertical )
841+
{
842+
c->setCurrentIndex( c->findText( tr( "Vertical" ) ) );
843+
}
844+
else //horizontal
845+
{
846+
c->setCurrentIndex( c->findText( tr( "Horizontal" ) ) );
847+
}
768848
}

‎src/app/composer/qgscomposermapwidget.h

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
#define QGSCOMPOSERMAPWIDGET_H
2020

2121
#include "ui_qgscomposermapwidgetbase.h"
22-
23-
class QgsComposerMap;
22+
#include "qgscomposermap.h"
2423

2524
/** \ingroup MapComposer
2625
* Input widget for the configuration of QgsComposerMap
@@ -61,9 +60,20 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase
6160
void on_mCrossWidthSpinBox_valueChanged( double d );
6261
void on_mAnnotationFontButton_clicked();
6362
void on_mDistanceToMapFrameSpinBox_valueChanged( double d );
64-
void on_mAnnotationPositionComboBox_currentIndexChanged( const QString& text );
63+
64+
//annotation position
65+
void on_mAnnotationPositionLeftComboBox_currentIndexChanged( const QString& text );
66+
void on_mAnnotationPositionRightComboBox_currentIndexChanged( const QString& text );
67+
void on_mAnnotationPositionTopComboBox_currentIndexChanged( const QString& text );
68+
void on_mAnnotationPositionBottomComboBox_currentIndexChanged( const QString& text );
69+
70+
//annotation direction
71+
void on_mAnnotationDirectionComboBoxLeft_currentIndexChanged( const QString& text );
72+
void on_mAnnotationDirectionComboBoxRight_currentIndexChanged( const QString& text );
73+
void on_mAnnotationDirectionComboBoxTop_currentIndexChanged( const QString& text );
74+
void on_mAnnotationDirectionComboBoxBottom_currentIndexChanged( const QString& text );
75+
6576
void on_mDrawAnnotationCheckBox_stateChanged( int state );
66-
void on_mAnnotationDirectionComboBox_currentIndexChanged( const QString& text );
6777
void on_mCoordinatePrecisionSpinBox_valueChanged( int value );
6878

6979
private slots:
@@ -82,6 +92,15 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase
8292

8393
/**Blocks / unblocks the signals of all GUI elements*/
8494
void blockAllSignals( bool b );
95+
96+
void handleChangedAnnotationPosition( QgsComposerMap::Border border, const QString& text );
97+
void handleChangedAnnotationDirection( QgsComposerMap::Border border, const QString& text );
98+
99+
void insertAnnotationPositionEntries( QComboBox* c );
100+
void insertAnnotationDirectionEntries( QComboBox* c );
101+
102+
void initAnnotationPositionBox( QComboBox* c, QgsComposerMap::GridAnnotationPosition pos );
103+
void initAnnotationDirectionBox( QComboBox* c, QgsComposerMap::GridAnnotationDirection dir );
85104
};
86105

87106
#endif

‎src/core/composer/qgscomposermap.cpp

Lines changed: 144 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616
***************************************************************************/
1717

1818
#include "qgscomposermap.h"
19-
2019
#include "qgscoordinatetransform.h"
2120
#include "qgslogger.h"
2221
#include "qgsmaprenderer.h"
23-
#include "qgsmaplayer.h"
2422
#include "qgsmaplayerregistry.h"
2523
#include "qgsmaptopixel.h"
2624
#include "qgsproject.h"
@@ -42,7 +40,9 @@
4240
QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int width, int height )
4341
: QgsComposerItem( x, y, width, height, composition ), mKeepLayerSet( false ), mGridEnabled( false ), mGridStyle( Solid ),
4442
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ),
45-
mGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mGridAnnotationDirection( Horizontal ),
43+
mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ), mTopGridAnnotationPosition( OutsideMapFrame ),
44+
mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ),
45+
mTopGridAnnotationDirection( Horizontal ), mBottomGridAnnotationDirection( Horizontal ),
4646
mCrossLength( 3 ), mMapCanvas( 0 ), mDrawCanvasItems( true )
4747
{
4848
mComposition = composition;
@@ -87,7 +87,9 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w
8787
QgsComposerMap::QgsComposerMap( QgsComposition *composition )
8888
: QgsComposerItem( 0, 0, 10, 10, composition ), mKeepLayerSet( false ), mGridEnabled( false ), mGridStyle( Solid ),
8989
mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ),
90-
mGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mGridAnnotationDirection( Horizontal ), mCrossLength( 3 ),
90+
mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ), mTopGridAnnotationPosition( OutsideMapFrame ),
91+
mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ),
92+
mTopGridAnnotationDirection( Horizontal ), mBottomGridAnnotationDirection( Horizontal ), mCrossLength( 3 ),
9193
mMapCanvas( 0 ), mDrawCanvasItems( true )
9294
{
9395
//Offset
@@ -694,9 +696,15 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
694696
//grid annotation
695697
QDomElement annotationElem = doc.createElement( "Annotation" );
696698
annotationElem.setAttribute( "show", mShowGridAnnotation );
697-
annotationElem.setAttribute( "position", mGridAnnotationPosition );
699+
annotationElem.setAttribute( "leftPosition", mLeftGridAnnotationPosition );
700+
annotationElem.setAttribute( "rightPosition", mRightGridAnnotationPosition );
701+
annotationElem.setAttribute( "topPosition", mTopGridAnnotationPosition );
702+
annotationElem.setAttribute( "bottomPosition", mBottomGridAnnotationPosition );
703+
annotationElem.setAttribute( "leftDirection", mLeftGridAnnotationDirection );
704+
annotationElem.setAttribute( "rightDirection", mRightGridAnnotationDirection );
705+
annotationElem.setAttribute( "topDirection", mTopGridAnnotationDirection );
706+
annotationElem.setAttribute( "bottomDirection", mBottomGridAnnotationDirection );
698707
annotationElem.setAttribute( "frameDistance", QString::number( mAnnotationFrameDistance ) );
699-
annotationElem.setAttribute( "direction", mGridAnnotationDirection );
700708
annotationElem.setAttribute( "font", mGridAnnotationFont.toString() );
701709
annotationElem.setAttribute( "precision", mGridAnnotationPrecision );
702710

@@ -811,9 +819,15 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
811819
{
812820
QDomElement annotationElem = annotationNodeList.at( 0 ).toElement();
813821
mShowGridAnnotation = ( annotationElem.attribute( "show", "0" ) != "0" );
814-
mGridAnnotationPosition = QgsComposerMap::GridAnnotationPosition( annotationElem.attribute( "position", "0" ).toInt() );
822+
mLeftGridAnnotationPosition = QgsComposerMap::GridAnnotationPosition( annotationElem.attribute( "leftPosition", "0" ).toInt() );
823+
mRightGridAnnotationPosition = QgsComposerMap::GridAnnotationPosition( annotationElem.attribute( "rightPosition", "0" ).toInt() );
824+
mTopGridAnnotationPosition = QgsComposerMap::GridAnnotationPosition( annotationElem.attribute( "topPosition", "0" ).toInt() );
825+
mBottomGridAnnotationPosition = QgsComposerMap::GridAnnotationPosition( annotationElem.attribute( "bottomPosition", "0" ).toInt() );
826+
mLeftGridAnnotationDirection = QgsComposerMap::GridAnnotationDirection( annotationElem.attribute( "leftDirection", "0" ).toInt() );
827+
mRightGridAnnotationDirection = QgsComposerMap::GridAnnotationDirection( annotationElem.attribute( "rightDirection", "0" ).toInt() );
828+
mTopGridAnnotationDirection = QgsComposerMap::GridAnnotationDirection( annotationElem.attribute( "topDirection", "0" ).toInt() );
829+
mBottomGridAnnotationDirection = QgsComposerMap::GridAnnotationDirection( annotationElem.attribute( "bottomDirection", "0" ).toInt() );
815830
mAnnotationFrameDistance = annotationElem.attribute( "frameDistance", "0" ).toDouble();
816-
mGridAnnotationDirection = QgsComposerMap::GridAnnotationDirection( annotationElem.attribute( "direction", "0" ).toInt() );
817831
mGridAnnotationFont.fromString( annotationElem.attribute( "font", "" ) );
818832
mGridAnnotationPrecision = annotationElem.attribute( "precision", "3" ).toInt();
819833
}
@@ -991,9 +1005,9 @@ void QgsComposerMap::drawCoordinateAnnotation( QPainter* p, const QPointF& pos,
9911005
if ( frameBorder == Left )
9921006
{
9931007

994-
if ( mGridAnnotationPosition == InsideMapFrame )
1008+
if ( mLeftGridAnnotationPosition == InsideMapFrame )
9951009
{
996-
if ( mGridAnnotationDirection == Vertical || mGridAnnotationDirection == BoundaryDirection )
1010+
if ( mLeftGridAnnotationDirection == Vertical || mLeftGridAnnotationDirection == BoundaryDirection )
9971011
{
9981012
xpos += textHeight + mAnnotationFrameDistance;
9991013
ypos += textWidth / 2.0;
@@ -1005,9 +1019,9 @@ void QgsComposerMap::drawCoordinateAnnotation( QPainter* p, const QPointF& pos,
10051019
ypos += textHeight / 2.0;
10061020
}
10071021
}
1008-
else //Outside map frame
1022+
else if ( mLeftGridAnnotationPosition == OutsideMapFrame ) //Outside map frame
10091023
{
1010-
if ( mGridAnnotationDirection == Vertical || mGridAnnotationDirection == BoundaryDirection )
1024+
if ( mLeftGridAnnotationDirection == Vertical || mLeftGridAnnotationDirection == BoundaryDirection )
10111025
{
10121026
xpos -= mAnnotationFrameDistance;
10131027
ypos += textWidth / 2.0;
@@ -1019,27 +1033,31 @@ void QgsComposerMap::drawCoordinateAnnotation( QPainter* p, const QPointF& pos,
10191033
ypos += textHeight / 2.0;
10201034
}
10211035
}
1036+
else
1037+
{
1038+
return;
1039+
}
10221040

10231041
}
10241042
else if ( frameBorder == Right )
10251043
{
1026-
if ( mGridAnnotationPosition == InsideMapFrame )
1044+
if ( mRightGridAnnotationPosition == InsideMapFrame )
10271045
{
1028-
if ( mGridAnnotationDirection == Vertical || mGridAnnotationDirection == BoundaryDirection )
1046+
if ( mRightGridAnnotationDirection == Vertical || mRightGridAnnotationDirection == BoundaryDirection )
10291047
{
10301048
xpos -= mAnnotationFrameDistance;
10311049
ypos += textWidth / 2.0;
10321050
rotation = 270;
10331051
}
1034-
else //Horizontal
1052+
else
10351053
{
10361054
xpos -= textWidth + mAnnotationFrameDistance;
10371055
ypos += textHeight / 2.0;
10381056
}
10391057
}
1040-
else //OutsideMapFrame
1058+
else if ( mRightGridAnnotationPosition == OutsideMapFrame )//OutsideMapFrame
10411059
{
1042-
if ( mGridAnnotationDirection == Vertical || mGridAnnotationDirection == BoundaryDirection )
1060+
if ( mRightGridAnnotationDirection == Vertical || mRightGridAnnotationDirection == BoundaryDirection )
10431061
{
10441062
xpos += textHeight + mAnnotationFrameDistance;
10451063
ypos += textWidth / 2.0;
@@ -1051,12 +1069,16 @@ void QgsComposerMap::drawCoordinateAnnotation( QPainter* p, const QPointF& pos,
10511069
ypos += textHeight / 2.0;
10521070
}
10531071
}
1072+
else
1073+
{
1074+
return;
1075+
}
10541076
}
10551077
else if ( frameBorder == Bottom )
10561078
{
1057-
if ( mGridAnnotationPosition == InsideMapFrame )
1079+
if ( mBottomGridAnnotationPosition == InsideMapFrame )
10581080
{
1059-
if ( mGridAnnotationDirection == Horizontal || mGridAnnotationDirection == BoundaryDirection )
1081+
if ( mBottomGridAnnotationDirection == Horizontal || mBottomGridAnnotationDirection == BoundaryDirection )
10601082
{
10611083
ypos -= mAnnotationFrameDistance;
10621084
xpos -= textWidth / 2.0;
@@ -1068,9 +1090,9 @@ void QgsComposerMap::drawCoordinateAnnotation( QPainter* p, const QPointF& pos,
10681090
rotation = 270;
10691091
}
10701092
}
1071-
else //OutsideMapFrame
1093+
else if ( mBottomGridAnnotationPosition == OutsideMapFrame ) //OutsideMapFrame
10721094
{
1073-
if ( mGridAnnotationDirection == Horizontal || mGridAnnotationDirection == BoundaryDirection )
1095+
if ( mBottomGridAnnotationDirection == Horizontal || mBottomGridAnnotationDirection == BoundaryDirection )
10741096
{
10751097
ypos += mAnnotationFrameDistance + textHeight;
10761098
xpos -= textWidth / 2.0;
@@ -1082,12 +1104,16 @@ void QgsComposerMap::drawCoordinateAnnotation( QPainter* p, const QPointF& pos,
10821104
rotation = 270;
10831105
}
10841106
}
1107+
else
1108+
{
1109+
return;
1110+
}
10851111
}
10861112
else //Top
10871113
{
1088-
if ( mGridAnnotationPosition == InsideMapFrame )
1114+
if ( mTopGridAnnotationPosition == InsideMapFrame )
10891115
{
1090-
if ( mGridAnnotationDirection == Horizontal || mGridAnnotationDirection == BoundaryDirection )
1116+
if ( mTopGridAnnotationDirection == Horizontal || mTopGridAnnotationDirection == BoundaryDirection )
10911117
{
10921118
xpos -= textWidth / 2.0;
10931119
ypos += textHeight + mAnnotationFrameDistance;
@@ -1099,9 +1125,9 @@ void QgsComposerMap::drawCoordinateAnnotation( QPainter* p, const QPointF& pos,
10991125
rotation = 270;
11001126
}
11011127
}
1102-
else //OutsideMapFrame
1128+
else if ( mTopGridAnnotationPosition == OutsideMapFrame ) //OutsideMapFrame
11031129
{
1104-
if ( mGridAnnotationDirection == Horizontal || mGridAnnotationDirection == BoundaryDirection )
1130+
if ( mTopGridAnnotationDirection == Horizontal || mTopGridAnnotationDirection == BoundaryDirection )
11051131
{
11061132
xpos -= textWidth / 2.0;
11071133
ypos -= mAnnotationFrameDistance;
@@ -1113,6 +1139,10 @@ void QgsComposerMap::drawCoordinateAnnotation( QPainter* p, const QPointF& pos,
11131139
rotation = 270;
11141140
}
11151141
}
1142+
else
1143+
{
1144+
return;
1145+
}
11161146
}
11171147

11181148
drawAnnotation( p, QPointF( xpos, ypos ), rotation, annotationString );
@@ -1320,7 +1350,8 @@ QPolygonF QgsComposerMap::transformedMapPolygon() const
13201350

13211351
double QgsComposerMap::maxExtension() const
13221352
{
1323-
if ( !mGridEnabled || !mShowGridAnnotation || mGridAnnotationPosition != OutsideMapFrame )
1353+
if ( !mGridEnabled || !mShowGridAnnotation || ( mLeftGridAnnotationPosition != OutsideMapFrame && mRightGridAnnotationPosition != OutsideMapFrame
1354+
&& mTopGridAnnotationPosition != OutsideMapFrame && mBottomGridAnnotationPosition != OutsideMapFrame ) )
13241355
{
13251356
return 0;
13261357
}
@@ -1611,3 +1642,90 @@ QPointF QgsComposerMap::composerMapPosForItem( const QGraphicsItem* item ) const
16111642
double mapY = mapRendererExtent.yMaximum() - itemScenePos.y() / graphicsSceneRect.height() * mapRendererExtent.height();
16121643
return mapToItemCoords( QPointF( mapX, mapY ) );
16131644
}
1645+
1646+
void QgsComposerMap::setGridAnnotationPosition( GridAnnotationPosition p, QgsComposerMap::Border border )
1647+
{
1648+
switch ( border )
1649+
{
1650+
case QgsComposerMap::Left:
1651+
mLeftGridAnnotationPosition = p;
1652+
break;
1653+
case QgsComposerMap::Right:
1654+
mRightGridAnnotationPosition = p;
1655+
break;
1656+
case QgsComposerMap::Top:
1657+
mTopGridAnnotationPosition = p;
1658+
break;
1659+
case QgsComposerMap::Bottom:
1660+
mBottomGridAnnotationPosition = p;
1661+
break;
1662+
default:
1663+
return;
1664+
}
1665+
updateBoundingRect();
1666+
update();
1667+
}
1668+
1669+
QgsComposerMap::GridAnnotationPosition QgsComposerMap::gridAnnotationPosition( QgsComposerMap::Border border ) const
1670+
{
1671+
switch ( border )
1672+
{
1673+
case QgsComposerMap::Left:
1674+
return mLeftGridAnnotationPosition;
1675+
break;
1676+
case QgsComposerMap::Right:
1677+
return mRightGridAnnotationPosition;
1678+
break;
1679+
case QgsComposerMap::Top:
1680+
return mTopGridAnnotationPosition;
1681+
break;
1682+
case QgsComposerMap::Bottom:
1683+
default:
1684+
return mBottomGridAnnotationPosition;
1685+
break;
1686+
}
1687+
}
1688+
1689+
void QgsComposerMap::setGridAnnotationDirection( GridAnnotationDirection d, QgsComposerMap::Border border )
1690+
{
1691+
switch ( border )
1692+
{
1693+
case QgsComposerMap::Left:
1694+
mLeftGridAnnotationDirection = d;
1695+
break;
1696+
case QgsComposerMap::Right:
1697+
mRightGridAnnotationDirection = d;
1698+
break;
1699+
case QgsComposerMap::Top:
1700+
mTopGridAnnotationDirection = d;
1701+
break;
1702+
case QgsComposerMap::Bottom:
1703+
mBottomGridAnnotationDirection = d;
1704+
break;
1705+
default:
1706+
return;
1707+
break;
1708+
}
1709+
updateBoundingRect();
1710+
update();
1711+
}
1712+
1713+
QgsComposerMap::GridAnnotationDirection QgsComposerMap::gridAnnotationDirection( QgsComposerMap::Border border ) const
1714+
{
1715+
switch ( border )
1716+
{
1717+
case QgsComposerMap::Left:
1718+
return mLeftGridAnnotationDirection;
1719+
break;
1720+
case QgsComposerMap::Right:
1721+
return mRightGridAnnotationDirection;
1722+
break;
1723+
case QgsComposerMap::Top:
1724+
return mTopGridAnnotationDirection;
1725+
break;
1726+
case QgsComposerMap::Bottom:
1727+
default:
1728+
return mBottomGridAnnotationDirection;
1729+
break;
1730+
}
1731+
}

‎src/core/composer/qgscomposermap.h

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
6666
enum GridAnnotationPosition
6767
{
6868
InsideMapFrame = 0,
69-
OutsideMapFrame
69+
OutsideMapFrame,
70+
Disabled
7071
};
7172

7273
enum GridAnnotationDirection
@@ -77,6 +78,15 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
7778
BoundaryDirection
7879
};
7980

81+
/**Enum for different frame borders*/
82+
enum Border
83+
{
84+
Left,
85+
Right,
86+
Bottom,
87+
Top
88+
};
89+
8090
/**This function is deprecated*/
8191
void draw( QPainter *painter, const QgsRectangle& extent, const QSize& size, int dpi );
8292

@@ -227,20 +237,16 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
227237
void setShowGridAnnotation( bool show ) {mShowGridAnnotation = show;}
228238
bool showGridAnnotation() const {return mShowGridAnnotation;}
229239

230-
/**Sets position of grid annotations. Possibilities are inside or outside of the map frame
231-
@note this function was added in version 1.4*/
232-
void setGridAnnotationPosition( GridAnnotationPosition p ) {mGridAnnotationPosition = p;}
233-
GridAnnotationPosition gridAnnotationPosition() const {return mGridAnnotationPosition;}
240+
void setGridAnnotationPosition( GridAnnotationPosition p, QgsComposerMap::Border border );
241+
GridAnnotationPosition gridAnnotationPosition( QgsComposerMap::Border border ) const;
234242

235243
/**Sets distance between map frame and annotations
236244
@note this function was added in version 1.4*/
237245
void setAnnotationFrameDistance( double d ) {mAnnotationFrameDistance = d;}
238246
double annotationFrameDistance() const {return mAnnotationFrameDistance;}
239247

240-
/**Sets grid annotation direction. Can be horizontal, vertical, direction of axis and horizontal and vertical
241-
@note this function was added in version 1.4*/
242-
void setGridAnnotationDirection( GridAnnotationDirection d ) {mGridAnnotationDirection = d;}
243-
GridAnnotationDirection gridAnnotationDirection() const {return mGridAnnotationDirection;}
248+
void setGridAnnotationDirection( GridAnnotationDirection d, QgsComposerMap::Border border );
249+
GridAnnotationDirection gridAnnotationDirection( QgsComposerMap::Border border ) const;
244250

245251
/**In case of annotations, the bounding rectangle can be larger than the map item rectangle
246252
@note this function was added in version 1.4*/
@@ -279,15 +285,6 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
279285

280286
private:
281287

282-
/**Enum for different frame borders*/
283-
enum Border
284-
{
285-
Left,
286-
Right,
287-
Bottom,
288-
Top
289-
};
290-
291288
// Pointer to map renderer of the QGIS main map. Note that QgsComposerMap uses a different map renderer,
292289
//it just copies some properties from the main map renderer.
293290
QgsMapRenderer *mMapRenderer;
@@ -352,12 +349,28 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
352349
int mGridAnnotationPrecision;
353350
/**True if coordinate values should be drawn*/
354351
bool mShowGridAnnotation;
355-
/**Annotation position inside or outside of map frame*/
356-
GridAnnotationPosition mGridAnnotationPosition;
352+
353+
/**Annotation position for left map side (inside / outside / not shown)*/
354+
GridAnnotationPosition mLeftGridAnnotationPosition;
355+
/**Annotation position for right map side (inside / outside / not shown)*/
356+
GridAnnotationPosition mRightGridAnnotationPosition;
357+
/**Annotation position for top map side (inside / outside / not shown)*/
358+
GridAnnotationPosition mTopGridAnnotationPosition;
359+
/**Annotation position for bottom map side (inside / outside / not shown)*/
360+
GridAnnotationPosition mBottomGridAnnotationPosition;
361+
357362
/**Distance between map frame and annotation*/
358363
double mAnnotationFrameDistance;
359-
/**Annotation can be horizontal / vertical or different for axes*/
360-
GridAnnotationDirection mGridAnnotationDirection;
364+
365+
/**Annotation direction on left side ( horizontal or vertical )*/
366+
GridAnnotationDirection mLeftGridAnnotationDirection;
367+
/**Annotation direction on right side ( horizontal or vertical )*/
368+
GridAnnotationDirection mRightGridAnnotationDirection;
369+
/**Annotation direction on top side ( horizontal or vertical )*/
370+
GridAnnotationDirection mTopGridAnnotationDirection;
371+
/**Annotation direction on bottom side ( horizontal or vertical )*/
372+
GridAnnotationDirection mBottomGridAnnotationDirection;
373+
361374
/**Current bounding rectangle. This is used to check if notification to the graphics scene is necessary*/
362375
QRectF mCurrentRectangle;
363376
/**The length of the cross sides for mGridStyle Cross*/

‎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

‎src/ui/qgscomposermapwidgetbase.ui

Lines changed: 284 additions & 198 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.