Skip to content

Commit

Permalink
[FEATURE][composer] New frame/annotations only grid style. Selecting
Browse files Browse the repository at this point in the history
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 dc27e13
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 7 deletions.
39 changes: 38 additions & 1 deletion src/app/composer/qgscomposermapwidget.cpp
Expand Up @@ -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" ) );
Expand Down Expand Up @@ -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" ) ) );
Expand All @@ -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" ) ) );
Expand All @@ -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;
}

Expand Down Expand Up @@ -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" ) )
{
Expand All @@ -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 );
Expand All @@ -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();
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/composer/qgscomposermap.h
Expand Up @@ -67,7 +67,8 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
{
Solid = 0, //solid lines
Cross, //only draw line crossings
Markers
Markers,
FrameAnnotationsOnly
};

enum GridAnnotationPosition
Expand Down
16 changes: 11 additions & 5 deletions src/core/composer/qgscomposermapgrid.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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 )
Expand Down
22 changes: 22 additions & 0 deletions tests/src/core/testqgscomposermapgrid.cpp
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit dc27e13

Please sign in to comment.