Skip to content

Commit 37f5a3d

Browse files
committedJan 5, 2018
Make some actions apply to reports when a report designer is open
1 parent 3ac2141 commit 37f5a3d

File tree

4 files changed

+53
-3
lines changed

4 files changed

+53
-3
lines changed
 

‎src/app/layout/qgslayoutdesignerdialog.cpp

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,8 @@ void QgsLayoutDesignerDialog::setMasterLayout( QgsMasterLayoutInterface *layout
776776
mMenuReport = nullptr;
777777
mReportToolbar->hide();
778778
}
779+
780+
updateActionNames( mMasterLayout->layoutType() );
779781
}
780782

781783
QgsMasterLayoutInterface *QgsLayoutDesignerDialog::masterLayout()
@@ -1554,11 +1556,21 @@ void QgsLayoutDesignerDialog::saveProject()
15541556
void QgsLayoutDesignerDialog::newLayout()
15551557
{
15561558
QString title;
1557-
if ( !QgisApp::instance()->uniqueLayoutTitle( this, title, true, QgsMasterLayoutInterface::PrintLayout ) )
1559+
if ( !QgisApp::instance()->uniqueLayoutTitle( this, title, true, mMasterLayout->layoutType() ) )
15581560
{
15591561
return;
15601562
}
1561-
QgisApp::instance()->createNewLayout( title );
1563+
1564+
switch ( mMasterLayout->layoutType() )
1565+
{
1566+
case QgsMasterLayoutInterface::PrintLayout:
1567+
QgisApp::instance()->createNewLayout( title );
1568+
break;
1569+
1570+
case QgsMasterLayoutInterface::Report:
1571+
QgisApp::instance()->createNewReport( title );
1572+
break;
1573+
}
15621574
}
15631575

15641576
void QgsLayoutDesignerDialog::showManager()
@@ -3901,7 +3913,6 @@ void QgsLayoutDesignerDialog::toggleActions( bool layoutAvailable )
39013913
mActionPasteInPlace->setEnabled( layoutAvailable );
39023914
mActionSaveAsTemplate->setEnabled( layoutAvailable );
39033915
mActionLoadFromTemplate->setEnabled( layoutAvailable );
3904-
mActionDuplicateLayout->setEnabled( layoutAvailable );
39053916
mActionExportAsImage->setEnabled( layoutAvailable );
39063917
mActionExportAsPDF->setEnabled( layoutAvailable );
39073918
mActionExportAsSVG->setEnabled( layoutAvailable );
@@ -3964,6 +3975,26 @@ QString QgsLayoutDesignerDialog::reportTypeString()
39643975
return tr( "report" );
39653976
}
39663977

3978+
void QgsLayoutDesignerDialog::updateActionNames( QgsMasterLayoutInterface::Type type )
3979+
{
3980+
switch ( type )
3981+
{
3982+
case QgsMasterLayoutInterface::PrintLayout:
3983+
mActionDuplicateLayout->setText( tr( "&Duplicate Layout…" ) );
3984+
mActionRemoveLayout->setText( tr( "Delete Layout…" ) );
3985+
mActionRenameLayout->setText( tr( "Rename Layout…" ) );
3986+
mActionNewLayout->setText( tr( "New Layout…" ) );
3987+
break;
3988+
3989+
case QgsMasterLayoutInterface::Report:
3990+
mActionDuplicateLayout->setText( tr( "&Duplicate Report…" ) );
3991+
mActionRemoveLayout->setText( tr( "Delete Report…" ) );
3992+
mActionRenameLayout->setText( tr( "Rename Report…" ) );
3993+
mActionNewLayout->setText( tr( "New Report…" ) );
3994+
break;
3995+
}
3996+
}
3997+
39673998
void QgsLayoutDesignerDialog::selectItems( const QList<QgsLayoutItem *> items )
39683999
{
39694000
for ( QGraphicsItem *item : items )

‎src/app/layout/qgslayoutdesignerdialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
479479
void setPrinterPageOrientation( QgsLayoutItemPage::Orientation orientation );
480480
QPrinter *printer();
481481
QString reportTypeString();
482+
void updateActionNames( QgsMasterLayoutInterface::Type type );
482483
};
483484

484485
#endif // QGSLAYOUTDESIGNERDIALOG_H

‎src/app/qgisapp.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
268268
#include "qgsrasterprojector.h"
269269
#include "qgsreadwritecontext.h"
270270
#include "qgsrectangle.h"
271+
#include "qgsreport.h"
271272
#include "qgsscalevisibilitydialog.h"
272273
#include "qgsgroupwmsdatadialog.h"
273274
#include "qgsselectbyformdialog.h"
@@ -7471,6 +7472,20 @@ QgsLayoutDesignerDialog *QgisApp::createNewLayout( QString title )
74717472
return openLayoutDesignerDialog( layout );
74727473
}
74737474

7475+
QgsLayoutDesignerDialog *QgisApp::createNewReport( QString title )
7476+
{
7477+
if ( title.isEmpty() )
7478+
{
7479+
title = QgsProject::instance()->layoutManager()->generateUniqueTitle( QgsMasterLayoutInterface::Report );
7480+
}
7481+
//create new report
7482+
std::unique_ptr< QgsReport > report = qgis::make_unique< QgsReport >( QgsProject::instance() );
7483+
report->setName( title );
7484+
QgsMasterLayoutInterface *layout = report.get();
7485+
QgsProject::instance()->layoutManager()->addLayout( report.release() );
7486+
return openLayoutDesignerDialog( layout );
7487+
}
7488+
74747489
QgsLayoutDesignerDialog *QgisApp::openLayoutDesignerDialog( QgsMasterLayoutInterface *layout )
74757490
{
74767491
// maybe a designer already open for this layout

‎src/app/qgisapp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
391391
//! Creates a new layout and returns a pointer to it
392392
QgsLayoutDesignerDialog *createNewLayout( QString title = QString() );
393393

394+
//! Creates a new report and returns a pointer to it
395+
QgsLayoutDesignerDialog *createNewReport( QString title = QString() );
396+
394397
/**
395398
* Opens a layout designer dialog for an existing \a layout.
396399
* If a designer already exists for this layout then it will be activated.

0 commit comments

Comments
 (0)
Please sign in to comment.