Skip to content
Permalink
Browse files

[FEATURE][composer] New frame/annotations only grid style. Selecting

this style causes only the frame and annotations to be drawn, with no
grid lines or other markings over the map. (Sponsored by NIWA, New
Zealand)
  • Loading branch information
nyalldawson committed Sep 3, 2014
1 parent dc5f94d commit dc27e13ed3fa9dc03231ab16aa36b6b4208f68a4
@@ -63,6 +63,7 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap ): QgsCo
mGridTypeComboBox->insertItem( 0, tr( "Solid" ) );
mGridTypeComboBox->insertItem( 1, tr( "Cross" ) );
mGridTypeComboBox->insertItem( 2, tr( "Markers" ) );
mGridTypeComboBox->insertItem( 3, tr( "Frame and annotations only" ) );

mAnnotationFormatComboBox->insertItem( 0, tr( "Decimal" ) );
mAnnotationFormatComboBox->insertItem( 1, tr( "DegreeMinute" ) );
@@ -1159,6 +1160,8 @@ void QgsComposerMapWidget::setGridItems( const QgsComposerMapGrid* grid )
mLineStyleLabel->setVisible( true );
mGridMarkerStyleButton->setVisible( false );
mMarkerStyleLabel->setVisible( false );
mGridBlendComboBox->setVisible( true );
mGridBlendLabel->setVisible( true );
break;
case QgsComposerMap::Markers:
mGridTypeComboBox->setCurrentIndex( mGridTypeComboBox->findText( tr( "Markers" ) ) );
@@ -1168,6 +1171,8 @@ void QgsComposerMapWidget::setGridItems( const QgsComposerMapGrid* grid )
mLineStyleLabel->setVisible( false );
mGridMarkerStyleButton->setVisible( true );
mMarkerStyleLabel->setVisible( true );
mGridBlendComboBox->setVisible( true );
mGridBlendLabel->setVisible( true );
break;
case QgsComposerMap::Solid:
mGridTypeComboBox->setCurrentIndex( mGridTypeComboBox->findText( tr( "Solid" ) ) );
@@ -1177,6 +1182,19 @@ void QgsComposerMapWidget::setGridItems( const QgsComposerMapGrid* grid )
mLineStyleLabel->setVisible( true );
mGridMarkerStyleButton->setVisible( false );
mMarkerStyleLabel->setVisible( false );
mGridBlendComboBox->setVisible( true );
mGridBlendLabel->setVisible( true );
break;
case QgsComposerMap::FrameAnnotationsOnly:
mGridTypeComboBox->setCurrentIndex( mGridTypeComboBox->findText( tr( "Frame and annotations only" ) ) );
mCrossWidthSpinBox->setVisible( false );
mCrossWidthLabel->setVisible( false );
mGridLineStyleButton->setVisible( false );
mLineStyleLabel->setVisible( false );
mGridMarkerStyleButton->setVisible( false );
mMarkerStyleLabel->setVisible( false );
mGridBlendComboBox->setVisible( false );
mGridBlendLabel->setVisible( false );
break;
}

@@ -1540,6 +1558,8 @@ void QgsComposerMapWidget::on_mGridTypeComboBox_currentIndexChanged( const QStri
mLineStyleLabel->setVisible( true );
mGridMarkerStyleButton->setVisible( false );
mMarkerStyleLabel->setVisible( false );
mGridBlendComboBox->setVisible( true );
mGridBlendLabel->setVisible( true );
}
else if ( text == tr( "Markers" ) )
{
@@ -1550,8 +1570,10 @@ void QgsComposerMapWidget::on_mGridTypeComboBox_currentIndexChanged( const QStri
mLineStyleLabel->setVisible( false );
mGridMarkerStyleButton->setVisible( true );
mMarkerStyleLabel->setVisible( true );
mGridBlendComboBox->setVisible( true );
mGridBlendLabel->setVisible( true );
}
else
else if ( text == tr( "Solid" ) )
{
grid->setGridStyle( QgsComposerMap::Solid );
mCrossWidthSpinBox->setVisible( false );
@@ -1560,7 +1582,22 @@ void QgsComposerMapWidget::on_mGridTypeComboBox_currentIndexChanged( const QStri
mLineStyleLabel->setVisible( true );
mGridMarkerStyleButton->setVisible( false );
mMarkerStyleLabel->setVisible( false );
mGridBlendComboBox->setVisible( true );
mGridBlendLabel->setVisible( true );
}
else
{
grid->setGridStyle( QgsComposerMap::FrameAnnotationsOnly );
mCrossWidthSpinBox->setVisible( false );
mCrossWidthLabel->setVisible( false );
mGridLineStyleButton->setVisible( false );
mLineStyleLabel->setVisible( false );
mGridMarkerStyleButton->setVisible( false );
mMarkerStyleLabel->setVisible( false );
mGridBlendComboBox->setVisible( false );
mGridBlendLabel->setVisible( false );
}

mComposerMap->update();
mComposerMap->endCommand();
}
@@ -67,7 +67,8 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
{
Solid = 0, //solid lines
Cross, //only draw line crossings
Markers
Markers,
FrameAnnotationsOnly
};

enum GridAnnotationPosition
@@ -321,18 +321,24 @@ void QgsComposerMapGrid::drawGridCRSTransform( QgsRenderContext &context, double
QList< QPair< double, QPolygonF > > xGridLines;
xGridLinesCRSTransform( crsBoundingRect, inverseTr, xGridLines );
QList< QPair< double, QPolygonF > >::const_iterator xGridIt = xGridLines.constBegin();
for ( ; xGridIt != xGridLines.constEnd(); ++xGridIt )
if ( mGridStyle != QgsComposerMap::FrameAnnotationsOnly )
{
drawGridLine( scalePolygon( xGridIt->second, dotsPerMM ), context );
for ( ; xGridIt != xGridLines.constEnd(); ++xGridIt )
{
drawGridLine( scalePolygon( xGridIt->second, dotsPerMM ), context );
}
}

//y grid lines
QList< QPair< double, QPolygonF > > yGridLines;
yGridLinesCRSTransform( crsBoundingRect, inverseTr, yGridLines );
QList< QPair< double, QPolygonF > >::const_iterator yGridIt = yGridLines.constBegin();
for ( ; yGridIt != yGridLines.constEnd(); ++yGridIt )
if ( mGridStyle != QgsComposerMap::FrameAnnotationsOnly )
{
drawGridLine( scalePolygon( yGridIt->second, dotsPerMM ), context );
for ( ; yGridIt != yGridLines.constEnd(); ++yGridIt )
{
drawGridLine( scalePolygon( yGridIt->second, dotsPerMM ), context );
}
}

//convert QPolygonF to QLineF to draw grid frames and annotations
@@ -436,7 +442,7 @@ void QgsComposerMapGrid::drawGridNoTransform( QgsRenderContext &context, double
drawGridLine( line, context );
}
}
else //cross or markers
else if ( mGridStyle != QgsComposerMap::FrameAnnotationsOnly ) //cross or markers
{
QPointF intersectionPoint, crossEnd1, crossEnd2;
for ( ; vIt != verticalLines.constEnd(); ++vIt )
@@ -38,6 +38,7 @@ class TestQgsComposerMapGrid: public QObject
void grid(); //test if grid and grid annotation works
void crossGrid(); //test if grid "cross" mode works
void markerGrid(); //test if grid "marker" mode works
void frameOnly(); //test if grid "frame/annotation" mode works
void zebraStyle(); //test zebra map border style

private:
@@ -165,6 +166,27 @@ void TestQgsComposerMapGrid::markerGrid()
QVERIFY( testResult );
}

void TestQgsComposerMapGrid::frameOnly()
{
mComposerMap->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3345223.125 ) );
mComposerMap->setGridEnabled( true );
mComposerMap->setGridStyle( QgsComposerMap::FrameAnnotationsOnly );
mComposerMap->setGridIntervalX( 2000 );
mComposerMap->setGridIntervalY( 2000 );
mComposerMap->setShowGridAnnotation( false );
//set a frame for testing
mComposerMap->setGridFrameStyle( QgsComposerMap::Zebra );
mComposerMap->setGridBlendMode( QPainter::CompositionMode_SourceOver );
QgsCompositionChecker checker( "composermap_gridframeonly", mComposition );

bool testResult = checker.testComposition( mReport, 0, 100 );
mComposerMap->setGridStyle( QgsComposerMap::Solid );
mComposerMap->setGridEnabled( false );
mComposerMap->setShowGridAnnotation( false );
mComposerMap->setGridFrameStyle( QgsComposerMap::NoGridFrame );
QVERIFY( testResult );
}

void TestQgsComposerMapGrid::zebraStyle()
{
mComposerMap->setNewExtent( QgsRectangle( 785462.375, 3341423.125, 789262.375, 3343323.125 ) ); //zoom in
Binary file not shown.

0 comments on commit dc27e13

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