46#include <QStyledItemDelegate>
47#include <QRandomGenerator>
63 , mMapCanvas( canvas )
82 mDiagramOptionsListWidget->setAttribute( Qt::WA_MacShowFocusRect,
false );
84 mBarSpacingSpinBox->setClearValue( 0 );
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 );
149 mDiagramTypeComboBox->setEnabled(
false );
150 mDiagramFrame->setEnabled(
false );
158 stackedPlacement->setCurrentWidget( pagePoint );
159 mLinePlacementFrame->setVisible(
false );
162 stackedPlacement->setCurrentWidget( pageLine );
163 mLinePlacementFrame->setVisible(
true );
166 stackedPlacement->setCurrentWidget( pagePolygon );
167 mLinePlacementFrame->setVisible(
false );
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 );
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 );
298 radAroundPoint->setChecked(
true );
302 radAroundLine->setChecked(
true );
303 chkLineAbove->setChecked(
true );
304 chkLineBelow->setChecked(
false );
305 chkLineOn->setChecked(
false );
306 chkLineOrientationDependent->setChecked(
false );
310 radOverCentroid->setChecked(
true );
311 mDiagramDistanceLabel->setEnabled(
false );
312 mDiagramDistanceSpinBox->setEnabled(
false );
313 mDistanceDDBtn->setEnabled(
false );
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 const int red = QRandomGenerator::global()->bounded( 1, 256 );
661 const int green = QRandomGenerator::global()->bounded( 1, 256 );
662 const int blue = QRandomGenerator::global()->bounded( 1, 256 );
663 const QColor randomColor( red, green, blue );
664 newItem->setData( ColumnColor, Qt::EditRole, randomColor );
665 mDiagramAttributesTreeWidget->addTopLevelItem( newItem );
670 const auto constSelectedItems = mAttributesTreeWidget->selectedItems();
671 for ( QTreeWidgetItem *attributeItem : constSelectedItems )
685 const auto constSelectedItems = mDiagramAttributesTreeWidget->selectedItems();
686 for ( QTreeWidgetItem *attributeItem : constSelectedItems )
688 delete attributeItem;
697 float maxValue = 0.0;
700 const QString sizeFieldNameOrExp = mSizeFieldExpressionWidget->currentField( &isExpression );
718 maxValue = std::max( maxValue, exp.
evaluate( &context ).toFloat() );
729 maxValue = mLayer->
maximumValue( attributeNumber ).toFloat();
732 mMaxValueSpinBox->setValue( maxValue );
739 case ColumnAttributeExpression:
741 const QString currentExpression = item->data( 0, RoleAttributeExpression ).toString();
743 const QString newExpression = showExpressionBuilder( currentExpression );
744 if ( !newExpression.isEmpty() )
746 item->setData( 0, Qt::DisplayRole, newExpression );
747 item->setData( 0, RoleAttributeExpression, newExpression );
755 case ColumnLegendText:
780 const int index = mDiagramTypeComboBox->currentIndex();
781 const bool diagramsEnabled = ( index != 0 );
783 std::unique_ptr< QgsDiagram > diagram;
785 if ( diagramsEnabled && 0 == mDiagramAttributesTreeWidget->topLevelItemCount() )
787 QMessageBox::warning(
this, tr(
"Diagrams: No attributes added." ),
788 tr(
"You did not add any attributes to this diagram layer. Please specify the attributes to visualize on the diagrams or disable diagrams." ) );
793 diagram = std::make_unique< QgsTextDiagram >();
797 diagram = std::make_unique< QgsPieDiagram >();
801 diagram = std::make_unique< QgsStackedBarDiagram >();
805 diagram = std::make_unique< QgsHistogramDiagram >();
809 ds.
enabled = ( mDiagramTypeComboBox->currentIndex() != 0 );
810 ds.
font = mDiagramFontButton->currentFont();
811 ds.
opacity = mOpacityWidget->opacity();
813 QList<QColor> categoryColors;
814 QList<QString> categoryAttributes;
815 QList<QString> categoryLabels;
816 categoryColors.reserve( mDiagramAttributesTreeWidget->topLevelItemCount() );
817 categoryAttributes.reserve( mDiagramAttributesTreeWidget->topLevelItemCount() );
818 categoryLabels.reserve( mDiagramAttributesTreeWidget->topLevelItemCount() );
819 for (
int i = 0; i < mDiagramAttributesTreeWidget->topLevelItemCount(); ++i )
821 QColor color = mDiagramAttributesTreeWidget->topLevelItem( i )->data( ColumnColor, Qt::EditRole ).value<QColor>();
822 categoryColors.append( color );
823 categoryAttributes.append( mDiagramAttributesTreeWidget->topLevelItem( i )->data( 0, RoleAttributeExpression ).toString() );
824 categoryLabels.append( mDiagramAttributesTreeWidget->topLevelItem( i )->text( 2 ) );
829 ds.
size = QSizeF( mDiagramSizeSpinBox->value(), mDiagramSizeSpinBox->value() );
830 ds.
sizeType = mDiagramUnitComboBox->unit();
831 ds.
sizeScale = mDiagramUnitComboBox->getMapUnitScale();
833 ds.
lineSizeScale = mDiagramLineUnitComboBox->getMapUnitScale();
837 if ( mIncreaseSmallDiagramsCheck->isChecked() )
839 ds.
minimumSize = mIncreaseMinimumSizeSpinBox->value();
847 ds.
penColor = mDiagramPenColorButton->color();
848 ds.
penWidth = mPenWidthSpinBox->value();
860 ds.
barWidth = mBarWidthSpinBox->value();
875 if ( mFixedSizeRadio->isChecked() )
887 dr->
setUpperSize( QSizeF( mSizeSpinBox->value(), mSizeSpinBox->value() ) );
890 const QString sizeFieldNameOrExp = mSizeFieldExpressionWidget->currentField( &isExpression );
912 dls.
setDistance( mDiagramDistanceSpinBox->value() );
914 dls.
setZIndex( mZIndexSpinBox->value() );
917 QWidget *curWdgt = stackedPlacement->currentWidget();
918 if ( ( curWdgt == pagePoint && radAroundPoint->isChecked() )
919 || ( curWdgt == pagePolygon && radAroundCentroid->isChecked() ) )
923 else if ( ( curWdgt == pagePoint && radOverPoint->isChecked() )
924 || ( curWdgt == pagePolygon && radOverCentroid->isChecked() ) )
928 else if ( ( curWdgt == pageLine && radAroundLine->isChecked() )
929 || ( curWdgt == pagePolygon && radPolygonPerimeter->isChecked() ) )
933 else if ( ( curWdgt == pageLine && radOverLine->isChecked() )
934 || ( curWdgt == pagePolygon && radInsidePolygon->isChecked() ) )
940 qFatal(
"Invalid settings" );
944 if ( chkLineAbove->isChecked() )
946 if ( chkLineBelow->isChecked() )
948 if ( chkLineOn->isChecked() )
950 if ( ! chkLineOrientationDependent->isChecked() )
961QString QgsDiagramProperties::showExpressionBuilder(
const QString &initialExpression )
971 dlg.setWindowTitle( tr(
"Expression Based Attribute" ) );
976 dlg.setGeomCalculator( myDa );
978 if ( dlg.exec() == QDialog::Accepted )
980 return dlg.expressionText();
991 QList<QTreeWidgetItem *> selections = mAttributesTreeWidget->selectedItems();
992 if ( !selections.empty() )
994 expression = selections[0]->text( 0 );
997 const QString newExpression = showExpressionBuilder( expression );
1000 if ( !newExpression.isEmpty() )
1002 QTreeWidgetItem *newItem =
new QTreeWidgetItem( mDiagramAttributesTreeWidget );
1004 newItem->setText( 0, newExpression );
1005 newItem->setText( 2, newExpression );
1006 newItem->setData( 0, RoleAttributeExpression, newExpression );
1007 newItem->setFlags( ( newItem->flags() | Qt::ItemIsEditable ) & ~Qt::ItemIsDropEnabled );
1010 QRandomGenerator colorGenerator;
1011 const int red = colorGenerator.bounded( 1, 256 );
1012 const int green = colorGenerator.bounded( 1, 256 );
1013 const int blue = colorGenerator.bounded( 1, 256 );
1015 const QColor randomColor( red, green, blue );
1016 newItem->setData( ColumnColor, Qt::EditRole, randomColor );
1017 mDiagramAttributesTreeWidget->addTopLevelItem( newItem );
1024 mDiagramOptionsListWidget->blockSignals(
true );
1025 mDiagramOptionsListWidget->setCurrentRow( index );
1026 mDiagramOptionsListWidget->blockSignals(
false );
1031 QWidget *curWdgt = stackedPlacement->currentWidget();
1033 if ( ( curWdgt == pagePoint && radAroundPoint->isChecked() )
1034 || ( curWdgt == pageLine && radAroundLine->isChecked() )
1035 || ( curWdgt == pagePolygon && radAroundCentroid->isChecked() ) )
1037 mDiagramDistanceLabel->setEnabled(
true );
1038 mDiagramDistanceSpinBox->setEnabled(
true );
1039 mDistanceDDBtn->setEnabled(
true );
1043 mDiagramDistanceLabel->setEnabled(
false );
1044 mDiagramDistanceSpinBox->setEnabled(
false );
1045 mDistanceDDBtn->setEnabled(
false );
1049 chkLineAbove->setEnabled( linePlacementEnabled );
1050 chkLineBelow->setEnabled( linePlacementEnabled );
1051 chkLineOn->setEnabled( linePlacementEnabled );
1052 chkLineOrientationDependent->setEnabled( linePlacementEnabled );
1057 mButtonSizeLegendSettings->setEnabled( mAttributeBasedScalingRadio->isChecked() );
1064 const QString sizeFieldNameOrExp = mSizeFieldExpressionWidget->currentField( &isExpression );
1066 const bool scaleByArea = mScaleDependencyComboBox->currentData().toBool();
1068 0.0, mMaxValueSpinBox->value(), 0.0, mSizeSpinBox->value() ) );
1073 dlg.setLayout(
new QVBoxLayout() );
1075 dlg.layout()->addWidget( panel );
1076 QDialogButtonBox *buttonBox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok );
1077 connect( buttonBox, &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
1078 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsDiagramProperties::showHelp );
1079 connect( buttonBox, &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
1080 dlg.layout()->addWidget( buttonBox );
1085void QgsDiagramProperties::showHelp()
1087 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#legend" ) );
1090void QgsDiagramProperties::createAuxiliaryField()
1114 property.setActive(
true );
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
@ Millimeters
Millimeters.
@ Points
Points (e.g., for font sizes)
@ MetersInMapUnits
Meters value as Map units.
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.
QFlags< LinePlacementFlag > LinePlacementFlags
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.
Property
Data definable properties.
@ PositionX
X-coordinate data defined diagram position.
@ Distance
Distance to diagram from feature.
@ PositionY
Y-coordinate data defined diagram position.
@ Show
Whether to show the diagram.
@ Priority
Diagram priority (between 0 and 10)
@ ZIndex
Z-index for diagram ordering.
@ StrokeColor
Stroke color.
@ BackgroundColor
Diagram background color.
@ StartAngle
Angle offset for pie diagram.
@ IsObstacle
Whether diagram features act as obstacles for other diagrams/labels.
@ StrokeWidth
Stroke width.
@ AlwaysShow
Whether the diagram should always be shown, even if it overlaps other diagrams/labels.
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)
Fetch next feature and stores in f, returns true on success.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Container of fields for a vector layer.
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
Q_INVOKABLE 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.
Alters the size of rendered diagrams using a linear scaling.
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.
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