Skip to content

Commit

Permalink
Show a progress dialog for wfs if there is a main window (to not cras…
Browse files Browse the repository at this point in the history
…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 committed Feb 2, 2009
1 parent 9740123 commit bacd648
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
45 changes: 43 additions & 2 deletions src/providers/wfs/qgswfsdata.cpp
Expand Up @@ -19,6 +19,7 @@
#include <QBuffer>
#include <QUrl>
#include <QList>
#include <QProgressDialog>
#include <QSet>

//just for a test
Expand Down Expand Up @@ -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() ) );

Expand All @@ -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
}

Expand All @@ -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 );
Expand Down Expand Up @@ -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;
}
10 changes: 10 additions & 0 deletions src/providers/wfs/qgswfsdata.h
Expand Up @@ -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
Expand Down Expand Up @@ -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*/
Expand Down

0 comments on commit bacd648

Please sign in to comment.