Skip to content
Permalink
Browse files

[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.
  • Loading branch information
nyalldawson committed Nov 5, 2014
1 parent b242324 commit 8b29097f36d22c9993a57e33a912f1a2705ee354
@@ -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 */
};

@@ -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 )
@@ -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 );
@@ -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;
@@ -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 */
};

@@ -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"
Binary file not shown.
Binary file not shown.

0 comments on commit 8b29097

Please sign in to comment.
You can’t perform that action at this time.