diff --git a/python/core/composer/qgscomposermapgrid.sip b/python/core/composer/qgscomposermapgrid.sip index 2f2702a28db..eb1cd814930 100644 --- a/python/core/composer/qgscomposermapgrid.sip +++ b/python/core/composer/qgscomposermapgrid.sip @@ -163,8 +163,9 @@ class QgsComposerMapGrid : QgsComposerMapItem */ enum AnnotationDirection { - Horizontal, /*< draw annotations horizontally */ - Vertical, /*< draw annotations vertically */ + Horizontal = 0, /*< draw annotations horizontally */ + Vertical, /*< draw annotations vertically, ascending */ + VerticalDescending, /*< draw annotations vertically, descending */ BoundaryDirection /*< annotations follow the boundary direction */ }; diff --git a/src/app/composer/qgscomposermapwidget.cpp b/src/app/composer/qgscomposermapwidget.cpp index c0dae160668..4e3609ff50f 100644 --- a/src/app/composer/qgscomposermapwidget.cpp +++ b/src/app/composer/qgscomposermapwidget.cpp @@ -914,8 +914,9 @@ void QgsComposerMapWidget::insertAnnotationPositionEntries( QComboBox* c ) void QgsComposerMapWidget::insertAnnotationDirectionEntries( QComboBox* c ) { - c->insertItem( 0, tr( "Horizontal" ) ); - c->insertItem( 1, tr( "Vertical" ) ); + c->addItem( tr( "Horizontal" ), QgsComposerMapGrid::Horizontal ); + c->addItem( tr( "Vertical ascending" ), QgsComposerMapGrid::Vertical ); + c->addItem( tr( "Vertical descending" ), QgsComposerMapGrid::VerticalDescending ); } void QgsComposerMapWidget::initFrameDisplayBox( QComboBox *c, QgsComposerMapGrid::DisplayMode display ) @@ -979,7 +980,7 @@ void QgsComposerMapWidget::handleChangedAnnotationPosition( QgsComposerMapGrid:: mComposerMap->endCommand(); } -void QgsComposerMapWidget::handleChangedAnnotationDirection( QgsComposerMapGrid::BorderSide border, const QString& text ) +void QgsComposerMapWidget::handleChangedAnnotationDirection( QgsComposerMapGrid::BorderSide border, const QgsComposerMapGrid::AnnotationDirection& direction ) { QgsComposerMapGrid* grid = currentGrid(); if ( !grid ) @@ -988,14 +989,7 @@ void QgsComposerMapWidget::handleChangedAnnotationDirection( QgsComposerMapGrid: } mComposerMap->beginCommand( tr( "Changed annotation direction" ) ); - if ( text == tr( "Horizontal" ) ) - { - grid->setAnnotationDirection( QgsComposerMapGrid::Horizontal, border ); - } - else if ( text == tr( "Vertical" ) ) - { - grid->setAnnotationDirection( QgsComposerMapGrid::Vertical, border ); - } + grid->setAnnotationDirection( direction, border ); mComposerMap->updateBoundingRect(); mComposerMap->update(); mComposerMap->endCommand(); @@ -1039,16 +1033,7 @@ void QgsComposerMapWidget::initAnnotationDirectionBox( QComboBox* c, QgsComposer { return; } - - if ( dir == QgsComposerMapGrid::Vertical ) - { - c->setCurrentIndex( c->findText( tr( "Vertical" ) ) ); - } - else if ( dir == QgsComposerMapGrid::Horizontal ) - { - c->setCurrentIndex( c->findText( tr( "Horizontal" ) ) ); - } - + c->setCurrentIndex( c->findData( dir ) ); } void QgsComposerMapWidget::refreshMapComboBox() @@ -2026,24 +2011,24 @@ void QgsComposerMapWidget::on_mAnnotationPositionBottomComboBox_currentIndexChan handleChangedAnnotationPosition( QgsComposerMapGrid::Bottom, text ); } -void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxLeft_currentIndexChanged( const QString& text ) +void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxLeft_currentIndexChanged( int index ) { - handleChangedAnnotationDirection( QgsComposerMapGrid::Left, text ); + handleChangedAnnotationDirection( QgsComposerMapGrid::Left, ( QgsComposerMapGrid::AnnotationDirection ) mAnnotationDirectionComboBoxLeft->itemData( index ).toInt() ); } -void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxRight_currentIndexChanged( const QString& text ) +void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxRight_currentIndexChanged( int index ) { - handleChangedAnnotationDirection( QgsComposerMapGrid::Right, text ); + handleChangedAnnotationDirection( QgsComposerMapGrid::Right, ( QgsComposerMapGrid::AnnotationDirection ) mAnnotationDirectionComboBoxRight->itemData( index ).toInt() ); } -void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxTop_currentIndexChanged( const QString& text ) +void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxTop_currentIndexChanged( int index ) { - handleChangedAnnotationDirection( QgsComposerMapGrid::Top, text ); + handleChangedAnnotationDirection( QgsComposerMapGrid::Top, ( QgsComposerMapGrid::AnnotationDirection ) mAnnotationDirectionComboBoxTop->itemData( index ).toInt() ); } -void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxBottom_currentIndexChanged( const QString& text ) +void QgsComposerMapWidget::on_mAnnotationDirectionComboBoxBottom_currentIndexChanged( int index ) { - handleChangedAnnotationDirection( QgsComposerMapGrid::Bottom, text ); + handleChangedAnnotationDirection( QgsComposerMapGrid::Bottom, ( QgsComposerMapGrid::AnnotationDirection ) mAnnotationDirectionComboBoxBottom->itemData( index ).toInt() ); } void QgsComposerMapWidget::on_mDistanceToMapFrameSpinBox_valueChanged( double d ) diff --git a/src/app/composer/qgscomposermapwidget.h b/src/app/composer/qgscomposermapwidget.h index f4265c16b80..ae70cb23f11 100644 --- a/src/app/composer/qgscomposermapwidget.h +++ b/src/app/composer/qgscomposermapwidget.h @@ -119,10 +119,10 @@ class QgsComposerMapWidget: public QgsComposerItemBaseWidget, private Ui::QgsCom void on_mAnnotationPositionBottomComboBox_currentIndexChanged( const QString& text ); //annotation direction - void on_mAnnotationDirectionComboBoxLeft_currentIndexChanged( const QString& text ); - void on_mAnnotationDirectionComboBoxRight_currentIndexChanged( const QString& text ); - void on_mAnnotationDirectionComboBoxTop_currentIndexChanged( const QString& text ); - void on_mAnnotationDirectionComboBoxBottom_currentIndexChanged( const QString& text ); + void on_mAnnotationDirectionComboBoxLeft_currentIndexChanged( int index ); + void on_mAnnotationDirectionComboBoxRight_currentIndexChanged( int index ); + void on_mAnnotationDirectionComboBoxTop_currentIndexChanged( int index ); + void on_mAnnotationDirectionComboBoxBottom_currentIndexChanged( int index ); void on_mAnnotationFormatComboBox_currentIndexChanged( int index ); void on_mCoordinatePrecisionSpinBox_valueChanged( int value ); @@ -184,7 +184,7 @@ class QgsComposerMapWidget: public QgsComposerItemBaseWidget, private Ui::QgsCom void handleChangedFrameDisplay( QgsComposerMapGrid::BorderSide border, const QgsComposerMapGrid::DisplayMode mode ); void handleChangedAnnotationDisplay( QgsComposerMapGrid::BorderSide border, const QString& text ); void handleChangedAnnotationPosition( QgsComposerMapGrid::BorderSide border, const QString& text ); - void handleChangedAnnotationDirection( QgsComposerMapGrid::BorderSide border, const QString& text ); + void handleChangedAnnotationDirection( QgsComposerMapGrid::BorderSide border, const QgsComposerMapGrid::AnnotationDirection &direction ); void insertFrameDisplayEntries( QComboBox* c ); void insertAnnotationDisplayEntries( QComboBox* c ); diff --git a/src/core/composer/qgscomposermapgrid.cpp b/src/core/composer/qgscomposermapgrid.cpp index b6f25a1bb15..0fbfabcc10d 100644 --- a/src/core/composer/qgscomposermapgrid.cpp +++ b/src/core/composer/qgscomposermapgrid.cpp @@ -1088,6 +1088,12 @@ void QgsComposerMapGrid::drawCoordinateAnnotation( QPainter* p, const QPointF& p ypos += textWidth / 2.0; rotation = 270; } + else if ( mLeftGridAnnotationDirection == QgsComposerMapGrid::VerticalDescending ) + { + xpos += ( mAnnotationFrameDistance + gridFrameDistance ); + ypos -= textWidth / 2.0; + rotation = 90; + } else { xpos += mAnnotationFrameDistance + gridFrameDistance; @@ -1106,6 +1112,12 @@ void QgsComposerMapGrid::drawCoordinateAnnotation( QPainter* p, const QPointF& p ypos += textWidth / 2.0; rotation = 270; } + else if ( mLeftGridAnnotationDirection == QgsComposerMapGrid::VerticalDescending ) + { + xpos -= textHeight + mAnnotationFrameDistance + gridFrameDistance; + ypos -= textWidth / 2.0; + rotation = 90; + } else { xpos -= ( textWidth + mAnnotationFrameDistance + gridFrameDistance ); @@ -1137,12 +1149,18 @@ void QgsComposerMapGrid::drawCoordinateAnnotation( QPainter* p, const QPointF& p { gridFrameDistance = 0; } - if ( mRightGridAnnotationDirection == QgsComposerMapGrid::Vertical || mRightGridAnnotationDirection == QgsComposerMapGrid::BoundaryDirection ) + if ( mRightGridAnnotationDirection == QgsComposerMapGrid::Vertical ) { xpos -= mAnnotationFrameDistance + gridFrameDistance; ypos += textWidth / 2.0; rotation = 270; } + else if ( mRightGridAnnotationDirection == QgsComposerMapGrid::VerticalDescending || mRightGridAnnotationDirection == QgsComposerMapGrid::BoundaryDirection ) + { + xpos -= textHeight + mAnnotationFrameDistance + gridFrameDistance; + ypos -= textWidth / 2.0; + rotation = 90; + } else { xpos -= textWidth + mAnnotationFrameDistance + gridFrameDistance; @@ -1155,12 +1173,18 @@ void QgsComposerMapGrid::drawCoordinateAnnotation( QPainter* p, const QPointF& p { gridFrameDistance = 0; } - if ( mRightGridAnnotationDirection == QgsComposerMapGrid::Vertical || mRightGridAnnotationDirection == QgsComposerMapGrid::BoundaryDirection ) + if ( mRightGridAnnotationDirection == QgsComposerMapGrid::Vertical ) { xpos += ( textHeight + mAnnotationFrameDistance + gridFrameDistance ); ypos += textWidth / 2.0; rotation = 270; } + else if ( mRightGridAnnotationDirection == QgsComposerMapGrid::VerticalDescending || mRightGridAnnotationDirection == QgsComposerMapGrid::BoundaryDirection ) + { + xpos += ( mAnnotationFrameDistance + gridFrameDistance ); + ypos -= textWidth / 2.0; + rotation = 90; + } else //Horizontal { xpos += ( mAnnotationFrameDistance + gridFrameDistance ); @@ -1196,6 +1220,12 @@ void QgsComposerMapGrid::drawCoordinateAnnotation( QPainter* p, const QPointF& p ypos -= mAnnotationFrameDistance + gridFrameDistance; xpos -= textWidth / 2.0; } + else if ( mBottomGridAnnotationDirection == QgsComposerMapGrid::VerticalDescending ) + { + xpos -= textHeight / 2.0; + ypos -= textWidth + mAnnotationFrameDistance + gridFrameDistance; + rotation = 90; + } else //Vertical { xpos += textHeight / 2.0; @@ -1214,6 +1244,12 @@ void QgsComposerMapGrid::drawCoordinateAnnotation( QPainter* p, const QPointF& p ypos += ( mAnnotationFrameDistance + textHeight + gridFrameDistance ); xpos -= textWidth / 2.0; } + else if ( mBottomGridAnnotationDirection == QgsComposerMapGrid::VerticalDescending ) + { + xpos -= textHeight / 2.0; + ypos += gridFrameDistance + mAnnotationFrameDistance; + rotation = 90; + } else //Vertical { xpos += textHeight / 2.0; @@ -1250,6 +1286,12 @@ void QgsComposerMapGrid::drawCoordinateAnnotation( QPainter* p, const QPointF& p xpos -= textWidth / 2.0; ypos += textHeight + mAnnotationFrameDistance + gridFrameDistance; } + else if ( mTopGridAnnotationDirection == QgsComposerMapGrid::VerticalDescending ) + { + xpos -= textHeight / 2.0; + ypos += mAnnotationFrameDistance + gridFrameDistance; + rotation = 90; + } else //Vertical { xpos += textHeight / 2.0; @@ -1268,6 +1310,12 @@ void QgsComposerMapGrid::drawCoordinateAnnotation( QPainter* p, const QPointF& p xpos -= textWidth / 2.0; ypos -= ( mAnnotationFrameDistance + gridFrameDistance ); } + else if ( mTopGridAnnotationDirection == QgsComposerMapGrid::VerticalDescending ) + { + xpos -= textHeight / 2.0; + ypos -= textWidth + mAnnotationFrameDistance + gridFrameDistance; + rotation = 90; + } else //Vertical { xpos += textHeight / 2.0; diff --git a/src/core/composer/qgscomposermapgrid.h b/src/core/composer/qgscomposermapgrid.h index a58b06f93de..3d08cf25350 100644 --- a/src/core/composer/qgscomposermapgrid.h +++ b/src/core/composer/qgscomposermapgrid.h @@ -199,7 +199,8 @@ class CORE_EXPORT QgsComposerMapGrid : public QgsComposerMapItem enum AnnotationDirection { Horizontal = 0, /*< draw annotations horizontally */ - Vertical, /*< draw annotations vertically */ + Vertical, /*< draw annotations vertically, ascending */ + VerticalDescending, /*< draw annotations vertically, descending */ BoundaryDirection /*< annotations follow the boundary direction */ }; diff --git a/tests/src/core/testqgscomposermapgrid.cpp b/tests/src/core/testqgscomposermapgrid.cpp index 3301a0f0cca..51059be13ef 100644 --- a/tests/src/core/testqgscomposermapgrid.cpp +++ b/tests/src/core/testqgscomposermapgrid.cpp @@ -52,6 +52,7 @@ class TestQgsComposerMapGrid: public QObject void lineBorder(); //test line border frame mode void lineBorderAnnotated(); //test line border frame with annotations void annotationFormats(); //various tests for annotation formats + void descendingAnnotations(); //test descending annotation direction private: QgsComposition* mComposition; @@ -608,7 +609,39 @@ void TestQgsComposerMapGrid::annotationFormats() } +void TestQgsComposerMapGrid::descendingAnnotations() +{ + mComposerMap->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3345223.125 ) ); + mComposerMap->grid()->setFrameStyle( QgsComposerMapGrid::NoFrame ); + mComposerMap->grid()->setEnabled( true ); + mComposerMap->grid()->setStyle( QgsComposerMapGrid::FrameAnnotationsOnly ); + mComposerMap->grid()->setAnnotationEnabled( true ); + mComposerMap->grid()->setAnnotationFontColor( Qt::black ); + mComposerMap->grid()->setAnnotationPosition( QgsComposerMapGrid::InsideMapFrame, QgsComposerMapGrid::Left ); + mComposerMap->grid()->setAnnotationPosition( QgsComposerMapGrid::InsideMapFrame, QgsComposerMapGrid::Right ); + mComposerMap->grid()->setAnnotationPosition( QgsComposerMapGrid::InsideMapFrame, QgsComposerMapGrid::Top ); + mComposerMap->grid()->setAnnotationPosition( QgsComposerMapGrid::InsideMapFrame, QgsComposerMapGrid::Bottom ); + mComposerMap->grid()->setAnnotationDirection( QgsComposerMapGrid::VerticalDescending, QgsComposerMapGrid::Left ); + mComposerMap->grid()->setAnnotationDirection( QgsComposerMapGrid::VerticalDescending, QgsComposerMapGrid::Right ); + mComposerMap->grid()->setAnnotationDirection( QgsComposerMapGrid::VerticalDescending, QgsComposerMapGrid::Top ); + mComposerMap->grid()->setAnnotationDirection( QgsComposerMapGrid::VerticalDescending, QgsComposerMapGrid::Bottom ); + + QgsCompositionChecker checker( "composermap_verticaldescending_inside", mComposition ); + bool testResult = checker.testComposition( mReport, 0, 0 ); + QVERIFY( testResult ); + + mComposerMap->grid()->setAnnotationPosition( QgsComposerMapGrid::OutsideMapFrame, QgsComposerMapGrid::Left ); + mComposerMap->grid()->setAnnotationPosition( QgsComposerMapGrid::OutsideMapFrame, QgsComposerMapGrid::Right ); + mComposerMap->grid()->setAnnotationPosition( QgsComposerMapGrid::OutsideMapFrame, QgsComposerMapGrid::Top ); + mComposerMap->grid()->setAnnotationPosition( QgsComposerMapGrid::OutsideMapFrame, QgsComposerMapGrid::Bottom ); + + QgsCompositionChecker checker2( "composermap_verticaldescending_outside", mComposition ); + bool testResult2 = checker2.testComposition( mReport, 0, 0 ); + QVERIFY( testResult2 ); + + mComposerMap->grid()->setAnnotationEnabled( false ); +} QTEST_MAIN( TestQgsComposerMapGrid ) #include "testqgscomposermapgrid.moc" diff --git a/tests/testdata/control_images/expected_composermap_verticaldescending_inside/expected_composermap_verticaldescending_inside.png b/tests/testdata/control_images/expected_composermap_verticaldescending_inside/expected_composermap_verticaldescending_inside.png new file mode 100644 index 00000000000..e12febb994d Binary files /dev/null and b/tests/testdata/control_images/expected_composermap_verticaldescending_inside/expected_composermap_verticaldescending_inside.png differ diff --git a/tests/testdata/control_images/expected_composermap_verticaldescending_outside/expected_composermap_verticaldescending_outside.png b/tests/testdata/control_images/expected_composermap_verticaldescending_outside/expected_composermap_verticaldescending_outside.png new file mode 100644 index 00000000000..907bb253816 Binary files /dev/null and b/tests/testdata/control_images/expected_composermap_verticaldescending_outside/expected_composermap_verticaldescending_outside.png differ