Skip to content

Commit 5100d85

Browse files
committedAug 5, 2017
add category in QgsLayerMetadata using keywords
1 parent c3ae3bf commit 5100d85

File tree

5 files changed

+85
-2
lines changed

5 files changed

+85
-2
lines changed
 

‎python/core/metadata/qgslayermetadata.sip

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ class QgsLayerMetadata
492492
CRS which is actually used to display and manipulate the layer within QGIS.
493493
This may be the case when a layer has an incorrect CRS within its metadata
494494
and a user has manually overridden the layer's CRS within QGIS.
495-
.. seealso:: setCrs()
495+
.. seealso:: crs()
496496
%End
497497

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

538+
bool removeKeywords( const QString &vocabulary );
539+
%Docstring
540+
Remove a vocabulary from the list.
541+
542+
.. seealso:: setKeywords()
543+
.. seealso:: addKeywords()
544+
:rtype: bool
545+
%End
546+
538547
QStringList keywordVocabularies() const;
539548
%Docstring
540549
Returns a list of keyword vocabularies contained in the metadata.
@@ -559,6 +568,23 @@ class QgsLayerMetadata
559568
:rtype: list of str
560569
%End
561570

571+
QStringList categories() const;
572+
%Docstring
573+
Returns categories of the resource.
574+
Categories are stored using a special vocabulary 'gmd:topicCategory' in keywords.
575+
576+
.. seealso:: keywords()
577+
:rtype: list of str
578+
%End
579+
580+
void setCategories( const QStringList &categories );
581+
%Docstring
582+
Sets categories of the resource.
583+
Categories are stored using a special vocabulary 'gmd:topicCategory' in keywords.
584+
585+
.. seealso:: keywords()
586+
%End
587+
562588
QgsLayerMetadata::ContactList contacts() const;
563589
%Docstring
564590
Returns a list of contact persons or entities associated with the resource.

‎resources/qgis-resource-metadata.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
<type>dataset</type>
77
<title>roads</title>
88
<abstract>my roads</abstract>
9+
<keywords vocabulary="gmd:topicCategory">
10+
<keyword>natural</keyword>
11+
</keywords>
912
<keywords vocabulary="GEMET">
1013
<keyword>kw1</keyword>
1114
<keyword>kw2</keyword>

‎src/core/metadata/qgslayermetadata.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ void QgsLayerMetadata::addKeywords( const QString &vocabulary, const QStringList
158158
mKeywords.insert( vocabulary, keywords );
159159
}
160160

161+
bool QgsLayerMetadata::removeKeywords( const QString &vocabulary )
162+
{
163+
return mKeywords.remove( vocabulary );
164+
}
165+
161166
QStringList QgsLayerMetadata::keywordVocabularies() const
162167
{
163168
return mKeywords.keys();
@@ -168,6 +173,23 @@ QStringList QgsLayerMetadata::keywords( const QString &vocabulary ) const
168173
return mKeywords.value( vocabulary );
169174
}
170175

176+
QStringList QgsLayerMetadata::categories() const
177+
{
178+
if ( mKeywords.contains( "gmd:topicCategory" ) )
179+
{
180+
return mKeywords.value( "gmd:topicCategory" );
181+
}
182+
else
183+
{
184+
return QStringList();
185+
}
186+
}
187+
188+
void QgsLayerMetadata::setCategories( const QStringList &category )
189+
{
190+
mKeywords.insert( "gmd:topicCategory", category );
191+
}
192+
171193
QList<QgsLayerMetadata::Contact> QgsLayerMetadata::contacts() const
172194
{
173195
return mContacts;

‎src/core/metadata/qgslayermetadata.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ class CORE_EXPORT QgsLayerMetadata
545545
* CRS which is actually used to display and manipulate the layer within QGIS.
546546
* This may be the case when a layer has an incorrect CRS within its metadata
547547
* and a user has manually overridden the layer's CRS within QGIS.
548-
* \see setCrs()
548+
* \see crs()
549549
*/
550550
void setCrs( const QgsCoordinateReferenceSystem &crs );
551551

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

591+
/**
592+
* Remove a vocabulary from the list.
593+
*
594+
* \see setKeywords()
595+
* \see addKeywords()
596+
*/
597+
bool removeKeywords( const QString &vocabulary );
598+
591599
/**
592600
* Returns a list of keyword vocabularies contained in the metadata.
593601
*
@@ -610,6 +618,22 @@ class CORE_EXPORT QgsLayerMetadata
610618
*/
611619
QStringList keywords( const QString &vocabulary ) const;
612620

621+
/**
622+
* Returns categories of the resource.
623+
* Categories are stored using a special vocabulary 'gmd:topicCategory' in keywords.
624+
*
625+
* \see keywords()
626+
*/
627+
QStringList categories() const;
628+
629+
/**
630+
* Sets categories of the resource.
631+
* Categories are stored using a special vocabulary 'gmd:topicCategory' in keywords.
632+
*
633+
* \see keywords()
634+
*/
635+
void setCategories( const QStringList &categories );
636+
613637
/**
614638
* Returns a list of contact persons or entities associated with the resource.
615639
* \see setContacts()

‎tests/src/python/test_qgslayermetadata.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ def testGettersSetters(self):
4848
m.setTitle('title')
4949
self.assertEqual(m.title(), 'title')
5050

51+
m.setCategories(['category'])
52+
self.assertEqual(m.categories(), ['category'])
53+
5154
m.setAbstract('abstract')
5255
self.assertEqual(m.abstract(), 'abstract')
5356

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

108+
m.setKeywords({'gmd:topicCategory': ['natural']})
109+
self.assertEqual(m.keywords(), {'gmd:topicCategory': ['natural']})
110+
self.assertEqual(m.categories(), ['natural'])
111+
self.assertTrue(m.removeKeywords('gmd:topicCategory'))
112+
105113
m.setKeywords({'vocab a': ['keyword a', 'other a'],
106114
'vocab b': ['keyword b', 'other b']})
107115
self.assertEqual(m.keywords(), {'vocab a': ['keyword a', 'other a'],

0 commit comments

Comments
 (0)
Please sign in to comment.