Skip to content

Commit

Permalink
Add button in layout manager dialog to create a new report
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 5, 2018
1 parent 56332b3 commit 78f2174
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/app/layout/qgslayoutmanagerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ QgsLayoutManagerDialog::QgsLayoutManagerDialog( QWidget *parent, Qt::WindowFlags
mShowButton = mButtonBox->addButton( tr( "&Show" ), QDialogButtonBox::ActionRole );
connect( mShowButton, &QAbstractButton::clicked, this, &QgsLayoutManagerDialog::showClicked );

mCreateReportButton = mButtonBox->addButton( tr( "Create &Report" ), QDialogButtonBox::ActionRole );
connect( mCreateReportButton, &QAbstractButton::clicked, this, &QgsLayoutManagerDialog::createReport );

mDuplicateButton = mButtonBox->addButton( tr( "&Duplicate" ), QDialogButtonBox::ActionRole );
connect( mDuplicateButton, &QAbstractButton::clicked, this, &QgsLayoutManagerDialog::duplicateClicked );

Expand Down Expand Up @@ -287,6 +290,31 @@ void QgsLayoutManagerDialog::mTemplatesUserDirBtn_pressed()
openLocalDirectory( mUserTemplatesDir );
}

void QgsLayoutManagerDialog::createReport()
{
QString title;
if ( !QgisApp::instance()->uniqueLayoutTitle( this, title, true ) )
{
return;
}

if ( title.isEmpty() )
{
title = QgsProject::instance()->layoutManager()->generateUniqueTitle();
}

std::unique_ptr< QgsReport > report = qgis::make_unique< QgsReport >( QgsProject::instance() );
report->setName( title );

std::unique_ptr< QgsLayout > header = qgis::make_unique< QgsLayout >( QgsProject::instance() );
header->initializeDefaults();
report->setHeader( header.release() );
report->setHeaderEnabled( true );

QgisApp::instance()->openLayoutDesignerDialog( report.get() );
QgsProject::instance()->layoutManager()->addLayout( report.release() );
}

void QgsLayoutManagerDialog::openLocalDirectory( const QString &localDirPath )
{
QDir localDir;
Expand Down
2 changes: 2 additions & 0 deletions src/app/layout/qgslayoutmanagerdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class QgsLayoutManagerDialog: public QDialog, private Ui::QgsLayoutManagerBase
QPushButton *mRemoveButton = nullptr;
QPushButton *mRenameButton = nullptr;
QPushButton *mDuplicateButton = nullptr;
QPushButton *mCreateReportButton = nullptr;
QgsLayoutManagerModel *mModel = nullptr;

#ifdef Q_OS_MAC
Expand All @@ -112,6 +113,7 @@ class QgsLayoutManagerDialog: public QDialog, private Ui::QgsLayoutManagerBase
//! Slot to open user templates dir with user's system
void mTemplatesUserDirBtn_pressed();

void createReport();
void removeClicked();
void showClicked();
//! Duplicate layout
Expand Down

0 comments on commit 78f2174

Please sign in to comment.