Skip to content
Permalink
Browse files

[FEATURE][QGIS Server] Add short name to layers, groups and project

A number of elements have both a <Name> and a <Title>. The Name is a text string used for machine-to-machine
communication while the Title is for the benefit of humans. For example, a dataset might have the descriptive Title
“Maximum Atmospheric Temperature” and be requested using the abbreviated Name “ATMAX”.

User can already set title for layers, groups and project. OWS name is based on the name used in layer tree. This name is more a label for humans than a name for machine-to-machine communication.

To add the capability to users to define Name as a text string for machine-to-machine communication, this pull-request adds:
* short name line edits to layers properties
* WMS data dialog to layer tree group (short name, title, abstract)
* short name line edits to project properties
* add a regexp validator "^[A-Za-z][A-Za-z0-9\._-]*" to short name line edit accessible through a static method
* add a TreeName element in the fullProjectSettings

If a short name has been set for layers, groups and project it is used by QGIS Sever as the layer name.
  • Loading branch information
rldhont committed Dec 23, 2015
1 parent e6a265c commit a32587bcd1401b7427160c2b4ffd0d5e079438b7
@@ -228,6 +228,9 @@ static void qtgui_UpdatePyArgv(PyObject *argvlist, int argc, char **argv)
//! Returns the path to user's style.
static QString userStyleV2Path();

//! Returns the short name regular exprecience for line edit validator
static QRegExp shortNameRegExp();

//! Returns the path to user's themes folder
static QString userThemesFolder();

@@ -76,6 +76,17 @@ class QgsMapLayer : QObject
*/
QString originalName() const;

/** Set the short name of the layer
* used by QGIS Server to identify the layer
* @return the layer short name
*/
void setShortName( const QString& shortName );
/** Get the short name of the layer
* used by QGIS Server to identify the layer
* @return the layer short name
*/
QString shortName() const;

/** Set the title of the layer
* used by QGIS Server in GetCapabilities request
* @return the layer title
@@ -205,6 +205,7 @@
#include "qgsrectangle.h"
#include "qgsscalecombobox.h"
#include "qgsscalevisibilitydialog.h"
#include "qgsgroupwmsdatadialog.h"
#include "qgsshortcutsmanager.h"
#include "qgssinglebandgrayrenderer.h"
#include "qgssnappingdialog.h"
@@ -7832,6 +7833,24 @@ void QgisApp::legendGroupSetCRS()
}
}

void QgisApp::legendGroupSetWMSData()
{
QgsLayerTreeGroup* currentGroup = mLayerTreeView->currentGroupNode();
if ( !currentGroup )
return;
QgsGroupWMSDataDialog* dlg = new QgsGroupWMSDataDialog( this );
dlg->setGroupShortName( currentGroup->customProperty( "wmsShortName" ).toString() );
dlg->setGroupTitle( currentGroup->customProperty( "wmsTitle" ).toString() );
dlg->setGroupTitle( currentGroup->customProperty( "wmsAbstract" ).toString() );
if ( dlg->exec() )
{
currentGroup->setCustomProperty( "wmsShortName", dlg->groupShortName() );
currentGroup->setCustomProperty( "wmsTitle", dlg->groupTitle() );
currentGroup->setCustomProperty( "wmsAbstract", dlg->groupAbstract() );
}
delete dlg;
}

void QgisApp::zoomToLayerExtent()
{
mLayerTreeView->defaultActions()->zoomToLayer( mMapCanvas );
@@ -753,6 +753,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow

/** Set the CRS of the current legend group*/
void legendGroupSetCRS();
/** Set the WMS data of the current legend group*/
void legendGroupSetWMSData();

//! zoom to extent of layer
void zoomToLayerExtent();
@@ -61,6 +61,8 @@ QMenu* QgsAppLayerTreeViewMenuProvider::createContextMenu()

menu->addAction( actions->actionRenameGroupOrLayer( menu ) );

menu->addAction( tr( "&Set Group WMS data" ), QgisApp::instance(), SLOT( legendGroupSetWMSData() ) );

menu->addAction( actions->actionMutuallyExclusiveGroup( menu ) );

if ( mView->selectedNodes( true ).count() >= 2 )
@@ -262,6 +262,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa

grpOWSServiceCapabilities->setChecked( QgsProject::instance()->readBoolEntry( "WMSServiceCapabilities", "/", false ) );
mWMSTitle->setText( QgsProject::instance()->readEntry( "WMSServiceTitle", "/" ) );
mWMSName->setText( QgsProject::instance()->readEntry( "WMSRootName", "/" ) );
mWMSContactOrganization->setText( QgsProject::instance()->readEntry( "WMSContactOrganization", "/", "" ) );
mWMSContactPerson->setText( QgsProject::instance()->readEntry( "WMSContactPerson", "/", "" ) );
mWMSContactMail->setText( QgsProject::instance()->readEntry( "WMSContactMail", "/", "" ) );
@@ -271,6 +272,10 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
mWMSUrlLineEdit->setText( QgsProject::instance()->readEntry( "WMSUrl", "/", "" ) );
mWMSKeywordList->setText( QgsProject::instance()->readListEntry( "WMSKeywordList", "/" ).join( ", " ) );

// WMS Name validator
QValidator *shortNameValidator = new QRegExpValidator( QgsApplication::shortNameRegExp(), this );
mWMSName->setValidator( shortNameValidator );

// WMS Contact Position
QString contactPositionText = QgsProject::instance()->readEntry( "WMSContactPosition", "/", "" );
mWMSContactPositionCb->addItem( "" );
@@ -785,6 +790,7 @@ void QgsProjectProperties::apply()

QgsProject::instance()->writeEntry( "WMSServiceCapabilities", "/", grpOWSServiceCapabilities->isChecked() );
QgsProject::instance()->writeEntry( "WMSServiceTitle", "/", mWMSTitle->text() );
QgsProject::instance()->writeEntry( "WMSRootName", "/", mWMSName->text() );
QgsProject::instance()->writeEntry( "WMSContactOrganization", "/", mWMSContactOrganization->text() );
QgsProject::instance()->writeEntry( "WMSContactPerson", "/", mWMSContactPerson->text() );
QgsProject::instance()->writeEntry( "WMSContactMail", "/", mWMSContactMail->text() );
@@ -750,6 +750,13 @@ void QgsRasterLayerProperties::sync()
txtbMetadata->document()->setDefaultStyleSheet( myStyle );
txtbMetadata->setHtml( mRasterLayer->metadata() );

// WMS Name as layer short name
mLayerShortNameLineEdit->setText( mRasterLayer->shortName() );
// WMS Name validator
QValidator *shortNameValidator = new QRegExpValidator( QgsApplication::shortNameRegExp(), this );
mLayerShortNameLineEdit->setValidator( shortNameValidator );

//layer title and abstract
mLayerTitleLineEdit->setText( mRasterLayer->title() );
mLayerAbstractTextEdit->setPlainText( mRasterLayer->abstract() );
mLayerKeywordListLineEdit->setText( mRasterLayer->keywordList() );
@@ -934,6 +941,7 @@ void QgsRasterLayerProperties::apply()
QPixmap thumbnail = QPixmap::fromImage( mRasterLayer->previewAsImage( pixmapThumbnail->size() ) );
pixmapThumbnail->setPixmap( thumbnail );

mRasterLayer->setShortName( mLayerShortNameLineEdit->text() );
mRasterLayer->setTitle( mLayerTitleLineEdit->text() );
mRasterLayer->setAbstract( mLayerAbstractTextEdit->toPlainText() );
mRasterLayer->setKeywordList( mLayerKeywordListLineEdit->text() );
@@ -249,6 +249,11 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
diagLayout->addWidget( diagramPropertiesDialog );
mDiagramFrame->setLayout( diagLayout );

// WMS Name as layer short name
mLayerShortNameLineEdit->setText( layer->shortName() );
// WMS Name validator
QValidator *shortNameValidator = new QRegExpValidator( QgsApplication::shortNameRegExp(), this );
mLayerShortNameLineEdit->setValidator( shortNameValidator );

//layer title and abstract
mLayerTitleLineEdit->setText( layer->title() );
@@ -588,6 +593,7 @@ void QgsVectorLayerProperties::apply()
diagramPropertiesDialog->apply();

//layer title and abstract
layer->setShortName( mLayerShortNameLineEdit->text() );
layer->setTitle( mLayerTitleLineEdit->text() );
layer->setAbstract( mLayerAbstractTextEdit->toPlainText() );
layer->setKeywordList( mLayerKeywordListLineEdit->text() );
@@ -717,6 +717,11 @@ QString QgsApplication::userStyleV2Path()
return qgisSettingsDirPath() + QLatin1String( "symbology-ng-style.db" );
}

QRegExp QgsApplication::shortNameRegExp()
{
return QRegExp( "^[A-Za-z][A-Za-z0-9\\._-]*" );
}

QString QgsApplication::userThemesFolder()
{
return qgisSettingsDirPath() + QLatin1String( "/themes" );
@@ -190,6 +190,9 @@ class CORE_EXPORT QgsApplication : public QApplication
//! Returns the path to user's style.
static QString userStyleV2Path();

//! Returns the short name regular exprecience for line edit validator
static QRegExp shortNameRegExp();

//! Returns the path to user's themes folder
static QString userThemesFolder();

@@ -67,6 +67,9 @@ QgsMapLayer::QgsMapLayer( QgsMapLayer::LayerType type,
mLayerName = capitaliseLayerName( mLayerOrigName );
QgsDebugMsg( "display name: '" + mLayerName + '\'' );

// Set short name = the first original name
mShortName = lyrname;

// Generate the unique ID of this layer
QDateTime dt = QDateTime::currentDateTime();
mID = lyrname + dt.toString( "yyyyMMddhhmmsszzz" );
@@ -425,6 +428,13 @@ bool QgsMapLayer::readLayerXML( const QDomElement& layerElement )
mne = mnl.toElement();
setLayerName( mne.text() );

//short name
QDomElement shortNameElem = layerElement.firstChildElement( "shortname" );
if ( !shortNameElem.isNull() )
{
mShortName = shortNameElem.text();
}

//title
QDomElement titleElem = layerElement.firstChildElement( "title" );
if ( !titleElem.isNull() )
@@ -640,6 +650,11 @@ bool QgsMapLayer::writeLayerXML( QDomElement& layerElement, QDomDocument& docume
QDomText layerNameText = document.createTextNode( originalName() );
layerName.appendChild( layerNameText );

// layer short name
QDomElement layerShortName = document.createElement( "shortname" );
QDomText layerShortNameText = document.createTextNode( shortName() );
layerShortName.appendChild( layerShortNameText );

// layer title
QDomElement layerTitle = document.createElement( "title" );
QDomText layerTitleText = document.createTextNode( title() );
@@ -651,6 +666,7 @@ bool QgsMapLayer::writeLayerXML( QDomElement& layerElement, QDomDocument& docume
layerAbstract.appendChild( layerAbstractText );

layerElement.appendChild( layerName );
layerElement.appendChild( layerShortName );
layerElement.appendChild( layerTitle );
layerElement.appendChild( layerAbstract );

@@ -92,6 +92,17 @@ class CORE_EXPORT QgsMapLayer : public QObject
*/
QString originalName() const { return mLayerOrigName; }

/** Set the short name of the layer
* used by QGIS Server to identify the layer
* @return the layer short name
*/
void setShortName( const QString& shortName ) { mShortName = shortName; }
/** Get the short name of the layer
* used by QGIS Server to identify the layer
* @return the layer short name
*/
QString shortName() const { return mShortName; }

/** Set the title of the layer
* used by QGIS Server in GetCapabilities request
* @return the layer title
@@ -677,6 +688,7 @@ class CORE_EXPORT QgsMapLayer : public QObject
*/
QString mLayerOrigName;

QString mShortName;
QString mTitle;

/** Description of the layer*/
@@ -265,6 +265,7 @@ SET(QGIS_GUI_SRCS
qgsvertexmarker.cpp
qgsunitselectionwidget.cpp
qgslegendfilterbutton.cpp
qgsgroupwmsdatadialog.cpp
)

IF (WITH_QTWEBKIT)
@@ -392,6 +393,7 @@ SET(QGIS_GUI_MOC_HDRS
qgsunitselectionwidget.h
qgsuserinputdockwidget.h
qgslegendfilterbutton.h
qgsgroupwmsdatadialog.h

raster/qgsrasterminmaxwidget.h
raster/qgspalettedrendererwidget.h
@@ -0,0 +1,57 @@
/***************************************************************************
qgsscalevisibilitydialog.cpp
--------------------------------------
Date : 20.05.2014
Copyright : (C) 2014 Denis Rouzaud
Email : denis.rouzaud@gmail.com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsapplication.h"
#include "qgsgroupwmsdatadialog.h"


QgsGroupWMSDataDialog::QgsGroupWMSDataDialog( QWidget *parent, const Qt::WindowFlags& fl ) :
QDialog( parent, fl )
{
setupUi( this );
// WMS Name validator
QValidator *shortNameValidator = new QRegExpValidator( QgsApplication::shortNameRegExp(), this );
mShortNameLineEdit->setValidator( shortNameValidator );
}

QString QgsGroupWMSDataDialog::groupShortName()
{
return mShortNameLineEdit->text();
}

void QgsGroupWMSDataDialog::setGroupShortName( QString shortName )
{
mShortNameLineEdit->setText( shortName );
}

QString QgsGroupWMSDataDialog::groupTitle()
{
return mTitleLineEdit->text();
}

void QgsGroupWMSDataDialog::setGroupTitle( QString title )
{
mTitleLineEdit->setText( title );
}

QString QgsGroupWMSDataDialog::groupAbstract()
{
return mAbstractTextEdit->toPlainText();
}

void QgsGroupWMSDataDialog::setGroupAbstract( QString abstract )
{
mAbstractTextEdit->setPlainText( abstract );
}
@@ -0,0 +1,62 @@
/***************************************************************************
qgsscalevisibilitydialog.cpp
--------------------------------------
Date : 20.05.2014
Copyright : (C) 2014 Denis Rouzaud
Email : denis.rouzaud@gmail.com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSGROUPWMSDATADIALOG_H
#define QGSGROUPWMSDATADIALOG_H

#include "ui_qgsgroupwmsdatadialogbase.h"
#include "qgisgui.h"
#include "qgscontexthelp.h"

#include "qgis.h"

class GUI_EXPORT QgsGroupWMSDataDialog: public QDialog, private Ui::QgsGroupWMSDataDialogBase
{
Q_OBJECT

public:
//! Constructor
QgsGroupWMSDataDialog( QWidget *parent = 0, const Qt::WindowFlags& fl = QgisGui::ModalDialogFlags );
//~QgsGroupWMSDataDialog();

//! return group WMS title
QString groupTitle();

//! return group WMS short name
QString groupShortName();

//! return group WMS abstract
QString groupAbstract();


public slots:
//! set group WMS title
void setGroupTitle( QString title );

//! set group WMS short name
void setGroupShortName( QString shortName );

//! set group WMS abstract
void setGroupAbstract( QString abstract );


private:

QString mGroupTitle;
QString mGroupShortName;

};

#endif // QGSGROUPWMSDATADIALOG_H

0 comments on commit a32587b

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