Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[needs-docs][layouts] Expose menus and toolbars (and some other goodi…
…es) 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
  • Loading branch information
nyalldawson committed Oct 19, 2018
1 parent c28c314 commit f23b09b
Show file tree
Hide file tree
Showing 6 changed files with 499 additions and 10 deletions.
218 changes: 218 additions & 0 deletions python/gui/auto_generated/layout/qgslayoutdesignerinterface.sip.in
Expand Up @@ -91,13 +91,231 @@ shown and raised to the top of the interface.
%End


virtual QMenu *layoutMenu() = 0;
%Docstring
Returns a reference to the designer's "Layout" menu.

.. seealso:: :py:func:`editMenu`

.. seealso:: :py:func:`viewMenu`

.. seealso:: :py:func:`itemsMenu`

.. seealso:: :py:func:`atlasMenu`

.. seealso:: :py:func:`reportMenu`

.. seealso:: :py:func:`settingsMenu`

.. versionadded:: 3.4
%End

virtual QMenu *editMenu() = 0;
%Docstring
Returns a reference to the designer's "Edit" menu.

.. seealso:: :py:func:`layoutMenu`

.. seealso:: :py:func:`viewMenu`

.. seealso:: :py:func:`itemsMenu`

.. seealso:: :py:func:`atlasMenu`

.. seealso:: :py:func:`reportMenu`

.. seealso:: :py:func:`settingsMenu`

.. versionadded:: 3.4
%End

virtual QMenu *viewMenu() = 0;
%Docstring
Returns a reference to the designer's "View" menu.

.. seealso:: :py:func:`layoutMenu`

.. seealso:: :py:func:`editMenu`

.. seealso:: :py:func:`itemsMenu`

.. seealso:: :py:func:`atlasMenu`

.. seealso:: :py:func:`reportMenu`

.. seealso:: :py:func:`settingsMenu`

.. versionadded:: 3.4
%End

virtual QMenu *itemsMenu() = 0;
%Docstring
Returns a reference to the designer's "Items" menu.

.. seealso:: :py:func:`layoutMenu`

.. seealso:: :py:func:`editMenu`

.. seealso:: :py:func:`viewMenu`

.. seealso:: :py:func:`atlasMenu`

.. seealso:: :py:func:`reportMenu`

.. seealso:: :py:func:`settingsMenu`

.. versionadded:: 3.4
%End

virtual QMenu *atlasMenu() = 0;
%Docstring
Returns a reference to the designer's "Atlas" menu.

Note that this may not exist or may be hidden if the designer is in report mode.

.. seealso:: :py:func:`layoutMenu`

.. seealso:: :py:func:`editMenu`

.. seealso:: :py:func:`viewMenu`

.. seealso:: :py:func:`itemsMenu`

.. seealso:: :py:func:`reportMenu`

.. seealso:: :py:func:`settingsMenu`

.. versionadded:: 3.4
%End

virtual QMenu *reportMenu() = 0;
%Docstring
Returns a reference to the designer's "Report" menu.

Note that this may not exist or may be hidden if the designer is not in report mode.

.. seealso:: :py:func:`layoutMenu`

.. seealso:: :py:func:`editMenu`

.. seealso:: :py:func:`viewMenu`

.. seealso:: :py:func:`itemsMenu`

.. seealso:: :py:func:`atlasMenu`

.. seealso:: :py:func:`settingsMenu`

.. versionadded:: 3.4
%End

virtual QMenu *settingsMenu() = 0;
%Docstring
Returns a reference to the designer's "Settings" menu.

.. seealso:: :py:func:`layoutMenu`

.. seealso:: :py:func:`editMenu`

.. seealso:: :py:func:`viewMenu`

.. seealso:: :py:func:`itemsMenu`

.. seealso:: :py:func:`atlasMenu`

.. seealso:: :py:func:`reportMenu`

.. versionadded:: 3.4
%End

virtual QToolBar *layoutToolbar() = 0;
%Docstring
Returns a reference to the designer's "Layout" toolbar.

.. seealso:: :py:func:`navigationToolbar`

.. seealso:: :py:func:`actionsToolbar`

.. seealso:: :py:func:`atlasToolbar`

.. versionadded:: 3.4
%End

virtual QToolBar *navigationToolbar() = 0;
%Docstring
Returns a reference to the designer's "Navigation" toolbar.

.. seealso:: :py:func:`layoutToolbar`

.. seealso:: :py:func:`actionsToolbar`

.. seealso:: :py:func:`atlasToolbar`

.. versionadded:: 3.4
%End

virtual QToolBar *actionsToolbar() = 0;
%Docstring
Returns a reference to the designer's "Actions" toolbar.

.. seealso:: :py:func:`layoutToolbar`

.. seealso:: :py:func:`navigationToolbar`

.. seealso:: :py:func:`atlasToolbar`

.. versionadded:: 3.4
%End

virtual QToolBar *atlasToolbar() = 0;
%Docstring
Returns a reference to the designer's "Atlas" toolbar.

Note that this toolbar may not exist or may be hidden if the
designer is in report mode.

.. seealso:: :py:func:`layoutToolbar`

.. seealso:: :py:func:`navigationToolbar`

.. seealso:: :py:func:`actionsToolbar`

.. versionadded:: 3.4
%End

virtual void addDockWidget( Qt::DockWidgetArea area, QDockWidget *dock ) = 0;
%Docstring
Adds a ``dock`` widget to the layout designer, in the specified dock ``area``.

.. seealso:: :py:func:`removeDockWidget`

.. versionadded:: 3.4
%End

virtual void removeDockWidget( QDockWidget *dock ) = 0;
%Docstring
Removes the specified ``dock`` widget from layout designer (without deleting it).

.. seealso:: :py:func:`addDockWidget`

.. versionadded:: 3.4
%End

public slots:

virtual void close() = 0;
%Docstring
Closes the layout designer.
%End

virtual void showRulers( bool visible ) = 0;
%Docstring
Toggles whether or not the rulers should be ``visible`` in the designer.

.. versionadded:: 3.4
%End


};

/************************************************************************
Expand Down
8 changes: 6 additions & 2 deletions python/gui/auto_generated/qgisinterface.sip.in
Expand Up @@ -916,12 +916,16 @@ Remove action from the Web menu

virtual void addDockWidget( Qt::DockWidgetArea area, QDockWidget *dockwidget ) = 0;
%Docstring
Add a dock widget to the main window
Adds a ``dock`` widget to the main window, in the specified dock ``area``.

.. seealso:: :py:func:`removeDockWidget`
%End

virtual void removeDockWidget( QDockWidget *dockwidget ) = 0;
%Docstring
Remove specified dock widget from main window (doesn't delete it).
Removes the specified ``dock`` widget from main window (without deleting it).

.. seealso:: :py:func:`addDockWidget`
%End

virtual void showLayerProperties( QgsMapLayer *l ) = 0;
Expand Down
75 changes: 70 additions & 5 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Expand Up @@ -142,11 +142,81 @@ void QgsAppLayoutDesignerInterface::showItemOptions( QgsLayoutItem *item, bool b
mDesigner->showItemOptions( item, bringPanelToFront );
}

QMenu *QgsAppLayoutDesignerInterface::layoutMenu()
{
return mDesigner->mLayoutMenu;
}

QMenu *QgsAppLayoutDesignerInterface::editMenu()
{
return mDesigner->menuEdit;
}

QMenu *QgsAppLayoutDesignerInterface::viewMenu()
{
return mDesigner->mMenuView;
}

QMenu *QgsAppLayoutDesignerInterface::itemsMenu()
{
return mDesigner->menuLayout;
}

QMenu *QgsAppLayoutDesignerInterface::atlasMenu()
{
return mDesigner->mMenuAtlas;
}

QMenu *QgsAppLayoutDesignerInterface::reportMenu()
{
return mDesigner->mMenuReport;
}

QMenu *QgsAppLayoutDesignerInterface::settingsMenu()
{
return mDesigner->menuSettings;
}

QToolBar *QgsAppLayoutDesignerInterface::layoutToolbar()
{
return mDesigner->mLayoutToolbar;
}

QToolBar *QgsAppLayoutDesignerInterface::navigationToolbar()
{
return mDesigner->mNavigationToolbar;
}

QToolBar *QgsAppLayoutDesignerInterface::actionsToolbar()
{
return mDesigner->mActionsToolbar;
}

QToolBar *QgsAppLayoutDesignerInterface::atlasToolbar()
{
return mDesigner->mAtlasToolbar;
}

void QgsAppLayoutDesignerInterface::addDockWidget( Qt::DockWidgetArea area, QDockWidget *dock )
{
mDesigner->addDockWidget( area, dock );
}

void QgsAppLayoutDesignerInterface::removeDockWidget( QDockWidget *dock )
{
mDesigner->removeDockWidget( dock );
}

void QgsAppLayoutDesignerInterface::close()
{
mDesigner->close();
}

void QgsAppLayoutDesignerInterface::showRulers( bool visible )
{
mDesigner->showRulers( visible );
}


static bool cmpByText_( QAction *a, QAction *b )
{
Expand Down Expand Up @@ -1895,7 +1965,6 @@ void QgsLayoutDesignerDialog::exportToRaster()

QgsLayoutExporter exporter( mLayout );

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

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

QFileInfo fi( outputFileName );

QString error;
std::unique_ptr< QgsFeedback > feedback = qgis::make_unique< QgsFeedback >();
std::unique_ptr< QProgressDialog > progressDialog = qgis::make_unique< QProgressDialog >( tr( "Rendering maps…" ), tr( "Abort" ), 0, 100, this );
Expand Down Expand Up @@ -3300,8 +3367,6 @@ void QgsLayoutDesignerDialog::exportReportToPdf()
pdfSettings.rasterizeWholeImage = rasterize;
pdfSettings.forceVectorOutput = forceVectorOutput;

QFileInfo fi( outputFileName );

QString error;
std::unique_ptr< QgsFeedback > feedback = qgis::make_unique< QgsFeedback >();
std::unique_ptr< QProgressDialog > progressDialog = qgis::make_unique< QProgressDialog >( tr( "Rendering maps…" ), tr( "Abort" ), 0, 0, this );
Expand Down
17 changes: 16 additions & 1 deletion src/app/layout/qgslayoutdesignerdialog.h
Expand Up @@ -63,9 +63,24 @@ class QgsAppLayoutDesignerInterface : public QgsLayoutDesignerInterface
void setAtlasPreviewEnabled( bool enabled ) override;
bool atlasPreviewEnabled() const override;
void showItemOptions( QgsLayoutItem *item, bool bringPanelToFront = true ) override;
QMenu *layoutMenu() override;
QMenu *editMenu() override;
QMenu *viewMenu() override;
QMenu *itemsMenu() override;
QMenu *atlasMenu() override;
QMenu *reportMenu() override;
QMenu *settingsMenu() override;
QToolBar *layoutToolbar() override;
QToolBar *navigationToolbar() override;
QToolBar *actionsToolbar() override;
QToolBar *atlasToolbar() override;
void addDockWidget( Qt::DockWidgetArea area, QDockWidget *dock ) override;
void removeDockWidget( QDockWidget *dock ) override;

public slots:

void close() override;
void showRulers( bool visible ) override;

private:

Expand All @@ -76,7 +91,7 @@ class QgsAppLayoutDesignerInterface : public QgsLayoutDesignerInterface
* \ingroup app
* \brief A window for designing layouts.
*/
class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesignerBase
class QgsLayoutDesignerDialog: public QMainWindow, public Ui::QgsLayoutDesignerBase
{
Q_OBJECT

Expand Down

0 comments on commit f23b09b

Please sign in to comment.