Skip to content

Commit 7af7b88

Browse files
committed
[composer] Correct placement of cross grids (fix #10626)
1 parent b5b864e commit 7af7b88

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

src/core/composer/qgscomposermap.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,7 +1480,7 @@ void QgsComposerMap::drawGrid( QPainter* p )
14801480
{
14811481
//start mark
14821482
crossEnd1 = QgsSymbolLayerV2Utils::pointOnLineWithDistance( vIt->second.p1(), vIt->second.p2(), mCrossLength );
1483-
drawGridLine( QLineF( vIt->second.p1(), crossEnd1 ), context );
1483+
drawGridLine( QLineF( vIt->second.p1() * dotsPerMM, crossEnd1 * dotsPerMM ), context );
14841484

14851485
//test for intersection with every horizontal line
14861486
hIt = horizontalLines.constBegin();
@@ -1490,20 +1490,20 @@ void QgsComposerMap::drawGrid( QPainter* p )
14901490
{
14911491
crossEnd1 = QgsSymbolLayerV2Utils::pointOnLineWithDistance( intersectionPoint, vIt->second.p1(), mCrossLength );
14921492
crossEnd2 = QgsSymbolLayerV2Utils::pointOnLineWithDistance( intersectionPoint, vIt->second.p2(), mCrossLength );
1493-
drawGridLine( QLineF( crossEnd1, crossEnd2 ), context );
1493+
drawGridLine( QLineF( crossEnd1 * dotsPerMM, crossEnd2 * dotsPerMM ), context );
14941494
}
14951495
}
14961496
//end mark
14971497
QPointF crossEnd2 = QgsSymbolLayerV2Utils::pointOnLineWithDistance( vIt->second.p2(), vIt->second.p1(), mCrossLength );
1498-
drawGridLine( QLineF( vIt->second.p2(), crossEnd2 ), context );
1498+
drawGridLine( QLineF( vIt->second.p2() * dotsPerMM, crossEnd2 * dotsPerMM ), context );
14991499
}
15001500

15011501
hIt = horizontalLines.constBegin();
15021502
for ( ; hIt != horizontalLines.constEnd(); ++hIt )
15031503
{
15041504
//start mark
15051505
crossEnd1 = QgsSymbolLayerV2Utils::pointOnLineWithDistance( hIt->second.p1(), hIt->second.p2(), mCrossLength );
1506-
drawGridLine( QLineF( hIt->second.p1(), crossEnd1 ), context );
1506+
drawGridLine( QLineF( hIt->second.p1() * dotsPerMM, crossEnd1 * dotsPerMM ), context );
15071507

15081508
vIt = verticalLines.constBegin();
15091509
for ( ; vIt != verticalLines.constEnd(); ++vIt )
@@ -1512,12 +1512,12 @@ void QgsComposerMap::drawGrid( QPainter* p )
15121512
{
15131513
crossEnd1 = QgsSymbolLayerV2Utils::pointOnLineWithDistance( intersectionPoint, hIt->second.p1(), mCrossLength );
15141514
crossEnd2 = QgsSymbolLayerV2Utils::pointOnLineWithDistance( intersectionPoint, hIt->second.p2(), mCrossLength );
1515-
drawGridLine( QLineF( crossEnd1, crossEnd2 ), context );
1515+
drawGridLine( QLineF( crossEnd1 * dotsPerMM, crossEnd2 * dotsPerMM ), context );
15161516
}
15171517
}
15181518
//end mark
15191519
crossEnd1 = QgsSymbolLayerV2Utils::pointOnLineWithDistance( hIt->second.p2(), hIt->second.p1(), mCrossLength );
1520-
drawGridLine( QLineF( hIt->second.p2(), crossEnd1 ), context );
1520+
drawGridLine( QLineF( hIt->second.p2() * dotsPerMM, crossEnd1 * dotsPerMM ), context );
15211521
}
15221522
}
15231523
// reset composition mode

tests/src/core/testqgscomposermap.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class TestQgsComposerMap: public QObject
3737
void cleanup();// will be called after every testfunction.
3838
void render(); //test if rendering of the composition with composr map is correct
3939
void grid(); //test if grid and grid annotation works
40+
void crossGrid(); //test if grid "cross" mode works
4041
void overviewMap(); //test if overview map frame works
4142
void overviewMapBlending(); //test if blend modes with overview map frame works
4243
void overviewMapInvert(); //test if invert of overview map frame works
@@ -139,6 +140,26 @@ void TestQgsComposerMap::grid()
139140
QVERIFY( testResult );
140141
}
141142

143+
void TestQgsComposerMap::crossGrid()
144+
{
145+
mComposerMap->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3345223.125 ) );
146+
mComposerMap->setGridEnabled( true );
147+
mComposerMap->setGridStyle( QgsComposerMap::Cross );
148+
mComposerMap->setCrossLength( 2.0 );
149+
mComposerMap->setGridIntervalX( 2000 );
150+
mComposerMap->setGridIntervalY( 2000 );
151+
mComposerMap->setShowGridAnnotation( false );
152+
mComposerMap->setGridPenWidth( 0.5 );
153+
mComposerMap->setGridPenColor( QColor( 0, 255, 0 ) );
154+
mComposerMap->setGridBlendMode( QPainter::CompositionMode_SourceOver );
155+
QgsCompositionChecker checker( "composermap_crossgrid", mComposition );
156+
157+
bool testResult = checker.testComposition( mReport, 0, 100 );
158+
mComposerMap->setGridEnabled( false );
159+
mComposerMap->setShowGridAnnotation( false );
160+
QVERIFY( testResult );
161+
}
162+
142163
void TestQgsComposerMap::overviewMap()
143164
{
144165
QgsComposerMap* overviewMap = new QgsComposerMap( mComposition, 20, 130, 70, 70 );

0 commit comments

Comments
 (0)