31
31
#include " qgsrenderer.h"
32
32
#include " qgssnappingdialog.h"
33
33
#include " qgsrasterlayer.h"
34
+ #include " qgsgenericprojectionselector.h"
35
+ #include " qgslogger.h"
34
36
35
37
// qt includes
36
38
#include < QColorDialog>
37
39
#include < QHeaderView> // Qt 4.4
38
- #include " qgslogger.h "
40
+ #include < QMessageBox >
39
41
40
42
// stdc++ includes
41
43
@@ -54,16 +56,16 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
54
56
// Properties stored in map canvas's QgsMapRenderer
55
57
// these ones are propagated to QgsProject by a signal
56
58
57
- QgsMapRenderer* myRender = mMapCanvas ->mapRenderer ();
58
- QGis::UnitType myUnit = myRender ->mapUnits ();
59
+ QgsMapRenderer* myRenderer = mMapCanvas ->mapRenderer ();
60
+ QGis::UnitType myUnit = myRenderer ->mapUnits ();
59
61
setMapUnits ( myUnit );
60
62
61
63
// see if the user wants on the fly projection enabled
62
- bool myProjectionEnabled = myRender ->hasCrsTransformEnabled ();
64
+ bool myProjectionEnabled = myRenderer ->hasCrsTransformEnabled ();
63
65
cbxProjectionEnabled->setChecked ( myProjectionEnabled );
64
66
btnGrpMapUnits->setEnabled ( !myProjectionEnabled );
65
67
66
- long myCRSID = myRender ->destinationSrs ().srsid ();
68
+ long myCRSID = myRenderer ->destinationSrs ().srsid ();
67
69
QgsDebugMsg ( " Read project CRSID: " + QString::number ( myCRSID ) );
68
70
projectionSelector->setSelectedCrsId ( myCRSID );
69
71
@@ -161,6 +163,39 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
161
163
twIdentifyLayers->setCellWidget ( i, 2 , cb );
162
164
}
163
165
166
+ grpWMSServiceCapabilities->setChecked ( QgsProject::instance ()->readBoolEntry ( " WMSServiceCapabilities" , " /" , false ) );
167
+ mWMSTitle ->setText ( QgsProject::instance ()->readEntry ( " WMSServiceTitle" , " /" ) );
168
+ mWMSContactOrganization ->setText ( QgsProject::instance ()->readEntry ( " WMSContactOrganization" , " /" , " " ) );
169
+ mWMSContactPerson ->setText ( QgsProject::instance ()->readEntry ( " WMSContactPerson" , " /" , " " ) );
170
+ mWMSContactMail ->setText ( QgsProject::instance ()->readEntry ( " WMSContactMail" , " /" , " " ) );
171
+ mWMSContactPhone ->setText ( QgsProject::instance ()->readEntry ( " WMSContactPhone" , " /" , " " ) );
172
+ mWMSAbstract ->setPlainText ( QgsProject::instance ()->readEntry ( " WMSServiceAbstract" , " /" , " " ) );
173
+
174
+ bool ok;
175
+ QStringList values;
176
+
177
+ mWMSExtMinX ->setValidator ( new QDoubleValidator ( mWMSExtMinX ) );
178
+ mWMSExtMinY ->setValidator ( new QDoubleValidator ( mWMSExtMinY ) );
179
+ mWMSExtMaxX ->setValidator ( new QDoubleValidator ( mWMSExtMaxX ) );
180
+ mWMSExtMaxY ->setValidator ( new QDoubleValidator ( mWMSExtMaxY ) );
181
+
182
+ values = QgsProject::instance ()->readListEntry ( " WMSExtent" , " /" , &ok );
183
+ grpWMSExt->setChecked ( ok && values.size () == 4 );
184
+ if ( grpWMSExt->isChecked () )
185
+ {
186
+ mWMSExtMinX ->setText ( values[0 ] );
187
+ mWMSExtMinY ->setText ( values[1 ] );
188
+ mWMSExtMaxX ->setText ( values[2 ] );
189
+ mWMSExtMaxY ->setText ( values[3 ] );
190
+ }
191
+
192
+ values = QgsProject::instance ()->readListEntry ( " WMSEpsgList" , " /" , &ok );
193
+ grpWMSList->setChecked ( ok && values.size () > 0 );
194
+ if ( grpWMSList->isChecked () )
195
+ {
196
+ mWMSList ->addItems ( values );
197
+ }
198
+
164
199
restoreState ();
165
200
}
166
201
@@ -243,11 +278,9 @@ void QgsProjectProperties::apply()
243
278
mapUnit = QGis::Degrees;
244
279
}
245
280
246
- QgsMapRenderer* myRender = mMapCanvas ->mapRenderer ();
247
-
248
- myRender->setMapUnits ( mapUnit );
249
-
250
- myRender->setProjectionsEnabled ( cbxProjectionEnabled->isChecked () );
281
+ QgsMapRenderer* myRenderer = mMapCanvas ->mapRenderer ();
282
+ myRenderer->setMapUnits ( mapUnit );
283
+ myRenderer->setProjectionsEnabled ( cbxProjectionEnabled->isChecked () );
251
284
252
285
// Only change the projection if there is a node in the tree
253
286
// selected that has an srid. This prevents error if the user
@@ -257,7 +290,7 @@ void QgsProjectProperties::apply()
257
290
if ( myCRSID )
258
291
{
259
292
QgsCoordinateReferenceSystem srs ( myCRSID, QgsCoordinateReferenceSystem::InternalCrsId );
260
- myRender ->setDestinationSrs ( srs );
293
+ myRenderer ->setDestinationSrs ( srs );
261
294
QgsDebugMsg ( QString ( " Selected CRS " ) + srs.description () );
262
295
// write the currently selected projections _proj string_ to project settings
263
296
QgsDebugMsg ( QString ( " SpatialRefSys/ProjectCRSProj4String: %1" ).arg ( projectionSelector->selectedProj4String () ) );
@@ -269,7 +302,7 @@ void QgsProjectProperties::apply()
269
302
// If we couldn't get the map units, default to the value in the
270
303
// projectproperties dialog box (set above)
271
304
if ( srs.mapUnits () != QGis::UnknownUnit )
272
- myRender ->setMapUnits ( srs.mapUnits () );
305
+ myRenderer ->setMapUnits ( srs.mapUnits () );
273
306
}
274
307
}
275
308
@@ -314,6 +347,49 @@ void QgsProjectProperties::apply()
314
347
315
348
QgsProject::instance ()->writeEntry ( " Identify" , " /disabledLayers" , noIdentifyLayerList );
316
349
350
+ QgsProject::instance ()->writeEntry ( " WMSServiceCapabilities" , " /" , grpWMSServiceCapabilities->isChecked () );
351
+ QgsProject::instance ()->writeEntry ( " WMSServiceTitle" , " /" , mWMSTitle ->text () );
352
+ QgsProject::instance ()->writeEntry ( " WMSContactOrganization" , " /" , mWMSContactOrganization ->text () );
353
+ QgsProject::instance ()->writeEntry ( " WMSContactPerson" , " /" , mWMSContactPerson ->text () );
354
+ QgsProject::instance ()->writeEntry ( " WMSContactMail" , " /" , mWMSContactMail ->text () );
355
+ QgsProject::instance ()->writeEntry ( " WMSContactPhone" , " /" , mWMSContactPhone ->text () );
356
+ QgsProject::instance ()->writeEntry ( " WMSServiceAbstract" , " /" , mWMSAbstract ->toPlainText () );
357
+
358
+ if ( grpWMSExt->isChecked () )
359
+ {
360
+ QgsProject::instance ()->writeEntry ( " WMSExtent" , " /" ,
361
+ QStringList ()
362
+ << mWMSExtMinX ->text ()
363
+ << mWMSExtMinY ->text ()
364
+ << mWMSExtMaxX ->text ()
365
+ << mWMSExtMaxY ->text () );
366
+ }
367
+ else
368
+ {
369
+ QgsProject::instance ()->removeEntry ( " WMSExtent" , " /" );
370
+ }
371
+
372
+ if ( grpWMSList->isChecked () && mWMSList ->count () == 0 )
373
+ {
374
+ QMessageBox::information ( this , tr ( " Coordinate System Restriction" ), tr ( " No coordinate systems selected. Disabling restriction." ) );
375
+ grpWMSList->setChecked ( false );
376
+ }
377
+
378
+ if ( grpWMSList->isChecked () )
379
+ {
380
+ QStringList crslist;
381
+ for ( int i = 0 ; i < mWMSList ->count (); i++ )
382
+ {
383
+ crslist << mWMSList ->item ( i )->text ();
384
+ }
385
+
386
+ QgsProject::instance ()->writeEntry ( " WMSEpsgList" , " /" , crslist );
387
+ }
388
+ else
389
+ {
390
+ QgsProject::instance ()->removeEntry ( " WMSEpsgList" , " /" );
391
+ }
392
+
317
393
// todo XXX set canvas color
318
394
emit refresh ();
319
395
}
@@ -403,3 +479,81 @@ void QgsProjectProperties::restoreState()
403
479
restoreGeometry ( settings.value ( " /Windows/ProjectProperties/geometry" ).toByteArray () );
404
480
tabWidget->setCurrentIndex ( settings.value ( " /Windows/ProjectProperties/tab" ).toInt () );
405
481
}
482
+
483
+ /* !
484
+ * Set WMS default extent to current canvas extent
485
+ */
486
+ void QgsProjectProperties::on_pbnWMSExtCanvas_clicked ()
487
+ {
488
+ QgsRectangle ext = mMapCanvas ->extent ();
489
+ mWMSExtMinX ->setText ( QString::number ( ext.xMinimum () ) );
490
+ mWMSExtMinY ->setText ( QString::number ( ext.yMinimum () ) );
491
+ mWMSExtMaxX ->setText ( QString::number ( ext.xMaximum () ) );
492
+ mWMSExtMaxY ->setText ( QString::number ( ext.yMaximum () ) );
493
+ }
494
+
495
+ void QgsProjectProperties::on_pbnWMSAddSRS_clicked ()
496
+ {
497
+ QgsGenericProjectionSelector *mySelector = new QgsGenericProjectionSelector ( this );
498
+ mySelector->setMessage ();
499
+ if ( mySelector->exec () )
500
+ {
501
+ long crs = mySelector->selectedEpsg ();
502
+
503
+ if ( crs > 0 )
504
+ {
505
+ QList<QListWidgetItem *> items = mWMSList ->findItems ( QString::number ( crs ), Qt::MatchFixedString );
506
+ if ( items.size () == 0 )
507
+ {
508
+ mWMSList ->addItem ( QString::number ( crs ) );
509
+ }
510
+ else
511
+ {
512
+ QMessageBox::information ( this , tr ( " Coordinate System Restriction" ), tr ( " CRS %1 was already selected" ).arg ( crs ) );
513
+ }
514
+ }
515
+ else
516
+ {
517
+ QMessageBox::information ( this , tr ( " Coordinate System Restriction" ), tr ( " Selected CRS is not a EPSG coordinate system." ) );
518
+ }
519
+ }
520
+
521
+ delete mySelector;
522
+ }
523
+
524
+ void QgsProjectProperties::on_pbnWMSRemoveSRS_clicked ()
525
+ {
526
+ foreach ( QListWidgetItem *item, mWMSList ->selectedItems () )
527
+ delete item;
528
+ }
529
+
530
+ void QgsProjectProperties::on_pbnWMSSetUsedSRS_clicked ()
531
+ {
532
+ if ( mWMSList ->count () > 1 )
533
+ {
534
+ if ( QMessageBox::question ( this ,
535
+ tr ( " Coordinate System Restrictions" ),
536
+ tr ( " The current selection of coordinate systems will be lost.\n Proceed?" ) ) == QMessageBox::No )
537
+ return ;
538
+ }
539
+
540
+ QSet<QString> crsList;
541
+
542
+ if ( cbxProjectionEnabled->isChecked () )
543
+ {
544
+ QgsCoordinateReferenceSystem srs ( projectionSelector->selectedCrsId (), QgsCoordinateReferenceSystem::InternalCrsId );
545
+ if ( srs.epsg () > 0 )
546
+ crsList << QString::number ( srs.epsg () );
547
+ }
548
+
549
+ const QMap<QString, QgsMapLayer*> &mapLayers = QgsMapLayerRegistry::instance ()->mapLayers ();
550
+ for ( QMap<QString, QgsMapLayer*>::const_iterator it = mapLayers.constBegin (); it != mapLayers.constEnd (); it++ )
551
+ {
552
+ long crs = it.value ()->crs ().epsg ();
553
+ if ( crs > 0 )
554
+ crsList << QString::number ( crs );
555
+ }
556
+
557
+ mWMSList ->clear ();
558
+ mWMSList ->addItems ( crsList.values () );
559
+ }
0 commit comments