51 #include <QMessageBox>
52 #include <QStyledItemDelegate>
53 #include <QRandomGenerator>
63 : QStyledItemDelegate( parent )
66 QWidget *
createEditor( QWidget *,
const QStyleOptionViewItem &,
const QModelIndex & )
const override
87 , mMapCanvas( canvas )
106 mDiagramOptionsListWidget->setAttribute( Qt::WA_MacShowFocusRect,
false );
108 mBarSpacingSpinBox->setClearValue( 0 );
114 mDiagramTypeComboBox->blockSignals(
true );
116 mDiagramTypeComboBox->addItem( pix, tr(
"No Diagrams" ),
"None" );
125 mDiagramTypeComboBox->blockSignals(
false );
128 mAxisLineStyleButton->setDialogTitle( tr(
"Axis Line Symbol" ) );
130 mScaleRangeWidget->setMapCanvas( mMapCanvas );
131 mSizeFieldExpressionWidget->registerExpressionContextGenerator(
this );
133 mBackgroundColorButton->setColorDialogTitle( tr(
"Select Background Color" ) );
134 mBackgroundColorButton->setAllowOpacity(
true );
135 mBackgroundColorButton->setContext( QStringLiteral(
"symbology" ) );
136 mBackgroundColorButton->setShowNoColor(
true );
137 mBackgroundColorButton->setNoColorString( tr(
"Transparent Background" ) );
138 mDiagramPenColorButton->setColorDialogTitle( tr(
"Select Pen Color" ) );
139 mDiagramPenColorButton->setAllowOpacity(
true );
140 mDiagramPenColorButton->setContext( QStringLiteral(
"symbology" ) );
141 mDiagramPenColorButton->setShowNoColor(
true );
142 mDiagramPenColorButton->setNoColorString( tr(
"Transparent Stroke" ) );
144 mMaxValueSpinBox->setShowClearButton(
false );
145 mSizeSpinBox->setClearValue( 5 );
147 mDiagramAttributesTreeWidget->setItemDelegateForColumn( ColumnAttributeExpression,
new EditBlockerDelegate(
this ) );
148 mDiagramAttributesTreeWidget->setItemDelegateForColumn( ColumnColor,
new QgsColorSwatchDelegate(
this ) );
150 mDiagramAttributesTreeWidget->setColumnWidth( ColumnColor,
Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance(
'X' ) * 6.6 );
163 mDiagramTypeComboBox->setEnabled(
false );
164 mDiagramFrame->setEnabled(
false );
172 stackedPlacement->setCurrentWidget( pagePoint );
173 mLinePlacementFrame->setVisible(
false );
176 stackedPlacement->setCurrentWidget( pageLine );
177 mLinePlacementFrame->setVisible(
true );
180 stackedPlacement->setCurrentWidget( pagePolygon );
181 mLinePlacementFrame->setVisible(
false );
190 mPlacePointBtnGrp =
new QButtonGroup(
this );
191 mPlacePointBtnGrp->addButton( radAroundPoint );
192 mPlacePointBtnGrp->addButton( radOverPoint );
193 mPlacePointBtnGrp->setExclusive(
true );
197 mPlaceLineBtnGrp =
new QButtonGroup(
this );
198 mPlaceLineBtnGrp->addButton( radAroundLine );
199 mPlaceLineBtnGrp->addButton( radOverLine );
200 mPlaceLineBtnGrp->setExclusive(
true );
204 mPlacePolygonBtnGrp =
new QButtonGroup(
this );
205 mPlacePolygonBtnGrp->addButton( radAroundCentroid );
206 mPlacePolygonBtnGrp->addButton( radOverCentroid );
207 mPlacePolygonBtnGrp->addButton( radPolygonPerimeter );
208 mPlacePolygonBtnGrp->addButton( radInsidePolygon );
209 mPlacePolygonBtnGrp->setExclusive(
true );
215 mScaleDependencyComboBox->addItem( tr(
"Area" ),
true );
216 mScaleDependencyComboBox->addItem( tr(
"Diameter" ),
false );
218 mAngleOffsetComboBox->addItem( tr(
"Top" ), 270 );
219 mAngleOffsetComboBox->addItem( tr(
"Right" ), 0 );
220 mAngleOffsetComboBox->addItem( tr(
"Bottom" ), 90 );
221 mAngleOffsetComboBox->addItem( tr(
"Left" ), 180 );
229 QSizePolicy policy( mDiagramOptionsListFrame->sizePolicy() );
230 policy.setHorizontalStretch( 0 );
231 mDiagramOptionsListFrame->setSizePolicy( policy );
232 if ( !settings.
contains( QStringLiteral(
"/Windows/Diagrams/OptionsSplitState" ) ) )
235 QList<int> splitsizes;
237 mDiagramOptionsSplitter->setSizes( splitsizes );
241 mDiagramOptionsSplitter->restoreState( settings.
value( QStringLiteral(
"Windows/Diagrams/OptionsSplitState" ) ).toByteArray() );
242 mDiagramOptionsListWidget->setCurrentRow( settings.
value( QStringLiteral(
"Windows/Diagrams/Tab" ), 0 ).toInt() );
245 mSizeFieldExpressionWidget->setLayer( mLayer );
249 mSizeFieldExpressionWidget->setGeomCalculator( myDa );
253 for (
int idx = 0; idx < layerFields.
count(); ++idx )
255 QTreeWidgetItem *newItem =
new QTreeWidgetItem( mAttributesTreeWidget );
256 const QString name = QStringLiteral(
"\"%1\"" ).arg( layerFields.
at( idx ).
name() );
257 newItem->setText( 0, name );
258 newItem->setData( 0, RoleAttributeExpression, name );
259 newItem->setFlags( newItem->flags() & ~Qt::ItemIsDropEnabled );
263 mPaintEffect->setEnabled(
false );
286 mDiagramAttributesTreeWidget->clear();
291 mDiagramTypeComboBox->blockSignals(
true );
292 mDiagramTypeComboBox->setCurrentIndex( 0 );
293 mDiagramTypeComboBox->blockSignals(
false );
294 mFixedSizeRadio->setChecked(
true );
297 mLabelPlacementComboBox->setCurrentIndex( mLabelPlacementComboBox->findText( tr(
"x-height" ) ) );
298 mDiagramSizeSpinBox->setEnabled(
true );
299 mDiagramSizeSpinBox->setValue( 15 );
300 mLinearScaleFrame->setEnabled(
false );
301 mIncreaseMinimumSizeSpinBox->setEnabled(
false );
302 mIncreaseMinimumSizeLabel->setEnabled(
false );
303 mBarWidthSpinBox->setValue( 5 );
306 mShowAllCheckBox->setChecked(
true );
307 mCheckBoxAttributeLegend->setChecked(
true );
312 radAroundPoint->setChecked(
true );
316 radAroundLine->setChecked(
true );
317 chkLineAbove->setChecked(
true );
318 chkLineBelow->setChecked(
false );
319 chkLineOn->setChecked(
false );
320 chkLineOrientationDependent->setChecked(
false );
324 radOverCentroid->setChecked(
true );
325 mDiagramDistanceLabel->setEnabled(
false );
326 mDiagramDistanceSpinBox->setEnabled(
false );
327 mDistanceDDBtn->setEnabled(
false );
334 mBackgroundColorButton->setColor( QColor( 255, 255, 255, 255 ) );
342 if ( dr->
rendererName() == QLatin1String(
"SingleCategory" ) )
344 mFixedSizeRadio->setChecked(
true );
348 mAttributeBasedScalingRadio->setChecked(
true );
350 mDiagramSizeSpinBox->setEnabled( mFixedSizeRadio->isChecked() );
351 mLinearScaleFrame->setEnabled( mAttributeBasedScalingRadio->isChecked() );
356 if ( !settingList.isEmpty() )
358 mDiagramFrame->setEnabled( settingList.at( 0 ).enabled );
359 mDiagramFontButton->setCurrentFont( settingList.at( 0 ).font );
360 const QSizeF size = settingList.at( 0 ).size;
361 mBackgroundColorButton->setColor( settingList.at( 0 ).backgroundColor );
362 mOpacityWidget->setOpacity( settingList.at( 0 ).opacity );
363 mDiagramPenColorButton->setColor( settingList.at( 0 ).penColor );
364 mPenWidthSpinBox->setValue( settingList.at( 0 ).penWidth );
365 mDiagramSizeSpinBox->setValue( ( size.width() + size.height() ) / 2.0 );
366 mScaleRangeWidget->setScaleRange( ( settingList.at( 0 ).minimumScale > 0 ? settingList.at( 0 ).minimumScale : mLayer->
minimumScale() ),
367 ( settingList.at( 0 ).maximumScale > 0 ? settingList.at( 0 ).maximumScale : mLayer->
maximumScale() ) );
368 mScaleVisibilityGroupBox->setChecked( settingList.at( 0 ).scaleBasedVisibility );
369 mDiagramUnitComboBox->setUnit( settingList.at( 0 ).sizeType );
370 mDiagramUnitComboBox->setMapUnitScale( settingList.at( 0 ).sizeScale );
371 mDiagramLineUnitComboBox->setUnit( settingList.at( 0 ).lineSizeUnit );
372 mDiagramLineUnitComboBox->setMapUnitScale( settingList.at( 0 ).lineSizeScale );
376 mLabelPlacementComboBox->setCurrentIndex( 0 );
380 mLabelPlacementComboBox->setCurrentIndex( 1 );
383 if ( settingList.at( 0 ).paintEffect() )
384 mPaintEffect.reset( settingList.at( 0 ).paintEffect()->clone() );
386 mAngleOffsetComboBox->setCurrentIndex( mAngleOffsetComboBox->findData( settingList.at( 0 ).rotationOffset ) );
387 mAngleDirectionComboBox->setCurrentIndex( mAngleDirectionComboBox->findData( settingList.at( 0 ).direction() ) );
393 switch ( settingList.at( 0 ).diagramOrientation )
396 mOrientationLeftButton->setChecked(
true );
400 mOrientationRightButton->setChecked(
true );
404 mOrientationUpButton->setChecked(
true );
408 mOrientationDownButton->setChecked(
true );
412 mBarWidthSpinBox->setValue( settingList.at( 0 ).barWidth );
413 mBarSpacingSpinBox->setValue( settingList.at( 0 ).spacing() );
414 mBarSpacingUnitComboBox->setUnit( settingList.at( 0 ).spacingUnit() );
415 mBarSpacingUnitComboBox->setMapUnitScale( settingList.at( 0 ).spacingMapUnitScale() );
417 mShowAxisGroupBox->setChecked( settingList.at( 0 ).showAxis() );
418 if ( settingList.at( 0 ).axisLineSymbol() )
419 mAxisLineStyleButton->setSymbol( settingList.at( 0 ).axisLineSymbol()->clone() );
421 mIncreaseSmallDiagramsCheck->setChecked( settingList.at( 0 ).minimumSize != 0 );
422 mIncreaseMinimumSizeSpinBox->setEnabled( mIncreaseSmallDiagramsCheck->isChecked() );
423 mIncreaseMinimumSizeLabel->setEnabled( mIncreaseSmallDiagramsCheck->isChecked() );
425 mIncreaseMinimumSizeSpinBox->setValue( settingList.at( 0 ).minimumSize );
427 if ( settingList.at( 0 ).scaleByArea )
429 mScaleDependencyComboBox->setCurrentIndex( 0 );
433 mScaleDependencyComboBox->setCurrentIndex( 1 );
436 const QList< QColor > categoryColors = settingList.at( 0 ).categoryColors;
437 const QList< QString > categoryAttributes = settingList.at( 0 ).categoryAttributes;
438 const QList< QString > categoryLabels = settingList.at( 0 ).categoryLabels;
439 QList< QString >::const_iterator catIt = categoryAttributes.constBegin();
440 QList< QColor >::const_iterator coIt = categoryColors.constBegin();
441 QList< QString >::const_iterator labIt = categoryLabels.constBegin();
442 for ( ; catIt != categoryAttributes.constEnd(); ++catIt, ++coIt, ++labIt )
444 QTreeWidgetItem *newItem =
new QTreeWidgetItem( mDiagramAttributesTreeWidget );
445 newItem->setText( 0, *catIt );
446 newItem->setData( 0, RoleAttributeExpression, *catIt );
447 newItem->setFlags( newItem->flags() & ~Qt::ItemIsDropEnabled );
450 newItem->setData( ColumnColor, Qt::EditRole, col );
451 newItem->setText( 2, *labIt );
452 newItem->setFlags( newItem->flags() | Qt::ItemIsEditable );
456 if ( dr->
rendererName() == QLatin1String(
"LinearlyInterpolated" ) )
461 mDiagramSizeSpinBox->setEnabled(
false );
462 mLinearScaleFrame->setEnabled(
true );
463 mMaxValueSpinBox->setValue( lidr->
upperValue() );
464 mSizeSpinBox->setValue( ( lidr->
upperSize().width() + lidr->
upperSize().height() ) / 2 );
481 mDiagramDistanceSpinBox->setValue( dls->
distance() );
482 mPrioritySlider->setValue( dls->
priority() );
483 mZIndexSpinBox->setValue( dls->
zIndex() );
488 radAroundPoint->setChecked(
true );
489 radAroundCentroid->setChecked(
true );
493 radOverPoint->setChecked(
true );
494 radOverCentroid->setChecked(
true );
498 radAroundLine->setChecked(
true );
499 radPolygonPerimeter->setChecked(
true );
503 radOverLine->setChecked(
true );
504 radInsidePolygon->setChecked(
true );
515 chkLineOrientationDependent->setChecked(
true );
527 mDiagramTypeComboBox->blockSignals(
true );
528 mDiagramTypeComboBox->setCurrentIndex( settingList.at( 0 ).enabled ? mDiagramTypeComboBox->findData( mDiagramType ) : 0 );
529 mDiagramTypeComboBox->blockSignals(
false );
532 if ( mDiagramTypeComboBox->currentIndex() == -1 )
534 QMessageBox::warning(
this, tr(
"Diagram Properties" ),
535 tr(
"The diagram type '%1' is unknown. A default type is selected for you." ).arg( mDiagramType ), QMessageBox::Ok );
536 mDiagramTypeComboBox->setCurrentIndex( mDiagramTypeComboBox->findData(
DIAGRAM_NAME_PIE ) );
540 mPaintEffectWidget->setPaintEffect( mPaintEffect.get() );
546 settings.
setValue( QStringLiteral(
"Windows/Diagrams/OptionsSplitState" ), mDiagramOptionsSplitter->saveState() );
547 settings.
setValue( QStringLiteral(
"Windows/Diagrams/Tab" ), mDiagramOptionsListWidget->currentRow() );
558 void QgsDiagramProperties::updateProperty()
569 mDiagramFrame->setEnabled(
false );
573 mDiagramFrame->setEnabled(
true );
575 mDiagramType = mDiagramTypeComboBox->itemData( index ).toString();
579 mTextOptionsFrame->show();
580 mBackgroundColorLabel->show();
581 mBackgroundColorButton->show();
582 mBackgroundColorDDBtn->show();
583 mDiagramFontButton->show();
587 mTextOptionsFrame->hide();
588 mBackgroundColorLabel->hide();
589 mBackgroundColorButton->hide();
590 mBackgroundColorDDBtn->hide();
591 mDiagramFontButton->hide();
596 mBarWidthLabel->show();
597 mBarWidthSpinBox->show();
598 mBarSpacingLabel->show();
599 mBarSpacingSpinBox->show();
600 mBarSpacingUnitComboBox->show();
601 mBarOptionsFrame->show();
602 mShowAxisGroupBox->show();
604 mAttributeBasedScalingRadio->setChecked(
true );
607 mLinearlyScalingLabel->setText( tr(
"Bar length: Scale linearly, so that the following value matches the specified bar length:" ) );
608 mSizeLabel->setText( tr(
"Bar length" ) );
609 mFrameIncreaseSize->setVisible(
false );
613 mBarWidthLabel->hide();
614 mBarWidthSpinBox->hide();
615 mBarSpacingLabel->hide();
616 mBarSpacingSpinBox->hide();
617 mBarSpacingUnitComboBox->hide();
618 mShowAxisGroupBox->hide();
619 mBarOptionsFrame->hide();
620 mLinearlyScalingLabel->setText( tr(
"Scale linearly between 0 and the following attribute value / diagram size:" ) );
621 mSizeLabel->setText( tr(
"Size" ) );
622 mAttributeBasedScalingRadio->setEnabled(
true );
623 mFixedSizeRadio->setEnabled(
true );
624 mDiagramSizeSpinBox->setEnabled( mFixedSizeRadio->isChecked() );
625 mFrameIncreaseSize->setVisible(
true );
630 mScaleDependencyComboBox->show();
631 mScaleDependencyLabel->show();
635 mScaleDependencyComboBox->hide();
636 mScaleDependencyLabel->hide();
641 mAngleOffsetComboBox->show();
642 mAngleDirectionComboBox->show();
643 mAngleDirectionLabel->show();
644 mAngleOffsetLabel->show();
645 mStartAngleDDBtn->show();
649 mAngleOffsetComboBox->hide();
650 mAngleDirectionComboBox->hide();
651 mAngleDirectionLabel->hide();
652 mAngleOffsetLabel->hide();
653 mStartAngleDDBtn->hide();
657 QString QgsDiagramProperties::guessLegendText(
const QString &expression )
660 QString text = expression.mid( expression.startsWith(
'\"' ) ? 1 : 0 );
661 if ( text.endsWith(
'\"' ) )
668 QTreeWidgetItem *newItem =
new QTreeWidgetItem( mDiagramAttributesTreeWidget );
670 newItem->setText( 0, item->text( 0 ) );
671 newItem->setText( 2, guessLegendText( item->text( 0 ) ) );
672 newItem->setData( 0, RoleAttributeExpression, item->data( 0, RoleAttributeExpression ) );
673 newItem->setFlags( ( newItem->flags() | Qt::ItemIsEditable ) & ~Qt::ItemIsDropEnabled );
676 QRandomGenerator colorGenerator;
677 const int red = colorGenerator.bounded( 1, 256 );
678 const int green = colorGenerator.bounded( 1, 256 );
679 const int blue = colorGenerator.bounded( 1, 256 );
680 const QColor randomColor( red, green, blue );
681 newItem->setData( ColumnColor, Qt::EditRole, randomColor );
682 mDiagramAttributesTreeWidget->addTopLevelItem( newItem );
687 const auto constSelectedItems = mAttributesTreeWidget->selectedItems();
688 for ( QTreeWidgetItem *attributeItem : constSelectedItems )
702 const auto constSelectedItems = mDiagramAttributesTreeWidget->selectedItems();
703 for ( QTreeWidgetItem *attributeItem : constSelectedItems )
705 delete attributeItem;
714 float maxValue = 0.0;
717 const QString sizeFieldNameOrExp = mSizeFieldExpressionWidget->currentField( &isExpression );
735 maxValue = std::max( maxValue, exp.
evaluate( &context ).toFloat() );
746 maxValue = mLayer->
maximumValue( attributeNumber ).toFloat();
749 mMaxValueSpinBox->setValue( maxValue );
756 case ColumnAttributeExpression:
758 const QString currentExpression = item->data( 0, RoleAttributeExpression ).toString();
760 const QString newExpression = showExpressionBuilder( currentExpression );
761 if ( !newExpression.isEmpty() )
763 item->setData( 0, Qt::DisplayRole, newExpression );
764 item->setData( 0, RoleAttributeExpression, newExpression );
772 case ColumnLegendText:
797 const int index = mDiagramTypeComboBox->currentIndex();
798 const bool diagramsEnabled = ( index != 0 );
800 std::unique_ptr< QgsDiagram > diagram;
802 if ( diagramsEnabled && 0 == mDiagramAttributesTreeWidget->topLevelItemCount() )
804 QMessageBox::warning(
this, tr(
"Diagrams: No attributes added." ),
805 tr(
"You did not add any attributes to this diagram layer. Please specify the attributes to visualize on the diagrams or disable diagrams." ) );
810 diagram = std::make_unique< QgsTextDiagram >();
814 diagram = std::make_unique< QgsPieDiagram >();
818 diagram = std::make_unique< QgsStackedBarDiagram >();
822 diagram = std::make_unique< QgsHistogramDiagram >();
826 ds.
enabled = ( mDiagramTypeComboBox->currentIndex() != 0 );
827 ds.
font = mDiagramFontButton->currentFont();
828 ds.
opacity = mOpacityWidget->opacity();
830 QList<QColor> categoryColors;
831 QList<QString> categoryAttributes;
832 QList<QString> categoryLabels;
833 categoryColors.reserve( mDiagramAttributesTreeWidget->topLevelItemCount() );
834 categoryAttributes.reserve( mDiagramAttributesTreeWidget->topLevelItemCount() );
835 categoryLabels.reserve( mDiagramAttributesTreeWidget->topLevelItemCount() );
836 for (
int i = 0; i < mDiagramAttributesTreeWidget->topLevelItemCount(); ++i )
838 QColor color = mDiagramAttributesTreeWidget->topLevelItem( i )->data( ColumnColor, Qt::EditRole ).value<QColor>();
840 categoryColors.append( color );
841 categoryAttributes.append( mDiagramAttributesTreeWidget->topLevelItem( i )->data( 0, RoleAttributeExpression ).toString() );
842 categoryLabels.append( mDiagramAttributesTreeWidget->topLevelItem( i )->text( 2 ) );
847 ds.
size = QSizeF( mDiagramSizeSpinBox->value(), mDiagramSizeSpinBox->value() );
848 ds.
sizeType = mDiagramUnitComboBox->unit();
849 ds.
sizeScale = mDiagramUnitComboBox->getMapUnitScale();
851 ds.
lineSizeScale = mDiagramLineUnitComboBox->getMapUnitScale();
855 if ( mIncreaseSmallDiagramsCheck->isChecked() )
857 ds.
minimumSize = mIncreaseMinimumSizeSpinBox->value();
865 ds.
penColor = mDiagramPenColorButton->color();
866 ds.
penWidth = mPenWidthSpinBox->value();
878 ds.
barWidth = mBarWidthSpinBox->value();
893 if ( mFixedSizeRadio->isChecked() )
905 dr->
setUpperSize( QSizeF( mSizeSpinBox->value(), mSizeSpinBox->value() ) );
908 const QString sizeFieldNameOrExp = mSizeFieldExpressionWidget->currentField( &isExpression );
930 dls.
setDistance( mDiagramDistanceSpinBox->value() );
932 dls.
setZIndex( mZIndexSpinBox->value() );
935 QWidget *curWdgt = stackedPlacement->currentWidget();
936 if ( ( curWdgt == pagePoint && radAroundPoint->isChecked() )
937 || ( curWdgt == pagePolygon && radAroundCentroid->isChecked() ) )
941 else if ( ( curWdgt == pagePoint && radOverPoint->isChecked() )
942 || ( curWdgt == pagePolygon && radOverCentroid->isChecked() ) )
946 else if ( ( curWdgt == pageLine && radAroundLine->isChecked() )
947 || ( curWdgt == pagePolygon && radPolygonPerimeter->isChecked() ) )
951 else if ( ( curWdgt == pageLine && radOverLine->isChecked() )
952 || ( curWdgt == pagePolygon && radInsidePolygon->isChecked() ) )
958 qFatal(
"Invalid settings" );
961 QgsDiagramLayerSettings::LinePlacementFlags flags = QgsDiagramLayerSettings::LinePlacementFlags();
962 if ( chkLineAbove->isChecked() )
964 if ( chkLineBelow->isChecked() )
966 if ( chkLineOn->isChecked() )
968 if ( ! chkLineOrientationDependent->isChecked() )
979 QString QgsDiagramProperties::showExpressionBuilder(
const QString &initialExpression )
989 dlg.setWindowTitle( tr(
"Expression Based Attribute" ) );
994 dlg.setGeomCalculator( myDa );
996 if ( dlg.exec() == QDialog::Accepted )
998 return dlg.expressionText();
1009 QList<QTreeWidgetItem *> selections = mAttributesTreeWidget->selectedItems();
1010 if ( !selections.empty() )
1012 expression = selections[0]->text( 0 );
1015 const QString newExpression = showExpressionBuilder( expression );
1018 if ( !newExpression.isEmpty() )
1020 QTreeWidgetItem *newItem =
new QTreeWidgetItem( mDiagramAttributesTreeWidget );
1022 newItem->setText( 0, newExpression );
1023 newItem->setText( 2, newExpression );
1024 newItem->setData( 0, RoleAttributeExpression, newExpression );
1025 newItem->setFlags( ( newItem->flags() | Qt::ItemIsEditable ) & ~Qt::ItemIsDropEnabled );
1028 QRandomGenerator colorGenerator;
1029 const int red = colorGenerator.bounded( 1, 256 );
1030 const int green = colorGenerator.bounded( 1, 256 );
1031 const int blue = colorGenerator.bounded( 1, 256 );
1033 const QColor randomColor( red, green, blue );
1034 newItem->setData( ColumnColor, Qt::EditRole, randomColor );
1035 mDiagramAttributesTreeWidget->addTopLevelItem( newItem );
1042 mDiagramOptionsListWidget->blockSignals(
true );
1043 mDiagramOptionsListWidget->setCurrentRow( index );
1044 mDiagramOptionsListWidget->blockSignals(
false );
1049 QWidget *curWdgt = stackedPlacement->currentWidget();
1051 if ( ( curWdgt == pagePoint && radAroundPoint->isChecked() )
1052 || ( curWdgt == pageLine && radAroundLine->isChecked() )
1053 || ( curWdgt == pagePolygon && radAroundCentroid->isChecked() ) )
1055 mDiagramDistanceLabel->setEnabled(
true );
1056 mDiagramDistanceSpinBox->setEnabled(
true );
1057 mDistanceDDBtn->setEnabled(
true );
1061 mDiagramDistanceLabel->setEnabled(
false );
1062 mDiagramDistanceSpinBox->setEnabled(
false );
1063 mDistanceDDBtn->setEnabled(
false );
1067 chkLineAbove->setEnabled( linePlacementEnabled );
1068 chkLineBelow->setEnabled( linePlacementEnabled );
1069 chkLineOn->setEnabled( linePlacementEnabled );
1070 chkLineOrientationDependent->setEnabled( linePlacementEnabled );
1075 mButtonSizeLegendSettings->setEnabled( mAttributeBasedScalingRadio->isChecked() );
1082 const QString sizeFieldNameOrExp = mSizeFieldExpressionWidget->currentField( &isExpression );
1084 const bool scaleByArea = mScaleDependencyComboBox->currentData().toBool();
1086 0.0, mMaxValueSpinBox->value(), 0.0, mSizeSpinBox->value() ) );
1091 dlg.setLayout(
new QVBoxLayout() );
1093 dlg.layout()->addWidget( panel );
1094 QDialogButtonBox *buttonBox =
new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok );
1095 connect( buttonBox, &QDialogButtonBox::accepted, &dlg, &QDialog::accept );
1096 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, &QgsDiagramProperties::showHelp );
1097 connect( buttonBox, &QDialogButtonBox::rejected, &dlg, &QDialog::reject );
1098 dlg.layout()->addWidget( buttonBox );
1103 void QgsDiagramProperties::showHelp()
1105 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#legend" ) );
1108 void QgsDiagramProperties::createAuxiliaryField()
1132 property.setActive(
true );
EditBlockerDelegate(QObject *parent=nullptr)
QWidget * createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const override
static const double UI_SCALE_FACTOR
UI scaling factor.
static QPixmap getThemePixmap(const QString &name, const QColor &foreColor=QColor(), const QColor &backColor=QColor(), int size=16)
Helper to get a theme icon as a pixmap.
bool addAuxiliaryField(const QgsPropertyDefinition &definition)
Adds an auxiliary field for the given property.
static QString nameFromProperty(const QgsPropertyDefinition &def, bool joined=false)
Returns the name of the auxiliary field for a property definition.
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.
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.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the diagram's property collection, used for data defined overrides.
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
void setAttributeLegend(bool enabled)
Sets whether the renderer will show legend items for diagram attributes.
QgsDiagram * diagram() const
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.
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.
const QgsDiagramLayerSettings * diagramLayerSettings() const
QgsAuxiliaryLayer * auxiliaryLayer()
Returns the current auxiliary layer.
void setDiagramLayerSettings(const QgsDiagramLayerSettings &s)
const QgsDiagramRenderer * diagramRenderer() const
void setDiagramRenderer(QgsDiagramRenderer *r)
Sets diagram rendering object (takes ownership)
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