Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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/qgis@4907 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
morb_au committed Feb 25, 2006
1 parent 2e8c32a commit 56ad39c
Show file tree
Hide file tree
Showing 14 changed files with 359 additions and 142 deletions.
18 changes: 17 additions & 1 deletion src/core/qgsrasterdataprovider.h
Expand Up @@ -87,7 +87,23 @@ class QgsRasterDataProvider : public QgsDataProvider
*/
virtual QString getMetadata() = 0;


/**
* If an operation returns 0 (e.g. draw()), this function
* returns the text of the error associated with the failure.
* Interactive users of this provider can then, for example,
* call a QMessageBox to display the contents.
*/
virtual QString errorCaptionString() = 0;

/**
* If an operation returns 0 (e.g. draw()), this function
* returns the text of the error associated with the failure.
* Interactive users of this provider can then, for example,
* call a QMessageBox to display the contents.
*/
virtual QString errorString() = 0;


protected:

};
Expand Down
83 changes: 62 additions & 21 deletions src/gui/qgisapp.cpp
Expand Up @@ -1692,7 +1692,8 @@ void QgisApp::addLayer()
bool QgisApp::addLayer(QFileInfo const & vectorFile)
{
// let the user know we're going to possibly be taking a while
QApplication::setOverrideCursor(Qt::WaitCursor);
// Let render() do its own cursor management
// QApplication::setOverrideCursor(Qt::WaitCursor);

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

Expand Down Expand Up @@ -1732,7 +1733,8 @@ bool QgisApp::addLayer(QFileInfo const & vectorFile)
if ( ! renderer )
{
mMapCanvas->freeze(false);
QApplication::restoreOverrideCursor();
// Let render() do its own cursor management
// QApplication::restoreOverrideCursor();

// XXX should we also delete the layer?

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

mMapCanvas->freeze(false);
QApplication::restoreOverrideCursor();

// Let render() do its own cursor management
// QApplication::restoreOverrideCursor();

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

QApplication::restoreOverrideCursor();
// Let render() do its own cursor management
// QApplication::restoreOverrideCursor();

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

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

QApplication::setOverrideCursor(Qt::WaitCursor);

// Let render() do its own cursor management
// QApplication::setOverrideCursor(Qt::WaitCursor);

for ( QStringList::ConstIterator it = theLayerQStringList.begin();
it != theLayerQStringList.end();
Expand All @@ -1846,7 +1851,9 @@ bool QgisApp::addLayer(QStringList const &theLayerQStringList, const QString& en
if ( ! layer )
{
mMapCanvas->freeze(false);
QApplication::restoreOverrideCursor();

// Let render() do its own cursor management
// QApplication::restoreOverrideCursor();

// XXX insert meaningful whine to the user here
return false;
Expand All @@ -1868,7 +1875,9 @@ bool QgisApp::addLayer(QStringList const &theLayerQStringList, const QString& en
if ( ! renderer )
{
mMapCanvas->freeze(false);
QApplication::restoreOverrideCursor();

// Let render() do its own cursor management
// QApplication::restoreOverrideCursor();

// XXX insert meaningful whine to the user here
return false;
Expand Down Expand Up @@ -1937,7 +1946,10 @@ bool QgisApp::addLayer(QStringList const &theLayerQStringList, const QString& en
// [gsherman]
mMapCanvas->render();
mMapCanvas->update();
QApplication::restoreOverrideCursor();

// Let render() do its own cursor management
// QApplication::restoreOverrideCursor();

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


Expand Down Expand Up @@ -1975,7 +1987,8 @@ void QgisApp::addDatabaseLayer()

if (dbs->exec())
{
QApplication::setOverrideCursor(Qt::WaitCursor);
// Let render() do its own cursor management
// QApplication::setOverrideCursor(Qt::WaitCursor);


// repaint the canvas if it was covered by the dialog
Expand Down Expand Up @@ -2056,7 +2069,10 @@ void QgisApp::addDatabaseLayer()
// [gsherman]
mMapCanvas->render();
mMapCanvas->update();
QApplication::restoreOverrideCursor();

// Let render() do its own cursor management
// QApplication::restoreOverrideCursor();

} // QgisApp::addDatabaseLayer()
#endif

Expand Down Expand Up @@ -4719,7 +4735,10 @@ QString QgisApp::activeLayerSource()
void QgisApp::addVectorLayer(QString vectorLayerPath, QString baseName, QString providerKey)
{
mMapCanvas->freeze();
QApplication::setOverrideCursor(Qt::WaitCursor);

// Let render() do its own cursor management
// QApplication::setOverrideCursor(Qt::WaitCursor);

// create the layer
QgsVectorLayer *layer;
/* Eliminate the need to instantiate the layer based on provider type.
Expand Down Expand Up @@ -4796,7 +4815,9 @@ void QgisApp::addVectorLayer(QString vectorLayerPath, QString baseName, QString
// [gsherman]
mMapCanvas->render();
mMapCanvas->update();
QApplication::restoreOverrideCursor();

// Let render() do its own cursor management
// QApplication::restoreOverrideCursor();

} // QgisApp::addVectorLayer

Expand All @@ -4805,7 +4826,10 @@ void QgisApp::addVectorLayer(QString vectorLayerPath, QString baseName, QString
void QgisApp::addMapLayer(QgsMapLayer *theMapLayer)
{
mMapCanvas->freeze();
QApplication::setOverrideCursor(Qt::WaitCursor);

// Let render() do its own cursor management
// QApplication::setOverrideCursor(Qt::WaitCursor);

if(theMapLayer->isValid())
{
// Register this layer with the layers registry
Expand Down Expand Up @@ -4838,7 +4862,9 @@ void QgisApp::addMapLayer(QgsMapLayer *theMapLayer)
// [gsherman]
mMapCanvas->render();
mMapCanvas->update();
QApplication::restoreOverrideCursor();

// Let render() do its own cursor management
// QApplication::restoreOverrideCursor();

}

Expand Down Expand Up @@ -5476,7 +5502,10 @@ bool QgisApp::addRasterLayer(QFileInfo const & rasterFile, bool guiWarning)
if (!addRasterLayer(layer))
{
mMapCanvas->freeze(false);
QApplication::restoreOverrideCursor();

// Let render() do its own cursor management
// QApplication::restoreOverrideCursor();

if(guiWarning)
{
// don't show the gui warning (probably because we are loading from command line)
Expand All @@ -5491,7 +5520,10 @@ bool QgisApp::addRasterLayer(QFileInfo const & rasterFile, bool guiWarning)
statusBar()->message(mMapCanvas->extent().stringRep(2));
mMapCanvas->freeze(false);
mOverviewCanvas->freeze(false);
QApplication::restoreOverrideCursor();

// Let render() do its own cursor management
// QApplication::restoreOverrideCursor();

return true;
}

Expand Down Expand Up @@ -5522,7 +5554,10 @@ void QgisApp::addRasterLayer(QString const & rasterLayerPath,
#endif

mMapCanvas->freeze();
QApplication::setOverrideCursor(Qt::WaitCursor);

// Let render() do its own cursor management
// QApplication::setOverrideCursor(Qt::WaitCursor);

// create the layer
QgsRasterLayer *layer;
/* Eliminate the need to instantiate the layer based on provider type.
Expand Down Expand Up @@ -5605,7 +5640,9 @@ void QgisApp::addRasterLayer(QString const & rasterLayerPath,
// [gsherman]
mMapCanvas->render();
mMapCanvas->update();
QApplication::restoreOverrideCursor();

// Let render() do its own cursor management
// QApplication::restoreOverrideCursor();

} // QgisApp::addRasterLayer

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

QApplication::setOverrideCursor(Qt::WaitCursor);
// Let render() do its own cursor management
// QApplication::setOverrideCursor(Qt::WaitCursor);

// this is messy since some files in the list may be rasters and others may
// be ogr layers. We'll set returnValue to false if one or more layers fail
// to load.
Expand Down Expand Up @@ -5682,7 +5721,9 @@ bool QgisApp::addRasterLayer(QStringList const &theFileNameQStringList, bool gui
statusBar()->message(mMapCanvas->extent().stringRep(2));
mMapCanvas->freeze(false);
mOverviewCanvas->freeze(false);
QApplication::restoreOverrideCursor();

// Let render() do its own cursor management
// QApplication::restoreOverrideCursor();

return returnValue;

Expand Down
33 changes: 30 additions & 3 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -80,7 +80,7 @@ email : sherman at mrcc.com
#include <qcursor.h>

#include <QRubberBand>

#include <QApplication>

#include "qgis.h"
#include "qgsrect.h"
Expand Down Expand Up @@ -558,6 +558,10 @@ void QgsMapCanvas::render(QPaintDevice * theQPaintDevice)
{
if (!mCanvasProperties->drawing)
{

// Tell the user we're going to be a while
QApplication::setOverrideCursor(Qt::WaitCursor);

mCanvasProperties->drawing = true;
QPainter *paint = new QPainter();

Expand Down Expand Up @@ -747,10 +751,16 @@ void QgsMapCanvas::render(QPaintDevice * theQPaintDevice)
// Now do the call to the layer that actually does
// the rendering work!
//
ml->draw(paint, &r1, mCanvasProperties->coordXForm, this);
if (!ml->draw(paint, &r1, mCanvasProperties->coordXForm, this))
{
showError(ml);
}
if (split)
{
ml->draw(paint, &r2,mCanvasProperties->coordXForm, this);
if (!ml->draw(paint, &r2, mCanvasProperties->coordXForm, this))
{
showError(ml);
}
}
}
#ifdef QGISDEBUG
Expand Down Expand Up @@ -922,6 +932,9 @@ void QgsMapCanvas::render(QPaintDevice * theQPaintDevice)
paint->end();
mCanvasProperties->drawing = false;
delete paint;

// Tell the user we've finished going to be a while
QApplication::restoreOverrideCursor();
}
mCanvasProperties->dirty = false;

Expand Down Expand Up @@ -3345,3 +3358,17 @@ QgsPoint QgsMapCanvas::maybeInversePoint(QgsPoint point, const char whenmsg[])
}
return point;
}


void QgsMapCanvas::showError(QgsMapLayer * mapLayer)
{
QMessageBox::warning(
this,
mapLayer->errorCaptionString(),
tr("Could not draw") + " " + mapLayer->name() + " " + tr("because") + ":\n" +
mapLayer->errorCaptionString()
);

}

// ENDS
3 changes: 3 additions & 0 deletions src/gui/qgsmapcanvas.h
Expand Up @@ -339,6 +339,9 @@ public slots:
*/
QgsMapCanvas();

//! show whatever error is exposed by the QgsMapLayer.
void showError(QgsMapLayer * mapLayer);

/**
List to store the points of digitised lines and polygons
Expand Down
12 changes: 11 additions & 1 deletion src/gui/qgsmaplayer.cpp
Expand Up @@ -153,7 +153,7 @@ void QgsMapLayer::draw(QPainter *, QgsRect * viewExtent, int yTransform)
// std::cout << "In QgsMapLayer::draw" << std::endl;
}

void QgsMapLayer::draw(QPainter *, QgsRect *, QgsMapToPixel *,QPaintDevice * )
bool QgsMapLayer::draw(QPainter *, QgsRect *, QgsMapToPixel *,QPaintDevice * )
{
// std::cout << "In QgsMapLayer::draw" << std::endl;
}
Expand Down Expand Up @@ -499,6 +499,16 @@ std::vector<QgsField> const & QgsMapLayer::fields() const
return bogus;
} // QgsMapLayer::fields()

QString QgsMapLayer::errorCaptionString()
{
return QString();
}

QString QgsMapLayer::errorString()
{
return QString();
}

void QgsMapLayer::connectNotify( const char * signal )
{
#ifdef QGISDEBUG
Expand Down
24 changes: 23 additions & 1 deletion src/gui/qgsmaplayer.h
Expand Up @@ -99,7 +99,10 @@ class QgsMapLayer : public QObject


virtual void draw(QPainter *, QgsRect *, int);
virtual void draw(QPainter *, QgsRect *, QgsMapToPixel * ,QPaintDevice *);

//! Returns FALSE if an error occurred during drawing
virtual bool draw(QPainter *, QgsRect *, QgsMapToPixel *, QPaintDevice *);

virtual void drawLabels(QPainter *, QgsRect *, QgsMapToPixel * ,QPaintDevice *);
/*! Identify the feature(s) in this layer that are contained in the search rectangle
*/
Expand Down Expand Up @@ -284,6 +287,25 @@ class QgsMapLayer : public QObject

/** \brief accessor for transparency level. */
virtual unsigned int getTransparency()=0;


/**
* If an operation returns 0 (e.g. draw()), this function
* returns the text of the error associated with the failure.
* Interactive users of this provider can then, for example,
* call a QMessageBox to display the contents.
*/
QString errorCaptionString();

/**
* If an operation returns 0 (e.g. draw()), this function
* returns the text of the error associated with the failure.
* Interactive users of this provider can then, for example,
* call a QMessageBox to display the contents.
*/
QString errorString();


public slots:
/** \brief Mutator for transparency level. Should be between 0 and 255 */
virtual void setTransparency(int)=0; //
Expand Down

0 comments on commit 56ad39c

Please sign in to comment.