Skip to content
Permalink
Browse files

[FEATURE]: possibility to overwrite wms url for capabilities document…

… in project properties
  • Loading branch information
mhugent committed Jul 31, 2012
1 parent de20264 commit dbad8734885e3f340ce62240404ed77b880f46bc
@@ -207,6 +207,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
mWMSContactPhone->setText( QgsProject::instance()->readEntry( "WMSContactPhone", "/", "" ) );
mWMSAbstract->setPlainText( QgsProject::instance()->readEntry( "WMSServiceAbstract", "/", "" ) );
mWMSOnlineResourceLineEdit->setText( QgsProject::instance()->readEntry( "WMSOnlineResource", "/", "" ) );
mWMSUrlLineEdit->setText( QgsProject::instance()->readEntry( "WMSUrl", "/", "" ) );

bool ok;
QStringList values;
@@ -489,6 +490,7 @@ void QgsProjectProperties::apply()
QgsProject::instance()->writeEntry( "WMSContactPhone", "/", mWMSContactPhone->text() );
QgsProject::instance()->writeEntry( "WMSServiceAbstract", "/", mWMSAbstract->toPlainText() );
QgsProject::instance()->writeEntry( "WMSOnlineResource", "/", mWMSOnlineResourceLineEdit->text() );
QgsProject::instance()->writeEntry( "WMSUrl", "/", mWMSUrlLineEdit->text() );

if ( grpWMSExt->isChecked() )
{
@@ -118,6 +118,9 @@ class QgsConfigParser
/**Appends service metadata to the capabilities document*/
virtual void serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const;

/**Returns service Adress (or empty string if not defined in the configuration*/
virtual QString serviceUrl() const { return QString(); }

QColor selectionColor() const { return mSelectionColor; }
void setSelectionColor( const QColor& c ) { mSelectionColor = c; }

@@ -1479,6 +1479,27 @@ void QgsProjectParser::serviceCapabilities( QDomElement& parentElement, QDomDocu
parentElement.appendChild( serviceElem );
}

QString QgsProjectParser::serviceUrl() const
{
QString url;

if( !mXMLDoc )
{
return url;
}

QDomElement propertiesElem = mXMLDoc->documentElement().firstChildElement( "properties" );
if ( !propertiesElem.isNull() )
{
QDomElement wmsUrlElem = propertiesElem.firstChildElement( "WMSUrl" );
if ( !wmsUrlElem.isNull() )
{
url = wmsUrlElem.text();
}
}
return url;
}

QString QgsProjectParser::convertToAbsolutePath( const QString& file ) const
{
if ( !file.startsWith( "./" ) && !file.startsWith( "../" ) )
@@ -106,6 +106,8 @@ class QgsProjectParser: public QgsConfigParser
/**Reads service metadata from projectfile or falls back to parent class method if not there*/
void serviceCapabilities( QDomElement& parentElement, QDomDocument& doc ) const;

QString serviceUrl() const;

private:

//forbidden
@@ -127,58 +127,11 @@ QDomDocument QgsWMSServer::getCapabilities( QString version )
requestElement.appendChild( elem );

//Prepare url
//Some client requests already have http://<SERVER_NAME> in the REQUEST_URI variable
QString hrefString;
QString requestUrl = getenv( "REQUEST_URI" );
QUrl mapUrl( requestUrl );
mapUrl.setHost( getenv( "SERVER_NAME" ) );

//Add non-default ports to url
QString portString = getenv( "SERVER_PORT" );
if ( !portString.isEmpty() )
{
bool portOk;
int portNumber = portString.toInt( &portOk );
if ( portOk )
{
if ( portNumber != 80 )
{
mapUrl.setPort( portNumber );
}
}
}

if ( QString( getenv( "HTTPS" ) ).compare( "on", Qt::CaseInsensitive ) == 0 )
{
mapUrl.setScheme( "https" );
}
else
{
mapUrl.setScheme( "http" );
}

QList<QPair<QString, QString> > queryItems = mapUrl.queryItems();
QList<QPair<QString, QString> >::const_iterator queryIt = queryItems.constBegin();
for ( ; queryIt != queryItems.constEnd(); ++queryIt )
QString hrefString = mConfigParser->serviceUrl();
if ( hrefString.isEmpty() )
{
if ( queryIt->first.compare( "REQUEST", Qt::CaseInsensitive ) == 0 )
{
mapUrl.removeQueryItem( queryIt->first );
}
else if ( queryIt->first.compare( "VERSION", Qt::CaseInsensitive ) == 0 )
{
mapUrl.removeQueryItem( queryIt->first );
}
else if ( queryIt->first.compare( "SERVICE", Qt::CaseInsensitive ) == 0 )
{
mapUrl.removeQueryItem( queryIt->first );
}
else if ( queryIt->first.compare( "_DC", Qt::CaseInsensitive ) == 0 )
{
mapUrl.removeQueryItem( queryIt->first );
}
hrefString = serviceUrl();
}
hrefString = mapUrl.toString();


// SOAP platform
@@ -201,7 +154,6 @@ QDomDocument QgsWMSServer::getCapabilities( QString version )
QDomElement olResourceElement = doc.createElement( "OnlineResource"/*wms:OnlineResource*/ );
olResourceElement.setAttribute( "xmlns:xlink", "http://www.w3.org/1999/xlink" );
olResourceElement.setAttribute( "xlink:type", "simple" );
requestUrl.truncate( requestUrl.indexOf( "?" ) + 1 );
olResourceElement.setAttribute( "xlink:href", hrefString );
getElement.appendChild( olResourceElement );

@@ -1993,3 +1945,56 @@ bool QgsWMSServer::checkMaximumWidthHeight() const
}
return true;
}

QString QgsWMSServer::serviceUrl() const
{
QUrl mapUrl( getenv( "REQUEST_URI" ) );
mapUrl.setHost( getenv( "SERVER_NAME" ) );

//Add non-default ports to url
QString portString = getenv( "SERVER_PORT" );
if ( !portString.isEmpty() )
{
bool portOk;
int portNumber = portString.toInt( &portOk );
if ( portOk )
{
if ( portNumber != 80 )
{
mapUrl.setPort( portNumber );
}
}
}

if ( QString( getenv( "HTTPS" ) ).compare( "on", Qt::CaseInsensitive ) == 0 )
{
mapUrl.setScheme( "https" );
}
else
{
mapUrl.setScheme( "http" );
}

QList<QPair<QString, QString> > queryItems = mapUrl.queryItems();
QList<QPair<QString, QString> >::const_iterator queryIt = queryItems.constBegin();
for ( ; queryIt != queryItems.constEnd(); ++queryIt )
{
if ( queryIt->first.compare( "REQUEST", Qt::CaseInsensitive ) == 0 )
{
mapUrl.removeQueryItem( queryIt->first );
}
else if ( queryIt->first.compare( "VERSION", Qt::CaseInsensitive ) == 0 )
{
mapUrl.removeQueryItem( queryIt->first );
}
else if ( queryIt->first.compare( "SERVICE", Qt::CaseInsensitive ) == 0 )
{
mapUrl.removeQueryItem( queryIt->first );
}
else if ( queryIt->first.compare( "_DC", Qt::CaseInsensitive ) == 0 )
{
mapUrl.removeQueryItem( queryIt->first );
}
}
return mapUrl.toString();
}
@@ -168,6 +168,9 @@ class QgsWMSServer
@return true if width/height values are okay*/
bool checkMaximumWidthHeight() const;

/**Get service address from REQUEST_URI if not specified in the configuration*/
QString serviceUrl() const;

/**Map containing the WMS parameters*/
QMap<QString, QString> mParameterMap;
QgsConfigParser* mConfigParser;
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>604</width>
<height>588</height>
<width>644</width>
<height>530</height>
</rect>
</property>
<property name="windowTitle">
@@ -756,9 +756,9 @@
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>637</width>
<height>808</height>
<y>-228</y>
<width>599</width>
<height>696</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
@@ -868,6 +868,52 @@
<string>WMS Capabilitities</string>
</property>
<layout class="QGridLayout" name="gridLayout_10">
<item row="2" column="0">
<widget class="QCheckBox" name="mAddWktGeometryCheckBox">
<property name="text">
<string>Add WKT geometry to feature info response</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QGroupBox" name="grpWMSList">
<property name="title">
<string>Coordinate Systems Restrictions</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0" colspan="3">
<widget class="QListWidget" name="mWMSList"/>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="pbnWMSAddSRS">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="pbnWMSRemoveSRS">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="pbnWMSSetUsedSRS">
<property name="text">
<string>Used</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="grpWMSExt">
<property name="title">
@@ -971,80 +1017,44 @@
</layout>
</widget>
</item>
<item row="1" column="1">
<widget class="QGroupBox" name="grpWMSList">
<property name="title">
<string>Coordinate Systems Restrictions</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0" colspan="3">
<widget class="QListWidget" name="mWMSList"/>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="pbnWMSAddSRS">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="pbnWMSRemoveSRS">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="pbnWMSSetUsedSRS">
<property name="text">
<string>Used</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="mAddWktGeometryCheckBox">
<item row="3" column="0">
<widget class="QLabel" name="mWMSUrlLabel">
<property name="text">
<string>Add WKT geometry to feature info response</string>
<string>Advertised WMS url</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="mMaxWidthLabel">
<property name="text">
<string>Maximum width</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="mMaxWidthLineEdit"/>
</item>
<item>
<widget class="QLabel" name="mMaxHeightLabel">
<property name="text">
<string>Maximum height</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="mMaxHeightLineEdit"/>
</item>
</layout>
</item>
<item row="4" column="0" colspan="2">
<widget class="QLineEdit" name="mWMSUrlLineEdit"/>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="mMaxWidthLabel">
<property name="text">
<string>Maximum width</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="mMaxWidthLineEdit"/>
</item>
<item>
<widget class="QLabel" name="mMaxHeightLabel">
<property name="text">
<string>Maximum height</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="mMaxHeightLineEdit"/>
</item>
</layout>
</item>
<item row="3" column="0">
<item row="7" column="0">
<widget class="QGroupBox" name="grpWFSCapabilities">
<property name="title">
<string>WFS Capabilitities</string>

0 comments on commit dbad873

Please sign in to comment.
You can’t perform that action at this time.