32 , mDefinition( definition )
37 layout()->setContentsMargins( 0, 0, 0, 0 );
38 layout()->setMargin( 0 );
42 mLegendPreview->hide();
44 minValueSpinBox->setShowClearButton(
false );
45 maxValueSpinBox->setShowClearButton(
false );
48 mExpressionWidget->setLayer(
const_cast< QgsVectorLayer *
>( mLayer ) );
59 mTransformCurveCheckBox->setChecked(
true );
60 mTransformCurveCheckBox->setCollapsed(
false );
65 connect( computeValuesButton, &QPushButton::clicked,
this, &QgsPropertyAssistantWidget::computeValuesFromLayer );
72 mLegendPreview->setModel( &mPreviewList );
73 mLegendPreview->setItemDelegate(
new QgsAssistantPreviewItemDelegate( &mPreviewList ) );
74 mLegendPreview->setHeaderHidden(
true );
75 mLegendPreview->expandAll();
76 mLegendVerticalFrame->setLayout(
new QVBoxLayout() );
77 mLegendVerticalFrame->layout()->setContentsMargins( 0, 0, 0, 0 );
78 mLegendVerticalFrame->layout()->setMargin( 0 );
79 mLegendVerticalFrame->hide();
86 mTransformerWidget =
new QgsPropertySizeAssistantWidget(
this, mDefinition, initialState );
87 mLegendPreview->show();
94 mTransformerWidget =
new QgsPropertyColorAssistantWidget(
this, mDefinition, initialState );
95 mLegendPreview->show();
101 mTransformerWidget =
new QgsPropertyGenericNumericAssistantWidget(
this, mDefinition, initialState );
109 mTransformerWidget =
new QgsPropertyGenericNumericAssistantWidget(
this, mDefinition, initialState );
115 if ( mTransformerWidget )
117 mOutputWidget->layout()->addWidget( mTransformerWidget );
120 mCurveEditor->setMinHistogramValueRange( minValueSpinBox->value() );
121 mCurveEditor->setMaxHistogramValueRange( maxValueSpinBox->value() );
123 mCurveEditor->setHistogramSource( mLayer, mExpressionWidget->currentField() );
126 mCurveEditor->setHistogramSource( mLayer, expression );
132 mTransformCurveCheckBox->setVisible( mTransformerWidget );
144 mExpressionContextGenerator = generator;
145 mExpressionWidget->registerExpressionContextGenerator( generator );
150 property.setActive( !mExpressionWidget->currentText().isEmpty() );
151 if ( mExpressionWidget->isExpression() )
152 property.setExpressionString( mExpressionWidget->currentField() );
154 property.setField( mExpressionWidget->currentField() );
156 if ( mTransformerWidget )
158 std::unique_ptr< QgsPropertyTransformer> t( mTransformerWidget->createTransformer( minValueSpinBox->value(), maxValueSpinBox->value() ) );
159 if ( mTransformCurveCheckBox->isChecked() )
165 t->setCurveTransform(
nullptr );
167 property.setTransformer( t.release() );
175 if (
dockMode && mLegendVerticalFrame->isHidden() )
177 mLegendVerticalFrame->layout()->addWidget( mLegendPreview );
178 mLegendVerticalFrame->show();
182 void QgsPropertyAssistantWidget::computeValuesFromLayer()
187 double minValue = 0.0;
188 double maxValue = 0.0;
190 if ( mExpressionWidget->isExpression() )
192 if ( !computeValuesFromExpression( mExpressionWidget->currentField(), minValue, maxValue ) )
197 if ( !computeValuesFromField( mExpressionWidget->currentField(), minValue, maxValue ) )
204 mCurveEditor->setMinHistogramValueRange( minValueSpinBox->value() );
205 mCurveEditor->setMaxHistogramValueRange( maxValueSpinBox->value() );
210 void QgsPropertyAssistantWidget::updatePreview()
212 if ( mLegendPreview->isHidden() || !mTransformerWidget || !mLayer )
215 mLegendPreview->setIconSize( QSize( 512, 512 ) );
216 mPreviewList.clear();
219 maxValueSpinBox->value(), 8 );
222 QList< QgsSymbolLegendNode * > nodes = mTransformerWidget->generatePreviews( breaks, mLayerTreeLayer, mSymbol.get(), minValueSpinBox->value(),
223 maxValueSpinBox->value(), mTransformCurveCheckBox->isChecked() ? &curve :
nullptr );
227 const auto constNodes = nodes;
230 const QSize minSize( node->minimumIconSize() );
231 node->setIconSize( minSize );
232 widthMax = std::max( minSize.width(), widthMax );
233 QStandardItem *item =
new QStandardItem( node->data( Qt::DecorationRole ).value<QPixmap>(), QString::number( breaks[i] ) );
234 item->setEditable(
false );
235 mPreviewList.appendRow( item );
241 for (
int i = 0; i < breaks.length(); i++ )
243 QPixmap img( mPreviewList.item( i )->icon().pixmap( mPreviewList.item( i )->icon().actualSize( QSize( 512, 512 ) ) ) );
244 QPixmap enlarged( widthMax, img.height() );
246 enlarged.fill( Qt::transparent );
247 QPainter p( &enlarged );
248 p.drawPixmap( QPoint( ( widthMax - img.width() ) / 2, 0 ), img );
250 mPreviewList.item( i )->setIcon( enlarged );
254 bool QgsPropertyAssistantWidget::computeValuesFromExpression(
const QString &expression,
double &minValue,
double &maxValue )
const
259 if ( mExpressionContextGenerator )
270 if ( !e.prepare( &context ) )
273 QSet<QString> referencedCols( e.referencedColumns() );
282 double min = std::numeric_limits<double>::max();
283 double max = std::numeric_limits<double>::lowest();
290 const double value = e.evaluate( &context ).toDouble( &ok );
293 max = std::max( max, value );
294 min = std::min( min, value );
306 bool QgsPropertyAssistantWidget::computeValuesFromField(
const QString &fieldName,
double &minValue,
double &maxValue )
const
309 if ( fieldIndex < 0 )
315 double minDouble = mLayer->
minimumValue( fieldIndex ).toDouble( &ok );
319 double maxDouble = mLayer->
maximumValue( fieldIndex ).toDouble( &ok );
323 minValue = minDouble;
324 maxValue = maxDouble;
335 : QgsPropertyAbstractTransformerWidget( parent, definition )
339 layout()->setContentsMargins( 0, 0, 0, 0 );
340 layout()->setMargin( 0 );
355 minSizeSpinBox->setShowClearButton(
false );
356 maxSizeSpinBox->setShowClearButton(
false );
357 nullSizeSpinBox->setShowClearButton(
false );
361 minSizeSpinBox->setValue( sizeTransform->minSize() );
362 maxSizeSpinBox->setValue( sizeTransform->maxSize() );
363 nullSizeSpinBox->setValue( sizeTransform->nullSize() );
364 exponentSpinBox->setValue( sizeTransform->exponent() );
365 scaleMethodComboBox->setCurrentIndex( scaleMethodComboBox->findData( sizeTransform->type() ) );
370 connect( minSizeSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
371 connect( maxSizeSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
372 connect( nullSizeSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
373 connect( exponentSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
374 connect( scaleMethodComboBox,
static_cast < void ( QComboBox::* )(
int )
> ( &QComboBox::currentIndexChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
375 connect( scaleMethodComboBox,
static_cast < void ( QComboBox::* )(
int )
> ( &QComboBox::currentIndexChanged ),
this,
383 QgsSizeScaleTransformer *QgsPropertySizeAssistantWidget::createTransformer(
double minValue,
double maxValue )
const
389 minSizeSpinBox->value(),
390 maxSizeSpinBox->value(),
391 nullSizeSpinBox->value(),
392 exponentSpinBox->value() );
396 QList< QgsSymbolLegendNode * > QgsPropertySizeAssistantWidget::generatePreviews(
const QList<double> &breaks,
QgsLayerTreeLayer *parent,
const QgsSymbol *symbol,
double minValue,
double maxValue,
QgsCurveTransform *curve )
const
398 QList< QgsSymbolLegendNode * > nodes;
401 std::unique_ptr< QgsSymbol > tempSymbol;
413 legendSymbol = tempSymbol.get();
418 std::unique_ptr< QgsSizeScaleTransformer > t( createTransformer( minValue, maxValue ) );
422 for (
int i = 0; i < breaks.length(); i++ )
424 std::unique_ptr< QgsSymbolLegendNode > node;
427 std::unique_ptr< QgsMarkerSymbol > symbolClone(
static_cast<QgsMarkerSymbol *
>( legendSymbol->
clone() ) );
430 symbolClone->setSize( t->size( breaks[i] ) );
433 else if (
dynamic_cast<const QgsLineSymbol *
>( legendSymbol ) )
435 std::unique_ptr< QgsLineSymbol > symbolClone(
static_cast<QgsLineSymbol *
>( legendSymbol->
clone() ) );
437 symbolClone->setWidth( t->size( breaks[i] ) );
441 nodes << node.release();
448 return QList< QgsSymbolLegendNode * >();
451 QgsPropertyColorAssistantWidget::QgsPropertyColorAssistantWidget( QWidget *parent,
const QgsPropertyDefinition &definition,
const QgsProperty &initialState )
452 : QgsPropertyAbstractTransformerWidget( parent, definition )
456 layout()->setContentsMargins( 0, 0, 0, 0 );
457 layout()->setMargin( 0 );
460 mNullColorButton->setAllowOpacity( supportsAlpha );
461 mNullColorButton->setShowNoColor(
true );
462 mNullColorButton->setColorDialogTitle( tr(
"Color For Null Values" ) );
463 mNullColorButton->setContext( QStringLiteral(
"symbology" ) );
464 mNullColorButton->setNoColorString( tr(
"Transparent" ) );
468 mNullColorButton->setColor( colorTransform->nullColor() );
469 if ( colorTransform->colorRamp() )
470 mColorRampButton->setColorRamp( colorTransform->colorRamp() );
476 if ( !mColorRampButton->colorRamp() )
480 std::unique_ptr< QgsColorRamp > defaultRamp(
QgsStyle::defaultStyle()->colorRamp( !defaultRampName.isEmpty() ? defaultRampName : QStringLiteral(
"Blues" ) ) );
482 mColorRampButton->setColorRamp( defaultRamp.get() );
486 QgsColorRampTransformer *QgsPropertyColorAssistantWidget::createTransformer(
double minValue,
double maxValue )
const
491 mColorRampButton->colorRamp(),
492 mNullColorButton->color() );
496 QList<QgsSymbolLegendNode *> QgsPropertyColorAssistantWidget::generatePreviews(
const QList<double> &breaks,
QgsLayerTreeLayer *parent,
const QgsSymbol *symbol,
double minValue,
double maxValue,
QgsCurveTransform *curve )
const
498 QList< QgsSymbolLegendNode * > nodes;
501 std::unique_ptr< QgsMarkerSymbol > tempSymbol;
506 legendSymbol = tempSymbol.get();
511 std::unique_ptr< QgsColorRampTransformer > t( createTransformer( minValue, maxValue ) );
515 for (
int i = 0; i < breaks.length(); i++ )
517 std::unique_ptr< QgsSymbolLegendNode > node;
518 std::unique_ptr< QgsMarkerSymbol > symbolClone(
static_cast<QgsMarkerSymbol *
>( legendSymbol->
clone() ) );
519 symbolClone->setColor( t->color( breaks[i] ) );
522 nodes << node.release();
527 QgsPropertyGenericNumericAssistantWidget::QgsPropertyGenericNumericAssistantWidget( QWidget *parent,
const QgsPropertyDefinition &definition,
const QgsProperty &initialState )
528 : QgsPropertyAbstractTransformerWidget( parent, definition )
532 layout()->setContentsMargins( 0, 0, 0, 0 );
533 layout()->setMargin( 0 );
535 nullOutputSpinBox->setShowClearButton(
false );
540 minOutputSpinBox->setMaximum( 360.0 );
541 minOutputSpinBox->setValue( 0.0 );
542 minOutputSpinBox->setShowClearButton(
true );
543 minOutputSpinBox->setClearValue( 0.0 );
544 minOutputSpinBox->setSuffix( tr(
" °" ) );
545 maxOutputSpinBox->setMaximum( 360.0 );
546 maxOutputSpinBox->setValue( 360.0 );
547 maxOutputSpinBox->setShowClearButton(
true );
548 maxOutputSpinBox->setClearValue( 360.0 );
549 maxOutputSpinBox->setSuffix( tr(
" °" ) );
550 exponentSpinBox->hide();
551 mExponentLabel->hide();
552 mLabelMinOutput->setText( tr(
"Angle from" ) );
553 mLabelNullOutput->setText( tr(
"Angle when NULL" ) );
557 minOutputSpinBox->setShowClearButton(
false );
558 maxOutputSpinBox->setShowClearButton(
false );
563 minOutputSpinBox->setValue( transform->minOutputValue() );
564 maxOutputSpinBox->setValue( transform->maxOutputValue() );
565 nullOutputSpinBox->setValue( transform->nullOutputValue() );
566 exponentSpinBox->setValue( transform->exponent() );
569 connect( minOutputSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
570 connect( maxOutputSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
571 connect( nullOutputSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
572 connect( exponentSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
580 minOutputSpinBox->value(),
581 maxOutputSpinBox->value(),
582 nullOutputSpinBox->value(),
583 exponentSpinBox->value() );