Skip to content

Commit 5403746

Browse files
author
mhugent
committed
Show a warning before printing WMS layers. Some WMS servers have a limit for WIDTH and HEIGHT parameters
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9357 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 3e60778 commit 5403746

File tree

4 files changed

+99
-0
lines changed

4 files changed

+99
-0
lines changed

src/app/composer/qgscomposer.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,11 @@ void QgsComposer::on_mActionPrint_activated( void )
435435
return;
436436
}
437437

438+
if(containsWMSLayer())
439+
{
440+
showWMSPrintingWarning();
441+
}
442+
438443
QPrinter printer;
439444

440445
//try to set most of the print dialog settings based on composer properties
@@ -487,6 +492,11 @@ void QgsComposer::on_mActionPrint_activated( void )
487492

488493
void QgsComposer::on_mActionExportAsImage_activated( void )
489494
{
495+
if(containsWMSLayer())
496+
{
497+
showWMSPrintingWarning();
498+
}
499+
490500
// Image size
491501
int width = ( int )( mComposition->printoutResolution() * mComposition->paperWidth() / 25.4 );
492502
int height = ( int )( mComposition-> printoutResolution() * mComposition->paperHeight() / 25.4 );
@@ -608,6 +618,11 @@ void QgsComposer::on_mActionExportAsImage_activated( void )
608618

609619
void QgsComposer::on_mActionExportAsSVG_activated( void )
610620
{
621+
if(containsWMSLayer())
622+
{
623+
showWMSPrintingWarning();
624+
}
625+
611626
QString myQSettingsLabel = "/UI/displaySVGWarning";
612627
QSettings myQSettings;
613628

@@ -1080,3 +1095,43 @@ void QgsComposer::setSelectionTool()
10801095
mActionSelectMoveItem->setChecked( true );
10811096
on_mActionSelectMoveItem_activated();
10821097
}
1098+
1099+
bool QgsComposer::containsWMSLayer() const
1100+
{
1101+
QMap<QgsComposerItem*, QWidget*>::const_iterator item_it = mItemWidgetMap.constBegin();
1102+
QgsComposerItem* currentItem = 0;
1103+
QgsComposerMap* currentMap = 0;
1104+
1105+
for(; item_it != mItemWidgetMap.constEnd(); ++item_it)
1106+
{
1107+
currentItem = item_it.key();
1108+
currentMap = dynamic_cast<QgsComposerMap*>(currentItem);
1109+
if(currentMap)
1110+
{
1111+
if(currentMap->containsWMSLayer())
1112+
{
1113+
return true;
1114+
}
1115+
}
1116+
}
1117+
return false;
1118+
}
1119+
1120+
void QgsComposer::showWMSPrintingWarning()
1121+
{
1122+
QString myQSettingsLabel = "/UI/displayComposerWMSWarning";
1123+
QSettings myQSettings;
1124+
1125+
bool displayWMSWarning = myQSettings.value( myQSettingsLabel, true ).toBool();
1126+
if(displayWMSWarning)
1127+
{
1128+
QgsMessageViewer* m = new QgsMessageViewer( this );
1129+
m->setWindowTitle( tr( "Project contains WMS layers" ) );
1130+
m->setMessage(tr("Some WMS servers (e.g. UMN mapserver) have a limit for the WIDTH and HEIGHT parameter. Printing layers from such servers may exceed this limit. If this is the case, the WMS layer will not be printed"), QgsMessageOutput::MessageText);
1131+
m->setCheckBoxText( tr( "Don't show this message again" ) );
1132+
m->setCheckBoxState( Qt::Unchecked );
1133+
m->setCheckBoxVisible( true );
1134+
m->setCheckBoxQSettingsLabel( myQSettingsLabel );
1135+
m->exec();
1136+
}
1137+
}

src/app/composer/qgscomposer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,12 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
204204
//! returns new world matrix for canvas view after zoom with factor scaleChange
205205
QMatrix updateMatrix( double scaleChange );
206206

207+
//! True if a composer map contains a WMS layer
208+
bool containsWMSLayer() const;
209+
210+
//! Displays a warning because of possible min/max size in WMS
211+
void showWMSPrintingWarning();
212+
207213
//! Pointer to composer view
208214
QgsComposerView *mView;
209215

src/core/composer/qgscomposermap.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "qgsmaptopixel.h"
2626
#include "qgsproject.h"
2727
#include "qgsmaprenderer.h"
28+
#include "qgsrasterlayer.h"
2829
#include "qgsrendercontext.h"
2930
#include "qgsscalecalculator.h"
3031
#include "qgsvectorlayer.h"
@@ -402,6 +403,40 @@ void QgsComposerMap::setOffset( double xOffset, double yOffset )
402403
mYOffset = yOffset;
403404
}
404405

406+
bool QgsComposerMap::containsWMSLayer() const
407+
{
408+
if(!mMapRenderer)
409+
{
410+
return false;
411+
}
412+
413+
QStringList layers = mMapRenderer->layerSet();
414+
415+
QStringList::const_iterator layer_it = layers.constBegin();
416+
QgsMapLayer* currentLayer = 0;
417+
418+
for(; layer_it != layers.constEnd(); ++layer_it)
419+
{
420+
currentLayer = QgsMapLayerRegistry::instance()->mapLayer(*layer_it);
421+
if(currentLayer)
422+
{
423+
QgsRasterLayer* currentRasterLayer = dynamic_cast<QgsRasterLayer*>(currentLayer);
424+
if(currentRasterLayer)
425+
{
426+
const QgsRasterDataProvider* rasterProvider = 0;
427+
if(rasterProvider = currentRasterLayer->dataProvider())
428+
{
429+
if(rasterProvider->name() == "wms")
430+
{
431+
return true;
432+
}
433+
}
434+
}
435+
}
436+
}
437+
return false;
438+
}
439+
405440
double QgsComposerMap::horizontalViewScaleFactor() const
406441
{
407442
double result = 1;

src/core/composer/qgscomposermap.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ class CORE_EXPORT QgsComposerMap : /*public QWidget, private Ui::QgsComposerMapB
118118
/**Sets offset values to shift image (useful for live updates when moving item content)*/
119119
void setOffset( double xOffset, double yOffset );
120120

121+
/**True if composer map renders a WMS layer*/
122+
bool containsWMSLayer() const;
123+
121124
/** stores state in Dom node
122125
* @param elem is Dom element corresponding to 'Composer' tag
123126
* @param temp write template file

0 commit comments

Comments
 (0)