46#include <QStyledItemDelegate>
47#include <QRandomGenerator>
63 , mMapCanvas( canvas )
82 mDiagramOptionsListWidget->setAttribute( Qt::WA_MacShowFocusRect,
false );
84 mBarSpacingSpinBox->setClearValue( 0 );
85 mBarSpacingUnitComboBox->setUnits( { Qgis::RenderUnit::Millimeters,
86 Qgis::RenderUnit::MetersInMapUnits,
87 Qgis::RenderUnit::MapUnits,
88 Qgis::RenderUnit::Pixels,
89 Qgis::RenderUnit::Points,
90 Qgis::RenderUnit::Inches } );
94 mDiagramTypeComboBox->blockSignals(
true );
96 mDiagramTypeComboBox->addItem( icon, tr(
"No Diagrams" ),
"None" );
105 mDiagramTypeComboBox->blockSignals(
false );
108 mAxisLineStyleButton->setDialogTitle( tr(
"Axis Line Symbol" ) );
110 mScaleRangeWidget->setMapCanvas( mMapCanvas );
111 mSizeFieldExpressionWidget->registerExpressionContextGenerator(
this );
113 mBackgroundColorButton->setColorDialogTitle( tr(
"Select Background Color" ) );
114 mBackgroundColorButton->setAllowOpacity(
true );
115 mBackgroundColorButton->setContext( QStringLiteral(
"symbology" ) );
116 mBackgroundColorButton->setShowNoColor(
true );
117 mBackgroundColorButton->setNoColorString( tr(
"Transparent Background" ) );
118 mDiagramPenColorButton->setColorDialogTitle( tr(
"Select Pen Color" ) );
119 mDiagramPenColorButton->setAllowOpacity(
true );
120 mDiagramPenColorButton->setContext( QStringLiteral(
"symbology" ) );
121 mDiagramPenColorButton->setShowNoColor(
true );
122 mDiagramPenColorButton->setNoColorString( tr(
"Transparent Stroke" ) );
124 mMaxValueSpinBox->setShowClearButton(
false );
125 mSizeSpinBox->setClearValue( 5 );
127 mDiagramAttributesTreeWidget->setItemDelegateForColumn( ColumnAttributeExpression,
new EditBlockerDelegate(
this ) );
128 mDiagramAttributesTreeWidget->setItemDelegateForColumn( ColumnColor,
new QgsColorSwatchDelegate(
this ) );
130 mDiagramAttributesTreeWidget->setColumnWidth( ColumnColor,
Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance(
'X' ) * 6.6 );
135 mDiagramUnitComboBox->setUnits( {Qgis::RenderUnit::Millimeters,
136 Qgis::RenderUnit::MapUnits,
137 Qgis::RenderUnit::Pixels,
138 Qgis::RenderUnit::Points,
139 Qgis::RenderUnit::Inches } );
140 mDiagramLineUnitComboBox->setUnits( { Qgis::RenderUnit::Millimeters,
141 Qgis::RenderUnit::MapUnits,
142 Qgis::RenderUnit::Pixels,
143 Qgis::RenderUnit::Points,
144 Qgis::RenderUnit::Inches } );
147 if ( layerType == Qgis::GeometryType::Unknown || layerType == Qgis::GeometryType::Null )
149 mDiagramTypeComboBox->setEnabled(
false );
150 mDiagramFrame->setEnabled(
false );
157 case Qgis::GeometryType::Point:
158 stackedPlacement->setCurrentWidget( pagePoint );
159 mLinePlacementFrame->setVisible(
false );
161 case Qgis::GeometryType::Line:
162 stackedPlacement->setCurrentWidget( pageLine );
163 mLinePlacementFrame->setVisible(
true );
165 case Qgis::GeometryType::Polygon:
166 stackedPlacement->setCurrentWidget( pagePolygon );
167 mLinePlacementFrame->setVisible(
false );
169 case Qgis::GeometryType::Null:
170 case Qgis::GeometryType::Unknown:
176 mPlacePointBtnGrp =
new QButtonGroup(
this );
177 mPlacePointBtnGrp->addButton( radAroundPoint );
178 mPlacePointBtnGrp->addButton( radOverPoint );
179 mPlacePointBtnGrp->setExclusive(
true );
183 mPlaceLineBtnGrp =
new QButtonGroup(
this );
184 mPlaceLineBtnGrp->addButton( radAroundLine );
185 mPlaceLineBtnGrp->addButton( radOverLine );
186 mPlaceLineBtnGrp->setExclusive(
true );
190 mPlacePolygonBtnGrp =
new QButtonGroup(
this );
191 mPlacePolygonBtnGrp->addButton( radAroundCentroid );
192 mPlacePolygonBtnGrp->addButton( radOverCentroid );
193 mPlacePolygonBtnGrp->addButton( radPolygonPerimeter );
194 mPlacePolygonBtnGrp->addButton( radInsidePolygon );
195 mPlacePolygonBtnGrp->setExclusive(
true );
201 mScaleDependencyComboBox->addItem( tr(
"Area" ),
true );
202 mScaleDependencyComboBox->addItem( tr(
"Diameter" ),
false );
204 mAngleOffsetComboBox->addItem( tr(
"Top" ), 270 );
205 mAngleOffsetComboBox->addItem( tr(
"Right" ), 0 );
206 mAngleOffsetComboBox->addItem( tr(
"Bottom" ), 90 );
207 mAngleOffsetComboBox->addItem( tr(
"Left" ), 180 );
215 QSizePolicy policy( mDiagramOptionsListFrame->sizePolicy() );
216 policy.setHorizontalStretch( 0 );
217 mDiagramOptionsListFrame->setSizePolicy( policy );
218 if ( !settings.
contains( QStringLiteral(
"/Windows/Diagrams/OptionsSplitState" ) ) )
221 QList<int> splitsizes;
223 mDiagramOptionsSplitter->setSizes( splitsizes );
227 mDiagramOptionsSplitter->restoreState( settings.
value( QStringLiteral(
"Windows/Diagrams/OptionsSplitState" ) ).toByteArray() );
228 mDiagramOptionsListWidget->setCurrentRow( settings.
value( QStringLiteral(
"Windows/Diagrams/Tab" ), 0 ).toInt() );
231 mSizeFieldExpressionWidget->setLayer( mLayer );
235 mSizeFieldExpressionWidget->setGeomCalculator( myDa );
239 for (
int idx = 0; idx < layerFields.
count(); ++idx )
241 QTreeWidgetItem *newItem =
new QTreeWidgetItem( mAttributesTreeWidget );
242 const QString name = QStringLiteral(
"\"%1\"" ).arg( layerFields.
at( idx ).
name() );
243 newItem->setText( 0, name );
244 newItem->setData( 0, RoleAttributeExpression, name );
245 newItem->setFlags( newItem->flags() & ~Qt::ItemIsDropEnabled );
249 mPaintEffect->setEnabled(
false );
272 mDiagramAttributesTreeWidget->clear();
277 mDiagramTypeComboBox->blockSignals(
true );
278 mDiagramTypeComboBox->setCurrentIndex( 0 );
279 mDiagramTypeComboBox->blockSignals(
false );
280 mFixedSizeRadio->setChecked(
true );
281 mDiagramUnitComboBox->setUnit( Qgis::RenderUnit::Millimeters );
282 mDiagramLineUnitComboBox->setUnit( Qgis::RenderUnit::Millimeters );
283 mLabelPlacementComboBox->setCurrentIndex( mLabelPlacementComboBox->findText( tr(
"x-height" ) ) );
284 mDiagramSizeSpinBox->setEnabled(
true );
285 mDiagramSizeSpinBox->setValue( 15 );
286 mLinearScaleFrame->setEnabled(
false );
287 mIncreaseMinimumSizeSpinBox->setEnabled(
false );
288 mIncreaseMinimumSizeLabel->setEnabled(
false );
289 mBarWidthSpinBox->setValue( 5 );
292 mShowAllCheckBox->setChecked(
true );
293 mCheckBoxAttributeLegend->setChecked(
true );
297 case Qgis::GeometryType::Point:
298 radAroundPoint->setChecked(
true );
301 case Qgis::GeometryType::Line:
302 radAroundLine->setChecked(
true );
303 chkLineAbove->setChecked(
true );
304 chkLineBelow->setChecked(
false );
305 chkLineOn->setChecked(
false );
306 chkLineOrientationDependent->setChecked(
false );
309 case Qgis::GeometryType::Polygon:
310 radOverCentroid->setChecked(
true );
311 mDiagramDistanceLabel->setEnabled(
false );
312 mDiagramDistanceSpinBox->setEnabled(
false );
313 mDistanceDDBtn->setEnabled(
false );
316 case Qgis::GeometryType::Unknown:
317 case Qgis::GeometryType::Null:
320 mBackgroundColorButton->setColor( QColor( 255, 255, 255, 255 ) );
328 if ( dr->
rendererName() == QLatin1String(
"SingleCategory" ) )
330 mFixedSizeRadio->setChecked(
true );
334 mAttributeBasedScalingRadio->setChecked(
true );
336 mDiagramSizeSpinBox->setEnabled( mFixedSizeRadio->isChecked() );
337 mLinearScaleFrame->setEnabled( mAttributeBasedScalingRadio->isChecked() );
342 if ( !settingList.isEmpty() )
344 mDiagramFrame->setEnabled( settingList.at( 0 ).enabled );
345 mDiagramFontButton->setCurrentFont( settingList.at( 0 ).font );
346 const QSizeF size = settingList.at( 0 ).size;
347 mBackgroundColorButton->setColor( settingList.at( 0 ).backgroundColor );
348 mOpacityWidget->setOpacity( settingList.at( 0 ).opacity );
349 mDiagramPenColorButton->setColor( settingList.at( 0 ).penColor );
350 mPenWidthSpinBox->setValue( settingList.at( 0 ).penWidth );
351 mDiagramSizeSpinBox->setValue( ( size.width() + size.height() ) / 2.0 );
352 mScaleRangeWidget->setScaleRange( ( settingList.at( 0 ).minimumScale > 0 ? settingList.at( 0 ).minimumScale : mLayer->
minimumScale() ),
353 ( settingList.at( 0 ).maximumScale > 0 ? settingList.at( 0 ).maximumScale : mLayer->
maximumScale() ) );
354 mScaleVisibilityGroupBox->setChecked( settingList.at( 0 ).scaleBasedVisibility );
355 mDiagramUnitComboBox->setUnit( settingList.at( 0 ).sizeType );
356 mDiagramUnitComboBox->setMapUnitScale( settingList.at( 0 ).sizeScale );
357 mDiagramLineUnitComboBox->setUnit( settingList.at( 0 ).lineSizeUnit );
358 mDiagramLineUnitComboBox->setMapUnitScale( settingList.at( 0 ).lineSizeScale );
362 mLabelPlacementComboBox->setCurrentIndex( 0 );
366 mLabelPlacementComboBox->setCurrentIndex( 1 );
369 if ( settingList.at( 0 ).paintEffect() )
370 mPaintEffect.reset( settingList.at( 0 ).paintEffect()->clone() );
372 mAngleOffsetComboBox->setCurrentIndex( mAngleOffsetComboBox->findData( settingList.at( 0 ).rotationOffset ) );
373 mAngleDirectionComboBox->setCurrentIndex( mAngleDirectionComboBox->findData( settingList.at( 0 ).direction() ) );
379 switch ( settingList.at( 0 ).diagramOrientation )
382 mOrientationLeftButton->setChecked(
true );
386 mOrientationRightButton->setChecked(
true );
390 mOrientationUpButton->setChecked(
true );
394 mOrientationDownButton->setChecked(
true );
398 mBarWidthSpinBox->setValue( settingList.at( 0 ).barWidth );
399 mBarSpacingSpinBox->setValue( settingList.at( 0 ).spacing() );
400 mBarSpacingUnitComboBox->setUnit( settingList.at( 0 ).spacingUnit() );
401 mBarSpacingUnitComboBox->setMapUnitScale( settingList.at( 0 ).spacingMapUnitScale() );
403 mShowAxisGroupBox->setChecked( settingList.at( 0 ).showAxis() );
404 if ( settingList.at( 0 ).axisLineSymbol() )
405 mAxisLineStyleButton->setSymbol( settingList.at( 0 ).axisLineSymbol()->clone() );
407 mIncreaseSmallDiagramsCheck->setChecked( settingList.at( 0 ).minimumSize != 0 );
408 mIncreaseMinimumSizeSpinBox->setEnabled( mIncreaseSmallDiagramsCheck->isChecked() );
409 mIncreaseMinimumSizeLabel->setEnabled( mIncreaseSmallDiagramsCheck->isChecked() );
411 mIncreaseMinimumSizeSpinBox->setValue( settingList.at( 0 ).minimumSize );
413 if ( settingList.at( 0 ).scaleByArea )
415 mScaleDependencyComboBox->setCurrentIndex( 0 );
419 mScaleDependencyComboBox->setCurrentIndex( 1 );
422 const QList< QColor > categoryColors = settingList.at( 0 ).categoryColors;
423 const QList< QString > categoryAttributes = settingList.at( 0 ).categoryAttributes;
424 const QList< QString > categoryLabels = settingList.at( 0 ).categoryLabels;
425 QList< QString >::const_iterator catIt = categoryAttributes.constBegin();
426 QList< QColor >::const_iterator coIt = categoryColors.constBegin();
427 QList< QString >::const_iterator labIt = categoryLabels.constBegin();
428 for ( ; catIt != categoryAttributes.constEnd(); ++catIt, ++coIt, ++labIt )
430 QTreeWidgetItem *newItem =
new QTreeWidgetItem( mDiagramAttributesTreeWidget );
431 newItem->setText( 0, *catIt );
432 newItem->setData( 0, RoleAttributeExpression, *catIt );
433 newItem->setFlags( newItem->flags() & ~Qt::ItemIsDropEnabled );
434 newItem->setData( ColumnColor, Qt::EditRole, *coIt );
435 newItem->setText( 2, *labIt );
436 newItem->setFlags( newItem->flags() | Qt::ItemIsEditable );
440 if ( dr->
rendererName() == QLatin1String(
"LinearlyInterpolated" ) )
445 mDiagramSizeSpinBox->setEnabled(
false );
446 mLinearScaleFrame->setEnabled(
true );
447 mMaxValueSpinBox->setValue( lidr->
upperValue() );
448 mSizeSpinBox->setValue( ( lidr->
upperSize().width() + lidr->
upperSize().height() ) / 2 );
465 mDiagramDistanceSpinBox->setValue( dls->
distance() );
466 mPrioritySlider->setValue( dls->
priority() );
467 mZIndexSpinBox->setValue( dls->
zIndex() );
472 radAroundPoint->setChecked(
true );
473 radAroundCentroid->setChecked(
true );
477 radOverPoint->setChecked(
true );
478 radOverCentroid->setChecked(
true );
482 radAroundLine->setChecked(
true );
483 radPolygonPerimeter->setChecked(
true );
487 radOverLine->setChecked(
true );
488 radInsidePolygon->setChecked(
true );
499 chkLineOrientationDependent->setChecked(
true );
511 mDiagramTypeComboBox->blockSignals(
true );
512 mDiagramTypeComboBox->setCurrentIndex( settingList.at( 0 ).enabled ? mDiagramTypeComboBox->findData( mDiagramType ) : 0 );
513 mDiagramTypeComboBox->blockSignals(
false );
516 if ( mDiagramTypeComboBox->currentIndex() == -1 )
518 QMessageBox::warning(
this, tr(
"Diagram Properties" ),
519 tr(
"The diagram type '%1' is unknown. A default type is selected for you." ).arg( mDiagramType ), QMessageBox::Ok );
520 mDiagramTypeComboBox->setCurrentIndex( mDiagramTypeComboBox->findData(
DIAGRAM_NAME_PIE ) );
524 mPaintEffectWidget->setPaintEffect( mPaintEffect.get() );
530 settings.
setValue( QStringLiteral(
"Windows/Diagrams/OptionsSplitState" ), mDiagramOptionsSplitter->saveState() );
531 settings.
setValue( QStringLiteral(
"Windows/Diagrams/Tab" ), mDiagramOptionsListWidget->currentRow() );
542void QgsDiagramProperties::updateProperty()
553 mDiagramFrame->setEnabled(
false );
557 mDiagramFrame->setEnabled(
true );
559 mDiagramType = mDiagramTypeComboBox->itemData( index ).toString();
563 mTextOptionsFrame->show();
564 mBackgroundColorLabel->show();
565 mBackgroundColorButton->show();
566 mBackgroundColorDDBtn->show();
567 mDiagramFontButton->show();
571 mTextOptionsFrame->hide();
572 mBackgroundColorLabel->hide();
573 mBackgroundColorButton->hide();
574 mBackgroundColorDDBtn->hide();
575 mDiagramFontButton->hide();
580 mBarWidthLabel->show();
581 mBarWidthSpinBox->show();
582 mBarSpacingLabel->show();
583 mBarSpacingSpinBox->show();
584 mBarSpacingUnitComboBox->show();
585 mBarOptionsFrame->show();
586 mShowAxisGroupBox->show();
588 mAttributeBasedScalingRadio->setChecked(
true );
591 mLinearlyScalingLabel->setText( tr(
"Bar length: Scale linearly, so that the following value matches the specified bar length:" ) );
592 mSizeLabel->setText( tr(
"Bar length" ) );
593 mFrameIncreaseSize->setVisible(
false );
597 mBarWidthLabel->hide();
598 mBarWidthSpinBox->hide();
599 mBarSpacingLabel->hide();
600 mBarSpacingSpinBox->hide();
601 mBarSpacingUnitComboBox->hide();
602 mShowAxisGroupBox->hide();
603 mBarOptionsFrame->hide();
604 mLinearlyScalingLabel->setText( tr(
"Scale linearly between 0 and the following attribute value / diagram size:" ) );
605 mSizeLabel->setText( tr(
"Size" ) );
606 mAttributeBasedScalingRadio->setEnabled(
true );
607 mFixedSizeRadio->setEnabled(
true );
608 mDiagramSizeSpinBox->setEnabled( mFixedSizeRadio->isChecked() );
609 mFrameIncreaseSize->setVisible(
true );
614 mScaleDependencyComboBox->show();
615 mScaleDependencyLabel->show();
619 mScaleDependencyComboBox->hide();
620 mScaleDependencyLabel->hide();
625 mAngleOffsetComboBox->show();
626 mAngleDirectionComboBox->show();
627 mAngleDirectionLabel->show();
628 mAngleOffsetLabel->show();
629 mStartAngleDDBtn->show();
633 mAngleOffsetComboBox->hide();
634 mAngleDirectionComboBox->hide();
635 mAngleDirectionLabel->hide();
636 mAngleOffsetLabel->hide();
637 mStartAngleDDBtn->hide();
641QString QgsDiagramProperties::guessLegendText(
const QString &expression )
644 QString text = expression.mid( expression.startsWith(
'\"' ) ? 1 : 0 );
645 if ( text.endsWith(
'\"' ) )
652 QTreeWidgetItem *newItem =
new QTreeWidgetItem( mDiagramAttributesTreeWidget );
654 newItem->setText( 0, item->text( 0 ) );
655 newItem->setText( 2, guessLegendText( item->text( 0 ) ) );
656 newItem->setData( 0, RoleAttributeExpression, item->data( 0, RoleAttributeExpression ) );
657 newItem->setFlags( ( newItem->flags() | Qt::ItemIsEditable ) & ~Qt::ItemIsDropEnabled );
660 QRandomGenerator colorGenerator;
661 const int red = colorGenerator.bounded( 1, 256 );
662 const int green = colorGenerator.bounded( 1, 256 );
663 const int blue = colorGenerator.bounded( 1, 256 );
664 const QColor randomColor( red, green, blue );
665 newItem->setData( ColumnColor, Qt::EditRole, randomColor );
666 mDiagramAttributesTreeWidget->addTopLevelItem( newItem );
671 const auto constSelectedItems = mAttributesTreeWidget->selectedItems();
672 for ( QTreeWidgetItem *attributeItem : constSelectedItems )
686 const auto constSelectedItems = mDiagramAttributesTreeWidget->selectedItems();
687 for ( QTreeWidgetItem *attributeItem : constSelectedItems )
689 delete attributeItem;
698 float maxValue = 0.0;
701 const QString sizeFieldNameOrExp = mSizeFieldExpressionWidget->currentField( &isExpression );
719 maxValue = std::max( maxValue, exp.
evaluate( &context ).toFloat() );
730 maxValue = mLayer->
maximumValue( attributeNumber ).toFloat();
733 mMaxValueSpinBox->setValue( maxValue );
740 case ColumnAttributeExpression:
742 const QString currentExpression = item->data( 0, RoleAttributeExpression ).toString();
744 const QString newExpression = showExpressionBuilder( currentExpression );
745 if ( !newExpression.isEmpty() )
747 item->setData( 0, Qt::DisplayRole, newExpression );
748 item->setData( 0, RoleAttributeExpression, newExpression );
756 case ColumnLegendText:
781 const int index = mDiagramTypeComboBox->currentIndex();
782 const bool diagramsEnabled = ( index != 0 );
784 std::unique_ptr< QgsDiagram > diagram;
786 if ( diagramsEnabled && 0 == mDiagramAttributesTreeWidget->topLevelItemCount() )
788 QMessageBox::warning(
this, tr(
"Diagrams: No attributes added." ),
789 tr(
"You did not add any attributes to this diagram layer. Please specify the attributes to visualize on the diagrams or disable diagrams." ) );
794 diagram = std::make_unique< QgsTextDiagram >();
798 diagram = std::make_unique< QgsPieDiagram >();
802 diagram = std::make_unique< QgsStackedBarDiagram >();
806 diagram = std::make_unique< QgsHistogramDiagram >();
810 ds.
enabled = ( mDiagramTypeComboBox->currentIndex() != 0 );
811 ds.
font = mDiagramFontButton->currentFont();
812 ds.
opacity = mOpacityWidget->opacity();
814 QList<QColor> categoryColors;
815 QList<QString> categoryAttributes;
816 QList<QString> categoryLabels;
817 categoryColors.reserve( mDiagramAttributesTreeWidget->topLevelItemCount() );
818 categoryAttributes.reserve( mDiagramAttributesTreeWidget->topLevelItemCount() );
819 categoryLabels.reserve( mDiagramAttributesTreeWidget->topLevelItemCount() );
820 for (
int i = 0; i < mDiagramAttributesTreeWidget->topLevelItemCount(); ++i )
822 QColor color = mDiagramAttributesTreeWidget->topLevelItem( i )->data( ColumnColor, Qt::EditRole ).value<QColor>();
823 categoryColors.append( color );
824 categoryAttributes.append( mDiagramAttributesTreeWidget->topLevelItem( i )->data( 0, RoleAttributeExpression ).toString() );
825 categoryLabels.append( mDiagramAttributesTreeWidget->topLevelItem( i )->text( 2 ) );
830 ds.
size = QSizeF( mDiagramSizeSpinBox->value(), mDiagramSizeSpinBox->value() );
831 ds.
sizeType = mDiagramUnitComboBox->unit();
832 ds.
sizeScale = mDiagramUnitComboBox->getMapUnitScale();
834 ds.
lineSizeScale = mDiagramLineUnitComboBox->getMapUnitScale();
838 if ( mIncreaseSmallDiagramsCheck->isChecked() )
840 ds.
minimumSize = mIncreaseMinimumSizeSpinBox->value();
848 ds.
penColor = mDiagramPenColorButton->color();
849 ds.
penWidth = mPenWidthSpinBox->value();
861 ds.
barWidth = mBarWidthSpinBox->value();
876 if ( mFixedSizeRadio->isChecked() )
888 dr->
setUpperSize( QSizeF( mSizeSpinBox->value(), mSizeSpinBox->value() ) );
891 const QString sizeFieldNameOrExp = mSizeFieldExpressionWidget->currentField( &isExpression );
913 dls.
setDistance( mDiagramDistanceSpinBox->value() );
915 dls.
setZIndex( mZIndexSpinBox->value() );
918 QWidget *curWdgt = stackedPlacement->currentWidget();
919 if ( ( curWdgt == pagePoint && radAroundPoint->isChecked() )
920 || ( curWdgt == pagePolygon && radAroundCentroid->isChecked() ) )
924 else if ( ( curWdgt == pagePoint && radOverPoint->isChecked() )
925 || ( curWdgt == pagePolygon && radOverCentroid->isChecked() ) )
929 else if ( ( curWdgt == pageLine && radAroundLine->isChecked() )
930 || ( curWdgt == pagePolygon && radPolygonPerimeter->isChecked() ) )
934 else if ( ( curWdgt == pageLine && radOverLine->isChecked() )
935 || ( curWdgt == pagePolygon && radInsidePolygon->isChecked() ) )
941 qFatal(
"Invalid settings" );
944 QgsDiagramLayerSettings::LinePlacementFlags flags = QgsDiagramLayerSettings::LinePlacementFlags();
945 if ( chkLineAbove->isChecked() )
947 if ( chkLineBelow->isChecked() )
949 if ( chkLineOn->isChecked() )
951 if ( ! chkLineOrientationDependent->isChecked() )
962QString QgsDiagramProperties::showExpressionBuilder(
const QString &initialExpression )
972 dlg.setWindowTitle( tr(
"Expression Based Attribute" ) );
977 dlg.setGeomCalculator( myDa );
979 if ( dlg.exec() == QDialog::Accepted )
981 return dlg.expressionText();
992 QList<QTreeWidgetItem *> selections = mAttributesTreeWidget->selectedItems();
993 if ( !selections.empty() )
995 expression = selections[0]->text( 0 );
998 const QString newExpression = showExpressionBuilder( expression );
1001 if ( !newExpression.isEmpty() )
1003 QTreeWidgetItem *newItem =
new QTreeWidgetItem( mDiagramAttributesTreeWidget );
1005 newItem->setText( 0, newExpression );
1006 newItem->setText( 2, newExpression );
1007 newItem->setData( 0, RoleAttributeExpression, newExpression );
1008 newItem->setFlags( ( newItem->flags() | Qt::ItemIsEditable ) & ~Qt::ItemIsDropEnabled );
1011 QRandomGenerator colorGenerator;
1012 const int red = colorGenerator.bounded( 1, 256 );
1013 const int green = colorGenerator.bounded( 1, 256 );
1014 const int blue = colorGenerator.bounded( 1, 256 );
1016 const QColor randomColor( red, green, blue );
1017 newItem->setData( ColumnColor, Qt::EditRole, randomColor );
1018 mDiagramAttributesTreeWidget->addTopLevelItem( newItem );
1025 mDiagramOptionsListWidget->blockSignals(
true );
1026 mDiagramOptionsListWidget->setCurrentRow( index );
1027 mDiagramOptionsListWidget->blockSignals(
false );
1032 QWidget *curWdgt = stackedPlacement->currentWidget();
1034 if ( ( curWdgt == pagePoint && radAroundPoint->isChecked() )
1035 || ( curWdgt == pageLine && radAroundLine->isChecked() )
1036 || ( curWdgt == pagePolygon && radAroundCentroid->isChecked() ) )
1038 mDiagramDistanceLabel->setEnabled(
true );
1039 mDiagramDistanceSpinBox->setEnabled(
true );
1040 mDistanceDDBtn->setEnabled(
true );
1044 mDiagramDistanceLabel->setEnabled(
false );
1045 mDiagramDistanceSpinBox->setEnabled(
false );
1046 mDistanceDDBtn->setEnabled(
false );
1049 const bool linePlacementEnabled = mLayer->
geometryType() == Qgis::GeometryType::Line && ( curWdgt == pageLine && radAroundLine->isChecked() );
1050 chkLineAbove->setEnabled( linePlacementEnabled );
1051 chkLineBelow->setEnabled( linePlacementEnabled );
1052 chkLineOn->setEnabled( linePlacementEnabled );
1053 chkLineOrientationDependent->setEnabled( linePlacementEnabled );
1058 mButtonSizeLegendSettings->setEnabled( mAttributeBasedScalingRadio->isChecked() );
1065 const QString sizeFieldNameOrExp = mSizeFieldExpressionWidget->currentField( &isExpression );
1067 const bool scaleByArea = mScaleDependencyComboBox->currentData().toBool();
1069 0.0, mMaxValueSpinBox->value(), 0.0, mSizeSpinBox->value() ) );
1074 dlg.setLayout(
new QVBoxLayout() );
1076 dlg.layout()->addWidget( panel );
1077 QDialogButtonBox *buttonBox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok );
1078 connect( buttonBox, &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
1079 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsDiagramProperties::showHelp );
1080 connect( buttonBox, &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
1081 dlg.layout()->addWidget( buttonBox );
1086void QgsDiagramProperties::showHelp()
1088 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#legend" ) );
1091void QgsDiagramProperties::createAuxiliaryField()
1115 property.setActive(
true );
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
static const double UI_SCALE_FACTOR
UI scaling factor.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QString nameFromProperty(const QgsPropertyDefinition &def, bool joined=false)
Returns the name of the auxiliary field for a property definition.
bool addAuxiliaryField(const QgsPropertyDefinition &definition)
Adds an auxiliary field for the given property.
bool exists(const QgsPropertyDefinition &definition) const
Returns true if the property is stored in the layer already, false otherwise.
A delegate for showing a color swatch in a list.
Object that keeps configuration of appearance of marker symbol's data-defined size in legend.
Stores the settings for rendering of all diagrams for a layer.
void setZIndex(double index)
Sets the diagram z-index.
Placement placement() const
Returns the diagram placement.
Property
Data definable properties.
@ StartAngle
Angle offset for pie diagram.
@ Distance
Distance to diagram from feature.
@ IsObstacle
Whether diagram features act as obstacles for other diagrams/labels.
@ PositionX
X-coordinate data defined diagram position.
@ Priority
Diagram priority (between 0 and 10)
@ AlwaysShow
Whether the diagram should always be shown, even if it overlaps other diagrams/labels.
@ Show
Whether to show the diagram.
@ StrokeColor
Stroke color.
@ StrokeWidth
Stroke width.
@ ZIndex
Z-index for diagram ordering.
@ BackgroundColor
Diagram background color.
@ PositionY
Y-coordinate data defined diagram position.
bool showAllDiagrams() const
Returns whether the layer should show all diagrams, including overlapping diagrams.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the diagram's property collection, used for data defined overrides.
LinePlacementFlags linePlacementFlags() const
Returns the diagram placement flags.
void setShowAllDiagrams(bool showAllDiagrams)
Sets whether the layer should show all diagrams, including overlapping diagrams.
void setDistance(double distance)
Sets the distance between the diagram and the feature.
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the diagram property definitions.
void setPriority(int value)
Sets the diagram priority.
int priority() const
Returns the diagram priority.
void setPlacement(Placement value)
Sets the diagram placement.
void setLinePlacementFlags(LinePlacementFlags flags)
Sets the the diagram placement flags.
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the diagram's property collection, used for data defined overrides.
double zIndex() const
Returns the diagram z-index.
double distance() const
Returns the distance between the diagram and the feature (in mm).
void scalingTypeChanged()
void mDiagramAttributesTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column)
void mAddCategoryPushButton_clicked()
void mDiagramTypeComboBox_currentIndexChanged(int index)
~QgsDiagramProperties() override
void syncToLayer()
Updates the widget to reflect the layer's current diagram settings.
void mRemoveCategoryPushButton_clicked()
QgsDiagramProperties(QgsVectorLayer *layer, QWidget *parent, QgsMapCanvas *canvas)
void showSizeLegendDialog()
void addAttribute(QTreeWidgetItem *item)
Adds an attribute from the list of available attributes to the assigned attributes with a random colo...
void mFindMaximumValueButton_clicked()
void mEngineSettingsButton_clicked()
void showAddAttributeExpressionDialog()
void mAttributesTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int column)
void auxiliaryFieldCreated()
void updatePlacementWidgets()
void mDiagramStackedWidget_currentChanged(int index)
Evaluates and returns the diagram settings relating to a diagram for a specific feature.
virtual QString rendererName() const =0
QgsDiagram * diagram() const
void setAttributeLegend(bool enabled)
Sets whether the renderer will show legend items for diagram attributes.
virtual QList< QgsDiagramSettings > diagramSettings() const =0
Returns list with all diagram settings in the renderer.
bool attributeLegend() const
Returns true if renderer will show legend items for diagram attributes.
void setDiagram(QgsDiagram *d)
Stores the settings for rendering a single diagram.
void setDirection(Direction direction)
Sets the chart's angular direction.
DiagramOrientation
Orientation of histogram.
LabelPlacementMethod labelPlacementMethod
double opacity
Opacity, from 0 (transparent) to 1.0 (opaque)
Qgis::RenderUnit sizeType
Diagram size unit.
void setSpacingUnit(Qgis::RenderUnit unit)
Sets the unit for the content spacing.
QList< QString > categoryAttributes
QList< QString > categoryLabels
DiagramOrientation diagramOrientation
QgsMapUnitScale lineSizeScale
Line unit scale.
QList< QColor > categoryColors
double rotationOffset
Rotation offset, in degrees clockwise from horizontal.
QgsMapUnitScale sizeScale
Diagram size unit scale.
double minimumScale
The minimum map scale (i.e.
void setSpacing(double spacing)
Sets the spacing between diagram contents.
bool scaleBasedVisibility
double maximumScale
The maximum map scale (i.e.
void setAxisLineSymbol(QgsLineSymbol *symbol)
Sets the line symbol to use for rendering axis in diagrams.
void setSpacingMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the content spacing.
Qgis::RenderUnit lineSizeUnit
Line unit index.
double minimumSize
Scale diagrams smaller than mMinimumSize to mMinimumSize.
Direction
Angular directions.
@ Counterclockwise
Counter-clockwise orientation.
@ Clockwise
Clockwise orientation.
void setShowAxis(bool showAxis)
Sets whether the diagram axis should be shown.
void setPaintEffect(QgsPaintEffect *effect)
Sets the paint effect to use while rendering diagrams.
virtual QString diagramName() const =0
Gets a descriptive name for this diagram type.
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.
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 setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
Class for parsing and evaluation of expressions (formerly called "search strings").
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
QString evalErrorString() const
Returns evaluation error.
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.
QVariant evaluate()
Evaluate the feature and return the result.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Container of fields for a vector layer.
int count() const
Returns number of items.
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Dialog for configuring the labeling engine.
A line symbol type, for rendering LineString and MultiLineString geometries.
void setLowerValue(double val)
double upperValue() const
QString classificationAttributeExpression() const
void setDiagramSettings(const QgsDiagramSettings &s)
void setDataDefinedSizeLegend(QgsDataDefinedSizeLegend *settings)
Configures appearance of legend.
void setLowerSize(QSizeF s)
QString classificationField() const
Returns the field name used for interpolating the diagram size.
void setClassificationAttributeExpression(const QString &expression)
bool classificationAttributeIsExpression() const
void setClassificationField(const QString &field)
Sets the field name used for interpolating the diagram size.
void setClassificationAttributeIsExpression(bool isExpression)
QgsDataDefinedSizeLegend * dataDefinedSizeLegend() const
Returns configuration of appearance of legend.
void setUpperSize(QSizeF s)
void setUpperValue(double val)
Map canvas is a class for displaying all GIS data types on a canvas.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
QgsCoordinateReferenceSystem crs
void triggerRepaint(bool deferredUpdate=false)
Will advise the map canvas (and any other interested party) that this layer requires to be repainted.
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
double minimumScale() const
Returns the minimum map scale (i.e.
double maximumScale() const
Returns the maximum map scale (i.e.
A dialog to create a new auxiliary layer.
static QgsPaintEffect * defaultStack()
Returns a new effect stack consisting of a sensible selection of default effects.
static bool isDefaultStack(QgsPaintEffect *effect)
Tests whether a paint effect matches the default effects stack.
static QgsProject * instance()
Returns the QgsProject singleton instance.
QgsCoordinateTransformContext transformContext
void setDirty(bool b=true)
Flag the project as dirty (modified).
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
Definition for a property.
A store for object properties.
void setTransformer(QgsPropertyTransformer *transformer)
Sets an optional transformer to use for manipulating the calculated values for the property.
static QgsProperty fromExpression(const QString &expression, bool isActive=true)
Returns a new ExpressionBasedProperty created from the specified expression.
void setField(const QString &field)
Sets the field name the property references.
static QgsProperty fromField(const QString &fieldName, bool isActive=true)
Returns a new FieldBasedProperty created from the specified field name.
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
bool contains(const QString &key, QgsSettings::Section section=QgsSettings::NoSection) const
Returns true if there exists a setting called key; returns false otherwise.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
Renders the diagrams for all features with the same settings.
void setDiagramSettings(const QgsDiagramSettings &s)
Represents a vector layer which manages a vector based data sets.
QVariant maximumValue(int index) const FINAL
Returns the maximum value for an attribute column or an invalid variant in case of error.
const QgsDiagramLayerSettings * diagramLayerSettings() const
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
QgsAuxiliaryLayer * auxiliaryLayer()
Returns the current auxiliary layer.
Q_INVOKABLE Qgis::GeometryType geometryType() const
Returns point, line or polygon.
void setDiagramLayerSettings(const QgsDiagramLayerSettings &s)
void setDiagramRenderer(QgsDiagramRenderer *r)
Sets diagram rendering object (takes ownership)
const QgsDiagramRenderer * diagramRenderer() const
#define DIAGRAM_NAME_HISTOGRAM
#define QgsDebugMsgLevel(str, level)
#define DIAGRAM_NAME_STACKED
#define DIAGRAM_NAME_TEXT