Skip to content
Permalink
Browse files

[needs-docs] Refactoring layout Manager dialog

  • Loading branch information
DelazJ authored and nyalldawson committed Apr 2, 2018
1 parent f6292d6 commit 035b3a7787dabb2cc52558b82c5de726062838fa
@@ -29,6 +29,7 @@
#include "qgsprintlayout.h"
#include "qgsreport.h"
#include "qgsreadwritecontext.h"
#include "qgshelp.h"

#include <QDesktopServices>
#include <QDialog>
@@ -71,23 +72,14 @@ QgsLayoutManagerDialog::QgsLayoutManagerDialog( QWidget *parent, Qt::WindowFlags
mLayoutListView->setModel( mProxyModel );

connect( mButtonBox, &QDialogButtonBox::rejected, this, &QWidget::close );
connect( mLayoutListView->selectionModel(), &QItemSelectionModel::selectionChanged,
connect( mButtonBox, &QDialogButtonBox::helpRequested, this, &QgsLayoutManagerDialog::showHelp );
connect( mLayoutListView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsLayoutManagerDialog::toggleButtons );
connect( mLayoutListView, &QListView::doubleClicked, this, &QgsLayoutManagerDialog::itemDoubleClicked );

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 );

mRemoveButton = mButtonBox->addButton( tr( "&Remove" ), QDialogButtonBox::ActionRole );
connect( mRemoveButton, &QAbstractButton::clicked, this, &QgsLayoutManagerDialog::removeClicked );

mRenameButton = mButtonBox->addButton( tr( "Re&name" ), QDialogButtonBox::ActionRole );
connect( mRenameButton, &QAbstractButton::clicked, this, &QgsLayoutManagerDialog::renameClicked );

#ifdef Q_OS_MAC
@@ -97,6 +89,7 @@ QgsLayoutManagerDialog::QgsLayoutManagerDialog( QWidget *parent, Qt::WindowFlags
#endif

mTemplate->addItem( tr( "Empty layout" ) );
mTemplate->addItem( tr( "Empty report" ) );
mTemplate->addItem( tr( "Specific" ) );

mUserTemplatesDir = QgsApplication::qgisSettingsDirPath() + "/composer_templates";
@@ -208,12 +201,12 @@ QMap<QString, QString> QgsLayoutManagerDialog::templatesFromPath( const QString
void QgsLayoutManagerDialog::mAddButton_clicked()
{
QFile templateFile;
bool loadingTemplate = ( mTemplate->currentIndex() > 0 );
bool loadingTemplate = ( mTemplate->currentIndex() > 1 );
QDomDocument templateDoc;
QString storedTitle;
if ( loadingTemplate )
{
if ( mTemplate->currentIndex() == 1 )
if ( mTemplate->currentIndex() == 2 )
{
templateFile.setFileName( mTemplateFileWidget->filePath() );
}
@@ -242,44 +235,51 @@ void QgsLayoutManagerDialog::mAddButton_clicked()
}
}

QString title;
if ( !QgisApp::instance()->uniqueLayoutTitle( this, title, true, QgsMasterLayoutInterface::PrintLayout, storedTitle ) )
if ( mTemplate->currentIndex() = 1 ) // if it's an empty report
{
return;
createReport();
}

if ( title.isEmpty() )
else
{
title = QgsProject::instance()->layoutManager()->generateUniqueTitle( QgsMasterLayoutInterface::PrintLayout );
}
QString title;
if ( !QgisApp::instance()->uniqueLayoutTitle( this, title, true, QgsMasterLayoutInterface::PrintLayout, storedTitle ) )
{
return;
}

std::unique_ptr< QgsPrintLayout > layout = qgis::make_unique< QgsPrintLayout >( QgsProject::instance() );
if ( loadingTemplate )
{
bool loadedOK = false;
( void )layout->loadFromTemplate( templateDoc, QgsReadWriteContext(), true, &loadedOK );
if ( !loadedOK )
if ( title.isEmpty() )
{
QMessageBox::warning( this, tr( "Create Layout" ), tr( "Invalid template file “%1”." ).arg( templateFile.fileName() ) );
layout.reset();
title = QgsProject::instance()->layoutManager()->generateUniqueTitle( QgsMasterLayoutInterface::PrintLayout );
}
}
else
{
layout->initializeDefaults();
}

if ( layout )
{
layout->setName( title );
QgisApp::instance()->openLayoutDesignerDialog( layout.get() );
QgsProject::instance()->layoutManager()->addLayout( layout.release() );
std::unique_ptr< QgsPrintLayout > layout = qgis::make_unique< QgsPrintLayout >( QgsProject::instance() );
if ( loadingTemplate )
{
bool loadedOK = false;
( void )layout->loadFromTemplate( templateDoc, QgsReadWriteContext(), true, &loadedOK );
if ( !loadedOK )
{
QMessageBox::warning( this, tr( "Create Layout" ), tr( "Invalid template file “%1”." ).arg( templateFile.fileName() ) );
layout.reset();
}
}
else
{
layout->initializeDefaults();
}

if ( layout )
{
layout->setName( title );
QgisApp::instance()->openLayoutDesignerDialog( layout.get() );
QgsProject::instance()->layoutManager()->addLayout( layout.release() );
}
}
}

void QgsLayoutManagerDialog::mTemplate_currentIndexChanged( int indx )
{
bool specific = ( indx == 1 ); // comes just after empty template
bool specific = ( indx == 2 ); // comes just after empty templates
mTemplateFileWidget->setEnabled( specific );
}

@@ -483,6 +483,11 @@ void QgsLayoutManagerDialog::itemDoubleClicked( const QModelIndex &index )
}
}

void QgsLayoutManagerDialog::showHelp()
{
QgsHelp::openHelp( QStringLiteral( "print_composer/overview_composer.html#the-layout-manager" ) );
}

//
// QgsLayoutManagerModel
//
@@ -124,7 +124,9 @@ class QgsLayoutManagerDialog: public QDialog, private Ui::QgsLayoutManagerBase
void mTemplatesDefaultDirBtn_pressed();
//! Slot to open user templates dir with user's system
void mTemplatesUserDirBtn_pressed();

//! Slot to open help file
void showHelp();

void createReport();
void removeClicked();
void showClicked();
@@ -25,14 +25,70 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListView" name="mLayoutListView">
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
</widget>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="1">
<widget class="QToolButton" name="mDuplicateButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&amp;Duplicate</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QToolButton" name="mRenameButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Re&amp;name</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QToolButton" name="mRemoveButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&amp;Remove</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="4">
<widget class="QListView" name="mLayoutListView">
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QToolButton" name="mShowButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&amp;Show</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QgsCollapsibleGroupBox" name="mTemplateGrpBox">
@@ -140,7 +196,7 @@
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
<set>QDialogButtonBox::Close|QDialogButtonBox::Help</set>
</property>
</widget>
</item>
@@ -162,6 +218,10 @@
</customwidgets>
<tabstops>
<tabstop>mLayoutListView</tabstop>
<tabstop>mShowButton</tabstop>
<tabstop>mDuplicateButton</tabstop>
<tabstop>mRemoveButton</tabstop>
<tabstop>mRenameButton</tabstop>
<tabstop>mTemplateGrpBox</tabstop>
<tabstop>mTemplate</tabstop>
<tabstop>mAddButton</tabstop>
@@ -171,34 +231,6 @@
</tabstops>
<resources>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
</resources>
<connections>
<connection>

0 comments on commit 035b3a7

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