Skip to content

Commit d5ff56c

Browse files
author
mhugent
committed
Show a progress dialog for wfs if there is a main window (to not crash non-graphical applications using wfs provider)
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@10090 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 39b3b9b commit d5ff56c

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

src/providers/wfs/qgswfsdata.cpp

+43-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <QBuffer>
2020
#include <QUrl>
2121
#include <QList>
22+
#include <QProgressDialog>
2223
#include <QSet>
2324

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

9394
QgsHttpTransaction::applyProxySettings( mHttp, mUri );
9495

96+
//find out if there is a QGIS main window. If yes, display a progress dialog
97+
QProgressDialog* progressDialog = 0;
98+
QWidget* mainWindow = findMainWindow();
99+
100+
if(mainWindow)
101+
{
102+
progressDialog = new QProgressDialog(tr("Loading WFS data"), tr("Abort"), 0, 0, mainWindow);
103+
progressDialog->setWindowModality(Qt::ApplicationModal);
104+
connect(&mHttp, SIGNAL(dataReadProgress(int, int)), this, SLOT(handleProgressEvent(int, int)));
105+
connect(this, SIGNAL(dataReadProgress(int)), progressDialog, SLOT(setValue(int)));
106+
connect(this, SIGNAL(totalStepsUpdate(int)), progressDialog, SLOT(setMaximum(int)));
107+
connect(progressDialog, SIGNAL(canceled()), &mHttp, SLOT(abort()));
108+
progressDialog->show();
109+
}
110+
95111
//mHttp.get( mUri );
96112
mHttp.get( requestUrl.path() + "?" + QString( requestUrl.encodedQuery() ) );
97113

@@ -111,9 +127,11 @@ int QgsWFSData::getWFSData()
111127
readData = mHttp.readAll();
112128
XML_Parse( p, readData.data(), readData.size(), atEnd );
113129
}
114-
qApp->processEvents( QEventLoop::ExcludeUserInputEvents );
130+
qApp->processEvents();
115131
}
116-
qWarning( "Left loop" );
132+
133+
delete progressDialog;
134+
117135
return 0; //soon
118136
}
119137

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

152+
void QgsWFSData::handleProgressEvent(int progress, int totalSteps)
153+
{
154+
emit dataReadProgress(progress);
155+
emit totalStepsUpdate(totalSteps);
156+
}
157+
134158
void QgsWFSData::startElement( const XML_Char* el, const XML_Char** attr )
135159
{
136160
QString elementName( el );
@@ -755,3 +779,20 @@ int QgsWFSData::totalWKBFragmentSize() const
755779
}
756780
return result;
757781
}
782+
783+
QWidget* QgsWFSData::findMainWindow() const
784+
{
785+
QWidget* mainWindow = 0;
786+
787+
QWidgetList topLevelWidgets = qApp->topLevelWidgets();
788+
QWidgetList::iterator it = topLevelWidgets.begin();
789+
for ( ; it != topLevelWidgets.end(); ++it )
790+
{
791+
if (( *it )->objectName() == "QgisApp" )
792+
{
793+
mainWindow = *it;
794+
break;
795+
}
796+
}
797+
return mainWindow;
798+
}

src/providers/wfs/qgswfsdata.h

+10
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ class QgsWFSData: public QObject
5757
private slots:
5858
void setFinished( bool error );
5959

60+
/**Takes progress value and total steps and emit signals 'dataReadProgress' and 'totalStepUpdate'*/
61+
void handleProgressEvent(int progress, int totalSteps);
62+
63+
signals:
64+
void dataReadProgress(int progress);
65+
void totalStepsUpdate(int totalSteps);
66+
6067
private:
6168

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

136+
/**Returns pointer to main window or 0 if it does not exist*/
137+
QWidget* findMainWindow() const;
138+
129139
QString mUri;
130140
//results are members such that handler routines are able to manipulate them
131141
/**Bounding box of the layer*/

0 commit comments

Comments
 (0)