Skip to content

Commit dc27e13

Browse files
committed
[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)
1 parent dc5f94d commit dc27e13

File tree

5 files changed

+73
-7
lines changed

5 files changed

+73
-7
lines changed

src/app/composer/qgscomposermapwidget.cpp

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap ): QgsCo
6363
mGridTypeComboBox->insertItem( 0, tr( "Solid" ) );
6464
mGridTypeComboBox->insertItem( 1, tr( "Cross" ) );
6565
mGridTypeComboBox->insertItem( 2, tr( "Markers" ) );
66+
mGridTypeComboBox->insertItem( 3, tr( "Frame and annotations only" ) );
6667

6768
mAnnotationFormatComboBox->insertItem( 0, tr( "Decimal" ) );
6869
mAnnotationFormatComboBox->insertItem( 1, tr( "DegreeMinute" ) );
@@ -1159,6 +1160,8 @@ void QgsComposerMapWidget::setGridItems( const QgsComposerMapGrid* grid )
11591160
mLineStyleLabel->setVisible( true );
11601161
mGridMarkerStyleButton->setVisible( false );
11611162
mMarkerStyleLabel->setVisible( false );
1163+
mGridBlendComboBox->setVisible( true );
1164+
mGridBlendLabel->setVisible( true );
11621165
break;
11631166
case QgsComposerMap::Markers:
11641167
mGridTypeComboBox->setCurrentIndex( mGridTypeComboBox->findText( tr( "Markers" ) ) );
@@ -1168,6 +1171,8 @@ void QgsComposerMapWidget::setGridItems( const QgsComposerMapGrid* grid )
11681171
mLineStyleLabel->setVisible( false );
11691172
mGridMarkerStyleButton->setVisible( true );
11701173
mMarkerStyleLabel->setVisible( true );
1174+
mGridBlendComboBox->setVisible( true );
1175+
mGridBlendLabel->setVisible( true );
11711176
break;
11721177
case QgsComposerMap::Solid:
11731178
mGridTypeComboBox->setCurrentIndex( mGridTypeComboBox->findText( tr( "Solid" ) ) );
@@ -1177,6 +1182,19 @@ void QgsComposerMapWidget::setGridItems( const QgsComposerMapGrid* grid )
11771182
mLineStyleLabel->setVisible( true );
11781183
mGridMarkerStyleButton->setVisible( false );
11791184
mMarkerStyleLabel->setVisible( false );
1185+
mGridBlendComboBox->setVisible( true );
1186+
mGridBlendLabel->setVisible( true );
1187+
break;
1188+
case QgsComposerMap::FrameAnnotationsOnly:
1189+
mGridTypeComboBox->setCurrentIndex( mGridTypeComboBox->findText( tr( "Frame and annotations only" ) ) );
1190+
mCrossWidthSpinBox->setVisible( false );
1191+
mCrossWidthLabel->setVisible( false );
1192+
mGridLineStyleButton->setVisible( false );
1193+
mLineStyleLabel->setVisible( false );
1194+
mGridMarkerStyleButton->setVisible( false );
1195+
mMarkerStyleLabel->setVisible( false );
1196+
mGridBlendComboBox->setVisible( false );
1197+
mGridBlendLabel->setVisible( false );
11801198
break;
11811199
}
11821200

@@ -1540,6 +1558,8 @@ void QgsComposerMapWidget::on_mGridTypeComboBox_currentIndexChanged( const QStri
15401558
mLineStyleLabel->setVisible( true );
15411559
mGridMarkerStyleButton->setVisible( false );
15421560
mMarkerStyleLabel->setVisible( false );
1561+
mGridBlendComboBox->setVisible( true );
1562+
mGridBlendLabel->setVisible( true );
15431563
}
15441564
else if ( text == tr( "Markers" ) )
15451565
{
@@ -1550,8 +1570,10 @@ void QgsComposerMapWidget::on_mGridTypeComboBox_currentIndexChanged( const QStri
15501570
mLineStyleLabel->setVisible( false );
15511571
mGridMarkerStyleButton->setVisible( true );
15521572
mMarkerStyleLabel->setVisible( true );
1573+
mGridBlendComboBox->setVisible( true );
1574+
mGridBlendLabel->setVisible( true );
15531575
}
1554-
else
1576+
else if ( text == tr( "Solid" ) )
15551577
{
15561578
grid->setGridStyle( QgsComposerMap::Solid );
15571579
mCrossWidthSpinBox->setVisible( false );
@@ -1560,7 +1582,22 @@ void QgsComposerMapWidget::on_mGridTypeComboBox_currentIndexChanged( const QStri
15601582
mLineStyleLabel->setVisible( true );
15611583
mGridMarkerStyleButton->setVisible( false );
15621584
mMarkerStyleLabel->setVisible( false );
1585+
mGridBlendComboBox->setVisible( true );
1586+
mGridBlendLabel->setVisible( true );
1587+
}
1588+
else
1589+
{
1590+
grid->setGridStyle( QgsComposerMap::FrameAnnotationsOnly );
1591+
mCrossWidthSpinBox->setVisible( false );
1592+
mCrossWidthLabel->setVisible( false );
1593+
mGridLineStyleButton->setVisible( false );
1594+
mLineStyleLabel->setVisible( false );
1595+
mGridMarkerStyleButton->setVisible( false );
1596+
mMarkerStyleLabel->setVisible( false );
1597+
mGridBlendComboBox->setVisible( false );
1598+
mGridBlendLabel->setVisible( false );
15631599
}
1600+
15641601
mComposerMap->update();
15651602
mComposerMap->endCommand();
15661603
}

src/core/composer/qgscomposermap.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
6767
{
6868
Solid = 0, //solid lines
6969
Cross, //only draw line crossings
70-
Markers
70+
Markers,
71+
FrameAnnotationsOnly
7172
};
7273

7374
enum GridAnnotationPosition

src/core/composer/qgscomposermapgrid.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,18 +321,24 @@ void QgsComposerMapGrid::drawGridCRSTransform( QgsRenderContext &context, double
321321
QList< QPair< double, QPolygonF > > xGridLines;
322322
xGridLinesCRSTransform( crsBoundingRect, inverseTr, xGridLines );
323323
QList< QPair< double, QPolygonF > >::const_iterator xGridIt = xGridLines.constBegin();
324-
for ( ; xGridIt != xGridLines.constEnd(); ++xGridIt )
324+
if ( mGridStyle != QgsComposerMap::FrameAnnotationsOnly )
325325
{
326-
drawGridLine( scalePolygon( xGridIt->second, dotsPerMM ), context );
326+
for ( ; xGridIt != xGridLines.constEnd(); ++xGridIt )
327+
{
328+
drawGridLine( scalePolygon( xGridIt->second, dotsPerMM ), context );
329+
}
327330
}
328331

329332
//y grid lines
330333
QList< QPair< double, QPolygonF > > yGridLines;
331334
yGridLinesCRSTransform( crsBoundingRect, inverseTr, yGridLines );
332335
QList< QPair< double, QPolygonF > >::const_iterator yGridIt = yGridLines.constBegin();
333-
for ( ; yGridIt != yGridLines.constEnd(); ++yGridIt )
336+
if ( mGridStyle != QgsComposerMap::FrameAnnotationsOnly )
334337
{
335-
drawGridLine( scalePolygon( yGridIt->second, dotsPerMM ), context );
338+
for ( ; yGridIt != yGridLines.constEnd(); ++yGridIt )
339+
{
340+
drawGridLine( scalePolygon( yGridIt->second, dotsPerMM ), context );
341+
}
336342
}
337343

338344
//convert QPolygonF to QLineF to draw grid frames and annotations
@@ -436,7 +442,7 @@ void QgsComposerMapGrid::drawGridNoTransform( QgsRenderContext &context, double
436442
drawGridLine( line, context );
437443
}
438444
}
439-
else //cross or markers
445+
else if ( mGridStyle != QgsComposerMap::FrameAnnotationsOnly ) //cross or markers
440446
{
441447
QPointF intersectionPoint, crossEnd1, crossEnd2;
442448
for ( ; vIt != verticalLines.constEnd(); ++vIt )

tests/src/core/testqgscomposermapgrid.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class TestQgsComposerMapGrid: public QObject
3838
void grid(); //test if grid and grid annotation works
3939
void crossGrid(); //test if grid "cross" mode works
4040
void markerGrid(); //test if grid "marker" mode works
41+
void frameOnly(); //test if grid "frame/annotation" mode works
4142
void zebraStyle(); //test zebra map border style
4243

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

169+
void TestQgsComposerMapGrid::frameOnly()
170+
{
171+
mComposerMap->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3345223.125 ) );
172+
mComposerMap->setGridEnabled( true );
173+
mComposerMap->setGridStyle( QgsComposerMap::FrameAnnotationsOnly );
174+
mComposerMap->setGridIntervalX( 2000 );
175+
mComposerMap->setGridIntervalY( 2000 );
176+
mComposerMap->setShowGridAnnotation( false );
177+
//set a frame for testing
178+
mComposerMap->setGridFrameStyle( QgsComposerMap::Zebra );
179+
mComposerMap->setGridBlendMode( QPainter::CompositionMode_SourceOver );
180+
QgsCompositionChecker checker( "composermap_gridframeonly", mComposition );
181+
182+
bool testResult = checker.testComposition( mReport, 0, 100 );
183+
mComposerMap->setGridStyle( QgsComposerMap::Solid );
184+
mComposerMap->setGridEnabled( false );
185+
mComposerMap->setShowGridAnnotation( false );
186+
mComposerMap->setGridFrameStyle( QgsComposerMap::NoGridFrame );
187+
QVERIFY( testResult );
188+
}
189+
168190
void TestQgsComposerMapGrid::zebraStyle()
169191
{
170192
mComposerMap->setNewExtent( QgsRectangle( 785462.375, 3341423.125, 789262.375, 3343323.125 ) ); //zoom in
111 KB
Loading

0 commit comments

Comments
 (0)