Skip to content

Commit

Permalink
Start hooking up map widget gui
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 7, 2017
1 parent 23d0617 commit 753f6f5
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 101 deletions.
2 changes: 2 additions & 0 deletions python/core/layout/qgslayoutitem.sip
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
UndoShapeStyle,
UndoShapeCornerRadius,
UndoNodeMove,
UndoAtlasMargin,
UndoMapRotation,
};

explicit QgsLayoutItem( QgsLayout *layout, bool manageZValue = true );
Expand Down
17 changes: 17 additions & 0 deletions python/gui/layout/qgslayoutitemguiregistry.sip
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,21 @@ class QgsLayoutItemAbstractGuiMetadata
:rtype: QgsLayoutItem
%End

virtual void newItemAddedToLayout( QgsLayoutItem *item );
%Docstring
Called when a newly created item of the associated type has been added to a layout.

This is only called for additions which result from GUI operations - i.e. it is not
called for items added from templates.
%End

};






class QgsLayoutItemGuiGroup
{
%Docstring
Expand Down Expand Up @@ -230,6 +239,14 @@ class QgsLayoutItemGuiRegistry : QObject
:rtype: QgsLayoutItem
%End

void newItemAddedToLayout( int metadataId, QgsLayoutItem *item );
%Docstring
Called when a newly created item of the associated metadata ``metadataId`` has been added to a layout.

This is only called for additions which result from GUI operations - i.e. it is not
called for items added from templates.
%End

QgsLayoutItemBaseWidget *createItemWidget( QgsLayoutItem *item ) const /Factory/;
%Docstring
Creates a new instance of a layout item configuration widget for the specified ``item``.
Expand Down
18 changes: 15 additions & 3 deletions src/app/layout/qgslayoutapputils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "qgslayoutitempolyline.h"
#include "qgslayoutpolygonwidget.h"
#include "qgslayoutpolylinewidget.h"
#include "qgisapp.h"
#include "qgsmapcanvas.h"

void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
{
Expand All @@ -50,11 +52,21 @@ void QgsLayoutAppUtils::registerGuiForKnownItemTypes()

registry->addLayoutItemGuiMetadata( new QgsLayoutItemGuiMetadata( QgsLayoutItemRegistry::LayoutItem + 1002, QStringLiteral( "test" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddLabel.svg" ) ), nullptr, createRubberBand ) );

registry->addLayoutItemGuiMetadata( new QgsLayoutItemGuiMetadata( QgsLayoutItemRegistry::LayoutMap, QObject::tr( "Map" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddMap.svg" ) ),
[ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
auto mapItemMetadata = qgis::make_unique< QgsLayoutItemGuiMetadata >( QgsLayoutItemRegistry::LayoutMap, QObject::tr( "Map" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddMap.svg" ) ),
[ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
{
return new QgsLayoutMapWidget( qobject_cast< QgsLayoutItemMap * >( item ) );
}, createRubberBand ) );
}, createRubberBand );
mapItemMetadata->setItemAddedToLayoutFunction( [ = ]( QgsLayoutItem * item )
{
QgsLayoutItemMap *map = qobject_cast< QgsLayoutItemMap * >( item );
Q_ASSERT( map );
if ( QgisApp::instance()->mapCanvas() )
{
map->zoomToExtent( QgisApp::instance()->mapCanvas()->mapSettings().visibleExtent() );
}
} );
registry->addLayoutItemGuiMetadata( mapItemMetadata.release() );

auto createShapeWidget =
[]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
Expand Down
Loading

0 comments on commit 753f6f5

Please sign in to comment.