Skip to content

Commit b9aaa49

Browse files
author
jef
committed
allow setting mapserver service properties in project properties
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15159 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 55cd73d commit b9aaa49

File tree

3 files changed

+443
-24
lines changed

3 files changed

+443
-24
lines changed

src/app/qgsprojectproperties.cpp

Lines changed: 166 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@
3131
#include "qgsrenderer.h"
3232
#include "qgssnappingdialog.h"
3333
#include "qgsrasterlayer.h"
34+
#include "qgsgenericprojectionselector.h"
35+
#include "qgslogger.h"
3436

3537
//qt includes
3638
#include <QColorDialog>
3739
#include <QHeaderView> // Qt 4.4
38-
#include "qgslogger.h"
40+
#include <QMessageBox>
3941

4042
//stdc++ includes
4143

@@ -54,16 +56,16 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
5456
// Properties stored in map canvas's QgsMapRenderer
5557
// these ones are propagated to QgsProject by a signal
5658

57-
QgsMapRenderer* myRender = mMapCanvas->mapRenderer();
58-
QGis::UnitType myUnit = myRender->mapUnits();
59+
QgsMapRenderer* myRenderer = mMapCanvas->mapRenderer();
60+
QGis::UnitType myUnit = myRenderer->mapUnits();
5961
setMapUnits( myUnit );
6062

6163
//see if the user wants on the fly projection enabled
62-
bool myProjectionEnabled = myRender->hasCrsTransformEnabled();
64+
bool myProjectionEnabled = myRenderer->hasCrsTransformEnabled();
6365
cbxProjectionEnabled->setChecked( myProjectionEnabled );
6466
btnGrpMapUnits->setEnabled( !myProjectionEnabled );
6567

66-
long myCRSID = myRender->destinationSrs().srsid();
68+
long myCRSID = myRenderer->destinationSrs().srsid();
6769
QgsDebugMsg( "Read project CRSID: " + QString::number( myCRSID ) );
6870
projectionSelector->setSelectedCrsId( myCRSID );
6971

@@ -161,6 +163,39 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
161163
twIdentifyLayers->setCellWidget( i, 2, cb );
162164
}
163165

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+
164199
restoreState();
165200
}
166201

@@ -243,11 +278,9 @@ void QgsProjectProperties::apply()
243278
mapUnit = QGis::Degrees;
244279
}
245280

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() );
251284

252285
// Only change the projection if there is a node in the tree
253286
// selected that has an srid. This prevents error if the user
@@ -257,7 +290,7 @@ void QgsProjectProperties::apply()
257290
if ( myCRSID )
258291
{
259292
QgsCoordinateReferenceSystem srs( myCRSID, QgsCoordinateReferenceSystem::InternalCrsId );
260-
myRender->setDestinationSrs( srs );
293+
myRenderer->setDestinationSrs( srs );
261294
QgsDebugMsg( QString( "Selected CRS " ) + srs.description() );
262295
// write the currently selected projections _proj string_ to project settings
263296
QgsDebugMsg( QString( "SpatialRefSys/ProjectCRSProj4String: %1" ).arg( projectionSelector->selectedProj4String() ) );
@@ -269,7 +302,7 @@ void QgsProjectProperties::apply()
269302
// If we couldn't get the map units, default to the value in the
270303
// projectproperties dialog box (set above)
271304
if ( srs.mapUnits() != QGis::UnknownUnit )
272-
myRender->setMapUnits( srs.mapUnits() );
305+
myRenderer->setMapUnits( srs.mapUnits() );
273306
}
274307
}
275308

@@ -314,6 +347,49 @@ void QgsProjectProperties::apply()
314347

315348
QgsProject::instance()->writeEntry( "Identify", "/disabledLayers", noIdentifyLayerList );
316349

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+
317393
//todo XXX set canvas color
318394
emit refresh();
319395
}
@@ -403,3 +479,81 @@ void QgsProjectProperties::restoreState()
403479
restoreGeometry( settings.value( "/Windows/ProjectProperties/geometry" ).toByteArray() );
404480
tabWidget->setCurrentIndex( settings.value( "/Windows/ProjectProperties/tab" ).toInt() );
405481
}
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.\nProceed?" ) ) == 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+
}

src/app/qgsprojectproperties.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ class QgsProjectProperties : public QDialog, private Ui::QgsProjectPropertiesBas
8484
*/
8585
void on_pbnCanvasColor_clicked();
8686

87+
/*!
88+
* Slots for WMS project settings
89+
*/
90+
void on_pbnWMSExtCanvas_clicked();
91+
void on_pbnWMSAddSRS_clicked();
92+
void on_pbnWMSRemoveSRS_clicked();
93+
void on_pbnWMSSetUsedSRS_clicked();
94+
8795
/*!
8896
* Slot to show the context help for this dialog
8997
*/

0 commit comments

Comments
 (0)