36 #include <QGraphicsScene>
37 #include <QGraphicsView>
43 :
QgsComposerItem( x, y, width, height, composition ), mKeepLayerSet( false ),
44 mOverviewFrameMapId( -1 ), mOverviewBlendMode( QPainter::CompositionMode_SourceOver ), mOverviewInverted( false ), mGridEnabled( false ), mGridStyle( Solid ),
45 mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationFontColor( QColor( 0, 0, 0 ) ),
46 mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ), mGridBlendMode( QPainter::CompositionMode_SourceOver ),
47 mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ),
48 mTopGridAnnotationPosition( OutsideMapFrame ), mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ),
49 mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ), mTopGridAnnotationDirection( Horizontal ),
50 mBottomGridAnnotationDirection( Horizontal ), mGridFrameStyle( NoGridFrame ), mGridFrameWidth( 2.0 ),
51 mCrossLength( 3 ), mMapCanvas( 0 ), mDrawCanvasItems( true )
82 setToolTip(
tr(
"Map %1" ).arg(
mId ) );
88 :
QgsComposerItem( 0, 0, 10, 10, composition ), mKeepLayerSet( false ), mOverviewFrameMapId( -1 ),
89 mOverviewBlendMode( QPainter::CompositionMode_SourceOver ), mOverviewInverted( false ), mGridEnabled( false ), mGridStyle( Solid ),
90 mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationFontColor( QColor( 0, 0, 0 ) ),
91 mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ), mGridBlendMode( QPainter::CompositionMode_SourceOver ),
92 mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ),
93 mTopGridAnnotationPosition( OutsideMapFrame ), mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ),
94 mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ), mTopGridAnnotationDirection( Horizontal ),
95 mBottomGridAnnotationDirection( Horizontal ), mGridFrameStyle( NoGridFrame ), mGridFrameWidth( 2.0 ), mCrossLength( 3 ),
96 mMapCanvas( 0 ), mDrawCanvasItems( true )
114 setToolTip(
tr(
"Map %1" ).arg(
mId ) );
160 if ( settings.value(
"/qgis/enable_anti_aliasing",
true ).toBool() )
162 painter->setRenderHint( QPainter::Antialiasing );
166 if ( theRendererContext )
179 double bk_scale = theMapRenderer.
scale();
184 bool bkLayerCaching = s.value(
"/qgis/enable_render_caching",
false ).toBool();
185 s.setValue(
"/qgis/enable_render_caching",
false );
187 if ( forceWidthScale )
189 theMapRenderer.
render( painter, forceWidthScale );
193 theMapRenderer.
render( painter );
195 s.setValue(
"/qgis/enable_render_caching", bkLayerCaching );
197 theMapRenderer.
setScale( bk_scale );
219 if ( horizontalVScaleFactor < 0 )
239 mCacheImage = QImage( w, h, QImage::Format_ARGB32 );
250 mCacheImage.fill( QColor( 255, 255, 255, 0 ).rgba() );
260 draw( &p, requestExtent, QSizeF( w, h ),
mCacheImage.logicalDpiX(), &forcedWidthScaleFactor );
276 QRectF thisPaintRect = QRectF( 0, 0, QGraphicsRectItem::rect().width(), QGraphicsRectItem::rect().height() );
278 painter->setClipRect( thisPaintRect );
284 QFont messageFont(
"", 12 );
285 painter->setFont( messageFont );
286 painter->setPen( QColor( 0, 0, 0 ) );
287 painter->drawText( thisPaintRect,
tr(
"Map will be printed here" ) );
301 if ( horizontalVScaleFactor < 0 )
307 double scale = rect().width() / imagePixelWidth;
321 painter->translate( xTopLeftShift, yTopLeftShift );
323 painter->translate( xShiftMM, -yShiftMM );
324 painter->scale( scale, scale );
342 QPaintDevice* thePaintDevice = painter->device();
343 if ( !thePaintDevice )
366 painter->translate( xTopLeftShift, yTopLeftShift );
368 painter->translate( xShiftMM, -yShiftMM );
369 draw( painter, requestRectangle, theSize, 25.4 );
380 painter->setClipRect( thisPaintRect , Qt::NoClip );
405 QGraphicsRectItem::update();
425 calculator.
setDpi( 25.4 );
432 QRectF currentRect = rect();
433 QRectF newSceneRect = QRectF( transform().dx(), transform().dy(), currentRect.width() + dx, currentRect.height() + dy );
465 int zoomMode = settings.value(
"/qgis/wheel_action", 2 ).toInt();
471 double zoomFactor = settings.value(
"/qgis/zoom_factor", 2.0 ).toDouble();
487 else if ( zoomMode == 2 )
489 centerX = mapMouseX + ( centerX - mapMouseX ) * ( 1.0 / zoomFactor );
490 centerY = mapMouseY + ( centerY - mapMouseY ) * ( 1.0 / zoomFactor );
494 double newIntervalX, newIntervalY;
501 else if ( delta < 0 )
524 double w = rectangle.width();
525 double h = rectangle.height();
550 QRectF currentRect = rect();
552 double newHeight = currentRect.width() * extent.
height() / extent.
width();
554 setSceneRect( QRectF( transform().dx(), transform().dy(), currentRect.width(), newHeight ) );
560 double currentScaleDenominator =
scale();
562 if ( scaleDenominator == currentScaleDenominator )
567 double scaleRatio = scaleDenominator / currentScaleDenominator;
613 QStringList::const_iterator layer_it = layers.constBegin();
616 for ( ; layer_it != layers.constEnd(); ++layer_it )
622 if ( currentRasterLayer )
625 if (( rasterProvider = currentRasterLayer->
dataProvider() ) )
627 if ( rasterProvider->
name() ==
"wms" )
651 QStringList::const_iterator layer_it = layers.constBegin();
654 for ( ; layer_it != layers.constEnd(); ++layer_it )
659 if ( currentLayer->
blendMode() != QPainter::CompositionMode_SourceOver )
665 if ( currentVectorLayer )
671 if ( currentVectorLayer->
featureBlendMode() != QPainter::CompositionMode_SourceOver )
680 if (( layerSettings.
blendMode != QPainter::CompositionMode_SourceOver ) ||
701 connect( layerRegistry, SIGNAL( layerWillBeRemoved( QString ) ),
this, SLOT(
updateCachedImage() ) );
713 QDomElement composerMapElem = doc.createElement(
"ComposerMap" );
714 composerMapElem.setAttribute(
"id",
mId );
719 composerMapElem.setAttribute(
"previewMode",
"Cache" );
723 composerMapElem.setAttribute(
"previewMode",
"Render" );
727 composerMapElem.setAttribute(
"previewMode",
"Rectangle" );
732 composerMapElem.setAttribute(
"keepLayerSet",
"true" );
736 composerMapElem.setAttribute(
"keepLayerSet",
"false" );
741 composerMapElem.setAttribute(
"drawCanvasItems",
"true" );
745 composerMapElem.setAttribute(
"drawCanvasItems",
"false" );
749 QDomElement overviewFrameElem = doc.createElement(
"overviewFrame" );
754 overviewFrameElem.setAttribute(
"overviewInverted",
"true" );
758 overviewFrameElem.setAttribute(
"overviewInverted",
"false" );
761 overviewFrameElem.appendChild( overviewFrameStyleElem );
762 composerMapElem.appendChild( overviewFrameElem );
766 QDomElement extentElem = doc.createElement(
"Extent" );
767 extentElem.setAttribute(
"xmin", QString::number(
mExtent.
xMinimum() ) );
768 extentElem.setAttribute(
"xmax", QString::number(
mExtent.
xMaximum() ) );
769 extentElem.setAttribute(
"ymin", QString::number(
mExtent.
yMinimum() ) );
770 extentElem.setAttribute(
"ymax", QString::number(
mExtent.
yMaximum() ) );
771 composerMapElem.appendChild( extentElem );
774 QDomElement layerSetElem = doc.createElement(
"LayerSet" );
775 QStringList::const_iterator layerIt =
mLayerSet.constBegin();
776 for ( ; layerIt !=
mLayerSet.constEnd(); ++layerIt )
778 QDomElement layerElem = doc.createElement(
"Layer" );
779 QDomText layerIdText = doc.createTextNode( *layerIt );
780 layerElem.appendChild( layerIdText );
781 layerSetElem.appendChild( layerElem );
783 composerMapElem.appendChild( layerSetElem );
789 QDomElement gridElem = doc.createElement(
"Grid" );
791 gridElem.setAttribute(
"gridStyle",
mGridStyle );
792 gridElem.setAttribute(
"intervalX", QString::number(
mGridIntervalX ) );
793 gridElem.setAttribute(
"intervalY", QString::number(
mGridIntervalY ) );
794 gridElem.setAttribute(
"offsetX", QString::number(
mGridOffsetX ) );
795 gridElem.setAttribute(
"offsetY", QString::number(
mGridOffsetY ) );
796 gridElem.setAttribute(
"crossLength", QString::number(
mCrossLength ) );
798 gridElem.setAttribute(
"gridFrameWidth", QString::number(
mGridFrameWidth ) );
801 gridElem.appendChild( gridLineStyleElem );
804 QDomElement annotationElem = doc.createElement(
"Annotation" );
819 QDomElement annotationFontColorElem = doc.createElement(
"fontColor" );
823 annotationElem.appendChild( annotationFontColorElem );
825 gridElem.appendChild( annotationElem );
826 composerMapElem.appendChild( gridElem );
828 elem.appendChild( composerMapElem );
829 return _writeXML( composerMapElem, doc );
834 if ( itemElem.isNull() )
839 QString idRead = itemElem.attribute(
"id",
"not found" );
840 if ( idRead !=
"not found" )
842 mId = idRead.toInt();
847 QString
previewMode = itemElem.attribute(
"previewMode" );
848 if ( previewMode ==
"Cache" )
852 else if ( previewMode ==
"Render" )
861 QDomElement overviewFrameElem = itemElem.firstChildElement(
"overviewFrame" );
862 if ( !overviewFrameElem.isNull() )
867 QString overviewInvertedFlag = overviewFrameElem.attribute(
"overviewInverted" );
868 if ( overviewInvertedFlag.compare(
"true", Qt::CaseInsensitive ) == 0 )
877 QDomElement overviewFrameSymbolElem = overviewFrameElem.firstChildElement(
"symbol" );
878 if ( !overviewFrameSymbolElem.isNull() )
886 QDomNodeList extentNodeList = itemElem.elementsByTagName(
"Extent" );
887 if ( extentNodeList.size() > 0 )
889 QDomElement extentElem = extentNodeList.at( 0 ).toElement();
890 double xmin, xmax, ymin, ymax;
891 xmin = extentElem.attribute(
"xmin" ).toDouble();
892 xmax = extentElem.attribute(
"xmax" ).toDouble();
893 ymin = extentElem.attribute(
"ymin" ).toDouble();
894 ymax = extentElem.attribute(
"ymax" ).toDouble();
900 QString keepLayerSetFlag = itemElem.attribute(
"keepLayerSet" );
901 if ( keepLayerSetFlag.compare(
"true", Qt::CaseInsensitive ) == 0 )
910 QString drawCanvasItemsFlag = itemElem.attribute(
"drawCanvasItems" );
911 if ( drawCanvasItemsFlag.compare(
"true", Qt::CaseInsensitive ) == 0 )
921 QDomNodeList layerSetNodeList = itemElem.elementsByTagName(
"LayerSet" );
923 if ( layerSetNodeList.size() > 0 )
925 QDomElement layerSetElem = layerSetNodeList.at( 0 ).toElement();
926 QDomNodeList layerIdNodeList = layerSetElem.elementsByTagName(
"Layer" );
927 for (
int i = 0; i < layerIdNodeList.size(); ++i )
929 layerSet << layerIdNodeList.at( i ).toElement().text();
939 QDomNodeList gridNodeList = itemElem.elementsByTagName(
"Grid" );
940 if ( gridNodeList.size() > 0 )
942 QDomElement gridElem = gridNodeList.at( 0 ).toElement();
943 mGridEnabled = ( gridElem.attribute(
"show",
"0" ) !=
"0" );
945 mGridIntervalX = gridElem.attribute(
"intervalX",
"0" ).toDouble();
946 mGridIntervalY = gridElem.attribute(
"intervalY",
"0" ).toDouble();
947 mGridOffsetX = gridElem.attribute(
"offsetX",
"0" ).toDouble();
948 mGridOffsetY = gridElem.attribute(
"offsetY",
"0" ).toDouble();
949 mCrossLength = gridElem.attribute(
"crossLength",
"3" ).toDouble();
951 mGridFrameWidth = gridElem.attribute(
"gridFrameWidth",
"2.0" ).toDouble();
954 QDomElement gridSymbolElem = gridElem.firstChildElement(
"symbol" );
956 if ( gridSymbolElem.isNull( ) )
962 gridElem.attribute(
"penColorGreen",
"0" ).toInt(),
963 gridElem.attribute(
"penColorBlue",
"0" ).toInt() ) );
970 QDomNodeList annotationNodeList = gridElem.elementsByTagName(
"Annotation" );
971 if ( annotationNodeList.size() > 0 )
973 QDomElement annotationElem = annotationNodeList.at( 0 ).toElement();
988 QDomNodeList annotationFontColorList = annotationElem.elementsByTagName(
"fontColor" );
989 if ( annotationFontColorList.size() > 0 )
991 QDomElement fontColorElem = annotationFontColorList.at( 0 ).toElement();
992 int red = fontColorElem.attribute(
"red",
"0" ).toInt();
993 int green = fontColorElem.attribute(
"green",
"0" ).toInt();
994 int blue = fontColorElem.attribute(
"blue",
"0" ).toInt();
1007 QDomNodeList composerItemList = itemElem.elementsByTagName(
"ComposerItem" );
1008 if ( composerItemList.size() > 0 )
1010 QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
1035 QStringList currentLayerSet;
1045 for (
int i =
mLayerSet.size() - 1; i >= 0; --i )
1047 if ( !currentLayerSet.contains(
mLayerSet.at( i ) ) )
1056 QList< QPair< double, QLineF > > verticalLines;
1058 QList< QPair< double, QLineF > >::const_iterator vIt = verticalLines.constBegin();
1059 QList< QPair< double, QLineF > > horizontalLines;
1061 QList< QPair< double, QLineF > >::const_iterator hIt = horizontalLines.constBegin();
1063 QRectF thisPaintRect = QRectF( 0, 0, QGraphicsRectItem::rect().width(), QGraphicsRectItem::rect().height() );
1064 p->setClipRect( thisPaintRect );
1073 for ( ; vIt != verticalLines.constEnd(); ++vIt )
1078 for ( ; hIt != horizontalLines.constEnd(); ++hIt )
1085 QPointF intersectionPoint, crossEnd1, crossEnd2;
1086 for ( ; vIt != verticalLines.constEnd(); ++vIt )
1090 drawGridLine( QLineF( vIt->second.p1(), crossEnd1 ), p );
1093 hIt = horizontalLines.constBegin();
1094 for ( ; hIt != horizontalLines.constEnd(); ++hIt )
1096 if ( hIt->second.intersect( vIt->second, &intersectionPoint ) == QLineF::BoundedIntersection )
1105 drawGridLine( QLineF( vIt->second.p2(), crossEnd2 ), p );
1108 hIt = horizontalLines.constBegin();
1109 for ( ; hIt != horizontalLines.constEnd(); ++hIt )
1113 drawGridLine( QLineF( hIt->second.p1(), crossEnd1 ), p );
1115 vIt = verticalLines.constBegin();
1116 for ( ; vIt != verticalLines.constEnd(); ++vIt )
1118 if ( vIt->second.intersect( hIt->second, &intersectionPoint ) == QLineF::BoundedIntersection )
1127 drawGridLine( QLineF( hIt->second.p2(), crossEnd1 ), p );
1133 p->setClipRect( thisPaintRect , Qt::NoClip );
1150 QMap< double, double > leftGridFrame;
1151 QMap< double, double > rightGridFrame;
1152 QMap< double, double > topGridFrame;
1153 QMap< double, double > bottomGridFrame;
1184 poly << line.p1() << line.p2();
1199 QMap< double, double > pos = borderPos;
1201 if ( border ==
Left || border ==
Right )
1203 pos.insert( rect().height(), rect().height() );
1208 pos.insert( rect().width(), rect().width() );
1212 QMap< double, double >::const_iterator posIt = pos.constBegin();
1213 for ( ; posIt != pos.constEnd(); ++posIt )
1215 p->setBrush( QBrush( white ? Qt::white : Qt::black ) );
1216 if ( border ==
Left || border ==
Right )
1218 height = posIt.key() - currentCoord;
1226 width = posIt.key() - currentCoord;
1230 p->drawRect( QRectF( x, y, width, height ) );
1231 currentCoord = posIt.key();
1244 QString currentAnnotationString;
1245 QList< QPair< double, QLineF > >::const_iterator it = hLines.constBegin();
1246 for ( ; it != hLines.constEnd(); ++it )
1253 it = vLines.constBegin();
1254 for ( ; it != vLines.constEnd(); ++it )
1268 double xpos = pos.x();
1269 double ypos = pos.y();
1274 if ( frameBorder ==
Left )
1282 ypos += textWidth / 2.0;
1288 ypos += textHeight / 2.0;
1296 ypos += textWidth / 2.0;
1302 ypos += textHeight / 2.0;
1311 else if ( frameBorder ==
Right )
1318 ypos += textWidth / 2.0;
1324 ypos += textHeight / 2.0;
1332 ypos += textWidth / 2.0;
1338 ypos += textHeight / 2.0;
1346 else if ( frameBorder ==
Bottom )
1353 xpos -= textWidth / 2.0;
1357 xpos += textHeight / 2.0;
1367 xpos -= textWidth / 2.0;
1371 xpos += textHeight / 2.0;
1387 xpos -= textWidth / 2.0;
1392 xpos += textHeight / 2.0;
1401 xpos -= textWidth / 2.0;
1406 xpos += textHeight / 2.0;
1417 drawAnnotation( p, QPointF( xpos, ypos ), rotation, annotationString );
1423 p->translate( pos );
1424 p->rotate( rotation );
1441 QString annotationString;
1451 QStringList split = annotationString.split(
"," );
1454 return split.at( 0 );
1458 if ( split.size() < 2 )
1462 return split.at( 1 );
1476 QRectF mapBoundingRect = mapPolygon.boundingRect();
1479 double roundCorrection = mapBoundingRect.top() > 0 ? 1.0 : 0.0;
1486 double yCanvasCoord;
1488 while ( currentLevel <= mapBoundingRect.bottom() )
1490 yCanvasCoord = rect().height() * ( 1 - ( currentLevel - mapBoundingRect.top() ) / mapBoundingRect.height() );
1491 lines.push_back( qMakePair( currentLevel, QLineF( 0, yCanvasCoord, rect().width(), yCanvasCoord ) ) );
1497 QVector<QLineF> borderLines;
1498 borderLines << QLineF( mapPolygon.at( 0 ), mapPolygon.at( 1 ) );
1499 borderLines << QLineF( mapPolygon.at( 1 ), mapPolygon.at( 2 ) );
1500 borderLines << QLineF( mapPolygon.at( 2 ), mapPolygon.at( 3 ) );
1501 borderLines << QLineF( mapPolygon.at( 3 ), mapPolygon.at( 0 ) );
1503 QList<QPointF> intersectionList;
1505 while ( currentLevel <= mapBoundingRect.bottom() )
1507 intersectionList.clear();
1508 QLineF gridLine( mapBoundingRect.left(), currentLevel, mapBoundingRect.right(), currentLevel );
1510 QVector<QLineF>::const_iterator it = borderLines.constBegin();
1511 for ( ; it != borderLines.constEnd(); ++it )
1513 QPointF intersectionPoint;
1514 if ( it->intersect( gridLine, &intersectionPoint ) == QLineF::BoundedIntersection )
1516 intersectionList.push_back( intersectionPoint );
1517 if ( intersectionList.size() >= 2 )
1524 if ( intersectionList.size() >= 2 )
1526 lines.push_back( qMakePair( currentLevel, QLineF(
mapToItemCoords( intersectionList.at( 0 ) ),
mapToItemCoords( intersectionList.at( 1 ) ) ) ) );
1544 QRectF mapBoundingRect = mapPolygon.boundingRect();
1547 double roundCorrection = mapBoundingRect.left() > 0 ? 1.0 : 0.0;
1553 double xCanvasCoord;
1555 while ( currentLevel <= mapBoundingRect.right() )
1557 xCanvasCoord = rect().width() * ( currentLevel - mapBoundingRect.left() ) / mapBoundingRect.width();
1558 lines.push_back( qMakePair( currentLevel, QLineF( xCanvasCoord, 0, xCanvasCoord, rect().height() ) ) );
1564 QVector<QLineF> borderLines;
1565 borderLines << QLineF( mapPolygon.at( 0 ), mapPolygon.at( 1 ) );
1566 borderLines << QLineF( mapPolygon.at( 1 ), mapPolygon.at( 2 ) );
1567 borderLines << QLineF( mapPolygon.at( 2 ), mapPolygon.at( 3 ) );
1568 borderLines << QLineF( mapPolygon.at( 3 ), mapPolygon.at( 0 ) );
1570 QList<QPointF> intersectionList;
1572 while ( currentLevel <= mapBoundingRect.right() )
1574 intersectionList.clear();
1575 QLineF gridLine( currentLevel, mapBoundingRect.bottom(), currentLevel, mapBoundingRect.top() );
1577 QVector<QLineF>::const_iterator it = borderLines.constBegin();
1578 for ( ; it != borderLines.constEnd(); ++it )
1580 QPointF intersectionPoint;
1581 if ( it->intersect( gridLine, &intersectionPoint ) == QLineF::BoundedIntersection )
1583 intersectionList.push_back( intersectionPoint );
1584 if ( intersectionList.size() >= 2 )
1591 if ( intersectionList.size() >= 2 )
1593 lines.push_back( qMakePair( currentLevel, QLineF(
mapToItemCoords( intersectionList.at( 0 ) ),
mapToItemCoords( intersectionList.at( 1 ) ) ) ) );
1630 p.setCapStyle( Qt::FlatCap );
1648 QRectF rectangle = rect();
1650 rectangle.setLeft( rectangle.left() - extension );
1651 rectangle.setRight( rectangle.right() + extension );
1652 rectangle.setTop( rectangle.top() - extension );
1653 rectangle.setBottom( rectangle.bottom() + extension );
1656 prepareGeometryChange();
1682 poly.translate( -dx, -dy );
1694 QList< QPair< double, QLineF > > xLines;
1695 QList< QPair< double, QLineF > > yLines;
1700 if ( xGridReturn != 0 && yGridReturn != 0 )
1706 double currentExtension = 0;
1707 QString currentAnnotationString;
1709 QList< QPair< double, QLineF > >::const_iterator it = xLines.constBegin();
1710 for ( ; it != xLines.constEnd(); ++it )
1714 maxExtension = qMax( maxExtension, currentExtension );
1717 it = yLines.constBegin();
1718 for ( ; it != yLines.constEnd(); ++it )
1722 maxExtension = qMax( maxExtension, currentExtension );
1750 poly << QPointF( rotationPoint.
x() + dx, rotationPoint.
y() + dy );
1756 poly << QPointF( rotationPoint.
x() + dx, rotationPoint.
y() + dy );
1762 poly << QPointF( rotationPoint.
x() + dx, rotationPoint.
y() + dy );
1768 poly << QPointF( rotationPoint.
x() + dx, rotationPoint.
y() + dy );
1781 QRectF bRect = poly.boundingRect();
1792 if ( extentWidth <= 0 )
1796 return rect().width() / extentWidth;
1848 double dxScaled = xShift * mmToMapUnits;
1849 double dyScaled = - yShift * mmToMapUnits;
1860 if ( mapPoly.size() < 1 )
1862 return QPointF( 0, 0 );
1867 double dx = mapCoords.x() - rotationPoint.
x();
1868 double dy = mapCoords.y() - rotationPoint.
y();
1870 QgsPoint backRotatedCoords( rotationPoint.
x() + dx, rotationPoint.
y() + dy );
1873 double xItem = rect().width() * ( backRotatedCoords.x() - unrotatedExtent.xMinimum() ) / unrotatedExtent.width();
1874 double yItem = rect().height() * ( 1 - ( backRotatedCoords.y() - unrotatedExtent.yMinimum() ) / unrotatedExtent.height() );
1875 return QPointF( xItem, yItem );
1880 if ( p.x() <= pen().widthF() )
1884 else if ( p.x() >= ( rect().width() - pen().widthF() ) )
1888 else if ( p.y() <= pen().widthF() )
1905 QList<QGraphicsItem*> itemList =
mMapCanvas->items();
1906 if ( itemList.size() < 1 )
1910 QGraphicsItem* currentItem = 0;
1912 #if QT_VERSION >= 0x40600 //Qt 4.6 provides the items in visibility order
1913 for (
int i = itemList.size() - 1; i >= 0; --i )
1915 currentItem = itemList.at( i );
1917 if ( !currentItem || currentItem->data( 0 ).toString() !=
"AnnotationItem" )
1923 #else //Qt <4.6 provides the items in random order
1924 QMultiMap<int, QGraphicsItem*> topLevelItems;
1925 QMultiMap<QGraphicsItem*, QGraphicsItem*> childItems;
1927 for (
int i = 0; i < itemList.size(); ++i )
1929 currentItem = itemList.at( i );
1931 if ( !currentItem || currentItem->data( 0 ) !=
"AnnotationItem" )
1935 if ( currentItem->parentItem() )
1937 childItems.insert( currentItem->parentItem(), currentItem );
1941 topLevelItems.insert( currentItem->zValue(), currentItem );
1945 QMultiMap<int, QGraphicsItem*>::iterator topLevelIt = topLevelItems.begin();
1946 for ( ; topLevelIt != topLevelItems.end(); ++topLevelIt )
1951 QMap<QGraphicsItem*, QGraphicsItem*>::iterator childIt = childItems.find( topLevelIt.value() );
1952 while ( childIt != childItems.end() && childIt.key() == topLevelIt.value() )
1974 double scaleFactor = 1.0 /
mMapCanvas->logicalDpiX() * 25.4;
1976 double itemX, itemY;
1977 QGraphicsItem* parent = item->parentItem();
1986 QPointF itemScenePos = item->scenePos();
1987 QPointF parentScenePos = parent->scenePos();
1991 itemX = mapPos.x() + ( itemScenePos.x() - parentScenePos.x() ) * scaleFactor;
1992 itemY = mapPos.y() + ( itemScenePos.y() - parentScenePos.y() ) * scaleFactor;
1994 painter->translate( itemX, itemY );
1997 painter->scale( scaleFactor, scaleFactor );
2000 item->setData( 1,
"composer" );
2001 item->paint( painter, itemStyle, 0 );
2002 item->setData( 1,
"" );
2010 return QPointF( 0, 0 );
2015 return QPointF( 0, 0 );
2018 QRectF graphicsSceneRect =
mMapCanvas->sceneRect();
2019 QPointF itemScenePos = item->scenePos();
2022 double mapX = itemScenePos.x() / graphicsSceneRect.
width() * mapRendererExtent.
width() + mapRendererExtent.
xMinimum();
2023 double mapY = mapRendererExtent.
yMaximum() - itemScenePos.y() / graphicsSceneRect.height() * mapRendererExtent.
height();
2115 QMap< double, double >& rightFrameEntries, QMap< double, double >& topFrameEntries, QMap< double, double >& bottomFrameEntries )
const
2117 QList< QPair< double, QPointF > > borderPositions;
2118 QList< QPair< double, QLineF > >::const_iterator it = hLines.constBegin();
2119 for ( ; it != hLines.constEnd(); ++it )
2121 borderPositions << qMakePair( it->first, it->second.p1() );
2122 borderPositions << qMakePair( it->first, it->second.p2() );
2124 it = vLines.constBegin();
2125 for ( ; it != vLines.constEnd(); ++it )
2127 borderPositions << qMakePair( it->first, it->second.p1() );
2128 borderPositions << qMakePair( it->first, it->second.p2() );
2131 QList< QPair< double, QPointF > >::const_iterator bIt = borderPositions.constBegin();
2132 for ( ; bIt != borderPositions.constEnd(); ++bIt )
2137 leftFrameEntries.insert( bIt->second.y(), bIt->first );
2141 rightFrameEntries.insert( bIt->second.y(), bIt->first );
2145 topFrameEntries.insert( bIt->second.x(), bIt->first );
2149 bottomFrameEntries.insert( bIt->second.x(), bIt->first );
2162 if ( !overviewFrameMap )
2188 QPolygonF intersectPolygon;
2189 double x = ( intersectRect.
xMinimum() - thisExtent.
xMinimum() ) / thisExtent.
width() * rect().width();
2191 double width = intersectRect.
width() / thisExtent.
width() * rect().width();
2192 double height = intersectRect.
height() / thisExtent.
height() * rect().height();
2193 intersectPolygon << QPointF( x, y ) << QPointF( x + width, y ) << QPointF( x + width, y + height ) << QPointF( x, y + height ) << QPointF( x, y );
2195 QList<QPolygonF> rings;
2205 QPolygonF outerPolygon;
2206 outerPolygon << QPointF( 0, 0 ) << QPointF( rect().width(), 0 ) << QPointF( rect().width(), rect().height() ) << QPointF( 0, rect().height() ) << QPointF( 0, 0 );
2209 rings.append( intersectPolygon );
2221 properties.insert(
"color",
"255,0,0,255" );
2222 properties.insert(
"style",
"solid" );
2223 properties.insert(
"style_border",
"no" );
2232 properties.insert(
"color",
"0,0,0,255" );
2233 properties.insert(
"width",
"0.3" );
2234 properties.insert(
"capstyle",
"flat" );
2242 bool degreeUnits =
true;
2248 if ( format ==
"DM" && degreeUnits )
2252 else if ( format ==
"DMS" && degreeUnits )
2277 QList<const QgsComposerMap*>::const_iterator mapIt = mapList.constBegin();
2278 for ( ; mapIt != mapList.constEnd(); ++mapIt )
2280 if (( *mapIt )->id() > maxId )
2282 maxId = ( *mapIt )->id();
QString toDegreesMinutesSeconds(int thePrecision) const
Return a string representation as degrees minutes seconds.
int mOverviewFrameMapId
Id of map which displays its extent rectangle into this composer map (overview map functionality)...
double mXOffset
Offset in x direction for showing map cache image.
void setMapUnits(QGis::UnitType mapUnits)
Set the map units.
QgsPalLayerSettings & layer(const QString &layerName)
returns PAL layer settings for a registered layer
void setForceVectorOutput(bool force)
Added in QGIS v1.5.
bool mGridEnabled
True if coordinate grid has to be displayed.
void draw(QPainter *painter, const QgsRectangle &extent, const QSizeF &size, double dpi, double *forceWidthScale=0)
Draw to paint device.
void setRenderingStopped(bool stopped)
A rectangle specified with double values.
Base class for all map layer types.
void renderPolygon(const QPolygonF &points, QList< QPolygonF > *rings, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
void render(QPainter *painter, double *forceWidthScale=0)
starts rendering @ param forceWidthScale Force a specific scale factor for line widths and marker siz...
bool mDrawing
set to true if in state of drawing.
void setLabelingEngine(QgsLabelingEngineInterface *iface)
Set labeling engine.
double mGridIntervalY
Grid line interval in y-direction (map units)
GridAnnotationDirection gridAnnotationDirection(QgsComposerMap::Border border) const
QgsRenderContext * rendererContext()
Accessor for render context.
double fontHeightCharacterMM(const QFont &font, const QChar &c) const
Returns the font height of a character in millimeters.
bool containsWMSLayer() const
True if composer map renders a WMS layer.
static QgsMapRenderer::BlendMode getBlendModeEnum(const QPainter::CompositionMode blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode Added in 1.9.
virtual void setRotation(double r)
void setXMaximum(double x)
Set the maximum x value.
double mapUnitsToMM() const
Returns the conversion factor map units -> mm.
void assignFreeId()
Sets mId to a number not yet used in the composition.
void setOffset(double xOffset, double yOffset)
Sets offset values to shift image (useful for live updates when moving item content) ...
double yMaximum() const
Get the y maximum value (top side of rectangle)
QStringList mLayerSet
Stored layer list (used if layer live-link mKeepLayerSet is disabled)
QFont mGridAnnotationFont
Font for grid line annotation.
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
void requestedExtent(QgsRectangle &extent) const
Calculates the extent to request and the yShift of the top-left point in case of rotation.
bool mDrawCanvasItems
True if annotation items, rubber band, etc.
QString toDegreesMinutes(int thePrecision) const
Return a string representation as degrees minutes.
QPainter::CompositionMode bufferBlendMode
QStringList layerSet() const
Getter for stored layer set that is used if mKeepLayerSet is true.
double maxExtension() const
QgsRectangle extent() const
returns current extent
static QgsFillSymbolV2 * createSimple(const QgsStringMap &properties)
Create a fill symbol with one symbol layer: SimpleFill with specified properties. ...
void cache()
Create cache image.
QList< const QgsComposerMap * > composerMapItems() const
Returns pointers to all composer maps in the scene.
A item that forms part of a map composition.
void connectUpdateSlot()
Establishes signal/slot connection for update in case of layer change.
QgsMapRenderer * mapRenderer()
Returns pointer to map renderer of qgis map canvas.
Border
Enum for different frame borders.
void updateItem()
Updates item, with the possibility to do custom update for subclasses.
QPointF composerMapPosForItem(const QGraphicsItem *item) const
QPainter::CompositionMode mOverviewBlendMode
Blend mode for overview.
void setDpi(double dpi)
Set the dpi to be used in scale calculations.
QGraphicsView * mMapCanvas
double mLastValidViewScaleFactor
Backup to restore item appearance if no view scale factor is available.
void setScale(double scale)
Sets scale for scale based visibility.
void setProjectionsEnabled(bool enabled)
sets whether to use projections for this layer set
virtual void drawFrame(QPainter *p)
Draw black frame around item.
static QPainter::CompositionMode getCompositionMode(const QgsMapRenderer::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode Added in 1.9.
void updateCachedImage()
Called if map canvas has changed.
bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
sets state from Dom document
void createDefaultGridLineSymbol()
QPolygonF transformedMapPolygon() const
Returns extent that considers rotation and shift with mOffsetX / mOffsetY.
QColor backgroundColor() const
Gets the background color for this item.
void setLayerSet(const QStringList &layers)
change current layer set
A non GUI class for rendering a map layer set onto a QPainter.
double mRotation
Item rotation in degrees, clockwise.
void mapPolygon(QPolygonF &poly) const
Returns the polygon of the map extent.
void initGridAnnotationFormatFromProject()
bool mShowGridAnnotation
True if coordinate values should be drawn.
void setSceneRect(const QRectF &rectangle)
Sets new scene rectangle bounds and recalculates hight and extent.
bool containsAdvancedEffects() const
True if composer map contains layers with blend modes or flattened layers for vectors.
QMap< QString, QString > QgsStringMap
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
QRectF boundingRect() const
In case of annotations, the bounding rectangle can be larger than the map item rectangle.
BlendMode
Blending modes enum defining the available composition modes that can be used when rendering a layer...
void zoomContent(int delta, double x, double y)
Zoom content of map.
void setGridPenColor(const QColor &c)
Sets the color of the grid pen.
virtual QString name() const =0
return a provider name
void setWidth(double width)
GridFrameStyle mGridFrameStyle
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
sets destination coordinate reference system
int mGridAnnotationPrecision
Digits after the dot.
void itemChanged()
Used e.g.
void setNewScale(double scaleDenominator)
Sets new scale and changes only mExtent.
bool _readXML(const QDomElement &itemElem, const QDomDocument &doc)
Reads parameter that are not subclass specific in document.
static QDomElement saveSymbol(QString symbolName, QgsSymbolV2 *symbol, QDomDocument &doc)
Perform transforms between map coordinates and device coordinates.
QgsLineSymbolV2 * mGridLineSymbol
void storeCurrentLayerSet()
Stores the current layer set of the qgis mapcanvas in mLayerSet.
GridAnnotationDirection mLeftGridAnnotationDirection
Annotation direction on left side ( horizontal or vertical )
void setColor(const QColor &color)
double mAnnotationFrameDistance
Distance between map frame and annotation.
double scale() const
Scale.
GridAnnotationDirection mRightGridAnnotationDirection
Annotation direction on right side ( horizontal or vertical )
void drawCoordinateAnnotations(QPainter *p, const QList< QPair< double, QLineF > > &hLines, const QList< QPair< double, QLineF > > &vLines)
Draw coordinates for mGridAnnotationType Coordinate.
QPainter::CompositionMode blendMode() const
Read blend mode for layer.
void setUseAdvancedEffects(bool enabled)
Used to enable or disable advanced effects such as blend modes.
double horizontalViewScaleFactor() const
Returns the zoom factor of the graphics view.
QRectF mCurrentRectangle
Current bounding rectangle.
void setScaleFactor(double factor)
double mCrossLength
The length of the cross sides for mGridStyle Cross.
QPainter::CompositionMode featureBlendMode() const
Read blend mode for layer.
virtual bool willUseLayer(QgsVectorLayer *layer)
called to find out whether the layer is used for labeling
double calculate(const QgsRectangle &mapExtent, int canvasWidth)
Calculate the scale denominator.
void updateBoundingRect()
Updates the bounding rect of this item.
double mGridOffsetY
Grid line offset in y-direction.
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
double xMaximum() const
Get the x maximum value (right side of rectangle)
virtual void updateItem()
Updates item, with the possibility to do custom update for subclasses.
void drawOverviewMapExtent(QPainter *p)
virtual void drawSelectionBoxes(QPainter *p)
Draw selection boxes around item.
virtual QgsLabelingEngineInterface * clone()=0
called when passing engine among map renderers
double textWidthMillimeters(const QFont &font, const QString &text) const
Returns the font width in millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE...
static QgsLineSymbolV2 * createSimple(const QgsStringMap &properties)
Create a line symbol with one symbol layer: SimpleLine with specified properties. ...
void rotate(double angle, double &x, double &y) const
Rotates a point / vector.
QPainter::CompositionMode blendMode
QString gridAnnotationString(double value, AnnotationCoordinate coord) const
bool hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
int printResolution() const
bool writeXML(QDomElement &elem, QDomDocument &doc) const
stores state in Dom node
bool drawCanvasItems() const
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
void setCacheUpdated(bool u=false)
void setYMinimum(double y)
Set the minimum y value.
double scale() const
Scale denominator.
void setDrawEditingInformation(bool b)
int yGridLines(QList< QPair< double, QLineF > > &lines) const
Returns the grid lines for the y-coordinates.
double mYOffset
Offset in y direction for showing map cache image.
void renderPolyline(const QPolygonF &points, const QgsFeature *f, QgsRenderContext &context, int layer=-1, bool selected=false)
bool setExtent(const QgsRectangle &extent)
sets extent and checks whether suitable (returns false if not)
void rotationChanged(double newRotation)
Is emitted on rotation change to notify north arrow pictures.
void drawAnnotation(QPainter *p, const QPointF &pos, int rotation, const QString &annotationText)
Draws a single annotation.
void setNewExtent(const QgsRectangle &extent)
Sets new Extent and changes width, height (and implicitely also scale)
void setGridPen(const QPen &p)
Sets the pen to draw composer grid.
void setPainter(QPainter *p)
void moveContent(double dx, double dy)
Move content of map.
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
void drawText(QPainter *p, double x, double y, const QString &text, const QFont &font) const
Draws Text.
void setOutputSize(QSize size, int dpi)
void drawGridFrame(QPainter *p, const QList< QPair< double, QLineF > > &hLines, const QList< QPair< double, QLineF > > &vLines)
double mGridIntervalX
Grid line interval in x-direction (map units)
GridAnnotationPosition mTopGridAnnotationPosition
Annotation position for top map side (inside / outside / not shown)
QPainter::CompositionMode shapeBlendMode
void drawCanvasItem(QGraphicsItem *item, QPainter *painter, const QStyleOptionGraphicsItem *itemStyle)
void setOverviewFrameMapSymbol(QgsFillSymbolV2 *symbol)
PreviewMode
Preview style.
GridAnnotationPosition gridAnnotationPosition(QgsComposerMap::Border border) const
GridAnnotationPosition mLeftGridAnnotationPosition
Annotation position for left map side (inside / outside / not shown)
QgsComposition * mComposition
A class to represent a point geometry.
GridAnnotationFormat mGridAnnotationFormat
Graphics scene for map printing.
void sortGridLinesOnBorders(const QList< QPair< double, QLineF > > &hLines, const QList< QPair< double, QLineF > > &vLines, QMap< double, double > &leftFrameEntries, QMap< double, double > &rightFrameEntries, QMap< double, double > &topFrameEntries, QMap< double, double > &bottomFrameEntries) const
This class tracks map layers that are currently loaded and provides a means to fetch a pointer to a m...
Object representing map window.
GridStyle mGridStyle
Solid or crosses.
QgsFillSymbolV2 * mOverviewFrameMapSymbol
Drawing style for overview farme.
GridAnnotationPosition mRightGridAnnotationPosition
Annotation position for right map side (inside / outside / not shown)
GridAnnotationDirection mTopGridAnnotationDirection
Annotation direction on top side ( horizontal or vertical )
void renderModeUpdateCachedImage()
Call updateCachedImage if item is in render mode.
PreviewMode previewMode() const
void drawGridLine(const QLineF &line, QPainter *p)
virtual ~QgsComposerMap()
void setGridAnnotationDirection(GridAnnotationDirection d, QgsComposerMap::Border border)
Calculates scale for a given combination of canvas size, map extent, and monitor dpi.
int layerTransparency() const
Read transparency for layer.
int xGridLines(QList< QPair< double, QLineF > > &lines) const
Returns the grid lines with associated coordinate value.
bool useAdvancedEffects() const
Returns true if a composition should use advanced effects such as blend modes.
void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget)
Reimplementation of QCanvasItem::paint - draw on canvas.
Contains information about the context of a rendering operation.
bool mKeepLayerSet
Flag if layers to be displayed should be read from qgis canvas (true) or from stored list in mLayerSe...
QString readEntry(const QString &scope, const QString &key, const QString &def=QString::null, bool *ok=0) const
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
void stopRender(QgsRenderContext &context)
double mGridOffsetX
Grid line offset in x-direction.
void setOverviewInverted(bool inverted)
Sets the overview's inversion mode.
QgsLabelingEngineInterface * labelingEngine()
Labeling engine (NULL if there's no custom engine)
bool _writeXML(QDomElement &itemElem, QDomDocument &doc) const
Writes parameter that are not subclass specific in document.
QgsMapRenderer * mMapRenderer
QgsRectangle extent() const
GridAnnotationDirection mBottomGridAnnotationDirection
Annotation direction on bottom side ( horizontal or vertical )
QPainter::CompositionMode blendMode() const
Returns the item's composition blending mode.
int mId
Unique identifier.
void setYMaximum(double y)
Set the maximum y value.
virtual void drawBackground(QPainter *p)
Draw background.
QgsRectangle intersect(const QgsRectangle *rect) const
return the intersection with the given rectangle
static QgsProject * instance()
access to canonical QgsProject instance
void startRender(QgsRenderContext &context, const QgsVectorLayer *layer=0)
void setMapRotation(double r)
virtual void setSceneRect(const QRectF &rectangle)
Sets this items bound in scene coordinates such that 1 item size units corresponds to 1 scene size un...
void setGridAnnotationPosition(GridAnnotationPosition p, QgsComposerMap::Border border)
void drawCoordinateAnnotation(QPainter *p, const QPointF &pos, QString annotationString)
void transformShift(double &xShift, double &yShift) const
Scales a composer map shift (in MM) and rotates it by mRotation.
const QgsComposition * composition() const
void drawGridFrameBorder(QPainter *p, const QMap< double, double > &borderPos, Border border)
bool hasBackground() const
Whether this item has a Background or not.
const QMap< QString, QgsMapLayer * > & mapLayers()
Retrieve the mapLayers collection (mainly intended for use by projection)
QgsComposerMap(QgsComposition *composition, int x, int y, int width, int height)
Constructor.
void resize(double dx, double dy)
resizes an item in x- and y direction (canvas coordinates)
QgsMapLayer * mapLayer(QString theLayerId)
Retrieve a pointer to a loaded layer by id.
QPainter::CompositionMode shadowBlendMode
static QgsSymbolV2 * loadSymbol(QDomElement &element)
QgsRasterDataProvider * dataProvider()
Returns the data provider.
void setRasterScaleFactor(double factor)
void setOverviewBlendMode(QPainter::CompositionMode blendMode)
Sets the overview's blending mode.
GridAnnotationPosition mBottomGridAnnotationPosition
Annotation position for bottom map side (inside / outside / not shown)
void setGridLineSymbol(QgsLineSymbolV2 *symbol)
void setGridPenWidth(double w)
Sets with of grid pen.
void createDefaultOverviewFrameSymbol()
void drawGrid(QPainter *p)
Draws the map grid.
QColor mGridAnnotationFontColor
Font color for grid line annotation.
QPointF mapToItemCoords(const QPointF &mapCoords) const
Transforms map coordinates to item coordinates (considering rotation and move offset) ...
void setPreviewMode(PreviewMode m)
QgsComposition::PlotStyle plotStyle() const
double width() const
Width of the rectangle.
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...
QGis::UnitType mapUnits() const
Represents a vector layer which manages a vector based data sets.
const QgsComposerMap * getComposerMapById(int id) const
Returns the composer map with specified id.
double xMinimum() const
Get the x minimum value (left side of rectangle)
PreviewMode mPreviewMode
Preview style.
QStringList & layerSet()
returns current layer set
void setAlpha(qreal alpha)
Set alpha transparency 1 for opaque, 0 for invisible.
QPainter::CompositionMode mGridBlendMode
Blend mode for grid.
void setGridBlendMode(QPainter::CompositionMode blendMode)
Sets the grid's blending mode.
void syncLayerSet()
Removes layer ids from mLayerSet that are no longer present in the qgis main map. ...
double fontAscentMillimeters(const QFont &font) const
Returns the font ascent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCAL...
void setOverviewFrameMap(int mapId)
Sets overview frame map.
int mNumCachedLayers
Number of layers when cache was created.
void setXMinimum(double x)
Set the minimum x value.
QgsRectangle transformedExtent() const
Returns extent that considers mOffsetX / mOffsetY (during content move)
double height() const
Height of the rectangle.
Base class for raster data providers.
void scale(double scaleFactor, const QgsPoint *c=0)
Scale the rectangle around its center point.
Border borderForLineCoord(const QPointF &p) const
Returns the item border of a point (in item coordinates)