33 #include <QDomDocument>
35 #include <QMutexLocker>
37 #include <QListIterator>
40 #include <QCoreApplication>
54 mSize = QSize( 0, 0 );
98 if ( extent.
width() > 0 &&
100 extent.
width() < 1 &&
105 double xMean = ( qAbs( extent.
xMinimum() ) + qAbs( extent.
xMaximum() ) ) * 0.5;
106 double yMean = ( qAbs( extent.
yMinimum() ) + qAbs( extent.
yMaximum() ) ) * 0.5;
108 double xRange = extent.
width() / xMean;
109 double yRange = extent.
height() / yMean;
111 static const double minProportion = 1e-12;
112 if ( xRange < minProportion || yRange < minProportion )
126 mSize = QSizeF( size.width(), size.height() );
145 return mSize.toSize();
155 double myHeight =
mSize.height();
156 double myWidth =
mSize.width();
160 if ( !myWidth || !myHeight )
171 mMapUnitsPerPixel = mapUnitsPerPixelY > mapUnitsPerPixelX ? mapUnitsPerPixelY : mapUnitsPerPixelX;
174 double dxmin, dxmax, dymin, dymax, whitespace;
176 if ( mapUnitsPerPixelY > mapUnitsPerPixelX )
227 bool mySameAsLastFlag =
true;
237 if (
mSize.width() == 1 &&
mSize.height() == 1 )
243 QPaintDevice* thePaintDevice = painter->device();
244 if ( !thePaintDevice )
253 QCoreApplication::processEvents();
283 int myRed = prj->
readNumEntry(
"Gui",
"/SelectionColorRedPart", 255 );
284 int myGreen = prj->
readNumEntry(
"Gui",
"/SelectionColorGreenPart", 255 );
285 int myBlue = prj->
readNumEntry(
"Gui",
"/SelectionColorBluePart", 0 );
286 int myAlpha = prj->
readNumEntry(
"Gui",
"/SelectionColorAlphaPart", 255 );
293 double scaleFactor = 1.0;
296 if ( forceWidthScale )
298 scaleFactor = *forceWidthScale;
302 scaleFactor = sceneDpi / 25.4;
305 double rasterScaleFactor = ( thePaintDevice->logicalDpiX() + thePaintDevice->logicalDpiY() ) / 2.0 / sceneDpi;
309 mySameAsLastFlag =
false;
314 mySameAsLastFlag =
false;
320 mySameAsLastFlag =
false;
325 mySameAsLastFlag =
false;
334 if ( !mySameAsLastFlag )
337 QSettings mySettings;
338 if ( mySettings.value(
"/qgis/enable_render_caching",
false ).toBool() )
350 while ( li.hasPrevious() )
361 QImage * mypFlattenedImage = 0;
363 QString layerId = li.previous();
365 QgsDebugMsg(
"Rendering at layer item " + layerId );
373 QgsDebugMsg(
"If there is a QPaintEngine error here, it is caused by an emit call" );
384 QgsDebugMsg( QString(
"layer %1: minscale:%2 maxscale:%3 scaledepvis:%4 extent:%5 blendmode:%6" )
397 mypContextPainter->setCompositionMode( ml->
blendMode() );
433 bool scaleRaster =
false;
454 QSettings mySettings;
455 bool useRenderCaching =
false;
458 if ( mySettings.value(
"/qgis/enable_render_caching",
false ).toBool() )
460 useRenderCaching =
true;
461 if ( !mySameAsLastFlag || ml->
cacheImage() == 0 )
463 QgsDebugMsg(
"Caching enabled but layer redraw forced by extent change or empty cache" );
466 if ( mypImage->isNull() )
475 QPainter * mypPainter =
new QPainter( ml->
cacheImage() );
477 if ( mySettings.value(
"/qgis/enable_anti_aliasing",
true ).toBool() )
479 mypPainter->setRenderHint( QPainter::Antialiasing );
483 else if ( mySameAsLastFlag )
486 QgsDebugMsg(
"Caching enabled --- drawing layer from cached image" );
487 mypContextPainter->drawImage( 0, 0, *( ml->
cacheImage() ) );
499 bool flattenedLayer =
false;
503 if (( !useRenderCaching )
504 && (( vl->
blendMode() != QPainter::CompositionMode_SourceOver )
508 flattenedLayer =
true;
511 if ( mypFlattenedImage->isNull() )
518 mypFlattenedImage->fill( 0 );
519 QPainter * mypPainter =
new QPainter( mypFlattenedImage );
520 if ( mySettings.value(
"/qgis/enable_anti_aliasing",
true ).toBool() )
522 mypPainter->setRenderHint( QPainter::Antialiasing );
524 mypPainter->scale( rasterScaleFactor, rasterScaleFactor );
584 QColor transparentFillColor = QColor( 0, 0, 0, 255 - ( 255 * vl->
layerTransparency() / 100 ) );
592 if ( useRenderCaching )
600 mypContextPainter->drawImage( 0, 0, *( ml->
cacheImage() ) );
602 else if ( flattenedLayer )
607 mypContextPainter->save();
608 mypContextPainter->scale( 1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor );
609 mypContextPainter->drawImage( 0, 0, *( mypFlattenedImage ) );
610 mypContextPainter->restore();
611 delete mypFlattenedImage;
612 mypFlattenedImage = 0;
619 QgsDebugMsg(
"Layer not rendered because it is not within the defined "
620 "visibility scale range" );
634 while ( li.hasPrevious() )
641 QString layerId = li.previous();
692 QgsDebugMsg(
"Rendering completed in (seconds): " + QString(
"%1" ).arg( renderTime.elapsed() / 1000.0 ) );
726 QgsDebugMsg(
"Adjusting DistArea projection on/off" );
746 if ( refreshCoordinateTransformInfo )
796 static const double splitCoord = 180.0;
809 ll = transform->
transform( ll.x(), ll.y(),
811 ur = transform->
transform( ur.x(), ur.y(),
816 if ( ll.x() > ur.x() )
836 extent =
QgsRectangle( -DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX );
837 r2 =
QgsRectangle( -DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX );
998 QStringList::iterator it =
mLayerSet.begin();
1005 QgsDebugMsg( QString(
"WARNING: layer '%1' not found in map layer registry!" ).arg( *it ) );
1042 const double padFactor = 1e-8;
1064 QgsDebugMsg( QString(
"Entering: %1" ).arg( layers.join(
", " ) ) );
1076 QDomNode myNode = theNode.namedItem(
"units" );
1077 QDomElement element = myNode.toElement();
1081 if (
"meters" == element.text() )
1085 else if (
"feet" == element.text() )
1089 else if (
"nautical miles" == element.text() )
1093 else if (
"degrees" == element.text() )
1097 else if (
"unknown" == element.text() )
1103 QgsDebugMsg(
"Unknown map unit type " + element.text() );
1109 QDomNode projNode = theNode.namedItem(
"projections" );
1110 element = projNode.toElement();
1115 QDomElement layerCoordTransformInfoElem = theNode.firstChildElement(
"layer_coordinate_transform_info" );
1116 if ( !layerCoordTransformInfoElem.isNull() )
1118 QDomNodeList layerCoordinateTransformList = layerCoordTransformInfoElem.elementsByTagName(
"layer_coordinate_transform" );
1119 QDomElement layerCoordTransformElem;
1120 for (
int i = 0; i < layerCoordinateTransformList.size(); ++i )
1122 layerCoordTransformElem = layerCoordinateTransformList.at( i ).toElement();
1123 QString layerId = layerCoordTransformElem.attribute(
"layerid" );
1124 if ( layerId.isEmpty() )
1130 lct.
srcAuthId = layerCoordTransformElem.attribute(
"srcAuthId" );
1131 lct.
destAuthId = layerCoordTransformElem.attribute(
"destAuthId" );
1132 lct.
srcDatumTransform = layerCoordTransformElem.attribute(
"srcDatumTransform",
"-1" ).toInt();
1133 lct.
destDatumTransform = layerCoordTransformElem.attribute(
"destDatumTransform",
"-1" ).toInt();
1140 QDomNode srsNode = theNode.namedItem(
"destinationsrs" );
1146 QDomNode extentNode = theNode.namedItem(
"extent" );
1148 QDomNode xminNode = extentNode.namedItem(
"xmin" );
1149 QDomNode yminNode = extentNode.namedItem(
"ymin" );
1150 QDomNode xmaxNode = extentNode.namedItem(
"xmax" );
1151 QDomNode ymaxNode = extentNode.namedItem(
"ymax" );
1153 QDomElement exElement = xminNode.toElement();
1154 double xmin = exElement.text().toDouble();
1157 exElement = yminNode.toElement();
1158 double ymin = exElement.text().toDouble();
1161 exElement = xmaxNode.toElement();
1162 double xmax = exElement.text().toDouble();
1165 exElement = ymaxNode.toElement();
1166 double ymax = exElement.text().toDouble();
1178 QDomElement unitsNode = theDoc.createElement(
"units" );
1179 theNode.appendChild( unitsNode );
1181 QString unitsString;
1186 unitsString =
"meters";
1189 unitsString =
"feet";
1192 unitsString =
"nautical miles";
1195 unitsString =
"degrees";
1199 unitsString =
"unknown";
1202 QDomText unitsText = theDoc.createTextNode( unitsString );
1203 unitsNode.appendChild( unitsText );
1207 QDomElement extentNode = theDoc.createElement(
"extent" );
1208 theNode.appendChild( extentNode );
1210 QDomElement xMin = theDoc.createElement(
"xmin" );
1211 QDomElement yMin = theDoc.createElement(
"ymin" );
1212 QDomElement xMax = theDoc.createElement(
"xmax" );
1213 QDomElement yMax = theDoc.createElement(
"ymax" );
1221 xMin.appendChild( xMinText );
1222 yMin.appendChild( yMinText );
1223 xMax.appendChild( xMaxText );
1224 yMax.appendChild( yMaxText );
1226 extentNode.appendChild( xMin );
1227 extentNode.appendChild( yMin );
1228 extentNode.appendChild( xMax );
1229 extentNode.appendChild( yMax );
1232 QDomElement projNode = theDoc.createElement(
"projections" );
1233 theNode.appendChild( projNode );
1236 projNode.appendChild( projText );
1239 QDomElement srsNode = theDoc.createElement(
"destinationsrs" );
1240 theNode.appendChild( srsNode );
1244 QDomElement layerCoordTransformInfo = theDoc.createElement(
"layer_coordinate_transform_info" );
1248 QDomElement layerCoordTransformElem = theDoc.createElement(
"layer_coordinate_transform" );
1249 layerCoordTransformElem.setAttribute(
"layerid", coordIt.key() );
1250 layerCoordTransformElem.setAttribute(
"srcAuthId", coordIt->srcAuthId );
1251 layerCoordTransformElem.setAttribute(
"destAuthId", coordIt->destAuthId );
1252 layerCoordTransformElem.setAttribute(
"srcDatumTransform", QString::number( coordIt->srcDatumTransform ) );
1253 layerCoordTransformElem.setAttribute(
"destDatumTransform", QString::number( coordIt->destDatumTransform ) );
1254 layerCoordTransformInfo.appendChild( layerCoordTransformElem );
1256 theNode.appendChild( layerCoordTransformInfo );
1282 && ctIt->srcAuthId == layer->
crs().
authid()
1295 || ctIt->srcAuthId == layer->
crs().
authid()
1309 switch ( blendMode )
1312 return QPainter::CompositionMode_SourceOver;
1314 return QPainter::CompositionMode_Lighten;
1316 return QPainter::CompositionMode_Screen;
1318 return QPainter::CompositionMode_ColorDodge;
1320 return QPainter::CompositionMode_Plus;
1322 return QPainter::CompositionMode_Darken;
1324 return QPainter::CompositionMode_Multiply;
1326 return QPainter::CompositionMode_ColorBurn;
1328 return QPainter::CompositionMode_Overlay;
1330 return QPainter::CompositionMode_SoftLight;
1332 return QPainter::CompositionMode_HardLight;
1334 return QPainter::CompositionMode_Difference;
1336 return QPainter::CompositionMode_Exclusion;
1338 return QPainter::CompositionMode_SourceOver;
1345 switch ( blendMode )
1347 case QPainter::CompositionMode_SourceOver:
1349 case QPainter::CompositionMode_Lighten:
1351 case QPainter::CompositionMode_Screen:
1353 case QPainter::CompositionMode_ColorDodge:
1355 case QPainter::CompositionMode_Plus:
1357 case QPainter::CompositionMode_Darken:
1359 case QPainter::CompositionMode_Multiply:
1361 case QPainter::CompositionMode_ColorBurn:
1363 case QPainter::CompositionMode_Overlay:
1365 case QPainter::CompositionMode_SoftLight:
1367 case QPainter::CompositionMode_HardLight:
1369 case QPainter::CompositionMode_Difference:
1371 case QPainter::CompositionMode_Exclusion: