19#include "moc_qgslabelinggui.cpp"
39#include <QButtonGroup>
49 expContext = mMapCanvas->createExpressionContext();
78void QgsLabelingGui::updateCalloutWidget(
QgsCallout *callout )
82 mCalloutStackedWidget->setCurrentWidget( pageDummy );
89 mCalloutStackedWidget->setCurrentWidget( pageDummy );
93 if ( mCalloutStackedWidget->currentWidget() != pageDummy )
96 if (
QgsCalloutWidget *pew = qobject_cast<QgsCalloutWidget *>( mCalloutStackedWidget->currentWidget() ) )
106 if ( mGeometryGeneratorGroupBox->isChecked() )
110 w->setGeometryType( geometryType );
111 w->setCallout( callout );
113 w->setContext( context() );
114 mCalloutStackedWidget->addWidget( w );
115 mCalloutStackedWidget->setCurrentWidget( w );
122 mCalloutStackedWidget->setCurrentWidget( pageDummy );
125void QgsLabelingGui::showObstacleSettings()
127 QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( mLayer );
145 auto applySettings = [=] {
146 mObstacleSettings = widget->
settings();
149 emit widgetChanged();
164 dialog.buttonBox()->addButton( QDialogButtonBox::Help );
165 connect( dialog.buttonBox(), &QDialogButtonBox::helpRequested,
this, [=] {
166 QgsHelp::openHelp( QStringLiteral(
"style_library/label_settings.html#obstacles" ) );
178void QgsLabelingGui::showLineAnchorSettings()
180 QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( mLayer );
198 auto applySettings = [=] {
201 mLineSettings.setAnchorType( widgetSettings.
anchorType() );
202 mLineSettings.setAnchorClipping( widgetSettings.
anchorClipping() );
206 emit widgetChanged();
221 dialog.buttonBox()->addButton( QDialogButtonBox::Help );
222 connect( dialog.buttonBox(), &QDialogButtonBox::helpRequested,
this, [=] {
223 QgsHelp::openHelp( QStringLiteral(
"style_library/label_settings.html#placement-for-line-layers" ) );
235void QgsLabelingGui::showDuplicateSettings()
246 auto vectorLayer = qobject_cast< QgsVectorLayer * >( mLayer );
250 auto applySettings = [=] {
251 mThinningSettings = widget->
settings();
254 emit widgetChanged();
280 , mSettings( layerSettings )
282 mGeomType = geomType;
292 , mSettings( settings )
294 mGeomType = geomType;
304 , mSettings( settings )
306 mGeomType = geomType;
324 , mSettings( settings )
331void QgsLabelingGui::init()
352 connect( mBufferDrawChkBx, &QAbstractButton::toggled,
this, &QgsLabelingGui::updateUi );
354 connect( mEnableMaskChkBx, &QAbstractButton::toggled,
this, &QgsLabelingGui::updateUi );
355 connect( mShapeDrawChkBx, &QAbstractButton::toggled,
this, &QgsLabelingGui::updateUi );
356 connect( mCalloutsDrawCheckBox, &QAbstractButton::toggled,
this, &QgsLabelingGui::updateUi );
357 connect( mShadowDrawChkBx, &QAbstractButton::toggled,
this, &QgsLabelingGui::updateUi );
358 connect( mDirectSymbChkBx, &QAbstractButton::toggled,
this, &QgsLabelingGui::updateUi );
359 connect( mFormatNumChkBx, &QAbstractButton::toggled,
this, &QgsLabelingGui::updateUi );
360 connect( mScaleBasedVisibilityChkBx, &QAbstractButton::toggled,
this, &QgsLabelingGui::updateUi );
361 connect( mFontLimitPixelChkBox, &QAbstractButton::toggled,
this, &QgsLabelingGui::updateUi );
362 connect( mGeometryGeneratorGroupBox, &QGroupBox::toggled,
this, &QgsLabelingGui::updateGeometryTypeBasedWidgets );
363 connect( mGeometryGeneratorType, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsLabelingGui::updateGeometryTypeBasedWidgets );
364 connect( mGeometryGeneratorExpressionButton, &QToolButton::clicked,
this, &QgsLabelingGui::showGeometryGeneratorExpressionBuilder );
365 connect( mGeometryGeneratorGroupBox, &QGroupBox::toggled,
this, &QgsLabelingGui::validateGeometryGeneratorExpression );
366 connect( mGeometryGenerator, &QgsCodeEditorExpression::textChanged,
this, &QgsLabelingGui::validateGeometryGeneratorExpression );
367 connect( mGeometryGeneratorType, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsLabelingGui::validateGeometryGeneratorExpression );
368 connect( mObstacleSettingsButton, &QAbstractButton::clicked,
this, &QgsLabelingGui::showObstacleSettings );
369 connect( mLineAnchorSettingsButton, &QAbstractButton::clicked,
this, &QgsLabelingGui::showLineAnchorSettings );
370 connect( mDuplicateSettingsButton, &QAbstractButton::clicked,
this, &QgsLabelingGui::showDuplicateSettings );
372 mFieldExpressionWidget->registerExpressionContextGenerator(
this );
374 mMinScaleWidget->setMapCanvas( mMapCanvas );
375 mMinScaleWidget->setShowCurrentScaleButton(
true );
376 mMaxScaleWidget->setMapCanvas( mMapCanvas );
377 mMaxScaleWidget->setShowCurrentScaleButton(
true );
379 mGeometryGeneratorExpressionButton->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
383 for (
const QString &type : calloutTypes )
388 mGeometryGeneratorWarningLabel->setStyleSheet( QStringLiteral(
"color: #FFC107;" ) );
389 mGeometryGeneratorWarningLabel->setTextInteractionFlags( Qt::TextBrowserInteraction );
390 connect( mGeometryGeneratorWarningLabel, &QLabel::linkActivated,
this, [
this](
const QString &link ) {
391 if ( link == QLatin1String(
"#determineGeometryGeneratorType" ) )
392 determineGeometryGeneratorType();
395 connect( mCalloutStyleComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLabelingGui::calloutTypeChanged );
397 mLblNoObstacle1->installEventFilter(
this );
400void QgsLabelingGui::setLayer(
QgsMapLayer *mapLayer )
413 QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( mapLayer );
415 mTextFormatsListWidget->setLayerType( vLayer ? vLayer->
geometryType() : mGeomType );
416 mBackgroundMarkerSymbolButton->setLayer( vLayer );
417 mBackgroundFillSymbolButton->setLayer( vLayer );
420 updateGeometryTypeBasedWidgets();
422 mFieldExpressionWidget->setLayer( mapLayer );
427 mFieldExpressionWidget->setGeomCalculator( da );
429 mFieldExpressionWidget->setEnabled( mMode == Labels || !mLayer );
430 mLabelingFrame->setEnabled( mMode == Labels || !mLayer );
432 blockInitSignals(
true );
434 mGeometryGenerator->setText( mSettings.geometryGenerator );
435 mGeometryGeneratorGroupBox->setChecked( mSettings.geometryGeneratorEnabled );
436 if ( !mSettings.geometryGeneratorEnabled )
437 mGeometryGeneratorGroupBox->setCollapsed(
true );
438 mGeometryGeneratorType->setCurrentIndex( mGeometryGeneratorType->findData( QVariant::fromValue( mSettings.geometryGeneratorType ) ) );
440 updateWidgetForFormat( mSettings.format().isValid() ? mSettings.format() :
QgsStyle::defaultTextFormatForProject(
QgsProject::instance(),
QgsStyle::TextFormatContext::Labeling ) );
442 mFieldExpressionWidget->setRow( -1 );
443 mFieldExpressionWidget->setField( mSettings.fieldName );
444 mCheckBoxSubstituteText->setChecked( mSettings.useSubstitutions );
445 mSubstitutions = mSettings.substitutions;
448 mCentroidRadioWhole->setChecked( mSettings.centroidWhole );
449 mCentroidInsideCheckBox->setChecked( mSettings.centroidInside );
450 mFitInsidePolygonCheckBox->setChecked( mSettings.fitInPolygonOnly );
451 mLineDistanceSpnBx->setValue( mSettings.dist );
452 mLineDistanceUnitWidget->setUnit( mSettings.distUnits );
453 mLineDistanceUnitWidget->setMapUnitScale( mSettings.distMapUnitScale );
455 mMaximumDistanceSpnBx->setValue( mSettings.pointSettings().maximumDistance() );
456 mMaximumDistanceUnitWidget->setUnit( mSettings.pointSettings().maximumDistanceUnit() );
457 mMaximumDistanceUnitWidget->setMapUnitScale( mSettings.pointSettings().maximumDistanceMapUnitScale() );
459 mOffsetTypeComboBox->setCurrentIndex( mOffsetTypeComboBox->findData(
static_cast<int>( mSettings.offsetType ) ) );
460 mQuadrantBtnGrp->button(
static_cast<int>( mSettings.pointSettings().quadrant() ) )->setChecked(
true );
461 mPointOffsetXSpinBox->setValue( mSettings.xOffset );
462 mPointOffsetYSpinBox->setValue( mSettings.yOffset );
463 mPointOffsetUnitWidget->setUnit( mSettings.offsetUnits );
464 mPointOffsetUnitWidget->setMapUnitScale( mSettings.labelOffsetMapUnitScale );
465 mPointAngleSpinBox->setValue( mSettings.angleOffset );
473 const int placementIndex = mPlacementModeComboBox->findData(
static_cast<int>( mSettings.placement ) );
474 if ( placementIndex >= 0 )
476 mPlacementModeComboBox->setCurrentIndex( placementIndex );
481 mPlacementModeComboBox->setCurrentIndex( 0 );
485 mRepeatDistanceSpinBox->setValue( mSettings.repeatDistance );
486 mRepeatDistanceUnitWidget->setUnit( mSettings.repeatDistanceUnit );
487 mRepeatDistanceUnitWidget->setMapUnitScale( mSettings.repeatDistanceMapUnitScale );
489 mOverrunDistanceSpinBox->setValue( mSettings.lineSettings().overrunDistance() );
490 mOverrunDistanceUnitWidget->setUnit( mSettings.lineSettings().overrunDistanceUnit() );
491 mOverrunDistanceUnitWidget->setMapUnitScale( mSettings.lineSettings().overrunDistanceMapUnitScale() );
493 mThinningSettings = mSettings.thinningSettings();
495 mLabelMarginSpinBox->setValue( mThinningSettings.labelMarginDistance() );
496 mLabelMarginUnitWidget->setUnit( mThinningSettings.labelMarginDistanceUnit() );
497 mLabelMarginUnitWidget->setMapUnitScale( mThinningSettings.labelMarginDistanceMapUnitScale() );
499 mPrioritySlider->setValue( mSettings.priority );
500 mChkNoObstacle->setChecked( mSettings.obstacleSettings().isObstacle() );
502 mObstacleSettings = mSettings.obstacleSettings();
504 mChkNoDuplicates->setChecked( mThinningSettings.allowDuplicateRemoval() );
506 mLineSettings = mSettings.lineSettings();
508 chkLabelPerFeaturePart->setChecked( mSettings.labelPerPart );
510 mComboOverlapHandling->setCurrentIndex( mComboOverlapHandling->findData(
static_cast<int>( mSettings.placementSettings().overlapHandling() ) ) );
511 mCheckAllowDegradedPlacement->setChecked( mSettings.placementSettings().allowDegradedPlacement() );
512 mPrioritizationComboBox->setCurrentIndex( mPrioritizationComboBox->findData( QVariant::fromValue( mSettings.placementSettings().prioritization() ) ) );
514 chkMergeLines->setChecked( mSettings.lineSettings().mergeLines() );
515 mMinSizeSpinBox->setValue( mThinningSettings.minimumFeatureSize() );
516 mLimitLabelChkBox->setChecked( mThinningSettings.limitNumberOfLabelsEnabled() );
517 mLimitLabelSpinBox->setValue( mThinningSettings.maximumNumberLabels() );
520 mDirectSymbChkBx->setChecked( mSettings.lineSettings().addDirectionSymbol() );
521 mDirectSymbLeftLineEdit->setText( mSettings.lineSettings().leftDirectionSymbol() );
522 mDirectSymbRightLineEdit->setText( mSettings.lineSettings().rightDirectionSymbol() );
523 mDirectSymbRevChkBx->setChecked( mSettings.lineSettings().reverseDirectionSymbol() );
525 mDirectSymbBtnGrp->button(
static_cast<int>( mSettings.lineSettings().directionSymbolPlacement() ) )->setChecked(
true );
526 mUpsidedownBtnGrp->button(
static_cast<int>( mSettings.upsidedownLabels ) )->setChecked(
true );
529 mMaxCharAngleInDSpinBox->setValue( mSettings.maxCurvedCharAngleIn );
531 mMaxCharAngleOutDSpinBox->setValue( std::fabs( mSettings.maxCurvedCharAngleOut ) );
533 wrapCharacterEdit->setText( mSettings.wrapChar );
534 mAutoWrapLengthSpinBox->setValue( mSettings.autoWrapLength );
535 mAutoWrapTypeComboBox->setCurrentIndex( mSettings.useMaxLineLengthForAutoWrap ? 0 : 1 );
537 if ( mFontMultiLineAlignComboBox->findData(
static_cast<int>( mSettings.multilineAlign ) ) != -1 )
539 mFontMultiLineAlignComboBox->setCurrentIndex( mFontMultiLineAlignComboBox->findData(
static_cast<int>( mSettings.multilineAlign ) ) );
545 mFontMultiLineAlignComboBox->setCurrentIndex( 0 );
548 chkPreserveRotation->setChecked( mSettings.preserveRotation );
550 mCoordRotationUnitComboBox->setCurrentIndex( 0 );
551 if ( mCoordRotationUnitComboBox->findData(
static_cast<unsigned int>( mSettings.rotationUnit() ) ) >= 0 )
552 mCoordRotationUnitComboBox->setCurrentIndex( mCoordRotationUnitComboBox->findData(
static_cast<unsigned int>( mSettings.rotationUnit() ) ) );
554 mScaleBasedVisibilityChkBx->setChecked( mSettings.scaleVisibility );
555 mMinScaleWidget->setScale( mSettings.minimumScale );
556 mMaxScaleWidget->setScale( mSettings.maximumScale );
558 mFormatNumChkBx->setChecked( mSettings.formatNumbers );
559 mFormatNumDecimalsSpnBx->setValue( mSettings.decimals );
560 mFormatNumPlusSignChkBx->setChecked( mSettings.plusSign );
564 mFontLimitPixelChkBox->setChecked( mSettings.fontLimitPixelSize );
565 mMinPixelLimit = mSettings.fontMinPixelSize;
566 mFontMinPixelSpinBox->setValue( mSettings.fontMinPixelSize == 0 ? 3 : mSettings.fontMinPixelSize );
567 mFontMaxPixelSpinBox->setValue( mSettings.fontMaxPixelSize );
569 mZIndexSpinBox->setValue( mSettings.zIndex );
571 mDataDefinedProperties = mSettings.dataDefinedProperties();
574 if (
auto *lCallout = mSettings.callout() )
576 whileBlocking( mCalloutsDrawCheckBox )->setChecked( lCallout->enabled() );
577 whileBlocking( mCalloutStyleComboBox )->setCurrentIndex( mCalloutStyleComboBox->findData( lCallout->type() ) );
578 updateCalloutWidget( lCallout );
583 whileBlocking( mCalloutStyleComboBox )->setCurrentIndex( mCalloutStyleComboBox->findData( defaultCallout->type() ) );
585 updateCalloutWidget( defaultCallout.get() );
588 updatePlacementWidgets();
589 updateLinePlacementOptions();
592 blockInitSignals(
false );
596 populateDataDefinedButtons();
603 mSettings = settings;
607void QgsLabelingGui::blockInitSignals(
bool block )
609 chkLineAbove->blockSignals( block );
610 chkLineBelow->blockSignals( block );
611 mPlacementModeComboBox->blockSignals( block );
614void QgsLabelingGui::setLabelMode( LabelMode mode )
617 mFieldExpressionWidget->setEnabled( mMode == Labels );
618 mLabelingFrame->setEnabled( mMode == Labels );
628 lyr.
drawLabels = ( mMode == Labels ) || !mLayer;
631 lyr.
fieldName = mFieldExpressionWidget->currentField( &isExpression );
637 if ( mCheckAllowLabelsOutsidePolygons->isChecked() )
644 lyr.
dist = mLineDistanceSpnBx->value();
645 lyr.
distUnits = mLineDistanceUnitWidget->unit();
653 if ( mQuadrantBtnGrp )
657 lyr.
xOffset = mPointOffsetXSpinBox->value();
658 lyr.
yOffset = mPointOffsetYSpinBox->value();
664 if ( chkLineAbove->isChecked() )
666 if ( chkLineBelow->isChecked() )
668 if ( chkLineOn->isChecked() )
670 if ( !chkLineOrientationDependent->isChecked() )
684 mThinningSettings.setLabelMarginDistance( mLabelMarginSpinBox->value() );
685 mThinningSettings.setLabelMarginDistanceUnit( mLabelMarginUnitWidget->unit() );
686 mThinningSettings.setLabelMarginDistanceMapUnitScale( mLabelMarginUnitWidget->getMapUnitScale() );
688 lyr.
priority = mPrioritySlider->value();
690 mObstacleSettings.setIsObstacle( mChkNoObstacle->isChecked() || mMode == ObstaclesOnly );
698 mThinningSettings.setAllowDuplicateRemoval( mChkNoDuplicates->isChecked() );
717 lyr.
decimals = mFormatNumDecimalsSpnBx->value();
718 lyr.
plusSign = mFormatNumPlusSignChkBx->isChecked();
725 if ( mDirectSymbBtnGrp )
729 if ( mUpsidedownBtnGrp )
738 mThinningSettings.setMinimumFeatureSize( mMinSizeSpinBox->value() );
739 mThinningSettings.setLimitNumberLabelsEnabled( mLimitLabelChkBox->isChecked() );
740 mThinningSettings.setMaximumNumberLabels( mLimitLabelSpinBox->value() );
747 lyr.
wrapChar = wrapCharacterEdit->text();
757 QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( mLayer );
760 lyr.
zIndex = mZIndexSpinBox->value();
765 const QString calloutType = mCalloutStyleComboBox->currentData().toString();
766 std::unique_ptr<QgsCallout> callout;
767 if (
QgsCalloutWidget *pew = qobject_cast<QgsCalloutWidget *>( mCalloutStackedWidget->currentWidget() ) )
769 callout.reset( pew->callout()->clone() );
774 callout->
setEnabled( mCalloutsDrawCheckBox->isChecked() );
782 f->setEnabled( chkBx->isChecked() || ddBtn->
isActive() );
785bool QgsLabelingGui::eventFilter( QObject *
object, QEvent *event )
787 if (
object == mLblNoObstacle1 )
789 if ( event->type() == QEvent::MouseButtonPress && qgis::down_cast<QMouseEvent *>( event )->button() == Qt::LeftButton )
792 mChkNoObstacle->setChecked( !mChkNoObstacle->isChecked() );
797 return QgsTextFormatWidget::eventFilter(
object, event );
800void QgsLabelingGui::updateUi()
804 syncDefinedCheckboxFrame( mBufferDrawDDBtn, mBufferDrawChkBx, mBufferFrame );
805 syncDefinedCheckboxFrame( mEnableMaskDDBtn, mEnableMaskChkBx, mMaskFrame );
806 syncDefinedCheckboxFrame( mShapeDrawDDBtn, mShapeDrawChkBx, mShapeFrame );
807 syncDefinedCheckboxFrame( mShadowDrawDDBtn, mShadowDrawChkBx, mShadowFrame );
808 syncDefinedCheckboxFrame( mCalloutDrawDDBtn, mCalloutsDrawCheckBox, mCalloutFrame );
810 syncDefinedCheckboxFrame( mDirectSymbDDBtn, mDirectSymbChkBx, mDirectSymbFrame );
811 syncDefinedCheckboxFrame( mFormatNumDDBtn, mFormatNumChkBx, mFormatNumFrame );
812 syncDefinedCheckboxFrame( mScaleBasedVisibilityDDBtn, mScaleBasedVisibilityChkBx, mScaleBasedVisibilityFrame );
813 syncDefinedCheckboxFrame( mFontLimitPixelDDBtn, mFontLimitPixelChkBox, mFontLimitPixelFrame );
815 chkMergeLines->setEnabled( !mDirectSymbChkBx->isChecked() );
816 if ( mDirectSymbChkBx->isChecked() )
818 chkMergeLines->setToolTip( tr(
"This option is not compatible with line direction symbols." ) );
822 chkMergeLines->setToolTip( QString() );
826void QgsLabelingGui::setFormatFromStyle(
const QString &name,
QgsStyle::StyleEntity type,
const QString &stylePath )
857 settings.
fieldName = mFieldExpressionWidget->currentField( &isExpression );
860 setSettings( settings );
868 if (
QgsCalloutWidget *cw = qobject_cast<QgsCalloutWidget *>( mCalloutStackedWidget->currentWidget() ) )
870 cw->setContext( context );
875void QgsLabelingGui::saveFormat()
878 saveDlg.setDefaultTags( mTextFormatsListWidget->currentTagFilter() );
879 if ( !saveDlg.exec() )
882 if ( saveDlg.name().isEmpty() )
885 QgsStyle *style = saveDlg.destinationStyle();
889 switch ( saveDlg.selectedType() )
896 const int res = QMessageBox::warning(
this, tr(
"Save Text Format" ), tr(
"Format with name '%1' already exists. Overwrite?" ).arg( saveDlg.name() ), QMessageBox::Yes | QMessageBox::No );
897 if ( res != QMessageBox::Yes )
903 const QStringList symbolTags = saveDlg.tags().split(
',' );
907 style->
saveTextFormat( saveDlg.name(), newFormat, saveDlg.isFavorite(), symbolTags );
916 const int res = QMessageBox::warning(
this, tr(
"Save Label Settings" ), tr(
"Label settings with the name '%1' already exist. Overwrite?" ).arg( saveDlg.name() ), QMessageBox::Yes | QMessageBox::No );
917 if ( res != QMessageBox::Yes )
923 const QStringList symbolTags = saveDlg.tags().split(
',' );
927 style->
saveLabelSettings( saveDlg.name(), newSettings, saveDlg.isFavorite(), symbolTags );
941void QgsLabelingGui::updateGeometryTypeBasedWidgets()
945 QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( mLayer );
947 if ( mGeometryGeneratorGroupBox->isChecked() )
960 mPlacementModeComboBox->clear();
962 switch ( geometryType )
989 qFatal(
"unknown geometry type unexpected" );
992 if ( mPlacementModeComboBox->findData(
static_cast<int>( prevPlacement ) ) != -1 )
994 mPlacementModeComboBox->setCurrentIndex( mPlacementModeComboBox->findData(
static_cast<int>( prevPlacement ) ) );
1007 mFontMultiLineAlignComboBox->removeItem( idx );
1010 updatePlacementWidgets();
1011 updateLinePlacementOptions();
1014void QgsLabelingGui::showGeometryGeneratorExpressionBuilder()
1016 QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( mLayer );
1019 expressionBuilder.setExpressionText( mGeometryGenerator->text() );
1020 expressionBuilder.setExpressionContext( createExpressionContext() );
1022 if ( expressionBuilder.exec() )
1024 mGeometryGenerator->setText( expressionBuilder.expressionText() );
1028void QgsLabelingGui::validateGeometryGeneratorExpression()
1032 QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( mLayer );
1034 if ( mGeometryGeneratorGroupBox->isChecked() )
1036 if ( !mPreviewFeature.isValid() && vLayer )
1043 expression.prepare( &context );
1045 if ( expression.hasParserError() )
1047 mGeometryGeneratorWarningLabel->setText( expression.parserErrorString() );
1052 const QVariant result = expression.evaluate( &context );
1057 mGeometryGeneratorWarningLabel->setText( tr(
"Result of the expression is not a geometry" ) );
1060 else if ( geometry.
type() != configuredGeometryType )
1062 mGeometryGeneratorWarningLabel->setText( QStringLiteral(
"<p>%1</p><p><a href=\"#determineGeometryGeneratorType\">%2</a></p>" ).arg( tr(
"Result of the expression does not match configured geometry type." ), tr(
"Change to %1" ).arg(
QgsWkbTypes::geometryDisplayString( geometry.
type() ) ) ) );
1070 QTimer *timer =
new QTimer();
1071 connect( timer, &QTimer::timeout,
this, [
this, valid]() {
1072 mGeometryGeneratorWarningLabel->setVisible( !valid );
1074 connect( timer, &QTimer::timeout, timer, &QTimer::deleteLater );
1078void QgsLabelingGui::determineGeometryGeneratorType()
1080 QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( mLayer );
1081 if ( !mPreviewFeature.isValid() && vLayer )
1088 expression.prepare( &context );
1091 mGeometryGeneratorType->setCurrentIndex( mGeometryGeneratorType->findData( QVariant::fromValue( geometry.
type() ) ) );
1094void QgsLabelingGui::calloutTypeChanged()
1096 const QString newCalloutType = mCalloutStyleComboBox->currentData().toString();
1097 QgsCalloutWidget *pew = qobject_cast<QgsCalloutWidget *>( mCalloutStackedWidget->currentWidget() );
1116 updateCalloutWidget( newCallout.get() );
1128 QVBoxLayout *vLayout =
new QVBoxLayout();
1129 mWidget =
new QgsLabelingGui( layer, mapCanvas, settings,
nullptr, geomType );
1130 vLayout->addWidget( mWidget );
1131 mButtonBox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok, Qt::Horizontal );
1132 connect( mButtonBox, &QDialogButtonBox::accepted,
this, &QDialog::accept );
1133 connect( mButtonBox, &QDialogButtonBox::rejected,
this, &QDialog::reject );
1134 connect( mButtonBox, &QDialogButtonBox::helpRequested,
this, &QgsLabelSettingsDialog::showHelp );
1135 vLayout->addWidget( mButtonBox );
1136 setLayout( vLayout );
1137 setWindowTitle( tr(
"Label Settings" ) );
1140QDialogButtonBox *QgsLabelSettingsDialog::buttonBox()
const
1145void QgsLabelSettingsDialog::showHelp()
Provides global constants and enumerations for use throughout the application.
@ BelowLine
Labels can be placed below a line feature. Unless MapOrientation is also specified this mode respects...
@ MapOrientation
Signifies that the AboveLine and BelowLine flags should respect the map's orientation rather than the...
@ OnLine
Labels can be placed directly over a line feature.
@ AboveLine
Labels can be placed above a line feature. Unless MapOrientation is also specified this mode respects...
AngleUnit
Units of angles.
@ SecondsOfArc
Seconds of arc.
@ Radians
Square kilometers.
@ MinutesOfArc
Minutes of arc.
@ MilliradiansSI
Angular milliradians (SI definition, 1/1000 of radian)
@ MilNATO
Angular mil (NATO definition, 6400 mil = 2PI radians)
LabelOffsetType
Behavior modifier for label offset and distance, only applies in some label placement modes.
LabelPrioritization
Label prioritization.
LabelPlacement
Placement modes which determine how label candidates are generated for a feature.
@ OverPoint
Arranges candidates over a point (or centroid of a polygon), or at a preset offset from the point....
@ Curved
Arranges candidates following the curvature of a line feature. Applies to line layers only.
@ 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'...
@ Free
Arranges candidates scattered throughout a polygon feature. Candidates are rotated to respect the pol...
@ OrderedPositionsAroundPoint
Candidates are placed in predefined positions around a point. Preference is given to positions with g...
@ Horizontal
Arranges horizontal candidates scattered throughout a polygon feature. Applies to polygon layers only...
@ PerimeterCurved
Arranges candidates following the curvature of a polygon's boundary. Applies to polygon layers only.
@ OutsidePolygons
Candidates are placed outside of polygon boundaries. Applies to polygon layers only.
@ AllowPlacementInsideOfPolygon
Labels can be placed inside a polygon feature.
@ AllowPlacementOutsideOfPolygon
Labels can be placed outside of a polygon feature.
QFlags< LabelLinePlacementFlag > LabelLinePlacementFlags
Line placement flags, which control how candidates are generated for a linear feature.
QFlags< LabelPolygonPlacementFlag > LabelPolygonPlacementFlags
Polygon placement flags, which control how candidates are generated for a polygon feature.
LabelQuadrantPosition
Label quadrant positions.
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
LabelMultiLineAlignment
Text alignment for multi-line labels.
@ FollowPlacement
Alignment follows placement of label, e.g., labels to the left of a feature will be drawn with right ...
@ Mesh
Mesh layer. Added in QGIS 3.2.
LabelOverlapHandling
Label overlap handling.
UpsideDownLabelHandling
Handling techniques for upside down labels.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
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.
static QgsCallout * defaultCallout()
Create a new instance of a callout with default settings.
QStringList calloutTypes() const
Returns a list of all available callout types.
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 * meshExpressionScope(QgsMesh::ElementType elementType)
Creates a new scope which contains functions relating to mesh layer element elementType.
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.
Handles parsing and evaluation of expressions (formerly called "search strings").
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
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.
static void initCalloutWidgets()
Initializes callout widgets.
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(Qgis::LabelLinePlacementFlags 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 setAnchorTextPoint(AnchorTextPoint point)
Sets the line anchor text point, which dictates which part of the label text should be placed at the ...
void setLeftDirectionSymbol(const QString &symbol)
Sets the string to use for left direction arrows.
AnchorTextPoint anchorTextPoint() const
Returns the line anchor text point, which dictates which part of the label text should be placed at t...
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 setOverrunDistanceUnit(const Qgis::RenderUnit &unit)
Sets the unit for label overrun distance.
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 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 setOverlapHandling(Qgis::LabelOverlapHandling handling)
Sets the technique used to handle overlapping labels.
void setPrioritization(Qgis::LabelPrioritization prioritization)
Sets the technique used to prioritize labels.
void setAllowDegradedPlacement(bool allow)
Sets whether labels can be placed in inferior fallback positions if they cannot otherwise be placed.
void setMaximumDistance(double distance)
Sets the maximum distance which labels are allowed to be from their corresponding points.
void setMaximumDistanceMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for label maximum distance.
void setQuadrant(Qgis::LabelQuadrantPosition quadrant)
Sets the quadrant in which to offset labels from the point.
void setMaximumDistanceUnit(Qgis::RenderUnit unit)
Sets the unit for label maximum distance.
Map canvas is a class for displaying all GIS data types on a canvas.
Base class for all map layer types.
Represents a mesh layer supporting display of data on structured or unstructured meshes.
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.
const QgsLabelPlacementSettings & placementSettings() const
Returns the label placement 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...
void setPolygonPlacementFlags(Qgis::LabelPolygonPlacementFlags flags)
Sets the polygon placement flags, which dictate how polygon labels can be placed.
QString wrapChar
Wrapping character string.
Qgis::LabelOffsetType offsetType
Offset type for layer (only applies in certain placement modes)
double xOffset
Horizontal offset of label.
Qgis::LabelPlacement placement
Label placement mode.
bool drawLabels
Whether to draw labels for this layer.
bool fontLimitPixelSize
true if label sizes should be limited by pixel size.
double minimumScale
The minimum map scale (i.e.
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...
Qgis::LabelMultiLineAlignment multilineAlign
Horizontal alignment of multi-line labels.
bool centroidInside
true if centroid positioned labels must be placed inside their corresponding feature polygon,...
int priority
Label priority.
Qgis::GeometryType geometryGeneratorType
The type of the result geometry of the geometry generator.
bool labelPerPart
true if every part of a multi-part feature should be labeled.
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)
Qgis::GeometryType layerType
Geometry type of layers associated with these settings.
void setThinningSettings(const QgsLabelThinningSettings &settings)
Sets the label thinning settings.
Qgis::RenderUnit offsetUnits
Units for offsets of label.
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.
const QgsLabelLineSettings & lineSettings() const
Returns the label line settings, which contain settings related to how the label engine places and fo...
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.
void setRotationUnit(Qgis::AngleUnit angleUnit)
Set unit for rotation of labels.
QgsMapUnitScale repeatDistanceMapUnitScale
Map unit scale for repeating labels for a single feature.
Qgis::RenderUnit distUnits
Units the distance from feature to the label.
bool centroidWhole
true if feature centroid should be calculated from the whole feature, or false if only the visible pa...
Qgis::RenderUnit repeatDistanceUnit
Units for repeating labels for a single feature.
Qgis::UpsideDownLabelHandling 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.
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 QgsLabelPointSettings & pointSettings() const
Returns the label point settings, which contain settings related to how the label engine places and f...
bool useSubstitutions
True if substitutions should be applied.
QgsStyle * styleAtPath(const QString &path)
Returns a reference to the style database associated with the project with matching file path.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
static QgsProject * instance()
Returns the QgsProject singleton instance.
const QgsProjectStyleSettings * styleSettings() const
Returns the project's style settings, which contains settings and properties relating to how a QgsPro...
QgsCoordinateTransformContext transformContext
A grouped map of multiple QgsProperty objects, each referenced by an integer key value.
A container for the context for various read/write operations on objects.
A dialog for setting properties of a newly saved style.
A database of saved style entities, including symbols, color ramps, text formats and others.
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.
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
@ ColorrampEntity
Color ramps.
@ LegendPatchShapeEntity
Legend patch shape.
static QgsStyle * defaultStyle(bool initialize=true)
Returns the 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.
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 setContext(const QgsSymbolWidgetContext &context)
Sets the context in which the widget is shown, e.g., the associated map canvas and expression context...
virtual void setFormatFromStyle(const QString &name, QgsStyle::StyleEntity type, const QString &stylePath)
Sets the current text settings from a style entry.
Container for all settings relating to text rendering.
static Q_INVOKABLE QString toString(Qgis::DistanceUnit unit)
Returns a translated string representing a distance unit.
Represents a vector layer which manages a vector based dataset.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
Q_INVOKABLE Qgis::GeometryType geometryType() const
Returns point, line or polygon.
Implements a map layer that is dedicated to rendering of vector tiles.
static QString geometryDisplayString(Qgis::GeometryType type)
Returns a display string for a geometry type.
@ Unknown
Unknown/invalid format.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.