52#include <QStyledItemDelegate>
53#include <QRandomGenerator>
69 , mMapCanvas( canvas )
88 mDiagramOptionsListWidget->setAttribute( Qt::WA_MacShowFocusRect,
false );
90 mBarSpacingSpinBox->setClearValue( 0 );
96 mDiagramTypeComboBox->blockSignals(
true );
98 mDiagramTypeComboBox->addItem( icon, tr(
"No Diagrams" ),
"None" );
107 mDiagramTypeComboBox->blockSignals(
false );
110 mAxisLineStyleButton->setDialogTitle( tr(
"Axis Line Symbol" ) );
112 mScaleRangeWidget->setMapCanvas( mMapCanvas );
113 mSizeFieldExpressionWidget->registerExpressionContextGenerator(
this );
115 mBackgroundColorButton->setColorDialogTitle( tr(
"Select Background Color" ) );
116 mBackgroundColorButton->setAllowOpacity(
true );
117 mBackgroundColorButton->setContext( QStringLiteral(
"symbology" ) );
118 mBackgroundColorButton->setShowNoColor(
true );
119 mBackgroundColorButton->setNoColorString( tr(
"Transparent Background" ) );
120 mDiagramPenColorButton->setColorDialogTitle( tr(
"Select Pen Color" ) );
121 mDiagramPenColorButton->setAllowOpacity(
true );
122 mDiagramPenColorButton->setContext( QStringLiteral(
"symbology" ) );
123 mDiagramPenColorButton->setShowNoColor(
true );
124 mDiagramPenColorButton->setNoColorString( tr(
"Transparent Stroke" ) );
126 mMaxValueSpinBox->setShowClearButton(
false );
127 mSizeSpinBox->setClearValue( 5 );
129 mDiagramAttributesTreeWidget->setItemDelegateForColumn( ColumnAttributeExpression,
new EditBlockerDelegate(
this ) );
130 mDiagramAttributesTreeWidget->setItemDelegateForColumn( ColumnColor,
new QgsColorSwatchDelegate(
this ) );
132 mDiagramAttributesTreeWidget->setColumnWidth( ColumnColor,
Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance(
'X' ) * 6.6 );
145 mDiagramTypeComboBox->setEnabled(
false );
146 mDiagramFrame->setEnabled(
false );
154 stackedPlacement->setCurrentWidget( pagePoint );
155 mLinePlacementFrame->setVisible(
false );
158 stackedPlacement->setCurrentWidget( pageLine );
159 mLinePlacementFrame->setVisible(
true );
162 stackedPlacement->setCurrentWidget( pagePolygon );
163 mLinePlacementFrame->setVisible(
false );
172 mPlacePointBtnGrp =
new QButtonGroup(
this );
173 mPlacePointBtnGrp->addButton( radAroundPoint );
174 mPlacePointBtnGrp->addButton( radOverPoint );
175 mPlacePointBtnGrp->setExclusive(
true );
179 mPlaceLineBtnGrp =
new QButtonGroup(
this );
180 mPlaceLineBtnGrp->addButton( radAroundLine );
181 mPlaceLineBtnGrp->addButton( radOverLine );
182 mPlaceLineBtnGrp->setExclusive(
true );
186 mPlacePolygonBtnGrp =
new QButtonGroup(
this );
187 mPlacePolygonBtnGrp->addButton( radAroundCentroid );
188 mPlacePolygonBtnGrp->addButton( radOverCentroid );
189 mPlacePolygonBtnGrp->addButton( radPolygonPerimeter );
190 mPlacePolygonBtnGrp->addButton( radInsidePolygon );
191 mPlacePolygonBtnGrp->setExclusive(
true );
197 mScaleDependencyComboBox->addItem( tr(
"Area" ),
true );
198 mScaleDependencyComboBox->addItem( tr(
"Diameter" ),
false );
200 mAngleOffsetComboBox->addItem( tr(
"Top" ), 270 );
201 mAngleOffsetComboBox->addItem( tr(
"Right" ), 0 );
202 mAngleOffsetComboBox->addItem( tr(
"Bottom" ), 90 );
203 mAngleOffsetComboBox->addItem( tr(
"Left" ), 180 );
211 QSizePolicy policy( mDiagramOptionsListFrame->sizePolicy() );
212 policy.setHorizontalStretch( 0 );
213 mDiagramOptionsListFrame->setSizePolicy( policy );
214 if ( !settings.
contains( QStringLiteral(
"/Windows/Diagrams/OptionsSplitState" ) ) )
217 QList<int> splitsizes;
219 mDiagramOptionsSplitter->setSizes( splitsizes );
223 mDiagramOptionsSplitter->restoreState( settings.
value( QStringLiteral(
"Windows/Diagrams/OptionsSplitState" ) ).toByteArray() );
224 mDiagramOptionsListWidget->setCurrentRow( settings.
value( QStringLiteral(
"Windows/Diagrams/Tab" ), 0 ).toInt() );
227 mSizeFieldExpressionWidget->setLayer( mLayer );
231 mSizeFieldExpressionWidget->setGeomCalculator( myDa );
235 for (
int idx = 0; idx < layerFields.
count(); ++idx )
237 QTreeWidgetItem *newItem =
new QTreeWidgetItem( mAttributesTreeWidget );
238 const QString name = QStringLiteral(
"\"%1\"" ).arg( layerFields.
at( idx ).
name() );
239 newItem->setText( 0, name );
240 newItem->setData( 0, RoleAttributeExpression, name );
241 newItem->setFlags( newItem->flags() & ~Qt::ItemIsDropEnabled );
245 mPaintEffect->setEnabled(
false );
268 mDiagramAttributesTreeWidget->clear();
273 mDiagramTypeComboBox->blockSignals(
true );
274 mDiagramTypeComboBox->setCurrentIndex( 0 );
275 mDiagramTypeComboBox->blockSignals(
false );
276 mFixedSizeRadio->setChecked(
true );
279 mLabelPlacementComboBox->setCurrentIndex( mLabelPlacementComboBox->findText( tr(
"x-height" ) ) );
280 mDiagramSizeSpinBox->setEnabled(
true );
281 mDiagramSizeSpinBox->setValue( 15 );
282 mLinearScaleFrame->setEnabled(
false );
283 mIncreaseMinimumSizeSpinBox->setEnabled(
false );
284 mIncreaseMinimumSizeLabel->setEnabled(
false );
285 mBarWidthSpinBox->setValue( 5 );
288 mShowAllCheckBox->setChecked(
true );
289 mCheckBoxAttributeLegend->setChecked(
true );
294 radAroundPoint->setChecked(
true );
298 radAroundLine->setChecked(
true );
299 chkLineAbove->setChecked(
true );
300 chkLineBelow->setChecked(
false );
301 chkLineOn->setChecked(
false );
302 chkLineOrientationDependent->setChecked(
false );
306 radOverCentroid->setChecked(
true );
307 mDiagramDistanceLabel->setEnabled(
false );
308 mDiagramDistanceSpinBox->setEnabled(
false );
309 mDistanceDDBtn->setEnabled(
false );
316 mBackgroundColorButton->setColor( QColor( 255, 255, 255, 255 ) );
324 if ( dr->
rendererName() == QLatin1String(
"SingleCategory" ) )
326 mFixedSizeRadio->setChecked(
true );
330 mAttributeBasedScalingRadio->setChecked(
true );
332 mDiagramSizeSpinBox->setEnabled( mFixedSizeRadio->isChecked() );
333 mLinearScaleFrame->setEnabled( mAttributeBasedScalingRadio->isChecked() );
338 if ( !settingList.isEmpty() )
340 mDiagramFrame->setEnabled( settingList.at( 0 ).enabled );
341 mDiagramFontButton->setCurrentFont( settingList.at( 0 ).font );
342 const QSizeF size = settingList.at( 0 ).size;
343 mBackgroundColorButton->setColor( settingList.at( 0 ).backgroundColor );
344 mOpacityWidget->setOpacity( settingList.at( 0 ).opacity );
345 mDiagramPenColorButton->setColor( settingList.at( 0 ).penColor );
346 mPenWidthSpinBox->setValue( settingList.at( 0 ).penWidth );
347 mDiagramSizeSpinBox->setValue( ( size.width() + size.height() ) / 2.0 );
348 mScaleRangeWidget->setScaleRange( ( settingList.at( 0 ).minimumScale > 0 ? settingList.at( 0 ).minimumScale : mLayer->
minimumScale() ),
349 ( settingList.at( 0 ).maximumScale > 0 ? settingList.at( 0 ).maximumScale : mLayer->
maximumScale() ) );
350 mScaleVisibilityGroupBox->setChecked( settingList.at( 0 ).scaleBasedVisibility );
351 mDiagramUnitComboBox->setUnit( settingList.at( 0 ).sizeType );
352 mDiagramUnitComboBox->setMapUnitScale( settingList.at( 0 ).sizeScale );
353 mDiagramLineUnitComboBox->setUnit( settingList.at( 0 ).lineSizeUnit );
354 mDiagramLineUnitComboBox->setMapUnitScale( settingList.at( 0 ).lineSizeScale );
358 mLabelPlacementComboBox->setCurrentIndex( 0 );
362 mLabelPlacementComboBox->setCurrentIndex( 1 );
365 if ( settingList.at( 0 ).paintEffect() )
366 mPaintEffect.reset( settingList.at( 0 ).paintEffect()->clone() );
368 mAngleOffsetComboBox->setCurrentIndex( mAngleOffsetComboBox->findData( settingList.at( 0 ).rotationOffset ) );
369 mAngleDirectionComboBox->setCurrentIndex( mAngleDirectionComboBox->findData( settingList.at( 0 ).direction() ) );
375 switch ( settingList.at( 0 ).diagramOrientation )
378 mOrientationLeftButton->setChecked(
true );
382 mOrientationRightButton->setChecked(
true );
386 mOrientationUpButton->setChecked(
true );
390 mOrientationDownButton->setChecked(
true );
394 mBarWidthSpinBox->setValue( settingList.at( 0 ).barWidth );
395 mBarSpacingSpinBox->setValue( settingList.at( 0 ).spacing() );
396 mBarSpacingUnitComboBox->setUnit( settingList.at( 0 ).spacingUnit() );
397 mBarSpacingUnitComboBox->setMapUnitScale( settingList.at( 0 ).spacingMapUnitScale() );
399 mShowAxisGroupBox->setChecked( settingList.at( 0 ).showAxis() );
400 if ( settingList.at( 0 ).axisLineSymbol() )
401 mAxisLineStyleButton->setSymbol( settingList.at( 0 ).axisLineSymbol()->clone() );
403 mIncreaseSmallDiagramsCheck->setChecked( settingList.at( 0 ).minimumSize != 0 );
404 mIncreaseMinimumSizeSpinBox->setEnabled( mIncreaseSmallDiagramsCheck->isChecked() );
405 mIncreaseMinimumSizeLabel->setEnabled( mIncreaseSmallDiagramsCheck->isChecked() );
407 mIncreaseMinimumSizeSpinBox->setValue( settingList.at( 0 ).minimumSize );
409 if ( settingList.at( 0 ).scaleByArea )
411 mScaleDependencyComboBox->setCurrentIndex( 0 );
415 mScaleDependencyComboBox->setCurrentIndex( 1 );
418 const QList< QColor > categoryColors = settingList.at( 0 ).categoryColors;
419 const QList< QString > categoryAttributes = settingList.at( 0 ).categoryAttributes;
420 const QList< QString > categoryLabels = settingList.at( 0 ).categoryLabels;
421 QList< QString >::const_iterator catIt = categoryAttributes.constBegin();
422 QList< QColor >::const_iterator coIt = categoryColors.constBegin();
423 QList< QString >::const_iterator labIt = categoryLabels.constBegin();
424 for ( ; catIt != categoryAttributes.constEnd(); ++catIt, ++coIt, ++labIt )
426 QTreeWidgetItem *newItem =
new QTreeWidgetItem( mDiagramAttributesTreeWidget );
427 newItem->setText( 0, *catIt );
428 newItem->setData( 0, RoleAttributeExpression, *catIt );
429 newItem->setFlags( newItem->flags() & ~Qt::ItemIsDropEnabled );
430 newItem->setData( ColumnColor, Qt::EditRole, *coIt );
431 newItem->setText( 2, *labIt );
432 newItem->setFlags( newItem->flags() | Qt::ItemIsEditable );
436 if ( dr->
rendererName() == QLatin1String(
"LinearlyInterpolated" ) )
441 mDiagramSizeSpinBox->setEnabled(
false );
442 mLinearScaleFrame->setEnabled(
true );
443 mMaxValueSpinBox->setValue( lidr->
upperValue() );
444 mSizeSpinBox->setValue( ( lidr->
upperSize().width() + lidr->
upperSize().height() ) / 2 );
461 mDiagramDistanceSpinBox->setValue( dls->
distance() );
462 mPrioritySlider->setValue( dls->
priority() );
463 mZIndexSpinBox->setValue( dls->
zIndex() );
468 radAroundPoint->setChecked(
true );
469 radAroundCentroid->setChecked(
true );
473 radOverPoint->setChecked(
true );
474 radOverCentroid->setChecked(
true );
478 radAroundLine->setChecked(
true );
479 radPolygonPerimeter->setChecked(
true );
483 radOverLine->setChecked(
true );
484 radInsidePolygon->setChecked(
true );
495 chkLineOrientationDependent->setChecked(
true );
507 mDiagramTypeComboBox->blockSignals(
true );
508 mDiagramTypeComboBox->setCurrentIndex( settingList.at( 0 ).enabled ? mDiagramTypeComboBox->findData( mDiagramType ) : 0 );
509 mDiagramTypeComboBox->blockSignals(
false );
512 if ( mDiagramTypeComboBox->currentIndex() == -1 )
514 QMessageBox::warning(
this, tr(
"Diagram Properties" ),
515 tr(
"The diagram type '%1' is unknown. A default type is selected for you." ).arg( mDiagramType ), QMessageBox::Ok );
516 mDiagramTypeComboBox->setCurrentIndex( mDiagramTypeComboBox->findData(
DIAGRAM_NAME_PIE ) );
520 mPaintEffectWidget->setPaintEffect( mPaintEffect.get() );
526 settings.
setValue( QStringLiteral(
"Windows/Diagrams/OptionsSplitState" ), mDiagramOptionsSplitter->saveState() );
527 settings.
setValue( QStringLiteral(
"Windows/Diagrams/Tab" ), mDiagramOptionsListWidget->currentRow() );
538void QgsDiagramProperties::updateProperty()
549 mDiagramFrame->setEnabled(
false );
553 mDiagramFrame->setEnabled(
true );
555 mDiagramType = mDiagramTypeComboBox->itemData( index ).toString();
559 mTextOptionsFrame->show();
560 mBackgroundColorLabel->show();
561 mBackgroundColorButton->show();
562 mBackgroundColorDDBtn->show();
563 mDiagramFontButton->show();
567 mTextOptionsFrame->hide();
568 mBackgroundColorLabel->hide();
569 mBackgroundColorButton->hide();
570 mBackgroundColorDDBtn->hide();
571 mDiagramFontButton->hide();
576 mBarWidthLabel->show();
577 mBarWidthSpinBox->show();
578 mBarSpacingLabel->show();
579 mBarSpacingSpinBox->show();
580 mBarSpacingUnitComboBox->show();
581 mBarOptionsFrame->show();
582 mShowAxisGroupBox->show();
584 mAttributeBasedScalingRadio->setChecked(
true );
587 mLinearlyScalingLabel->setText( tr(
"Bar length: Scale linearly, so that the following value matches the specified bar length:" ) );
588 mSizeLabel->setText( tr(
"Bar length" ) );
589 mFrameIncreaseSize->setVisible(
false );
593 mBarWidthLabel->hide();
594 mBarWidthSpinBox->hide();
595 mBarSpacingLabel->hide();
596 mBarSpacingSpinBox->hide();
597 mBarSpacingUnitComboBox->hide();
598 mShowAxisGroupBox->hide();
599 mBarOptionsFrame->hide();
600 mLinearlyScalingLabel->setText( tr(
"Scale linearly between 0 and the following attribute value / diagram size:" ) );
601 mSizeLabel->setText( tr(
"Size" ) );
602 mAttributeBasedScalingRadio->setEnabled(
true );
603 mFixedSizeRadio->setEnabled(
true );
604 mDiagramSizeSpinBox->setEnabled( mFixedSizeRadio->isChecked() );
605 mFrameIncreaseSize->setVisible(
true );
610 mScaleDependencyComboBox->show();
611 mScaleDependencyLabel->show();
615 mScaleDependencyComboBox->hide();
616 mScaleDependencyLabel->hide();
621 mAngleOffsetComboBox->show();
622 mAngleDirectionComboBox->show();
623 mAngleDirectionLabel->show();
624 mAngleOffsetLabel->show();
625 mStartAngleDDBtn->show();
629 mAngleOffsetComboBox->hide();
630 mAngleDirectionComboBox->hide();
631 mAngleDirectionLabel->hide();
632 mAngleOffsetLabel->hide();
633 mStartAngleDDBtn->hide();
637QString QgsDiagramProperties::guessLegendText(
const QString &expression )
640 QString text = expression.mid( expression.startsWith(
'\"' ) ? 1 : 0 );
641 if ( text.endsWith(
'\"' ) )
648 QTreeWidgetItem *newItem =
new QTreeWidgetItem( mDiagramAttributesTreeWidget );
650 newItem->setText( 0, item->text( 0 ) );
651 newItem->setText( 2, guessLegendText( item->text( 0 ) ) );
652 newItem->setData( 0, RoleAttributeExpression, item->data( 0, RoleAttributeExpression ) );
653 newItem->setFlags( ( newItem->flags() | Qt::ItemIsEditable ) & ~Qt::ItemIsDropEnabled );
656 QRandomGenerator colorGenerator;
657 const int red = colorGenerator.bounded( 1, 256 );
658 const int green = colorGenerator.bounded( 1, 256 );
659 const int blue = colorGenerator.bounded( 1, 256 );
660 const QColor randomColor( red, green, blue );
661 newItem->setData( ColumnColor, Qt::EditRole, randomColor );
662 mDiagramAttributesTreeWidget->addTopLevelItem( newItem );
667 const auto constSelectedItems = mAttributesTreeWidget->selectedItems();
668 for ( QTreeWidgetItem *attributeItem : constSelectedItems )
682 const auto constSelectedItems = mDiagramAttributesTreeWidget->selectedItems();
683 for ( QTreeWidgetItem *attributeItem : constSelectedItems )
685 delete attributeItem;
694 float maxValue = 0.0;
697 const QString sizeFieldNameOrExp = mSizeFieldExpressionWidget->currentField( &isExpression );
715 maxValue = std::max( maxValue, exp.
evaluate( &context ).toFloat() );
726 maxValue = mLayer->
maximumValue( attributeNumber ).toFloat();
729 mMaxValueSpinBox->setValue( maxValue );
736 case ColumnAttributeExpression:
738 const QString currentExpression = item->data( 0, RoleAttributeExpression ).toString();
740 const QString newExpression = showExpressionBuilder( currentExpression );
741 if ( !newExpression.isEmpty() )
743 item->setData( 0, Qt::DisplayRole, newExpression );
744 item->setData( 0, RoleAttributeExpression, newExpression );
752 case ColumnLegendText:
777 const int index = mDiagramTypeComboBox->currentIndex();
778 const bool diagramsEnabled = ( index != 0 );
780 std::unique_ptr< QgsDiagram > diagram;
782 if ( diagramsEnabled && 0 == mDiagramAttributesTreeWidget->topLevelItemCount() )
784 QMessageBox::warning(
this, tr(
"Diagrams: No attributes added." ),
785 tr(
"You did not add any attributes to this diagram layer. Please specify the attributes to visualize on the diagrams or disable diagrams." ) );
790 diagram = std::make_unique< QgsTextDiagram >();
794 diagram = std::make_unique< QgsPieDiagram >();
798 diagram = std::make_unique< QgsStackedBarDiagram >();
802 diagram = std::make_unique< QgsHistogramDiagram >();
806 ds.
enabled = ( mDiagramTypeComboBox->currentIndex() != 0 );
807 ds.
font = mDiagramFontButton->currentFont();
808 ds.
opacity = mOpacityWidget->opacity();
810 QList<QColor> categoryColors;
811 QList<QString> categoryAttributes;
812 QList<QString> categoryLabels;
813 categoryColors.reserve( mDiagramAttributesTreeWidget->topLevelItemCount() );
814 categoryAttributes.reserve( mDiagramAttributesTreeWidget->topLevelItemCount() );
815 categoryLabels.reserve( mDiagramAttributesTreeWidget->topLevelItemCount() );
816 for (
int i = 0; i < mDiagramAttributesTreeWidget->topLevelItemCount(); ++i )
818 QColor color = mDiagramAttributesTreeWidget->topLevelItem( i )->data( ColumnColor, Qt::EditRole ).value<QColor>();
819 categoryColors.append( color );
820 categoryAttributes.append( mDiagramAttributesTreeWidget->topLevelItem( i )->data( 0, RoleAttributeExpression ).toString() );
821 categoryLabels.append( mDiagramAttributesTreeWidget->topLevelItem( i )->text( 2 ) );
826 ds.
size = QSizeF( mDiagramSizeSpinBox->value(), mDiagramSizeSpinBox->value() );
827 ds.
sizeType = mDiagramUnitComboBox->unit();
828 ds.
sizeScale = mDiagramUnitComboBox->getMapUnitScale();
830 ds.
lineSizeScale = mDiagramLineUnitComboBox->getMapUnitScale();
834 if ( mIncreaseSmallDiagramsCheck->isChecked() )
836 ds.
minimumSize = mIncreaseMinimumSizeSpinBox->value();
844 ds.
penColor = mDiagramPenColorButton->color();
845 ds.
penWidth = mPenWidthSpinBox->value();
857 ds.
barWidth = mBarWidthSpinBox->value();
872 if ( mFixedSizeRadio->isChecked() )
884 dr->
setUpperSize( QSizeF( mSizeSpinBox->value(), mSizeSpinBox->value() ) );
887 const QString sizeFieldNameOrExp = mSizeFieldExpressionWidget->currentField( &isExpression );
909 dls.
setDistance( mDiagramDistanceSpinBox->value() );
911 dls.
setZIndex( mZIndexSpinBox->value() );
914 QWidget *curWdgt = stackedPlacement->currentWidget();
915 if ( ( curWdgt == pagePoint && radAroundPoint->isChecked() )
916 || ( curWdgt == pagePolygon && radAroundCentroid->isChecked() ) )
920 else if ( ( curWdgt == pagePoint && radOverPoint->isChecked() )
921 || ( curWdgt == pagePolygon && radOverCentroid->isChecked() ) )
925 else if ( ( curWdgt == pageLine && radAroundLine->isChecked() )
926 || ( curWdgt == pagePolygon && radPolygonPerimeter->isChecked() ) )
930 else if ( ( curWdgt == pageLine && radOverLine->isChecked() )
931 || ( curWdgt == pagePolygon && radInsidePolygon->isChecked() ) )
937 qFatal(
"Invalid settings" );
940 QgsDiagramLayerSettings::LinePlacementFlags flags = QgsDiagramLayerSettings::LinePlacementFlags();
941 if ( chkLineAbove->isChecked() )
943 if ( chkLineBelow->isChecked() )
945 if ( chkLineOn->isChecked() )
947 if ( ! chkLineOrientationDependent->isChecked() )
958QString QgsDiagramProperties::showExpressionBuilder(
const QString &initialExpression )
968 dlg.setWindowTitle( tr(
"Expression Based Attribute" ) );
973 dlg.setGeomCalculator( myDa );
975 if ( dlg.exec() == QDialog::Accepted )
977 return dlg.expressionText();
988 QList<QTreeWidgetItem *> selections = mAttributesTreeWidget->selectedItems();
989 if ( !selections.empty() )
991 expression = selections[0]->text( 0 );
994 const QString newExpression = showExpressionBuilder( expression );
997 if ( !newExpression.isEmpty() )
999 QTreeWidgetItem *newItem =
new QTreeWidgetItem( mDiagramAttributesTreeWidget );
1001 newItem->setText( 0, newExpression );
1002 newItem->setText( 2, newExpression );
1003 newItem->setData( 0, RoleAttributeExpression, newExpression );
1004 newItem->setFlags( ( newItem->flags() | Qt::ItemIsEditable ) & ~Qt::ItemIsDropEnabled );
1007 QRandomGenerator colorGenerator;
1008 const int red = colorGenerator.bounded( 1, 256 );
1009 const int green = colorGenerator.bounded( 1, 256 );
1010 const int blue = colorGenerator.bounded( 1, 256 );
1012 const QColor randomColor( red, green, blue );
1013 newItem->setData( ColumnColor, Qt::EditRole, randomColor );
1014 mDiagramAttributesTreeWidget->addTopLevelItem( newItem );
1021 mDiagramOptionsListWidget->blockSignals(
true );
1022 mDiagramOptionsListWidget->setCurrentRow( index );
1023 mDiagramOptionsListWidget->blockSignals(
false );
1028 QWidget *curWdgt = stackedPlacement->currentWidget();
1030 if ( ( curWdgt == pagePoint && radAroundPoint->isChecked() )
1031 || ( curWdgt == pageLine && radAroundLine->isChecked() )
1032 || ( curWdgt == pagePolygon && radAroundCentroid->isChecked() ) )
1034 mDiagramDistanceLabel->setEnabled(
true );
1035 mDiagramDistanceSpinBox->setEnabled(
true );
1036 mDistanceDDBtn->setEnabled(
true );
1040 mDiagramDistanceLabel->setEnabled(
false );
1041 mDiagramDistanceSpinBox->setEnabled(
false );
1042 mDistanceDDBtn->setEnabled(
false );
1046 chkLineAbove->setEnabled( linePlacementEnabled );
1047 chkLineBelow->setEnabled( linePlacementEnabled );
1048 chkLineOn->setEnabled( linePlacementEnabled );
1049 chkLineOrientationDependent->setEnabled( linePlacementEnabled );
1054 mButtonSizeLegendSettings->setEnabled( mAttributeBasedScalingRadio->isChecked() );
1061 const QString sizeFieldNameOrExp = mSizeFieldExpressionWidget->currentField( &isExpression );
1063 const bool scaleByArea = mScaleDependencyComboBox->currentData().toBool();
1065 0.0, mMaxValueSpinBox->value(), 0.0, mSizeSpinBox->value() ) );
1070 dlg.setLayout(
new QVBoxLayout() );
1072 dlg.layout()->addWidget( panel );
1073 QDialogButtonBox *buttonBox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok );
1074 connect( buttonBox, &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
1075 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsDiagramProperties::showHelp );
1076 connect( buttonBox, &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
1077 dlg.layout()->addWidget( buttonBox );
1082void QgsDiagramProperties::showHelp()
1084 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#legend" ) );
1087void QgsDiagramProperties::createAuxiliaryField()
1111 property.setActive(
true );
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.
QgsUnitTypes::RenderUnit sizeType
Diagram size unit.
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)
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.
QgsUnitTypes::RenderUnit lineSizeUnit
Line unit index.
void setSpacingMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale for the content spacing.
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.
void setSpacingUnit(QgsUnitTypes::RenderUnit unit)
Sets the unit for the content spacing.
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)
QList< QgsUnitTypes::RenderUnit > RenderUnitList
List of render units.
@ RenderMetersInMapUnits
Meters value as Map units.
@ RenderPoints
Points (e.g., for font sizes)
@ RenderMillimeters
Millimeters.
@ RenderMapUnits
Map units.
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.
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
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.
void setDiagramLayerSettings(const QgsDiagramLayerSettings &s)
void setDiagramRenderer(QgsDiagramRenderer *r)
Sets diagram rendering object (takes ownership)
const QgsDiagramRenderer * diagramRenderer() const
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
#define DIAGRAM_NAME_HISTOGRAM
#define QgsDebugMsgLevel(str, level)
#define DIAGRAM_NAME_STACKED
#define DIAGRAM_NAME_TEXT