34 #define MAX_GRID_LINES 1000 //maximum number of horizontal or vertical grid lines to draw 86 QList< QgsComposerMapGrid* > list;
87 QList< QgsComposerMapItem* >::const_iterator it =
mItems.begin();
88 for ( ; it !=
mItems.end(); ++it )
111 QDomNodeList mapGridNodeList = elem.elementsByTagName(
"ComposerMapGrid" );
112 for (
int i = 0; i < mapGridNodeList.size(); ++i )
114 QDomElement mapGridElem = mapGridNodeList.at( i ).toElement();
116 mapGrid->
readXML( mapGridElem, doc );
127 QList< QgsComposerMapItem* >::const_iterator it =
mItems.constBegin();
128 for ( ; it !=
mItems.constEnd(); ++it )
133 maxGridExtension = qMax( maxGridExtension, grid->
maxExtension() );
158 void QgsComposerMapGrid::init()
160 mTransformDirty =
true;
162 mGridIntervalX = 0.0;
163 mGridIntervalY = 0.0;
166 mGridAnnotationFontColor = Qt::black;
167 mGridAnnotationPrecision = 3;
168 mShowGridAnnotation =
false;
177 mAnnotationFrameDistance = 1.0;
186 mGridFrameWidth = 2.0;
187 mGridFramePenThickness = 0.3;
188 mGridFramePenColor = QColor( 0, 0, 0 );
189 mGridFrameFillColor1 = Qt::white;
190 mGridFrameFillColor2 = Qt::black;
197 mGridMarkerSymbol = 0;
199 mBlendMode = QPainter::CompositionMode_SourceOver;
203 QString defaultFontString = settings.value(
"/Composer/defaultFont" ).toString();
204 if ( !defaultFontString.isEmpty() )
206 mGridAnnotationFont.setFamily( defaultFontString );
209 createDefaultGridLineSymbol();
210 createDefaultGridMarkerSymbol();
215 delete mGridLineSymbol;
216 delete mGridMarkerSymbol;
219 void QgsComposerMapGrid::createDefaultGridLineSymbol()
221 delete mGridLineSymbol;
223 properties.insert(
"color",
"0,0,0,255" );
224 properties.insert(
"width",
"0.3" );
225 properties.insert(
"capstyle",
"flat" );
229 void QgsComposerMapGrid::createDefaultGridMarkerSymbol()
231 delete mGridMarkerSymbol;
233 properties.insert(
"name",
"circle" );
234 properties.insert(
"size",
"2.0" );
235 properties.insert(
"color",
"0,0,0,255" );
241 if ( mGridLineSymbol )
249 if ( mGridLineSymbol )
262 QDomElement mapGridElem = doc.createElement(
"ComposerMapGrid" );
263 mapGridElem.setAttribute(
"gridStyle", mGridStyle );
270 QDomElement lineStyleElem = doc.createElement(
"lineStyle" );
272 lineStyleElem.appendChild( gridLineStyleElem );
273 mapGridElem.appendChild( lineStyleElem );
275 QDomElement markerStyleElem = doc.createElement(
"markerStyle" );
277 markerStyleElem.appendChild( gridMarkerStyleElem );
278 mapGridElem.appendChild( markerStyleElem );
280 mapGridElem.setAttribute(
"gridFrameStyle", mGridFrameStyle );
281 mapGridElem.setAttribute(
"gridFrameSideFlags", mGridFrameSides );
282 mapGridElem.setAttribute(
"gridFrameWidth",
qgsDoubleToString( mGridFrameWidth ) );
283 mapGridElem.setAttribute(
"gridFramePenThickness",
qgsDoubleToString( mGridFramePenThickness ) );
287 mapGridElem.setAttribute(
"leftFrameDivisions", mLeftFrameDivisions );
288 mapGridElem.setAttribute(
"rightFrameDivisions", mRightFrameDivisions );
289 mapGridElem.setAttribute(
"topFrameDivisions", mTopFrameDivisions );
290 mapGridElem.setAttribute(
"bottomFrameDivisions", mBottomFrameDivisions );
296 mapGridElem.setAttribute(
"annotationFormat", mGridAnnotationFormat );
297 mapGridElem.setAttribute(
"showAnnotation", mShowGridAnnotation );
298 mapGridElem.setAttribute(
"leftAnnotationDisplay", mLeftGridAnnotationDisplay );
299 mapGridElem.setAttribute(
"rightAnnotationDisplay", mRightGridAnnotationDisplay );
300 mapGridElem.setAttribute(
"topAnnotationDisplay", mTopGridAnnotationDisplay );
301 mapGridElem.setAttribute(
"bottomAnnotationDisplay", mBottomGridAnnotationDisplay );
302 mapGridElem.setAttribute(
"leftAnnotationPosition", mLeftGridAnnotationPosition );
303 mapGridElem.setAttribute(
"rightAnnotationPosition", mRightGridAnnotationPosition );
304 mapGridElem.setAttribute(
"topAnnotationPosition", mTopGridAnnotationPosition );
305 mapGridElem.setAttribute(
"bottomAnnotationPosition", mBottomGridAnnotationPosition );
306 mapGridElem.setAttribute(
"leftAnnotationDirection", mLeftGridAnnotationDirection );
307 mapGridElem.setAttribute(
"rightAnnotationDirection", mRightGridAnnotationDirection );
308 mapGridElem.setAttribute(
"topAnnotationDirection", mTopGridAnnotationDirection );
309 mapGridElem.setAttribute(
"bottomAnnotationDirection", mBottomGridAnnotationDirection );
310 mapGridElem.setAttribute(
"frameAnnotationDistance", QString::number( mAnnotationFrameDistance ) );
311 mapGridElem.setAttribute(
"annotationFont", mGridAnnotationFont.toString() );
313 mapGridElem.setAttribute(
"annotationPrecision", mGridAnnotationPrecision );
314 mapGridElem.setAttribute(
"unit", mGridUnit );
315 mapGridElem.setAttribute(
"blendMode", mBlendMode );
318 elem.appendChild( mapGridElem );
325 if ( itemElem.isNull() )
334 mGridIntervalX = itemElem.attribute(
"intervalX",
"0" ).toDouble();
335 mGridIntervalY = itemElem.attribute(
"intervalY",
"0" ).toDouble();
336 mGridOffsetX = itemElem.attribute(
"offsetX",
"0" ).toDouble();
337 mGridOffsetY = itemElem.attribute(
"offsetY",
"0" ).toDouble();
338 mCrossLength = itemElem.attribute(
"crossLength",
"3" ).toDouble();
340 mGridFrameSides = ( QgsComposerMapGrid::FrameSideFlags )itemElem.attribute(
"gridFrameSideFlags",
"15" ).toInt();
341 mGridFrameWidth = itemElem.attribute(
"gridFrameWidth",
"2.0" ).toDouble();
342 mGridFramePenThickness = itemElem.attribute(
"gridFramePenThickness",
"0.3" ).toDouble();
351 QDomElement lineStyleElem = itemElem.firstChildElement(
"lineStyle" );
352 if ( !lineStyleElem.isNull() )
354 QDomElement symbolElem = lineStyleElem.firstChildElement(
"symbol" );
355 if ( !symbolElem.isNull() )
357 delete mGridLineSymbol;
358 mGridLineSymbol = QgsSymbolLayerV2Utils::loadSymbol<QgsLineSymbolV2>( symbolElem );
365 mGridLineSymbol->
setWidth( itemElem.attribute(
"penWidth",
"0" ).toDouble() );
366 mGridLineSymbol->
setColor( QColor( itemElem.attribute(
"penColorRed",
"0" ).toInt(),
367 itemElem.attribute(
"penColorGreen",
"0" ).toInt(),
368 itemElem.attribute(
"penColorBlue",
"0" ).toInt() ) );
371 QDomElement markerStyleElem = itemElem.firstChildElement(
"markerStyle" );
372 if ( !markerStyleElem.isNull() )
374 QDomElement symbolElem = markerStyleElem.firstChildElement(
"symbol" );
375 if ( !symbolElem.isNull() )
377 delete mGridMarkerSymbol;
378 mGridMarkerSymbol = QgsSymbolLayerV2Utils::loadSymbol<QgsMarkerSymbolV2>( symbolElem );
383 QDomElement crsElem = itemElem.firstChildElement(
"spatialrefsys" );
384 if ( !crsElem.isNull() )
386 mCRS.
readXML( const_cast<QDomElement&>( itemElem ) );
392 mBlendMode = ( QPainter::CompositionMode )( itemElem.attribute(
"blendMode",
"0" ).toUInt() );
395 mShowGridAnnotation = ( itemElem.attribute(
"showAnnotation",
"0" ) !=
"0" );
431 mAnnotationFrameDistance = itemElem.attribute(
"frameAnnotationDistance",
"0" ).toDouble();
432 mGridAnnotationFont.fromString( itemElem.attribute(
"annotationFont",
"" ) );
434 mGridAnnotationPrecision = itemElem.attribute(
"annotationPrecision",
"3" ).toInt();
435 int gridUnitInt = itemElem.attribute(
"unit", QString::number(
MapUnit ) ).toInt();
443 mTransformDirty =
true;
448 return mBlendMode == QPainter::CompositionMode_SourceOver;
451 QPolygonF QgsComposerMapGrid::scalePolygon(
const QPolygonF &polygon,
const double scale )
const 453 QTransform t = QTransform::fromScale( scale, scale );
454 return t.map( polygon );
457 void QgsComposerMapGrid::drawGridCRSTransform(
QgsRenderContext &context,
double dotsPerMM, QList< QPair< double, QLineF > > &horizontalLines,
458 QList< QPair< double, QLineF > > &verticalLines )
467 if ( mapPolygon != mPrevMapPolygon )
469 mTransformDirty =
true;
470 mPrevMapPolygon = mapPolygon;
473 if ( mTransformDirty )
475 calculateCRSTransformLines();
481 QList< QPair< double, QPolygonF > >::const_iterator xGridIt = mTransformedXLines.constBegin();
482 for ( ; xGridIt != mTransformedXLines.constEnd(); ++xGridIt )
484 drawGridLine( scalePolygon( xGridIt->second, dotsPerMM ), context );
487 QList< QPair< double, QPolygonF > >::const_iterator yGridIt = mTransformedYLines.constBegin();
488 for ( ; yGridIt != mTransformedYLines.constEnd(); ++yGridIt )
490 drawGridLine( scalePolygon( yGridIt->second, dotsPerMM ), context );
498 QList< QgsPoint >::const_iterator intersectionIt = mTransformedIntersections.constBegin();
499 for ( ; intersectionIt != mTransformedIntersections.constEnd(); ++intersectionIt )
501 double x = intersectionIt->x();
502 double y = intersectionIt->y();
506 QLineF line1 = QLineF( x - mCrossLength, y, x + mCrossLength, y );
507 line1.p1().rx() = line1.p1().x() < 0 ? 0 : line1.p1().x();
508 line1.p2().rx() = line1.p2().x() > maxX ? maxX : line1.p2().x();
509 QLineF line2 = QLineF( x, y - mCrossLength, x, y + mCrossLength );
510 line2.p1().ry() = line2.p1().y() < 0 ? 0 : line2.p1().y();
511 line2.p2().ry() = line2.p2().y() > maxY ? maxY : line2.p2().y();
514 drawGridLine( QLineF( line1.p1() * dotsPerMM, line1.p2() * dotsPerMM ), context );
515 drawGridLine( QLineF( line2.p1() * dotsPerMM, line2.p2() * dotsPerMM ), context );
519 drawGridMarker( QPointF( x, y ) * dotsPerMM, context );
525 QList< QPair< double, QPolygonF > >::const_iterator yGridLineIt = mTransformedYLines.constBegin();
526 for ( ; yGridLineIt != mTransformedYLines.constEnd(); ++yGridLineIt )
528 verticalLines.push_back( qMakePair( yGridLineIt->first, QLineF( yGridLineIt->second.first(), yGridLineIt->second.last() ) ) );
530 QList< QPair< double, QPolygonF > >::const_iterator xGridLineIt = mTransformedXLines.constBegin();
531 for ( ; xGridLineIt != mTransformedXLines.constEnd(); ++xGridLineIt )
533 horizontalLines.push_back( qMakePair( xGridLineIt->first, QLineF( xGridLineIt->second.first(), xGridLineIt->second.last() ) ) );
537 void QgsComposerMapGrid::calculateCRSTransformLines()
541 if ( crsGridParams( crsBoundingRect, inverseTr ) != 0 )
547 mTransformedXLines.clear();
548 xGridLinesCRSTransform( crsBoundingRect, inverseTr, mTransformedXLines );
551 mTransformedYLines.clear();
552 yGridLinesCRSTransform( crsBoundingRect, inverseTr, mTransformedYLines );
559 QList< QgsGeometry* > yLines;
560 QList< QPair< double, QPolygonF > >::const_iterator yGridIt = mTransformedYLines.constBegin();
561 for ( ; yGridIt != mTransformedYLines.constEnd(); ++yGridIt )
564 for (
int i = 0; i < ( *yGridIt ).second.size(); ++i )
566 yLine.append(
QgsPoint(( *yGridIt ).second.at( i ).x(), ( *yGridIt ).second.at( i ).y() ) );
570 QList< QgsGeometry* > xLines;
571 QList< QPair< double, QPolygonF > >::const_iterator xGridIt = mTransformedXLines.constBegin();
572 for ( ; xGridIt != mTransformedXLines.constEnd(); ++xGridIt )
575 for (
int i = 0; i < ( *xGridIt ).second.size(); ++i )
577 xLine.append(
QgsPoint(( *xGridIt ).second.at( i ).x(), ( *xGridIt ).second.at( i ).y() ) );
583 mTransformedIntersections.clear();
584 QList< QgsGeometry* >::const_iterator yLineIt = yLines.constBegin();
585 for ( ; yLineIt != yLines.constEnd(); ++yLineIt )
587 QList< QgsGeometry* >::const_iterator xLineIt = xLines.constBegin();
588 for ( ; xLineIt != xLines.constEnd(); ++xLineIt )
596 while ( vertex !=
QgsPoint( 0, 0 ) )
598 mTransformedIntersections << vertex;
605 qDeleteAll( yLines );
607 qDeleteAll( xLines );
611 mTransformDirty =
false;
620 QPaintDevice* thePaintDevice = p->device();
621 if ( !thePaintDevice )
627 p->setCompositionMode( mBlendMode );
628 p->setRenderHint( QPainter::Antialiasing );
631 p->setClipRect( thisPaintRect );
632 if ( thisPaintRect != mPrevPaintRect )
635 mTransformDirty =
true;
636 mPrevPaintRect = thisPaintRect;
640 double dotsPerMM = thePaintDevice->logicalDpiX() / 25.4;
641 p->scale( 1 / dotsPerMM, 1 / dotsPerMM );
653 QList< QPair< double, QLineF > > verticalLines;
654 QList< QPair< double, QLineF > > horizontalLines;
659 drawGridCRSTransform( context, dotsPerMM, horizontalLines, verticalLines );
663 drawGridNoTransform( context, dotsPerMM, horizontalLines, verticalLines );
668 p->setClipping(
false );
677 drawGridFrame( p, horizontalLines, verticalLines );
680 if ( mShowGridAnnotation )
682 drawCoordinateAnnotations( p, horizontalLines, verticalLines );
686 void QgsComposerMapGrid::drawGridNoTransform(
QgsRenderContext &context,
double dotsPerMM, QList< QPair< double, QLineF > > &horizontalLines,
687 QList< QPair< double, QLineF > > &verticalLines )
const 690 yGridLines( verticalLines );
691 QList< QPair< double, QLineF > >::const_iterator vIt = verticalLines.constBegin();
692 xGridLines( horizontalLines );
693 QList< QPair< double, QLineF > >::const_iterator hIt = horizontalLines.constBegin();
701 for ( ; vIt != verticalLines.constEnd(); ++vIt )
703 line = QLineF( vIt->second.p1() * dotsPerMM, vIt->second.p2() * dotsPerMM );
704 drawGridLine( line, context );
707 for ( ; hIt != horizontalLines.constEnd(); ++hIt )
709 line = QLineF( hIt->second.p1() * dotsPerMM, hIt->second.p2() * dotsPerMM );
710 drawGridLine( line, context );
715 QPointF intersectionPoint, crossEnd1, crossEnd2;
716 for ( ; vIt != verticalLines.constEnd(); ++vIt )
719 hIt = horizontalLines.constBegin();
720 for ( ; hIt != horizontalLines.constEnd(); ++hIt )
722 if ( hIt->second.intersect( vIt->second, &intersectionPoint ) == QLineF::BoundedIntersection )
727 crossEnd1 = (( intersectionPoint - vIt->second.p1() ).manhattanLength() > 0.01 ) ?
729 crossEnd2 = (( intersectionPoint - vIt->second.p2() ).manhattanLength() > 0.01 ) ?
732 drawGridLine( QLineF( crossEnd1 * dotsPerMM, crossEnd2 * dotsPerMM ), context );
736 drawGridMarker( intersectionPoint * dotsPerMM, context );
748 hIt = horizontalLines.constBegin();
749 for ( ; hIt != horizontalLines.constEnd(); ++hIt )
751 vIt = verticalLines.constBegin();
752 for ( ; vIt != verticalLines.constEnd(); ++vIt )
754 if ( vIt->second.intersect( hIt->second, &intersectionPoint ) == QLineF::BoundedIntersection )
757 crossEnd1 = (( intersectionPoint - hIt->second.p1() ).manhattanLength() > 0.01 ) ?
759 crossEnd2 = (( intersectionPoint - hIt->second.p2() ).manhattanLength() > 0.01 ) ?
762 drawGridLine( QLineF( crossEnd1 * dotsPerMM, crossEnd2 * dotsPerMM ), context );
769 void QgsComposerMapGrid::drawGridFrame( QPainter* p,
const QList< QPair< double, QLineF > >& hLines,
const QList< QPair< double, QLineF > >& vLines )
const 772 p->setRenderHint( QPainter::Antialiasing );
775 QMap< double, double > leftGridFrame;
776 QMap< double, double > rightGridFrame;
777 QMap< double, double > topGridFrame;
778 QMap< double, double > bottomGridFrame;
780 sortGridLinesOnBorders( hLines, vLines, leftGridFrame, rightGridFrame, topGridFrame, bottomGridFrame );
801 void QgsComposerMapGrid::drawGridLine(
const QLineF& line,
QgsRenderContext& context )
const 804 poly << line.p1() << line.p2();
805 drawGridLine( poly, context );
808 void QgsComposerMapGrid::drawGridLine(
const QPolygonF& line,
QgsRenderContext& context )
const 820 void QgsComposerMapGrid::drawGridMarker(
const QPointF& point,
QgsRenderContext& context )
const 828 mGridMarkerSymbol->
renderPoint( point, 0, context );
839 switch ( mGridFrameStyle )
842 drawGridFrameZebraBorder( p, borderPos, border );
847 drawGridFrameTicks( p, borderPos, border );
851 drawGridFrameLineBorder( p, border );
860 void QgsComposerMapGrid::drawGridFrameZebraBorder( QPainter* p,
const QMap< double, double >& borderPos,
QgsComposerMapGrid::BorderSide border )
const 867 QMap< double, double > pos = borderPos;
869 double currentCoord = 0;
872 currentCoord = - mGridFrameWidth;
877 currentCoord = - mGridFrameWidth;
904 QPen framePen = QPen( mGridFramePenColor );
905 framePen.setWidthF( mGridFramePenThickness );
906 framePen.setJoinStyle( Qt::MiterJoin );
907 p->setPen( framePen );
909 QMap< double, double >::const_iterator posIt = pos.constBegin();
910 for ( ; posIt != pos.constEnd(); ++posIt )
912 p->setBrush( QBrush( color1 ? mGridFrameFillColor1 : mGridFrameFillColor2 ) );
915 height = posIt.key() - currentCoord;
916 width = mGridFrameWidth;
922 height = mGridFrameWidth;
923 width = posIt.key() - currentCoord;
927 p->drawRect( QRectF( x, y, width, height ) );
928 currentCoord = posIt.key();
946 QPen framePen = QPen( mGridFramePenColor );
947 framePen.setWidthF( mGridFramePenThickness );
948 framePen.setCapStyle( Qt::FlatCap );
949 p->setBrush( Qt::NoBrush );
950 p->setPen( framePen );
952 QMap< double, double >::const_iterator posIt = borderPos.constBegin();
953 for ( ; posIt != borderPos.constEnd(); ++posIt )
961 width = mGridFrameWidth;
966 width = mGridFrameWidth;
971 width = mGridFrameWidth * 2;
981 height = mGridFrameWidth;
986 height = mGridFrameWidth;
991 height = mGridFrameWidth * 2;
995 p->drawLine( QLineF( x, y, x + width, y + height ) );
1007 QPen framePen = QPen( mGridFramePenColor );
1008 framePen.setWidthF( mGridFramePenThickness );
1009 framePen.setCapStyle( Qt::SquareCap );
1010 p->setBrush( Qt::NoBrush );
1011 p->setPen( framePen );
1016 p->drawLine( QLineF( 0, 0, 0,
mComposerMap->rect().height() ) );
1022 p->drawLine( QLineF( 0, 0,
mComposerMap->rect().width(), 0 ) );
1030 void QgsComposerMapGrid::drawCoordinateAnnotations( QPainter* p,
const QList< QPair< double, QLineF > >& hLines,
const QList< QPair< double, QLineF > >& vLines )
const 1037 QString currentAnnotationString;
1038 QList< QPair< double, QLineF > >::const_iterator it = hLines.constBegin();
1039 for ( ; it != hLines.constEnd(); ++it )
1046 it = vLines.constBegin();
1047 for ( ; it != vLines.constEnd(); ++it )
1055 void QgsComposerMapGrid::drawCoordinateAnnotation( QPainter* p,
const QPointF& pos, QString annotationString,
const AnnotationCoordinate coordinateType )
const 1065 double xpos = pos.x();
1066 double ypos = pos.y();
1069 double gridFrameDistance = 0;
1072 gridFrameDistance = mGridFrameWidth;
1076 gridFrameDistance += ( mGridFramePenThickness / 2.0 );
1089 gridFrameDistance = 0;
1096 gridFrameDistance = 0;
1100 xpos += textHeight + mAnnotationFrameDistance + gridFrameDistance;
1101 ypos += textWidth / 2.0;
1106 xpos += ( mAnnotationFrameDistance + gridFrameDistance );
1107 ypos -= textWidth / 2.0;
1112 xpos += mAnnotationFrameDistance + gridFrameDistance;
1113 ypos += textHeight / 2.0;
1120 gridFrameDistance = 0;
1124 xpos -= ( mAnnotationFrameDistance + gridFrameDistance );
1125 ypos += textWidth / 2.0;
1130 xpos -= textHeight + mAnnotationFrameDistance + gridFrameDistance;
1131 ypos -= textWidth / 2.0;
1136 xpos -= ( textWidth + mAnnotationFrameDistance + gridFrameDistance );
1137 ypos += textHeight / 2.0;
1156 gridFrameDistance = 0;
1163 gridFrameDistance = 0;
1167 xpos -= mAnnotationFrameDistance + gridFrameDistance;
1168 ypos += textWidth / 2.0;
1173 xpos -= textHeight + mAnnotationFrameDistance + gridFrameDistance;
1174 ypos -= textWidth / 2.0;
1179 xpos -= textWidth + mAnnotationFrameDistance + gridFrameDistance;
1180 ypos += textHeight / 2.0;
1187 gridFrameDistance = 0;
1191 xpos += ( textHeight + mAnnotationFrameDistance + gridFrameDistance );
1192 ypos += textWidth / 2.0;
1197 xpos += ( mAnnotationFrameDistance + gridFrameDistance );
1198 ypos -= textWidth / 2.0;
1203 xpos += ( mAnnotationFrameDistance + gridFrameDistance );
1204 ypos += textHeight / 2.0;
1222 gridFrameDistance = 0;
1229 gridFrameDistance = 0;
1233 ypos -= mAnnotationFrameDistance + gridFrameDistance;
1234 xpos -= textWidth / 2.0;
1238 xpos -= textHeight / 2.0;
1239 ypos -= textWidth + mAnnotationFrameDistance + gridFrameDistance;
1244 xpos += textHeight / 2.0;
1245 ypos -= mAnnotationFrameDistance + gridFrameDistance;
1253 gridFrameDistance = 0;
1257 ypos += ( mAnnotationFrameDistance + textHeight + gridFrameDistance );
1258 xpos -= textWidth / 2.0;
1262 xpos -= textHeight / 2.0;
1263 ypos += gridFrameDistance + mAnnotationFrameDistance;
1268 xpos += textHeight / 2.0;
1269 ypos += ( textWidth + mAnnotationFrameDistance + gridFrameDistance );
1288 gridFrameDistance = 0;
1295 gridFrameDistance = 0;
1299 xpos -= textWidth / 2.0;
1300 ypos += textHeight + mAnnotationFrameDistance + gridFrameDistance;
1304 xpos -= textHeight / 2.0;
1305 ypos += mAnnotationFrameDistance + gridFrameDistance;
1310 xpos += textHeight / 2.0;
1311 ypos += textWidth + mAnnotationFrameDistance + gridFrameDistance;
1319 gridFrameDistance = 0;
1323 xpos -= textWidth / 2.0;
1324 ypos -= ( mAnnotationFrameDistance + gridFrameDistance );
1328 xpos -= textHeight / 2.0;
1329 ypos -= textWidth + mAnnotationFrameDistance + gridFrameDistance;
1334 xpos += textHeight / 2.0;
1335 ypos -= ( mAnnotationFrameDistance + gridFrameDistance );
1345 drawAnnotation( p, QPointF( xpos, ypos ), rotation, annotationString );
1348 void QgsComposerMapGrid::drawAnnotation( QPainter* p,
const QPointF& pos,
int rotation,
const QString& annotationText )
const 1356 p->translate( pos );
1357 p->rotate( rotation );
1366 return QString::number( value,
'f', mGridAnnotationPrecision );
1373 bool geographic =
false;
1383 double coordRounded = qRound( value * pow( 10.0, mGridAnnotationPrecision ) ) / pow( 10.0, mGridAnnotationPrecision );
1387 if ( !geographic || ( coordRounded != 180.0 && coordRounded != 0.0 ) )
1395 if ( !geographic || coordRounded != 0.0 )
1403 return QString::number( qAbs( value ),
'f', mGridAnnotationPrecision ) + QChar( 176 ) + hemisphere;
1407 return QString::number( qAbs( value ),
'f', mGridAnnotationPrecision ) + hemisphere;
1415 QString annotationString;
1426 annotationString = p.
toDegreesMinutes( mGridAnnotationPrecision,
true,
true );
1441 QStringList split = annotationString.split(
"," );
1444 return split.at( 0 );
1448 if ( split.size() < 2 )
1452 return split.at( 1 );
1456 int QgsComposerMapGrid::xGridLines( QList< QPair< double, QLineF > >& lines )
const 1466 QRectF mapBoundingRect = mapPolygon.boundingRect();
1467 double gridIntervalY = mGridIntervalY;
1468 double gridOffsetY = mGridOffsetY;
1469 double annotationScale = 1.0;
1474 if ( mGridUnit ==
CM )
1476 annotationScale = 0.1;
1477 gridIntervalY *= 10; gridOffsetY *= 10;
1482 double roundCorrection = mapBoundingRect.top() > 0 ? 1.0 : 0.0;
1483 double currentLevel = ( int )(( mapBoundingRect.top() - gridOffsetY ) / gridIntervalY + roundCorrection ) * gridIntervalY + gridOffsetY;
1485 int gridLineCount = 0;
1490 double yCanvasCoord;
1491 while ( currentLevel <= mapBoundingRect.bottom() && gridLineCount <
MAX_GRID_LINES )
1493 yCanvasCoord =
mComposerMap->rect().height() * ( 1 - ( currentLevel - mapBoundingRect.top() ) / mapBoundingRect.height() );
1494 lines.push_back( qMakePair( currentLevel * annotationScale, QLineF( 0, yCanvasCoord,
mComposerMap->rect().width(), yCanvasCoord ) ) );
1495 currentLevel += gridIntervalY;
1502 QVector<QLineF> borderLines;
1503 borderLines << QLineF( mapPolygon.at( 0 ), mapPolygon.at( 1 ) );
1504 borderLines << QLineF( mapPolygon.at( 1 ), mapPolygon.at( 2 ) );
1505 borderLines << QLineF( mapPolygon.at( 2 ), mapPolygon.at( 3 ) );
1506 borderLines << QLineF( mapPolygon.at( 3 ), mapPolygon.at( 0 ) );
1508 QList<QPointF> intersectionList;
1510 while ( currentLevel <= mapBoundingRect.bottom() && gridLineCount <
MAX_GRID_LINES )
1512 intersectionList.clear();
1513 QLineF gridLine( mapBoundingRect.left(), currentLevel, mapBoundingRect.right(), currentLevel );
1515 QVector<QLineF>::const_iterator it = borderLines.constBegin();
1516 for ( ; it != borderLines.constEnd(); ++it )
1518 QPointF intersectionPoint;
1519 if ( it->intersect( gridLine, &intersectionPoint ) == QLineF::BoundedIntersection )
1521 intersectionList.push_back( intersectionPoint );
1522 if ( intersectionList.size() >= 2 )
1529 if ( intersectionList.size() >= 2 )
1534 currentLevel += gridIntervalY;
1541 int QgsComposerMapGrid::yGridLines( QList< QPair< double, QLineF > >& lines )
const 1550 QRectF mapBoundingRect = mapPolygon.boundingRect();
1551 double gridIntervalX = mGridIntervalX;
1552 double gridOffsetX = mGridOffsetX;
1553 double annotationScale = 1.0;
1558 if ( mGridUnit ==
CM )
1560 annotationScale = 0.1;
1561 gridIntervalX *= 10; gridOffsetX *= 10;
1566 double roundCorrection = mapBoundingRect.left() > 0 ? 1.0 : 0.0;
1567 double currentLevel = ( int )(( mapBoundingRect.left() - gridOffsetX ) / gridIntervalX + roundCorrection ) * gridIntervalX + gridOffsetX;
1569 int gridLineCount = 0;
1573 double xCanvasCoord;
1574 while ( currentLevel <= mapBoundingRect.right() && gridLineCount <
MAX_GRID_LINES )
1576 xCanvasCoord =
mComposerMap->rect().width() * ( currentLevel - mapBoundingRect.left() ) / mapBoundingRect.width();
1577 lines.push_back( qMakePair( currentLevel * annotationScale, QLineF( xCanvasCoord, 0, xCanvasCoord,
mComposerMap->rect().height() ) ) );
1578 currentLevel += gridIntervalX;
1585 QVector<QLineF> borderLines;
1586 borderLines << QLineF( mapPolygon.at( 0 ), mapPolygon.at( 1 ) );
1587 borderLines << QLineF( mapPolygon.at( 1 ), mapPolygon.at( 2 ) );
1588 borderLines << QLineF( mapPolygon.at( 2 ), mapPolygon.at( 3 ) );
1589 borderLines << QLineF( mapPolygon.at( 3 ), mapPolygon.at( 0 ) );
1591 QList<QPointF> intersectionList;
1593 while ( currentLevel <= mapBoundingRect.right() && gridLineCount <
MAX_GRID_LINES )
1595 intersectionList.clear();
1596 QLineF gridLine( currentLevel, mapBoundingRect.bottom(), currentLevel, mapBoundingRect.top() );
1598 QVector<QLineF>::const_iterator it = borderLines.constBegin();
1599 for ( ; it != borderLines.constEnd(); ++it )
1601 QPointF intersectionPoint;
1602 if ( it->intersect( gridLine, &intersectionPoint ) == QLineF::BoundedIntersection )
1604 intersectionList.push_back( intersectionPoint );
1605 if ( intersectionList.size() >= 2 )
1612 if ( intersectionList.size() >= 2 )
1617 currentLevel += gridIntervalX;
1631 double roundCorrection = bbox.
yMaximum() > 0 ? 1.0 : 0.0;
1632 double currentLevel = ( int )(( bbox.
yMaximum() - mGridOffsetY ) / mGridIntervalY + roundCorrection ) * mGridIntervalY + mGridOffsetY;
1636 double step = ( maxX - minX ) / 20;
1638 bool crosses180 =
false;
1639 bool crossed180 =
false;
1644 step = ( maxX + 360.0 - minX ) / 20;
1650 int gridLineCount = 0;
1654 double currentX = minX;
1658 if (( !crosses180 || crossed180 ) && ( currentX > maxX ) )
1670 QgsDebugMsg( QString(
"Caught CRS exception %1" ).arg( cse.
what() ) );
1674 if ( crosses180 && currentX > 180.0 )
1683 QList<QPolygonF>::const_iterator lineIt = lineSegments.constBegin();
1684 for ( ; lineIt != lineSegments.constEnd(); ++lineIt )
1686 if (( *lineIt ).size() > 0 )
1688 lines.append( qMakePair( currentLevel, *lineIt ) );
1692 currentLevel -= mGridIntervalY;
1706 double roundCorrection = bbox.
xMinimum() > 0 ? 1.0 : 0.0;
1707 double currentLevel = ( int )(( bbox.
xMinimum() - mGridOffsetX ) / mGridIntervalX + roundCorrection ) * mGridIntervalX + mGridOffsetX;
1711 double step = ( maxY - minY ) / 20;
1716 bool crosses180 =
false;
1717 bool crossed180 =
false;
1724 int gridLineCount = 0;
1725 while (( currentLevel <= bbox.
xMaximum() || ( crosses180 && !crossed180 ) ) && gridLineCount <
MAX_GRID_LINES )
1728 double currentY = minY;
1732 if ( currentY > maxY )
1745 QgsDebugMsg( QString(
"Caught CRS exception %1" ).arg( cse.
what() ) );
1752 QList<QPolygonF>::const_iterator lineIt = lineSegments.constBegin();
1753 for ( ; lineIt != lineSegments.constEnd(); ++lineIt )
1755 if (( *lineIt ).size() > 0 )
1757 lines.append( qMakePair( currentLevel, *lineIt ) );
1761 currentLevel += mGridIntervalX;
1762 if ( crosses180 && currentLevel > 180.0 )
1764 currentLevel -= 360.0;
1772 void QgsComposerMapGrid::sortGridLinesOnBorders(
const QList< QPair< double, QLineF > >& hLines,
const QList< QPair< double, QLineF > >& vLines, QMap< double, double >& leftFrameEntries,
1773 QMap< double, double >& rightFrameEntries, QMap< double, double >& topFrameEntries, QMap< double, double >& bottomFrameEntries )
const 1775 QList< QgsMapAnnotation > borderPositions;
1776 QList< QPair< double, QLineF > >::const_iterator it = hLines.constBegin();
1777 for ( ; it != hLines.constEnd(); ++it )
1779 QgsMapAnnotation p1;
1780 p1.coordinate = it->first;
1781 p1.itemPosition = it->second.p1();
1783 borderPositions << p1;
1785 QgsMapAnnotation p2;
1786 p2.coordinate = it->first;
1787 p2.itemPosition = it->second.p2();
1789 borderPositions << p2;
1791 it = vLines.constBegin();
1792 for ( ; it != vLines.constEnd(); ++it )
1794 QgsMapAnnotation p1;
1795 p1.coordinate = it->first;
1796 p1.itemPosition = it->second.p1();
1798 borderPositions << p1;
1800 QgsMapAnnotation p2;
1801 p2.coordinate = it->first;
1802 p2.itemPosition = it->second.p2();
1804 borderPositions << p2;
1807 QList< QgsMapAnnotation >::const_iterator bIt = borderPositions.constBegin();
1808 for ( ; bIt != borderPositions.constEnd(); ++bIt )
1813 leftFrameEntries.insert( bIt->itemPosition.y(), bIt->coordinate );
1817 rightFrameEntries.insert( bIt->itemPosition.y(), bIt->coordinate );
1821 topFrameEntries.insert( bIt->itemPosition.x(), bIt->coordinate );
1825 bottomFrameEntries.insert( bIt->itemPosition.x(), bIt->coordinate );
1835 return shouldShowDivisionForDisplayMode( coordinate, mLeftFrameDivisions );
1837 return shouldShowDivisionForDisplayMode( coordinate, mRightFrameDivisions );
1839 return shouldShowDivisionForDisplayMode( coordinate, mTopFrameDivisions );
1842 return shouldShowDivisionForDisplayMode( coordinate, mBottomFrameDivisions );
1853 bool sortByDistance(
const QPair<qreal , QgsComposerMapGrid::BorderSide>& a,
const QPair<qreal , QgsComposerMapGrid::BorderSide>& b )
1855 return a.first < b.first;
1868 if (( p.y() <= tolerance && p.x() <= tolerance )
1869 || ( p.y() <= tolerance && p.x() >= (
mComposerMap->rect().width() - tolerance ) )
1870 || ( p.y() >= (
mComposerMap->rect().height() - tolerance ) && p.x() <= tolerance )
1871 || ( p.y() >= (
mComposerMap->rect().height() - tolerance ) && p.x() >= (
mComposerMap->rect().width() - tolerance ) )
1877 if ( p.x() <= tolerance )
1888 if ( p.y() <= tolerance )
1900 QList< QPair<qreal, QgsComposerMapGrid::BorderSide > > distanceToSide;
1906 qSort( distanceToSide.begin(), distanceToSide.end(),
sortByDistance );
1907 return distanceToSide.at( 0 ).second;
1912 delete mGridLineSymbol;
1913 mGridLineSymbol = symbol;
1918 delete mGridMarkerSymbol;
1919 mGridMarkerSymbol = symbol;
1927 mLeftGridAnnotationDisplay = display;
1930 mRightGridAnnotationDisplay = display;
1933 mTopGridAnnotationDisplay = display;
1936 mBottomGridAnnotationDisplay = display;
1954 return mLeftGridAnnotationDisplay;
1957 return mRightGridAnnotationDisplay;
1960 return mTopGridAnnotationDisplay;
1964 return mBottomGridAnnotationDisplay;
1986 QStringList coordStrings;
1989 QList< QPair< double, QPolygonF > > xGridLines;
1990 QList< QPair< double, QPolygonF > > yGridLines;
1993 if ( crsGridParams( crsRect, inverseTransform ) != 0 )
1998 int xGridReturn = xGridLinesCRSTransform( crsRect, inverseTransform, xGridLines );
1999 int yGridReturn = yGridLinesCRSTransform( crsRect, inverseTransform, yGridLines );
2000 if ( xGridReturn != 0 || yGridReturn != 0 )
2005 QList< QPair< double, QPolygonF > >::const_iterator it = xGridLines.constBegin();
2006 for ( ; it != xGridLines.constEnd(); ++it )
2010 it = yGridLines.constBegin();
2011 for ( ; it != yGridLines.constEnd(); ++it )
2018 QList< QPair< double, QLineF > > xLines;
2019 QList< QPair< double, QLineF > > yLines;
2020 int xGridReturn = xGridLines( xLines );
2021 int yGridReturn = yGridLines( yLines );
2022 if ( xGridReturn != 0 && yGridReturn != 0 )
2027 QList< QPair< double, QLineF > >::const_iterator it = xLines.constBegin();
2028 for ( ; it != xLines.constEnd(); ++it )
2033 it = yLines.constBegin();
2034 for ( ; it != yLines.constEnd(); ++it )
2041 double currentExtension = 0;
2043 QStringList::const_iterator coordIt = coordStrings.constBegin();
2044 for ( ; coordIt != coordStrings.constEnd(); ++coordIt )
2047 maxExtension = qMax( maxExtension, currentExtension );
2051 double gridFrameDist = ( mGridFrameStyle ==
QgsComposerMapGrid::NoFrame ) ? 0 : mGridFrameWidth + ( mGridFramePenThickness / 2.0 );
2052 return maxExtension + mAnnotationFrameDistance + gridFrameDist;
2057 if ( unit == mGridUnit )
2062 mTransformDirty =
true;
2067 if ( interval == mGridIntervalX )
2071 mGridIntervalX = interval;
2072 mTransformDirty =
true;
2077 if ( interval == mGridIntervalY )
2081 mGridIntervalY = interval;
2082 mTransformDirty =
true;
2087 if ( offset == mGridOffsetX )
2091 mGridOffsetX = offset;
2092 mTransformDirty =
true;
2097 if ( offset == mGridOffsetY )
2101 mGridOffsetY = offset;
2102 mTransformDirty =
true;
2107 if ( style == mGridStyle )
2112 mTransformDirty =
true;
2120 mLeftGridAnnotationDirection = direction;
2123 mRightGridAnnotationDirection = direction;
2126 mTopGridAnnotationDirection = direction;
2129 mBottomGridAnnotationDirection = direction;
2145 mGridFrameSides = flags;
2151 mGridFrameSides |= flag;
2153 mGridFrameSides &= ~flag;
2158 return mGridFrameSides;
2163 return mGridFrameSides.testFlag( flag );
2168 mLeftGridAnnotationDirection = direction;
2169 mRightGridAnnotationDirection = direction;
2170 mTopGridAnnotationDirection = direction;
2171 mBottomGridAnnotationDirection = direction;
2179 mLeftGridAnnotationPosition = position;
2182 mRightGridAnnotationPosition = position;
2185 mTopGridAnnotationPosition = position;
2188 mBottomGridAnnotationPosition = position;
2206 return mLeftGridAnnotationPosition;
2209 return mRightGridAnnotationPosition;
2212 return mTopGridAnnotationPosition;
2216 return mBottomGridAnnotationPosition;
2225 return mLeftGridAnnotationDirection;
2231 return mLeftGridAnnotationDirection;
2234 return mRightGridAnnotationDirection;
2237 return mTopGridAnnotationDirection;
2241 return mBottomGridAnnotationDirection;
2251 mLeftFrameDivisions = divisions;
2254 mRightFrameDivisions = divisions;
2257 mTopFrameDivisions = divisions;
2260 mBottomFrameDivisions = divisions;
2277 return mLeftFrameDivisions;
2280 return mRightFrameDivisions;
2283 return mTopFrameDivisions;
2287 return mBottomFrameDivisions;
2303 QRectF mbr = mapPolygon.boundingRect();
2304 QgsRectangle mapBoundingRect( mbr.left(), mbr.bottom(), mbr.right(), mbr.top() );
2310 QgsPoint lowerLeft( mapBoundingRect.xMinimum(), mapBoundingRect.yMinimum() );
2311 QgsPoint upperRight( mapBoundingRect.xMaximum(), mapBoundingRect.yMaximum() );
2313 lowerLeft =
tr.transform( lowerLeft.x(), lowerLeft.y() );
2314 upperRight =
tr.transform( upperRight.x(), upperRight.y() );
2316 if ( lowerLeft.x() > upperRight.x() )
2324 crsRect =
tr.transformBoundingBox( mapBoundingRect );
2329 crsRect =
tr.transformBoundingBox( mapBoundingRect );
2337 QgsDebugMsg( QString(
"Caught CRS exception %1" ).arg( cse.
what() ) );
2343 QList<QPolygonF> QgsComposerMapGrid::trimLinesToMap(
const QPolygonF& line,
const QgsRectangle& rect )
2351 QList<QPolygonF> trimmedLines;
2352 QList<QgsGeometry*>::const_iterator geomIt = intersectedParts.constBegin();
2353 for ( ; geomIt != intersectedParts.constEnd(); ++geomIt )
2355 trimmedLines << ( *geomIt )->asQPolygonF();
2358 qDeleteAll( intersectedParts );
2359 intersectedParts.clear();
2363 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.
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 addItem(QgsComposerMapItem *item)
Adds a new map item to the stack and takes ownership of the item.
void setOffsetY(const double offset)
Sets the offset for grid lines in the y-direction.
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.
const QgsMapSettings & mapSettings() const
Return setting of QGIS map canvas.
FrameStyle
Style for grid frame.
QVector< QgsPoint > QgsPolyline
polyline is represented as a vector of points
QgsComposerMapItem(const QString &name, QgsComposerMap *map)
Constructor for QgsComposerMapItem.
QList< QgsGeometry * > asGeometryCollection() const
return contents of the geometry as a list of geometries
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()
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.
AnnotationDirection
Direction of grid annotations.
QgsPoint vertexAt(int atVertex)
Returns coordinates of a vertex.
void removeGrid(const QString &gridId)
Removes a grid from the stack and deletes the corresponding QgsComposerMapGrid.
void setGridLineColor(const QColor &color)
Sets color of grid lines.
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)
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.
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 setColor(const QColor &color)
virtual ~QgsComposerMapGridStack()
void updateBoundingRect()
Updates the bounding rect of this item.
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. ...
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
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.
void setUnits(const GridUnit unit)
Sets the units to use for grid measurements such as the interval and offset for grid lines...
void setPainter(QPainter *p)
GridStyle style() const
Gets the grid's style, which controls how the grid is drawn over the map's contents.
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.
QgsGeometry * intersection(QgsGeometry *geometry)
Returns a geometry representing the points shared by this geometry and other.
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...
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...
void stopRender(QgsRenderContext &context)
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.
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)
construct geometry from a rectangle
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)
construct geometry from a polyline
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.
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.
double maxGridExtension() const
Calculates the maximum distance grids within the stack extend beyond the QgsComposerMap's item rect...
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.
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)
QgsComposerMap * mComposerMap