Skip to content

Commit f23b09b

Browse files
committed
[needs-docs][layouts] Expose menus and toolbars (and some other goodies) to stable
layout designer interface API This commit adds more methods to the public, stable API for the layout designer dialog, allowing plugins and scripts greater flexibility in extending and hooking into the layout designer. New API includes: - access to the main menus shown in the dialog, allowing custom actions to be added to the dialog - access to the dialog's toolbars - methods for adding (and removing) additional dock widgets to the designer - the method used to show/hide rulers in the designer
1 parent c28c314 commit f23b09b

6 files changed

+499
-10
lines changed

python/gui/auto_generated/layout/qgslayoutdesignerinterface.sip.in

+218
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,231 @@ shown and raised to the top of the interface.
9191
%End
9292

9393

94+
virtual QMenu *layoutMenu() = 0;
95+
%Docstring
96+
Returns a reference to the designer's "Layout" menu.
97+
98+
.. seealso:: :py:func:`editMenu`
99+
100+
.. seealso:: :py:func:`viewMenu`
101+
102+
.. seealso:: :py:func:`itemsMenu`
103+
104+
.. seealso:: :py:func:`atlasMenu`
105+
106+
.. seealso:: :py:func:`reportMenu`
107+
108+
.. seealso:: :py:func:`settingsMenu`
109+
110+
.. versionadded:: 3.4
111+
%End
112+
113+
virtual QMenu *editMenu() = 0;
114+
%Docstring
115+
Returns a reference to the designer's "Edit" menu.
116+
117+
.. seealso:: :py:func:`layoutMenu`
118+
119+
.. seealso:: :py:func:`viewMenu`
120+
121+
.. seealso:: :py:func:`itemsMenu`
122+
123+
.. seealso:: :py:func:`atlasMenu`
124+
125+
.. seealso:: :py:func:`reportMenu`
126+
127+
.. seealso:: :py:func:`settingsMenu`
128+
129+
.. versionadded:: 3.4
130+
%End
131+
132+
virtual QMenu *viewMenu() = 0;
133+
%Docstring
134+
Returns a reference to the designer's "View" menu.
135+
136+
.. seealso:: :py:func:`layoutMenu`
137+
138+
.. seealso:: :py:func:`editMenu`
139+
140+
.. seealso:: :py:func:`itemsMenu`
141+
142+
.. seealso:: :py:func:`atlasMenu`
143+
144+
.. seealso:: :py:func:`reportMenu`
145+
146+
.. seealso:: :py:func:`settingsMenu`
147+
148+
.. versionadded:: 3.4
149+
%End
150+
151+
virtual QMenu *itemsMenu() = 0;
152+
%Docstring
153+
Returns a reference to the designer's "Items" menu.
154+
155+
.. seealso:: :py:func:`layoutMenu`
156+
157+
.. seealso:: :py:func:`editMenu`
158+
159+
.. seealso:: :py:func:`viewMenu`
160+
161+
.. seealso:: :py:func:`atlasMenu`
162+
163+
.. seealso:: :py:func:`reportMenu`
164+
165+
.. seealso:: :py:func:`settingsMenu`
166+
167+
.. versionadded:: 3.4
168+
%End
169+
170+
virtual QMenu *atlasMenu() = 0;
171+
%Docstring
172+
Returns a reference to the designer's "Atlas" menu.
173+
174+
Note that this may not exist or may be hidden if the designer is in report mode.
175+
176+
.. seealso:: :py:func:`layoutMenu`
177+
178+
.. seealso:: :py:func:`editMenu`
179+
180+
.. seealso:: :py:func:`viewMenu`
181+
182+
.. seealso:: :py:func:`itemsMenu`
183+
184+
.. seealso:: :py:func:`reportMenu`
185+
186+
.. seealso:: :py:func:`settingsMenu`
187+
188+
.. versionadded:: 3.4
189+
%End
190+
191+
virtual QMenu *reportMenu() = 0;
192+
%Docstring
193+
Returns a reference to the designer's "Report" menu.
194+
195+
Note that this may not exist or may be hidden if the designer is not in report mode.
196+
197+
.. seealso:: :py:func:`layoutMenu`
198+
199+
.. seealso:: :py:func:`editMenu`
200+
201+
.. seealso:: :py:func:`viewMenu`
202+
203+
.. seealso:: :py:func:`itemsMenu`
204+
205+
.. seealso:: :py:func:`atlasMenu`
206+
207+
.. seealso:: :py:func:`settingsMenu`
208+
209+
.. versionadded:: 3.4
210+
%End
211+
212+
virtual QMenu *settingsMenu() = 0;
213+
%Docstring
214+
Returns a reference to the designer's "Settings" menu.
215+
216+
.. seealso:: :py:func:`layoutMenu`
217+
218+
.. seealso:: :py:func:`editMenu`
219+
220+
.. seealso:: :py:func:`viewMenu`
221+
222+
.. seealso:: :py:func:`itemsMenu`
223+
224+
.. seealso:: :py:func:`atlasMenu`
225+
226+
.. seealso:: :py:func:`reportMenu`
227+
228+
.. versionadded:: 3.4
229+
%End
230+
231+
virtual QToolBar *layoutToolbar() = 0;
232+
%Docstring
233+
Returns a reference to the designer's "Layout" toolbar.
234+
235+
.. seealso:: :py:func:`navigationToolbar`
236+
237+
.. seealso:: :py:func:`actionsToolbar`
238+
239+
.. seealso:: :py:func:`atlasToolbar`
240+
241+
.. versionadded:: 3.4
242+
%End
243+
244+
virtual QToolBar *navigationToolbar() = 0;
245+
%Docstring
246+
Returns a reference to the designer's "Navigation" toolbar.
247+
248+
.. seealso:: :py:func:`layoutToolbar`
249+
250+
.. seealso:: :py:func:`actionsToolbar`
251+
252+
.. seealso:: :py:func:`atlasToolbar`
253+
254+
.. versionadded:: 3.4
255+
%End
256+
257+
virtual QToolBar *actionsToolbar() = 0;
258+
%Docstring
259+
Returns a reference to the designer's "Actions" toolbar.
260+
261+
.. seealso:: :py:func:`layoutToolbar`
262+
263+
.. seealso:: :py:func:`navigationToolbar`
264+
265+
.. seealso:: :py:func:`atlasToolbar`
266+
267+
.. versionadded:: 3.4
268+
%End
269+
270+
virtual QToolBar *atlasToolbar() = 0;
271+
%Docstring
272+
Returns a reference to the designer's "Atlas" toolbar.
273+
274+
Note that this toolbar may not exist or may be hidden if the
275+
designer is in report mode.
276+
277+
.. seealso:: :py:func:`layoutToolbar`
278+
279+
.. seealso:: :py:func:`navigationToolbar`
280+
281+
.. seealso:: :py:func:`actionsToolbar`
282+
283+
.. versionadded:: 3.4
284+
%End
285+
286+
virtual void addDockWidget( Qt::DockWidgetArea area, QDockWidget *dock ) = 0;
287+
%Docstring
288+
Adds a ``dock`` widget to the layout designer, in the specified dock ``area``.
289+
290+
.. seealso:: :py:func:`removeDockWidget`
291+
292+
.. versionadded:: 3.4
293+
%End
294+
295+
virtual void removeDockWidget( QDockWidget *dock ) = 0;
296+
%Docstring
297+
Removes the specified ``dock`` widget from layout designer (without deleting it).
298+
299+
.. seealso:: :py:func:`addDockWidget`
300+
301+
.. versionadded:: 3.4
302+
%End
303+
94304
public slots:
95305

96306
virtual void close() = 0;
97307
%Docstring
98308
Closes the layout designer.
99309
%End
100310

311+
virtual void showRulers( bool visible ) = 0;
312+
%Docstring
313+
Toggles whether or not the rulers should be ``visible`` in the designer.
314+
315+
.. versionadded:: 3.4
316+
%End
317+
318+
101319
};
102320

103321
/************************************************************************

python/gui/auto_generated/qgisinterface.sip.in

+6-2
Original file line numberDiff line numberDiff line change
@@ -916,12 +916,16 @@ Remove action from the Web menu
916916

917917
virtual void addDockWidget( Qt::DockWidgetArea area, QDockWidget *dockwidget ) = 0;
918918
%Docstring
919-
Add a dock widget to the main window
919+
Adds a ``dock`` widget to the main window, in the specified dock ``area``.
920+
921+
.. seealso:: :py:func:`removeDockWidget`
920922
%End
921923

922924
virtual void removeDockWidget( QDockWidget *dockwidget ) = 0;
923925
%Docstring
924-
Remove specified dock widget from main window (doesn't delete it).
926+
Removes the specified ``dock`` widget from main window (without deleting it).
927+
928+
.. seealso:: :py:func:`addDockWidget`
925929
%End
926930

927931
virtual void showLayerProperties( QgsMapLayer *l ) = 0;

src/app/layout/qgslayoutdesignerdialog.cpp

+70-5
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,81 @@ void QgsAppLayoutDesignerInterface::showItemOptions( QgsLayoutItem *item, bool b
142142
mDesigner->showItemOptions( item, bringPanelToFront );
143143
}
144144

145+
QMenu *QgsAppLayoutDesignerInterface::layoutMenu()
146+
{
147+
return mDesigner->mLayoutMenu;
148+
}
149+
150+
QMenu *QgsAppLayoutDesignerInterface::editMenu()
151+
{
152+
return mDesigner->menuEdit;
153+
}
154+
155+
QMenu *QgsAppLayoutDesignerInterface::viewMenu()
156+
{
157+
return mDesigner->mMenuView;
158+
}
159+
160+
QMenu *QgsAppLayoutDesignerInterface::itemsMenu()
161+
{
162+
return mDesigner->menuLayout;
163+
}
164+
165+
QMenu *QgsAppLayoutDesignerInterface::atlasMenu()
166+
{
167+
return mDesigner->mMenuAtlas;
168+
}
169+
170+
QMenu *QgsAppLayoutDesignerInterface::reportMenu()
171+
{
172+
return mDesigner->mMenuReport;
173+
}
174+
175+
QMenu *QgsAppLayoutDesignerInterface::settingsMenu()
176+
{
177+
return mDesigner->menuSettings;
178+
}
179+
180+
QToolBar *QgsAppLayoutDesignerInterface::layoutToolbar()
181+
{
182+
return mDesigner->mLayoutToolbar;
183+
}
184+
185+
QToolBar *QgsAppLayoutDesignerInterface::navigationToolbar()
186+
{
187+
return mDesigner->mNavigationToolbar;
188+
}
189+
190+
QToolBar *QgsAppLayoutDesignerInterface::actionsToolbar()
191+
{
192+
return mDesigner->mActionsToolbar;
193+
}
194+
195+
QToolBar *QgsAppLayoutDesignerInterface::atlasToolbar()
196+
{
197+
return mDesigner->mAtlasToolbar;
198+
}
199+
200+
void QgsAppLayoutDesignerInterface::addDockWidget( Qt::DockWidgetArea area, QDockWidget *dock )
201+
{
202+
mDesigner->addDockWidget( area, dock );
203+
}
204+
205+
void QgsAppLayoutDesignerInterface::removeDockWidget( QDockWidget *dock )
206+
{
207+
mDesigner->removeDockWidget( dock );
208+
}
209+
145210
void QgsAppLayoutDesignerInterface::close()
146211
{
147212
mDesigner->close();
148213
}
149214

215+
void QgsAppLayoutDesignerInterface::showRulers( bool visible )
216+
{
217+
mDesigner->showRulers( visible );
218+
}
219+
150220

151221
static bool cmpByText_( QAction *a, QAction *b )
152222
{
@@ -1895,7 +1965,6 @@ void QgsLayoutDesignerDialog::exportToRaster()
18951965

18961966
QgsLayoutExporter exporter( mLayout );
18971967

1898-
QFileInfo fi( fileNExt.first );
18991968
QgsLayoutExporter::ExportResult result = exporter.exportToImage( fileNExt.first, settings );
19001969

19011970
proxyTask->finalize( result == QgsLayoutExporter::Success );
@@ -2909,8 +2978,6 @@ void QgsLayoutDesignerDialog::exportAtlasToPdf()
29092978
pdfSettings.rasterizeWholeImage = mLayout->customProperty( QStringLiteral( "rasterize" ), false ).toBool();
29102979
pdfSettings.forceVectorOutput = mLayout->customProperty( QStringLiteral( "forceVector" ), false ).toBool();
29112980

2912-
QFileInfo fi( outputFileName );
2913-
29142981
QString error;
29152982
std::unique_ptr< QgsFeedback > feedback = qgis::make_unique< QgsFeedback >();
29162983
std::unique_ptr< QProgressDialog > progressDialog = qgis::make_unique< QProgressDialog >( tr( "Rendering maps…" ), tr( "Abort" ), 0, 100, this );
@@ -3300,8 +3367,6 @@ void QgsLayoutDesignerDialog::exportReportToPdf()
33003367
pdfSettings.rasterizeWholeImage = rasterize;
33013368
pdfSettings.forceVectorOutput = forceVectorOutput;
33023369

3303-
QFileInfo fi( outputFileName );
3304-
33053370
QString error;
33063371
std::unique_ptr< QgsFeedback > feedback = qgis::make_unique< QgsFeedback >();
33073372
std::unique_ptr< QProgressDialog > progressDialog = qgis::make_unique< QProgressDialog >( tr( "Rendering maps…" ), tr( "Abort" ), 0, 0, this );

src/app/layout/qgslayoutdesignerdialog.h

+16-1
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,24 @@ class QgsAppLayoutDesignerInterface : public QgsLayoutDesignerInterface
6363
void setAtlasPreviewEnabled( bool enabled ) override;
6464
bool atlasPreviewEnabled() const override;
6565
void showItemOptions( QgsLayoutItem *item, bool bringPanelToFront = true ) override;
66+
QMenu *layoutMenu() override;
67+
QMenu *editMenu() override;
68+
QMenu *viewMenu() override;
69+
QMenu *itemsMenu() override;
70+
QMenu *atlasMenu() override;
71+
QMenu *reportMenu() override;
72+
QMenu *settingsMenu() override;
73+
QToolBar *layoutToolbar() override;
74+
QToolBar *navigationToolbar() override;
75+
QToolBar *actionsToolbar() override;
76+
QToolBar *atlasToolbar() override;
77+
void addDockWidget( Qt::DockWidgetArea area, QDockWidget *dock ) override;
78+
void removeDockWidget( QDockWidget *dock ) override;
79+
6680
public slots:
6781

6882
void close() override;
83+
void showRulers( bool visible ) override;
6984

7085
private:
7186

@@ -76,7 +91,7 @@ class QgsAppLayoutDesignerInterface : public QgsLayoutDesignerInterface
7691
* \ingroup app
7792
* \brief A window for designing layouts.
7893
*/
79-
class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesignerBase
94+
class QgsLayoutDesignerDialog: public QMainWindow, public Ui::QgsLayoutDesignerBase
8095
{
8196
Q_OBJECT
8297

0 commit comments

Comments
 (0)