Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make some actions apply to reports when a report designer is open
  • Loading branch information
nyalldawson committed Jan 5, 2018
1 parent 3ac2141 commit 37f5a3d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 3 deletions.
37 changes: 34 additions & 3 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Expand Up @@ -776,6 +776,8 @@ void QgsLayoutDesignerDialog::setMasterLayout( QgsMasterLayoutInterface *layout
mMenuReport = nullptr;
mReportToolbar->hide();
}

updateActionNames( mMasterLayout->layoutType() );
}

QgsMasterLayoutInterface *QgsLayoutDesignerDialog::masterLayout()
Expand Down Expand Up @@ -1554,11 +1556,21 @@ void QgsLayoutDesignerDialog::saveProject()
void QgsLayoutDesignerDialog::newLayout()
{
QString title;
if ( !QgisApp::instance()->uniqueLayoutTitle( this, title, true, QgsMasterLayoutInterface::PrintLayout ) )
if ( !QgisApp::instance()->uniqueLayoutTitle( this, title, true, mMasterLayout->layoutType() ) )
{
return;
}
QgisApp::instance()->createNewLayout( title );

switch ( mMasterLayout->layoutType() )
{
case QgsMasterLayoutInterface::PrintLayout:
QgisApp::instance()->createNewLayout( title );
break;

case QgsMasterLayoutInterface::Report:
QgisApp::instance()->createNewReport( title );
break;
}
}

void QgsLayoutDesignerDialog::showManager()
Expand Down Expand Up @@ -3901,7 +3913,6 @@ void QgsLayoutDesignerDialog::toggleActions( bool layoutAvailable )
mActionPasteInPlace->setEnabled( layoutAvailable );
mActionSaveAsTemplate->setEnabled( layoutAvailable );
mActionLoadFromTemplate->setEnabled( layoutAvailable );
mActionDuplicateLayout->setEnabled( layoutAvailable );
mActionExportAsImage->setEnabled( layoutAvailable );
mActionExportAsPDF->setEnabled( layoutAvailable );
mActionExportAsSVG->setEnabled( layoutAvailable );
Expand Down Expand Up @@ -3964,6 +3975,26 @@ QString QgsLayoutDesignerDialog::reportTypeString()
return tr( "report" );
}

void QgsLayoutDesignerDialog::updateActionNames( QgsMasterLayoutInterface::Type type )
{
switch ( type )
{
case QgsMasterLayoutInterface::PrintLayout:
mActionDuplicateLayout->setText( tr( "&Duplicate Layout…" ) );
mActionRemoveLayout->setText( tr( "Delete Layout…" ) );
mActionRenameLayout->setText( tr( "Rename Layout…" ) );
mActionNewLayout->setText( tr( "New Layout…" ) );
break;

case QgsMasterLayoutInterface::Report:
mActionDuplicateLayout->setText( tr( "&Duplicate Report…" ) );
mActionRemoveLayout->setText( tr( "Delete Report…" ) );
mActionRenameLayout->setText( tr( "Rename Report…" ) );
mActionNewLayout->setText( tr( "New Report…" ) );
break;
}
}

void QgsLayoutDesignerDialog::selectItems( const QList<QgsLayoutItem *> items )
{
for ( QGraphicsItem *item : items )
Expand Down
1 change: 1 addition & 0 deletions src/app/layout/qgslayoutdesignerdialog.h
Expand Up @@ -479,6 +479,7 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
void setPrinterPageOrientation( QgsLayoutItemPage::Orientation orientation );
QPrinter *printer();
QString reportTypeString();
void updateActionNames( QgsMasterLayoutInterface::Type type );
};

#endif // QGSLAYOUTDESIGNERDIALOG_H
Expand Down
15 changes: 15 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -268,6 +268,7 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
#include "qgsrasterprojector.h"
#include "qgsreadwritecontext.h"
#include "qgsrectangle.h"
#include "qgsreport.h"
#include "qgsscalevisibilitydialog.h"
#include "qgsgroupwmsdatadialog.h"
#include "qgsselectbyformdialog.h"
Expand Down Expand Up @@ -7471,6 +7472,20 @@ QgsLayoutDesignerDialog *QgisApp::createNewLayout( QString title )
return openLayoutDesignerDialog( layout );
}

QgsLayoutDesignerDialog *QgisApp::createNewReport( QString title )
{
if ( title.isEmpty() )
{
title = QgsProject::instance()->layoutManager()->generateUniqueTitle( QgsMasterLayoutInterface::Report );
}
//create new report
std::unique_ptr< QgsReport > report = qgis::make_unique< QgsReport >( QgsProject::instance() );
report->setName( title );
QgsMasterLayoutInterface *layout = report.get();
QgsProject::instance()->layoutManager()->addLayout( report.release() );
return openLayoutDesignerDialog( layout );
}

QgsLayoutDesignerDialog *QgisApp::openLayoutDesignerDialog( QgsMasterLayoutInterface *layout )
{
// maybe a designer already open for this layout
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgisapp.h
Expand Up @@ -391,6 +391,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! Creates a new layout and returns a pointer to it
QgsLayoutDesignerDialog *createNewLayout( QString title = QString() );

//! Creates a new report and returns a pointer to it
QgsLayoutDesignerDialog *createNewReport( QString title = QString() );

/**
* Opens a layout designer dialog for an existing \a layout.
* If a designer already exists for this layout then it will be activated.
Expand Down

0 comments on commit 37f5a3d

Please sign in to comment.