32 , mDefinition( definition )
37 layout()->setContentsMargins( 0, 0, 0, 0 );
41 mLegendPreview->hide();
43 minValueSpinBox->setShowClearButton(
false );
44 maxValueSpinBox->setShowClearButton(
false );
47 mExpressionWidget->setLayer(
const_cast< QgsVectorLayer *
>( mLayer ) );
51 if (
auto *lTransformer = initialState.
transformer() )
53 minValueSpinBox->setValue( lTransformer->minValue() );
54 maxValueSpinBox->setValue( lTransformer->maxValue() );
56 if ( lTransformer->curveTransform() )
58 mTransformCurveCheckBox->setChecked(
true );
59 mTransformCurveCheckBox->setCollapsed(
false );
60 mCurveEditor->setCurve( *lTransformer->curveTransform() );
64 connect( computeValuesButton, &QPushButton::clicked,
this, &QgsPropertyAssistantWidget::computeValuesFromLayer );
71 mLegendPreview->setModel( &mPreviewList );
72 mLegendPreview->setItemDelegate(
new QgsAssistantPreviewItemDelegate( &mPreviewList ) );
73 mLegendPreview->setHeaderHidden(
true );
74 mLegendPreview->expandAll();
75 mLegendVerticalFrame->setLayout(
new QVBoxLayout() );
76 mLegendVerticalFrame->layout()->setContentsMargins( 0, 0, 0, 0 );
77 mLegendVerticalFrame->hide();
84 mTransformerWidget =
new QgsPropertySizeAssistantWidget(
this, mDefinition, initialState );
85 mLegendPreview->show();
92 mTransformerWidget =
new QgsPropertyColorAssistantWidget(
this, mDefinition, initialState );
93 mLegendPreview->show();
99 mTransformerWidget =
new QgsPropertyGenericNumericAssistantWidget(
this, mDefinition, initialState );
107 mTransformerWidget =
new QgsPropertyGenericNumericAssistantWidget(
this, mDefinition, initialState );
113 if ( mTransformerWidget )
115 mOutputWidget->layout()->addWidget( mTransformerWidget );
118 mCurveEditor->setMinHistogramValueRange( minValueSpinBox->value() );
119 mCurveEditor->setMaxHistogramValueRange( maxValueSpinBox->value() );
121 mCurveEditor->setHistogramSource( mLayer, mExpressionWidget->currentField() );
124 mCurveEditor->setHistogramSource( mLayer, expression );
130 mTransformCurveCheckBox->setVisible( mTransformerWidget );
142 mExpressionContextGenerator = generator;
143 mExpressionWidget->registerExpressionContextGenerator( generator );
148 property.setActive( !mExpressionWidget->currentText().isEmpty() );
149 if ( mExpressionWidget->isExpression() )
150 property.setExpressionString( mExpressionWidget->currentField() );
152 property.setField( mExpressionWidget->currentField() );
154 if ( mTransformerWidget )
156 std::unique_ptr< QgsPropertyTransformer> t( mTransformerWidget->createTransformer( minValueSpinBox->value(), maxValueSpinBox->value() ) );
157 if ( mTransformCurveCheckBox->isChecked() )
163 t->setCurveTransform(
nullptr );
165 property.setTransformer( t.release() );
173 if (
dockMode && mLegendVerticalFrame->isHidden() )
175 mLegendVerticalFrame->layout()->addWidget( mLegendPreview );
176 mLegendVerticalFrame->show();
180 void QgsPropertyAssistantWidget::computeValuesFromLayer()
185 double minValue = 0.0;
186 double maxValue = 0.0;
188 if ( mExpressionWidget->isExpression() )
190 if ( !computeValuesFromExpression( mExpressionWidget->currentField(), minValue, maxValue ) )
195 if ( !computeValuesFromField( mExpressionWidget->currentField(), minValue, maxValue ) )
202 mCurveEditor->setMinHistogramValueRange( minValueSpinBox->value() );
203 mCurveEditor->setMaxHistogramValueRange( maxValueSpinBox->value() );
208 void QgsPropertyAssistantWidget::updatePreview()
210 if ( mLegendPreview->isHidden() || !mTransformerWidget || !mLayer )
213 mLegendPreview->setIconSize( QSize( 512, 512 ) );
214 mPreviewList.clear();
217 maxValueSpinBox->value(), 8 );
220 QList< QgsSymbolLegendNode * > nodes = mTransformerWidget->generatePreviews( breaks, mLayerTreeLayer, mSymbol.get(), minValueSpinBox->value(),
221 maxValueSpinBox->value(), mTransformCurveCheckBox->isChecked() ? &curve :
nullptr );
225 const auto constNodes = nodes;
228 const QSize minSize( node->minimumIconSize() );
229 node->setIconSize( minSize );
230 widthMax = std::max( minSize.width(), widthMax );
231 QStandardItem *item =
new QStandardItem( node->data( Qt::DecorationRole ).value<QPixmap>(), QString::number( breaks[i] ) );
232 item->setEditable(
false );
233 mPreviewList.appendRow( item );
239 for (
int i = 0; i < breaks.length(); i++ )
241 QPixmap img( mPreviewList.item( i )->icon().pixmap( mPreviewList.item( i )->icon().actualSize( QSize( 512, 512 ) ) ) );
242 QPixmap enlarged( widthMax, img.height() );
244 enlarged.fill( Qt::transparent );
245 QPainter p( &enlarged );
246 p.drawPixmap( QPoint( ( widthMax - img.width() ) / 2, 0 ), img );
248 mPreviewList.item( i )->setIcon( enlarged );
252 bool QgsPropertyAssistantWidget::computeValuesFromExpression(
const QString &expression,
double &minValue,
double &maxValue )
const
257 if ( mExpressionContextGenerator )
268 if ( !e.prepare( &context ) )
271 QSet<QString> referencedCols( e.referencedColumns() );
280 double min = std::numeric_limits<double>::max();
281 double max = std::numeric_limits<double>::lowest();
288 const double value = e.evaluate( &context ).toDouble( &ok );
291 max = std::max( max, value );
292 min = std::min( min, value );
304 bool QgsPropertyAssistantWidget::computeValuesFromField(
const QString &fieldName,
double &minValue,
double &maxValue )
const
307 if ( fieldIndex < 0 )
313 double minDouble = mLayer->
minimumValue( fieldIndex ).toDouble( &ok );
317 double maxDouble = mLayer->
maximumValue( fieldIndex ).toDouble( &ok );
321 minValue = minDouble;
322 maxValue = maxDouble;
333 : QgsPropertyAbstractTransformerWidget( parent, definition )
337 layout()->setContentsMargins( 0, 0, 0, 0 );
352 minSizeSpinBox->setShowClearButton(
false );
353 maxSizeSpinBox->setShowClearButton(
false );
354 nullSizeSpinBox->setShowClearButton(
false );
358 minSizeSpinBox->setValue( sizeTransform->minSize() );
359 maxSizeSpinBox->setValue( sizeTransform->maxSize() );
360 nullSizeSpinBox->setValue( sizeTransform->nullSize() );
361 exponentSpinBox->setValue( sizeTransform->exponent() );
362 scaleMethodComboBox->setCurrentIndex( scaleMethodComboBox->findData( sizeTransform->type() ) );
367 connect( minSizeSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
368 connect( maxSizeSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
369 connect( nullSizeSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
370 connect( exponentSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
371 connect( scaleMethodComboBox,
static_cast < void ( QComboBox::* )(
int )
> ( &QComboBox::currentIndexChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
372 connect( scaleMethodComboBox,
static_cast < void ( QComboBox::* )(
int )
> ( &QComboBox::currentIndexChanged ),
this,
380 QgsSizeScaleTransformer *QgsPropertySizeAssistantWidget::createTransformer(
double minValue,
double maxValue )
const
386 minSizeSpinBox->value(),
387 maxSizeSpinBox->value(),
388 nullSizeSpinBox->value(),
389 exponentSpinBox->value() );
393 QList< QgsSymbolLegendNode * > QgsPropertySizeAssistantWidget::generatePreviews(
const QList<double> &breaks,
QgsLayerTreeLayer *parent,
const QgsSymbol *symbol,
double minValue,
double maxValue,
QgsCurveTransform *curve )
const
395 QList< QgsSymbolLegendNode * > nodes;
398 std::unique_ptr< QgsSymbol > tempSymbol;
410 legendSymbol = tempSymbol.get();
415 std::unique_ptr< QgsSizeScaleTransformer > t( createTransformer( minValue, maxValue ) );
419 for (
int i = 0; i < breaks.length(); i++ )
421 std::unique_ptr< QgsSymbolLegendNode > node;
424 std::unique_ptr< QgsMarkerSymbol > symbolClone(
static_cast<QgsMarkerSymbol *
>( legendSymbol->
clone() ) );
427 symbolClone->setSize( t->size( breaks[i] ) );
430 else if (
dynamic_cast<const QgsLineSymbol *
>( legendSymbol ) )
432 std::unique_ptr< QgsLineSymbol > symbolClone(
static_cast<QgsLineSymbol *
>( legendSymbol->
clone() ) );
434 symbolClone->setWidth( t->size( breaks[i] ) );
438 nodes << node.release();
445 return QList< QgsSymbolLegendNode * >();
448 QgsPropertyColorAssistantWidget::QgsPropertyColorAssistantWidget( QWidget *parent,
const QgsPropertyDefinition &definition,
const QgsProperty &initialState )
449 : QgsPropertyAbstractTransformerWidget( parent, definition )
453 layout()->setContentsMargins( 0, 0, 0, 0 );
456 mNullColorButton->setAllowOpacity( supportsAlpha );
457 mNullColorButton->setShowNoColor(
true );
458 mNullColorButton->setColorDialogTitle( tr(
"Color For Null Values" ) );
459 mNullColorButton->setContext( QStringLiteral(
"symbology" ) );
460 mNullColorButton->setNoColorString( tr(
"Transparent" ) );
464 mNullColorButton->setColor( colorTransform->nullColor() );
465 if ( colorTransform->colorRamp() )
466 mColorRampButton->setColorRamp( colorTransform->colorRamp() );
472 if ( !mColorRampButton->colorRamp() )
476 std::unique_ptr< QgsColorRamp > defaultRamp(
QgsStyle::defaultStyle()->colorRamp( !defaultRampName.isEmpty() ? defaultRampName : QStringLiteral(
"Blues" ) ) );
478 mColorRampButton->setColorRamp( defaultRamp.get() );
482 QgsColorRampTransformer *QgsPropertyColorAssistantWidget::createTransformer(
double minValue,
double maxValue )
const
487 mColorRampButton->colorRamp(),
488 mNullColorButton->color() );
492 QList<QgsSymbolLegendNode *> QgsPropertyColorAssistantWidget::generatePreviews(
const QList<double> &breaks,
QgsLayerTreeLayer *parent,
const QgsSymbol *symbol,
double minValue,
double maxValue,
QgsCurveTransform *curve )
const
494 QList< QgsSymbolLegendNode * > nodes;
497 std::unique_ptr< QgsMarkerSymbol > tempSymbol;
502 legendSymbol = tempSymbol.get();
507 std::unique_ptr< QgsColorRampTransformer > t( createTransformer( minValue, maxValue ) );
511 for (
int i = 0; i < breaks.length(); i++ )
513 std::unique_ptr< QgsSymbolLegendNode > node;
514 std::unique_ptr< QgsMarkerSymbol > symbolClone(
static_cast<QgsMarkerSymbol *
>( legendSymbol->
clone() ) );
515 symbolClone->setColor( t->color( breaks[i] ) );
518 nodes << node.release();
523 QgsPropertyGenericNumericAssistantWidget::QgsPropertyGenericNumericAssistantWidget( QWidget *parent,
const QgsPropertyDefinition &definition,
const QgsProperty &initialState )
524 : QgsPropertyAbstractTransformerWidget( parent, definition )
528 layout()->setContentsMargins( 0, 0, 0, 0 );
530 nullOutputSpinBox->setShowClearButton(
false );
535 minOutputSpinBox->setMaximum( 360.0 );
536 minOutputSpinBox->setValue( 0.0 );
537 minOutputSpinBox->setShowClearButton(
true );
538 minOutputSpinBox->setClearValue( 0.0 );
539 minOutputSpinBox->setSuffix( tr(
" °" ) );
540 maxOutputSpinBox->setMaximum( 360.0 );
541 maxOutputSpinBox->setValue( 360.0 );
542 maxOutputSpinBox->setShowClearButton(
true );
543 maxOutputSpinBox->setClearValue( 360.0 );
544 maxOutputSpinBox->setSuffix( tr(
" °" ) );
545 exponentSpinBox->hide();
546 mExponentLabel->hide();
547 mLabelMinOutput->setText( tr(
"Angle from" ) );
548 mLabelNullOutput->setText( tr(
"Angle when NULL" ) );
552 minOutputSpinBox->setShowClearButton(
false );
553 maxOutputSpinBox->setShowClearButton(
false );
558 minOutputSpinBox->setValue( transform->minOutputValue() );
559 maxOutputSpinBox->setValue( transform->maxOutputValue() );
560 nullOutputSpinBox->setValue( transform->nullOutputValue() );
561 exponentSpinBox->setValue( transform->exponent() );
564 connect( minOutputSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
565 connect( maxOutputSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
566 connect( nullOutputSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
567 connect( exponentSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
575 minOutputSpinBox->value(),
576 maxOutputSpinBox->value(),
577 nullOutputSpinBox->value(),
578 exponentSpinBox->value() );