Skip to content
Permalink
Browse files

Auto generated names for reports are 'Report #'

  • Loading branch information
nyalldawson committed Jan 5, 2018
1 parent b184c5e commit 3ac214170fec52ca7e650ff6efb587e5842703b8
@@ -161,9 +161,9 @@ Generates a unique title for a new composition, which does not
clash with any already contained by the manager.
%End

QString generateUniqueTitle() const;
QString generateUniqueTitle( QgsMasterLayoutInterface::Type type = QgsMasterLayoutInterface::PrintLayout ) const;
%Docstring
Generates a unique title for a new layout, which does not
Generates a unique title for a new layout of the specified ``type``, which does not
clash with any already contained by the manager.
%End

@@ -249,7 +249,7 @@ void QgsLayoutManagerDialog::mAddButton_clicked()

if ( title.isEmpty() )
{
title = QgsProject::instance()->layoutManager()->generateUniqueTitle();
title = QgsProject::instance()->layoutManager()->generateUniqueTitle( QgsMasterLayoutInterface::PrintLayout );
}

std::unique_ptr< QgsPrintLayout > layout = qgis::make_unique< QgsPrintLayout >( QgsProject::instance() );
@@ -302,7 +302,7 @@ void QgsLayoutManagerDialog::createReport()

if ( title.isEmpty() )
{
title = QgsProject::instance()->layoutManager()->generateUniqueTitle();
title = QgsProject::instance()->layoutManager()->generateUniqueTitle( QgsMasterLayoutInterface::Report );
}

std::unique_ptr< QgsReport > report = qgis::make_unique< QgsReport >( QgsProject::instance() );
@@ -7392,7 +7392,7 @@ bool QgisApp::uniqueLayoutTitle( QWidget *parent, QString &title, bool acceptEmp
else
{
titleValid = true;
newTitle = QgsProject::instance()->layoutManager()->generateUniqueTitle();
newTitle = QgsProject::instance()->layoutManager()->generateUniqueTitle( type );
}
}
else if ( layoutNames.indexOf( newTitle, 1 ) >= 0 )
@@ -7461,7 +7461,7 @@ QgsLayoutDesignerDialog *QgisApp::createNewLayout( QString title )
{
if ( title.isEmpty() )
{
title = QgsProject::instance()->layoutManager()->generateUniqueTitle();
title = QgsProject::instance()->layoutManager()->generateUniqueTitle( QgsMasterLayoutInterface::PrintLayout );
}
//create new layout object
QgsPrintLayout *layout = new QgsPrintLayout( QgsProject::instance() );
@@ -355,7 +355,7 @@ QString QgsLayoutManager::generateUniqueComposerTitle() const
return name;
}

QString QgsLayoutManager::generateUniqueTitle() const
QString QgsLayoutManager::generateUniqueTitle( QgsMasterLayoutInterface::Type type ) const
{
QStringList names;
for ( QgsMasterLayoutInterface *l : mLayouts )
@@ -366,7 +366,15 @@ QString QgsLayoutManager::generateUniqueTitle() const
int id = 1;
while ( name.isEmpty() || names.contains( name ) )
{
name = tr( "Layout %1" ).arg( id );
switch ( type )
{
case QgsMasterLayoutInterface::PrintLayout:
name = tr( "Layout %1" ).arg( id );
break;
case QgsMasterLayoutInterface::Report:
name = tr( "Report %1" ).arg( id );
break;
}
id++;
}
return name;
@@ -161,10 +161,10 @@ class CORE_EXPORT QgsLayoutManager : public QObject
QString generateUniqueComposerTitle() const;

/**
* Generates a unique title for a new layout, which does not
* Generates a unique title for a new layout of the specified \a type, which does not
* clash with any already contained by the manager.
*/
QString generateUniqueTitle() const;
QString generateUniqueTitle( QgsMasterLayoutInterface::Type type = QgsMasterLayoutInterface::PrintLayout ) const;

signals:

@@ -19,7 +19,9 @@
from qgis.core import (QgsComposition,
QgsPrintLayout,
QgsLayoutManager,
QgsProject)
QgsProject,
QgsReport,
QgsMasterLayoutInterface)

from qgis.testing import start_app, unittest
from utilities import unitTestDataPath
@@ -375,20 +377,29 @@ def testDuplicateComposition(self):
def testGenerateUniqueTitle(self):
project = QgsProject()
manager = QgsLayoutManager(project)
self.assertEqual(manager.generateUniqueTitle(), 'Layout 1')
self.assertEqual(manager.generateUniqueTitle(QgsMasterLayoutInterface.PrintLayout), 'Layout 1')
self.assertEqual(manager.generateUniqueTitle(QgsMasterLayoutInterface.Report), 'Report 1')

layout = QgsPrintLayout(project)
layout.setName(manager.generateUniqueTitle())
manager.addLayout(layout)

self.assertEqual(manager.generateUniqueTitle(), 'Layout 2')
self.assertEqual(manager.generateUniqueTitle(QgsMasterLayoutInterface.Report), 'Report 1')
layout2 = QgsPrintLayout(project)
layout2.setName(manager.generateUniqueTitle())
manager.addLayout(layout2)

self.assertEqual(manager.generateUniqueTitle(), 'Layout 3')

report1 = QgsReport(project)
report1.setName(manager.generateUniqueTitle(QgsMasterLayoutInterface.Report))
manager.addLayout(report1)
self.assertEqual(manager.generateUniqueTitle(QgsMasterLayoutInterface.Report), 'Report 2')

manager.clear()
self.assertEqual(manager.generateUniqueTitle(), 'Layout 1')
self.assertEqual(manager.generateUniqueTitle(QgsMasterLayoutInterface.Report), 'Report 1')

def testRenameSignalCompositions(self):
project = QgsProject()

0 comments on commit 3ac2141

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