Use correct layout type (report/print layout) in new title dialog

This commit is contained in:
Nyall Dawson 2018-01-05 11:52:57 +10:00
parent ce161e0e7d
commit eae4eeb8f5
13 changed files with 66 additions and 14 deletions

View File

@ -20,12 +20,23 @@ class QgsMasterLayoutInterface
%End
public:
enum Type
{
PrintLayout,
Report,
};
virtual ~QgsMasterLayoutInterface();
virtual QgsMasterLayoutInterface *clone() const = 0 /Factory/;
%Docstring
Creates a clone of the layout. Ownership of the returned layout
is transferred to the caller.
%End
virtual QgsMasterLayoutInterface::Type layoutType() const = 0;
%Docstring
Returns the master layout type.
%End
virtual QString name() const = 0;

View File

@ -30,6 +30,8 @@ Constructor for QgsPrintLayout.
virtual QgsProject *layoutProject() const;
virtual QgsMasterLayoutInterface::Type layoutType() const;
virtual QIcon icon() const;

View File

@ -38,6 +38,8 @@ Constructor for QgsReport, associated with the specified
Note that ownership is not transferred to ``project``.
%End
virtual QgsMasterLayoutInterface::Type layoutType() const;
virtual QString type() const;
virtual QString description() const;
virtual QIcon icon() const;

View File

@ -1515,7 +1515,7 @@ void QgsLayoutDesignerDialog::addItemsFromTemplate()
void QgsLayoutDesignerDialog::duplicate()
{
QString newTitle;
if ( !QgisApp::instance()->uniqueLayoutTitle( this, newTitle, false, tr( "%1 copy" ).arg( masterLayout()->name() ) ) )
if ( !QgisApp::instance()->uniqueLayoutTitle( this, newTitle, false, masterLayout()->layoutType(), tr( "%1 copy" ).arg( masterLayout()->name() ) ) )
{
return;
}
@ -1546,7 +1546,7 @@ void QgsLayoutDesignerDialog::saveProject()
void QgsLayoutDesignerDialog::newLayout()
{
QString title;
if ( !QgisApp::instance()->uniqueLayoutTitle( this, title, true ) )
if ( !QgisApp::instance()->uniqueLayoutTitle( this, title, true, QgsMasterLayoutInterface::PrintLayout ) )
{
return;
}
@ -1568,7 +1568,7 @@ void QgsLayoutDesignerDialog::renameLayout()
{
QString currentTitle = masterLayout()->name();
QString newTitle;
if ( !QgisApp::instance()->uniqueLayoutTitle( this, newTitle, false, currentTitle ) )
if ( !QgisApp::instance()->uniqueLayoutTitle( this, newTitle, false, masterLayout()->layoutType(), currentTitle ) )
{
return;
}

View File

@ -242,7 +242,7 @@ void QgsLayoutManagerDialog::mAddButton_clicked()
}
QString title;
if ( !QgisApp::instance()->uniqueLayoutTitle( this, title, true, storedTitle ) )
if ( !QgisApp::instance()->uniqueLayoutTitle( this, title, true, QgsMasterLayoutInterface::PrintLayout, storedTitle ) )
{
return;
}
@ -295,7 +295,7 @@ void QgsLayoutManagerDialog::mTemplatesUserDirBtn_pressed()
void QgsLayoutManagerDialog::createReport()
{
QString title;
if ( !QgisApp::instance()->uniqueLayoutTitle( this, title, true ) )
if ( !QgisApp::instance()->uniqueLayoutTitle( this, title, true, QgsMasterLayoutInterface::Report ) )
{
return;
}
@ -427,7 +427,7 @@ void QgsLayoutManagerDialog::duplicateClicked()
QString currentTitle = currentLayout->name();
QString newTitle;
if ( !QgisApp::instance()->uniqueLayoutTitle( this, newTitle, false, tr( "%1 copy" ).arg( currentTitle ) ) )
if ( !QgisApp::instance()->uniqueLayoutTitle( this, newTitle, false, currentLayout->layoutType(), tr( "%1 copy" ).arg( currentTitle ) ) )
{
return;
}
@ -467,7 +467,7 @@ void QgsLayoutManagerDialog::renameClicked()
QString currentTitle = currentLayout->name();
QString newTitle;
if ( !QgisApp::instance()->uniqueLayoutTitle( this, newTitle, false, currentTitle ) )
if ( !QgisApp::instance()->uniqueLayoutTitle( this, newTitle, false, currentLayout->layoutType(), currentTitle ) )
{
return;
}

View File

@ -6002,7 +6002,7 @@ void QgisApp::newPrintComposer()
void QgisApp::newPrintLayout()
{
QString title;
if ( !uniqueLayoutTitle( this, title, true ) )
if ( !uniqueLayoutTitle( this, title, true, QgsMasterLayoutInterface::PrintLayout ) )
{
return;
}
@ -7335,7 +7335,7 @@ bool QgisApp::uniqueComposerTitle( QWidget *parent, QString &composerTitle, bool
return true;
}
bool QgisApp::uniqueLayoutTitle( QWidget *parent, QString &title, bool acceptEmpty, const QString &currentTitle )
bool QgisApp::uniqueLayoutTitle( QWidget *parent, QString &title, bool acceptEmpty, QgsMasterLayoutInterface::Type type, const QString &currentTitle )
{
if ( !parent )
{
@ -7344,10 +7344,22 @@ bool QgisApp::uniqueLayoutTitle( QWidget *parent, QString &title, bool acceptEmp
bool ok = false;
bool titleValid = false;
QString newTitle = QString( currentTitle );
QString chooseMsg = tr( "Create unique print layout title" );
QString typeString;
switch ( type )
{
case QgsMasterLayoutInterface::PrintLayout:
typeString = tr( "print layout" );
break;
case QgsMasterLayoutInterface::Report:
typeString = tr( "report" );
break;
}
QString chooseMsg = tr( "Enter a unique %1 title" ).arg( typeString );
if ( acceptEmpty )
{
chooseMsg += '\n' + tr( "(title generated if left empty)" );
chooseMsg += '\n' + tr( "(a title will be automatically generated if left empty)" );
}
QString titleMsg = chooseMsg;
@ -7361,7 +7373,7 @@ bool QgisApp::uniqueLayoutTitle( QWidget *parent, QString &title, bool acceptEmp
while ( !titleValid )
{
newTitle = QInputDialog::getText( parent,
tr( "Layout title" ),
tr( "Create %1 title" ).arg( typeString ),
titleMsg,
QLineEdit::Normal,
newTitle,

View File

@ -155,6 +155,7 @@ class QgsLayoutQptDropHandler;
#include "qgsmaplayeractionregistry.h"
#include "qgsoptionswidgetfactory.h"
#include "qgsattributetablefiltermodel.h"
#include "qgsmasterlayoutinterface.h"
#include "ui_qgisapp.h"
#include "qgis_app.h"
@ -376,7 +377,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
*
* \returns true if user did not cancel the dialog.
*/
bool uniqueLayoutTitle( QWidget *parent, QString &title, bool acceptEmpty, const QString &currentTitle = QString() );
bool uniqueLayoutTitle( QWidget *parent, QString &title, bool acceptEmpty, QgsMasterLayoutInterface::Type type, const QString &currentTitle = QString() );
//! Creates a new composer and returns a pointer to it

View File

@ -32,6 +32,13 @@ class CORE_EXPORT QgsMasterLayoutInterface
public:
//! Master layout type
enum Type
{
PrintLayout = 0, //!< Individual print layout (QgsPrintLayout)
Report = 1, //!< Report (QgsReport)
};
virtual ~QgsMasterLayoutInterface() = default;
/**
@ -40,6 +47,11 @@ class CORE_EXPORT QgsMasterLayoutInterface
*/
virtual QgsMasterLayoutInterface *clone() const = 0 SIP_FACTORY;
/**
* Returns the master layout type.
*/
virtual QgsMasterLayoutInterface::Type layoutType() const = 0;
/**
* Returns the layout's name.
* \see setName()

View File

@ -106,3 +106,8 @@ QgsExpressionContext QgsPrintLayout::createExpressionContext() const
return context;
}
QgsMasterLayoutInterface::Type QgsPrintLayout::layoutType() const
{
return QgsMasterLayoutInterface::PrintLayout;
}

View File

@ -41,6 +41,7 @@ class CORE_EXPORT QgsPrintLayout : public QgsLayout, public QgsMasterLayoutInter
QgsPrintLayout *clone() const override SIP_FACTORY;
QgsProject *layoutProject() const override;
QgsMasterLayoutInterface::Type layoutType() const override;
QIcon icon() const override;
/**

View File

@ -61,5 +61,9 @@ bool QgsReport::readLayoutXml( const QDomElement &layoutElement, const QDomDocum
return true;
}
///@endcond
QgsMasterLayoutInterface::Type QgsReport::layoutType() const
{
return QgsMasterLayoutInterface::Report;
}
///@endcond

View File

@ -52,6 +52,7 @@ class CORE_EXPORT QgsReport : public QObject, public QgsAbstractReportSection, p
*/
QgsReport( QgsProject *project );
QgsMasterLayoutInterface::Type layoutType() const override;
QString type() const override { return QStringLiteral( "SectionReport" ); }
QString description() const override { return QObject::tr( "Report" ); }
QIcon icon() const override;

View File

@ -8,6 +8,7 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/src/core/composer
${CMAKE_SOURCE_DIR}/src/core/expression
${CMAKE_SOURCE_DIR}/src/core/geometry
${CMAKE_SOURCE_DIR}/src/core/layout
${CMAKE_SOURCE_DIR}/src/core/metadata
${CMAKE_SOURCE_DIR}/src/core/raster
${CMAKE_SOURCE_DIR}/src/core/symbology