45
45
#include < QMenuBar>
46
46
#include < QMenuItem>
47
47
#include < QMessageBox>
48
- #include < QNetworkProxy>
49
48
#include < QPainter>
50
49
#include < QPictureIO>
51
50
#include < QPixmap>
67
66
#include < QToolButton>
68
67
#include < QVBoxLayout>
69
68
#include < QWhatsThis>
69
+
70
+ #include < QNetworkAccessManager>
71
+ #include < QNetworkDiskCache>
72
+ #include < QNetworkReply>
73
+ #include < QNetworkProxy>
74
+ #include < QAuthenticator>
75
+
70
76
//
71
77
// Mac OS X Includes
72
78
// Must include before GEOS 3 due to unqualified use of 'Point'
@@ -328,12 +334,12 @@ QgisApp *QgisApp::smInstance = 0;
328
334
329
335
// constructor starts here
330
336
QgisApp::QgisApp ( QSplashScreen *splash, bool restorePlugins, QWidget * parent, Qt::WFlags fl )
331
- : QMainWindow( parent, fl ),
332
- mSplash( splash ),
333
- mPythonUtils( NULL )
337
+ : QMainWindow( parent, fl )
338
+ , mSplash( splash )
339
+ , mPythonUtils( NULL )
340
+ , mNAM( NULL )
334
341
#ifdef HAVE_QWT
335
- ,
336
- mpGpsWidget ( NULL )
342
+ , mpGpsWidget( NULL )
337
343
#endif
338
344
{
339
345
if ( smInstance )
@@ -347,6 +353,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
347
353
348
354
smInstance = this ;
349
355
356
+ namSetup ();
357
+
350
358
// setupUi(this);
351
359
resize ( 640 , 480 );
352
360
@@ -1841,6 +1849,9 @@ void QgisApp::setupConnections()
1841
1849
connect ( mMapCanvas , SIGNAL ( layersChanged () ), this , SLOT ( markDirty () ) );
1842
1850
connect ( mMapLegend , SIGNAL ( zOrderChanged () ), this , SLOT ( markDirty () ) );
1843
1851
1852
+ connect ( QgsMapLayerRegistry::instance (), SIGNAL ( layerWasAdded ( QgsMapLayer * ) ),
1853
+ this , SLOT ( layerWasAdded ( QgsMapLayer * ) ) );
1854
+
1844
1855
connect ( mRenderSuppressionCBox , SIGNAL ( toggled ( bool ) ), mMapCanvas , SLOT ( setRenderFlag ( bool ) ) );
1845
1856
//
1846
1857
// Do we really need this ??? - its already connected to the esc key...TS
@@ -4468,11 +4479,7 @@ void QgisApp::loadPythonSupport()
4468
4479
#endif
4469
4480
QString version = QString ( " %1.%2.%3" ).arg ( QGis::QGIS_VERSION_INT / 10000 ).arg ( QGis::QGIS_VERSION_INT / 100 % 100 ).arg ( QGis::QGIS_VERSION_INT % 100 );
4470
4481
QgsDebugMsg ( QString ( " load library %1 (%2)" ).arg ( pythonlibName ).arg ( version ) );
4471
- #if QT_VERSION >= 0x040400
4472
4482
QLibrary pythonlib ( pythonlibName, version );
4473
- #else
4474
- QLibrary pythonlib ( pythonlibName );
4475
- #endif
4476
4483
// It's necessary to set these two load hints, otherwise Python library won't work correctly
4477
4484
// see http://lists.kde.org/?l=pykde&m=117190116820758&w=2
4478
4485
pythonlib.setLoadHints ( QLibrary::ResolveAllSymbolsHint | QLibrary::ExportExternalSymbolsHint );
@@ -5074,6 +5081,25 @@ void QgisApp::markDirty()
5074
5081
QgsProject::instance ()->dirty ( true );
5075
5082
}
5076
5083
5084
+ void QgisApp::layerWasAdded ( QgsMapLayer *layer )
5085
+ {
5086
+ QgsDataProvider *provider = 0 ;
5087
+
5088
+ QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
5089
+ if ( vlayer )
5090
+ provider = vlayer->dataProvider ();
5091
+
5092
+ QgsRasterLayer *rlayer = qobject_cast<QgsRasterLayer *>( layer );
5093
+ if ( rlayer )
5094
+ provider = rlayer->dataProvider ();
5095
+
5096
+ if ( provider )
5097
+ {
5098
+ connect ( provider, SIGNAL ( dataChanged () ), layer, SLOT ( clearCacheImage () ) );
5099
+ connect ( provider, SIGNAL ( dataChanged () ), mMapCanvas , SLOT ( refresh () ) );
5100
+ }
5101
+ }
5102
+
5077
5103
void QgisApp::showExtents ()
5078
5104
{
5079
5105
if ( !mToggleExtentsViewButton ->isChecked () )
@@ -5194,7 +5220,7 @@ void QgisApp::projectProperties()
5194
5220
SLOT ( updateMouseCoordinatePrecision () ) );
5195
5221
QApplication::restoreOverrideCursor ();
5196
5222
5197
- // pass any refresg signals off to canvases
5223
+ // pass any refresh signals off to canvases
5198
5224
// Line below was commented out by wonder three years ago (r4949).
5199
5225
// It is needed to refresh scale bar after changing display units.
5200
5226
connect ( pp, SIGNAL ( refresh () ), mMapCanvas , SLOT ( refresh () ) );
@@ -5345,12 +5371,14 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
5345
5371
mActionCapturePoint ->setEnabled ( true );
5346
5372
mActionCapturePoint ->setVisible ( true );
5347
5373
mActionDeletePart ->setEnabled ( true );
5374
+ mActionAddIsland ->setEnabled ( true );
5348
5375
}
5349
5376
else
5350
5377
{
5351
5378
mActionCapturePoint ->setEnabled ( false );
5352
5379
mActionCapturePoint ->setVisible ( false );
5353
5380
mActionDeletePart ->setEnabled ( false );
5381
+ mActionAddIsland ->setEnabled ( false );
5354
5382
}
5355
5383
mActionCaptureLine ->setEnabled ( false );
5356
5384
mActionCapturePolygon ->setEnabled ( false );
@@ -5362,6 +5390,9 @@ void QgisApp::activateDeactivateLayerRelatedActions( QgsMapLayer* layer )
5362
5390
mActionMoveVertex->setEnabled( false );
5363
5391
#endif
5364
5392
mActionAddRing ->setEnabled ( false );
5393
+ #if 0
5394
+ mActionAddIsland->setEnabled( false );
5395
+ #endif
5365
5396
mActionAddIsland ->setEnabled ( false );
5366
5397
mActionReshapeFeatures ->setEnabled ( false );
5367
5398
mActionSplitFeatures ->setEnabled ( false );
@@ -5608,6 +5639,7 @@ bool QgisApp::addRasterLayer( QgsRasterLayer * theRasterLayer )
5608
5639
SIGNAL ( drawingProgress ( int , int ) ),
5609
5640
this ,
5610
5641
SLOT ( showProgress ( int , int ) ) );
5642
+
5611
5643
// connect up any request the raster may make to update the statusbar message
5612
5644
QObject::connect ( theRasterLayer,
5613
5645
SIGNAL ( statusChanged ( QString ) ),
@@ -5681,13 +5713,14 @@ QgsRasterLayer* QgisApp::addRasterLayer( QString const & rasterFile, QString con
5681
5713
\note Copied from the equivalent addVectorLayer function in this file
5682
5714
TODO Make it work for rasters specifically.
5683
5715
*/
5684
- QgsRasterLayer* QgisApp::addRasterLayer ( QString const & rasterLayerPath,
5685
- QString const & baseName,
5686
- QString const & providerKey,
5687
- QStringList const & layers,
5688
- QStringList const & styles,
5689
- QString const & format,
5690
- QString const & crs )
5716
+ QgsRasterLayer* QgisApp::addRasterLayer (
5717
+ QString const &rasterLayerPath,
5718
+ QString const &baseName,
5719
+ QString const &providerKey,
5720
+ QStringList const & layers,
5721
+ QStringList const & styles,
5722
+ QString const &format,
5723
+ QString const &crs )
5691
5724
{
5692
5725
QgsDebugMsg ( " about to get library for " + providerKey );
5693
5726
@@ -6127,3 +6160,115 @@ void QgisApp::showLayerProperties( QgsMapLayer *ml )
6127
6160
6128
6161
}
6129
6162
}
6163
+
6164
+ void QgisApp::namSetup ()
6165
+ {
6166
+ if ( mNAM )
6167
+ return ;
6168
+
6169
+ mNAM = new QNetworkAccessManager ( this );
6170
+
6171
+ namUpdate ();
6172
+
6173
+ connect ( mNAM , SIGNAL ( authenticationRequired ( QNetworkReply *, QAuthenticator * ) ),
6174
+ this , SLOT ( namAuthenticationRequired ( QNetworkReply *, QAuthenticator * ) ) );
6175
+
6176
+ connect ( mNAM , SIGNAL ( proxyAuthenticationRequired ( const QNetworkProxy &, QAuthenticator * ) ),
6177
+ this , SLOT ( namProxyAuthenticationRequired ( const QNetworkProxy &, QAuthenticator * ) ) );
6178
+
6179
+ QCoreApplication::instance ()->setProperty ( " qgisNetworkAccessManager" , qVariantFromValue<QObject*>( mNAM ) );
6180
+ }
6181
+
6182
+ QNetworkAccessManager *QgisApp::nam ()
6183
+ {
6184
+ namSetup ();
6185
+ return mNAM ;
6186
+ }
6187
+
6188
+ void QgisApp::namAuthenticationRequired ( QNetworkReply *reply, QAuthenticator *auth )
6189
+ {
6190
+ QString username = auth->user ();
6191
+ QString password = auth->password ();
6192
+
6193
+ bool ok = QgsCredentials::instance ()->get (
6194
+ QString ( " %1 at %2" ).arg ( auth->realm () ).arg ( reply->url ().host () ),
6195
+ username, password,
6196
+ tr ( " Authentication required" ) );
6197
+ if ( !ok )
6198
+ return ;
6199
+
6200
+ auth->setUser ( username );
6201
+ auth->setPassword ( password );
6202
+ }
6203
+
6204
+ void QgisApp::namProxyAuthenticationRequired ( const QNetworkProxy &proxy, QAuthenticator *auth )
6205
+ {
6206
+ QString username = auth->user ();
6207
+ QString password = auth->password ();
6208
+
6209
+ bool ok = QgsCredentials::instance ()->get (
6210
+ QString ( " proxy %1:%2 [%3]" ).arg ( proxy.hostName () ).arg ( proxy.port () ).arg ( auth->realm () ),
6211
+ username, password,
6212
+ tr ( " Proxy authentication required" ) );
6213
+ if ( !ok )
6214
+ return ;
6215
+
6216
+ auth->setUser ( username );
6217
+ auth->setPassword ( password );
6218
+ }
6219
+
6220
+ void QgisApp::namUpdate ()
6221
+ {
6222
+ QSettings settings;
6223
+
6224
+ // read type, host, port, user, passw from settings
6225
+ QString proxyHost = settings.value ( " proxy/proxyHost" , " " ).toString ();
6226
+ int proxyPort = settings.value ( " proxy/proxyPort" , " " ).toString ().toInt ();
6227
+ QString proxyUser = settings.value ( " proxy/proxyUser" , " " ).toString ();
6228
+ QString proxyPassword = settings.value ( " proxy/proxyPassword" , " " ).toString ();
6229
+
6230
+ QString proxyTypeString = settings.value ( " proxy/proxyType" , " " ).toString ();
6231
+ QNetworkProxy::ProxyType proxyType = QNetworkProxy::NoProxy;
6232
+ if ( proxyTypeString == " DefaultProxy" )
6233
+ {
6234
+ proxyType = QNetworkProxy::DefaultProxy;
6235
+ }
6236
+ else if ( proxyTypeString == " Socks5Proxy" )
6237
+ {
6238
+ proxyType = QNetworkProxy::Socks5Proxy;
6239
+ }
6240
+ else if ( proxyTypeString == " HttpProxy" )
6241
+ {
6242
+ proxyType = QNetworkProxy::HttpProxy;
6243
+ }
6244
+ else if ( proxyTypeString == " HttpCachingProxy" )
6245
+ {
6246
+ proxyType = QNetworkProxy::HttpCachingProxy;
6247
+ }
6248
+ else if ( proxyTypeString == " FtpCachingProxy" )
6249
+ {
6250
+ proxyType = QNetworkProxy::FtpCachingProxy;
6251
+ }
6252
+ QgsDebugMsg ( QString ( " setting proxy %1 %2:%3 %4/%5" )
6253
+ .arg ( proxyType )
6254
+ .arg ( proxyHost ).arg ( proxyPort )
6255
+ .arg ( proxyUser ).arg ( proxyPassword )
6256
+ );
6257
+ nam ()->setProxy ( QNetworkProxy ( proxyType, proxyHost, proxyPort, proxyUser, proxyPassword ) );
6258
+
6259
+ QNetworkDiskCache *cache = qobject_cast<QNetworkDiskCache*>( nam ()->cache () );
6260
+ if ( !cache )
6261
+ cache = new QNetworkDiskCache ( this );
6262
+
6263
+ QString cacheDirectory = settings.value ( " cache/directory" , QgsApplication::qgisSettingsDirPath () + " cache" ).toString ();
6264
+ qint64 cacheSize = settings.value ( " cache/size" , 50 * 1024 * 1024 ).toULongLong ();
6265
+ QgsDebugMsg ( QString ( " setCacheDirectory: %1" ).arg ( cacheDirectory ) );
6266
+ QgsDebugMsg ( QString ( " setMaximumCacheSize: %1" ).arg ( cacheSize ) );
6267
+ cache->setCacheDirectory ( cacheDirectory );
6268
+ cache->setMaximumCacheSize ( cacheSize );
6269
+ QgsDebugMsg ( QString ( " cacheDirectory: %1" ).arg ( cache->cacheDirectory () ) );
6270
+ QgsDebugMsg ( QString ( " maximumCacheSize: %1" ).arg ( cache->maximumCacheSize () ) );
6271
+
6272
+ if ( mNAM ->cache () != cache )
6273
+ mNAM ->setCache ( cache );
6274
+ }
0 commit comments