Skip to content
Permalink
Browse files

Start hooking up map widget gui

  • Loading branch information
nyalldawson committed Oct 20, 2017
1 parent 23d0617 commit 753f6f5050e6f522153c7ec56b562d90cddbd1b0
@@ -63,6 +63,8 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
UndoShapeStyle,
UndoShapeCornerRadius,
UndoNodeMove,
UndoAtlasMargin,
UndoMapRotation,
};

explicit QgsLayoutItem( QgsLayout *layout, bool manageZValue = true );
@@ -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
@@ -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``.
@@ -27,6 +27,8 @@
#include "qgslayoutitempolyline.h"
#include "qgslayoutpolygonwidget.h"
#include "qgslayoutpolylinewidget.h"
#include "qgisapp.h"
#include "qgsmapcanvas.h"

void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
{
@@ -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 *

0 comments on commit 753f6f5

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