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" );
791 static const double splitCoord = 180.0;
805 if ( ll.
x() > ur.
x() )
822 extent =
QgsRectangle( -DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX );
823 r2 =
QgsRectangle( -DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX );
831 QgsDebugMsg( QString(
"sourceCrs = " +
tr( theLayer )->sourceCrs().authid() ) );
832 QgsDebugMsg( QString(
"destCRS = " +
tr( theLayer )->destCRS().authid() ) );
853 QgsDebugMsg( QString(
"layer sourceCrs = " +
tr( theLayer )->sourceCrs().authid() ) );
854 QgsDebugMsg( QString(
"layer destCRS = " +
tr( theLayer )->destCRS().authid() ) );
961 QStringList::iterator it =
mLayerSet.begin();
968 QgsDebugMsg( QString(
"WARNING: layer '%1' not found in map layer registry!" ).arg( *it ) );
1005 const double padFactor = 1e-8;
1027 QgsDebugMsg( QString(
"Entering: %1" ).arg( layers.join(
", " ) ) );
1039 QDomNode myNode = theNode.namedItem(
"units" );
1040 QDomElement element = myNode.toElement();
1044 if (
"meters" == element.text() )
1048 else if (
"feet" == element.text() )
1052 else if (
"degrees" == element.text() )
1056 else if (
"unknown" == element.text() )
1062 QgsDebugMsg(
"Unknown map unit type " + element.text() );
1068 QDomNode projNode = theNode.namedItem(
"projections" );
1069 element = projNode.toElement();
1074 QDomNode srsNode = theNode.namedItem(
"destinationsrs" );
1080 QDomNode extentNode = theNode.namedItem(
"extent" );
1082 QDomNode xminNode = extentNode.namedItem(
"xmin" );
1083 QDomNode yminNode = extentNode.namedItem(
"ymin" );
1084 QDomNode xmaxNode = extentNode.namedItem(
"xmax" );
1085 QDomNode ymaxNode = extentNode.namedItem(
"ymax" );
1087 QDomElement exElement = xminNode.toElement();
1088 double xmin = exElement.text().toDouble();
1091 exElement = yminNode.toElement();
1092 double ymin = exElement.text().toDouble();
1095 exElement = xmaxNode.toElement();
1096 double xmax = exElement.text().toDouble();
1099 exElement = ymaxNode.toElement();
1100 double ymax = exElement.text().toDouble();
1111 QDomElement unitsNode = theDoc.createElement(
"units" );
1112 theNode.appendChild( unitsNode );
1114 QString unitsString;
1119 unitsString =
"meters";
1122 unitsString =
"feet";
1125 unitsString =
"degrees";
1129 unitsString =
"unknown";
1132 QDomText unitsText = theDoc.createTextNode( unitsString );
1133 unitsNode.appendChild( unitsText );
1137 QDomElement extentNode = theDoc.createElement(
"extent" );
1138 theNode.appendChild( extentNode );
1140 QDomElement xMin = theDoc.createElement(
"xmin" );
1141 QDomElement yMin = theDoc.createElement(
"ymin" );
1142 QDomElement xMax = theDoc.createElement(
"xmax" );
1143 QDomElement yMax = theDoc.createElement(
"ymax" );
1151 xMin.appendChild( xMinText );
1152 yMin.appendChild( yMinText );
1153 xMax.appendChild( xMaxText );
1154 yMax.appendChild( yMaxText );
1156 extentNode.appendChild( xMin );
1157 extentNode.appendChild( yMin );
1158 extentNode.appendChild( xMax );
1159 extentNode.appendChild( yMax );
1162 QDomElement projNode = theDoc.createElement(
"projections" );
1163 theNode.appendChild( projNode );
1166 projNode.appendChild( projText );
1169 QDomElement srsNode = theDoc.createElement(
"destinationsrs" );
1170 theNode.appendChild( srsNode );
1198 switch ( blendMode )
1201 return QPainter::CompositionMode_SourceOver;
1203 return QPainter::CompositionMode_Lighten;
1205 return QPainter::CompositionMode_Screen;
1207 return QPainter::CompositionMode_ColorDodge;
1209 return QPainter::CompositionMode_Plus;
1211 return QPainter::CompositionMode_Darken;
1213 return QPainter::CompositionMode_Multiply;
1215 return QPainter::CompositionMode_ColorBurn;
1217 return QPainter::CompositionMode_Overlay;
1219 return QPainter::CompositionMode_SoftLight;
1221 return QPainter::CompositionMode_HardLight;
1223 return QPainter::CompositionMode_Difference;
1225 return QPainter::CompositionMode_Exclusion;
1227 return QPainter::CompositionMode_SourceOver;
1234 switch ( blendMode )
1236 case QPainter::CompositionMode_SourceOver:
1238 case QPainter::CompositionMode_Lighten:
1240 case QPainter::CompositionMode_Screen:
1242 case QPainter::CompositionMode_ColorDodge:
1244 case QPainter::CompositionMode_Plus:
1246 case QPainter::CompositionMode_Darken:
1248 case QPainter::CompositionMode_Multiply:
1250 case QPainter::CompositionMode_ColorBurn:
1252 case QPainter::CompositionMode_Overlay:
1254 case QPainter::CompositionMode_SoftLight:
1256 case QPainter::CompositionMode_HardLight:
1258 case QPainter::CompositionMode_Difference:
1260 case QPainter::CompositionMode_Exclusion: