35 #define MAX_GRID_LINES 1000 //maximum number of horizontal or vertical grid lines to draw
113 for (
int i = 0; i < mapGridNodeList.
size(); ++i )
117 mapGrid->
readXML( mapGridElem, doc );
134 maxGridExtension = qMax( maxGridExtension, grid->
maxExtension() );
153 QgsComposerMapGrid::QgsComposerMapGrid()
159 void QgsComposerMapGrid::init()
161 mTransformDirty =
true;
163 mGridIntervalX = 0.0;
164 mGridIntervalY = 0.0;
167 mGridAnnotationFontColor = Qt::black;
168 mGridAnnotationPrecision = 3;
169 mShowGridAnnotation =
false;
178 mAnnotationFrameDistance = 1.0;
187 mGridFrameWidth = 2.0;
188 mGridFramePenThickness = 0.3;
189 mGridFramePenColor =
QColor( 0, 0, 0 );
190 mGridFrameFillColor1 = Qt::white;
191 mGridFrameFillColor2 = Qt::black;
198 mGridMarkerSymbol = 0;
200 mBlendMode = QPainter::CompositionMode_SourceOver;
205 if ( !defaultFontString.
isEmpty() )
207 mGridAnnotationFont.
setFamily( defaultFontString );
210 createDefaultGridLineSymbol();
211 createDefaultGridMarkerSymbol();
216 delete mGridLineSymbol;
217 delete mGridMarkerSymbol;
220 void QgsComposerMapGrid::createDefaultGridLineSymbol()
222 delete mGridLineSymbol;
224 properties.
insert(
"color",
"0,0,0,255" );
225 properties.
insert(
"width",
"0.3" );
226 properties.
insert(
"capstyle",
"flat" );
230 void QgsComposerMapGrid::createDefaultGridMarkerSymbol()
232 delete mGridMarkerSymbol;
234 properties.
insert(
"name",
"circle" );
235 properties.
insert(
"size",
"2.0" );
236 properties.
insert(
"color",
"0,0,0,255" );
242 if ( mGridLineSymbol )
250 if ( mGridLineSymbol )
278 markerStyleElem.
appendChild( gridMarkerStyleElem );
281 mapGridElem.
setAttribute(
"gridFrameStyle", mGridFrameStyle );
282 mapGridElem.
setAttribute(
"gridFrameSideFlags", mGridFrameSides );
288 mapGridElem.
setAttribute(
"leftFrameDivisions", mLeftFrameDivisions );
289 mapGridElem.
setAttribute(
"rightFrameDivisions", mRightFrameDivisions );
290 mapGridElem.
setAttribute(
"topFrameDivisions", mTopFrameDivisions );
291 mapGridElem.
setAttribute(
"bottomFrameDivisions", mBottomFrameDivisions );
297 mapGridElem.
setAttribute(
"annotationFormat", mGridAnnotationFormat );
298 mapGridElem.
setAttribute(
"showAnnotation", mShowGridAnnotation );
299 mapGridElem.
setAttribute(
"leftAnnotationDisplay", mLeftGridAnnotationDisplay );
300 mapGridElem.
setAttribute(
"rightAnnotationDisplay", mRightGridAnnotationDisplay );
301 mapGridElem.
setAttribute(
"topAnnotationDisplay", mTopGridAnnotationDisplay );
302 mapGridElem.
setAttribute(
"bottomAnnotationDisplay", mBottomGridAnnotationDisplay );
303 mapGridElem.
setAttribute(
"leftAnnotationPosition", mLeftGridAnnotationPosition );
304 mapGridElem.
setAttribute(
"rightAnnotationPosition", mRightGridAnnotationPosition );
305 mapGridElem.
setAttribute(
"topAnnotationPosition", mTopGridAnnotationPosition );
306 mapGridElem.
setAttribute(
"bottomAnnotationPosition", mBottomGridAnnotationPosition );
307 mapGridElem.
setAttribute(
"leftAnnotationDirection", mLeftGridAnnotationDirection );
308 mapGridElem.
setAttribute(
"rightAnnotationDirection", mRightGridAnnotationDirection );
309 mapGridElem.
setAttribute(
"topAnnotationDirection", mTopGridAnnotationDirection );
310 mapGridElem.
setAttribute(
"bottomAnnotationDirection", mBottomGridAnnotationDirection );
314 mapGridElem.
setAttribute(
"annotationPrecision", mGridAnnotationPrecision );
341 mGridFrameSides = ( QgsComposerMapGrid::FrameSideFlags )itemElem.
attribute(
"gridFrameSideFlags",
"15" ).
toInt();
343 mGridFramePenThickness = itemElem.
attribute(
"gridFramePenThickness",
"0.3" ).
toDouble();
353 if ( !lineStyleElem.isNull() )
356 if ( !symbolElem.
isNull() )
358 delete mGridLineSymbol;
359 mGridLineSymbol = QgsSymbolLayerV2Utils::loadSymbol<QgsLineSymbolV2>( symbolElem );
373 if ( !markerStyleElem.
isNull() )
376 if ( !symbolElem.
isNull() )
378 delete mGridMarkerSymbol;
379 mGridMarkerSymbol = QgsSymbolLayerV2Utils::loadSymbol<QgsMarkerSymbolV2>( symbolElem );
387 mCRS.
readXML( const_cast<QDomElement&>( itemElem ) );
393 mBlendMode = ( QPainter::CompositionMode )( itemElem.
attribute(
"blendMode",
"0" ).
toUInt() );
396 mShowGridAnnotation = ( itemElem.
attribute(
"showAnnotation",
"0" ) !=
"0" );
432 mAnnotationFrameDistance = itemElem.
attribute(
"frameAnnotationDistance",
"0" ).
toDouble();
438 mGridAnnotationPrecision = itemElem.
attribute(
"annotationPrecision",
"3" ).
toInt();
447 mTransformDirty =
true;
452 return mBlendMode == QPainter::CompositionMode_SourceOver;
455 QPolygonF QgsComposerMapGrid::scalePolygon(
const QPolygonF &polygon,
const double scale )
const
458 return t.
map( polygon );
471 if ( mapPolygon != mPrevMapPolygon )
473 mTransformDirty =
true;
474 mPrevMapPolygon = mapPolygon;
477 if ( mTransformDirty )
479 calculateCRSTransformLines();
486 for ( ; xGridIt != mTransformedXLines.
constEnd(); ++xGridIt )
488 drawGridLine( scalePolygon( xGridIt->second, dotsPerMM ), context );
492 for ( ; yGridIt != mTransformedYLines.
constEnd(); ++yGridIt )
494 drawGridLine( scalePolygon( yGridIt->second, dotsPerMM ), context );
503 for ( ; intersectionIt != mTransformedIntersections.
constEnd(); ++intersectionIt )
505 double x = intersectionIt->x();
506 double y = intersectionIt->y();
510 QLineF line1 =
QLineF( x - mCrossLength, y, x + mCrossLength, y );
511 line1.
p1().
rx() = line1.
p1().
x() < 0 ? 0 : line1.
p1().
x();
512 line1.
p2().
rx() = line1.
p2().
x() > maxX ? maxX : line1.
p2().
x();
513 QLineF line2 =
QLineF( x, y - mCrossLength, x, y + mCrossLength );
514 line2.
p1().
ry() = line2.
p1().
y() < 0 ? 0 : line2.
p1().
y();
515 line2.
p2().
ry() = line2.
p2().
y() > maxY ? maxY : line2.
p2().
y();
518 drawGridLine(
QLineF( line1.
p1() * dotsPerMM, line1.
p2() * dotsPerMM ), context );
519 drawGridLine(
QLineF( line2.
p1() * dotsPerMM, line2.
p2() * dotsPerMM ), context );
523 drawGridMarker(
QPointF( x, y ) * dotsPerMM, context );
530 for ( ; yGridLineIt != mTransformedYLines.
constEnd(); ++yGridLineIt )
532 verticalLines.push_back( qMakePair( yGridLineIt->
first,
QLineF( yGridLineIt->second.
first(), yGridLineIt->second.
last() ) ) );
535 for ( ; xGridLineIt != mTransformedXLines.
constEnd(); ++xGridLineIt )
537 horizontalLines.push_back( qMakePair( xGridLineIt->
first,
QLineF( xGridLineIt->second.
first(), xGridLineIt->second.
last() ) ) );
541 void QgsComposerMapGrid::calculateCRSTransformLines()
545 if ( crsGridParams( crsBoundingRect, inverseTr ) != 0 )
551 mTransformedXLines.
clear();
552 xGridLinesCRSTransform( crsBoundingRect, inverseTr, mTransformedXLines );
555 mTransformedYLines.
clear();
556 yGridLinesCRSTransform( crsBoundingRect, inverseTr, mTransformedYLines );
565 for ( ; yGridIt != mTransformedYLines.
constEnd(); ++yGridIt )
568 for (
int i = 0; i < ( *yGridIt ).second.size(); ++i )
570 yLine.
append(
QgsPoint(( *yGridIt ).second.at( i ).x(), ( *yGridIt ).second.at( i ).y() ) );
576 for ( ; xGridIt != mTransformedXLines.
constEnd(); ++xGridIt )
579 for (
int i = 0; i < ( *xGridIt ).second.size(); ++i )
581 xLine.
append(
QgsPoint(( *xGridIt ).second.at( i ).x(), ( *xGridIt ).second.at( i ).y() ) );
587 mTransformedIntersections.
clear();
589 for ( ; yLineIt != yLines.
constEnd(); ++yLineIt )
592 for ( ; xLineIt != xLines.
constEnd(); ++xLineIt )
602 while ( vertex !=
QgsPoint( 0, 0 ) )
604 mTransformedIntersections << vertex;
612 qDeleteAll( yLines );
614 qDeleteAll( xLines );
618 mTransformDirty =
false;
628 if ( !thePaintDevice )
639 if ( thisPaintRect != mPrevPaintRect )
642 mTransformDirty =
true;
643 mPrevPaintRect = thisPaintRect;
647 double dotsPerMM = thePaintDevice->
logicalDpiX() / 25.4;
648 p->
scale( 1 / dotsPerMM, 1 / dotsPerMM );
666 drawGridCRSTransform( context, dotsPerMM, horizontalLines, verticalLines );
670 drawGridNoTransform( context, dotsPerMM, horizontalLines, verticalLines );
684 drawGridFrame( p, horizontalLines, verticalLines );
687 if ( mShowGridAnnotation )
689 drawCoordinateAnnotations( p, horizontalLines, verticalLines );
697 yGridLines( verticalLines );
699 xGridLines( horizontalLines );
708 for ( ; vIt != verticalLines.
constEnd(); ++vIt )
710 line =
QLineF( vIt->second.p1() * dotsPerMM, vIt->second.p2() * dotsPerMM );
711 drawGridLine( line, context );
714 for ( ; hIt != horizontalLines.
constEnd(); ++hIt )
716 line =
QLineF( hIt->second.p1() * dotsPerMM, hIt->second.p2() * dotsPerMM );
717 drawGridLine( line, context );
722 QPointF intersectionPoint, crossEnd1, crossEnd2;
723 for ( ; vIt != verticalLines.
constEnd(); ++vIt )
727 for ( ; hIt != horizontalLines.
constEnd(); ++hIt )
729 if ( hIt->second.intersect( vIt->second, &intersectionPoint ) == QLineF::BoundedIntersection )
734 crossEnd1 = (( intersectionPoint - vIt->second.p1() ).manhattanLength() > 0.01 ) ?
736 crossEnd2 = (( intersectionPoint - vIt->second.p2() ).manhattanLength() > 0.01 ) ?
739 drawGridLine(
QLineF( crossEnd1 * dotsPerMM, crossEnd2 * dotsPerMM ), context );
743 drawGridMarker( intersectionPoint * dotsPerMM, context );
756 for ( ; hIt != horizontalLines.
constEnd(); ++hIt )
759 for ( ; vIt != verticalLines.
constEnd(); ++vIt )
761 if ( vIt->second.intersect( hIt->second, &intersectionPoint ) == QLineF::BoundedIntersection )
764 crossEnd1 = (( intersectionPoint - hIt->second.p1() ).manhattanLength() > 0.01 ) ?
766 crossEnd2 = (( intersectionPoint - hIt->second.p2() ).manhattanLength() > 0.01 ) ?
769 drawGridLine(
QLineF( crossEnd1 * dotsPerMM, crossEnd2 * dotsPerMM ), context );
787 sortGridLinesOnBorders( hLines, vLines, leftGridFrame, rightGridFrame, topGridFrame, bottomGridFrame );
811 poly << line.
p1() << line.
p2();
812 drawGridLine( poly, context );
835 mGridMarkerSymbol->
renderPoint( point, 0, context );
846 switch ( mGridFrameStyle )
849 drawGridFrameZebraBorder( p, borderPos, border );
854 drawGridFrameTicks( p, borderPos, border );
858 drawGridFrameLineBorder( p, border );
876 double currentCoord = 0;
879 currentCoord = - mGridFrameWidth;
884 currentCoord = - mGridFrameWidth;
911 QPen framePen =
QPen( mGridFramePenColor );
912 framePen.
setWidthF( mGridFramePenThickness );
917 for ( ; posIt != pos.
constEnd(); ++posIt )
919 p->
setBrush(
QBrush( color1 ? mGridFrameFillColor1 : mGridFrameFillColor2 ) );
922 height = posIt.
key() - currentCoord;
923 width = mGridFrameWidth;
929 height = mGridFrameWidth;
930 width = posIt.
key() - currentCoord;
935 currentCoord = posIt.
key();
953 QPen framePen =
QPen( mGridFramePenColor );
954 framePen.
setWidthF( mGridFramePenThickness );
960 for ( ; posIt != borderPos.
constEnd(); ++posIt )
968 width = mGridFrameWidth;
973 width = mGridFrameWidth;
978 width = mGridFrameWidth * 2;
988 height = mGridFrameWidth;
993 height = mGridFrameWidth;
998 height = mGridFrameWidth * 2;
1014 QPen framePen =
QPen( mGridFramePenColor );
1015 framePen.
setWidthF( mGridFramePenThickness );
1044 QString currentAnnotationString;
1046 for ( ; it != hLines.
constEnd(); ++it )
1054 for ( ; it != vLines.
constEnd(); ++it )
1062 void QgsComposerMapGrid::drawCoordinateAnnotation(
QPainter* p,
const QPointF& pos,
QString annotationString,
const AnnotationCoordinate coordinateType )
const
1072 double xpos = pos.
x();
1073 double ypos = pos.
y();
1076 double gridFrameDistance = 0;
1079 gridFrameDistance = mGridFrameWidth;
1083 gridFrameDistance += ( mGridFramePenThickness / 2.0 );
1096 gridFrameDistance = 0;
1103 gridFrameDistance = 0;
1107 xpos += textHeight + mAnnotationFrameDistance + gridFrameDistance;
1108 ypos += textWidth / 2.0;
1113 xpos += ( mAnnotationFrameDistance + gridFrameDistance );
1114 ypos -= textWidth / 2.0;
1119 xpos += mAnnotationFrameDistance + gridFrameDistance;
1120 ypos += textHeight / 2.0;
1127 gridFrameDistance = 0;
1131 xpos -= ( mAnnotationFrameDistance + gridFrameDistance );
1132 ypos += textWidth / 2.0;
1137 xpos -= textHeight + mAnnotationFrameDistance + gridFrameDistance;
1138 ypos -= textWidth / 2.0;
1143 xpos -= ( textWidth + mAnnotationFrameDistance + gridFrameDistance );
1144 ypos += textHeight / 2.0;
1163 gridFrameDistance = 0;
1170 gridFrameDistance = 0;
1174 xpos -= mAnnotationFrameDistance + gridFrameDistance;
1175 ypos += textWidth / 2.0;
1180 xpos -= textHeight + mAnnotationFrameDistance + gridFrameDistance;
1181 ypos -= textWidth / 2.0;
1186 xpos -= textWidth + mAnnotationFrameDistance + gridFrameDistance;
1187 ypos += textHeight / 2.0;
1194 gridFrameDistance = 0;
1198 xpos += ( textHeight + mAnnotationFrameDistance + gridFrameDistance );
1199 ypos += textWidth / 2.0;
1204 xpos += ( mAnnotationFrameDistance + gridFrameDistance );
1205 ypos -= textWidth / 2.0;
1210 xpos += ( mAnnotationFrameDistance + gridFrameDistance );
1211 ypos += textHeight / 2.0;
1229 gridFrameDistance = 0;
1236 gridFrameDistance = 0;
1240 ypos -= mAnnotationFrameDistance + gridFrameDistance;
1241 xpos -= textWidth / 2.0;
1245 xpos -= textHeight / 2.0;
1246 ypos -= textWidth + mAnnotationFrameDistance + gridFrameDistance;
1251 xpos += textHeight / 2.0;
1252 ypos -= mAnnotationFrameDistance + gridFrameDistance;
1260 gridFrameDistance = 0;
1264 ypos += ( mAnnotationFrameDistance + textHeight + gridFrameDistance );
1265 xpos -= textWidth / 2.0;
1269 xpos -= textHeight / 2.0;
1270 ypos += gridFrameDistance + mAnnotationFrameDistance;
1275 xpos += textHeight / 2.0;
1276 ypos += ( textWidth + mAnnotationFrameDistance + gridFrameDistance );
1295 gridFrameDistance = 0;
1302 gridFrameDistance = 0;
1306 xpos -= textWidth / 2.0;
1307 ypos += textHeight + mAnnotationFrameDistance + gridFrameDistance;
1311 xpos -= textHeight / 2.0;
1312 ypos += mAnnotationFrameDistance + gridFrameDistance;
1317 xpos += textHeight / 2.0;
1318 ypos += textWidth + mAnnotationFrameDistance + gridFrameDistance;
1326 gridFrameDistance = 0;
1330 xpos -= textWidth / 2.0;
1331 ypos -= ( mAnnotationFrameDistance + gridFrameDistance );
1335 xpos -= textHeight / 2.0;
1336 ypos -= textWidth + mAnnotationFrameDistance + gridFrameDistance;
1341 xpos += textHeight / 2.0;
1342 ypos -= ( mAnnotationFrameDistance + gridFrameDistance );
1352 drawAnnotation( p,
QPointF( xpos, ypos ), rotation, annotationString );
1355 void QgsComposerMapGrid::drawAnnotation(
QPainter* p,
const QPointF& pos,
int rotation,
const QString& annotationText )
const
1380 bool geographic =
false;
1390 double coordRounded = qRound( value * pow( 10.0, mGridAnnotationPrecision ) ) / pow( 10.0, mGridAnnotationPrecision );
1394 if ( !geographic || ( coordRounded != 180.0 && coordRounded != 0.0 ) )
1402 if ( !geographic || coordRounded != 0.0 )
1410 return QString::number( qAbs( value ),
'f', mGridAnnotationPrecision ) +
QChar( 176 ) + hemisphere;
1414 return QString::number( qAbs( value ),
'f', mGridAnnotationPrecision ) + hemisphere;
1433 annotationString = p.
toDegreesMinutes( mGridAnnotationPrecision,
true,
true );
1451 return split.
at( 0 );
1455 if ( split.
size() < 2 )
1459 return split.
at( 1 );
1474 double gridIntervalY = mGridIntervalY;
1475 double gridOffsetY = mGridOffsetY;
1476 double annotationScale = 1.0;
1481 if ( mGridUnit ==
CM )
1483 annotationScale = 0.1;
1484 gridIntervalY *= 10; gridOffsetY *= 10;
1489 double roundCorrection = mapBoundingRect.
top() > 0 ? 1.0 : 0.0;
1490 double currentLevel = ( int )(( mapBoundingRect.
top() - gridOffsetY ) / gridIntervalY + roundCorrection ) * gridIntervalY + gridOffsetY;
1492 int gridLineCount = 0;
1497 double yCanvasCoord;
1501 lines.push_back( qMakePair( currentLevel * annotationScale,
QLineF( 0, yCanvasCoord,
mComposerMap->
rect().
width(), yCanvasCoord ) ) );
1502 currentLevel += gridIntervalY;
1510 borderLines <<
QLineF( mapPolygon.
at( 0 ), mapPolygon.
at( 1 ) );
1511 borderLines <<
QLineF( mapPolygon.
at( 1 ), mapPolygon.
at( 2 ) );
1512 borderLines <<
QLineF( mapPolygon.
at( 2 ), mapPolygon.
at( 3 ) );
1513 borderLines <<
QLineF( mapPolygon.
at( 3 ), mapPolygon.
at( 0 ) );
1519 intersectionList.
clear();
1520 QLineF gridLine( mapBoundingRect.
left(), currentLevel, mapBoundingRect.
right(), currentLevel );
1523 for ( ; it != borderLines.
constEnd(); ++it )
1526 if ( it->intersect( gridLine, &intersectionPoint ) == QLineF::BoundedIntersection )
1528 intersectionList.push_back( intersectionPoint );
1529 if ( intersectionList.size() >= 2 )
1536 if ( intersectionList.size() >= 2 )
1541 currentLevel += gridIntervalY;
1558 double gridIntervalX = mGridIntervalX;
1559 double gridOffsetX = mGridOffsetX;
1560 double annotationScale = 1.0;
1565 if ( mGridUnit ==
CM )
1567 annotationScale = 0.1;
1568 gridIntervalX *= 10; gridOffsetX *= 10;
1573 double roundCorrection = mapBoundingRect.
left() > 0 ? 1.0 : 0.0;
1574 double currentLevel = ( int )(( mapBoundingRect.
left() - gridOffsetX ) / gridIntervalX + roundCorrection ) * gridIntervalX + gridOffsetX;
1576 int gridLineCount = 0;
1580 double xCanvasCoord;
1584 lines.push_back( qMakePair( currentLevel * annotationScale,
QLineF( xCanvasCoord, 0, xCanvasCoord,
mComposerMap->
rect().
height() ) ) );
1585 currentLevel += gridIntervalX;
1593 borderLines <<
QLineF( mapPolygon.
at( 0 ), mapPolygon.
at( 1 ) );
1594 borderLines <<
QLineF( mapPolygon.
at( 1 ), mapPolygon.
at( 2 ) );
1595 borderLines <<
QLineF( mapPolygon.
at( 2 ), mapPolygon.
at( 3 ) );
1596 borderLines <<
QLineF( mapPolygon.
at( 3 ), mapPolygon.
at( 0 ) );
1602 intersectionList.
clear();
1603 QLineF gridLine( currentLevel, mapBoundingRect.
bottom(), currentLevel, mapBoundingRect.
top() );
1606 for ( ; it != borderLines.
constEnd(); ++it )
1609 if ( it->intersect( gridLine, &intersectionPoint ) == QLineF::BoundedIntersection )
1611 intersectionList.push_back( intersectionPoint );
1612 if ( intersectionList.size() >= 2 )
1619 if ( intersectionList.size() >= 2 )
1624 currentLevel += gridIntervalX;
1638 double roundCorrection = bbox.
yMaximum() > 0 ? 1.0 : 0.0;
1639 double currentLevel = ( int )(( bbox.
yMaximum() - mGridOffsetY ) / mGridIntervalY + roundCorrection ) * mGridIntervalY + mGridOffsetY;
1643 double step = ( maxX - minX ) / 20;
1645 bool crosses180 =
false;
1646 bool crossed180 =
false;
1651 step = ( maxX + 360.0 - minX ) / 20;
1657 int gridLineCount = 0;
1661 double currentX = minX;
1665 if (( !crosses180 || crossed180 ) && ( currentX > maxX ) )
1681 if ( crosses180 && currentX > 180.0 )
1691 for ( ; lineIt != lineSegments.
constEnd(); ++lineIt )
1693 if (( *lineIt ).size() > 0 )
1695 lines.append( qMakePair( currentLevel, *lineIt ) );
1699 currentLevel -= mGridIntervalY;
1713 double roundCorrection = bbox.
xMinimum() > 0 ? 1.0 : 0.0;
1714 double currentLevel = ( int )(( bbox.
xMinimum() - mGridOffsetX ) / mGridIntervalX + roundCorrection ) * mGridIntervalX + mGridOffsetX;
1718 double step = ( maxY - minY ) / 20;
1723 bool crosses180 =
false;
1724 bool crossed180 =
false;
1731 int gridLineCount = 0;
1732 while (( currentLevel <= bbox.
xMaximum() || ( crosses180 && !crossed180 ) ) && gridLineCount <
MAX_GRID_LINES )
1735 double currentY = minY;
1739 if ( currentY > maxY )
1760 for ( ; lineIt != lineSegments.
constEnd(); ++lineIt )
1762 if (( *lineIt ).size() > 0 )
1764 lines.append( qMakePair( currentLevel, *lineIt ) );
1768 currentLevel += mGridIntervalX;
1769 if ( crosses180 && currentLevel > 180.0 )
1771 currentLevel -= 360.0;
1784 for ( ; it != hLines.
constEnd(); ++it )
1786 QgsMapAnnotation p1;
1787 p1.coordinate = it->
first;
1788 p1.itemPosition = it->second.p1();
1790 borderPositions << p1;
1792 QgsMapAnnotation p2;
1793 p2.coordinate = it->
first;
1794 p2.itemPosition = it->second.p2();
1796 borderPositions << p2;
1799 for ( ; it != vLines.
constEnd(); ++it )
1801 QgsMapAnnotation p1;
1802 p1.coordinate = it->
first;
1803 p1.itemPosition = it->second.p1();
1805 borderPositions << p1;
1807 QgsMapAnnotation p2;
1808 p2.coordinate = it->
first;
1809 p2.itemPosition = it->second.p2();
1811 borderPositions << p2;
1815 for ( ; bIt != borderPositions.
constEnd(); ++bIt )
1820 leftFrameEntries.
insert( bIt->itemPosition.y(), bIt->coordinate );
1824 rightFrameEntries.
insert( bIt->itemPosition.y(), bIt->coordinate );
1828 topFrameEntries.
insert( bIt->itemPosition.x(), bIt->coordinate );
1832 bottomFrameEntries.
insert( bIt->itemPosition.x(), bIt->coordinate );
1842 return shouldShowDivisionForDisplayMode( coordinate, mLeftFrameDivisions );
1844 return shouldShowDivisionForDisplayMode( coordinate, mRightFrameDivisions );
1846 return shouldShowDivisionForDisplayMode( coordinate, mTopFrameDivisions );
1849 return shouldShowDivisionForDisplayMode( coordinate, mBottomFrameDivisions );
1862 return a.first < b.first;
1875 if (( p.
y() <= tolerance && p.
x() <= tolerance )
1884 if ( p.
x() <= tolerance )
1895 if ( p.
y() <= tolerance )
1914 return distanceToSide.
at( 0 ).second;
1919 delete mGridLineSymbol;
1920 mGridLineSymbol = symbol;
1925 delete mGridMarkerSymbol;
1926 mGridMarkerSymbol = symbol;
1934 mLeftGridAnnotationDisplay = display;
1937 mRightGridAnnotationDisplay = display;
1940 mTopGridAnnotationDisplay = display;
1943 mBottomGridAnnotationDisplay = display;
1961 return mLeftGridAnnotationDisplay;
1964 return mRightGridAnnotationDisplay;
1967 return mTopGridAnnotationDisplay;
1971 return mBottomGridAnnotationDisplay;
2000 if ( crsGridParams( crsRect, inverseTransform ) != 0 )
2005 int xGridReturn = xGridLinesCRSTransform( crsRect, inverseTransform, xGridLines );
2006 int yGridReturn = yGridLinesCRSTransform( crsRect, inverseTransform, yGridLines );
2007 if ( xGridReturn != 0 || yGridReturn != 0 )
2013 for ( ; it != xGridLines.
constEnd(); ++it )
2018 for ( ; it != yGridLines.
constEnd(); ++it )
2027 int xGridReturn = xGridLines( xLines );
2028 int yGridReturn = yGridLines( yLines );
2029 if ( xGridReturn != 0 && yGridReturn != 0 )
2035 for ( ; it != xLines.
constEnd(); ++it )
2041 for ( ; it != yLines.
constEnd(); ++it )
2048 double currentExtension = 0;
2051 for ( ; coordIt != coordStrings.
constEnd(); ++coordIt )
2054 maxExtension = qMax( maxExtension, currentExtension );
2058 double gridFrameDist = ( mGridFrameStyle ==
QgsComposerMapGrid::NoFrame ) ? 0 : mGridFrameWidth + ( mGridFramePenThickness / 2.0 );
2059 return maxExtension + mAnnotationFrameDistance + gridFrameDist;
2064 if ( unit == mGridUnit )
2069 mTransformDirty =
true;
2074 if ( interval == mGridIntervalX )
2078 mGridIntervalX = interval;
2079 mTransformDirty =
true;
2084 if ( interval == mGridIntervalY )
2088 mGridIntervalY = interval;
2089 mTransformDirty =
true;
2094 if ( offset == mGridOffsetX )
2098 mGridOffsetX = offset;
2099 mTransformDirty =
true;
2104 if ( offset == mGridOffsetY )
2108 mGridOffsetY = offset;
2109 mTransformDirty =
true;
2114 if ( style == mGridStyle )
2119 mTransformDirty =
true;
2127 mLeftGridAnnotationDirection = direction;
2130 mRightGridAnnotationDirection = direction;
2133 mTopGridAnnotationDirection = direction;
2136 mBottomGridAnnotationDirection = direction;
2152 mGridFrameSides = flags;
2158 mGridFrameSides |= flag;
2160 mGridFrameSides &= ~flag;
2165 return mGridFrameSides;
2170 return mGridFrameSides.testFlag( flag );
2175 mLeftGridAnnotationDirection = direction;
2176 mRightGridAnnotationDirection = direction;
2177 mTopGridAnnotationDirection = direction;
2178 mBottomGridAnnotationDirection = direction;
2186 mLeftGridAnnotationPosition = position;
2189 mRightGridAnnotationPosition = position;
2192 mTopGridAnnotationPosition = position;
2195 mBottomGridAnnotationPosition = position;
2213 return mLeftGridAnnotationPosition;
2216 return mRightGridAnnotationPosition;
2219 return mTopGridAnnotationPosition;
2223 return mBottomGridAnnotationPosition;
2232 return mLeftGridAnnotationDirection;
2238 return mLeftGridAnnotationDirection;
2241 return mRightGridAnnotationDirection;
2244 return mTopGridAnnotationDirection;
2248 return mBottomGridAnnotationDirection;
2258 mLeftFrameDivisions = divisions;
2261 mRightFrameDivisions = divisions;
2264 mTopFrameDivisions = divisions;
2267 mBottomFrameDivisions = divisions;
2284 return mLeftFrameDivisions;
2287 return mRightFrameDivisions;
2290 return mTopFrameDivisions;
2294 return mBottomFrameDivisions;
2310 QRectF mbr = mapPolygon.boundingRect();
2317 QgsPoint lowerLeft( mapBoundingRect.xMinimum(), mapBoundingRect.yMinimum() );
2318 QgsPoint upperRight( mapBoundingRect.xMaximum(), mapBoundingRect.yMaximum() );
2320 lowerLeft =
tr.transform( lowerLeft.x(), lowerLeft.y() );
2321 upperRight =
tr.transform( upperRight.x(), upperRight.y() );
2323 if ( lowerLeft.x() > upperRight.x() )
2331 crsRect =
tr.transformBoundingBox( mapBoundingRect );
2336 crsRect =
tr.transformBoundingBox( mapBoundingRect );
2360 for ( ; geomIt != intersectedParts.
constEnd(); ++geomIt )
2362 trimmedLines << ( *geomIt )->asQPolygonF();
2365 qDeleteAll( intersectedParts );
2366 intersectedParts.
clear();
2370 return trimmedLines;
QgsComposerMapGrid(const QString &name, QgsComposerMap *map)
Constructor for QgsComposerMapGrid.
static QgsGeometry * fromQPolygonF(const QPolygonF &polygon)
Construct geometry from a QPolygonF.
void setStyle(const GridStyle style)
Sets the grid style, which controls how the grid is drawn over the map's contents.
void setForceVectorOutput(bool force)
void addGrid(QgsComposerMapGrid *grid)
Adds a new map grid to the stack and takes ownership of the grid.
void draw(QPainter *painter) override
Draws a grid.
QDomNodeList elementsByTagName(const QString &tagname) const
A rectangle specified with double values.
static QgsMarkerSymbolV2 * createSimple(const QgsStringMap &properties)
Create a marker symbol with one symbol layer: SimpleMarker with specified properties.
void setAnnotationDirection(const AnnotationDirection direction, const BorderSide border)
Sets the direction for drawing frame annotations.
void setFrameSideFlags(const FrameSideFlags flags)
Sets flags for grid frame sides.
void setLineSymbol(QgsLineSymbolV2 *symbol)
Sets the line symbol used for drawing grid lines.
GridStyle
Grid drawing style.
QgsComposerMapGrid * grid(const QString &gridId) const
Returns a reference to a grid within the stack.
void setCompositionMode(CompositionMode mode)
void addItem(QgsComposerMapItem *item)
Adds a new map item to the stack and takes ownership of the item.
void setRenderHint(RenderHint hint, bool on)
void setOffsetY(const double offset)
Sets the offset for grid lines in the y-direction.
QDomNode appendChild(const QDomNode &newChild)
void append(const T &value)
QString attribute(const QString &name, const QString &defValue) const
double yMaximum() const
Get the y maximum value (top side of rectangle)
void setOutputDpi(int dpi)
Set DPI used for conversion between real world units (e.g. mm) and pixels.
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
const QgsMapSettings & mapSettings() const
Return setting of QGIS map canvas.
FrameStyle
Style for grid frame.
void scale(qreal sx, qreal sy)
void setClipping(bool enable)
const_iterator constEnd() const
const_iterator constBegin() const
QList< QgsGeometry * > asGeometryCollection() const
Return contents of the geometry as a list of geometries.
const T & at(int i) const
QRectF sceneBoundingRect() const
static void drawText(QPainter *painter, const QPointF &pos, const QString &text, const QFont &font, const QColor &color=QColor())
Draws text on a painter at a specific position, taking care of composer specific issues (calculation ...
virtual ~QgsComposerMapGrid()
A geometry is the spatial representation of a feature.
void setJoinStyle(Qt::PenJoinStyle style)
static QColor decodeColor(QString str)
static double fontAscentMM(const QFont &font)
Calculate font ascent in millimeters, including workarounds for QT font rendering issues...
QPolygonF transformedMapPolygon() const
Returns extent that considers rotation and shift with mOffsetX / mOffsetY.
void drawLine(const QLineF &line)
AnnotationDirection
Direction of grid annotations.
void removeGrid(const QString &gridId)
Removes a grid from the stack and deletes the corresponding QgsComposerMapGrid.
double toDouble(bool *ok) const
void setGridLineColor(const QColor &color)
Sets color of grid lines.
QString tr(const char *sourceText, const char *disambiguation, int n)
QMap< QString, QString > QgsStringMap
void setAnnotationDisplay(const DisplayMode display, const BorderSide border)
Sets what types of grid annotations should be drawn for a specified side of the map frame...
AnnotationFormat
Format for displaying grid annotations.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
void update(const QRectF &rect)
An item which is drawn inside a QgsComposerMap, eg a grid or map overview.
AnnotationPosition annotationPosition(const BorderSide border) const
Gets the position for the grid annotations on a specified side of the map frame.
void setWidth(double width)
void setFrameSideFlag(const FrameSideFlag flag, bool on=true)
Sets whether the grid frame is drawn for a certain side of the map item.
static QString encodeColor(QColor color)
The QgsMapSettings class contains configuration for rendering of the map.
const QgsComposerMapItem * constItem(const QString &itemId) const
Returns a const reference to an item within the stack.
QDomElement toElement() const
bool testFrameSideFlag(const FrameSideFlag flag) const
Tests whether the grid frame should be drawn on a specified side of the map item. ...
static QDomElement saveSymbol(QString symbolName, QgsSymbolV2 *symbol, QDomDocument &doc)
void setCapStyle(Qt::PenCapStyle style)
void drawRect(const QRectF &rectangle)
void setColor(const QColor &color)
QString number(int n, int base)
void append(const T &value)
virtual ~QgsComposerMapGridStack()
void updateBoundingRect()
Updates the bounding rect of this item.
bool fromString(const QString &descrip)
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
const QgsComposerMapGrid * constGrid(const QString &gridId) const
Returns a const reference to a grid within the stack.
bool mEnabled
True if item is to be displayed on map.
double xMaximum() const
Get the x maximum value (right side of rectangle)
DisplayMode frameDivisions(const BorderSide border) const
Gets the type of grid divisions which are used for frames on a specified side of the map...
static double fontHeightCharacterMM(const QFont &font, const QChar &character)
Calculate font height in millimeters of a single character, including workarounds for QT font renderi...
bool writeXML(QDomElement &elem, QDomDocument &doc) const override
Stores grid state in DOM element.
void startRender(QgsRenderContext &context, const QgsFields *fields=0)
static QgsLineSymbolV2 * createSimple(const QgsStringMap &properties)
Create a line symbol with one symbol layer: SimpleLine with specified properties. ...
void setPen(const QColor &color)
void setAttribute(const QString &name, const QString &value)
QRectF mapRectFromScene(const QRectF &rect) const
const QgsComposition * composition() const
Returns the composition the item is attached to.
void removeItem(const QString &itemId)
Removes an item from the stack and deletes the corresponding QgsComposerMapItem.
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
int toInt(bool *ok, int base) const
DisplayMode
Display settings for grid annotations and frames.
bool readXML(const QDomElement &elem, const QDomDocument &doc) override
Sets the grid stack's state from a DOM document.
FrameSideFlags frameSideFlags() const
Returns the flags which control which sides of the map item the grid frame is drawn on...
void moveItemUp(const QString &itemId)
Moves an item up the stack, causing it to be rendered above other items.
void renderPolyline(const QPolygonF &points, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
AnnotationPosition
Position for grid annotations.
const_iterator constEnd() const
void setUnits(const GridUnit unit)
Sets the units to use for grid measurements such as the interval and offset for grid lines...
QPaintDevice * device() const
void setWidthF(qreal width)
void setBrush(const QBrush &brush)
void setPainter(QPainter *p)
GridStyle style() const
Gets the grid's style, which controls how the grid is drawn over the map's contents.
static bool setFromXmlChildNode(QFont &font, const QDomElement &element, const QString &childNode)
Sets the properties of a font to match the properties stored in an XML child node.
FrameSideFlag
Flags for controlling which side of the map a frame is drawn on.
An individual grid which is drawn above the map content in a QgsComposerMap.
QgsComposerMapGrid & operator[](int idx)
Returns a reference to a grid within the stack.
QgsComposerMap * mComposerMap
Associated composer map.
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets the CRS for the grid.
bool usesAdvancedEffects() const override
Returns true if the item is drawn using advanced effects, such as blend modes.
void renderPoint(const QPointF &point, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
void setGridLineWidth(const double width)
Sets width of grid lines.
double mapRotation(QgsComposerObject::PropertyValueType valueType=QgsComposerObject::EvaluatedValue) const
Returns the rotation used for drawing the map within the composer item.
A class to represent a point.
bool readXML(const QDomElement &itemElem, const QDomDocument &doc) override
Sets grid state from a DOM document.
QgsComposerMapGridStack(QgsComposerMap *map)
Constructor for QgsComposerMapGridStack.
QgsComposerMapItem * item(const QString &itemId) const
Returns a reference to an item within the stack.
Object representing map window.
void moveItemDown(const QString &itemId)
Moves an item up the stack, causing it to be rendered above other items.
QgsRectangle * currentMapExtent()
Returns a pointer to the current map extent, which is either the original user specified extent or th...
QList< QgsComposerMapGrid * > asList() const
Returns a list of QgsComposerMapGrids contained by the stack.
virtual QString name() const
Get friendly display name for the item.
BorderSide
Border sides for annotations.
QString qgsDoubleToString(const double &a, const int &precision=17)
void setAnnotationPosition(const AnnotationPosition position, const BorderSide border)
Sets the position for the grid annotations on a specified side of the map frame.
DisplayMode annotationDisplay(const BorderSide border) const
Gets the display mode for the grid annotations on a specified side of the map frame.
QList< QgsComposerMapItem * > mItems
static double textWidthMM(const QFont &font, const QString &text)
Calculate font width in millimeters for a string, including workarounds for QT font rendering issues...
QgsGeometry * intersection(const QgsGeometry *geometry) const
Returns a geometry representing the points shared by this geometry and other.
const T & at(int i) const
QVariant value(const QString &key, const QVariant &defaultValue) const
const_iterator constBegin() const
bool writeXML(QDomNode &theNode, QDomDocument &theDoc) const
Contains information about the context of a rendering operation.
double maxExtension() const
Calculates the maximum distance the grid extends beyond the QgsComposerMap's item rect...
QRectF boundingRect() const
void stopRender(QgsRenderContext &context)
void setClipRect(const QRectF &rectangle, Qt::ClipOperation operation)
void setOutputSize(const QSize &size)
Set the size of the resulting map image.
QString toDegreesMinutes(int thePrecision, const bool useSuffix=true, const bool padded=false) const
Return a string representation as degrees minutes.
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings
A collection of map items which are drawn above the map content in a QgsComposerMap.
bool hasFrame() const
Whether this item has a frame or not.
QDomElement firstChildElement(const QString &tagName) const
void setFamily(const QString &family)
Class for storing a coordinate reference system (CRS)
void setExtent(const QgsRectangle &rect)
Set coordinates of the rectangle which should be rendered.
void setMarkerSymbol(QgsMarkerSymbolV2 *symbol)
Sets the marker symbol used for drawing grid points.
void setIntervalY(const double interval)
Sets the interval between grid lines in the y-direction.
static QgsGeometry * fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
void translate(const QPointF &offset)
void setFrameDivisions(const DisplayMode divisions, const BorderSide border)
Sets what type of grid divisions should be used for frames on a specified side of the map...
static QgsGeometry * fromPolyline(const QgsPolyline &polyline)
Creates a new geometry from a QgsPolyline object.
void moveGridUp(const QString &gridId)
Moves a grid up the stack, causing it to be rendered above other grids.
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc) override
Sets map item state from a DOM document.
iterator insert(const Key &key, const T &value)
QString toDegreesMinutesSeconds(int thePrecision, const bool useSuffix=true, const bool padded=false) const
Return a string representation as degrees minutes seconds.
bool readXML(QDomNode &theNode)
Custom exception class for Coordinate Reference System related exceptions.
static QDomElement toXmlElement(const QFont &font, QDomDocument &document, const QString &elementName)
Returns a DOM element containing the properties of the font.
const_iterator constEnd() const
double maxGridExtension() const
Calculates the maximum distance grids within the stack extend beyond the QgsComposerMap's item rect...
QDomElement createElement(const QString &tagName)
const_iterator constBegin() const
void moveGridDown(const QString &gridId)
Moves a grid down the stack, causing it to be rendered below other grids.
void removeItems()
Clears the item stack and deletes all QgsComposerMapItems contained by the stack. ...
QPointF mapToItemCoords(const QPointF &mapCoords) const
Transforms map coordinates to item coordinates (considering rotation and move offset) ...
virtual bool writeXML(QDomElement &elem, QDomDocument &doc) const override
Stores map item state in DOM element.
AnnotationDirection annotationDirection(const BorderSide border) const
Gets the direction for drawing frame annotations.
static QPointF pointOnLineWithDistance(const QPointF &startPoint, const QPointF &directionPoint, double distance)
Returns a point on the line from startPoint to directionPoint that is a certain distance away from th...
bool geographicFlag() const
double xMinimum() const
Get the x minimum value (left side of rectangle)
QgsCoordinateReferenceSystem crs() const
Retrieves the CRS for the grid.
GridUnit
Unit for grid values.
void setIntervalX(const double interval)
Sets the interval between grid lines in the x-direction.
QgsPoint vertexAt(int atVertex) const
Returns coordinates of a vertex.
void setOffsetX(const double offset)
Sets the offset for grid lines in the x-direction.
AnnotationCoordinate
Annotation coordinate type.
bool sortByDistance(const QPair< qreal, QgsComposerMapGrid::BorderSide > &a, const QPair< qreal, QgsComposerMapGrid::BorderSide > &b)
QDomNode at(int index) const
QgsComposerMap * mComposerMap
uint toUInt(bool *ok, int base) const