Skip to content

Commit 8fc79ce

Browse files
author
morb_au
committed
Several WMS-related improvements:
* Better bounding-box checking on legacy WMS servers - JPL World Map Service works again. * Providers can now expose the last error encountered by the provider. Only WMS returns useful information though. * Error display is now handled by the QgsMapCanvas not the QgsWmsProvider - this frees QgsWmsProvider from a dependency on the GUI being available. * For map redraws, QApplication::setOverrideCursor and QApplication::restoreOverrideCursor are now handled by the QgsMapCanvas not the QgisApp - this helps stop error message popups (via QMessageBox) from suffering from the "hourglass" cursor appearing not the "pointer". * Consective WMS operations do not fail any more - the "url" variable was being appended to, not cleared before each draw. git-svn-id: http://svn.osgeo.org/qgis/trunk@4907 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent dad3f6b commit 8fc79ce

14 files changed

+359
-142
lines changed

src/core/qgsrasterdataprovider.h

+17-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,23 @@ class QgsRasterDataProvider : public QgsDataProvider
8787
*/
8888
virtual QString getMetadata() = 0;
8989

90-
90+
/**
91+
* If an operation returns 0 (e.g. draw()), this function
92+
* returns the text of the error associated with the failure.
93+
* Interactive users of this provider can then, for example,
94+
* call a QMessageBox to display the contents.
95+
*/
96+
virtual QString errorCaptionString() = 0;
97+
98+
/**
99+
* If an operation returns 0 (e.g. draw()), this function
100+
* returns the text of the error associated with the failure.
101+
* Interactive users of this provider can then, for example,
102+
* call a QMessageBox to display the contents.
103+
*/
104+
virtual QString errorString() = 0;
105+
106+
91107
protected:
92108

93109
};

src/gui/qgisapp.cpp

+62-21
Original file line numberDiff line numberDiff line change
@@ -1692,7 +1692,8 @@ void QgisApp::addLayer()
16921692
bool QgisApp::addLayer(QFileInfo const & vectorFile)
16931693
{
16941694
// let the user know we're going to possibly be taking a while
1695-
QApplication::setOverrideCursor(Qt::WaitCursor);
1695+
// Let render() do its own cursor management
1696+
// QApplication::setOverrideCursor(Qt::WaitCursor);
16961697

16971698
mMapCanvas->freeze(); // XXX why do we do this?
16981699

@@ -1732,7 +1733,8 @@ bool QgisApp::addLayer(QFileInfo const & vectorFile)
17321733
if ( ! renderer )
17331734
{
17341735
mMapCanvas->freeze(false);
1735-
QApplication::restoreOverrideCursor();
1736+
// Let render() do its own cursor management
1737+
// QApplication::restoreOverrideCursor();
17361738

17371739
// XXX should we also delete the layer?
17381740

@@ -1784,7 +1786,9 @@ bool QgisApp::addLayer(QFileInfo const & vectorFile)
17841786
delete layer;
17851787

17861788
mMapCanvas->freeze(false);
1787-
QApplication::restoreOverrideCursor();
1789+
1790+
// Let render() do its own cursor management
1791+
// QApplication::restoreOverrideCursor();
17881792

17891793
return false;
17901794
}
@@ -1800,7 +1804,8 @@ bool QgisApp::addLayer(QFileInfo const & vectorFile)
18001804
// the layer is intially added
18011805
mMapCanvas->update();
18021806

1803-
QApplication::restoreOverrideCursor();
1807+
// Let render() do its own cursor management
1808+
// QApplication::restoreOverrideCursor();
18041809

18051810
statusBar()->message(mMapCanvas->extent().stringRep(2));
18061811

@@ -1822,8 +1827,8 @@ bool QgisApp::addLayer(QStringList const &theLayerQStringList, const QString& en
18221827
{
18231828
mMapCanvas->freeze();
18241829

1825-
QApplication::setOverrideCursor(Qt::WaitCursor);
1826-
1830+
// Let render() do its own cursor management
1831+
// QApplication::setOverrideCursor(Qt::WaitCursor);
18271832

18281833
for ( QStringList::ConstIterator it = theLayerQStringList.begin();
18291834
it != theLayerQStringList.end();
@@ -1846,7 +1851,9 @@ bool QgisApp::addLayer(QStringList const &theLayerQStringList, const QString& en
18461851
if ( ! layer )
18471852
{
18481853
mMapCanvas->freeze(false);
1849-
QApplication::restoreOverrideCursor();
1854+
1855+
// Let render() do its own cursor management
1856+
// QApplication::restoreOverrideCursor();
18501857

18511858
// XXX insert meaningful whine to the user here
18521859
return false;
@@ -1868,7 +1875,9 @@ bool QgisApp::addLayer(QStringList const &theLayerQStringList, const QString& en
18681875
if ( ! renderer )
18691876
{
18701877
mMapCanvas->freeze(false);
1871-
QApplication::restoreOverrideCursor();
1878+
1879+
// Let render() do its own cursor management
1880+
// QApplication::restoreOverrideCursor();
18721881

18731882
// XXX insert meaningful whine to the user here
18741883
return false;
@@ -1937,7 +1946,10 @@ bool QgisApp::addLayer(QStringList const &theLayerQStringList, const QString& en
19371946
// [gsherman]
19381947
mMapCanvas->render();
19391948
mMapCanvas->update();
1940-
QApplication::restoreOverrideCursor();
1949+
1950+
// Let render() do its own cursor management
1951+
// QApplication::restoreOverrideCursor();
1952+
19411953
statusBar()->message(mMapCanvas->extent().stringRep(2));
19421954

19431955

@@ -1975,7 +1987,8 @@ void QgisApp::addDatabaseLayer()
19751987

19761988
if (dbs->exec())
19771989
{
1978-
QApplication::setOverrideCursor(Qt::WaitCursor);
1990+
// Let render() do its own cursor management
1991+
// QApplication::setOverrideCursor(Qt::WaitCursor);
19791992

19801993

19811994
// repaint the canvas if it was covered by the dialog
@@ -2056,7 +2069,10 @@ void QgisApp::addDatabaseLayer()
20562069
// [gsherman]
20572070
mMapCanvas->render();
20582071
mMapCanvas->update();
2059-
QApplication::restoreOverrideCursor();
2072+
2073+
// Let render() do its own cursor management
2074+
// QApplication::restoreOverrideCursor();
2075+
20602076
} // QgisApp::addDatabaseLayer()
20612077
#endif
20622078

@@ -4719,7 +4735,10 @@ QString QgisApp::activeLayerSource()
47194735
void QgisApp::addVectorLayer(QString vectorLayerPath, QString baseName, QString providerKey)
47204736
{
47214737
mMapCanvas->freeze();
4722-
QApplication::setOverrideCursor(Qt::WaitCursor);
4738+
4739+
// Let render() do its own cursor management
4740+
// QApplication::setOverrideCursor(Qt::WaitCursor);
4741+
47234742
// create the layer
47244743
QgsVectorLayer *layer;
47254744
/* Eliminate the need to instantiate the layer based on provider type.
@@ -4796,7 +4815,9 @@ void QgisApp::addVectorLayer(QString vectorLayerPath, QString baseName, QString
47964815
// [gsherman]
47974816
mMapCanvas->render();
47984817
mMapCanvas->update();
4799-
QApplication::restoreOverrideCursor();
4818+
4819+
// Let render() do its own cursor management
4820+
// QApplication::restoreOverrideCursor();
48004821

48014822
} // QgisApp::addVectorLayer
48024823

@@ -4805,7 +4826,10 @@ void QgisApp::addVectorLayer(QString vectorLayerPath, QString baseName, QString
48054826
void QgisApp::addMapLayer(QgsMapLayer *theMapLayer)
48064827
{
48074828
mMapCanvas->freeze();
4808-
QApplication::setOverrideCursor(Qt::WaitCursor);
4829+
4830+
// Let render() do its own cursor management
4831+
// QApplication::setOverrideCursor(Qt::WaitCursor);
4832+
48094833
if(theMapLayer->isValid())
48104834
{
48114835
// Register this layer with the layers registry
@@ -4838,7 +4862,9 @@ void QgisApp::addMapLayer(QgsMapLayer *theMapLayer)
48384862
// [gsherman]
48394863
mMapCanvas->render();
48404864
mMapCanvas->update();
4841-
QApplication::restoreOverrideCursor();
4865+
4866+
// Let render() do its own cursor management
4867+
// QApplication::restoreOverrideCursor();
48424868

48434869
}
48444870

@@ -5476,7 +5502,10 @@ bool QgisApp::addRasterLayer(QFileInfo const & rasterFile, bool guiWarning)
54765502
if (!addRasterLayer(layer))
54775503
{
54785504
mMapCanvas->freeze(false);
5479-
QApplication::restoreOverrideCursor();
5505+
5506+
// Let render() do its own cursor management
5507+
// QApplication::restoreOverrideCursor();
5508+
54805509
if(guiWarning)
54815510
{
54825511
// don't show the gui warning (probably because we are loading from command line)
@@ -5491,7 +5520,10 @@ bool QgisApp::addRasterLayer(QFileInfo const & rasterFile, bool guiWarning)
54915520
statusBar()->message(mMapCanvas->extent().stringRep(2));
54925521
mMapCanvas->freeze(false);
54935522
mOverviewCanvas->freeze(false);
5494-
QApplication::restoreOverrideCursor();
5523+
5524+
// Let render() do its own cursor management
5525+
// QApplication::restoreOverrideCursor();
5526+
54955527
return true;
54965528
}
54975529

@@ -5522,7 +5554,10 @@ void QgisApp::addRasterLayer(QString const & rasterLayerPath,
55225554
#endif
55235555

55245556
mMapCanvas->freeze();
5525-
QApplication::setOverrideCursor(Qt::WaitCursor);
5557+
5558+
// Let render() do its own cursor management
5559+
// QApplication::setOverrideCursor(Qt::WaitCursor);
5560+
55265561
// create the layer
55275562
QgsRasterLayer *layer;
55285563
/* Eliminate the need to instantiate the layer based on provider type.
@@ -5605,7 +5640,9 @@ void QgisApp::addRasterLayer(QString const & rasterLayerPath,
56055640
// [gsherman]
56065641
mMapCanvas->render();
56075642
mMapCanvas->update();
5608-
QApplication::restoreOverrideCursor();
5643+
5644+
// Let render() do its own cursor management
5645+
// QApplication::restoreOverrideCursor();
56095646

56105647
} // QgisApp::addRasterLayer
56115648

@@ -5627,7 +5664,9 @@ bool QgisApp::addRasterLayer(QStringList const &theFileNameQStringList, bool gui
56275664
mMapCanvas->freeze(true);
56285665
mOverviewCanvas->freeze(true);
56295666

5630-
QApplication::setOverrideCursor(Qt::WaitCursor);
5667+
// Let render() do its own cursor management
5668+
// QApplication::setOverrideCursor(Qt::WaitCursor);
5669+
56315670
// this is messy since some files in the list may be rasters and others may
56325671
// be ogr layers. We'll set returnValue to false if one or more layers fail
56335672
// to load.
@@ -5682,7 +5721,9 @@ bool QgisApp::addRasterLayer(QStringList const &theFileNameQStringList, bool gui
56825721
statusBar()->message(mMapCanvas->extent().stringRep(2));
56835722
mMapCanvas->freeze(false);
56845723
mOverviewCanvas->freeze(false);
5685-
QApplication::restoreOverrideCursor();
5724+
5725+
// Let render() do its own cursor management
5726+
// QApplication::restoreOverrideCursor();
56865727

56875728
return returnValue;
56885729

src/gui/qgsmapcanvas.cpp

+30-3
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ email : sherman at mrcc.com
8080
#include <qcursor.h>
8181

8282
#include <QRubberBand>
83-
83+
#include <QApplication>
8484

8585
#include "qgis.h"
8686
#include "qgsrect.h"
@@ -558,6 +558,10 @@ void QgsMapCanvas::render(QPaintDevice * theQPaintDevice)
558558
{
559559
if (!mCanvasProperties->drawing)
560560
{
561+
562+
// Tell the user we're going to be a while
563+
QApplication::setOverrideCursor(Qt::WaitCursor);
564+
561565
mCanvasProperties->drawing = true;
562566
QPainter *paint = new QPainter();
563567

@@ -747,10 +751,16 @@ void QgsMapCanvas::render(QPaintDevice * theQPaintDevice)
747751
// Now do the call to the layer that actually does
748752
// the rendering work!
749753
//
750-
ml->draw(paint, &r1, mCanvasProperties->coordXForm, this);
754+
if (!ml->draw(paint, &r1, mCanvasProperties->coordXForm, this))
755+
{
756+
showError(ml);
757+
}
751758
if (split)
752759
{
753-
ml->draw(paint, &r2,mCanvasProperties->coordXForm, this);
760+
if (!ml->draw(paint, &r2, mCanvasProperties->coordXForm, this))
761+
{
762+
showError(ml);
763+
}
754764
}
755765
}
756766
#ifdef QGISDEBUG
@@ -922,6 +932,9 @@ void QgsMapCanvas::render(QPaintDevice * theQPaintDevice)
922932
paint->end();
923933
mCanvasProperties->drawing = false;
924934
delete paint;
935+
936+
// Tell the user we've finished going to be a while
937+
QApplication::restoreOverrideCursor();
925938
}
926939
mCanvasProperties->dirty = false;
927940

@@ -3345,3 +3358,17 @@ QgsPoint QgsMapCanvas::maybeInversePoint(QgsPoint point, const char whenmsg[])
33453358
}
33463359
return point;
33473360
}
3361+
3362+
3363+
void QgsMapCanvas::showError(QgsMapLayer * mapLayer)
3364+
{
3365+
QMessageBox::warning(
3366+
this,
3367+
mapLayer->errorCaptionString(),
3368+
tr("Could not draw") + " " + mapLayer->name() + " " + tr("because") + ":\n" +
3369+
mapLayer->errorCaptionString()
3370+
);
3371+
3372+
}
3373+
3374+
// ENDS

src/gui/qgsmapcanvas.h

+3
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,9 @@ public slots:
339339
*/
340340
QgsMapCanvas();
341341

342+
//! show whatever error is exposed by the QgsMapLayer.
343+
void showError(QgsMapLayer * mapLayer);
344+
342345
/**
343346
List to store the points of digitised lines and polygons
344347

src/gui/qgsmaplayer.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void QgsMapLayer::draw(QPainter *, QgsRect * viewExtent, int yTransform)
153153
// std::cout << "In QgsMapLayer::draw" << std::endl;
154154
}
155155

156-
void QgsMapLayer::draw(QPainter *, QgsRect *, QgsMapToPixel *,QPaintDevice * )
156+
bool QgsMapLayer::draw(QPainter *, QgsRect *, QgsMapToPixel *,QPaintDevice * )
157157
{
158158
// std::cout << "In QgsMapLayer::draw" << std::endl;
159159
}
@@ -499,6 +499,16 @@ std::vector<QgsField> const & QgsMapLayer::fields() const
499499
return bogus;
500500
} // QgsMapLayer::fields()
501501

502+
QString QgsMapLayer::errorCaptionString()
503+
{
504+
return QString();
505+
}
506+
507+
QString QgsMapLayer::errorString()
508+
{
509+
return QString();
510+
}
511+
502512
void QgsMapLayer::connectNotify( const char * signal )
503513
{
504514
#ifdef QGISDEBUG

src/gui/qgsmaplayer.h

+23-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ class QgsMapLayer : public QObject
9999

100100

101101
virtual void draw(QPainter *, QgsRect *, int);
102-
virtual void draw(QPainter *, QgsRect *, QgsMapToPixel * ,QPaintDevice *);
102+
103+
//! Returns FALSE if an error occurred during drawing
104+
virtual bool draw(QPainter *, QgsRect *, QgsMapToPixel *, QPaintDevice *);
105+
103106
virtual void drawLabels(QPainter *, QgsRect *, QgsMapToPixel * ,QPaintDevice *);
104107
/*! Identify the feature(s) in this layer that are contained in the search rectangle
105108
*/
@@ -284,6 +287,25 @@ class QgsMapLayer : public QObject
284287

285288
/** \brief accessor for transparency level. */
286289
virtual unsigned int getTransparency()=0;
290+
291+
292+
/**
293+
* If an operation returns 0 (e.g. draw()), this function
294+
* returns the text of the error associated with the failure.
295+
* Interactive users of this provider can then, for example,
296+
* call a QMessageBox to display the contents.
297+
*/
298+
QString errorCaptionString();
299+
300+
/**
301+
* If an operation returns 0 (e.g. draw()), this function
302+
* returns the text of the error associated with the failure.
303+
* Interactive users of this provider can then, for example,
304+
* call a QMessageBox to display the contents.
305+
*/
306+
QString errorString();
307+
308+
287309
public slots:
288310
/** \brief Mutator for transparency level. Should be between 0 and 255 */
289311
virtual void setTransparency(int)=0; //

0 commit comments

Comments
 (0)