Skip to content
Permalink
Browse files

Merge pull request #4963 from Gustry/category

add category in QgsLayerMetadata using keywords
  • Loading branch information
nyalldawson committed Aug 5, 2017
2 parents 0854e79 + 5100d85 commit 19fd3e89120f1c97729e207e94caaae1eb5e223a
@@ -492,7 +492,7 @@ class QgsLayerMetadata
CRS which is actually used to display and manipulate the layer within QGIS.
This may be the case when a layer has an incorrect CRS within its metadata
and a user has manually overridden the layer's CRS within QGIS.
.. seealso:: setCrs()
.. seealso:: crs()
%End

KeywordMap keywords() const;
@@ -535,6 +535,15 @@ class QgsLayerMetadata
.. seealso:: setKeywords()
%End

bool removeKeywords( const QString &vocabulary );
%Docstring
Remove a vocabulary from the list.

.. seealso:: setKeywords()
.. seealso:: addKeywords()
:rtype: bool
%End

QStringList keywordVocabularies() const;
%Docstring
Returns a list of keyword vocabularies contained in the metadata.
@@ -559,6 +568,23 @@ class QgsLayerMetadata
:rtype: list of str
%End

QStringList categories() const;
%Docstring
Returns categories of the resource.
Categories are stored using a special vocabulary 'gmd:topicCategory' in keywords.

.. seealso:: keywords()
:rtype: list of str
%End

void setCategories( const QStringList &categories );
%Docstring
Sets categories of the resource.
Categories are stored using a special vocabulary 'gmd:topicCategory' in keywords.

.. seealso:: keywords()
%End

QgsLayerMetadata::ContactList contacts() const;
%Docstring
Returns a list of contact persons or entities associated with the resource.
@@ -6,6 +6,9 @@
<type>dataset</type>
<title>roads</title>
<abstract>my roads</abstract>
<keywords vocabulary="gmd:topicCategory">
<keyword>natural</keyword>
</keywords>
<keywords vocabulary="GEMET">
<keyword>kw1</keyword>
<keyword>kw2</keyword>
@@ -158,6 +158,11 @@ void QgsLayerMetadata::addKeywords( const QString &vocabulary, const QStringList
mKeywords.insert( vocabulary, keywords );
}

bool QgsLayerMetadata::removeKeywords( const QString &vocabulary )
{
return mKeywords.remove( vocabulary );
}

QStringList QgsLayerMetadata::keywordVocabularies() const
{
return mKeywords.keys();
@@ -168,6 +173,23 @@ QStringList QgsLayerMetadata::keywords( const QString &vocabulary ) const
return mKeywords.value( vocabulary );
}

QStringList QgsLayerMetadata::categories() const
{
if ( mKeywords.contains( "gmd:topicCategory" ) )
{
return mKeywords.value( "gmd:topicCategory" );
}
else
{
return QStringList();
}
}

void QgsLayerMetadata::setCategories( const QStringList &category )
{
mKeywords.insert( "gmd:topicCategory", category );
}

QList<QgsLayerMetadata::Contact> QgsLayerMetadata::contacts() const
{
return mContacts;
@@ -545,7 +545,7 @@ class CORE_EXPORT QgsLayerMetadata
* CRS which is actually used to display and manipulate the layer within QGIS.
* This may be the case when a layer has an incorrect CRS within its metadata
* and a user has manually overridden the layer's CRS within QGIS.
* \see setCrs()
* \see crs()
*/
void setCrs( const QgsCoordinateReferenceSystem &crs );

@@ -588,6 +588,14 @@ class CORE_EXPORT QgsLayerMetadata
*/
void addKeywords( const QString &vocabulary, const QStringList &keywords );

/**
* Remove a vocabulary from the list.
*
* \see setKeywords()
* \see addKeywords()
*/
bool removeKeywords( const QString &vocabulary );

/**
* Returns a list of keyword vocabularies contained in the metadata.
*
@@ -610,6 +618,22 @@ class CORE_EXPORT QgsLayerMetadata
*/
QStringList keywords( const QString &vocabulary ) const;

/**
* Returns categories of the resource.
* Categories are stored using a special vocabulary 'gmd:topicCategory' in keywords.
*
* \see keywords()
*/
QStringList categories() const;

/**
* Sets categories of the resource.
* Categories are stored using a special vocabulary 'gmd:topicCategory' in keywords.
*
* \see keywords()
*/
void setCategories( const QStringList &categories );

/**
* Returns a list of contact persons or entities associated with the resource.
* \see setContacts()
@@ -48,6 +48,9 @@ def testGettersSetters(self):
m.setTitle('title')
self.assertEqual(m.title(), 'title')

m.setCategories(['category'])
self.assertEqual(m.categories(), ['category'])

m.setAbstract('abstract')
self.assertEqual(m.abstract(), 'abstract')

@@ -102,6 +105,11 @@ def testExtent(self):
def testKeywords(self):
m = QgsLayerMetadata()

m.setKeywords({'gmd:topicCategory': ['natural']})
self.assertEqual(m.keywords(), {'gmd:topicCategory': ['natural']})
self.assertEqual(m.categories(), ['natural'])
self.assertTrue(m.removeKeywords('gmd:topicCategory'))

m.setKeywords({'vocab a': ['keyword a', 'other a'],
'vocab b': ['keyword b', 'other b']})
self.assertEqual(m.keywords(), {'vocab a': ['keyword a', 'other a'],

0 comments on commit 19fd3e8

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