Skip to content

Commit 753f6f5

Browse files
committed
Start hooking up map widget gui
1 parent 23d0617 commit 753f6f5

File tree

10 files changed

+158
-101
lines changed

10 files changed

+158
-101
lines changed

python/core/layout/qgslayoutitem.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
6363
UndoShapeStyle,
6464
UndoShapeCornerRadius,
6565
UndoNodeMove,
66+
UndoAtlasMargin,
67+
UndoMapRotation,
6668
};
6769

6870
explicit QgsLayoutItem( QgsLayout *layout, bool manageZValue = true );

python/gui/layout/qgslayoutitemguiregistry.sip

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,21 @@ class QgsLayoutItemAbstractGuiMetadata
112112
:rtype: QgsLayoutItem
113113
%End
114114

115+
virtual void newItemAddedToLayout( QgsLayoutItem *item );
116+
%Docstring
117+
Called when a newly created item of the associated type has been added to a layout.
118+
119+
This is only called for additions which result from GUI operations - i.e. it is not
120+
called for items added from templates.
121+
%End
122+
115123
};
116124

117125

118126

119127

120128

129+
121130
class QgsLayoutItemGuiGroup
122131
{
123132
%Docstring
@@ -230,6 +239,14 @@ class QgsLayoutItemGuiRegistry : QObject
230239
:rtype: QgsLayoutItem
231240
%End
232241

242+
void newItemAddedToLayout( int metadataId, QgsLayoutItem *item );
243+
%Docstring
244+
Called when a newly created item of the associated metadata ``metadataId`` has been added to a layout.
245+
246+
This is only called for additions which result from GUI operations - i.e. it is not
247+
called for items added from templates.
248+
%End
249+
233250
QgsLayoutItemBaseWidget *createItemWidget( QgsLayoutItem *item ) const /Factory/;
234251
%Docstring
235252
Creates a new instance of a layout item configuration widget for the specified ``item``.

src/app/layout/qgslayoutapputils.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include "qgslayoutitempolyline.h"
2828
#include "qgslayoutpolygonwidget.h"
2929
#include "qgslayoutpolylinewidget.h"
30+
#include "qgisapp.h"
31+
#include "qgsmapcanvas.h"
3032

3133
void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
3234
{
@@ -50,11 +52,21 @@ void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
5052

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

53-
registry->addLayoutItemGuiMetadata( new QgsLayoutItemGuiMetadata( QgsLayoutItemRegistry::LayoutMap, QObject::tr( "Map" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddMap.svg" ) ),
54-
[ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
55+
auto mapItemMetadata = qgis::make_unique< QgsLayoutItemGuiMetadata >( QgsLayoutItemRegistry::LayoutMap, QObject::tr( "Map" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddMap.svg" ) ),
56+
[ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
5557
{
5658
return new QgsLayoutMapWidget( qobject_cast< QgsLayoutItemMap * >( item ) );
57-
}, createRubberBand ) );
59+
}, createRubberBand );
60+
mapItemMetadata->setItemAddedToLayoutFunction( [ = ]( QgsLayoutItem * item )
61+
{
62+
QgsLayoutItemMap *map = qobject_cast< QgsLayoutItemMap * >( item );
63+
Q_ASSERT( map );
64+
if ( QgisApp::instance()->mapCanvas() )
65+
{
66+
map->zoomToExtent( QgisApp::instance()->mapCanvas()->mapSettings().visibleExtent() );
67+
}
68+
} );
69+
registry->addLayoutItemGuiMetadata( mapItemMetadata.release() );
5870

5971
auto createShapeWidget =
6072
[]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *

0 commit comments

Comments
 (0)