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();