Skip to content

Commit

Permalink
Add history item to metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 3, 2017
1 parent b2f52d8 commit bf2ce3d
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
22 changes: 22 additions & 0 deletions python/core/metadata/qgslayermetadata.sip
Expand Up @@ -355,6 +355,28 @@ class QgsLayerMetadata
\see licenses()
%End

QStringList history() const;
%Docstring
Returns a freeform description of the history or lineage of the resource.
\see setHistory()
:rtype: list of str
%End

void setHistory( const QStringList &history );
%Docstring
Sets the freeform description of the ``history`` or lineage of the resource.
Any existing history items will be overwritten.
\see addHistoryItem()
\see history()
%End

void addHistoryItem( const QString &text );
%Docstring
Adds a single history ``text`` to the end of the existing history list.
\see history()
\see setHistory()
%End

QString encoding() const;
%Docstring
Returns the character encoding of the data in the resource. An empty string will be returned if no encoding is set.
Expand Down
17 changes: 17 additions & 0 deletions src/core/metadata/qgslayermetadata.cpp
Expand Up @@ -108,6 +108,21 @@ void QgsLayerMetadata::setLicenses( const QStringList &licenses )
mLicenses = licenses;
}

QStringList QgsLayerMetadata::history() const
{
return mHistory;
}

void QgsLayerMetadata::setHistory( const QStringList &history )
{
mHistory = history;
}

void QgsLayerMetadata::addHistoryItem( const QString &text )
{
mHistory << text;
}

QString QgsLayerMetadata::encoding() const
{
return mEncoding;
Expand Down Expand Up @@ -204,6 +219,7 @@ void QgsLayerMetadata::saveToLayer( QgsMapLayer *layer ) const
layer->setCustomProperty( QStringLiteral( "metadata/fees" ), mFees );
layer->setCustomProperty( QStringLiteral( "metadata/rights" ), mRights );
layer->setCustomProperty( QStringLiteral( "metadata/licenses" ), mLicenses );
layer->setCustomProperty( QStringLiteral( "metadata/history" ), mHistory );
layer->setCustomProperty( QStringLiteral( "metadata/encoding" ), mEncoding );
layer->setCustomProperty( QStringLiteral( "metadata/crs" ), mCrs.authid() );
layer->setCustomProperty( QStringLiteral( "metadata/constraints" ), QVariant::fromValue( mConstraints ) );
Expand All @@ -223,6 +239,7 @@ void QgsLayerMetadata::readFromLayer( const QgsMapLayer *layer )
mFees = layer->customProperty( QStringLiteral( "metadata/fees" ) ).toString();
mRights = layer->customProperty( QStringLiteral( "metadata/rights" ) ).toStringList();
mLicenses = layer->customProperty( QStringLiteral( "metadata/licenses" ) ).toStringList();
mHistory = layer->customProperty( QStringLiteral( "metadata/history" ) ).toStringList();
mEncoding = layer->customProperty( QStringLiteral( "metadata/encoding" ) ).toString();
QString crsAuthId = layer->customProperty( QStringLiteral( "metadata/crs" ) ).toString();
mCrs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( crsAuthId );
Expand Down
22 changes: 22 additions & 0 deletions src/core/metadata/qgslayermetadata.h
Expand Up @@ -395,6 +395,27 @@ class CORE_EXPORT QgsLayerMetadata
*/
void setLicenses( const QStringList &licenses );

/**
* Returns a freeform description of the history or lineage of the resource.
* \see setHistory()
*/
QStringList history() const;

/**
* Sets the freeform description of the \a history or lineage of the resource.
* Any existing history items will be overwritten.
* \see addHistoryItem()
* \see history()
*/
void setHistory( const QStringList &history );

/**
* Adds a single history \a text to the end of the existing history list.
* \see history()
* \see setHistory()
*/
void addHistoryItem( const QString &text );

/**
* Returns the character encoding of the data in the resource. An empty string will be returned if no encoding is set.
* \see setEncoding()
Expand Down Expand Up @@ -572,6 +593,7 @@ class CORE_EXPORT QgsLayerMetadata
ConstraintList mConstraints;
QStringList mRights;
QStringList mLicenses;
QStringList mHistory;

// IMPORTANT - look up before adding anything here!!

Expand Down
9 changes: 9 additions & 0 deletions tests/src/python/test_qgslayermetadata.py
Expand Up @@ -59,6 +59,13 @@ def testGettersSetters(self):
m.setLicenses(['l a', 'l b'])
self.assertEqual(m.licenses(), ['l a', 'l b'])

m.setHistory(['loaded into QGIS'])
self.assertEqual(m.history(), ['loaded into QGIS'])
m.setHistory(['accidentally deleted some features'])
self.assertEqual(m.history(), ['accidentally deleted some features'])
m.addHistoryItem('panicked and deleted more')
self.assertEqual(m.history(), ['accidentally deleted some features', 'panicked and deleted more'])

m.setEncoding('encoding')
self.assertEqual(m.encoding(), 'encoding')

Expand Down Expand Up @@ -192,6 +199,7 @@ def createTestMetadata(self):
m.setConstraints([QgsLayerMetadata.Constraint('None', 'access')])
m.setRights(['Copyright foo 2017'])
m.setLicenses(['WTFPL'])
m.setHistory(['history a', 'history b'])
m.setKeywords({'GEMET': ['kw1', 'kw2']})
m.setEncoding('utf-8')
m.setCrs(QgsCoordinateReferenceSystem.fromOgcWmsCrs('EPSG:4326'))
Expand Down Expand Up @@ -254,6 +262,7 @@ def checkExpectedMetadata(self, m):
self.assertEqual(m.constraints()[0].type, 'access')
self.assertEqual(m.rights(), ['Copyright foo 2017'])
self.assertEqual(m.licenses(), ['WTFPL'])
self.assertEqual(m.history(), ['history a', 'history b'])
self.assertEqual(m.encoding(), 'utf-8')
self.assertEqual(m.keywords(), {'GEMET': ['kw1', 'kw2']})
self.assertEqual(m.crs().authid(), 'EPSG:4326')
Expand Down

0 comments on commit bf2ce3d

Please sign in to comment.