Add metadata information for layers

To complete the metadata tab and ilayer information, we add keywordlist,
metadata url and attribution information.
The user can add keywords to his layers, store a metadata url with type
and format and attribution title and url.
These data are reused by QGIS-Sever in the WMS GetCapabilities request.
This capability is sponsored by ifremer.
This commit is contained in:
D'Hont René-Luc 2013-05-29 15:25:53 +02:00
parent f1f17ed911
commit 287cce06ad
8 changed files with 473 additions and 20 deletions

View File

@ -84,6 +84,23 @@ class QgsMapLayer : QObject
void setAbstract( const QString& abstract );
const QString& abstract() const;
void setKeywordList( const QString& kwdList );
const QString& keywordList() const;
/* Layer attribution information */
void setAttribution( const QString& attrib );
const QString& attribution() const;
void setAttributionUrl( const QString& attribUrl );
const QString& attributionUrl() const;
/* Layer metadataUrl information */
void setMetadataUrl( const QString& metaUrl );
const QString& metadataUrl() const;
void setMetadataUrlType( const QString& metaUrlType );
const QString& metadataUrlType() const;
void setMetadataUrlFormat( const QString& metaUrlFormat );
const QString& metadataUrlFormat() const;
/**Synchronises with changes in the datasource
@note added in version 1.6*/
virtual void reload();

View File

@ -731,6 +731,21 @@ void QgsRasterLayerProperties::sync()
mLayerTitleLineEdit->setText( mRasterLayer->title() );
mLayerAbstractTextEdit->setPlainText( mRasterLayer->abstract() );
mLayerKeywordListLineEdit->setText( mRasterLayer->keywordList() );
//layer attribution and metadataUrl
mLayerAttributionLineEdit->setText( mRasterLayer->attribution() );
mLayerAttributionUrlLineEdit->setText( mRasterLayer->attributionUrl() );
mLayerMetadataUrlLineEdit->setText( mRasterLayer->metadataUrl() );
mLayerMetadataUrlTypeComboBox->setCurrentIndex(
mLayerMetadataUrlTypeComboBox->findText(
mRasterLayer->metadataUrlType()
)
);
mLayerMetadataUrlFormatComboBox->setCurrentIndex(
mLayerMetadataUrlFormatComboBox->findText(
mRasterLayer->metadataUrlFormat()
)
);
} // QgsRasterLayerProperties::sync()
@ -896,6 +911,13 @@ void QgsRasterLayerProperties::apply()
mRasterLayer->setTitle( mLayerTitleLineEdit->text() );
mRasterLayer->setAbstract( mLayerAbstractTextEdit->toPlainText() );
mRasterLayer->setKeywordList( mLayerKeywordListLineEdit->text() );
//layer attribution and metadataUrl
mRasterLayer->setAttribution( mLayerAttributionLineEdit->text() );
mRasterLayer->setAttributionUrl( mLayerAttributionUrlLineEdit->text() );
mRasterLayer->setMetadataUrl( mLayerMetadataUrlLineEdit->text() );
mRasterLayer->setMetadataUrlType( mLayerMetadataUrlTypeComboBox->currentText() );
mRasterLayer->setMetadataUrlFormat( mLayerMetadataUrlFormatComboBox->currentText() );
// update symbology
emit refreshLegend( mRasterLayer->id(), false );

View File

@ -228,6 +228,21 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
{
mLayerTitleLineEdit->setText( layer->title() );
mLayerAbstractTextEdit->setPlainText( layer->abstract() );
mLayerKeywordListLineEdit->setText( layer->keywordList() );
//layer attribution and metadataUrl
mLayerAttributionLineEdit->setText( layer->attribution() );
mLayerAttributionUrlLineEdit->setText( layer->attributionUrl() );
mLayerMetadataUrlLineEdit->setText( layer->metadataUrl() );
mLayerMetadataUrlTypeComboBox->setCurrentIndex(
mLayerMetadataUrlTypeComboBox->findText(
layer->metadataUrlType()
)
);
mLayerMetadataUrlFormatComboBox->setCurrentIndex(
mLayerMetadataUrlFormatComboBox->findText(
layer->metadataUrlFormat()
)
);
}
setWindowTitle( tr( "Layer Properties - %1" ).arg( layer->name() ) );
@ -465,6 +480,13 @@ void QgsVectorLayerProperties::apply()
//layer title and abstract
layer->setTitle( mLayerTitleLineEdit->text() );
layer->setAbstract( mLayerAbstractTextEdit->toPlainText() );
layer->setKeywordList( mLayerKeywordListLineEdit->text() );
//layer attribution and metadataUrl
layer->setAttribution( mLayerAttributionLineEdit->text() );
layer->setAttributionUrl( mLayerAttributionUrlLineEdit->text() );
layer->setMetadataUrl( mLayerMetadataUrlLineEdit->text() );
layer->setMetadataUrlType( mLayerMetadataUrlTypeComboBox->currentText() );
layer->setMetadataUrlFormat( mLayerMetadataUrlFormatComboBox->currentText() );
// update symbology
emit refreshLegend( layer->id(), QgsLegendItem::DontChange );

View File

@ -359,6 +359,35 @@ bool QgsMapLayer::readLayerXML( const QDomElement& layerElement )
mAbstract = abstractElem.text();
}
//keywordList
QDomElement keywordListElem = layerElement.firstChildElement( "keywordList" );
if ( !keywordListElem.isNull() )
{
QStringList kwdList;
for(QDomNode n = keywordListElem.firstChild(); !n.isNull(); n = n.nextSibling())
{
kwdList << n.toElement().text();
}
mKeywordList = kwdList.join( ", " );
}
//attribution
QDomElement attribElem = layerElement.firstChildElement( "attribution" );
if ( !attribElem.isNull() )
{
mAttribution = attribElem.text();
mAttributionUrl = attribElem.attribute( "href", "" );
}
//metadataUrl
QDomElement metaUrlElem = layerElement.firstChildElement( "metadataUrl" );
if ( !metaUrlElem.isNull() )
{
mMetadataUrl = metaUrlElem.text();
mMetadataUrlType = metaUrlElem.attribute( "type", "" );
mMetadataUrlFormat = metaUrlElem.attribute( "format", "" );
}
#if 0
//read transparency level
QDomNode transparencyNode = layer_node.namedItem( "transparencyLevelInt" );
@ -457,6 +486,44 @@ bool QgsMapLayer::writeLayerXML( QDomElement& layerElement, QDomDocument& docume
layerElement.appendChild( layerName );
layerElement.appendChild( layerTitle );
layerElement.appendChild( layerAbstract );
// layer keyword list
QStringList keywordStringList = keywordList().split( "," );
if ( keywordStringList.size() > 0 )
{
QDomElement layerKeywordList = document.createElement( "keywordList" );
for (int i = 0; i < keywordStringList.size(); ++i)
{
QDomElement layerKeywordValue = document.createElement( "value" );
QDomText layerKeywordText = document.createTextNode( keywordStringList.at( i ).trimmed() );
layerKeywordValue.appendChild( layerKeywordText );
layerKeywordList.appendChild( layerKeywordValue );
}
layerElement.appendChild( layerKeywordList );
}
// layer attribution
QString aAttribution = attribution();
if ( !aAttribution.isEmpty() )
{
QDomElement layerAttribution = document.createElement( "attribution" ) ;
QDomText layerAttributionText = document.createTextNode( aAttribution );
layerAttribution.appendChild( layerAttributionText );
layerAttribution.setAttribute( "href", attributionUrl() );
layerElement.appendChild( layerAttribution );
}
// layer metadataUrl
QString aMetadataUrl = metadataUrl();
if ( !aMetadataUrl.isEmpty() )
{
QDomElement layerMetadataUrl = document.createElement( "metadataUrl" ) ;
QDomText layerMetadataUrlText = document.createTextNode( aMetadataUrl );
layerMetadataUrl.appendChild( layerMetadataUrlText );
layerMetadataUrl.setAttribute( "type", metadataUrlType() );
layerMetadataUrl.setAttribute( "format", metadataUrlFormat() );
layerElement.appendChild( layerMetadataUrl );
}
// timestamp if supported
if ( timestamp() > QDateTime() )

View File

@ -96,6 +96,23 @@ class CORE_EXPORT QgsMapLayer : public QObject
void setAbstract( const QString& abstract ) { mAbstract = abstract; }
const QString& abstract() const { return mAbstract; }
void setKeywordList( const QString& keywords ) { mKeywordList = keywords; }
const QString& keywordList() const { return mKeywordList; }
/* Layer attribution information */
void setAttribution( const QString& attrib ) { mAttribution = attrib; }
const QString& attribution() const { return mAttribution; }
void setAttributionUrl( const QString& attribUrl ) { mAttributionUrl = attribUrl; }
const QString& attributionUrl() const { return mAttributionUrl; }
/* Layer metadataUrl information */
void setMetadataUrl( const QString& metaUrl ) { mMetadataUrl = metaUrl; }
const QString& metadataUrl() const { return mMetadataUrl; }
void setMetadataUrlType( const QString& metaUrlType ) { mMetadataUrlType = metaUrlType; }
const QString& metadataUrlType() const { return mMetadataUrlType; }
void setMetadataUrlFormat( const QString& metaUrlFormat ) { mMetadataUrlFormat = metaUrlFormat; }
const QString& metadataUrlFormat() const { return mMetadataUrlFormat; }
/* Set the blending mode used for rendering a layer */
void setBlendMode( const QPainter::CompositionMode blendMode );
/* Returns the current blending mode for a layer */
@ -475,6 +492,16 @@ class CORE_EXPORT QgsMapLayer : public QObject
/**Description of the layer*/
QString mAbstract;
QString mKeywordList;
/**Attribution of the layer*/
QString mAttribution;
QString mAttributionUrl;
/**MetadataUrl of the layer*/
QString mMetadataUrl;
QString mMetadataUrlType;
QString mMetadataUrlFormat;
/** \brief Error */
QgsError mError;

View File

@ -551,6 +551,72 @@ void QgsProjectParser::addLayers( QDomDocument &doc,
layerElem.appendChild( abstractElem );
}
//keyword list
QStringList keywordStringList = currentLayer->keywordList().split( "," );
if ( keywordStringList.size() > 0 )
{
bool siaFormat = featureInfoFormatSIA2045();
QDomElement keywordListElem = doc.createElement( "KeywordList" );
for ( int i = 0; i < keywordStringList.size(); ++i )
{
QDomElement keywordElem = doc.createElement( "Keyword" );
QDomText keywordText = doc.createTextNode( keywordStringList.at( i ).trimmed() );
keywordElem.appendChild( keywordText );
if ( siaFormat )
{
keywordElem.setAttribute( "vocabulary", "SIA_Geo405" );
}
keywordListElem.appendChild( keywordElem );
}
layerElem.appendChild( keywordListElem );
}
QString attribution = currentLayer->attribution();
if ( !attribution.isEmpty() )
{
QDomElement attribElem = doc.createElement( "Attribution" );
QDomElement attribTitleElem = doc.createElement( "Title" );
QDomText attribText = doc.createTextNode( attribution );
attribTitleElem.appendChild( attribText );
attribElem.appendChild( attribTitleElem );
QString attributionUrl = currentLayer->attributionUrl();
if ( !attributionUrl.isEmpty() )
{
QDomElement attribORElem = doc.createElement( "OnlineResource" );
attribORElem.setAttribute( "xmlns:xlink", "http://www.w3.org/1999/xlink" );
attribORElem.setAttribute( "xlink:type", "simple" );
attribORElem.setAttribute( "xlink:href", attributionUrl );
attribElem.appendChild( attribORElem );
}
layerElem.appendChild( attribElem );
}
QString metadataUrl = currentLayer->metadataUrl();
if ( !metadataUrl.isEmpty() )
{
QDomElement metaUrlElem = doc.createElement( "MetadataUrl" );
QString metadataUrlType = currentLayer->metadataUrlType();
if ( !metadataUrlType.isEmpty() )
{
metaUrlElem.setAttribute( "type", metadataUrlType );
}
QString metadataUrlFormat = currentLayer->metadataUrlFormat();
if ( !metadataUrlFormat.isEmpty() )
{
QDomElement metaUrlFormatElem = doc.createElement( "Format" );
QDomText metaUrlFormatText = doc.createTextNode( metadataUrlFormat );
metaUrlFormatElem.appendChild( metaUrlFormatText );
metaUrlElem.appendChild( metaUrlFormatElem );
}
QDomElement metaUrlORElem = doc.createElement( "OnlineResource" );
metaUrlORElem.setAttribute( "xmlns:xlink", "http://www.w3.org/1999/xlink" );
metaUrlORElem.setAttribute( "xlink:type", "simple" );
metaUrlORElem.setAttribute( "xlink:href", metadataUrl );
metaUrlElem.appendChild( metaUrlORElem );
layerElem.appendChild( metaUrlElem );
}
//CRS
QStringList crsList = createCRSListForLayer( currentLayer );
appendCRSElementsToLayer( layerElem, doc, crsList );

View File

@ -1303,7 +1303,7 @@
<property name="syncGroup" stdset="0">
<string notr="true">rastertransp</string>
</property>
<layout class="QGridLayout" name="gridLayout_7">
<layout class="QGridLayout" name="gridLayout_11">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<property name="leftMargin">
@ -1866,6 +1866,23 @@ p, li { white-space: pre-wrap; }
<string notr="true">rastermeta</string>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="1" column="0">
<widget class="QLabel" name="mLayerTitleLabel">
<property name="text">
<string>Title</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="mLayerTitleLineEdit"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="mLayerAbstractLabel">
<property name="text">
<string>Abstract</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QTextEdit" name="mLayerAbstractTextEdit">
<property name="sizePolicy">
@ -1882,26 +1899,125 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="mLayerTitleLineEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="mLayerTitleLabel">
<item row="5" column="0">
<widget class="QLabel" name="mLayerKeywordListLabel">
<property name="text">
<string>Title</string>
<string>Keyword list</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="mLayerAbstractLabel">
<property name="text">
<string>Abstract</string>
</property>
</widget>
<item row="5" column="1">
<widget class="QLineEdit" name="mLayerKeywordListLineEdit"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QgsCollapsibleGroupBox" name="mMetaAttributionGrpBx">
<property name="title">
<string>Attribution</string>
</property>
<property name="syncGroup" stdset="0">
<string notr="true">vectormeta</string>
</property>
<layout class="QGridLayout" name="gridLayout_7">
<item row="0" column="0">
<widget class="QLabel" name="mLayerAttributionLabel">
<property name="text">
<string>Title</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="mLayerAttributionLineEdit"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="mLayerAttributionUrlLabel">
<property name="text">
<string>Url</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="mLayerAttributionUrlLineEdit"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QgsCollapsibleGroupBox" name="mMetaMetaUrlGrpBx">
<property name="title">
<string>MetadataUrl</string>
</property>
<property name="syncGroup" stdset="0">
<string notr="true">vectormeta</string>
</property>
<layout class="QGridLayout" name="gridLayout_9">
<item row="0" column="0">
<widget class="QLabel" name="mLayerMetadataUrlLabel">
<property name="text">
<string>Url</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="4">
<widget class="QLineEdit" name="mLayerMetadataUrlLineEdit"/>
</item>
<item row="1" column="1">
<widget class="QLabel" name="mLayerMetadataUrlTypeLabel">
<property name="text">
<string>Type</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QComboBox" name="mLayerMetadataUrlTypeComboBox">
<item>
<property name="text">
<string notr="true"></string>
</property>
</item>
<item>
<property name="text">
<string notr="true" extracomment="FGDC-STD-001-1988">FGDC</string>
</property>
</item>
<item>
<property name="text">
<string notr="true" extracomment="ISO 19115">TC211</string>
</property>
</item>
</widget>
</item>
<item row="1" column="3">
<widget class="QLabel" name="mLayerMetadataUrlFormatLabel">
<property name="text">
<string>Format</string>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QComboBox" name="mLayerMetadataUrlFormatComboBox">
<item>
<property name="text">
<string notr="true"></string>
</property>
</item>
<item>
<property name="text">
<string notr="true">text/plain</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">text/xml</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QgsCollapsibleGroupBox" name="mMetaPropertiesGrpBx">
<property name="sizePolicy">

View File

@ -1333,6 +1333,23 @@
<string notr="true">vectormeta</string>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="1" column="0">
<widget class="QLabel" name="mLayerTitleLabel">
<property name="text">
<string>Title</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="mLayerTitleLineEdit"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="mLayerAbstractLabel">
<property name="text">
<string>Abstract</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QTextEdit" name="mLayerAbstractTextEdit">
<property name="sizePolicy">
@ -1349,23 +1366,122 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="mLayerTitleLineEdit"/>
<item row="5" column="0">
<widget class="QLabel" name="mLayerKeywordListLabel">
<property name="text">
<string>Keyword list</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="mLayerTitleLabel">
<item row="5" column="1">
<widget class="QLineEdit" name="mLayerKeywordListLineEdit"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QgsCollapsibleGroupBox" name="mMetaAttributionGrpBx">
<property name="title">
<string>Attribution</string>
</property>
<property name="syncGroup" stdset="0">
<string notr="true">vectormeta</string>
</property>
<layout class="QGridLayout" name="gridLayout_7">
<item row="0" column="0">
<widget class="QLabel" name="mLayerAttributionLabel">
<property name="text">
<string>Title</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="mLayerAbstractLabel">
<item row="0" column="1">
<widget class="QLineEdit" name="mLayerAttributionLineEdit"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="mLayerAttributionUrlLabel">
<property name="text">
<string>Abstract</string>
<string>Url</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="mLayerAttributionUrlLineEdit"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QgsCollapsibleGroupBox" name="mMetaMetaUrlGrpBx">
<property name="title">
<string>MetadataUrl</string>
</property>
<property name="syncGroup" stdset="0">
<string notr="true">vectormeta</string>
</property>
<layout class="QGridLayout" name="gridLayout_9">
<item row="0" column="0">
<widget class="QLabel" name="mLayerMetadataUrlLabel">
<property name="text">
<string>Url</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="4">
<widget class="QLineEdit" name="mLayerMetadataUrlLineEdit"/>
</item>
<item row="1" column="1">
<widget class="QLabel" name="mLayerMetadataUrlTypeLabel">
<property name="text">
<string>Type</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QComboBox" name="mLayerMetadataUrlTypeComboBox">
<item>
<property name="text">
<string notr="true"></string>
</property>
</item>
<item>
<property name="text">
<string notr="true" extracomment="FGDC-STD-001-1988">FGDC</string>
</property>
</item>
<item>
<property name="text">
<string notr="true" extracomment="ISO 19115">TC211</string>
</property>
</item>
</widget>
</item>
<item row="1" column="3">
<widget class="QLabel" name="mLayerMetadataUrlFormatLabel">
<property name="text">
<string>Format</string>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QComboBox" name="mLayerMetadataUrlFormatComboBox">
<item>
<property name="text">
<string notr="true"></string>
</property>
</item>
<item>
<property name="text">
<string notr="true">text/plain</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">text/xml</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>