Skip to content

Commit 8b29097

Browse files
committedNov 6, 2014
[FEATURE][composer] Vertical descending direction for annotations
This change adds a new descending vertical direction mode for map grid annotations. Previously only ascending text was supported for vertical annotations.
1 parent b242324 commit 8b29097

File tree

8 files changed

+107
-39
lines changed

8 files changed

+107
-39
lines changed
 

‎python/core/composer/qgscomposermapgrid.sip

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,9 @@ class QgsComposerMapGrid : QgsComposerMapItem
163163
*/
164164
enum AnnotationDirection
165165
{
166-
Horizontal, /*< draw annotations horizontally */
167-
Vertical, /*< draw annotations vertically */
166+
Horizontal = 0, /*< draw annotations horizontally */
167+
Vertical, /*< draw annotations vertically, ascending */
168+
VerticalDescending, /*< draw annotations vertically, descending */
168169
BoundaryDirection /*< annotations follow the boundary direction */
169170
};
170171

‎src/app/composer/qgscomposermapwidget.cpp

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -914,8 +914,9 @@ void QgsComposerMapWidget::insertAnnotationPositionEntries( QComboBox* c )
914914

915915
void QgsComposerMapWidget::insertAnnotationDirectionEntries( QComboBox* c )
916916
{
917-
c->insertItem( 0, tr( "Horizontal" ) );
918-
c->insertItem( 1, tr( "Vertical" ) );
917+
c->addItem( tr( "Horizontal" ), QgsComposerMapGrid::Horizontal );
918+
c->addItem( tr( "Vertical ascending" ), QgsComposerMapGrid::Vertical );
919+
c->addItem( tr( "Vertical descending" ), QgsComposerMapGrid::VerticalDescending );
919920
}
920921

921922
void QgsComposerMapWidget::initFrameDisplayBox( QComboBox *c, QgsComposerMapGrid::DisplayMode display )
@@ -979,7 +980,7 @@ void QgsComposerMapWidget::handleChangedAnnotationPosition( QgsComposerMapGrid::
979980
mComposerMap->endCommand();
980981
}
981982

982-
void QgsComposerMapWidget::handleChangedAnnotationDirection( QgsComposerMapGrid::BorderSide border, const QString& text )
983+
void QgsComposerMapWidget::handleChangedAnnotationDirection( QgsComposerMapGrid::BorderSide border, const QgsComposerMapGrid::AnnotationDirection& direction )
983984
{
984985
QgsComposerMapGrid* grid = currentGrid();
985986
if ( !grid )
@@ -988,14 +989,7 @@ void QgsComposerMapWidget::handleChangedAnnotationDirection( QgsComposerMapGrid:
988989
}
989990

990991
mComposerMap->beginCommand( tr( "Changed annotation direction" ) );
991-
if ( text == tr( "Horizontal" ) )
992-
{
993-
grid->setAnnotationDirection( QgsComposerMapGrid::Horizontal, border );
994-
}
995-
else if ( text == tr( "Vertical" ) )
996-
{
997-
grid->setAnnotationDirection( QgsComposerMapGrid::Vertical, border );
998-
}
992+
grid->setAnnotationDirection( direction, border );
999993
mComposerMap->updateBoundingRect();
1000994
mComposerMap->update();
1001995
mComposerMap->endCommand();
@@ -1039,16 +1033,7 @@ void QgsComposerMapWidget::initAnnotationDirectionBox( QComboBox* c, QgsComposer
10391033
{
10401034
return;
10411035
}
1042-
1043-
if ( dir == QgsComposerMapGrid::Vertical )
1044-
{
1045-
c->setCurrentIndex( c->findText( tr( "Vertical" ) ) );
1046-
}
1047-
else if ( dir == QgsComposerMapGrid::Horizontal )
1048-
{
1049-
c->setCurrentIndex( c->findText( tr( "Horizontal" ) ) );
1050-
}
1051-
1036+
c->setCurrentIndex( c->findData( dir ) );
10521037
}
10531038

10541039
void QgsComposerMapWidget::refreshMapComboBox()
@@ -2026,24 +2011,24 @@ void QgsComposerMapWidget::on_mAnnotationPositionBottomComboBox_currentIndexChan
20262011
handleChangedAnnotationPosition( QgsComposerMapGrid::Bottom, text );
20272012
}
20282013

2029-
void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxLeft_currentIndexChanged( const QString& text )
2014+
void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxLeft_currentIndexChanged( int index )
20302015
{
2031-
handleChangedAnnotationDirection( QgsComposerMapGrid::Left, text );
2016+
handleChangedAnnotationDirection( QgsComposerMapGrid::Left, ( QgsComposerMapGrid::AnnotationDirection ) mAnnotationDirectionComboBoxLeft->itemData( index ).toInt() );
20322017
}
20332018

2034-
void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxRight_currentIndexChanged( const QString& text )
2019+
void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxRight_currentIndexChanged( int index )
20352020
{
2036-
handleChangedAnnotationDirection( QgsComposerMapGrid::Right, text );
2021+
handleChangedAnnotationDirection( QgsComposerMapGrid::Right, ( QgsComposerMapGrid::AnnotationDirection ) mAnnotationDirectionComboBoxRight->itemData( index ).toInt() );
20372022
}
20382023

2039-
void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxTop_currentIndexChanged( const QString& text )
2024+
void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxTop_currentIndexChanged( int index )
20402025
{
2041-
handleChangedAnnotationDirection( QgsComposerMapGrid::Top, text );
2026+
handleChangedAnnotationDirection( QgsComposerMapGrid::Top, ( QgsComposerMapGrid::AnnotationDirection ) mAnnotationDirectionComboBoxTop->itemData( index ).toInt() );
20422027
}
20432028

2044-
void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxBottom_currentIndexChanged( const QString& text )
2029+
void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxBottom_currentIndexChanged( int index )
20452030
{
2046-
handleChangedAnnotationDirection( QgsComposerMapGrid::Bottom, text );
2031+
handleChangedAnnotationDirection( QgsComposerMapGrid::Bottom, ( QgsComposerMapGrid::AnnotationDirection ) mAnnotationDirectionComboBoxBottom->itemData( index ).toInt() );
20472032
}
20482033

20492034
void QgsComposerMapWidget::on_mDistanceToMapFrameSpinBox_valueChanged( double d )

‎src/app/composer/qgscomposermapwidget.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ class QgsComposerMapWidget: public QgsComposerItemBaseWidget, private Ui::QgsCom
119119
void on_mAnnotationPositionBottomComboBox_currentIndexChanged( const QString& text );
120120

121121
//annotation direction
122-
void on_mAnnotationDirectionComboBoxLeft_currentIndexChanged( const QString& text );
123-
void on_mAnnotationDirectionComboBoxRight_currentIndexChanged( const QString& text );
124-
void on_mAnnotationDirectionComboBoxTop_currentIndexChanged( const QString& text );
125-
void on_mAnnotationDirectionComboBoxBottom_currentIndexChanged( const QString& text );
122+
void on_mAnnotationDirectionComboBoxLeft_currentIndexChanged( int index );
123+
void on_mAnnotationDirectionComboBoxRight_currentIndexChanged( int index );
124+
void on_mAnnotationDirectionComboBoxTop_currentIndexChanged( int index );
125+
void on_mAnnotationDirectionComboBoxBottom_currentIndexChanged( int index );
126126

127127
void on_mAnnotationFormatComboBox_currentIndexChanged( int index );
128128
void on_mCoordinatePrecisionSpinBox_valueChanged( int value );
@@ -184,7 +184,7 @@ class QgsComposerMapWidget: public QgsComposerItemBaseWidget, private Ui::QgsCom
184184
void handleChangedFrameDisplay( QgsComposerMapGrid::BorderSide border, const QgsComposerMapGrid::DisplayMode mode );
185185
void handleChangedAnnotationDisplay( QgsComposerMapGrid::BorderSide border, const QString& text );
186186
void handleChangedAnnotationPosition( QgsComposerMapGrid::BorderSide border, const QString& text );
187-
void handleChangedAnnotationDirection( QgsComposerMapGrid::BorderSide border, const QString& text );
187+
void handleChangedAnnotationDirection( QgsComposerMapGrid::BorderSide border, const QgsComposerMapGrid::AnnotationDirection &direction );
188188

189189
void insertFrameDisplayEntries( QComboBox* c );
190190
void insertAnnotationDisplayEntries( QComboBox* c );

‎src/core/composer/qgscomposermapgrid.cpp

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,12 @@ void QgsComposerMapGrid::drawCoordinateAnnotation( QPainter* p, const QPointF& p
10881088
ypos += textWidth / 2.0;
10891089
rotation = 270;
10901090
}
1091+
else if ( mLeftGridAnnotationDirection == QgsComposerMapGrid::VerticalDescending )
1092+
{
1093+
xpos += ( mAnnotationFrameDistance + gridFrameDistance );
1094+
ypos -= textWidth / 2.0;
1095+
rotation = 90;
1096+
}
10911097
else
10921098
{
10931099
xpos += mAnnotationFrameDistance + gridFrameDistance;
@@ -1106,6 +1112,12 @@ void QgsComposerMapGrid::drawCoordinateAnnotation( QPainter* p, const QPointF& p
11061112
ypos += textWidth / 2.0;
11071113
rotation = 270;
11081114
}
1115+
else if ( mLeftGridAnnotationDirection == QgsComposerMapGrid::VerticalDescending )
1116+
{
1117+
xpos -= textHeight + mAnnotationFrameDistance + gridFrameDistance;
1118+
ypos -= textWidth / 2.0;
1119+
rotation = 90;
1120+
}
11091121
else
11101122
{
11111123
xpos -= ( textWidth + mAnnotationFrameDistance + gridFrameDistance );
@@ -1137,12 +1149,18 @@ void QgsComposerMapGrid::drawCoordinateAnnotation( QPainter* p, const QPointF& p
11371149
{
11381150
gridFrameDistance = 0;
11391151
}
1140-
if ( mRightGridAnnotationDirection == QgsComposerMapGrid::Vertical || mRightGridAnnotationDirection == QgsComposerMapGrid::BoundaryDirection )
1152+
if ( mRightGridAnnotationDirection == QgsComposerMapGrid::Vertical )
11411153
{
11421154
xpos -= mAnnotationFrameDistance + gridFrameDistance;
11431155
ypos += textWidth / 2.0;
11441156
rotation = 270;
11451157
}
1158+
else if ( mRightGridAnnotationDirection == QgsComposerMapGrid::VerticalDescending || mRightGridAnnotationDirection == QgsComposerMapGrid::BoundaryDirection )
1159+
{
1160+
xpos -= textHeight + mAnnotationFrameDistance + gridFrameDistance;
1161+
ypos -= textWidth / 2.0;
1162+
rotation = 90;
1163+
}
11461164
else
11471165
{
11481166
xpos -= textWidth + mAnnotationFrameDistance + gridFrameDistance;
@@ -1155,12 +1173,18 @@ void QgsComposerMapGrid::drawCoordinateAnnotation( QPainter* p, const QPointF& p
11551173
{
11561174
gridFrameDistance = 0;
11571175
}
1158-
if ( mRightGridAnnotationDirection == QgsComposerMapGrid::Vertical || mRightGridAnnotationDirection == QgsComposerMapGrid::BoundaryDirection )
1176+
if ( mRightGridAnnotationDirection == QgsComposerMapGrid::Vertical )
11591177
{
11601178
xpos += ( textHeight + mAnnotationFrameDistance + gridFrameDistance );
11611179
ypos += textWidth / 2.0;
11621180
rotation = 270;
11631181
}
1182+
else if ( mRightGridAnnotationDirection == QgsComposerMapGrid::VerticalDescending || mRightGridAnnotationDirection == QgsComposerMapGrid::BoundaryDirection )
1183+
{
1184+
xpos += ( mAnnotationFrameDistance + gridFrameDistance );
1185+
ypos -= textWidth / 2.0;
1186+
rotation = 90;
1187+
}
11641188
else //Horizontal
11651189
{
11661190
xpos += ( mAnnotationFrameDistance + gridFrameDistance );
@@ -1196,6 +1220,12 @@ void QgsComposerMapGrid::drawCoordinateAnnotation( QPainter* p, const QPointF& p
11961220
ypos -= mAnnotationFrameDistance + gridFrameDistance;
11971221
xpos -= textWidth / 2.0;
11981222
}
1223+
else if ( mBottomGridAnnotationDirection == QgsComposerMapGrid::VerticalDescending )
1224+
{
1225+
xpos -= textHeight / 2.0;
1226+
ypos -= textWidth + mAnnotationFrameDistance + gridFrameDistance;
1227+
rotation = 90;
1228+
}
11991229
else //Vertical
12001230
{
12011231
xpos += textHeight / 2.0;
@@ -1214,6 +1244,12 @@ void QgsComposerMapGrid::drawCoordinateAnnotation( QPainter* p, const QPointF& p
12141244
ypos += ( mAnnotationFrameDistance + textHeight + gridFrameDistance );
12151245
xpos -= textWidth / 2.0;
12161246
}
1247+
else if ( mBottomGridAnnotationDirection == QgsComposerMapGrid::VerticalDescending )
1248+
{
1249+
xpos -= textHeight / 2.0;
1250+
ypos += gridFrameDistance + mAnnotationFrameDistance;
1251+
rotation = 90;
1252+
}
12171253
else //Vertical
12181254
{
12191255
xpos += textHeight / 2.0;
@@ -1250,6 +1286,12 @@ void QgsComposerMapGrid::drawCoordinateAnnotation( QPainter* p, const QPointF& p
12501286
xpos -= textWidth / 2.0;
12511287
ypos += textHeight + mAnnotationFrameDistance + gridFrameDistance;
12521288
}
1289+
else if ( mTopGridAnnotationDirection == QgsComposerMapGrid::VerticalDescending )
1290+
{
1291+
xpos -= textHeight / 2.0;
1292+
ypos += mAnnotationFrameDistance + gridFrameDistance;
1293+
rotation = 90;
1294+
}
12531295
else //Vertical
12541296
{
12551297
xpos += textHeight / 2.0;
@@ -1268,6 +1310,12 @@ void QgsComposerMapGrid::drawCoordinateAnnotation( QPainter* p, const QPointF& p
12681310
xpos -= textWidth / 2.0;
12691311
ypos -= ( mAnnotationFrameDistance + gridFrameDistance );
12701312
}
1313+
else if ( mTopGridAnnotationDirection == QgsComposerMapGrid::VerticalDescending )
1314+
{
1315+
xpos -= textHeight / 2.0;
1316+
ypos -= textWidth + mAnnotationFrameDistance + gridFrameDistance;
1317+
rotation = 90;
1318+
}
12711319
else //Vertical
12721320
{
12731321
xpos += textHeight / 2.0;

‎src/core/composer/qgscomposermapgrid.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ class CORE_EXPORT QgsComposerMapGrid : public QgsComposerMapItem
199199
enum AnnotationDirection
200200
{
201201
Horizontal = 0, /*< draw annotations horizontally */
202-
Vertical, /*< draw annotations vertically */
202+
Vertical, /*< draw annotations vertically, ascending */
203+
VerticalDescending, /*< draw annotations vertically, descending */
203204
BoundaryDirection /*< annotations follow the boundary direction */
204205
};
205206

‎tests/src/core/testqgscomposermapgrid.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class TestQgsComposerMapGrid: public QObject
5252
void lineBorder(); //test line border frame mode
5353
void lineBorderAnnotated(); //test line border frame with annotations
5454
void annotationFormats(); //various tests for annotation formats
55+
void descendingAnnotations(); //test descending annotation direction
5556

5657
private:
5758
QgsComposition* mComposition;
@@ -608,7 +609,39 @@ void TestQgsComposerMapGrid::annotationFormats()
608609

609610
}
610611

612+
void TestQgsComposerMapGrid::descendingAnnotations()
613+
{
614+
mComposerMap->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3345223.125 ) );
611615

616+
mComposerMap->grid()->setFrameStyle( QgsComposerMapGrid::NoFrame );
617+
mComposerMap->grid()->setEnabled( true );
618+
mComposerMap->grid()->setStyle( QgsComposerMapGrid::FrameAnnotationsOnly );
619+
mComposerMap->grid()->setAnnotationEnabled( true );
620+
mComposerMap->grid()->setAnnotationFontColor( Qt::black );
621+
mComposerMap->grid()->setAnnotationPosition( QgsComposerMapGrid::InsideMapFrame, QgsComposerMapGrid::Left );
622+
mComposerMap->grid()->setAnnotationPosition( QgsComposerMapGrid::InsideMapFrame, QgsComposerMapGrid::Right );
623+
mComposerMap->grid()->setAnnotationPosition( QgsComposerMapGrid::InsideMapFrame, QgsComposerMapGrid::Top );
624+
mComposerMap->grid()->setAnnotationPosition( QgsComposerMapGrid::InsideMapFrame, QgsComposerMapGrid::Bottom );
625+
mComposerMap->grid()->setAnnotationDirection( QgsComposerMapGrid::VerticalDescending, QgsComposerMapGrid::Left );
626+
mComposerMap->grid()->setAnnotationDirection( QgsComposerMapGrid::VerticalDescending, QgsComposerMapGrid::Right );
627+
mComposerMap->grid()->setAnnotationDirection( QgsComposerMapGrid::VerticalDescending, QgsComposerMapGrid::Top );
628+
mComposerMap->grid()->setAnnotationDirection( QgsComposerMapGrid::VerticalDescending, QgsComposerMapGrid::Bottom );
629+
630+
QgsCompositionChecker checker( "composermap_verticaldescending_inside", mComposition );
631+
bool testResult = checker.testComposition( mReport, 0, 0 );
632+
QVERIFY( testResult );
633+
634+
mComposerMap->grid()->setAnnotationPosition( QgsComposerMapGrid::OutsideMapFrame, QgsComposerMapGrid::Left );
635+
mComposerMap->grid()->setAnnotationPosition( QgsComposerMapGrid::OutsideMapFrame, QgsComposerMapGrid::Right );
636+
mComposerMap->grid()->setAnnotationPosition( QgsComposerMapGrid::OutsideMapFrame, QgsComposerMapGrid::Top );
637+
mComposerMap->grid()->setAnnotationPosition( QgsComposerMapGrid::OutsideMapFrame, QgsComposerMapGrid::Bottom );
638+
639+
QgsCompositionChecker checker2( "composermap_verticaldescending_outside", mComposition );
640+
bool testResult2 = checker2.testComposition( mReport, 0, 0 );
641+
QVERIFY( testResult2 );
642+
643+
mComposerMap->grid()->setAnnotationEnabled( false );
644+
}
612645

613646
QTEST_MAIN( TestQgsComposerMapGrid )
614647
#include "testqgscomposermapgrid.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.