Skip to content
Permalink
Browse files

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.
  • Loading branch information
rldhont committed May 29, 2013
1 parent f1f17ed commit 287cce06ad46e726a43f34d42b143f01cecef28f
@@ -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();
@@ -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 );
@@ -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 );
@@ -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() )
@@ -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;
@@ -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 );

0 comments on commit 287cce0

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