Skip to content

Commit

Permalink
Use correct layout type (report/print layout) in new title dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 5, 2018
1 parent ce161e0 commit eae4eeb
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 14 deletions.
11 changes: 11 additions & 0 deletions python/core/layout/qgsmasterlayoutinterface.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions python/core/layout/qgsprintlayout.sip
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Constructor for QgsPrintLayout.

virtual QgsProject *layoutProject() const;

virtual QgsMasterLayoutInterface::Type layoutType() const;

virtual QIcon icon() const;


Expand Down
2 changes: 2 additions & 0 deletions python/core/layout/qgsreport.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/app/layout/qgslayoutmanagerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
22 changes: 17 additions & 5 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 )
{
Expand All @@ -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;

Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/app/qgisapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions src/core/layout/qgsmasterlayoutinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions src/core/layout/qgsprintlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,8 @@ QgsExpressionContext QgsPrintLayout::createExpressionContext() const

return context;
}

QgsMasterLayoutInterface::Type QgsPrintLayout::layoutType() const
{
return QgsMasterLayoutInterface::PrintLayout;
}
1 change: 1 addition & 0 deletions src/core/layout/qgsprintlayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
6 changes: 5 additions & 1 deletion src/core/layout/qgsreport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,9 @@ bool QgsReport::readLayoutXml( const QDomElement &layoutElement, const QDomDocum
return true;
}

///@endcond
QgsMasterLayoutInterface::Type QgsReport::layoutType() const
{
return QgsMasterLayoutInterface::Report;
}

///@endcond
1 change: 1 addition & 0 deletions src/core/layout/qgsreport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions tests/src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eae4eeb

Please sign in to comment.