Skip to content
Permalink
Browse files

Show a progress dialog for wfs if there is a main window (to not cras…

…h non-graphical applications using wfs provider)

git-svn-id: http://svn.osgeo.org/qgis/trunk@10090 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Feb 2, 2009
1 parent 9740123 commit bacd648fa52a4410e727ae0958d2f4a221e81a5d
Showing with 53 additions and 2 deletions.
  1. +43 −2 src/providers/wfs/qgswfsdata.cpp
  2. +10 −0 src/providers/wfs/qgswfsdata.h
@@ -19,6 +19,7 @@
#include <QBuffer>
#include <QUrl>
#include <QList>
#include <QProgressDialog>
#include <QSet>

//just for a test
@@ -92,6 +93,21 @@ int QgsWFSData::getWFSData()

QgsHttpTransaction::applyProxySettings( mHttp, mUri );

//find out if there is a QGIS main window. If yes, display a progress dialog
QProgressDialog* progressDialog = 0;
QWidget* mainWindow = findMainWindow();

if(mainWindow)
{
progressDialog = new QProgressDialog(tr("Loading WFS data"), tr("Abort"), 0, 0, mainWindow);
progressDialog->setWindowModality(Qt::ApplicationModal);
connect(&mHttp, SIGNAL(dataReadProgress(int, int)), this, SLOT(handleProgressEvent(int, int)));
connect(this, SIGNAL(dataReadProgress(int)), progressDialog, SLOT(setValue(int)));
connect(this, SIGNAL(totalStepsUpdate(int)), progressDialog, SLOT(setMaximum(int)));
connect(progressDialog, SIGNAL(canceled()), &mHttp, SLOT(abort()));
progressDialog->show();
}

//mHttp.get( mUri );
mHttp.get( requestUrl.path() + "?" + QString( requestUrl.encodedQuery() ) );

@@ -111,9 +127,11 @@ int QgsWFSData::getWFSData()
readData = mHttp.readAll();
XML_Parse( p, readData.data(), readData.size(), atEnd );
}
qApp->processEvents( QEventLoop::ExcludeUserInputEvents );
qApp->processEvents();
}
qWarning( "Left loop" );

delete progressDialog;

return 0; //soon
}

@@ -131,6 +149,12 @@ void QgsWFSData::setFinished( bool error )
mFinished = true;
}

void QgsWFSData::handleProgressEvent(int progress, int totalSteps)
{
emit dataReadProgress(progress);
emit totalStepsUpdate(totalSteps);
}

void QgsWFSData::startElement( const XML_Char* el, const XML_Char** attr )
{
QString elementName( el );
@@ -755,3 +779,20 @@ int QgsWFSData::totalWKBFragmentSize() const
}
return result;
}

QWidget* QgsWFSData::findMainWindow() const
{
QWidget* mainWindow = 0;

QWidgetList topLevelWidgets = qApp->topLevelWidgets();
QWidgetList::iterator it = topLevelWidgets.begin();
for ( ; it != topLevelWidgets.end(); ++it )
{
if (( *it )->objectName() == "QgisApp" )
{
mainWindow = *it;
break;
}
}
return mainWindow;
}
@@ -57,6 +57,13 @@ class QgsWFSData: public QObject
private slots:
void setFinished( bool error );

/**Takes progress value and total steps and emit signals 'dataReadProgress' and 'totalStepUpdate'*/
void handleProgressEvent(int progress, int totalSteps);

signals:
void dataReadProgress(int progress);
void totalStepsUpdate(int totalSteps);

private:

enum parseMode
@@ -126,6 +133,9 @@ class QgsWFSData: public QObject
/**Adds all the integers contained in mCurrentWKBFragmentSizes*/
int totalWKBFragmentSize() const;

/**Returns pointer to main window or 0 if it does not exist*/
QWidget* findMainWindow() const;

QString mUri;
//results are members such that handler routines are able to manipulate them
/**Bounding box of the layer*/

0 comments on commit bacd648

Please sign in to comment.
You can’t perform that action at this time.