Skip to content
Permalink
Browse files

Make some actions apply to reports when a report designer is open

  • Loading branch information
nyalldawson committed Jan 5, 2018
1 parent 3ac2141 commit 37f5a3d5d1ebbf12ef17a57fc9d9ad54e4d81151
Showing with 53 additions and 3 deletions.
  1. +34 −3 src/app/layout/qgslayoutdesignerdialog.cpp
  2. +1 −0 src/app/layout/qgslayoutdesignerdialog.h
  3. +15 −0 src/app/qgisapp.cpp
  4. +3 −0 src/app/qgisapp.h
@@ -776,6 +776,8 @@ void QgsLayoutDesignerDialog::setMasterLayout( QgsMasterLayoutInterface *layout
mMenuReport = nullptr;
mReportToolbar->hide();
}

updateActionNames( mMasterLayout->layoutType() );
}

QgsMasterLayoutInterface *QgsLayoutDesignerDialog::masterLayout()
@@ -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()
@@ -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 );
@@ -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 )
@@ -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
@@ -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"
@@ -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
@@ -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.

0 comments on commit 37f5a3d

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