Skip to content
Permalink
Browse files

Make project title getters/setters a shortcut to metadata title field

And silently upgrade old project titles to metadata titles
  • Loading branch information
nyalldawson committed Mar 22, 2018
1 parent bba3f6c commit 99faf06f60eeae600937acc068dba9a631696e53
Showing with 32 additions and 10 deletions.
  1. +8 −0 python/core/qgsproject.sip.in
  2. +12 −9 src/core/qgsproject.cpp
  3. +5 −1 src/core/qgsproject.h
  4. +7 −0 tests/src/python/test_qgsprojectmetadata.py
@@ -54,6 +54,10 @@ Sets the project's title.

.. versionadded:: 2.4

.. note::

Since QGIS 3.2 this is just a shortcut to setting the title in the project's metadata().

.. seealso:: :py:func:`title`
%End

@@ -62,6 +66,10 @@ Sets the project's title.
Returns the project's title.

.. seealso:: :py:func:`setTitle`

.. note::

Since QGIS 3.2 this is just a shortcut to retrieving the title from the project's metadata().
%End

bool isDirty() const;
@@ -391,21 +391,20 @@ QgsProject *QgsProject::instance()

void QgsProject::setTitle( const QString &title )
{
if ( title == mTitle )
if ( title == mMetadata.title() )
return;

mTitle = title;
mMetadata.setTitle( title );
emit metadataChanged();

setDirty( true );
}


QString QgsProject::title() const
{
return mTitle;
return mMetadata.title();
}


bool QgsProject::isDirty() const
{
return mDirty;
@@ -504,7 +503,6 @@ void QgsProject::clear()
{
mFile.setFileName( QString() );
mProperties.clearKeys();
mTitle.clear();
mHomePath.clear();
mAutoTransaction = false;
mEvaluateDefaultValues = false;
@@ -876,7 +874,6 @@ bool QgsProject::readProjectFile( const QString &filename )


QgsDebugMsg( "Opened document " + projectFile.fileName() );
QgsDebugMsg( "Project title: " + mTitle );

// get project version string, if any
QgsProjectVersion fileVersion = getVersion( *doc );
@@ -912,8 +909,9 @@ bool QgsProject::readProjectFile( const QString &filename )

dump_( mProperties );

// now get project title
_getTitle( *doc, mTitle );
// get older style project title
QString oldTitle;
_getTitle( *doc, oldTitle );

QDomNodeList homePathNl = doc->elementsByTagName( QStringLiteral( "homePath" ) );
if ( homePathNl.count() > 0 )
@@ -981,6 +979,11 @@ bool QgsProject::readProjectFile( const QString &filename )
QDomElement metadataElement = nl.at( 0 ).toElement();
mMetadata.readMetadataXml( metadataElement );
}
if ( mMetadata.title().isEmpty() && !oldTitle.isEmpty() )
{
// upgrade older title storage to storing within project metadata.
mMetadata.setTitle( oldTitle );
}
emit metadataChanged();

nl = doc->elementsByTagName( QStringLiteral( "autotransaction" ) );
@@ -112,13 +112,18 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
* Sets the project's title.
* \param title new title
* \since QGIS 2.4
*
* \note Since QGIS 3.2 this is just a shortcut to setting the title in the project's metadata().
*
* \see title()
*/
void setTitle( const QString &title );

/**
* Returns the project's title.
* \see setTitle()
*
* \note Since QGIS 3.2 this is just a shortcut to retrieving the title from the project's metadata().
*/
QString title() const;

@@ -1285,7 +1290,6 @@ class CORE_EXPORT QgsProject : public QObject, public QgsExpressionContextGenera
*/
QString mHomePath;
mutable QgsProjectPropertyKey mProperties; // property hierarchy, TODO: this shouldn't be mutable
QString mTitle; // project title
bool mAutoTransaction = false; // transaction grouped editing
bool mEvaluateDefaultValues = false; // evaluate default values immediately
QgsCoordinateReferenceSystem mCrs;
@@ -342,6 +342,13 @@ def testProject(self):
self.assertEqual(len(metadata_changed_spy), 2)
self.assertEqual(p.metadata().author(), '')

# test that the project title is just a shortcut to the metadata title field
p.setTitle('my title')
self.assertEqual(p.metadata().title(), 'my title')
m.setTitle('my title 2')
p.setMetadata(m)
self.assertEqual(p.title(), 'my title 2')


if __name__ == '__main__':
unittest.main()

0 comments on commit 99faf06

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