Skip to content

Commit

Permalink
[composer] Correct placement of cross grids (fix #10626)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 18, 2014
1 parent b5b864e commit 7af7b88
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/core/composer/qgscomposermap.cpp
Expand Up @@ -1480,7 +1480,7 @@ void QgsComposerMap::drawGrid( QPainter* p )
{
//start mark
crossEnd1 = QgsSymbolLayerV2Utils::pointOnLineWithDistance( vIt->second.p1(), vIt->second.p2(), mCrossLength );
drawGridLine( QLineF( vIt->second.p1(), crossEnd1 ), context );
drawGridLine( QLineF( vIt->second.p1() * dotsPerMM, crossEnd1 * dotsPerMM ), context );

//test for intersection with every horizontal line
hIt = horizontalLines.constBegin();
Expand All @@ -1490,20 +1490,20 @@ void QgsComposerMap::drawGrid( QPainter* p )
{
crossEnd1 = QgsSymbolLayerV2Utils::pointOnLineWithDistance( intersectionPoint, vIt->second.p1(), mCrossLength );
crossEnd2 = QgsSymbolLayerV2Utils::pointOnLineWithDistance( intersectionPoint, vIt->second.p2(), mCrossLength );
drawGridLine( QLineF( crossEnd1, crossEnd2 ), context );
drawGridLine( QLineF( crossEnd1 * dotsPerMM, crossEnd2 * dotsPerMM ), context );
}
}
//end mark
QPointF crossEnd2 = QgsSymbolLayerV2Utils::pointOnLineWithDistance( vIt->second.p2(), vIt->second.p1(), mCrossLength );
drawGridLine( QLineF( vIt->second.p2(), crossEnd2 ), context );
drawGridLine( QLineF( vIt->second.p2() * dotsPerMM, crossEnd2 * dotsPerMM ), context );
}

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

vIt = verticalLines.constBegin();
for ( ; vIt != verticalLines.constEnd(); ++vIt )
Expand All @@ -1512,12 +1512,12 @@ void QgsComposerMap::drawGrid( QPainter* p )
{
crossEnd1 = QgsSymbolLayerV2Utils::pointOnLineWithDistance( intersectionPoint, hIt->second.p1(), mCrossLength );
crossEnd2 = QgsSymbolLayerV2Utils::pointOnLineWithDistance( intersectionPoint, hIt->second.p2(), mCrossLength );
drawGridLine( QLineF( crossEnd1, crossEnd2 ), context );
drawGridLine( QLineF( crossEnd1 * dotsPerMM, crossEnd2 * dotsPerMM ), context );
}
}
//end mark
crossEnd1 = QgsSymbolLayerV2Utils::pointOnLineWithDistance( hIt->second.p2(), hIt->second.p1(), mCrossLength );
drawGridLine( QLineF( hIt->second.p2(), crossEnd1 ), context );
drawGridLine( QLineF( hIt->second.p2() * dotsPerMM, crossEnd1 * dotsPerMM ), context );
}
}
// reset composition mode
Expand Down
21 changes: 21 additions & 0 deletions tests/src/core/testqgscomposermap.cpp
Expand Up @@ -37,6 +37,7 @@ class TestQgsComposerMap: public QObject
void cleanup();// will be called after every testfunction.
void render(); //test if rendering of the composition with composr map is correct
void grid(); //test if grid and grid annotation works
void crossGrid(); //test if grid "cross" mode works
void overviewMap(); //test if overview map frame works
void overviewMapBlending(); //test if blend modes with overview map frame works
void overviewMapInvert(); //test if invert of overview map frame works
Expand Down Expand Up @@ -139,6 +140,26 @@ void TestQgsComposerMap::grid()
QVERIFY( testResult );
}

void TestQgsComposerMap::crossGrid()
{
mComposerMap->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3345223.125 ) );
mComposerMap->setGridEnabled( true );
mComposerMap->setGridStyle( QgsComposerMap::Cross );
mComposerMap->setCrossLength( 2.0 );
mComposerMap->setGridIntervalX( 2000 );
mComposerMap->setGridIntervalY( 2000 );
mComposerMap->setShowGridAnnotation( false );
mComposerMap->setGridPenWidth( 0.5 );
mComposerMap->setGridPenColor( QColor( 0, 255, 0 ) );
mComposerMap->setGridBlendMode( QPainter::CompositionMode_SourceOver );
QgsCompositionChecker checker( "composermap_crossgrid", mComposition );

bool testResult = checker.testComposition( mReport, 0, 100 );
mComposerMap->setGridEnabled( false );
mComposerMap->setShowGridAnnotation( false );
QVERIFY( testResult );
}

void TestQgsComposerMap::overviewMap()
{
QgsComposerMap* overviewMap = new QgsComposerMap( mComposition, 20, 130, 70, 70 );
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 7af7b88

Please sign in to comment.