38 #include <QButtonGroup> 
   39 #include <QMessageBox> 
   69   if ( !abstractMetadata )
 
   71     QgsDebugMsg( QStringLiteral( 
"Failed to find callout entry in registry: %1" ).arg( name ) );
 
   77     QgsDebugMsg( QStringLiteral( 
"Failed to cast callout's metadata: " ) .arg( name ) );
 
   84 void QgsLabelingGui::initCalloutWidgets()
 
   86   _initCalloutWidgetFunction( QStringLiteral( 
"simple" ), QgsSimpleLineCalloutWidget::create );
 
   87   _initCalloutWidgetFunction( QStringLiteral( 
"manhattan" ), QgsManhattanLineCalloutWidget::create );
 
   88   _initCalloutWidgetFunction( QStringLiteral( 
"curved" ), QgsCurvedLineCalloutWidget::create );
 
   89   _initCalloutWidgetFunction( QStringLiteral( 
"balloon" ), QgsBalloonCalloutWidget::create );
 
   92 void QgsLabelingGui::updateCalloutWidget( 
QgsCallout *callout )
 
   96     mCalloutStackedWidget->setCurrentWidget( pageDummy );
 
  100   if ( mCalloutStackedWidget->currentWidget() != pageDummy )
 
  103     if ( 
QgsCalloutWidget *pew = qobject_cast< QgsCalloutWidget * >( mCalloutStackedWidget->currentWidget() ) )
 
  114       if ( mGeometryGeneratorGroupBox->isChecked() )
 
  117         geometryType = mLayer->geometryType();
 
  118       w->setGeometryType( geometryType );
 
  119       w->setCallout( callout );
 
  121       w->setContext( context() );
 
  122       mCalloutStackedWidget->addWidget( w );
 
  123       mCalloutStackedWidget->setCurrentWidget( w );
 
  130   mCalloutStackedWidget->setCurrentWidget( pageDummy );
 
  133 void QgsLabelingGui::showObstacleSettings()
 
  147   auto applySettings = [ = ]
 
  149     mObstacleSettings = widget->
settings();
 
  152     emit widgetChanged();
 
  168     dialog.buttonBox()->addButton( QDialogButtonBox::Help );
 
  169     connect( dialog.buttonBox(), &QDialogButtonBox::helpRequested, 
this, [ = ]
 
  171       QgsHelp::openHelp( QStringLiteral( 
"style_library/label_settings.html#obstacles" ) );
 
  183 void QgsLabelingGui::showLineAnchorSettings()
 
  197   auto applySettings = [ = ]
 
  201     mLineSettings.setAnchorType( widgetSettings.
anchorType() );
 
  202     mLineSettings.setAnchorClipping( widgetSettings.
anchorClipping() );
 
  205     emit widgetChanged();
 
  231   , mSettings( layerSettings )
 
  233   , mCanvas( mapCanvas )
 
  235   mGeomType = geomType;
 
  236   static std::once_flag initialized;
 
  237   std::call_once( initialized, [ = ]( )
 
  239     initCalloutWidgets();
 
  257   connect( mBufferDrawChkBx, &QAbstractButton::toggled, 
this, &QgsLabelingGui::updateUi );
 
  259   connect( mEnableMaskChkBx, &QAbstractButton::toggled, 
this, &QgsLabelingGui::updateUi );
 
  260   connect( mShapeDrawChkBx, &QAbstractButton::toggled, 
this, &QgsLabelingGui::updateUi );
 
  261   connect( mCalloutsDrawCheckBox, &QAbstractButton::toggled, 
this, &QgsLabelingGui::updateUi );
 
  262   connect( mShadowDrawChkBx, &QAbstractButton::toggled, 
this, &QgsLabelingGui::updateUi );
 
  263   connect( mDirectSymbChkBx, &QAbstractButton::toggled, 
this, &QgsLabelingGui::updateUi );
 
  264   connect( mFormatNumChkBx, &QAbstractButton::toggled, 
this, &QgsLabelingGui::updateUi );
 
  265   connect( mScaleBasedVisibilityChkBx, &QAbstractButton::toggled, 
this, &QgsLabelingGui::updateUi );
 
  266   connect( mFontLimitPixelChkBox, &QAbstractButton::toggled, 
this, &QgsLabelingGui::updateUi );
 
  267   connect( mGeometryGeneratorGroupBox, &QGroupBox::toggled, 
this, &QgsLabelingGui::updateGeometryTypeBasedWidgets );
 
  268   connect( mGeometryGeneratorType, qOverload<int>( &QComboBox::currentIndexChanged ), 
this, &QgsLabelingGui::updateGeometryTypeBasedWidgets );
 
  269   connect( mGeometryGeneratorExpressionButton, &QToolButton::clicked, 
this, &QgsLabelingGui::showGeometryGeneratorExpressionBuilder );
 
  270   connect( mGeometryGeneratorGroupBox, &QGroupBox::toggled, 
this, &QgsLabelingGui::validateGeometryGeneratorExpression );
 
  271   connect( mGeometryGenerator, &QgsCodeEditorExpression::textChanged, 
this, &QgsLabelingGui::validateGeometryGeneratorExpression );
 
  272   connect( mGeometryGeneratorType, qOverload<int>( &QComboBox::currentIndexChanged ), 
this, &QgsLabelingGui::validateGeometryGeneratorExpression );
 
  273   connect( mObstacleSettingsButton, &QAbstractButton::clicked, 
this, &QgsLabelingGui::showObstacleSettings );
 
  274   connect( mLineAnchorSettingsButton, &QAbstractButton::clicked, 
this, &QgsLabelingGui::showLineAnchorSettings );
 
  276   mFieldExpressionWidget->registerExpressionContextGenerator( 
this );
 
  278   mMinScaleWidget->setMapCanvas( mCanvas );
 
  279   mMinScaleWidget->setShowCurrentScaleButton( 
true );
 
  280   mMaxScaleWidget->setMapCanvas( mCanvas );
 
  281   mMaxScaleWidget->setShowCurrentScaleButton( 
true );
 
  284   for ( 
const QString &type : calloutTypes )
 
  290   mGeometryGeneratorWarningLabel->setStyleSheet( QStringLiteral( 
"color: #FFC107;" ) );
 
  291   mGeometryGeneratorWarningLabel->setTextInteractionFlags( Qt::TextBrowserInteraction );
 
  292   connect( mGeometryGeneratorWarningLabel, &QLabel::linkActivated, 
this, [
this]( 
const QString & link )
 
  294     if ( link == QLatin1String( 
"#determineGeometryGeneratorType" ) )
 
  295       determineGeometryGeneratorType();
 
  298   connect( mCalloutStyleComboBox, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsLabelingGui::calloutTypeChanged );
 
  300   mLblNoObstacle1->installEventFilter( 
this );
 
  305 void QgsLabelingGui::setLayer( 
QgsMapLayer *mapLayer )
 
  320   mTextFormatsListWidget->setLayerType( mLayer ? mLayer->geometryType() : mGeomType );
 
  321   mBackgroundMarkerSymbolButton->setLayer( mLayer );
 
  322   mBackgroundFillSymbolButton->setLayer( mLayer );
 
  325   updateGeometryTypeBasedWidgets();
 
  327   mFieldExpressionWidget->setLayer( mLayer );
 
  332   mFieldExpressionWidget->setGeomCalculator( da );
 
  334   mFieldExpressionWidget->setEnabled( mMode == Labels || !mLayer );
 
  335   mLabelingFrame->setEnabled( mMode == Labels || !mLayer );
 
  337   blockInitSignals( 
true );
 
  339   mGeometryGenerator->setText( mSettings.geometryGenerator );
 
  340   mGeometryGeneratorGroupBox->setChecked( mSettings.geometryGeneratorEnabled );
 
  341   if ( !mSettings.geometryGeneratorEnabled )
 
  342     mGeometryGeneratorGroupBox->setCollapsed( 
true );
 
  343   mGeometryGeneratorType->setCurrentIndex( mGeometryGeneratorType->findData( mSettings.geometryGeneratorType ) );
 
  347   mFieldExpressionWidget->setRow( -1 );
 
  348   mFieldExpressionWidget->setField( mSettings.fieldName );
 
  349   mCheckBoxSubstituteText->setChecked( mSettings.useSubstitutions );
 
  350   mSubstitutions = mSettings.substitutions;
 
  353   mCentroidRadioWhole->setChecked( mSettings.centroidWhole );
 
  354   mCentroidInsideCheckBox->setChecked( mSettings.centroidInside );
 
  355   mFitInsidePolygonCheckBox->setChecked( mSettings.fitInPolygonOnly );
 
  356   mLineDistanceSpnBx->setValue( mSettings.dist );
 
  357   mLineDistanceUnitWidget->setUnit( mSettings.distUnits );
 
  358   mLineDistanceUnitWidget->setMapUnitScale( mSettings.distMapUnitScale );
 
  359   mOffsetTypeComboBox->setCurrentIndex( mOffsetTypeComboBox->findData( mSettings.offsetType ) );
 
  360   mQuadrantBtnGrp->button( 
static_cast<int>( mSettings.quadOffset ) )->setChecked( 
true );
 
  361   mPointOffsetXSpinBox->setValue( mSettings.xOffset );
 
  362   mPointOffsetYSpinBox->setValue( mSettings.yOffset );
 
  363   mPointOffsetUnitWidget->setUnit( mSettings.offsetUnits );
 
  364   mPointOffsetUnitWidget->setMapUnitScale( mSettings.labelOffsetMapUnitScale );
 
  365   mPointAngleSpinBox->setValue( mSettings.angleOffset );
 
  366   chkLineAbove->setChecked( mSettings.lineSettings().placementFlags() & QgsLabeling::LinePlacementFlag::AboveLine );
 
  367   chkLineBelow->setChecked( mSettings.lineSettings().placementFlags() & QgsLabeling::LinePlacementFlag::BelowLine );
 
  368   chkLineOn->setChecked( mSettings.lineSettings().placementFlags() & QgsLabeling::LinePlacementFlag::OnLine );
 
  369   chkLineOrientationDependent->setChecked( !( mSettings.lineSettings().placementFlags() & QgsLabeling::LinePlacementFlag::MapOrientation ) );
 
  371   mCheckAllowLabelsOutsidePolygons->setChecked( mSettings.polygonPlacementFlags() & QgsLabeling::PolygonPlacementFlag::AllowPlacementOutsideOfPolygon );
 
  373   const int placementIndex = mPlacementModeComboBox->findData( mSettings.placement );
 
  374   if ( placementIndex >= 0 )
 
  376     mPlacementModeComboBox->setCurrentIndex( placementIndex );
 
  381     mPlacementModeComboBox->setCurrentIndex( 0 );
 
  385   mRepeatDistanceSpinBox->setValue( mSettings.repeatDistance );
 
  386   mRepeatDistanceUnitWidget->setUnit( mSettings.repeatDistanceUnit );
 
  387   mRepeatDistanceUnitWidget->setMapUnitScale( mSettings.repeatDistanceMapUnitScale );
 
  389   mOverrunDistanceSpinBox->setValue( mSettings.lineSettings().overrunDistance() );
 
  390   mOverrunDistanceUnitWidget->setUnit( mSettings.lineSettings().overrunDistanceUnit() );
 
  391   mOverrunDistanceUnitWidget->setMapUnitScale( mSettings.lineSettings().overrunDistanceMapUnitScale() );
 
  393   mPrioritySlider->setValue( mSettings.priority );
 
  394   mChkNoObstacle->setChecked( mSettings.obstacleSettings().isObstacle() );
 
  396   mObstacleSettings = mSettings.obstacleSettings();
 
  397   mLineSettings = mSettings.lineSettings();
 
  399   chkLabelPerFeaturePart->setChecked( mSettings.labelPerPart );
 
  400   mPalShowAllLabelsForLayerChkBx->setChecked( mSettings.displayAll );
 
  401   chkMergeLines->setChecked( mSettings.lineSettings().mergeLines() );
 
  402   mMinSizeSpinBox->setValue( mSettings.thinningSettings().minimumFeatureSize() );
 
  403   mLimitLabelChkBox->setChecked( mSettings.thinningSettings().limitNumberOfLabelsEnabled() );
 
  404   mLimitLabelSpinBox->setValue( mSettings.thinningSettings().maximumNumberLabels() );
 
  407   mDirectSymbChkBx->setChecked( mSettings.lineSettings().addDirectionSymbol() );
 
  408   mDirectSymbLeftLineEdit->setText( mSettings.lineSettings().leftDirectionSymbol() );
 
  409   mDirectSymbRightLineEdit->setText( mSettings.lineSettings().rightDirectionSymbol() );
 
  410   mDirectSymbRevChkBx->setChecked( mSettings.lineSettings().reverseDirectionSymbol() );
 
  412   mDirectSymbBtnGrp->button( 
static_cast<int>( mSettings.lineSettings().directionSymbolPlacement() ) )->setChecked( 
true );
 
  413   mUpsidedownBtnGrp->button( 
static_cast<int>( mSettings.upsidedownLabels ) )->setChecked( 
true );
 
  416   mMaxCharAngleInDSpinBox->setValue( mSettings.maxCurvedCharAngleIn );
 
  418   mMaxCharAngleOutDSpinBox->setValue( std::fabs( mSettings.maxCurvedCharAngleOut ) );
 
  420   wrapCharacterEdit->setText( mSettings.wrapChar );
 
  421   mAutoWrapLengthSpinBox->setValue( mSettings.autoWrapLength );
 
  422   mAutoWrapTypeComboBox->setCurrentIndex( mSettings.useMaxLineLengthForAutoWrap ? 0 : 1 );
 
  424   if ( mFontMultiLineAlignComboBox->findData( mSettings.multilineAlign ) != -1 )
 
  426     mFontMultiLineAlignComboBox->setCurrentIndex( mFontMultiLineAlignComboBox->findData( mSettings.multilineAlign ) );
 
  432     mFontMultiLineAlignComboBox->setCurrentIndex( 0 );
 
  435   chkPreserveRotation->setChecked( mSettings.preserveRotation );
 
  437   mCoordRotationUnitComboBox->setCurrentIndex( 0 );
 
  438   if ( mCoordRotationUnitComboBox->findData( 
static_cast< unsigned int >( mSettings.rotationUnit() ) ) >= 0 )
 
  439     mCoordRotationUnitComboBox->setCurrentIndex( mCoordRotationUnitComboBox->findData( 
static_cast< unsigned int >( mSettings.rotationUnit() ) ) );
 
  441   mScaleBasedVisibilityChkBx->setChecked( mSettings.scaleVisibility );
 
  442   mMinScaleWidget->setScale( mSettings.minimumScale );
 
  443   mMaxScaleWidget->setScale( mSettings.maximumScale );
 
  445   mFormatNumChkBx->setChecked( mSettings.formatNumbers );
 
  446   mFormatNumDecimalsSpnBx->setValue( mSettings.decimals );
 
  447   mFormatNumPlusSignChkBx->setChecked( mSettings.plusSign );
 
  451   mFontLimitPixelChkBox->setChecked( mSettings.fontLimitPixelSize );
 
  452   mMinPixelLimit = mSettings.fontMinPixelSize; 
 
  453   mFontMinPixelSpinBox->setValue( mSettings.fontMinPixelSize == 0 ? 3 : mSettings.fontMinPixelSize );
 
  454   mFontMaxPixelSpinBox->setValue( mSettings.fontMaxPixelSize );
 
  456   mZIndexSpinBox->setValue( mSettings.zIndex );
 
  458   mDataDefinedProperties = mSettings.dataDefinedProperties();
 
  461   if ( 
auto *lCallout = mSettings.callout() )
 
  463     whileBlocking( mCalloutsDrawCheckBox )->setChecked( lCallout->enabled() );
 
  464     whileBlocking( mCalloutStyleComboBox )->setCurrentIndex( mCalloutStyleComboBox->findData( lCallout->type() ) );
 
  465     updateCalloutWidget( lCallout );
 
  470     whileBlocking( mCalloutStyleComboBox )->setCurrentIndex( mCalloutStyleComboBox->findData( defaultCallout->type() ) );
 
  472     updateCalloutWidget( defaultCallout.get() );
 
  475   updatePlacementWidgets();
 
  476   updateLinePlacementOptions();
 
  479   blockInitSignals( 
false );
 
  483   populateDataDefinedButtons();
 
  485   enableDataDefinedAlignment( mCoordXDDBtn->isActive() && mCoordYDDBtn->isActive() );
 
  491   mSettings = settings;
 
  495 void QgsLabelingGui::blockInitSignals( 
bool block )
 
  497   chkLineAbove->blockSignals( block );
 
  498   chkLineBelow->blockSignals( block );
 
  499   mPlacementModeComboBox->blockSignals( block );
 
  502 void QgsLabelingGui::setLabelMode( LabelMode mode )
 
  505   mFieldExpressionWidget->setEnabled( mMode == Labels );
 
  506   mLabelingFrame->setEnabled( mMode == Labels );
 
  516   lyr.
drawLabels = ( mMode == Labels ) || !mLayer;
 
  519   lyr.
fieldName = mFieldExpressionWidget->currentField( &isExpression );
 
  524   QgsLabeling::PolygonPlacementFlags polygonPlacementFlags = QgsLabeling::PolygonPlacementFlag::AllowPlacementInsideOfPolygon;
 
  525   if ( mCheckAllowLabelsOutsidePolygons->isChecked() )
 
  526     polygonPlacementFlags |= QgsLabeling::PolygonPlacementFlag::AllowPlacementOutsideOfPolygon;
 
  532   lyr.
dist = mLineDistanceSpnBx->value();
 
  533   lyr.
distUnits = mLineDistanceUnitWidget->unit();
 
  536   if ( mQuadrantBtnGrp )
 
  540   lyr.
xOffset = mPointOffsetXSpinBox->value();
 
  541   lyr.
yOffset = mPointOffsetYSpinBox->value();
 
  546   QgsLabeling::LinePlacementFlags linePlacementFlags = QgsLabeling::LinePlacementFlags();
 
  547   if ( chkLineAbove->isChecked() )
 
  548     linePlacementFlags |= QgsLabeling::LinePlacementFlag::AboveLine;
 
  549   if ( chkLineBelow->isChecked() )
 
  550     linePlacementFlags |= QgsLabeling::LinePlacementFlag::BelowLine;
 
  551   if ( chkLineOn->isChecked() )
 
  552     linePlacementFlags |= QgsLabeling::LinePlacementFlag::OnLine;
 
  553   if ( ! chkLineOrientationDependent->isChecked() )
 
  554     linePlacementFlags |= QgsLabeling::LinePlacementFlag::MapOrientation;
 
  567   lyr.
priority = mPrioritySlider->value();
 
  569   mObstacleSettings.setIsObstacle( mChkNoObstacle->isChecked() || mMode == ObstaclesOnly );
 
  577   lyr.
displayAll = mPalShowAllLabelsForLayerChkBx->isChecked();
 
  590   lyr.
decimals = mFormatNumDecimalsSpnBx->value();
 
  591   lyr.
plusSign = mFormatNumPlusSignChkBx->isChecked();
 
  598   if ( mDirectSymbBtnGrp )
 
  602   if ( mUpsidedownBtnGrp )
 
  618   lyr.
wrapChar = wrapCharacterEdit->text();
 
  628   lyr.
layerType = mLayer ? mLayer->geometryType() : mGeomType;
 
  630   lyr.
zIndex = mZIndexSpinBox->value();
 
  635   const QString calloutType = mCalloutStyleComboBox->currentData().toString();
 
  636   std::unique_ptr< QgsCallout > callout;
 
  637   if ( 
QgsCalloutWidget *pew = qobject_cast< QgsCalloutWidget * >( mCalloutStackedWidget->currentWidget() ) )
 
  639     callout.reset( pew->callout()->clone() );
 
  644   callout->
setEnabled( mCalloutsDrawCheckBox->isChecked() );
 
  652   f->setEnabled( chkBx->isChecked() || ddBtn->
isActive() );
 
  655 bool QgsLabelingGui::eventFilter( QObject *
object, QEvent *event )
 
  657   if ( 
object == mLblNoObstacle1 )
 
  659     if ( event->type() == QEvent::MouseButtonPress && qgis::down_cast< QMouseEvent * >( event )->button() == Qt::LeftButton )
 
  662       mChkNoObstacle->setChecked( !mChkNoObstacle->isChecked() );
 
  667   return QgsTextFormatWidget::eventFilter( 
object, event );
 
  670 void QgsLabelingGui::updateUi()
 
  674   syncDefinedCheckboxFrame( mBufferDrawDDBtn, mBufferDrawChkBx, mBufferFrame );
 
  675   syncDefinedCheckboxFrame( mEnableMaskDDBtn, mEnableMaskChkBx, mMaskFrame );
 
  676   syncDefinedCheckboxFrame( mShapeDrawDDBtn, mShapeDrawChkBx, mShapeFrame );
 
  677   syncDefinedCheckboxFrame( mShadowDrawDDBtn, mShadowDrawChkBx, mShadowFrame );
 
  678   syncDefinedCheckboxFrame( mCalloutDrawDDBtn, mCalloutsDrawCheckBox, mCalloutFrame );
 
  680   syncDefinedCheckboxFrame( mDirectSymbDDBtn, mDirectSymbChkBx, mDirectSymbFrame );
 
  681   syncDefinedCheckboxFrame( mFormatNumDDBtn, mFormatNumChkBx, mFormatNumFrame );
 
  682   syncDefinedCheckboxFrame( mScaleBasedVisibilityDDBtn, mScaleBasedVisibilityChkBx, mScaleBasedVisibilityFrame );
 
  683   syncDefinedCheckboxFrame( mFontLimitPixelDDBtn, mFontLimitPixelChkBox, mFontLimitPixelFrame );
 
  685   chkMergeLines->setEnabled( !mDirectSymbChkBx->isChecked() );
 
  686   if ( mDirectSymbChkBx->isChecked() )
 
  688     chkMergeLines->setToolTip( tr( 
"This option is not compatible with line direction symbols." ) );
 
  692     chkMergeLines->setToolTip( QString() );
 
  722         settings.
fieldName = mFieldExpressionWidget->currentField( &isExpression );
 
  725       setSettings( settings );
 
  733   if ( 
QgsCalloutWidget *cw = qobject_cast< QgsCalloutWidget * >( mCalloutStackedWidget->currentWidget() ) )
 
  735     cw->setContext( context );
 
  740 void QgsLabelingGui::saveFormat()
 
  747   saveDlg.setDefaultTags( mTextFormatsListWidget->currentTagFilter() );
 
  748   if ( !saveDlg.exec() )
 
  751   if ( saveDlg.name().isEmpty() )
 
  754   switch ( saveDlg.selectedType() )
 
  761         const int res = QMessageBox::warning( 
this, tr( 
"Save Text Format" ),
 
  762                                               tr( 
"Format with name '%1' already exists. Overwrite?" )
 
  763                                               .arg( saveDlg.name() ),
 
  764                                               QMessageBox::Yes | QMessageBox::No );
 
  765         if ( res != QMessageBox::Yes )
 
  771       const QStringList symbolTags = saveDlg.tags().split( 
',' );
 
  775       style->
saveTextFormat( saveDlg.name(), newFormat, saveDlg.isFavorite(), symbolTags );
 
  784         const int res = QMessageBox::warning( 
this, tr( 
"Save Label Settings" ),
 
  785                                               tr( 
"Label settings with the name '%1' already exist. Overwrite?" )
 
  786                                               .arg( saveDlg.name() ),
 
  787                                               QMessageBox::Yes | QMessageBox::No );
 
  788         if ( res != QMessageBox::Yes )
 
  794       const QStringList symbolTags = saveDlg.tags().split( 
',' );
 
  798       style->
saveLabelSettings( saveDlg.name(), newSettings, saveDlg.isFavorite(), symbolTags );
 
  812 void QgsLabelingGui::updateGeometryTypeBasedWidgets()
 
  816   if ( mGeometryGeneratorGroupBox->isChecked() )
 
  819     geometryType = mLayer->geometryType();
 
  829   mPlacementModeComboBox->clear();
 
  831   switch ( geometryType )
 
  858       qFatal( 
"unknown geometry type unexpected" );
 
  861   if ( mPlacementModeComboBox->findData( prevPlacement ) != -1 )
 
  863     mPlacementModeComboBox->setCurrentIndex( mPlacementModeComboBox->findData( prevPlacement ) );
 
  876       mFontMultiLineAlignComboBox->removeItem( idx );
 
  879   updatePlacementWidgets();
 
  880   updateLinePlacementOptions();
 
  883 void QgsLabelingGui::showGeometryGeneratorExpressionBuilder()
 
  887   expressionBuilder.setExpressionText( mGeometryGenerator->text() );
 
  888   expressionBuilder.setExpressionContext( createExpressionContext() );
 
  890   if ( expressionBuilder.exec() )
 
  892     mGeometryGenerator->setText( expressionBuilder.expressionText() );
 
  896 void QgsLabelingGui::validateGeometryGeneratorExpression()
 
  900   if ( mGeometryGeneratorGroupBox->isChecked() )
 
  902     if ( !mPreviewFeature.isValid() && mLayer )
 
  903       mLayer->getFeatures( 
QgsFeatureRequest().setLimit( 1 ) ).nextFeature( mPreviewFeature );
 
  909     expression.prepare( &context );
 
  911     if ( expression.hasParserError() )
 
  913       mGeometryGeneratorWarningLabel->setText( expression.parserErrorString() );
 
  918       const QVariant result = expression.evaluate( &context );
 
  923         mGeometryGeneratorWarningLabel->setText( tr( 
"Result of the expression is not a geometry" ) );
 
  926       else if ( geometry.
type() != configuredGeometryType )
 
  928         mGeometryGeneratorWarningLabel->setText( QStringLiteral( 
"<p>%1</p><p><a href=\"#determineGeometryGeneratorType\">%2</a></p>" ).arg(
 
  929               tr( 
"Result of the expression does not match configured geometry type." ),
 
  938   QTimer *timer = 
new QTimer();
 
  939   connect( timer, &QTimer::timeout, 
this, [
this, valid]()
 
  941     mGeometryGeneratorWarningLabel->setVisible( !valid );
 
  943   connect( timer, &QTimer::timeout, timer, &QTimer::deleteLater );
 
  947 void QgsLabelingGui::determineGeometryGeneratorType()
 
  949   if ( !mPreviewFeature.isValid() && mLayer )
 
  950     mLayer->getFeatures( 
QgsFeatureRequest().setLimit( 1 ) ).nextFeature( mPreviewFeature );
 
  956   expression.prepare( &context );
 
  959   mGeometryGeneratorType->setCurrentIndex( mGeometryGeneratorType->findData( geometry.
type() ) );
 
  962 void QgsLabelingGui::calloutTypeChanged()
 
  964   const QString newCalloutType = mCalloutStyleComboBox->currentData().toString();
 
  965   QgsCalloutWidget *pew = qobject_cast< QgsCalloutWidget * >( mCalloutStackedWidget->currentWidget() );
 
  984   updateCalloutWidget( newCallout.get() );
 
  997   QVBoxLayout *vLayout = 
new QVBoxLayout();
 
  998   mWidget = 
new QgsLabelingGui( layer, mapCanvas, settings, 
nullptr, geomType );
 
  999   vLayout->addWidget( mWidget );
 
 1000   mButtonBox = 
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok, Qt::Horizontal );
 
 1001   connect( mButtonBox, &QDialogButtonBox::accepted, 
this, &QDialog::accept );
 
 1002   connect( mButtonBox, &QDialogButtonBox::rejected, 
this, &QDialog::reject );
 
 1003   connect( mButtonBox, &QDialogButtonBox::helpRequested, 
this, &QgsLabelSettingsDialog::showHelp );
 
 1004   vLayout->addWidget( mButtonBox );
 
 1005   setLayout( vLayout );
 
 1006   setWindowTitle( tr( 
"Label Settings" ) );
 
 1009 QDialogButtonBox *QgsLabelSettingsDialog::buttonBox()
 const 
 1014 void QgsLabelSettingsDialog::showHelp()
 
static QgsCalloutRegistry * calloutRegistry()
Returns the application's callout registry, used for managing callout types.
 
Registry of available callout classes.
 
QgsCalloutAbstractMetadata * calloutMetadata(const QString &type) const
Returns the metadata for specified the specified callout type.
 
QStringList calloutTypes() const
Returns a list of all available callout types.
 
QgsCallout * createCallout(const QString &type, const QVariantMap &properties=QVariantMap(), const QgsReadWriteContext &context=QgsReadWriteContext()) const
Creates a new instance of a callout, given the callout type and properties.
 
Abstract base class for callout renderers.
 
void setEnabled(bool enabled)
Sets whether the callout is enabled.
 
virtual QString type() const =0
Returns a unique string representing the callout type.
 
virtual QVariantMap properties(const QgsReadWriteContext &context) const
Returns the properties describing the callout encoded in a string format.
 
A general purpose distance and area calculator, capable of performing ellipsoid based calculations.
 
void setSourceCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets source spatial reference system crs.
 
bool setEllipsoid(const QString &ellipsoid)
Sets the ellipsoid by its acronym.
 
A generic dialog for building expression strings.
 
Single scope for storing variables and functions for use within a QgsExpressionContext.
 
static QgsExpressionContextScope * updateSymbolScope(const QgsSymbol *symbol, QgsExpressionContextScope *symbolScope=nullptr)
Updates a symbol scope related to a QgsSymbol to an expression context.
 
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
 
static QgsExpressionContextScope * atlasScope(const QgsLayoutAtlas *atlas)
Creates a new scope which contains variables and functions relating to a QgsLayoutAtlas.
 
static QgsExpressionContextScope * mapSettingsScope(const QgsMapSettings &mapSettings)
Creates a new scope which contains variables and functions relating to a QgsMapSettings object.
 
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
 
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context.
 
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
 
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
 
static const QString EXPR_SYMBOL_COLOR
Inbuilt variable name for symbol color variable.
 
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
 
void setHighlightedVariables(const QStringList &variableNames)
Sets the list of variable names within the context intended to be highlighted to the user.
 
static const QString EXPR_ORIGINAL_VALUE
Inbuilt variable name for value original value variable.
 
Class for parsing and evaluation of expressions (formerly called "search strings").
 
This class wraps a request for features to a vector layer (or directly its vector data provider).
 
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
 
A geometry is the spatial representation of a feature.
 
QgsWkbTypes::GeometryType type
 
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
 
Contains settings related to how the label engine places and formats labels for line features (or pol...
 
void setPlacementFlags(QgsLabeling::LinePlacementFlags flags)
Returns the line placement flags, which dictate how line labels can be placed above or below the line...
 
void setLineAnchorPercent(double percent)
Sets the percent along the line at which labels should be placed.
 
void setDirectionSymbolPlacement(DirectionSymbolPlacement placement)
Sets the placement for direction symbols.
 
AnchorType anchorType() const
Returns the line anchor type, which dictates how the lineAnchorPercent() setting is handled.
 
void setLeftDirectionSymbol(const QString &symbol)
Sets the string to use for left direction arrows.
 
void setMergeLines(bool merge)
Sets whether connected line features with identical label text should be merged prior to generating l...
 
DirectionSymbolPlacement
Placement options for direction symbols.
 
void setRightDirectionSymbol(const QString &symbol)
Sets the string to use for right direction arrows.
 
void setAnchorClipping(AnchorClipping clipping)
Sets the line anchor clipping mode, which dictates how line strings are clipped before calculating th...
 
void setOverrunDistanceMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for label overrun distance.
 
double lineAnchorPercent() const
Returns the percent along the line at which labels should be placed.
 
void setAnchorType(AnchorType type)
Sets the line anchor type, which dictates how the lineAnchorPercent() setting is handled.
 
void setOverrunDistance(double distance)
Sets the distance which labels are allowed to overrun past the start or end of line features.
 
AnchorClipping anchorClipping() const
Returns the line anchor clipping mode, which dictates how line strings are clipped before calculating...
 
void setOverrunDistanceUnit(const QgsUnitTypes::RenderUnit &unit)
Sets the unit for label overrun distance.
 
void setReverseDirectionSymbol(bool reversed)
Sets whether the direction symbols should be reversed.
 
void setAddDirectionSymbol(bool enabled)
Sets whether '<' or '>' (or custom strings set via leftDirectionSymbol and rightDirectionSymbol) will...
 
void setMaximumNumberLabels(int number)
Sets the maximum number of labels which should be drawn for this layer.
 
void setLimitNumberLabelsEnabled(bool enabled)
Sets whether the the number of labels drawn for the layer should be limited.
 
void setMinimumFeatureSize(double size)
Sets the minimum feature size (in millimeters) for a feature to be labelled.
 
Map canvas is a class for displaying all GIS data types on a canvas.
 
Base class for all map layer types.
 
Contains settings for how a map layer will be labeled.
 
bool fitInPolygonOnly
true if only labels which completely fit within a polygon are allowed.
 
double yOffset
Vertical offset of label.
 
QgsMapUnitScale labelOffsetMapUnitScale
Map unit scale for label offset.
 
int fontMaxPixelSize
Maximum pixel size for showing rendered map unit labels (1 - 10000).
 
void setObstacleSettings(const QgsLabelObstacleSettings &settings)
Sets the label obstacle settings.
 
double maxCurvedCharAngleIn
Maximum angle between inside curved label characters (valid range 20.0 to 60.0).
 
void setFormat(const QgsTextFormat &format)
Sets the label text formatting settings, e.g., font settings, buffer settings, etc.
 
double zIndex
Z-Index of label, where labels with a higher z-index are rendered on top of labels with a lower z-ind...
 
bool displayAll
If true, all features will be labelled even when overlaps occur.
 
QString wrapChar
Wrapping character string.
 
double xOffset
Horizontal offset of label.
 
bool drawLabels
Whether to draw labels for this layer.
 
bool fontLimitPixelSize
true if label sizes should be limited by pixel size.
 
QuadrantPosition quadOffset
Sets the quadrant in which to offset labels from feature.
 
double minimumScale
The minimum map scale (i.e.
 
QgsWkbTypes::GeometryType geometryGeneratorType
The type of the result geometry of the geometry generator.
 
QgsUnitTypes::RenderUnit offsetUnits
Units for offsets of label.
 
bool scaleVisibility
Set to true to limit label visibility to a range of scales.
 
double repeatDistance
Distance for repeating labels for a single feature.
 
bool geometryGeneratorEnabled
Defines if the geometry generator is enabled or not. If disabled, the standard geometry will be taken...
 
Placement
Placement modes which determine how label candidates are generated for a feature.
 
@ PerimeterCurved
Arranges candidates following the curvature of a polygon's boundary. Applies to polygon layers only.
 
@ Curved
Arranges candidates following the curvature of a line feature. Applies to line layers only.
 
@ Horizontal
Arranges horizontal candidates scattered throughout a polygon feature. Applies to polygon layers only...
 
@ Free
Arranges candidates scattered throughout a polygon feature. Candidates are rotated to respect the pol...
 
@ OverPoint
Arranges candidates over a point (or centroid of a polygon), or at a preset offset from the point....
 
@ AroundPoint
Arranges candidates in a circle around a point (or centroid of a polygon). Applies to point or polygo...
 
@ Line
Arranges candidates parallel to a generalised line representing the feature or parallel to a polygon'...
 
@ OrderedPositionsAroundPoint
Candidates are placed in predefined positions around a point. Preference is given to positions with g...
 
@ OutsidePolygons
Candidates are placed outside of polygon boundaries. Applies to polygon layers only....
 
bool centroidInside
true if centroid positioned labels must be placed inside their corresponding feature polygon,...
 
int priority
Label priority.
 
bool labelPerPart
true if every part of a multi-part feature should be labeled.
 
QgsUnitTypes::RenderUnit distUnits
Units the distance from feature to the label.
 
QgsUnitTypes::RenderUnit repeatDistanceUnit
Units for repeating labels for a single feature.
 
OffsetType offsetType
Offset type for layer (only applies in certain placement modes)
 
MultiLineAlign multilineAlign
Horizontal alignment of multi-line labels.
 
int fontMinPixelSize
Minimum pixel size for showing rendered map unit labels (1 - 1000).
 
double angleOffset
Label rotation, in degrees clockwise.
 
double maxCurvedCharAngleOut
Maximum angle between outside curved label characters (valid range -20.0 to -95.0)
 
const QgsLabelLineSettings & lineSettings() const
Returns the label line settings, which contain settings related to how the label engine places and fo...
 
void setPolygonPlacementFlags(QgsLabeling::PolygonPlacementFlags flags)
Sets the polygon placement flags, which dictate how polygon labels can be placed.
 
void setRotationUnit(QgsUnitTypes::AngleUnit angleUnit)
Set unit for rotation of labels.
 
OffsetType
Behavior modifier for label offset and distance, only applies in some label placement modes.
 
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the label's property collection, used for data defined overrides.
 
bool isExpression
true if this label is made from a expression string, e.g., FieldName || 'mm'
 
bool preserveRotation
True if label rotation should be preserved during label pin/unpin operations.
 
bool plusSign
Whether '+' signs should be prepended to positive numeric labels.
 
QString geometryGenerator
The geometry generator expression. Null if disabled.
 
QgsMapUnitScale distMapUnitScale
Map unit scale for label feature distance.
 
QgsStringReplacementCollection substitutions
Substitution collection for automatic text substitution with labels.
 
int decimals
Number of decimal places to show for numeric labels.
 
double dist
Distance from feature to the label.
 
QgsMapUnitScale repeatDistanceMapUnitScale
Map unit scale for repeating labels for a single feature.
 
bool centroidWhole
true if feature centroid should be calculated from the whole feature, or false if only the visible pa...
 
UpsideDownLabels upsidedownLabels
Controls whether upside down labels are displayed and how they are handled.
 
QString fieldName
Name of field (or an expression) to use for label text.
 
bool formatNumbers
Set to true to format numeric label text as numbers (e.g.
 
QgsWkbTypes::GeometryType layerType
Geometry type of layers associated with these settings.
 
void setCallout(QgsCallout *callout)
Sets the label callout renderer, responsible for drawing label callouts.
 
double maximumScale
The maximum map scale (i.e.
 
int autoWrapLength
If non-zero, indicates that label text should be automatically wrapped to (ideally) the specified num...
 
bool useMaxLineLengthForAutoWrap
If true, indicates that when auto wrapping label text the autoWrapLength length indicates the maximum...
 
void setUnplacedVisibility(Qgis::UnplacedLabelVisibility visibility)
Sets the layer's unplaced label visibility.
 
const QgsLabelThinningSettings & thinningSettings() const
Returns the label thinning settings.
 
bool useSubstitutions
True if substitutions should be applied.
 
static QgsProject * instance()
Returns the QgsProject singleton instance.
 
QgsCoordinateTransformContext transformContext
 
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
 
The class is used as a container of context for various read/write operations on other objects.
 
a dialog for setting properties of a newly saved style.
 
bool removeLabelSettings(const QString &name)
Removes label settings from the style.
 
bool saveLabelSettings(const QString &name, const QgsPalLayerSettings &settings, bool favorite, const QStringList &tags)
Adds label settings to the database.
 
QgsTextFormat defaultTextFormat(QgsStyle::TextFormatContext context=QgsStyle::TextFormatContext::Labeling) const
Returns the default text format to use for new text based objects in the specified context.
 
QStringList textFormatNames() const
Returns a list of names of text formats in the style.
 
bool removeTextFormat(const QString &name)
Removes a text format from the style.
 
StyleEntity
Enum for Entities involved in a style.
 
@ LabelSettingsEntity
Label settings.
 
@ TextFormatEntity
Text formats.
 
@ SmartgroupEntity
Smart groups.
 
@ Symbol3DEntity
3D symbol entity (since QGIS 3.14)
 
@ ColorrampEntity
Color ramps.
 
@ LegendPatchShapeEntity
Legend patch shape (since QGIS 3.14)
 
static QgsStyle * defaultStyle()
Returns default application-wide style.
 
QStringList labelSettingsNames() const
Returns a list of names of label settings in the style.
 
bool addTextFormat(const QString &name, const QgsTextFormat &format, bool update=false)
Adds a text format with the specified name to the style.
 
QgsPalLayerSettings labelSettings(const QString &name) const
Returns the label settings with the specified name.
 
@ Labeling
Text format used in labeling.
 
bool saveTextFormat(const QString &name, const QgsTextFormat &format, bool favorite, const QStringList &tags)
Adds a text format to the database.
 
bool addLabelSettings(const QString &name, const QgsPalLayerSettings &settings, bool update=false)
Adds label settings with the specified name to the style.
 
Contains settings which reflect the context in which a symbol (or renderer) widget is shown,...
 
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the widget.
 
void setExpressionContext(QgsExpressionContext *context)
Sets the optional expression context used for the widget.
 
A widget for customizing text formatting settings.
 
virtual void setFormatFromStyle(const QString &name, QgsStyle::StyleEntity type)
Sets the current text settings from a style entry.
 
virtual void setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the widget is shown, e.g., the associated map canvas and expression context...
 
Container for all settings relating to text rendering.
 
AngleUnit
Units of angles.
 
@ AngleRadians
Square kilometers.
 
@ AngleMilNATO
Angular mil (NATO definition, 6400 mil = 2PI radians)
 
@ AngleMilliradiansSI
Angular milliradians (SI definition, 1/1000 of radian)
 
@ AngleTurn
Turn/revolutions.
 
@ AngleMinutesOfArc
Minutes of arc.
 
@ AngleSecondsOfArc
Seconds of arc.
 
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.
 
static QString geometryDisplayString(GeometryType type) SIP_HOLDGIL
Returns a display string for a geometry type.
 
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
 
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
 
QgsCalloutWidget *(* QgsCalloutWidgetFunc)(QgsVectorLayer *)