QGIS API Documentation  3.20.0-Odense (decaadbb31)
qgslayoutlabelwidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayoutlabelwidget.cpp
3  ------------------------
4  begin : October 2017
5  copyright : (C) 2017 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "qgslayoutlabelwidget.h"
19 #include "qgslayoutitemlabel.h"
20 #include "qgslayout.h"
22 #include "qgsguiutils.h"
23 #include "qgslayoutitemmap.h"
24 #include "qgsvectorlayer.h"
25 #include "qgsprojoperation.h"
26 
27 #include <QColorDialog>
28 #include <QFontDialog>
29 #include <QWidget>
30 #include <QAction>
31 #include <QMenu>
32 
34  : QgsLayoutItemBaseWidget( nullptr, label )
35  , mLabel( label )
36 {
37  Q_ASSERT( mLabel );
38 
39  setupUi( this );
40  connect( mHtmlCheckBox, &QCheckBox::stateChanged, this, &QgsLayoutLabelWidget::mHtmlCheckBox_stateChanged );
41  connect( mTextEdit, &QPlainTextEdit::textChanged, this, &QgsLayoutLabelWidget::mTextEdit_textChanged );
42  connect( mInsertExpressionButton, &QPushButton::clicked, this, &QgsLayoutLabelWidget::mInsertExpressionButton_clicked );
43  connect( mMarginXDoubleSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutLabelWidget::mMarginXDoubleSpinBox_valueChanged );
44  connect( mMarginYDoubleSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutLabelWidget::mMarginYDoubleSpinBox_valueChanged );
45  connect( mFontColorButton, &QgsColorButton::colorChanged, this, &QgsLayoutLabelWidget::mFontColorButton_colorChanged );
46  connect( mCenterRadioButton, &QRadioButton::clicked, this, &QgsLayoutLabelWidget::mCenterRadioButton_clicked );
47  connect( mLeftRadioButton, &QRadioButton::clicked, this, &QgsLayoutLabelWidget::mLeftRadioButton_clicked );
48  connect( mRightRadioButton, &QRadioButton::clicked, this, &QgsLayoutLabelWidget::mRightRadioButton_clicked );
49  connect( mTopRadioButton, &QRadioButton::clicked, this, &QgsLayoutLabelWidget::mTopRadioButton_clicked );
50  connect( mBottomRadioButton, &QRadioButton::clicked, this, &QgsLayoutLabelWidget::mBottomRadioButton_clicked );
51  connect( mMiddleRadioButton, &QRadioButton::clicked, this, &QgsLayoutLabelWidget::mMiddleRadioButton_clicked );
52  setPanelTitle( tr( "Label Properties" ) );
53 
54  mFontButton->setMode( QgsFontButton::ModeQFont );
55 
56  //add widget for general composer item properties
57  mItemPropertiesWidget = new QgsLayoutItemPropertiesWidget( this, label );
58  mainLayout->addWidget( mItemPropertiesWidget );
59 
60  mFontColorButton->setColorDialogTitle( tr( "Select Font Color" ) );
61  mFontColorButton->setContext( QStringLiteral( "composer" ) );
62  mFontColorButton->setAllowOpacity( true );
63 
64  mMarginXDoubleSpinBox->setClearValue( 0.0 );
65  mMarginYDoubleSpinBox->setClearValue( 0.0 );
66 
67  setGuiElementValues();
68  connect( mLabel, &QgsLayoutObject::changed, this, &QgsLayoutLabelWidget::setGuiElementValues );
69 
70  connect( mFontButton, &QgsFontButton::changed, this, &QgsLayoutLabelWidget::fontChanged );
71  connect( mJustifyRadioButton, &QRadioButton::clicked, this, &QgsLayoutLabelWidget::justifyClicked );
72 
73  mDynamicTextMenu = new QMenu( this );
74  mDynamicTextButton->setMenu( mDynamicTextMenu );
75 
76  connect( mDynamicTextMenu, &QMenu::aboutToShow, this, [ = ]
77  {
78  mDynamicTextMenu->clear();
79  if ( mLabel->layout() )
80  {
81  // we need to rebuild this on each show, as the content varies depending on other available items...
82  buildInsertDynamicTextMenu( mLabel->layout(), mDynamicTextMenu, [ = ]( const QString & expression )
83  {
84  mLabel->beginCommand( tr( "Insert dynamic text" ) );
85  mTextEdit->insertPlainText( "[%" + expression + "%]" );
86  mLabel->endCommand();
87  } );
88  }
89  } );
90 
91  QMenu *expressionMenu = new QMenu( this );
92  QAction *convertToStaticAction = new QAction( tr( "Convert to Static Text" ), this );
93  expressionMenu->addAction( convertToStaticAction );
94  connect( convertToStaticAction, &QAction::triggered, mLabel, &QgsLayoutItemLabel::convertToStaticText );
95  mInsertExpressionButton->setMenu( expressionMenu );
96 }
97 
99 {
100  if ( mItemPropertiesWidget )
101  mItemPropertiesWidget->setMasterLayout( masterLayout );
102 }
103 
104 void QgsLayoutLabelWidget::buildInsertDynamicTextMenu( QgsLayout *layout, QMenu *menu, const std::function<void ( const QString & )> &callback )
105 {
106  Q_ASSERT( layout );
107  auto addExpression = [&callback]( QMenu * menu, const QString & name, const QString & expression )
108  {
109  QAction *action = new QAction( name, menu );
110  connect( action, &QAction::triggered, action, [callback, expression]
111  {
112  callback( expression );
113  } );
114  menu->addAction( action );
115  };
116 
117  QMenu *dateMenu = new QMenu( tr( "Current Date" ), menu );
118  for ( const std::pair< QString, QString > &expression :
119  {
120  std::make_pair( tr( "ISO Format (%1)" ).arg( QDateTime::currentDateTime().toString( QStringLiteral( "yyyy-MM-dd" ) ) ), QStringLiteral( "format_date(now(), 'yyyy-MM-dd')" ) ),
121  std::make_pair( tr( "Day/Month/Year (%1)" ).arg( QDateTime::currentDateTime().toString( QStringLiteral( "dd/MM/yyyy" ) ) ), QStringLiteral( "format_date(now(), 'dd/MM/yyyy')" ) ),
122  std::make_pair( tr( "Month/Day/Year (%1)" ).arg( QDateTime::currentDateTime().toString( QStringLiteral( "MM/dd/yyyy" ) ) ), QStringLiteral( "format_date(now(), 'MM/dd/yyyy')" ) ),
123  } )
124  {
125  addExpression( dateMenu, expression.first, expression.second );
126  }
127  menu->addMenu( dateMenu );
128 
129  QMenu *mapsMenu = new QMenu( tr( "Map Properties" ), menu );
130  QList< QgsLayoutItemMap * > maps;
131  layout->layoutItems( maps );
132  for ( QgsLayoutItemMap *map : std::as_const( maps ) )
133  {
134  // these expressions require the map to have a non-empty ID set
135  if ( map->id().isEmpty() )
136  continue;
137 
138  QMenu *mapMenu = new QMenu( map->displayName(), mapsMenu );
139  for ( const std::pair< QString, QString > &expression :
140  {
141  std::make_pair( tr( "Scale (%1)" ).arg( map->scale() ), QStringLiteral( "item_variables('%1')['map_scale']" ).arg( map->id() ) ),
142  std::make_pair( tr( "Rotation (%1)" ).arg( map->rotation() ), QStringLiteral( "item_variables('%1')['map_rotation']" ).arg( map->id() ) ),
143  } )
144  {
145  addExpression( mapMenu, expression.first, expression.second );
146  }
147  mapMenu->addSeparator();
148  for ( const std::pair< QString, QString > &expression :
149  {
150  std::make_pair( tr( "CRS Identifier (%1)" ).arg( map->crs().authid() ), QStringLiteral( "item_variables('%1')['map_crs']" ).arg( map->id() ) ),
151  std::make_pair( tr( "CRS Name (%1)" ).arg( map->crs().description() ), QStringLiteral( "item_variables('%1')['map_crs_description']" ).arg( map->id() ) ),
152  std::make_pair( tr( "Ellipsoid Name (%1)" ).arg( map->crs().ellipsoidAcronym() ), QStringLiteral( "item_variables('%1')['map_crs_ellipsoid']" ).arg( map->id() ) ),
153  std::make_pair( tr( "Units (%1)" ).arg( QgsUnitTypes::toString( map->crs().mapUnits() ) ), QStringLiteral( "item_variables('%1')['map_units']" ).arg( map->id() ) ),
154  std::make_pair( tr( "Projection (%1)" ).arg( map->crs().operation().description() ), QStringLiteral( "item_variables('%1')['map_crs_projection']" ).arg( map->id() ) ),
155  } )
156  {
157  addExpression( mapMenu, expression.first, expression.second );
158  }
159  mapMenu->addSeparator();
160 
161  const QgsRectangle mapExtent = map->extent();
162  const QgsPointXY center = mapExtent.center();
163  for ( const std::pair< QString, QString > &expression :
164  {
165  std::make_pair( tr( "Center (X) (%1)" ).arg( center.x() ), QStringLiteral( "x(item_variables('%1')['map_extent_center'])" ).arg( map->id() ) ),
166  std::make_pair( tr( "Center (Y) (%1)" ).arg( center.y() ), QStringLiteral( "y(item_variables('%1')['map_extent_center'])" ).arg( map->id() ) ),
167  std::make_pair( tr( "X Minimum (%1)" ).arg( mapExtent.xMinimum() ), QStringLiteral( "x_min(item_variables('%1')['map_extent'])" ).arg( map->id() ) ),
168  std::make_pair( tr( "Y Minimum (%1)" ).arg( mapExtent.yMinimum() ), QStringLiteral( "y_min(item_variables('%1')['map_extent'])" ).arg( map->id() ) ),
169  std::make_pair( tr( "X Maximum (%1)" ).arg( mapExtent.xMaximum() ), QStringLiteral( "x_max(item_variables('%1')['map_extent'])" ).arg( map->id() ) ),
170  std::make_pair( tr( "Y Maximum (%1)" ).arg( mapExtent.yMaximum() ), QStringLiteral( "y_max(item_variables('%1')['map_extent'])" ).arg( map->id() ) ),
171  } )
172  {
173  addExpression( mapMenu, expression.first, expression.second );
174  }
175  mapMenu->addSeparator();
176  for ( const std::pair< QString, QString > &expression :
177  {
178  std::make_pair( tr( "Layer Credits" ), QStringLiteral( "array_to_string(map_credits('%1'))" ).arg( map->id() ) ),
179  } )
180  {
181  addExpression( mapMenu, expression.first, expression.second );
182  }
183  mapsMenu->addMenu( mapMenu );
184  }
185  menu->addMenu( mapsMenu );
186  menu->addSeparator();
187 
188  if ( layout->reportContext().layer() )
189  {
190  const QgsFields fields = layout->reportContext().layer()->fields();
191 
192  QMenu *fieldsMenu = new QMenu( tr( "Field" ), menu );
193  for ( const QgsField &field : fields )
194  {
195  addExpression( fieldsMenu, field.displayName(), QStringLiteral( "\"%1\"" ).arg( field.name() ) );
196  }
197 
198  menu->addMenu( fieldsMenu );
199  menu->addSeparator();
200  }
201 
202  for ( const std::pair< QString, QString > &expression :
203  {
204  std::make_pair( tr( "Layout Name" ), QStringLiteral( "@layout_name" ) ),
205  std::make_pair( tr( "Layout Page Number" ), QStringLiteral( "@layout_page" ) ),
206  std::make_pair( tr( "Layout Page Count" ), QStringLiteral( "@layout_numpages" ) )
207  } )
208  {
209  addExpression( menu, expression.first, expression.second );
210  }
211  menu->addSeparator();
212  for ( const std::pair< QString, QString > &expression :
213  {
214  std::make_pair( tr( "Project Author" ), QStringLiteral( "@project_author" ) ),
215  std::make_pair( tr( "Project Title" ), QStringLiteral( "@project_title" ) ),
216  std::make_pair( tr( "Project Path" ), QStringLiteral( "@project_path" ) )
217  } )
218  {
219  addExpression( menu, expression.first, expression.second );
220  }
221  menu->addSeparator();
222  for ( const std::pair< QString, QString > &expression :
223  {
224  std::make_pair( tr( "Current User Name" ), QStringLiteral( "@user_full_name" ) ),
225  std::make_pair( tr( "Current User Account" ), QStringLiteral( "@user_account_name" ) )
226  } )
227  {
228  addExpression( menu, expression.first, expression.second );
229  }
230 }
231 
233 {
234  if ( item->type() != QgsLayoutItemRegistry::LayoutLabel )
235  return false;
236 
237  if ( mLabel )
238  {
239  disconnect( mLabel, &QgsLayoutObject::changed, this, &QgsLayoutLabelWidget::setGuiElementValues );
240  }
241 
242  mLabel = qobject_cast< QgsLayoutItemLabel * >( item );
243  mItemPropertiesWidget->setItem( mLabel );
244 
245  if ( mLabel )
246  {
247  connect( mLabel, &QgsLayoutObject::changed, this, &QgsLayoutLabelWidget::setGuiElementValues );
248  }
249 
250  setGuiElementValues();
251 
252  return true;
253 }
254 
255 void QgsLayoutLabelWidget::mHtmlCheckBox_stateChanged( int state )
256 {
257  if ( mLabel )
258  {
259  mVerticalAlignementLabel->setDisabled( state );
260  mTopRadioButton->setDisabled( state );
261  mMiddleRadioButton->setDisabled( state );
262  mBottomRadioButton->setDisabled( state );
263 
264  mLabel->beginCommand( tr( "Change Label Mode" ) );
265  mLabel->blockSignals( true );
266  mLabel->setMode( state ? QgsLayoutItemLabel::ModeHtml : QgsLayoutItemLabel::ModeFont );
267  mLabel->setText( mTextEdit->toPlainText() );
268  mLabel->update();
269  mLabel->blockSignals( false );
270  mLabel->endCommand();
271  }
272 }
273 
274 void QgsLayoutLabelWidget::mTextEdit_textChanged()
275 {
276  if ( mLabel )
277  {
278  mLabel->beginCommand( tr( "Change Label Text" ), QgsLayoutItem::UndoLabelText );
279  mLabel->blockSignals( true );
280  mLabel->setText( mTextEdit->toPlainText() );
281  mLabel->update();
282  mLabel->blockSignals( false );
283  mLabel->endCommand();
284  }
285 }
286 
287 void QgsLayoutLabelWidget::fontChanged()
288 {
289  if ( mLabel )
290  {
291  QFont newFont = mFontButton->currentFont();
292  mLabel->beginCommand( tr( "Change Label Font" ), QgsLayoutItem::UndoLabelFont );
293  mLabel->setFont( newFont );
294  mLabel->update();
295  mLabel->endCommand();
296  }
297 }
298 
299 void QgsLayoutLabelWidget::justifyClicked()
300 {
301  if ( mLabel )
302  {
303  mLabel->beginCommand( tr( "Change Label Alignment" ) );
304  mLabel->setHAlign( Qt::AlignJustify );
305  mLabel->update();
306  mLabel->endCommand();
307  }
308 }
309 
310 void QgsLayoutLabelWidget::mMarginXDoubleSpinBox_valueChanged( double d )
311 {
312  if ( mLabel )
313  {
314  mLabel->beginCommand( tr( "Change Label Margin" ), QgsLayoutItem::UndoLabelMargin );
315  mLabel->setMarginX( d );
316  mLabel->update();
317  mLabel->endCommand();
318  }
319 }
320 
321 void QgsLayoutLabelWidget::mMarginYDoubleSpinBox_valueChanged( double d )
322 {
323  if ( mLabel )
324  {
325  mLabel->beginCommand( tr( "Change Label Margin" ), QgsLayoutItem::UndoLabelMargin );
326  mLabel->setMarginY( d );
327  mLabel->update();
328  mLabel->endCommand();
329  }
330 }
331 
332 void QgsLayoutLabelWidget::mFontColorButton_colorChanged( const QColor &newLabelColor )
333 {
334  if ( !mLabel )
335  {
336  return;
337  }
338 
339  mLabel->beginCommand( tr( "Change Label Color" ), QgsLayoutItem::UndoLabelFontColor );
340  mLabel->setFontColor( newLabelColor );
341  mLabel->update();
342  mLabel->endCommand();
343 }
344 
345 void QgsLayoutLabelWidget::mInsertExpressionButton_clicked()
346 {
347  if ( !mLabel )
348  {
349  return;
350  }
351 
352  QString selText = mTextEdit->textCursor().selectedText();
353 
354  // html editor replaces newlines with Paragraph Separator characters - see https://github.com/qgis/QGIS/issues/27568
355  selText = selText.replace( QChar( 0x2029 ), QChar( '\n' ) );
356 
357  // edit the selected expression if there's one
358  if ( selText.startsWith( QLatin1String( "[%" ) ) && selText.endsWith( QLatin1String( "%]" ) ) )
359  selText = selText.mid( 2, selText.size() - 4 );
360 
361  // use the atlas coverage layer, if any
362  QgsVectorLayer *layer = coverageLayer();
363 
364  QgsExpressionContext context = mLabel->createExpressionContext();
365  QgsExpressionBuilderDialog exprDlg( layer, selText, this, QStringLiteral( "generic" ), context );
366 
367  exprDlg.setWindowTitle( tr( "Insert Expression" ) );
368  if ( exprDlg.exec() == QDialog::Accepted )
369  {
370  QString expression = exprDlg.expressionText();
371  if ( !expression.isEmpty() )
372  {
373  mLabel->beginCommand( tr( "Insert expression" ) );
374  mTextEdit->insertPlainText( "[%" + expression + "%]" );
375  mLabel->endCommand();
376  }
377  }
378 }
379 
380 void QgsLayoutLabelWidget::mCenterRadioButton_clicked()
381 {
382  if ( mLabel )
383  {
384  mLabel->beginCommand( tr( "Change Label Alignment" ) );
385  mLabel->setHAlign( Qt::AlignHCenter );
386  mLabel->update();
387  mLabel->endCommand();
388  }
389 }
390 
391 void QgsLayoutLabelWidget::mRightRadioButton_clicked()
392 {
393  if ( mLabel )
394  {
395  mLabel->beginCommand( tr( "Change Label Alignment" ) );
396  mLabel->setHAlign( Qt::AlignRight );
397  mLabel->update();
398  mLabel->endCommand();
399  }
400 }
401 
402 void QgsLayoutLabelWidget::mLeftRadioButton_clicked()
403 {
404  if ( mLabel )
405  {
406  mLabel->beginCommand( tr( "Change Label Alignment" ) );
407  mLabel->setHAlign( Qt::AlignLeft );
408  mLabel->update();
409  mLabel->endCommand();
410  }
411 }
412 
413 void QgsLayoutLabelWidget::mTopRadioButton_clicked()
414 {
415  if ( mLabel )
416  {
417  mLabel->beginCommand( tr( "Change Label Alignment" ) );
418  mLabel->setVAlign( Qt::AlignTop );
419  mLabel->update();
420  mLabel->endCommand();
421  }
422 }
423 
424 void QgsLayoutLabelWidget::mBottomRadioButton_clicked()
425 {
426  if ( mLabel )
427  {
428  mLabel->beginCommand( tr( "Change Label Alignment" ) );
429  mLabel->setVAlign( Qt::AlignBottom );
430  mLabel->update();
431  mLabel->endCommand();
432  }
433 }
434 
435 void QgsLayoutLabelWidget::mMiddleRadioButton_clicked()
436 {
437  if ( mLabel )
438  {
439  mLabel->beginCommand( tr( "Change Label Alignment" ) );
440  mLabel->setVAlign( Qt::AlignVCenter );
441  mLabel->update();
442  mLabel->endCommand();
443  }
444 }
445 
446 void QgsLayoutLabelWidget::setGuiElementValues()
447 {
448  blockAllSignals( true );
449  mTextEdit->setPlainText( mLabel->text() );
450  mTextEdit->moveCursor( QTextCursor::End, QTextCursor::MoveAnchor );
451  mMarginXDoubleSpinBox->setValue( mLabel->marginX() );
452  mMarginYDoubleSpinBox->setValue( mLabel->marginY() );
453  mHtmlCheckBox->setChecked( mLabel->mode() == QgsLayoutItemLabel::ModeHtml );
454  mTopRadioButton->setChecked( mLabel->vAlign() == Qt::AlignTop );
455  mMiddleRadioButton->setChecked( mLabel->vAlign() == Qt::AlignVCenter );
456  mBottomRadioButton->setChecked( mLabel->vAlign() == Qt::AlignBottom );
457  mLeftRadioButton->setChecked( mLabel->hAlign() == Qt::AlignLeft );
458  mJustifyRadioButton->setChecked( mLabel->hAlign() == Qt::AlignJustify );
459  mCenterRadioButton->setChecked( mLabel->hAlign() == Qt::AlignHCenter );
460  mRightRadioButton->setChecked( mLabel->hAlign() == Qt::AlignRight );
461  mFontColorButton->setColor( mLabel->fontColor() );
462  mFontButton->setCurrentFont( mLabel->font() );
463  mVerticalAlignementLabel->setDisabled( mLabel->mode() == QgsLayoutItemLabel::ModeHtml );
464  mTopRadioButton->setDisabled( mLabel->mode() == QgsLayoutItemLabel::ModeHtml );
465  mMiddleRadioButton->setDisabled( mLabel->mode() == QgsLayoutItemLabel::ModeHtml );
466  mBottomRadioButton->setDisabled( mLabel->mode() == QgsLayoutItemLabel::ModeHtml );
467 
468  blockAllSignals( false );
469 }
470 
471 void QgsLayoutLabelWidget::blockAllSignals( bool block )
472 {
473  mTextEdit->blockSignals( block );
474  mHtmlCheckBox->blockSignals( block );
475  mMarginXDoubleSpinBox->blockSignals( block );
476  mMarginYDoubleSpinBox->blockSignals( block );
477  mTopRadioButton->blockSignals( block );
478  mMiddleRadioButton->blockSignals( block );
479  mBottomRadioButton->blockSignals( block );
480  mLeftRadioButton->blockSignals( block );
481  mCenterRadioButton->blockSignals( block );
482  mRightRadioButton->blockSignals( block );
483  mJustifyRadioButton->blockSignals( block );
484  mFontColorButton->blockSignals( block );
485  mFontButton->blockSignals( block );
486 }
void colorChanged(const QColor &color)
Emitted whenever a new color is set for the button.
A generic dialog for building expression strings.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:51
QString name
Definition: qgsfield.h:60
QString displayName() const
Returns the name to use when displaying this field.
Definition: qgsfield.cpp:88
Container of fields for a vector layer.
Definition: qgsfields.h:45
@ ModeQFont
Configure font settings for use with QFont objects.
Definition: qgsfontbutton.h:62
void changed()
Emitted when the widget's text format settings are changed.
A base class for property widgets for layout items.
QgsVectorLayer * coverageLayer() const
Returns the current layout context coverage layer (if set).
A layout item subclass for text labels.
void convertToStaticText()
Converts the label's text() to a static string, by evaluating any expressions included in the text an...
@ ModeHtml
Label displays rendered HTML content.
@ ModeFont
Label displays text rendered using a single font.
Layout graphical items for displaying a map.
A widget for controlling the common properties of layout items (e.g.
void setMasterLayout(QgsMasterLayoutInterface *masterLayout)
Sets the master layout associated with the item.
void setItem(QgsLayoutItem *item)
Sets the layout item.
Base class for graphical items within a QgsLayout.
@ UndoLabelFontColor
Label color.
@ UndoLabelMargin
Label margin.
@ UndoLabelFont
Label font.
@ UndoLabelText
Label text.
int type() const override
Returns a unique graphics item type identifier.
void setMasterLayout(QgsMasterLayoutInterface *masterLayout) override
Sets the master layout associated with the item.
bool setNewItem(QgsLayoutItem *item) override
Attempts to update the widget to show the properties for the specified item.
QgsLayoutLabelWidget(QgsLayoutItemLabel *label)
constructor
static void buildInsertDynamicTextMenu(QgsLayout *layout, QMenu *menu, const std::function< void(const QString &expression) > &callback)
Populates the specified menu with actions reflecting dynamic text expressions applicable for a layout...
void changed()
Emitted when the object's properties change.
QgsVectorLayer * layer() const
Returns the vector layer associated with the layout's context.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:51
void layoutItems(QList< T * > &itemList) const
Returns a list of layout items of a specific type.
Definition: qgslayout.h:122
QgsLayoutReportContext & reportContext()
Returns a reference to the layout's report context, which stores information relating to the current ...
Definition: qgslayout.cpp:369
Interface for master layout type objects, such as print layouts and reports.
void setPanelTitle(const QString &panelTitle)
Set the title of the panel when shown in the interface.
A class to represent a 2D point.
Definition: qgspointxy.h:59
double y
Definition: qgspointxy.h:63
Q_GADGET double x
Definition: qgspointxy.h:62
A rectangle specified with double values.
Definition: qgsrectangle.h:42
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:193
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:183
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:188
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:198
QgsPointXY center() const SIP_HOLDGIL
Returns the center point of the rectangle.
Definition: qgsrectangle.h:251
static Q_INVOKABLE QString toString(QgsUnitTypes::DistanceUnit unit)
Returns a translated string representing a distance unit.
Represents a vector layer which manages a vector based data sets.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
const QgsField & field
Definition: qgsfield.h:463