Skip to content

Commit 035b3a7

Browse files
DelazJnyalldawson
authored andcommitted
[needs-docs] Refactoring layout Manager dialog
1 parent f6292d6 commit 035b3a7

File tree

3 files changed

+116
-77
lines changed

3 files changed

+116
-77
lines changed

src/app/layout/qgslayoutmanagerdialog.cpp

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "qgsprintlayout.h"
3030
#include "qgsreport.h"
3131
#include "qgsreadwritecontext.h"
32+
#include "qgshelp.h"
3233

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

7374
connect( mButtonBox, &QDialogButtonBox::rejected, this, &QWidget::close );
74-
connect( mLayoutListView->selectionModel(), &QItemSelectionModel::selectionChanged,
75+
connect( mButtonBox, &QDialogButtonBox::helpRequested, this, &QgsLayoutManagerDialog::showHelp );
76+
connect( mLayoutListView->selectionModel(), &QItemSelectionModel::selectionChanged,
7577
this, &QgsLayoutManagerDialog::toggleButtons );
7678
connect( mLayoutListView, &QListView::doubleClicked, this, &QgsLayoutManagerDialog::itemDoubleClicked );
7779

78-
mShowButton = mButtonBox->addButton( tr( "&Show" ), QDialogButtonBox::ActionRole );
7980
connect( mShowButton, &QAbstractButton::clicked, this, &QgsLayoutManagerDialog::showClicked );
80-
81-
mCreateReportButton = mButtonBox->addButton( tr( "Create &Report" ), QDialogButtonBox::ActionRole );
82-
connect( mCreateReportButton, &QAbstractButton::clicked, this, &QgsLayoutManagerDialog::createReport );
83-
84-
mDuplicateButton = mButtonBox->addButton( tr( "&Duplicate" ), QDialogButtonBox::ActionRole );
8581
connect( mDuplicateButton, &QAbstractButton::clicked, this, &QgsLayoutManagerDialog::duplicateClicked );
86-
87-
mRemoveButton = mButtonBox->addButton( tr( "&Remove" ), QDialogButtonBox::ActionRole );
8882
connect( mRemoveButton, &QAbstractButton::clicked, this, &QgsLayoutManagerDialog::removeClicked );
89-
90-
mRenameButton = mButtonBox->addButton( tr( "Re&name" ), QDialogButtonBox::ActionRole );
9183
connect( mRenameButton, &QAbstractButton::clicked, this, &QgsLayoutManagerDialog::renameClicked );
9284

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

9991
mTemplate->addItem( tr( "Empty layout" ) );
92+
mTemplate->addItem( tr( "Empty report" ) );
10093
mTemplate->addItem( tr( "Specific" ) );
10194

10295
mUserTemplatesDir = QgsApplication::qgisSettingsDirPath() + "/composer_templates";
@@ -208,12 +201,12 @@ QMap<QString, QString> QgsLayoutManagerDialog::templatesFromPath( const QString
208201
void QgsLayoutManagerDialog::mAddButton_clicked()
209202
{
210203
QFile templateFile;
211-
bool loadingTemplate = ( mTemplate->currentIndex() > 0 );
204+
bool loadingTemplate = ( mTemplate->currentIndex() > 1 );
212205
QDomDocument templateDoc;
213206
QString storedTitle;
214207
if ( loadingTemplate )
215208
{
216-
if ( mTemplate->currentIndex() == 1 )
209+
if ( mTemplate->currentIndex() == 2 )
217210
{
218211
templateFile.setFileName( mTemplateFileWidget->filePath() );
219212
}
@@ -242,44 +235,51 @@ void QgsLayoutManagerDialog::mAddButton_clicked()
242235
}
243236
}
244237

245-
QString title;
246-
if ( !QgisApp::instance()->uniqueLayoutTitle( this, title, true, QgsMasterLayoutInterface::PrintLayout, storedTitle ) )
238+
if ( mTemplate->currentIndex() = 1 ) // if it's an empty report
247239
{
248-
return;
240+
createReport();
249241
}
250-
251-
if ( title.isEmpty() )
242+
else
252243
{
253-
title = QgsProject::instance()->layoutManager()->generateUniqueTitle( QgsMasterLayoutInterface::PrintLayout );
254-
}
244+
QString title;
245+
if ( !QgisApp::instance()->uniqueLayoutTitle( this, title, true, QgsMasterLayoutInterface::PrintLayout, storedTitle ) )
246+
{
247+
return;
248+
}
255249

256-
std::unique_ptr< QgsPrintLayout > layout = qgis::make_unique< QgsPrintLayout >( QgsProject::instance() );
257-
if ( loadingTemplate )
258-
{
259-
bool loadedOK = false;
260-
( void )layout->loadFromTemplate( templateDoc, QgsReadWriteContext(), true, &loadedOK );
261-
if ( !loadedOK )
250+
if ( title.isEmpty() )
262251
{
263-
QMessageBox::warning( this, tr( "Create Layout" ), tr( "Invalid template file “%1”." ).arg( templateFile.fileName() ) );
264-
layout.reset();
252+
title = QgsProject::instance()->layoutManager()->generateUniqueTitle( QgsMasterLayoutInterface::PrintLayout );
265253
}
266-
}
267-
else
268-
{
269-
layout->initializeDefaults();
270-
}
271254

272-
if ( layout )
273-
{
274-
layout->setName( title );
275-
QgisApp::instance()->openLayoutDesignerDialog( layout.get() );
276-
QgsProject::instance()->layoutManager()->addLayout( layout.release() );
255+
std::unique_ptr< QgsPrintLayout > layout = qgis::make_unique< QgsPrintLayout >( QgsProject::instance() );
256+
if ( loadingTemplate )
257+
{
258+
bool loadedOK = false;
259+
( void )layout->loadFromTemplate( templateDoc, QgsReadWriteContext(), true, &loadedOK );
260+
if ( !loadedOK )
261+
{
262+
QMessageBox::warning( this, tr( "Create Layout" ), tr( "Invalid template file “%1”." ).arg( templateFile.fileName() ) );
263+
layout.reset();
264+
}
265+
}
266+
else
267+
{
268+
layout->initializeDefaults();
269+
}
270+
271+
if ( layout )
272+
{
273+
layout->setName( title );
274+
QgisApp::instance()->openLayoutDesignerDialog( layout.get() );
275+
QgsProject::instance()->layoutManager()->addLayout( layout.release() );
276+
}
277277
}
278278
}
279279

280280
void QgsLayoutManagerDialog::mTemplate_currentIndexChanged( int indx )
281281
{
282-
bool specific = ( indx == 1 ); // comes just after empty template
282+
bool specific = ( indx == 2 ); // comes just after empty templates
283283
mTemplateFileWidget->setEnabled( specific );
284284
}
285285

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

486+
void QgsLayoutManagerDialog::showHelp()
487+
{
488+
QgsHelp::openHelp( QStringLiteral( "print_composer/overview_composer.html#the-layout-manager" ) );
489+
}
490+
486491
//
487492
// QgsLayoutManagerModel
488493
//

src/app/layout/qgslayoutmanagerdialog.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ class QgsLayoutManagerDialog: public QDialog, private Ui::QgsLayoutManagerBase
124124
void mTemplatesDefaultDirBtn_pressed();
125125
//! Slot to open user templates dir with user's system
126126
void mTemplatesUserDirBtn_pressed();
127-
127+
//! Slot to open help file
128+
void showHelp();
129+
128130
void createReport();
129131
void removeClicked();
130132
void showClicked();

src/ui/layout/qgslayoutmanagerbase.ui

Lines changed: 69 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,70 @@
2525
</property>
2626
<layout class="QVBoxLayout" name="verticalLayout">
2727
<item>
28-
<widget class="QListView" name="mLayoutListView">
29-
<property name="selectionMode">
30-
<enum>QAbstractItemView::ExtendedSelection</enum>
31-
</property>
32-
<property name="selectionBehavior">
33-
<enum>QAbstractItemView::SelectRows</enum>
34-
</property>
35-
</widget>
28+
<layout class="QGridLayout" name="gridLayout_2">
29+
<item row="1" column="1">
30+
<widget class="QToolButton" name="mDuplicateButton">
31+
<property name="sizePolicy">
32+
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
33+
<horstretch>0</horstretch>
34+
<verstretch>0</verstretch>
35+
</sizepolicy>
36+
</property>
37+
<property name="text">
38+
<string>&amp;Duplicate</string>
39+
</property>
40+
</widget>
41+
</item>
42+
<item row="1" column="3">
43+
<widget class="QToolButton" name="mRenameButton">
44+
<property name="sizePolicy">
45+
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
46+
<horstretch>0</horstretch>
47+
<verstretch>0</verstretch>
48+
</sizepolicy>
49+
</property>
50+
<property name="text">
51+
<string>Re&amp;name</string>
52+
</property>
53+
</widget>
54+
</item>
55+
<item row="1" column="2">
56+
<widget class="QToolButton" name="mRemoveButton">
57+
<property name="sizePolicy">
58+
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
59+
<horstretch>0</horstretch>
60+
<verstretch>0</verstretch>
61+
</sizepolicy>
62+
</property>
63+
<property name="text">
64+
<string>&amp;Remove</string>
65+
</property>
66+
</widget>
67+
</item>
68+
<item row="0" column="0" colspan="4">
69+
<widget class="QListView" name="mLayoutListView">
70+
<property name="selectionMode">
71+
<enum>QAbstractItemView::ExtendedSelection</enum>
72+
</property>
73+
<property name="selectionBehavior">
74+
<enum>QAbstractItemView::SelectRows</enum>
75+
</property>
76+
</widget>
77+
</item>
78+
<item row="1" column="0">
79+
<widget class="QToolButton" name="mShowButton">
80+
<property name="sizePolicy">
81+
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
82+
<horstretch>0</horstretch>
83+
<verstretch>0</verstretch>
84+
</sizepolicy>
85+
</property>
86+
<property name="text">
87+
<string>&amp;Show</string>
88+
</property>
89+
</widget>
90+
</item>
91+
</layout>
3692
</item>
3793
<item>
3894
<widget class="QgsCollapsibleGroupBox" name="mTemplateGrpBox">
@@ -140,7 +196,7 @@
140196
<enum>Qt::Horizontal</enum>
141197
</property>
142198
<property name="standardButtons">
143-
<set>QDialogButtonBox::Close</set>
199+
<set>QDialogButtonBox::Close|QDialogButtonBox::Help</set>
144200
</property>
145201
</widget>
146202
</item>
@@ -162,6 +218,10 @@
162218
</customwidgets>
163219
<tabstops>
164220
<tabstop>mLayoutListView</tabstop>
221+
<tabstop>mShowButton</tabstop>
222+
<tabstop>mDuplicateButton</tabstop>
223+
<tabstop>mRemoveButton</tabstop>
224+
<tabstop>mRenameButton</tabstop>
165225
<tabstop>mTemplateGrpBox</tabstop>
166226
<tabstop>mTemplate</tabstop>
167227
<tabstop>mAddButton</tabstop>
@@ -171,34 +231,6 @@
171231
</tabstops>
172232
<resources>
173233
<include location="../../../images/images.qrc"/>
174-
<include location="../../../images/images.qrc"/>
175-
<include location="../../../images/images.qrc"/>
176-
<include location="../../../images/images.qrc"/>
177-
<include location="../../../images/images.qrc"/>
178-
<include location="../../../images/images.qrc"/>
179-
<include location="../../../images/images.qrc"/>
180-
<include location="../../../images/images.qrc"/>
181-
<include location="../../../images/images.qrc"/>
182-
<include location="../../../images/images.qrc"/>
183-
<include location="../../../images/images.qrc"/>
184-
<include location="../../../images/images.qrc"/>
185-
<include location="../../../images/images.qrc"/>
186-
<include location="../../../images/images.qrc"/>
187-
<include location="../../../images/images.qrc"/>
188-
<include location="../../../images/images.qrc"/>
189-
<include location="../../../images/images.qrc"/>
190-
<include location="../../../images/images.qrc"/>
191-
<include location="../../../images/images.qrc"/>
192-
<include location="../../../images/images.qrc"/>
193-
<include location="../../../images/images.qrc"/>
194-
<include location="../../../images/images.qrc"/>
195-
<include location="../../../images/images.qrc"/>
196-
<include location="../../../images/images.qrc"/>
197-
<include location="../../../images/images.qrc"/>
198-
<include location="../../../images/images.qrc"/>
199-
<include location="../../../images/images.qrc"/>
200-
<include location="../../../images/images.qrc"/>
201-
<include location="../../../images/images.qrc"/>
202234
</resources>
203235
<connections>
204236
<connection>

0 commit comments

Comments
 (0)