33 #include <QDomDocument>
35 #include <QMutexLocker>
37 #include <QListIterator>
40 #include <QCoreApplication>
55 mSize = QSize( 0, 0 );
99 if ( extent.
width() > 0 &&
101 extent.
width() < 1 &&
106 double xMean = ( qAbs( extent.
xMinimum() ) + qAbs( extent.
xMaximum() ) ) * 0.5;
107 double yMean = ( qAbs( extent.
yMinimum() ) + qAbs( extent.
yMaximum() ) ) * 0.5;
109 double xRange = extent.
width() / xMean;
110 double yRange = extent.
height() / yMean;
112 static const double minProportion = 1e-12;
113 if ( xRange < minProportion || yRange < minProportion )
141 mSize = QSizeF( size.width(), size.height() );
160 return mSize.toSize();
170 double myHeight =
mSize.height();
171 double myWidth =
mSize.width();
175 if ( !myWidth || !myHeight )
186 mMapUnitsPerPixel = mapUnitsPerPixelY > mapUnitsPerPixelX ? mapUnitsPerPixelY : mapUnitsPerPixelX;
189 double dxmin, dxmax, dymin, dymax, whitespace;
191 if ( mapUnitsPerPixelY > mapUnitsPerPixelX )
247 if (
mSize.width() == 1 &&
mSize.height() == 1 )
253 QPaintDevice* thePaintDevice = painter->device();
254 if ( !thePaintDevice )
263 QCoreApplication::processEvents();
293 int myRed = prj->
readNumEntry(
"Gui",
"/SelectionColorRedPart", 255 );
294 int myGreen = prj->
readNumEntry(
"Gui",
"/SelectionColorGreenPart", 255 );
295 int myBlue = prj->
readNumEntry(
"Gui",
"/SelectionColorBluePart", 0 );
296 int myAlpha = prj->
readNumEntry(
"Gui",
"/SelectionColorAlphaPart", 255 );
303 double scaleFactor = 1.0;
306 if ( forceWidthScale )
308 scaleFactor = *forceWidthScale;
312 scaleFactor = sceneDpi / 25.4;
315 double rasterScaleFactor = ( thePaintDevice->logicalDpiX() + thePaintDevice->logicalDpiY() ) / 2.0 / sceneDpi;
344 while ( li.hasPrevious() )
355 QImage * mypFlattenedImage = 0;
357 QString layerId = li.previous();
359 QgsDebugMsg(
"Rendering at layer item " + layerId );
367 QgsDebugMsg(
"If there is a QPaintEngine error here, it is caused by an emit call" );
378 QgsDebugMsg( QString(
"layer %1: minscale:%2 maxscale:%3 scaledepvis:%4 extent:%5 blendmode:%6" )
391 mypContextPainter->setCompositionMode( ml->
blendMode() );
427 bool scaleRaster =
false;
436 QSettings mySettings;
442 bool flattenedLayer =
false;
446 if ((( vl->
blendMode() != QPainter::CompositionMode_SourceOver )
450 flattenedLayer =
true;
453 if ( mypFlattenedImage->isNull() )
460 mypFlattenedImage->fill( 0 );
461 QPainter * mypPainter =
new QPainter( mypFlattenedImage );
462 if ( mySettings.value(
"/qgis/enable_anti_aliasing",
true ).toBool() )
464 mypPainter->setRenderHint( QPainter::Antialiasing );
466 mypPainter->scale( rasterScaleFactor, rasterScaleFactor );
526 QColor transparentFillColor = QColor( 0, 0, 0, 255 - ( 255 * vl->
layerTransparency() / 100 ) );
534 if ( flattenedLayer )
539 mypContextPainter->save();
540 mypContextPainter->scale( 1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor );
541 mypContextPainter->drawImage( 0, 0, *( mypFlattenedImage ) );
542 mypContextPainter->restore();
543 delete mypFlattenedImage;
544 mypFlattenedImage = 0;
551 QgsDebugMsg(
"Layer not rendered because it is not within the defined "
552 "visibility scale range" );
566 while ( li.hasPrevious() )
573 QString layerId = li.previous();
624 QgsDebugMsg(
"Rendering completed in (seconds): " + QString(
"%1" ).arg( renderTime.elapsed() / 1000.0 ) );
655 QgsDebugMsg(
"Adjusting DistArea projection on/off" );
679 if ( refreshCoordinateTransformInfo )
693 QgsDebugMsg( QString(
"Transform error caught: %1" ).arg( e.
what() ) );
736 static const double splitCoord = 180.0;
749 ll = transform->
transform( ll.x(), ll.y(),
751 ur = transform->
transform( ur.x(), ur.y(),
756 if ( ll.x() > ur.x() )
776 extent =
QgsRectangle( -DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX );
777 r2 =
QgsRectangle( -DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX );
938 QStringList::iterator it =
mLayerSet.begin();
945 QgsDebugMsg( QString(
"WARNING: layer '%1' not found in map layer registry!" ).arg( *it ) );
982 const double padFactor = 1e-8;
1004 QgsDebugMsg( QString(
"Entering: %1" ).arg( layers.join(
", " ) ) );
1018 tmpSettings.
readXML( theNode );
1021 QDomElement layerCoordTransformInfoElem = theNode.firstChildElement(
"layer_coordinate_transform_info" );
1022 if ( !layerCoordTransformInfoElem.isNull() )
1024 QDomNodeList layerCoordinateTransformList = layerCoordTransformInfoElem.elementsByTagName(
"layer_coordinate_transform" );
1025 QDomElement layerCoordTransformElem;
1026 for (
int i = 0; i < layerCoordinateTransformList.size(); ++i )
1028 layerCoordTransformElem = layerCoordinateTransformList.at( i ).toElement();
1029 QString layerId = layerCoordTransformElem.attribute(
"layerid" );
1030 if ( layerId.isEmpty() )
1036 lct.
srcAuthId = layerCoordTransformElem.attribute(
"srcAuthId" );
1037 lct.
destAuthId = layerCoordTransformElem.attribute(
"destAuthId" );
1038 lct.
srcDatumTransform = layerCoordTransformElem.attribute(
"srcDatumTransform",
"-1" ).toInt();
1039 lct.
destDatumTransform = layerCoordTransformElem.attribute(
"destDatumTransform",
"-1" ).toInt();
1064 tmpSettings.
writeXML( theNode, theDoc );
1066 QDomElement layerCoordTransformInfo = theDoc.createElement(
"layer_coordinate_transform_info" );
1070 QDomElement layerCoordTransformElem = theDoc.createElement(
"layer_coordinate_transform" );
1071 layerCoordTransformElem.setAttribute(
"layerid", coordIt.key() );
1072 layerCoordTransformElem.setAttribute(
"srcAuthId", coordIt->srcAuthId );
1073 layerCoordTransformElem.setAttribute(
"destAuthId", coordIt->destAuthId );
1074 layerCoordTransformElem.setAttribute(
"srcDatumTransform", QString::number( coordIt->srcDatumTransform ) );
1075 layerCoordTransformElem.setAttribute(
"destDatumTransform", QString::number( coordIt->destDatumTransform ) );
1076 layerCoordTransformInfo.appendChild( layerCoordTransformElem );
1078 theNode.appendChild( layerCoordTransformInfo );
1104 && ctIt->srcAuthId == layer->
crs().
authid()
1117 || ctIt->srcAuthId == layer->
crs().
authid()
1131 switch ( blendMode )
1134 return QPainter::CompositionMode_SourceOver;
1136 return QPainter::CompositionMode_Lighten;
1138 return QPainter::CompositionMode_Screen;
1140 return QPainter::CompositionMode_ColorDodge;
1142 return QPainter::CompositionMode_Plus;
1144 return QPainter::CompositionMode_Darken;
1146 return QPainter::CompositionMode_Multiply;
1148 return QPainter::CompositionMode_ColorBurn;
1150 return QPainter::CompositionMode_Overlay;
1152 return QPainter::CompositionMode_SoftLight;
1154 return QPainter::CompositionMode_HardLight;
1156 return QPainter::CompositionMode_Difference;
1158 return QPainter::CompositionMode_Exclusion;
1160 return QPainter::CompositionMode_Source;
1162 return QPainter::CompositionMode_DestinationOver;
1164 return QPainter::CompositionMode_Clear;
1166 return QPainter::CompositionMode_Destination;
1168 return QPainter::CompositionMode_SourceIn;
1170 return QPainter::CompositionMode_DestinationIn;
1172 return QPainter::CompositionMode_SourceOut;
1174 return QPainter::CompositionMode_DestinationOut;
1176 return QPainter::CompositionMode_SourceAtop;
1178 return QPainter::CompositionMode_DestinationAtop;
1180 return QPainter::CompositionMode_Xor;
1182 QgsDebugMsg( QString(
"Blend mode %1 mapped to SourceOver" ).arg( blendMode ) );
1183 return QPainter::CompositionMode_SourceOver;
1190 switch ( blendMode )
1192 case QPainter::CompositionMode_SourceOver:
1194 case QPainter::CompositionMode_Lighten:
1196 case QPainter::CompositionMode_Screen:
1198 case QPainter::CompositionMode_ColorDodge:
1200 case QPainter::CompositionMode_Plus:
1202 case QPainter::CompositionMode_Darken:
1204 case QPainter::CompositionMode_Multiply:
1206 case QPainter::CompositionMode_ColorBurn:
1208 case QPainter::CompositionMode_Overlay:
1210 case QPainter::CompositionMode_SoftLight:
1212 case QPainter::CompositionMode_HardLight:
1214 case QPainter::CompositionMode_Difference:
1216 case QPainter::CompositionMode_Exclusion:
1218 case QPainter::CompositionMode_Source:
1220 case QPainter::CompositionMode_DestinationOver:
1222 case QPainter::CompositionMode_Clear:
1224 case QPainter::CompositionMode_Destination:
1226 case QPainter::CompositionMode_SourceIn:
1228 case QPainter::CompositionMode_DestinationIn:
1230 case QPainter::CompositionMode_SourceOut:
1232 case QPainter::CompositionMode_DestinationOut:
1234 case QPainter::CompositionMode_SourceAtop:
1236 case QPainter::CompositionMode_DestinationAtop:
1238 case QPainter::CompositionMode_Xor:
1241 QgsDebugMsg( QString(
"Composition mode %1 mapped to Normal" ).arg( blendMode ) );