37 #include <QGraphicsScene>
38 #include <QGraphicsView>
44 :
QgsComposerItem( x, y, width, height, composition ), mMapRotation( 0 ), mKeepLayerSet( false ),
45 mOverviewFrameMapId( -1 ), mOverviewBlendMode( QPainter::CompositionMode_SourceOver ), mOverviewInverted( false ), mOverviewCentered( false ),
46 mGridEnabled( false ), mGridStyle( Solid ),
47 mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationFontColor( QColor( 0, 0, 0 ) ),
48 mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ), mGridBlendMode( QPainter::CompositionMode_SourceOver ),
49 mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ),
50 mTopGridAnnotationPosition( OutsideMapFrame ), mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ),
51 mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ), mTopGridAnnotationDirection( Horizontal ),
52 mBottomGridAnnotationDirection( Horizontal ), mGridFrameStyle( NoGridFrame ), mGridFrameWidth( 2.0 ),
53 mGridFramePenThickness( 0.5 ), mGridFramePenColor( QColor( 0, 0, 0 ) ), mGridFrameFillColor1( Qt::white ), mGridFrameFillColor2( Qt::black ),
54 mCrossLength( 3 ), mMapCanvas( 0 ), mDrawCanvasItems( true ), mAtlasDriven( false ), mAtlasFixedScale( false ), mAtlasMargin( 0.10 )
79 QString defaultFontString = settings.value(
"/Composer/defaultFont" ).toString();
80 if ( !defaultFontString.isEmpty() )
99 setToolTip(
tr(
"Map %1" ).arg(
mId ) );
105 :
QgsComposerItem( 0, 0, 10, 10, composition ), mMapRotation( 0 ), mKeepLayerSet( false ), mOverviewFrameMapId( -1 ),
106 mOverviewBlendMode( QPainter::CompositionMode_SourceOver ), mOverviewInverted( false ), mOverviewCentered( false ),
107 mGridEnabled( false ), mGridStyle( Solid ),
108 mGridIntervalX( 0.0 ), mGridIntervalY( 0.0 ), mGridOffsetX( 0.0 ), mGridOffsetY( 0.0 ), mGridAnnotationFontColor( QColor( 0, 0, 0 ) ),
109 mGridAnnotationPrecision( 3 ), mShowGridAnnotation( false ), mGridBlendMode( QPainter::CompositionMode_SourceOver ),
110 mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ),
111 mTopGridAnnotationPosition( OutsideMapFrame ), mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ),
112 mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ), mTopGridAnnotationDirection( Horizontal ),
113 mBottomGridAnnotationDirection( Horizontal ), mGridFrameStyle( NoGridFrame ), mGridFrameWidth( 2.0 ), mGridFramePenThickness( 0.5 ),
114 mGridFramePenColor( QColor( 0, 0, 0 ) ), mGridFrameFillColor1( Qt::white ), mGridFrameFillColor2( Qt::black ),
115 mCrossLength( 3 ), mMapCanvas( 0 ), mDrawCanvasItems( true ), mAtlasDriven( false ), mAtlasFixedScale( false ), mAtlasMargin( 0.10 )
133 setToolTip(
tr(
"Map %1" ).arg(
mId ) );
140 double itemWidthHeightRatio = itemWidth / itemHeight;
141 double newWidthHeightRatio = extent.
width() / extent.
height();
143 if ( itemWidthHeightRatio <= newWidthHeightRatio )
146 double newHeight = extent.
width() / itemWidthHeightRatio;
147 double deltaHeight = newHeight - extent.
height();
154 double newWidth = itemWidthHeightRatio * extent.
height();
155 double deltaWidth = newWidth - extent.
width();
196 if ( settings.value(
"/qgis/enable_anti_aliasing",
true ).toBool() )
198 painter->setRenderHint( QPainter::Antialiasing );
202 if ( theRendererContext )
222 double bk_scale = theMapRenderer.
scale();
227 bool bkLayerCaching = s.value(
"/qgis/enable_render_caching",
false ).toBool();
228 s.setValue(
"/qgis/enable_render_caching",
false );
233 if ( forceWidthScale )
235 theMapRenderer.
render( painter, forceWidthScale );
239 theMapRenderer.
render( painter );
241 s.setValue(
"/qgis/enable_render_caching", bkLayerCaching );
243 theMapRenderer.
setScale( bk_scale );
265 if ( horizontalVScaleFactor < 0 )
286 mCacheImage = QImage( w, h, QImage::Format_ARGB32 );
297 mCacheImage.fill( QColor( 255, 255, 255, 0 ).rgba() );
307 draw( &p, requestExtent, QSizeF( w, h ),
mCacheImage.logicalDpiX(), &forcedWidthScaleFactor );
323 QRectF thisPaintRect = QRectF( 0, 0, QGraphicsRectItem::rect().width(), QGraphicsRectItem::rect().height() );
325 painter->setClipRect( thisPaintRect );
331 QFont messageFont(
"", 12 );
332 painter->setFont( messageFont );
333 painter->setPen( QColor( 0, 0, 0, 125 ) );
334 painter->drawText( thisPaintRect,
tr(
"Map will be printed here" ) );
351 double scale = rect().width() / imagePixelWidth;
365 painter->translate( xTopLeftShift, yTopLeftShift );
367 painter->translate( xShiftMM, -yShiftMM );
368 painter->scale( scale, scale );
386 QPaintDevice* thePaintDevice = painter->device();
387 if ( !thePaintDevice )
413 painter->translate( xTopLeftShift, yTopLeftShift );
415 painter->translate( xShiftMM, -yShiftMM );
416 draw( painter, requestRectangle, theSize, 25.4 );
427 painter->setClipRect( thisPaintRect , Qt::NoClip );
451 QGraphicsRectItem::update();
470 QStringList renderLayerSet;
488 if ( removeAt != -1 )
490 renderLayerSet.removeAt( removeAt );
495 return renderLayerSet;
502 calculator.
setDpi( 25.4 );
509 QRectF currentRect = rect();
510 QRectF newSceneRect = QRectF( pos().x(), pos().y(), currentRect.width() + dx, currentRect.height() + dy );
542 int zoomMode = settings.value(
"/qgis/wheel_action", 2 ).toInt();
548 double zoomFactor = settings.value(
"/qgis/zoom_factor", 2.0 ).toDouble();
564 else if ( zoomMode == 2 )
566 centerX = mapMouseX + ( centerX - mapMouseX ) * ( 1.0 / zoomFactor );
567 centerY = mapMouseY + ( centerY - mapMouseY ) * ( 1.0 / zoomFactor );
571 double newIntervalX, newIntervalY;
578 else if ( delta < 0 )
601 double w = rectangle.width();
602 double h = rectangle.height();
627 QRectF currentRect = rect();
629 double newHeight = currentRect.width() * extent.
height() / extent.
width();
631 setSceneRect( QRectF( pos().x(), pos().y(), currentRect.width(), newHeight ) );
646 double currentWidthHeightRatio = rect().
width() / rect().height();
647 double newWidthHeightRatio = newExtent.
width() / newExtent.
height();
649 if ( currentWidthHeightRatio < newWidthHeightRatio )
652 double newHeight = newExtent.
width() / currentWidthHeightRatio;
653 double deltaHeight = newHeight - newExtent.
height();
657 else if ( currentWidthHeightRatio >= newWidthHeightRatio )
660 double newWidth = currentWidthHeightRatio * newExtent.
height();
661 double deltaWidth = newWidth - newExtent.
width();
716 double currentScaleDenominator =
scale();
718 if ( scaleDenominator == currentScaleDenominator )
723 double scaleRatio = scaleDenominator / currentScaleDenominator;
776 QStringList::const_iterator layer_it = layers.constBegin();
779 for ( ; layer_it != layers.constEnd(); ++layer_it )
785 if ( currentRasterLayer )
788 if (( rasterProvider = currentRasterLayer->
dataProvider() ) )
790 if ( rasterProvider->
name() ==
"wms" )
814 QStringList::const_iterator layer_it = layers.constBegin();
817 for ( ; layer_it != layers.constEnd(); ++layer_it )
822 if ( currentLayer->
blendMode() != QPainter::CompositionMode_SourceOver )
828 if ( currentVectorLayer )
834 if ( currentVectorLayer->
featureBlendMode() != QPainter::CompositionMode_SourceOver )
843 if (( layerSettings.
blendMode != QPainter::CompositionMode_SourceOver ) ||
864 connect( layerRegistry, SIGNAL( layerWillBeRemoved( QString ) ),
this, SLOT(
updateCachedImage() ) );
876 QDomElement composerMapElem = doc.createElement(
"ComposerMap" );
877 composerMapElem.setAttribute(
"id",
mId );
882 composerMapElem.setAttribute(
"previewMode",
"Cache" );
886 composerMapElem.setAttribute(
"previewMode",
"Render" );
890 composerMapElem.setAttribute(
"previewMode",
"Rectangle" );
895 composerMapElem.setAttribute(
"keepLayerSet",
"true" );
899 composerMapElem.setAttribute(
"keepLayerSet",
"false" );
904 composerMapElem.setAttribute(
"drawCanvasItems",
"true" );
908 composerMapElem.setAttribute(
"drawCanvasItems",
"false" );
912 QDomElement overviewFrameElem = doc.createElement(
"overviewFrame" );
917 overviewFrameElem.setAttribute(
"overviewInverted",
"true" );
921 overviewFrameElem.setAttribute(
"overviewInverted",
"false" );
924 overviewFrameElem.setAttribute(
"overviewCentered",
mOverviewCentered ?
"true" :
"false" );
927 overviewFrameElem.appendChild( overviewFrameStyleElem );
928 composerMapElem.appendChild( overviewFrameElem );
932 QDomElement extentElem = doc.createElement(
"Extent" );
937 composerMapElem.appendChild( extentElem );
940 composerMapElem.setAttribute(
"mapRotation", QString::number(
mMapRotation ) );
943 QDomElement layerSetElem = doc.createElement(
"LayerSet" );
944 QStringList::const_iterator layerIt =
mLayerSet.constBegin();
945 for ( ; layerIt !=
mLayerSet.constEnd(); ++layerIt )
947 QDomElement layerElem = doc.createElement(
"Layer" );
948 QDomText layerIdText = doc.createTextNode( *layerIt );
949 layerElem.appendChild( layerIdText );
950 layerSetElem.appendChild( layerElem );
952 composerMapElem.appendChild( layerSetElem );
958 QDomElement gridElem = doc.createElement(
"Grid" );
960 gridElem.setAttribute(
"gridStyle",
mGridStyle );
970 QDomElement framePenColorElem = doc.createElement(
"framePenColor" );
975 gridElem.appendChild( framePenColorElem );
977 QDomElement frameFillColor1Elem = doc.createElement(
"frameFillColor1" );
982 gridElem.appendChild( frameFillColor1Elem );
983 QDomElement frameFillColor2Elem = doc.createElement(
"frameFillColor2" );
988 gridElem.appendChild( frameFillColor2Elem );
992 gridElem.appendChild( gridLineStyleElem );
995 QDomElement annotationElem = doc.createElement(
"Annotation" );
1010 QDomElement annotationFontColorElem = doc.createElement(
"fontColor" );
1015 annotationElem.appendChild( annotationFontColorElem );
1017 gridElem.appendChild( annotationElem );
1018 composerMapElem.appendChild( gridElem );
1021 QDomElement atlasElem = doc.createElement(
"AtlasMap" );
1025 composerMapElem.appendChild( atlasElem );
1027 elem.appendChild( composerMapElem );
1028 return _writeXML( composerMapElem, doc );
1033 if ( itemElem.isNull() )
1038 QString idRead = itemElem.attribute(
"id",
"not found" );
1039 if ( idRead !=
"not found" )
1041 mId = idRead.toInt();
1046 QString
previewMode = itemElem.attribute(
"previewMode" );
1047 if ( previewMode ==
"Cache" )
1051 else if ( previewMode ==
"Render" )
1060 QDomElement overviewFrameElem = itemElem.firstChildElement(
"overviewFrame" );
1061 if ( !overviewFrameElem.isNull() )
1066 QString overviewInvertedFlag = overviewFrameElem.attribute(
"overviewInverted" );
1067 if ( overviewInvertedFlag.compare(
"true", Qt::CaseInsensitive ) == 0 )
1076 if ( overviewFrameElem.attribute(
"overviewCentered" ).compare(
"true", Qt::CaseInsensitive ) == 0 )
1085 QDomElement overviewFrameSymbolElem = overviewFrameElem.firstChildElement(
"symbol" );
1086 if ( !overviewFrameSymbolElem.isNull() )
1094 QDomNodeList extentNodeList = itemElem.elementsByTagName(
"Extent" );
1095 if ( extentNodeList.size() > 0 )
1097 QDomElement extentElem = extentNodeList.at( 0 ).toElement();
1098 double xmin, xmax, ymin, ymax;
1099 xmin = extentElem.attribute(
"xmin" ).toDouble();
1100 xmax = extentElem.attribute(
"xmax" ).toDouble();
1101 ymin = extentElem.attribute(
"ymin" ).toDouble();
1102 ymax = extentElem.attribute(
"ymax" ).toDouble();
1108 if ( itemElem.attribute(
"mapRotation",
"0" ).toDouble() != 0 )
1110 mMapRotation = itemElem.attribute(
"mapRotation",
"0" ).toDouble();
1114 QString keepLayerSetFlag = itemElem.attribute(
"keepLayerSet" );
1115 if ( keepLayerSetFlag.compare(
"true", Qt::CaseInsensitive ) == 0 )
1124 QString drawCanvasItemsFlag = itemElem.attribute(
"drawCanvasItems" );
1125 if ( drawCanvasItemsFlag.compare(
"true", Qt::CaseInsensitive ) == 0 )
1135 QDomNodeList layerSetNodeList = itemElem.elementsByTagName(
"LayerSet" );
1137 if ( layerSetNodeList.size() > 0 )
1139 QDomElement layerSetElem = layerSetNodeList.at( 0 ).toElement();
1140 QDomNodeList layerIdNodeList = layerSetElem.elementsByTagName(
"Layer" );
1141 for (
int i = 0; i < layerIdNodeList.size(); ++i )
1143 layerSet << layerIdNodeList.at( i ).toElement().text();
1153 QDomNodeList gridNodeList = itemElem.elementsByTagName(
"Grid" );
1154 if ( gridNodeList.size() > 0 )
1156 QDomElement gridElem = gridNodeList.at( 0 ).toElement();
1157 mGridEnabled = ( gridElem.attribute(
"show",
"0" ) !=
"0" );
1159 mGridIntervalX = gridElem.attribute(
"intervalX",
"0" ).toDouble();
1160 mGridIntervalY = gridElem.attribute(
"intervalY",
"0" ).toDouble();
1161 mGridOffsetX = gridElem.attribute(
"offsetX",
"0" ).toDouble();
1162 mGridOffsetY = gridElem.attribute(
"offsetY",
"0" ).toDouble();
1163 mCrossLength = gridElem.attribute(
"crossLength",
"3" ).toDouble();
1165 mGridFrameWidth = gridElem.attribute(
"gridFrameWidth",
"2.0" ).toDouble();
1169 QDomNodeList gridFramePenColorList = gridElem.elementsByTagName(
"framePenColor" );
1170 if ( gridFramePenColorList.size() > 0 )
1172 QDomElement penColorElem = gridFramePenColorList.at( 0 ).toElement();
1173 int red = penColorElem.attribute(
"red",
"0" ).toInt();
1174 int green = penColorElem.attribute(
"green",
"0" ).toInt();
1175 int blue = penColorElem.attribute(
"blue",
"0" ).toInt();
1176 int alpha = penColorElem.attribute(
"alpha",
"255" ).toInt();
1184 QDomNodeList gridFrameFillColor1List = gridElem.elementsByTagName(
"frameFillColor1" );
1185 if ( gridFrameFillColor1List.size() > 0 )
1187 QDomElement fillColorElem = gridFrameFillColor1List.at( 0 ).toElement();
1188 int red = fillColorElem.attribute(
"red",
"0" ).toInt();
1189 int green = fillColorElem.attribute(
"green",
"0" ).toInt();
1190 int blue = fillColorElem.attribute(
"blue",
"0" ).toInt();
1191 int alpha = fillColorElem.attribute(
"alpha",
"255" ).toInt();
1199 QDomNodeList gridFrameFillColor2List = gridElem.elementsByTagName(
"frameFillColor2" );
1200 if ( gridFrameFillColor2List.size() > 0 )
1202 QDomElement fillColorElem = gridFrameFillColor2List.at( 0 ).toElement();
1203 int red = fillColorElem.attribute(
"red",
"0" ).toInt();
1204 int green = fillColorElem.attribute(
"green",
"0" ).toInt();
1205 int blue = fillColorElem.attribute(
"blue",
"0" ).toInt();
1206 int alpha = fillColorElem.attribute(
"alpha",
"255" ).toInt();
1216 QDomElement gridSymbolElem = gridElem.firstChildElement(
"symbol" );
1218 if ( gridSymbolElem.isNull( ) )
1224 gridElem.attribute(
"penColorGreen",
"0" ).toInt(),
1225 gridElem.attribute(
"penColorBlue",
"0" ).toInt() ) );
1232 QDomNodeList annotationNodeList = gridElem.elementsByTagName(
"Annotation" );
1233 if ( annotationNodeList.size() > 0 )
1235 QDomElement annotationElem = annotationNodeList.at( 0 ).toElement();
1250 QDomNodeList annotationFontColorList = annotationElem.elementsByTagName(
"fontColor" );
1251 if ( annotationFontColorList.size() > 0 )
1253 QDomElement fontColorElem = annotationFontColorList.at( 0 ).toElement();
1254 int red = fontColorElem.attribute(
"red",
"0" ).toInt();
1255 int green = fontColorElem.attribute(
"green",
"0" ).toInt();
1256 int blue = fontColorElem.attribute(
"blue",
"0" ).toInt();
1257 int alpha = fontColorElem.attribute(
"alpha",
"255" ).toInt();
1270 QDomNodeList atlasNodeList = itemElem.elementsByTagName(
"AtlasMap" );
1271 if ( atlasNodeList.size() > 0 )
1273 QDomElement atlasElem = atlasNodeList.at( 0 ).toElement();
1274 mAtlasDriven = ( atlasElem.attribute(
"atlasDriven",
"0" ) !=
"0" );
1276 mAtlasMargin = atlasElem.attribute(
"margin",
"0.1" ).toDouble();
1280 QDomNodeList composerItemList = itemElem.elementsByTagName(
"ComposerItem" );
1281 if ( composerItemList.size() > 0 )
1283 QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
1285 if ( composerItemElem.attribute(
"rotation",
"0" ).toDouble() != 0 )
1288 mMapRotation = composerItemElem.attribute(
"rotation",
"0" ).toDouble();
1315 QStringList currentLayerSet;
1325 for (
int i =
mLayerSet.size() - 1; i >= 0; --i )
1327 if ( !currentLayerSet.contains(
mLayerSet.at( i ) ) )
1336 QList< QPair< double, QLineF > > verticalLines;
1338 QList< QPair< double, QLineF > >::const_iterator vIt = verticalLines.constBegin();
1339 QList< QPair< double, QLineF > > horizontalLines;
1341 QList< QPair< double, QLineF > >::const_iterator hIt = horizontalLines.constBegin();
1343 QRectF thisPaintRect = QRectF( 0, 0, QGraphicsRectItem::rect().width(), QGraphicsRectItem::rect().height() );
1344 p->setClipRect( thisPaintRect );
1353 for ( ; vIt != verticalLines.constEnd(); ++vIt )
1358 for ( ; hIt != horizontalLines.constEnd(); ++hIt )
1365 QPointF intersectionPoint, crossEnd1, crossEnd2;
1366 for ( ; vIt != verticalLines.constEnd(); ++vIt )
1370 drawGridLine( QLineF( vIt->second.p1(), crossEnd1 ), p );
1373 hIt = horizontalLines.constBegin();
1374 for ( ; hIt != horizontalLines.constEnd(); ++hIt )
1376 if ( hIt->second.intersect( vIt->second, &intersectionPoint ) == QLineF::BoundedIntersection )
1385 drawGridLine( QLineF( vIt->second.p2(), crossEnd2 ), p );
1388 hIt = horizontalLines.constBegin();
1389 for ( ; hIt != horizontalLines.constEnd(); ++hIt )
1393 drawGridLine( QLineF( hIt->second.p1(), crossEnd1 ), p );
1395 vIt = verticalLines.constBegin();
1396 for ( ; vIt != verticalLines.constEnd(); ++vIt )
1398 if ( vIt->second.intersect( hIt->second, &intersectionPoint ) == QLineF::BoundedIntersection )
1407 drawGridLine( QLineF( hIt->second.p2(), crossEnd1 ), p );
1413 p->setClipRect( thisPaintRect , Qt::NoClip );
1430 QMap< double, double > leftGridFrame;
1431 QMap< double, double > rightGridFrame;
1432 QMap< double, double > topGridFrame;
1433 QMap< double, double > bottomGridFrame;
1464 poly << line.p1() << line.p2();
1479 QMap< double, double > pos = borderPos;
1481 if ( border ==
Left || border ==
Right )
1483 pos.insert( rect().height(), rect().height() );
1488 pos.insert( rect().width(), rect().width() );
1495 framePen.setJoinStyle( Qt::MiterJoin );
1496 p->setPen( framePen );
1498 QMap< double, double >::const_iterator posIt = pos.constBegin();
1499 for ( ; posIt != pos.constEnd(); ++posIt )
1502 if ( border ==
Left || border ==
Right )
1504 height = posIt.key() - currentCoord;
1512 width = posIt.key() - currentCoord;
1516 p->drawRect( QRectF( x, y, width, height ) );
1517 currentCoord = posIt.key();
1530 QString currentAnnotationString;
1531 QList< QPair< double, QLineF > >::const_iterator it = hLines.constBegin();
1532 for ( ; it != hLines.constEnd(); ++it )
1539 it = vLines.constBegin();
1540 for ( ; it != vLines.constEnd(); ++it )
1554 double xpos = pos.x();
1555 double ypos = pos.y();
1560 if ( frameBorder ==
Left )
1568 ypos += textWidth / 2.0;
1574 ypos += textHeight / 2.0;
1582 ypos += textWidth / 2.0;
1588 ypos += textHeight / 2.0;
1597 else if ( frameBorder ==
Right )
1604 ypos += textWidth / 2.0;
1610 ypos += textHeight / 2.0;
1618 ypos += textWidth / 2.0;
1624 ypos += textHeight / 2.0;
1632 else if ( frameBorder ==
Bottom )
1639 xpos -= textWidth / 2.0;
1643 xpos += textHeight / 2.0;
1653 xpos -= textWidth / 2.0;
1657 xpos += textHeight / 2.0;
1673 xpos -= textWidth / 2.0;
1678 xpos += textHeight / 2.0;
1687 xpos -= textWidth / 2.0;
1692 xpos += textHeight / 2.0;
1703 drawAnnotation( p, QPointF( xpos, ypos ), rotation, annotationString );
1709 p->translate( pos );
1710 p->rotate( rotation );
1727 QString annotationString;
1737 QStringList split = annotationString.split(
"," );
1740 return split.at( 0 );
1744 if ( split.size() < 2 )
1748 return split.at( 1 );
1762 QRectF mapBoundingRect = mapPolygon.boundingRect();
1765 double roundCorrection = mapBoundingRect.top() > 0 ? 1.0 : 0.0;
1772 double yCanvasCoord;
1774 while ( currentLevel <= mapBoundingRect.bottom() )
1776 yCanvasCoord = rect().height() * ( 1 - ( currentLevel - mapBoundingRect.top() ) / mapBoundingRect.height() );
1777 lines.push_back( qMakePair( currentLevel, QLineF( 0, yCanvasCoord, rect().width(), yCanvasCoord ) ) );
1783 QVector<QLineF> borderLines;
1784 borderLines << QLineF( mapPolygon.at( 0 ), mapPolygon.at( 1 ) );
1785 borderLines << QLineF( mapPolygon.at( 1 ), mapPolygon.at( 2 ) );
1786 borderLines << QLineF( mapPolygon.at( 2 ), mapPolygon.at( 3 ) );
1787 borderLines << QLineF( mapPolygon.at( 3 ), mapPolygon.at( 0 ) );
1789 QList<QPointF> intersectionList;
1791 while ( currentLevel <= mapBoundingRect.bottom() )
1793 intersectionList.clear();
1794 QLineF gridLine( mapBoundingRect.left(), currentLevel, mapBoundingRect.right(), currentLevel );
1796 QVector<QLineF>::const_iterator it = borderLines.constBegin();
1797 for ( ; it != borderLines.constEnd(); ++it )
1799 QPointF intersectionPoint;
1800 if ( it->intersect( gridLine, &intersectionPoint ) == QLineF::BoundedIntersection )
1802 intersectionList.push_back( intersectionPoint );
1803 if ( intersectionList.size() >= 2 )
1810 if ( intersectionList.size() >= 2 )
1812 lines.push_back( qMakePair( currentLevel, QLineF(
mapToItemCoords( intersectionList.at( 0 ) ),
mapToItemCoords( intersectionList.at( 1 ) ) ) ) );
1830 QRectF mapBoundingRect = mapPolygon.boundingRect();
1833 double roundCorrection = mapBoundingRect.left() > 0 ? 1.0 : 0.0;
1839 double xCanvasCoord;
1841 while ( currentLevel <= mapBoundingRect.right() )
1843 xCanvasCoord = rect().width() * ( currentLevel - mapBoundingRect.left() ) / mapBoundingRect.width();
1844 lines.push_back( qMakePair( currentLevel, QLineF( xCanvasCoord, 0, xCanvasCoord, rect().height() ) ) );
1850 QVector<QLineF> borderLines;
1851 borderLines << QLineF( mapPolygon.at( 0 ), mapPolygon.at( 1 ) );
1852 borderLines << QLineF( mapPolygon.at( 1 ), mapPolygon.at( 2 ) );
1853 borderLines << QLineF( mapPolygon.at( 2 ), mapPolygon.at( 3 ) );
1854 borderLines << QLineF( mapPolygon.at( 3 ), mapPolygon.at( 0 ) );
1856 QList<QPointF> intersectionList;
1858 while ( currentLevel <= mapBoundingRect.right() )
1860 intersectionList.clear();
1861 QLineF gridLine( currentLevel, mapBoundingRect.bottom(), currentLevel, mapBoundingRect.top() );
1863 QVector<QLineF>::const_iterator it = borderLines.constBegin();
1864 for ( ; it != borderLines.constEnd(); ++it )
1866 QPointF intersectionPoint;
1867 if ( it->intersect( gridLine, &intersectionPoint ) == QLineF::BoundedIntersection )
1869 intersectionList.push_back( intersectionPoint );
1870 if ( intersectionList.size() >= 2 )
1877 if ( intersectionList.size() >= 2 )
1879 lines.push_back( qMakePair( currentLevel, QLineF(
mapToItemCoords( intersectionList.at( 0 ) ),
mapToItemCoords( intersectionList.at( 1 ) ) ) ) );
1916 p.setCapStyle( Qt::FlatCap );
1934 QRectF rectangle = rect();
1936 rectangle.setLeft( rectangle.left() - extension );
1937 rectangle.setRight( rectangle.right() + extension );
1938 rectangle.setTop( rectangle.top() - extension );
1939 rectangle.setBottom( rectangle.bottom() + extension );
1942 prepareGeometryChange();
1974 poly.translate( -dx, -dy );
1980 double frameExtension =
mFrame ? pen().widthF() / 2.0 : 0.0;
1984 return frameExtension;
1987 QList< QPair< double, QLineF > > xLines;
1988 QList< QPair< double, QLineF > > yLines;
1993 if ( xGridReturn != 0 && yGridReturn != 0 )
1995 return frameExtension;
1999 double currentExtension = 0;
2000 QString currentAnnotationString;
2002 QList< QPair< double, QLineF > >::const_iterator it = xLines.constBegin();
2003 for ( ; it != xLines.constEnd(); ++it )
2007 maxExtension = qMax( maxExtension, currentExtension );
2010 it = yLines.constBegin();
2011 for ( ; it != yLines.constEnd(); ++it )
2015 maxExtension = qMax( maxExtension, currentExtension );
2040 dx = rotationPoint.
x() - extent.
xMinimum();
2041 dy = rotationPoint.
y() - extent.
yMaximum();
2043 poly << QPointF( rotationPoint.
x() + dx, rotationPoint.
y() + dy );
2046 dx = rotationPoint.
x() - extent.
xMaximum();
2047 dy = rotationPoint.
y() - extent.
yMaximum();
2049 poly << QPointF( rotationPoint.
x() + dx, rotationPoint.
y() + dy );
2052 dx = rotationPoint.
x() - extent.
xMaximum();
2053 dy = rotationPoint.
y() - extent.
yMinimum();
2055 poly << QPointF( rotationPoint.
x() + dx, rotationPoint.
y() + dy );
2058 dx = rotationPoint.
x() - extent.
xMinimum();
2059 dy = rotationPoint.
y() - extent.
yMinimum();
2061 poly << QPointF( rotationPoint.
x() + dx, rotationPoint.
y() + dy );
2080 QRectF bRect = poly.boundingRect();
2091 if ( extentWidth <= 0 )
2095 return rect().width() / extentWidth;
2180 double dxScaled = xShift * mmToMapUnits;
2181 double dyScaled = - yShift * mmToMapUnits;
2192 if ( mapPoly.size() < 1 )
2194 return QPointF( 0, 0 );
2199 double dx = mapCoords.x() - rotationPoint.
x();
2200 double dy = mapCoords.y() - rotationPoint.
y();
2202 QgsPoint backRotatedCoords( rotationPoint.
x() + dx, rotationPoint.
y() + dy );
2205 double xItem = rect().width() * ( backRotatedCoords.x() - unrotatedExtent.xMinimum() ) / unrotatedExtent.width();
2206 double yItem = rect().height() * ( 1 - ( backRotatedCoords.y() - unrotatedExtent.yMinimum() ) / unrotatedExtent.height() );
2207 return QPointF( xItem, yItem );
2212 if ( p.x() <= pen().widthF() )
2216 else if ( p.x() >= ( rect().width() - pen().widthF() ) )
2220 else if ( p.y() <= pen().widthF() )
2237 QList<QGraphicsItem*> itemList =
mMapCanvas->items();
2238 if ( itemList.size() < 1 )
2242 QGraphicsItem* currentItem = 0;
2244 for (
int i = itemList.size() - 1; i >= 0; --i )
2246 currentItem = itemList.at( i );
2248 if ( !currentItem || currentItem->data( 0 ).toString() !=
"AnnotationItem" )
2269 double scaleFactor = 1.0 /
mMapCanvas->logicalDpiX() * 25.4;
2271 double itemX, itemY;
2272 QGraphicsItem* parent = item->parentItem();
2281 QPointF itemScenePos = item->scenePos();
2282 QPointF parentScenePos = parent->scenePos();
2286 itemX = mapPos.x() + ( itemScenePos.x() - parentScenePos.x() ) * scaleFactor;
2287 itemY = mapPos.y() + ( itemScenePos.y() - parentScenePos.y() ) * scaleFactor;
2289 painter->translate( itemX, itemY );
2292 painter->scale( scaleFactor, scaleFactor );
2295 item->setData( 1,
"composer" );
2296 item->paint( painter, itemStyle, 0 );
2297 item->setData( 1,
"" );
2305 return QPointF( 0, 0 );
2310 return QPointF( 0, 0 );
2313 QRectF graphicsSceneRect =
mMapCanvas->sceneRect();
2314 QPointF itemScenePos = item->scenePos();
2317 double mapX = itemScenePos.x() / graphicsSceneRect.
width() * mapRendererExtent.
width() + mapRendererExtent.
xMinimum();
2318 double mapY = mapRendererExtent.
yMaximum() - itemScenePos.y() / graphicsSceneRect.height() * mapRendererExtent.
height();
2410 QMap< double, double >& rightFrameEntries, QMap< double, double >& topFrameEntries, QMap< double, double >& bottomFrameEntries )
const
2412 QList< QPair< double, QPointF > > borderPositions;
2413 QList< QPair< double, QLineF > >::const_iterator it = hLines.constBegin();
2414 for ( ; it != hLines.constEnd(); ++it )
2416 borderPositions << qMakePair( it->first, it->second.p1() );
2417 borderPositions << qMakePair( it->first, it->second.p2() );
2419 it = vLines.constBegin();
2420 for ( ; it != vLines.constEnd(); ++it )
2422 borderPositions << qMakePair( it->first, it->second.p1() );
2423 borderPositions << qMakePair( it->first, it->second.p2() );
2426 QList< QPair< double, QPointF > >::const_iterator bIt = borderPositions.constBegin();
2427 for ( ; bIt != borderPositions.constEnd(); ++bIt )
2432 leftFrameEntries.insert( bIt->second.y(), bIt->first );
2436 rightFrameEntries.insert( bIt->second.y(), bIt->first );
2440 topFrameEntries.insert( bIt->second.x(), bIt->first );
2444 bottomFrameEntries.insert( bIt->second.x(), bIt->first );
2464 if ( !overviewFrameMap )
2484 QPolygonF intersectPolygon;
2485 double x = ( intersectRect.
xMinimum() - thisExtent.
xMinimum() ) / thisExtent.
width() * rect().width();
2487 double width = intersectRect.
width() / thisExtent.
width() * rect().width();
2488 double height = intersectRect.
height() / thisExtent.
height() * rect().height();
2489 intersectPolygon << QPointF( x, y ) << QPointF( x + width, y ) << QPointF( x + width, y + height ) << QPointF( x, y + height ) << QPointF( x, y );
2491 QList<QPolygonF> rings;
2501 QPolygonF outerPolygon;
2502 outerPolygon << QPointF( 0, 0 ) << QPointF( rect().width(), 0 ) << QPointF( rect().width(), rect().height() ) << QPointF( 0, rect().height() ) << QPointF( 0, 0 );
2505 rings.append( intersectPolygon );
2517 properties.insert(
"color",
"255,0,0,255" );
2518 properties.insert(
"style",
"solid" );
2519 properties.insert(
"style_border",
"no" );
2528 properties.insert(
"color",
"0,0,0,255" );
2529 properties.insert(
"width",
"0.3" );
2530 properties.insert(
"capstyle",
"flat" );
2538 bool degreeUnits =
true;
2544 if ( format ==
"DM" && degreeUnits )
2548 else if ( format ==
"DMS" && degreeUnits )
2573 QList<const QgsComposerMap*>::const_iterator mapIt = mapList.constBegin();
2574 for ( ; mapIt != mapList.constEnd(); ++mapIt )
2576 if (( *mapIt )->id() > maxId )
2578 maxId = ( *mapIt )->id();