QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
qgslayoutguiutils.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayoutapputils.cpp
3  ---------------------
4  Date : October 2017
5  Copyright : (C) 2017 Nyall Dawson
6  Email : nyall dot dawson at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgslayoutguiutils.h"
17 #include "qgsgui.h"
18 #include "qgslayout.h"
20 #include "qgslayoutitemregistry.h"
22 #include "qgslayoutitemshape.h"
23 #include "qgslayoutmapwidget.h"
24 #include "qgslayoutshapewidget.h"
25 #include "qgslayoutitemmap.h"
26 #include "qgslayoutitempolygon.h"
27 #include "qgslayoutitempolyline.h"
28 #include "qgslayoutpolygonwidget.h"
30 #include "qgslayoutpicturewidget.h"
31 #include "qgslayoutitempicture.h"
32 #include "qgslayoutitemlabel.h"
33 #include "qgslayoutlabelwidget.h"
34 #include "qgslayoutitemlegend.h"
35 #include "qgslayoutitemscalebar.h"
36 #include "qgslayoutlegendwidget.h"
37 #include "qgslayoutframe.h"
38 #include "qgslayoutitemhtml.h"
39 #include "qgslayouthtmlwidget.h"
45 #include "qgsmapcanvas.h"
46 
55 {
56  // start by trying to find a selected map
57  QList<QgsLayoutItemMap *> mapItems;
58  referenceItem->layout()->layoutItems( mapItems );
59 
60  QgsLayoutItemMap *targetMap = nullptr;
61  for ( QgsLayoutItemMap *map : qgis::as_const( mapItems ) )
62  {
63  if ( map->isSelected() )
64  {
65  return map;
66  }
67  }
68 
69  // nope, no selection... hm, was the item drawn over a map? If so, use the topmost intersecting one
70  double largestZValue = std::numeric_limits< double >::lowest();
71  for ( QgsLayoutItemMap *map : qgis::as_const( mapItems ) )
72  {
73  if ( map->collidesWithItem( referenceItem ) && map->zValue() > largestZValue )
74  {
75  targetMap = map;
76  largestZValue = map->zValue();
77  }
78  }
79  if ( targetMap )
80  return targetMap;
81 
82  // ah frick it, just use the reference (or biggest!) map
83  return referenceItem->layout()->referenceMap();
84 }
85 
87 {
89 
90  registry->addItemGroup( QgsLayoutItemGuiGroup( QStringLiteral( "shapes" ), QObject::tr( "Shape" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddBasicShape.svg" ) ) ) );
91  registry->addItemGroup( QgsLayoutItemGuiGroup( QStringLiteral( "nodes" ), QObject::tr( "Node Item" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddNodesItem.svg" ) ) ) );
92 
93  auto createRubberBand = ( []( QgsLayoutView * view )->QgsLayoutViewRubberBand *
94  {
95  return new QgsLayoutViewRectangularRubberBand( view );
96  } );
97  auto createEllipseBand = ( []( QgsLayoutView * view )->QgsLayoutViewRubberBand *
98  {
99  return new QgsLayoutViewEllipticalRubberBand( view );
100  } );
101  auto createTriangleBand = ( []( QgsLayoutView * view )->QgsLayoutViewRubberBand *
102  {
103  return new QgsLayoutViewTriangleRubberBand( view );
104  } );
105 
106 #if 0
107  registry->addLayoutItemGuiMetadata( new QgsLayoutItemGuiMetadata( QgsLayoutItemRegistry::LayoutItem + 1002, QStringLiteral( "test" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddLabel.svg" ) ), nullptr, createRubberBand ) );
108 #endif
109 
110  // map item
111 
112  auto mapItemMetadata = qgis::make_unique< QgsLayoutItemGuiMetadata >( QgsLayoutItemRegistry::LayoutMap, QObject::tr( "Map" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddMap.svg" ) ),
113  [ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
114  {
115  return new QgsLayoutMapWidget( qobject_cast< QgsLayoutItemMap * >( item ), mapCanvas );
116  }, createRubberBand );
117  mapItemMetadata->setItemAddedToLayoutFunction( [ = ]( QgsLayoutItem * item )
118  {
119  QgsLayoutItemMap *map = qobject_cast< QgsLayoutItemMap * >( item );
120  Q_ASSERT( map );
121 
122  //get the color for map canvas background and set map background color accordingly
123  map->setBackgroundColor( QgsProject::instance()->backgroundColor() );
124 
125  if ( mapCanvas )
126  {
127  map->zoomToExtent( mapCanvas->mapSettings().visibleExtent() );
128  }
129  } );
130  registry->addLayoutItemGuiMetadata( mapItemMetadata.release() );
131 
132  // picture item
133 
134  registry->addLayoutItemGuiMetadata( new QgsLayoutItemGuiMetadata( QgsLayoutItemRegistry::LayoutPicture, QObject::tr( "Picture" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddImage.svg" ) ),
135  [ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
136  {
137  return new QgsLayoutPictureWidget( qobject_cast< QgsLayoutItemPicture * >( item ) );
138  }, createRubberBand ) );
139 
140 
141  // label item
142 
143  auto labelItemMetadata = qgis::make_unique< QgsLayoutItemGuiMetadata >( QgsLayoutItemRegistry::LayoutLabel, QObject::tr( "Label" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionLabel.svg" ) ),
144  [ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
145  {
146  return new QgsLayoutLabelWidget( qobject_cast< QgsLayoutItemLabel * >( item ) );
147  }, createRubberBand );
148  labelItemMetadata->setItemAddedToLayoutFunction( [ = ]( QgsLayoutItem * item )
149  {
150  QgsLayoutItemLabel *label = qobject_cast< QgsLayoutItemLabel * >( item );
151  Q_ASSERT( label );
152 
153  label->setText( QObject::tr( "Lorem ipsum" ) );
154  if ( QApplication::isRightToLeft() )
155  {
156  label->setHAlign( Qt::AlignRight );
157  }
158  QSizeF minSize = label->sizeForText();
159  QSizeF currentSize = label->rect().size();
160 
161  //make sure label size is sufficient to fit text
162  double labelWidth = std::max( minSize.width(), currentSize.width() );
163  double labelHeight = std::max( minSize.height(), currentSize.height() );
164  label->attemptSetSceneRect( QRectF( label->pos().x(), label->pos().y(), labelWidth, labelHeight ) );
165  } );
166 
167  registry->addLayoutItemGuiMetadata( labelItemMetadata.release() );
168 
169 
170  // legend item
171 
172  auto legendItemMetadata = qgis::make_unique< QgsLayoutItemGuiMetadata >( QgsLayoutItemRegistry::LayoutLegend, QObject::tr( "Legend" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddLegend.svg" ) ),
173  [ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
174  {
175  return new QgsLayoutLegendWidget( qobject_cast< QgsLayoutItemLegend * >( item ), mapCanvas );
176  }, createRubberBand );
177  legendItemMetadata->setItemAddedToLayoutFunction( [ = ]( QgsLayoutItem * item )
178  {
179  QgsLayoutItemLegend *legend = qobject_cast< QgsLayoutItemLegend * >( item );
180  Q_ASSERT( legend );
181 
182  // try to find a good map to link the legend with by default
183  legend->setLinkedMap( findSensibleDefaultLinkedMapItem( legend ) );
184 
185  if ( QApplication::isRightToLeft() )
186  {
187  // for right-to-left locales, use an appropriate default layout
188  legend->setSymbolAlignment( Qt::AlignRight );
189  legend->rstyle( QgsLegendStyle::Group ).setAlignment( Qt::AlignRight );
190  legend->rstyle( QgsLegendStyle::Subgroup ).setAlignment( Qt::AlignRight );
191  legend->rstyle( QgsLegendStyle::SymbolLabel ).setAlignment( Qt::AlignRight );
192  legend->setTitleAlignment( Qt::AlignRight );
193  }
194 
195  //set default legend font from settings
196  QgsSettings settings;
197  const QString defaultFontString = settings.value( QStringLiteral( "LayoutDesigner/defaultFont" ), QVariant(), QgsSettings::Gui ).toString();
198  if ( !defaultFontString.isEmpty() )
199  {
200  legend->rstyle( QgsLegendStyle::Title ).rfont().setFamily( defaultFontString );
201  legend->rstyle( QgsLegendStyle::Group ).rfont().setFamily( defaultFontString );
202  legend->rstyle( QgsLegendStyle::Subgroup ).rfont().setFamily( defaultFontString );
203  legend->rstyle( QgsLegendStyle::SymbolLabel ).rfont().setFamily( defaultFontString );
204  }
205 
206  legend->updateLegend();
207  } );
208 
209  registry->addLayoutItemGuiMetadata( legendItemMetadata.release() );
210 
211  // scalebar item
212 
213  auto scalebarItemMetadata = qgis::make_unique< QgsLayoutItemGuiMetadata >( QgsLayoutItemRegistry::LayoutScaleBar, QObject::tr( "Scale Bar" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionScaleBar.svg" ) ),
214  [ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
215  {
216  return new QgsLayoutScaleBarWidget( qobject_cast< QgsLayoutItemScaleBar * >( item ) );
217  }, createRubberBand );
218  scalebarItemMetadata->setItemAddedToLayoutFunction( [ = ]( QgsLayoutItem * item )
219  {
220  QgsLayoutItemScaleBar *scalebar = qobject_cast< QgsLayoutItemScaleBar * >( item );
221  Q_ASSERT( scalebar );
222 
223  // try to find a good map to link the scalebar with by default
224  if ( QgsLayoutItemMap *targetMap = findSensibleDefaultLinkedMapItem( scalebar ) )
225  {
226  scalebar->setLinkedMap( targetMap );
227  scalebar->applyDefaultSize( scalebar->guessUnits() );
228  }
229  } );
230 
231  registry->addLayoutItemGuiMetadata( scalebarItemMetadata.release() );
232 
233 
234  // north arrow
235  std::unique_ptr< QgsLayoutItemGuiMetadata > northArrowMetadata = qgis::make_unique< QgsLayoutItemGuiMetadata>(
236  QgsLayoutItemRegistry::LayoutPicture, QObject::tr( "North Arrow" ), QgsApplication::getThemeIcon( QStringLiteral( "/north_arrow.svg" ) ),
237  [ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
238  {
239  return new QgsLayoutPictureWidget( qobject_cast< QgsLayoutItemPicture * >( item ) );
240  }, createRubberBand );
241  northArrowMetadata->setItemCreationFunction( []( QgsLayout * layout )->QgsLayoutItem *
242  {
243 
244  // count how many existing north arrows are already in layout
245  QList< QgsLayoutItemPicture * > pictureItems;
246  layout->layoutItems( pictureItems );
247  int northArrowCount = 0;
248 
249  QgsSettings settings;
250  const QString defaultPath = settings.value( QStringLiteral( "LayoutDesigner/defaultNorthArrow" ), QStringLiteral( ":/images/north_arrows/layout_default_north_arrow.svg" ), QgsSettings::Gui ).toString();
251 
252  for ( QgsLayoutItemPicture *p : qgis::as_const( pictureItems ) )
253  {
254  // look for pictures which use the default north arrow svg
255  if ( p->picturePath() == defaultPath )
256  northArrowCount++;
257  }
258 
259  std::unique_ptr< QgsLayoutItemPicture > picture = qgis::make_unique< QgsLayoutItemPicture >( layout );
260  picture->setNorthMode( QgsLayoutItemPicture::GridNorth );
261  picture->setPicturePath( defaultPath );
262  // set an id by default, so that north arrows are discernible in layout item lists
263  picture->setId( northArrowCount > 0 ? QObject::tr( "North Arrow %1" ).arg( northArrowCount + 1 ) : QObject::tr( "North Arrow" ) );
264  return picture.release();
265  } );
266  northArrowMetadata->setItemAddedToLayoutFunction( [ = ]( QgsLayoutItem * item )
267  {
268  QgsLayoutItemPicture *picture = qobject_cast< QgsLayoutItemPicture * >( item );
269  Q_ASSERT( picture );
270 
271  QList<QgsLayoutItemMap *> mapItems;
272  picture->layout()->layoutItems( mapItems );
273 
274  // try to find a good map to link the north arrow with by default
275  picture->setLinkedMap( findSensibleDefaultLinkedMapItem( picture ) );
276  } );
277  registry->addLayoutItemGuiMetadata( northArrowMetadata.release() );
278 
279  // shape items
280 
281  auto createShapeWidget =
282  []( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
283  {
284  return new QgsLayoutShapeWidget( qobject_cast< QgsLayoutItemShape * >( item ) );
285  };
286 
287  registry->addLayoutItemGuiMetadata( new QgsLayoutItemGuiMetadata( QgsLayoutItemRegistry::LayoutShape, QObject::tr( "Rectangle" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddBasicRectangle.svg" ) ), createShapeWidget, createRubberBand, QStringLiteral( "shapes" ), false, nullptr, []( QgsLayout * layout )->QgsLayoutItem*
288  {
289  std::unique_ptr< QgsLayoutItemShape > shape = qgis::make_unique< QgsLayoutItemShape >( layout );
290  shape->setShapeType( QgsLayoutItemShape::Rectangle );
291  return shape.release();
292  } ) );
293  registry->addLayoutItemGuiMetadata( new QgsLayoutItemGuiMetadata( QgsLayoutItemRegistry::LayoutShape, QObject::tr( "Ellipse" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddBasicCircle.svg" ) ), createShapeWidget, createEllipseBand, QStringLiteral( "shapes" ), false, nullptr, []( QgsLayout * layout )->QgsLayoutItem*
294  {
295  std::unique_ptr< QgsLayoutItemShape > shape = qgis::make_unique< QgsLayoutItemShape >( layout );
296  shape->setShapeType( QgsLayoutItemShape::Ellipse );
297  return shape.release();
298  } ) );
299  registry->addLayoutItemGuiMetadata( new QgsLayoutItemGuiMetadata( QgsLayoutItemRegistry::LayoutShape, QObject::tr( "Triangle" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddBasicTriangle.svg" ) ), createShapeWidget, createTriangleBand, QStringLiteral( "shapes" ), false, nullptr, []( QgsLayout * layout )->QgsLayoutItem*
300  {
301  std::unique_ptr< QgsLayoutItemShape > shape = qgis::make_unique< QgsLayoutItemShape >( layout );
302  shape->setShapeType( QgsLayoutItemShape::Triangle );
303  return shape.release();
304  } ) );
305 
306  // arrow
307  std::unique_ptr< QgsLayoutItemGuiMetadata > arrowMetadata = qgis::make_unique< QgsLayoutItemGuiMetadata>(
308  QgsLayoutItemRegistry::LayoutPolyline, QObject::tr( "Arrow" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddArrow.svg" ) ),
309  [ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
310  {
311  return new QgsLayoutPolylineWidget( qobject_cast< QgsLayoutItemPolyline * >( item ) );
312  }, createRubberBand, QString(), true );
313  arrowMetadata->setItemCreationFunction( []( QgsLayout * layout )->QgsLayoutItem *
314  {
315  std::unique_ptr< QgsLayoutItemPolyline > arrow = qgis::make_unique< QgsLayoutItemPolyline >( layout );
316  arrow->setEndMarker( QgsLayoutItemPolyline::ArrowHead );
317  return arrow.release();
318  } );
319  arrowMetadata->setNodeRubberBandCreationFunction( []( QgsLayoutView * )->QGraphicsPathItem*
320  {
321  std::unique_ptr< QGraphicsPathItem > band = qgis::make_unique< QGraphicsPathItem >();
322  band->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
323  band->setZValue( QgsLayout::ZViewTool );
324  return band.release();
325  } );
326  registry->addLayoutItemGuiMetadata( arrowMetadata.release() );
327 
328  // node items
329 
330  std::unique_ptr< QgsLayoutItemGuiMetadata > polygonMetadata = qgis::make_unique< QgsLayoutItemGuiMetadata >(
331  QgsLayoutItemRegistry::LayoutPolygon, QObject::tr( "Polygon" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddPolygon.svg" ) ),
332  [ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
333  {
334  return new QgsLayoutPolygonWidget( qobject_cast< QgsLayoutItemPolygon * >( item ) );
335  }, createRubberBand, QStringLiteral( "nodes" ), true );
336  polygonMetadata->setNodeRubberBandCreationFunction( []( QgsLayoutView * )->QGraphicsPolygonItem*
337  {
338  std::unique_ptr< QGraphicsPolygonItem > band = qgis::make_unique< QGraphicsPolygonItem >();
339  band->setBrush( Qt::NoBrush );
340  band->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
341  band->setZValue( QgsLayout::ZViewTool );
342  return band.release();
343  } );
344  registry->addLayoutItemGuiMetadata( polygonMetadata.release() );
345 
346  std::unique_ptr< QgsLayoutItemGuiMetadata > polylineMetadata = qgis::make_unique< QgsLayoutItemGuiMetadata>(
347  QgsLayoutItemRegistry::LayoutPolyline, QObject::tr( "Polyline" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddPolyline.svg" ) ),
348  [ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
349  {
350  return new QgsLayoutPolylineWidget( qobject_cast< QgsLayoutItemPolyline * >( item ) );
351  }, createRubberBand, QStringLiteral( "nodes" ), true );
352  polylineMetadata->setNodeRubberBandCreationFunction( []( QgsLayoutView * )->QGraphicsPathItem*
353  {
354  std::unique_ptr< QGraphicsPathItem > band = qgis::make_unique< QGraphicsPathItem >();
355  band->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
356  band->setZValue( QgsLayout::ZViewTool );
357  return band.release();
358  } );
359  registry->addLayoutItemGuiMetadata( polylineMetadata.release() );
360 
361 
362  // html item
363 
364  auto htmlItemMetadata = qgis::make_unique< QgsLayoutItemGuiMetadata >( QgsLayoutItemRegistry::LayoutHtml, QObject::tr( "HTML" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddHtml.svg" ) ),
365  [ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
366  {
367  return new QgsLayoutHtmlWidget( qobject_cast< QgsLayoutFrame * >( item ) );
368  }, createRubberBand );
369  htmlItemMetadata->setItemCreationFunction( [ = ]( QgsLayout * layout )->QgsLayoutItem *
370  {
371  std::unique_ptr< QgsLayoutItemHtml > htmlMultiFrame = qgis::make_unique< QgsLayoutItemHtml >( layout );
372  QgsLayoutItemHtml *html = htmlMultiFrame.get();
373  layout->addMultiFrame( htmlMultiFrame.release() );
374  std::unique_ptr< QgsLayoutFrame > frame = qgis::make_unique< QgsLayoutFrame >( layout, html );
375  QgsLayoutFrame *f = frame.get();
376  html->addFrame( frame.release() );
377  return f;
378  } );
379  registry->addLayoutItemGuiMetadata( htmlItemMetadata.release() );
380 
381  // attribute table item
382 
383  auto attributeTableItemMetadata = qgis::make_unique< QgsLayoutItemGuiMetadata >( QgsLayoutItemRegistry::LayoutAttributeTable, QObject::tr( "Attribute Table" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddTable.svg" ) ),
384  [ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
385  {
386  return new QgsLayoutAttributeTableWidget( qobject_cast< QgsLayoutFrame * >( item ) );
387  }, createRubberBand );
388  attributeTableItemMetadata->setItemCreationFunction( [ = ]( QgsLayout * layout )->QgsLayoutItem *
389  {
390  std::unique_ptr< QgsLayoutItemAttributeTable > tableMultiFrame = qgis::make_unique< QgsLayoutItemAttributeTable >( layout );
391  QgsLayoutItemAttributeTable *table = tableMultiFrame.get();
392 
393  //set first vector layer from layer registry as table source
394  QMap<QString, QgsMapLayer *> layerMap = layout->project()->mapLayers();
395  for ( auto it = layerMap.constBegin() ; it != layerMap.constEnd(); ++it )
396  {
397  if ( QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( it.value() ) )
398  {
399  table->setVectorLayer( vl );
400  break;
401  }
402  }
403 
404  layout->addMultiFrame( tableMultiFrame.release() );
405  std::unique_ptr< QgsLayoutFrame > frame = qgis::make_unique< QgsLayoutFrame >( layout, table );
406  QgsLayoutFrame *f = frame.get();
407  table->addFrame( frame.release() );
408  return f;
409  } );
410  registry->addLayoutItemGuiMetadata( attributeTableItemMetadata.release() );
411 
412  // manual table item
413 
414  auto manualTableItemMetadata = qgis::make_unique< QgsLayoutItemGuiMetadata >( QgsLayoutItemRegistry::LayoutManualTable, QObject::tr( "Fixed Table" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddManualTable.svg" ) ),
415  [ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
416  {
417  return new QgsLayoutManualTableWidget( qobject_cast< QgsLayoutFrame * >( item ) );
418  }, createRubberBand );
419  manualTableItemMetadata->setItemCreationFunction( [ = ]( QgsLayout * layout )->QgsLayoutItem *
420  {
421  std::unique_ptr< QgsLayoutItemManualTable > tableMultiFrame = qgis::make_unique< QgsLayoutItemManualTable >( layout );
422  QgsLayoutItemManualTable *table = tableMultiFrame.get();
423 
424  // initially start with a 2x2 empty table
425  QgsTableContents contents;
426  contents << ( QgsTableRow() << QgsTableCell() << QgsTableCell() );
427  contents << ( QgsTableRow() << QgsTableCell() << QgsTableCell() );
428  table->setTableContents( contents );
429 
430  layout->addMultiFrame( tableMultiFrame.release() );
431 
432  std::unique_ptr< QgsLayoutFrame > frame = qgis::make_unique< QgsLayoutFrame >( layout, table );
433  QgsLayoutFrame *f = frame.get();
434  table->addFrame( frame.release() );
435  return f;
436  } );
437  registry->addLayoutItemGuiMetadata( manualTableItemMetadata.release() );
438 }
QgsUnitTypes::DistanceUnit guessUnits() const
Attempts to guess the most reasonable unit choice for the scalebar, given the current linked map&#39;s sc...
Stores GUI metadata about a group of layout item classes.
QgsLayoutItemMap * findSensibleDefaultLinkedMapItem(QgsLayoutItem *referenceItem)
Attempts to find the best guess at a map item to link referenceItem to, by:
Base class for graphical items within a QgsLayout.
A graphical widget to display and interact with QgsLayouts.
Definition: qgslayoutview.h:49
QgsLayoutViewEllipseRubberBand is elliptical rubber band for use within QgsLayoutView widgets...
This class is a composition of two QSettings instances:
Definition: qgssettings.h:58
Convenience metadata class that uses static functions to handle layout item GUI behavior.
void setTableContents(const QgsTableContents &contents)
Sets the contents of the table.
A layout item subclass for text labels.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
Input widget for the configuration of QgsLayoutItemMap.
Encapsulates the contents and formatting of a single table cell.
Definition: qgstablecell.h:34
void setLinkedMap(QgsLayoutItemMap *map)
Sets the map item linked to the scalebar.
QgsLayoutViewTriangleRubberBand is triangular rubber band for use within QgsLayoutView widgets...
A layout item subclass that displays SVG files or raster format images (jpg, png, ...
void setAlignment(Qt::Alignment alignment)
Sets the alignment for the legend component.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
Z-value for temporary view tool items.
Definition: qgslayout.h:64
Registry of available layout item GUI behavior.
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes takes output image size into accou...
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:75
void layoutItems(QList< T *> &itemList) const
Returns a list of layout items of a specific type.
Definition: qgslayout.h:121
A widget for configuring layout manual table items.
A widget for setting properties relating to a layout legend.
Layout graphical items for displaying a map.
const QgsLayout * layout() const
Returns the layout the object is attached to.
static QgsLayoutItemGuiRegistry * layoutItemGuiRegistry()
Returns the global layout item GUI registry, used for registering the GUI behavior of layout items...
Definition: qgsgui.cpp:98
void setHAlign(Qt::AlignmentFlag alignment)
Sets the horizontal alignment of the label.
static void registerGuiForKnownItemTypes(QgsMapCanvas *mapCanvas)
Registers the GUI handlers for known layout item types.
A widget for configuring layout html items.
A widget for configuring layout attribute table items.
void attemptSetSceneRect(const QRectF &rect, bool includesFrame=false)
Attempts to update the item&#39;s position and size to match the passed rect in layout coordinates...
QgsLegendStyle & rstyle(QgsLegendStyle::Style s)
Returns reference to modifiable legend style.
A widget for configuring layout picture items.
void setLinkedMap(QgsLayoutItemMap *map)
Sets the map object for rotation.
A layout table subclass that displays attributes from a vector layer.
Legend subgroup title.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49
QMap< QString, QgsMapLayer * > mapLayers(const bool validOnly=false) const
Returns a map of all registered layers by layer ID.
void updateLegend()
Updates the model and all legend entries.
bool addItemGroup(const QgsLayoutItemGuiGroup &group)
Registers a new item group with the registry.
A widget for layout item settings.
QSizeF sizeForText() const
Returns the required item size (in layout units) for the label&#39;s text to fill the item...
QgsLayoutViewRectangularRubberBand is rectangular rubber band for use within QgsLayoutView widgets...
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
QVector< QgsTableRow > QgsTableContents
A set of table rows.
Definition: qgstablecell.h:158
QgsLayoutItemMap * referenceMap() const
Returns the map item which will be used to generate corresponding world files when the layout is expo...
Definition: qgslayout.cpp:429
A widget to define the properties of a QgsLayoutItemScaleBar.
void setLinkedMap(QgsLayoutItemMap *map)
Sets the map to associate with the legend.
A base class for property widgets for layout items.
QgsLayoutViewRubberBand is an abstract base class for temporary rubber band items in various shapes...
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:450
Input widget for QgsLayoutItemPolyline.
QgsProject * project() const
The project associated with the layout.
Definition: qgslayout.cpp:131
QFont & rfont()
Returns a modifiable reference to the component&#39;s font.
A layout item subclass for scale bars.
bool addLayoutItemGuiMetadata(QgsLayoutItemAbstractGuiMetadata *metadata)
Registers the gui metadata for a new layout item type.
A layout table subclass that displays manually entered (and formatted) content.
Input widget for QgsLayoutItemPolygon.
void zoomToExtent(const QgsRectangle &extent)
Zooms the map so that the specified extent is fully visible within the map item.
A layout item subclass for map legends.
Symbol label (excluding icon)
Represents a vector layer which manages a vector based data sets.
Base class for frame items, which form a layout multiframe item.
A layout multiframe subclass for HTML content.
void setTitleAlignment(Qt::AlignmentFlag alignment)
Sets the alignment of the legend title.
void addMultiFrame(QgsLayoutMultiFrame *multiFrame)
Adds a multiFrame to the layout.
Definition: qgslayout.cpp:571
void setSymbolAlignment(Qt::AlignmentFlag alignment)
Sets the alignment for placement of legend symbols.
void setText(const QString &text)
Sets the label&#39;s preset text.
void applyDefaultSize(QgsUnitTypes::DistanceUnit units=QgsUnitTypes::DistanceMeters)
Applies the default size to the scale bar (scale bar 1/5 of map item width)
QVector< QgsTableCell > QgsTableRow
A row of table cells.
Definition: qgstablecell.h:149
A widget for configuring layout shape items.
Legend group title.
void setBackgroundColor(const QColor &color)
Sets the background color for this item.