41 #include <QGraphicsScene>
42 #include <QGraphicsView>
52 , mEvaluatedMapRotation( 0 )
53 , mKeepLayerSet( false )
54 , mKeepLayerStyles( false )
55 , mUpdatesEnabled( true )
57 , mDrawCanvasItems( true )
58 , mAtlasDriven( false )
59 , mAtlasScalingMode( Auto )
60 , mAtlasMargin( 0.10 )
68 mCurrentRectangle = rect();
71 mCacheUpdated =
false;
97 , mEvaluatedMapRotation( 0 )
98 , mKeepLayerSet( false )
99 , mKeepLayerStyles( false )
100 , mUpdatesEnabled( true )
102 , mDrawCanvasItems( true )
103 , mAtlasDriven( false )
104 , mAtlasScalingMode( Auto )
105 , mAtlasMargin( 0.10 )
114 mCurrentRectangle = rect();
120 void QgsComposerMap::init()
136 void QgsComposerMap::updateToolTip()
138 setToolTip(
tr(
"Map %1" ).arg( mId ) );
141 void QgsComposerMap::adjustExtentToItemShape(
double itemWidth,
double itemHeight,
QgsRectangle& extent )
const
143 double itemWidthHeightRatio = itemWidth / itemHeight;
144 double newWidthHeightRatio = extent.
width() / extent.
height();
146 if ( itemWidthHeightRatio <= newWidthHeightRatio )
149 double newHeight = extent.
width() / itemWidthHeightRatio;
150 double deltaHeight = newHeight - extent.
height();
157 double newWidth = itemWidthHeightRatio * extent.
height();
158 double deltaWidth = newWidth - extent.
width();
166 delete mOverviewStack;
174 Q_UNUSED( forceWidthScale );
180 if ( size.width() == 0 || size.height() == 0 )
205 jobMapSettings.
setRotation( mEvaluatedMapRotation );
208 QStringList theLayerSet = layersToRender();
214 ( layerIdx >= 0 && layerIdx < theLayerSet.length() )
215 ? QStringList( theLayerSet[ theLayerSet.length() - layerIdx - 1 ] )
242 return jobMapSettings;
260 if ( horizontalVScaleFactor < 0 )
270 int w = widthMM * horizontalVScaleFactor;
271 int h = heightMM * horizontalVScaleFactor;
274 if ( w > 5000 || h > 5000 )
279 h = w * heightMM / widthMM;
284 w = h * widthMM / heightMM;
288 mCacheImage = QImage( w, h, QImage::Format_ARGB32 );
291 mCacheImage.setDotsPerMeterX( 1000 * w / widthMM );
292 mCacheImage.setDotsPerMeterY( 1000 * h / heightMM );
303 mCacheImage.fill( QColor( 255, 255, 255, 0 ).rgba() );
306 QPainter p( &mCacheImage );
308 draw( &p, ext, QSizeF( w, h ), mCacheImage.logicalDpiX() );
310 mCacheUpdated =
true;
328 QRectF thisPaintRect = QRectF( 0, 0, QGraphicsRectItem::rect().width(), QGraphicsRectItem::rect().height() );
330 painter->setClipRect( thisPaintRect );
336 QFont messageFont(
"", 12 );
337 painter->setFont( messageFont );
338 painter->setPen( QColor( 0, 0, 0, 125 ) );
339 painter->drawText( thisPaintRect,
tr(
"Map will be printed here" ) );
350 double imagePixelWidth = mCacheImage.width();
351 double scale = rect().width() / imagePixelWidth;
355 painter->translate( mXOffset, mYOffset );
356 painter->scale( scale, scale );
357 painter->drawImage( 0, 0, mCacheImage );
374 QPaintDevice* thePaintDevice = painter->device();
375 if ( !thePaintDevice )
381 if ( shouldDrawPart( Background ) )
391 painter->translate( mXOffset, mYOffset );
393 double dotsPerMM = thePaintDevice->logicalDpiX() / 25.4;
394 theSize *= dotsPerMM;
395 painter->scale( 1 / dotsPerMM, 1 / dotsPerMM );
396 draw( painter, cExtent, theSize, thePaintDevice->logicalDpiX() );
407 painter->setClipRect( thisPaintRect, Qt::NoClip );
408 if ( shouldDrawPart( OverviewMapExtent ) &&
413 if ( shouldDrawPart( Grid ) &&
418 if ( shouldDrawPart( Frame ) )
422 if ( isSelected() && shouldDrawPart( SelectionBoxes ) )
434 + layersToRender().length()
438 + ( isSelected() ? 1 : 0 )
442 bool QgsComposerMap::shouldDrawPart( PartType part )
const
454 if ( SelectionBoxes == part )
469 if ( OverviewMapExtent == part )
480 if ( Background == part )
492 mCacheUpdated =
false;
494 QGraphicsRectItem::update();
499 if ( mPreviewMode ==
Render )
517 QStringList QgsComposerMap::layersToRender()
const
520 QStringList renderLayerSet;
523 renderLayerSet = mLayerSet;
538 if ( removeAt != -1 )
540 renderLayerSet.removeAt( removeAt );
545 return renderLayerSet;
552 calculator.
setDpi( 25.4 );
559 QRectF currentRect = rect();
560 QRectF newSceneRect = QRectF( pos().x(), pos().y(), currentRect.width() + dx, currentRect.height() + dy );
569 transformShift( dx, dy );
597 double zoomFactor = settings.value(
"/qgis/zoom_factor", 2.0 ).toDouble();
598 zoomFactor = delta > 0 ? zoomFactor : 1 / zoomFactor;
600 zoomContent( zoomFactor, QPointF( x, y ), zoomMode );
633 centerX = mapX + ( centerX - mapX ) * ( 1.0 / factor );
634 centerY = mapY + ( centerY - mapY ) * ( 1.0 / factor );
638 double newIntervalX, newIntervalY;
662 calculator.
setDpi( 25.4 );
663 double scaleRatio =
scale() / calculator.
calculate( mExtent, rect().width() );
664 mExtent.
scale( scaleRatio );
678 double w = rectangle.width();
679 double h = rectangle.height();
685 double newHeight = mExtent.
width() * h / w;
690 mCacheUpdated =
false;
710 QRectF currentRect = rect();
714 setSceneRect( QRectF( pos().x(), pos().y(), currentRect.width(), newHeight ) );
724 double newWidthHeightRatio = newExtent.
width() / newExtent.
height();
726 if ( currentWidthHeightRatio < newWidthHeightRatio )
729 double newHeight = newExtent.
width() / currentWidthHeightRatio;
730 double deltaHeight = newHeight - newExtent.
height();
737 double newWidth = currentWidthHeightRatio * newExtent.
height();
738 double deltaWidth = newWidth - newExtent.
width();
752 mCacheUpdated =
false;
760 if ( mAtlasFeatureExtent != extent )
766 double currentWidthHeightRatio = rect().
width() / rect().height();
767 double newWidthHeightRatio = newExtent.
width() / newExtent.
height();
769 if ( currentWidthHeightRatio < newWidthHeightRatio )
772 double newHeight = newExtent.
width() / currentWidthHeightRatio;
773 double deltaHeight = newHeight - newExtent.
height();
777 else if ( currentWidthHeightRatio >= newWidthHeightRatio )
780 double newWidth = currentWidthHeightRatio * newExtent.
height();
781 double deltaWidth = newWidth - newExtent.
width();
786 mAtlasFeatureExtent = newExtent;
792 mCacheUpdated =
false;
806 return &mAtlasFeatureExtent;
822 return &mAtlasFeatureExtent;
833 double currentScaleDenominator =
scale();
835 if ( scaleDenominator == currentScaleDenominator || scaleDenominator == 0 )
840 double scaleRatio = scaleDenominator / currentScaleDenominator;
850 calculator.
setDpi( 25.4 );
851 scaleRatio = scaleDenominator / calculator.
calculate( mExtent, rect().width() );
852 mExtent.
scale( scaleRatio );
855 mCacheUpdated =
false;
886 mEvaluatedMapRotation = mMapRotation;
897 void QgsComposerMap::refreshMapExtents()
903 bool useDdXMin =
false;
904 bool useDdXMax =
false;
905 bool useDdYMin =
false;
906 bool useDdYMax =
false;
915 minXD = exprVal.toDouble( &ok );
916 QgsDebugMsg( QString(
"exprVal Map XMin:%1" ).arg( minXD ) );
917 if ( ok && !exprVal.isNull() )
926 minYD = exprVal.toDouble( &ok );
927 QgsDebugMsg( QString(
"exprVal Map YMin:%1" ).arg( minYD ) );
928 if ( ok && !exprVal.isNull() )
937 maxXD = exprVal.toDouble( &ok );
938 QgsDebugMsg( QString(
"exprVal Map XMax:%1" ).arg( maxXD ) );
939 if ( ok && !exprVal.isNull() )
948 maxYD = exprVal.toDouble( &ok );
949 QgsDebugMsg( QString(
"exprVal Map YMax:%1" ).arg( maxYD ) );
950 if ( ok && !exprVal.isNull() )
964 double newWidthHeightRatio = newExtent.
width() / newExtent.
height();
966 if ( currentWidthHeightRatio < newWidthHeightRatio )
969 double newHeight = newExtent.
width() / currentWidthHeightRatio;
970 double deltaHeight = newHeight - newExtent.
height();
977 double newWidth = currentWidthHeightRatio * newExtent.
height();
978 double deltaWidth = newWidth - newExtent.
width();
992 double scaleD = exprVal.toDouble( &ok );
993 QgsDebugMsg( QString(
"exprVal Map Scale:%1" ).arg( scaleD ) );
994 if ( ok && !exprVal.isNull() )
1001 if ( useDdXMax || useDdXMin || useDdYMax || useDdYMin )
1005 if ( useDdXMin && !useDdXMax )
1011 else if ( !useDdXMin && useDdXMax )
1017 if ( useDdYMin && !useDdYMax )
1023 else if ( !useDdYMin && useDdYMax )
1043 double rotationD = exprVal.toDouble( &ok );
1044 QgsDebugMsg( QString(
"exprVal Map Rotation:%1" ).arg( rotationD ) );
1045 if ( ok && !exprVal.isNull() )
1047 mapRotation = rotationD;
1051 if ( mEvaluatedMapRotation != mapRotation )
1061 if ( !mUpdatesEnabled )
1077 QStringList::const_iterator layer_it = layers.constBegin();
1080 for ( ; layer_it != layers.constEnd(); ++layer_it )
1086 if ( currentRasterLayer )
1089 if (( rasterProvider = currentRasterLayer->
dataProvider() ) )
1091 if ( rasterProvider->
name() ==
"wms" )
1122 QStringList::const_iterator layer_it = layers.constBegin();
1125 for ( ; layer_it != layers.constEnd(); ++layer_it )
1130 if ( currentLayer->
blendMode() != QPainter::CompositionMode_SourceOver )
1136 if ( currentVectorLayer )
1142 if ( currentVectorLayer->
featureBlendMode() != QPainter::CompositionMode_SourceOver )
1151 if (( layerSettings.
blendMode != QPainter::CompositionMode_SourceOver ) ||
1166 void QgsComposerMap::connectUpdateSlot()
1170 if ( layerRegistry )
1172 connect( layerRegistry, SIGNAL( layerWillBeRemoved( QString ) ),
this, SLOT(
updateCachedImage() ) );
1179 if ( elem.isNull() )
1184 QDomElement composerMapElem = doc.createElement(
"ComposerMap" );
1185 composerMapElem.setAttribute(
"id", mId );
1188 if ( mPreviewMode ==
Cache )
1190 composerMapElem.setAttribute(
"previewMode",
"Cache" );
1192 else if ( mPreviewMode ==
Render )
1194 composerMapElem.setAttribute(
"previewMode",
"Render" );
1198 composerMapElem.setAttribute(
"previewMode",
"Rectangle" );
1201 if ( mKeepLayerSet )
1203 composerMapElem.setAttribute(
"keepLayerSet",
"true" );
1207 composerMapElem.setAttribute(
"keepLayerSet",
"false" );
1210 if ( mDrawCanvasItems )
1212 composerMapElem.setAttribute(
"drawCanvasItems",
"true" );
1216 composerMapElem.setAttribute(
"drawCanvasItems",
"false" );
1220 QDomElement extentElem = doc.createElement(
"Extent" );
1225 composerMapElem.appendChild( extentElem );
1228 composerMapElem.setAttribute(
"mapRotation", QString::number( mMapRotation ) );
1231 QDomElement layerSetElem = doc.createElement(
"LayerSet" );
1232 QStringList::const_iterator layerIt = mLayerSet.constBegin();
1233 for ( ; layerIt != mLayerSet.constEnd(); ++layerIt )
1235 QDomElement layerElem = doc.createElement(
"Layer" );
1236 QDomText layerIdText = doc.createTextNode( *layerIt );
1237 layerElem.appendChild( layerIdText );
1238 layerSetElem.appendChild( layerElem );
1240 composerMapElem.appendChild( layerSetElem );
1243 if ( mKeepLayerStyles )
1245 QDomElement stylesElem = doc.createElement(
"LayerStyles" );
1246 QMap<QString, QString>::const_iterator styleIt = mLayerStyleOverrides.constBegin();
1247 for ( ; styleIt != mLayerStyleOverrides.constEnd(); ++styleIt )
1249 QDomElement styleElem = doc.createElement(
"LayerStyle" );
1250 styleElem.setAttribute(
"layerid", styleIt.key() );
1253 stylesElem.appendChild( styleElem );
1255 composerMapElem.appendChild( stylesElem );
1259 QDomElement gridElem = doc.createElement(
"Grid" );
1260 composerMapElem.appendChild( gridElem );
1263 mGridStack->
writeXML( composerMapElem, doc );
1266 mOverviewStack->
writeXML( composerMapElem, doc );
1269 QDomElement atlasElem = doc.createElement(
"AtlasMap" );
1270 atlasElem.setAttribute(
"atlasDriven", mAtlasDriven );
1271 atlasElem.setAttribute(
"scalingMode", mAtlasScalingMode );
1273 composerMapElem.appendChild( atlasElem );
1275 elem.appendChild( composerMapElem );
1276 return _writeXML( composerMapElem, doc );
1281 if ( itemElem.isNull() )
1286 QString idRead = itemElem.attribute(
"id",
"not found" );
1287 if ( idRead !=
"not found" )
1289 mId = idRead.toInt();
1295 QString
previewMode = itemElem.attribute(
"previewMode" );
1296 if ( previewMode ==
"Cache" )
1298 mPreviewMode =
Cache;
1300 else if ( previewMode ==
"Render" )
1310 QDomNodeList extentNodeList = itemElem.elementsByTagName(
"Extent" );
1311 if ( extentNodeList.size() > 0 )
1313 QDomElement extentElem = extentNodeList.at( 0 ).toElement();
1314 double xmin, xmax, ymin, ymax;
1315 xmin = extentElem.attribute(
"xmin" ).toDouble();
1316 xmax = extentElem.attribute(
"xmax" ).toDouble();
1317 ymin = extentElem.attribute(
"ymin" ).toDouble();
1318 ymax = extentElem.attribute(
"ymax" ).toDouble();
1323 if ( itemElem.attribute(
"mapRotation",
"0" ).toDouble() != 0 )
1325 mMapRotation = itemElem.attribute(
"mapRotation",
"0" ).toDouble();
1329 QString keepLayerSetFlag = itemElem.attribute(
"keepLayerSet" );
1330 if ( keepLayerSetFlag.compare(
"true", Qt::CaseInsensitive ) == 0 )
1332 mKeepLayerSet =
true;
1336 mKeepLayerSet =
false;
1339 QString drawCanvasItemsFlag = itemElem.attribute(
"drawCanvasItems",
"true" );
1340 if ( drawCanvasItemsFlag.compare(
"true", Qt::CaseInsensitive ) == 0 )
1342 mDrawCanvasItems =
true;
1346 mDrawCanvasItems =
false;
1349 mLayerStyleOverrides.clear();
1352 QDomNodeList layerSetNodeList = itemElem.elementsByTagName(
"LayerSet" );
1354 if ( layerSetNodeList.size() > 0 )
1356 QDomElement layerSetElem = layerSetNodeList.at( 0 ).toElement();
1357 QDomNodeList layerIdNodeList = layerSetElem.elementsByTagName(
"Layer" );
1358 for (
int i = 0; i < layerIdNodeList.size(); ++i )
1360 const QDomElement& layerIdElement = layerIdNodeList.at( i ).toElement();
1361 layerSet << layerIdElement.text();
1367 QDomNodeList layerStylesNodeList = itemElem.elementsByTagName(
"LayerStyles" );
1368 mKeepLayerStyles = layerStylesNodeList.size() > 0;
1369 if ( mKeepLayerStyles )
1371 QDomElement layerStylesElem = layerStylesNodeList.at( 0 ).toElement();
1372 QDomNodeList layerStyleNodeList = layerStylesElem.elementsByTagName(
"LayerStyle" );
1373 for (
int i = 0; i < layerStyleNodeList.size(); ++i )
1375 const QDomElement& layerStyleElement = layerStyleNodeList.at( i ).toElement();
1376 QString layerId = layerStyleElement.attribute(
"layerid" );
1378 style.
readXml( layerStyleElement );
1379 mLayerStyleOverrides.insert( layerId, style.
xmlData() );
1384 mNumCachedLayers = 0;
1385 mCacheUpdated =
false;
1388 mOverviewStack->
readXML( itemElem, doc );
1391 mGridStack->
readXML( itemElem, doc );
1396 QDomNodeList gridNodeList = itemElem.elementsByTagName(
"Grid" );
1397 if ( mGridStack->
size() == 0 && gridNodeList.size() > 0 )
1399 QDomElement gridElem = gridNodeList.at( 0 ).toElement();
1401 mapGrid->
setEnabled( gridElem.attribute(
"show",
"0" ) !=
"0" );
1403 mapGrid->
setIntervalX( gridElem.attribute(
"intervalX",
"0" ).toDouble() );
1404 mapGrid->
setIntervalY( gridElem.attribute(
"intervalY",
"0" ).toDouble() );
1405 mapGrid->
setOffsetX( gridElem.attribute(
"offsetX",
"0" ).toDouble() );
1406 mapGrid->
setOffsetY( gridElem.attribute(
"offsetY",
"0" ).toDouble() );
1407 mapGrid->
setCrossLength( gridElem.attribute(
"crossLength",
"3" ).toDouble() );
1409 mapGrid->
setFrameWidth( gridElem.attribute(
"gridFrameWidth",
"2.0" ).toDouble() );
1410 mapGrid->
setFramePenSize( gridElem.attribute(
"gridFramePenThickness",
"0.5" ).toDouble() );
1415 QDomElement gridSymbolElem = gridElem.firstChildElement(
"symbol" );
1417 if ( gridSymbolElem.isNull() )
1421 lineSymbol->
setWidth( gridElem.attribute(
"penWidth",
"0" ).toDouble() );
1422 lineSymbol->
setColor( QColor( gridElem.attribute(
"penColorRed",
"0" ).toInt(),
1423 gridElem.attribute(
"penColorGreen",
"0" ).toInt(),
1424 gridElem.attribute(
"penColorBlue",
"0" ).toInt() ) );
1428 lineSymbol = QgsSymbolLayerV2Utils::loadSymbol<QgsLineSymbolV2>( gridSymbolElem );
1433 QDomNodeList annotationNodeList = gridElem.elementsByTagName(
"Annotation" );
1434 if ( annotationNodeList.size() > 0 )
1436 QDomElement annotationElem = annotationNodeList.at( 0 ).toElement();
1448 QFont annotationFont;
1449 annotationFont.fromString( annotationElem.attribute(
"font",
"" ) );
1455 mGridStack->
addGrid( mapGrid );
1459 QDomElement overviewFrameElem = itemElem.firstChildElement(
"overviewFrame" );
1460 if ( !overviewFrameElem.isNull() )
1464 mapOverview->
setFrameMap( overviewFrameElem.attribute(
"overviewFrameMap",
"-1" ).toInt() );
1466 mapOverview->
setInverted( overviewFrameElem.attribute(
"overviewInverted" ).compare(
"true", Qt::CaseInsensitive ) == 0 );
1467 mapOverview->
setCentered( overviewFrameElem.attribute(
"overviewCentered" ).compare(
"true", Qt::CaseInsensitive ) == 0 );
1470 QDomElement overviewFrameSymbolElem = overviewFrameElem.firstChildElement(
"symbol" );
1471 if ( !overviewFrameSymbolElem.isNull() )
1473 fillSymbol = QgsSymbolLayerV2Utils::loadSymbol<QgsFillSymbolV2>( overviewFrameSymbolElem );
1480 QDomNodeList atlasNodeList = itemElem.elementsByTagName(
"AtlasMap" );
1481 if ( atlasNodeList.size() > 0 )
1483 QDomElement atlasElem = atlasNodeList.at( 0 ).toElement();
1484 mAtlasDriven = ( atlasElem.attribute(
"atlasDriven",
"0" ) !=
"0" );
1485 if ( atlasElem.hasAttribute(
"fixedScale" ) )
1487 mAtlasScalingMode = ( atlasElem.attribute(
"fixedScale",
"0" ) !=
"0" ) ?
Fixed :
Auto;
1489 else if ( atlasElem.hasAttribute(
"scalingMode" ) )
1491 mAtlasScalingMode =
static_cast<AtlasScalingMode>( atlasElem.attribute(
"scalingMode" ).toInt() );
1493 mAtlasMargin = atlasElem.attribute(
"margin",
"0.1" ).toDouble();
1497 QDomNodeList composerItemList = itemElem.elementsByTagName(
"ComposerItem" );
1498 if ( composerItemList.size() > 0 )
1500 QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
1502 if ( composerItemElem.attribute(
"rotation",
"0" ).toDouble() != 0 )
1505 mMapRotation = composerItemElem.attribute(
"rotation",
"0" ).toDouble();
1520 if ( mKeepLayerStyles )
1529 mLayerStyleOverrides.clear();
1530 foreach (
const QString& layerID, mLayerSet )
1536 mLayerStyleOverrides.insert( layerID, style.
xmlData() );
1541 void QgsComposerMap::syncLayerSet()
1543 if ( mLayerSet.size() < 1 )
1549 QStringList currentLayerSet;
1550 if ( mKeepLayerSet )
1559 for (
int i = mLayerSet.size() - 1; i >= 0; --i )
1561 if ( !currentLayerSet.contains( mLayerSet.at( i ) ) )
1563 mLayerStyleOverrides.remove( mLayerSet.at( i ) );
1564 mLayerSet.removeAt( i );
1571 if ( mGridStack->
size() < 1 )
1576 return mGridStack->
grid( 0 );
1674 p.setWidthF( line->
width() );
1676 p.setCapStyle( Qt::FlatCap );
1888 if ( mOverviewStack->
size() < 1 )
1893 return mOverviewStack->
overview( 0 );
1915 return mCurrentRectangle;
1920 QRectF rectangle = rect();
1921 double frameExtension =
mFrame ? pen().widthF() / 2.0 : 0.0;
1924 double maxExtension = qMax( frameExtension, maxGridExtension );
1926 rectangle.setLeft( rectangle.left() - maxExtension );
1927 rectangle.setRight( rectangle.right() + maxExtension );
1928 rectangle.setTop( rectangle.top() - maxExtension );
1929 rectangle.setBottom( rectangle.bottom() + maxExtension );
1930 if ( rectangle != mCurrentRectangle )
1932 prepareGeometryChange();
1933 mCurrentRectangle = rectangle;
1945 double dx = mXOffset;
1946 double dy = mYOffset;
1947 transformShift( dx, dy );
1953 double dx = mXOffset;
1954 double dy = mYOffset;
1958 transformShift( dx, dy );
1963 poly.translate( -dx, -dy );
1967 void QgsComposerMap::mapPolygon(
const QgsRectangle& extent, QPolygonF& poly )
const
1970 if ( mEvaluatedMapRotation == 0 )
1977 poly << QPointF( poly.at( 0 ) );
1986 dx = rotationPoint.x() - extent.
xMinimum();
1987 dy = rotationPoint.y() - extent.
yMaximum();
1989 poly << QPointF( rotationPoint.x() - dx, rotationPoint.y() - dy );
1992 dx = rotationPoint.x() - extent.
xMaximum();
1993 dy = rotationPoint.y() - extent.
yMaximum();
1995 poly << QPointF( rotationPoint.x() - dx, rotationPoint.y() - dy );
1998 dx = rotationPoint.x() - extent.
xMaximum();
1999 dy = rotationPoint.y() - extent.
yMinimum();
2001 poly << QPointF( rotationPoint.x() - dx, rotationPoint.y() - dy );
2004 dx = rotationPoint.x() - extent.
xMinimum();
2005 dy = rotationPoint.y() - extent.
yMinimum();
2007 poly << QPointF( rotationPoint.x() - dx, rotationPoint.y() - dy );
2010 poly << QPointF( poly.at( 0 ) );
2027 return tr(
"Map %1" ).arg( mId );
2033 if ( mEvaluatedMapRotation == 0 )
2040 mapPolygon( newExtent, poly );
2041 QRectF bRect = poly.boundingRect();
2052 if ( extentWidth <= 0 )
2056 return rect().width() / extentWidth;
2081 refreshMapExtents();
2090 mCacheUpdated =
false;
2168 void QgsComposerMap::transformShift(
double& xShift,
double& yShift )
const
2171 double dxScaled = xShift * mmToMapUnits;
2172 double dyScaled = - yShift * mmToMapUnits;
2183 if ( mapPoly.size() < 1 )
2185 return QPointF( 0, 0 );
2190 double dx = mapCoords.x() - rotationPoint.
x();
2191 double dy = mapCoords.y() - rotationPoint.
y();
2193 QgsPoint backRotatedCoords( rotationPoint.
x() + dx, rotationPoint.
y() + dy );
2196 double xItem = rect().width() * ( backRotatedCoords.x() - unrotatedExtent.xMinimum() ) / unrotatedExtent.width();
2197 double yItem = rect().height() * ( 1 - ( backRotatedCoords.y() - unrotatedExtent.yMinimum() ) / unrotatedExtent.height() );
2198 return QPointF( xItem, yItem );
2208 if ( !mMapCanvas || !mDrawCanvasItems )
2213 QList<QGraphicsItem*> itemList = mMapCanvas->items();
2214 if ( itemList.size() < 1 )
2218 QGraphicsItem* currentItem = 0;
2220 for (
int i = itemList.size() - 1; i >= 0; --i )
2222 currentItem = itemList.at( i );
2224 if ( !currentItem || currentItem->data( 0 ).toString() !=
"AnnotationItem" )
2228 drawCanvasItem( currentItem, painter, itemStyle );
2232 void QgsComposerMap::drawCanvasItem( QGraphicsItem* item, QPainter* painter,
const QStyleOptionGraphicsItem* itemStyle )
2234 if ( !item || !mMapCanvas || !item->isVisible() )
2240 painter->setRenderHint( QPainter::Antialiasing );
2243 double scaleFactor = 1.0 / mMapCanvas->logicalDpiX() * 25.4;
2245 double itemX, itemY;
2246 QGraphicsItem* parent = item->parentItem();
2249 QPointF mapPos = composerMapPosForItem( item );
2255 QPointF itemScenePos = item->scenePos();
2256 QPointF parentScenePos = parent->scenePos();
2258 QPointF mapPos = composerMapPosForItem( parent );
2260 itemX = mapPos.x() + ( itemScenePos.x() - parentScenePos.x() ) * scaleFactor;
2261 itemY = mapPos.y() + ( itemScenePos.y() - parentScenePos.y() ) * scaleFactor;
2263 painter->translate( itemX, itemY );
2265 painter->scale( scaleFactor, scaleFactor );
2268 item->setData( 1,
"composer" );
2269 item->paint( painter, itemStyle, 0 );
2270 item->setData( 1,
"" );
2274 QPointF QgsComposerMap::composerMapPosForItem(
const QGraphicsItem* item )
const
2276 if ( !item || !mMapCanvas )
2278 return QPointF( 0, 0 );
2283 return QPointF( 0, 0 );
2286 QRectF graphicsSceneRect = mMapCanvas->sceneRect();
2287 QPointF itemScenePos = item->scenePos();
2290 double mapX = itemScenePos.x() / graphicsSceneRect.
width() * mapRendererExtent.
width() + mapRendererExtent.
xMinimum();
2291 double mapY = mapRendererExtent.
yMaximum() - itemScenePos.y() / graphicsSceneRect.height() * mapRendererExtent.
height();
2310 QList<const QgsComposerMap*>::const_iterator mapIt = mapList.constBegin();
2311 for ( ; mapIt != mapList.constEnd(); ++mapIt )
2313 if (( *mapIt )->id() > maxId )
2315 maxId = ( *mapIt )->id();
2348 mAtlasDriven = enabled;
2354 refreshMapExtents();
2360 return mAtlasScalingMode ==
Fixed;
2366 mAtlasScalingMode = fixed ?
Fixed :
Auto;
2376 double margin = mAtlasMargin;
2381 double ddMargin = exprVal.toDouble( &ok );
2382 QgsDebugMsg( QString(
"exprVal Map Atlas Margin:%1" ).arg( ddMargin ) );
2383 if ( ok && !exprVal.isNull() )
2386 margin = ddMargin / 100;
2393 return mAtlasMargin;