35 , mDefinition( definition )
40 layout()->setContentsMargins( 0, 0, 0, 0 );
44 mLegendPreview->hide();
46 minValueSpinBox->setShowClearButton(
false );
47 maxValueSpinBox->setShowClearButton(
false );
50 mExpressionWidget->setLayer(
const_cast< QgsVectorLayer *
>( mLayer ) );
54 if (
auto *lTransformer = initialState.
transformer() )
56 minValueSpinBox->setValue( lTransformer->minValue() );
57 maxValueSpinBox->setValue( lTransformer->maxValue() );
59 if ( lTransformer->curveTransform() )
61 mTransformCurveCheckBox->setChecked(
true );
62 mTransformCurveCheckBox->setCollapsed(
false );
63 mCurveEditor->setCurve( *lTransformer->curveTransform() );
67 connect( computeValuesButton, &QPushButton::clicked,
this, &QgsPropertyAssistantWidget::computeValuesFromLayer );
74 mLegendPreview->setModel( &mPreviewList );
75 mLegendPreview->setItemDelegate(
new QgsAssistantPreviewItemDelegate( &mPreviewList ) );
76 mLegendPreview->setHeaderHidden(
true );
77 mLegendPreview->expandAll();
78 mLegendVerticalFrame->setLayout(
new QVBoxLayout() );
79 mLegendVerticalFrame->layout()->setContentsMargins( 0, 0, 0, 0 );
80 mLegendVerticalFrame->hide();
87 mTransformerWidget =
new QgsPropertySizeAssistantWidget(
this, mDefinition, initialState );
88 mLegendPreview->show();
95 mTransformerWidget =
new QgsPropertyColorAssistantWidget(
this, mDefinition, initialState );
96 mLegendPreview->show();
102 mTransformerWidget =
new QgsPropertyGenericNumericAssistantWidget(
this, mDefinition, initialState );
110 mTransformerWidget =
new QgsPropertyGenericNumericAssistantWidget(
this, mDefinition, initialState );
116 if ( mTransformerWidget )
118 mOutputWidget->layout()->addWidget( mTransformerWidget );
121 mCurveEditor->setMinHistogramValueRange( minValueSpinBox->value() );
122 mCurveEditor->setMaxHistogramValueRange( maxValueSpinBox->value() );
124 mCurveEditor->setHistogramSource( mLayer, mExpressionWidget->currentField() );
127 mCurveEditor->setHistogramSource( mLayer, expression );
133 mTransformCurveCheckBox->setVisible( mTransformerWidget );
145 mExpressionContextGenerator = generator;
146 mExpressionWidget->registerExpressionContextGenerator( generator );
151 property.setActive( !mExpressionWidget->currentText().isEmpty() );
152 if ( mExpressionWidget->isExpression() )
153 property.setExpressionString( mExpressionWidget->currentField() );
155 property.setField( mExpressionWidget->currentField() );
157 if ( mTransformerWidget )
159 std::unique_ptr< QgsPropertyTransformer> t( mTransformerWidget->createTransformer( minValueSpinBox->value(), maxValueSpinBox->value() ) );
160 if ( mTransformCurveCheckBox->isChecked() )
166 t->setCurveTransform(
nullptr );
168 property.setTransformer( t.release() );
176 if (
dockMode && mLegendVerticalFrame->isHidden() )
178 mLegendVerticalFrame->layout()->addWidget( mLegendPreview );
179 mLegendVerticalFrame->show();
183 void QgsPropertyAssistantWidget::computeValuesFromLayer()
188 double minValue = 0.0;
189 double maxValue = 0.0;
191 if ( mExpressionWidget->isExpression() )
193 if ( !computeValuesFromExpression( mExpressionWidget->currentField(), minValue, maxValue ) )
198 if ( !computeValuesFromField( mExpressionWidget->currentField(), minValue, maxValue ) )
205 mCurveEditor->setMinHistogramValueRange( minValueSpinBox->value() );
206 mCurveEditor->setMaxHistogramValueRange( maxValueSpinBox->value() );
211 void QgsPropertyAssistantWidget::updatePreview()
213 if ( mLegendPreview->isHidden() || !mTransformerWidget || !mLayer )
216 mLegendPreview->setIconSize( QSize( 512, 512 ) );
217 mPreviewList.clear();
220 maxValueSpinBox->value(), 8 );
223 const QList< QgsSymbolLegendNode * > nodes = mTransformerWidget->generatePreviews( breaks, mLayerTreeLayer, mSymbol.get(), minValueSpinBox->value(),
224 maxValueSpinBox->value(), mTransformCurveCheckBox->isChecked() ? &curve :
nullptr );
228 const auto constNodes = nodes;
231 const QSize minSize( node->minimumIconSize() );
232 node->setIconSize( minSize );
233 widthMax = std::max( minSize.width(), widthMax );
234 QStandardItem *item =
new QStandardItem( node->data( Qt::DecorationRole ).value<QPixmap>(), QLocale().toString( breaks[i] ) );
235 item->setEditable(
false );
236 mPreviewList.appendRow( item );
242 for (
int i = 0; i < breaks.length(); i++ )
244 const QPixmap img( mPreviewList.item( i )->icon().pixmap( mPreviewList.item( i )->icon().actualSize( QSize( 512, 512 ) ) ) );
245 QPixmap enlarged( widthMax, img.height() );
247 enlarged.fill( Qt::transparent );
248 QPainter p( &enlarged );
249 p.drawPixmap( QPoint( ( widthMax - img.width() ) / 2, 0 ), img );
251 mPreviewList.item( i )->setIcon( enlarged );
255 bool QgsPropertyAssistantWidget::computeValuesFromExpression(
const QString &expression,
double &minValue,
double &maxValue )
const
260 if ( mExpressionContextGenerator )
271 if ( !e.prepare( &context ) )
274 const QSet<QString> referencedCols( e.referencedColumns() );
283 double min = std::numeric_limits<double>::max();
284 double max = std::numeric_limits<double>::lowest();
291 const double value = e.evaluate( &context ).toDouble( &ok );
294 max = std::max( max, value );
295 min = std::min( min, value );
307 bool QgsPropertyAssistantWidget::computeValuesFromField(
const QString &fieldName,
double &minValue,
double &maxValue )
const
310 if ( fieldIndex < 0 )
320 const double minDouble = min.toDouble( &ok );
324 const double maxDouble = max.toDouble( &ok );
328 minValue = minDouble;
329 maxValue = maxDouble;
340 : QgsPropertyAbstractTransformerWidget( parent, definition )
344 layout()->setContentsMargins( 0, 0, 0, 0 );
359 minSizeSpinBox->setShowClearButton(
false );
360 maxSizeSpinBox->setShowClearButton(
false );
361 nullSizeSpinBox->setShowClearButton(
false );
365 minSizeSpinBox->setValue( sizeTransform->minSize() );
366 maxSizeSpinBox->setValue( sizeTransform->maxSize() );
367 nullSizeSpinBox->setValue( sizeTransform->nullSize() );
368 exponentSpinBox->setValue( sizeTransform->exponent() );
369 scaleMethodComboBox->setCurrentIndex( scaleMethodComboBox->findData( sizeTransform->type() ) );
374 connect( minSizeSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
375 connect( maxSizeSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
376 connect( nullSizeSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
377 connect( exponentSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
378 connect( scaleMethodComboBox,
static_cast < void ( QComboBox::* )(
int )
> ( &QComboBox::currentIndexChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
379 connect( scaleMethodComboBox,
static_cast < void ( QComboBox::* )(
int )
> ( &QComboBox::currentIndexChanged ),
this,
387 QgsSizeScaleTransformer *QgsPropertySizeAssistantWidget::createTransformer(
double minValue,
double maxValue )
const
393 minSizeSpinBox->value(),
394 maxSizeSpinBox->value(),
395 nullSizeSpinBox->value(),
396 exponentSpinBox->value() );
400 QList< QgsSymbolLegendNode * > QgsPropertySizeAssistantWidget::generatePreviews(
const QList<double> &breaks,
QgsLayerTreeLayer *parent,
const QgsSymbol *symbol,
double minValue,
double maxValue,
QgsCurveTransform *curve )
const
402 QList< QgsSymbolLegendNode * > nodes;
405 std::unique_ptr< QgsSymbol > tempSymbol;
417 legendSymbol = tempSymbol.get();
422 std::unique_ptr< QgsSizeScaleTransformer > t( createTransformer( minValue, maxValue ) );
426 for (
int i = 0; i < breaks.length(); i++ )
428 std::unique_ptr< QgsSymbolLegendNode > node;
431 std::unique_ptr< QgsMarkerSymbol > symbolClone(
static_cast<QgsMarkerSymbol *
>( legendSymbol->
clone() ) );
434 symbolClone->setSize( t->size( breaks[i] ) );
437 else if (
dynamic_cast<const QgsLineSymbol *
>( legendSymbol ) )
439 std::unique_ptr< QgsLineSymbol > symbolClone(
static_cast<QgsLineSymbol *
>( legendSymbol->
clone() ) );
441 symbolClone->setWidth( t->size( breaks[i] ) );
445 nodes << node.release();
452 return QList< QgsSymbolLegendNode * >();
455 QgsPropertyColorAssistantWidget::QgsPropertyColorAssistantWidget( QWidget *parent,
const QgsPropertyDefinition &definition,
const QgsProperty &initialState )
456 : QgsPropertyAbstractTransformerWidget( parent, definition )
460 layout()->setContentsMargins( 0, 0, 0, 0 );
463 mNullColorButton->setAllowOpacity( supportsAlpha );
464 mNullColorButton->setShowNoColor(
true );
465 mNullColorButton->setColorDialogTitle( tr(
"Color For Null Values" ) );
466 mNullColorButton->setContext( QStringLiteral(
"symbology" ) );
467 mNullColorButton->setNoColorString( tr(
"Transparent" ) );
471 mNullColorButton->setColor( colorTransform->nullColor() );
472 if ( colorTransform->colorRamp() )
473 mColorRampButton->setColorRamp( colorTransform->colorRamp() );
479 if ( !mColorRampButton->colorRamp() )
482 std::unique_ptr< QgsColorRamp > colorRamp(
QgsProject::instance()->styleSettings()->defaultColorRamp() );
488 mColorRampButton->setColorRamp( colorRamp.get() );
492 QgsColorRampTransformer *QgsPropertyColorAssistantWidget::createTransformer(
double minValue,
double maxValue )
const
497 mColorRampButton->colorRamp(),
498 mNullColorButton->color() );
502 QList<QgsSymbolLegendNode *> QgsPropertyColorAssistantWidget::generatePreviews(
const QList<double> &breaks,
QgsLayerTreeLayer *parent,
const QgsSymbol *symbol,
double minValue,
double maxValue,
QgsCurveTransform *curve )
const
504 QList< QgsSymbolLegendNode * > nodes;
507 std::unique_ptr< QgsMarkerSymbol > tempSymbol;
512 legendSymbol = tempSymbol.get();
517 std::unique_ptr< QgsColorRampTransformer > t( createTransformer( minValue, maxValue ) );
521 for (
int i = 0; i < breaks.length(); i++ )
523 std::unique_ptr< QgsSymbolLegendNode > node;
524 std::unique_ptr< QgsMarkerSymbol > symbolClone(
static_cast<QgsMarkerSymbol *
>( legendSymbol->
clone() ) );
525 symbolClone->setColor( t->color( breaks[i] ) );
528 nodes << node.release();
533 QgsPropertyGenericNumericAssistantWidget::QgsPropertyGenericNumericAssistantWidget( QWidget *parent,
const QgsPropertyDefinition &definition,
const QgsProperty &initialState )
534 : QgsPropertyAbstractTransformerWidget( parent, definition )
538 layout()->setContentsMargins( 0, 0, 0, 0 );
540 nullOutputSpinBox->setShowClearButton(
false );
547 minOutputSpinBox->setMaximum( 360.0 );
548 minOutputSpinBox->setValue( 0.0 );
549 minOutputSpinBox->setShowClearButton(
true );
550 minOutputSpinBox->setClearValue( 0.0 );
551 minOutputSpinBox->setSuffix( tr(
" °" ) );
552 maxOutputSpinBox->setMaximum( 360.0 );
553 maxOutputSpinBox->setValue( 360.0 );
554 maxOutputSpinBox->setShowClearButton(
true );
555 maxOutputSpinBox->setClearValue( 360.0 );
556 maxOutputSpinBox->setSuffix( tr(
" °" ) );
557 exponentSpinBox->hide();
558 mExponentLabel->hide();
559 mLabelMinOutput->setText( tr(
"Angle from" ) );
560 mLabelNullOutput->setText( tr(
"Angle when NULL" ) );
567 minOutputSpinBox->setMaximum( 100.0 );
568 minOutputSpinBox->setValue( 0.0 );
569 minOutputSpinBox->setShowClearButton(
true );
570 minOutputSpinBox->setClearValue( 0.0 );
571 minOutputSpinBox->setSuffix( tr(
" %" ) );
572 maxOutputSpinBox->setMaximum( 100.0 );
573 maxOutputSpinBox->setValue( 100.0 );
574 maxOutputSpinBox->setShowClearButton(
true );
575 maxOutputSpinBox->setClearValue( 100.0 );
576 maxOutputSpinBox->setSuffix( tr(
" %" ) );
577 mLabelMinOutput->setText( tr(
"Opacity from" ) );
578 mLabelNullOutput->setText( tr(
"Opacity when NULL" ) );
584 minOutputSpinBox->setMinimum( 0 );
585 maxOutputSpinBox->setMinimum( 0 );
586 minOutputSpinBox->setShowClearButton(
false );
587 maxOutputSpinBox->setShowClearButton(
false );
591 minOutputSpinBox->setMinimum( 1 );
592 maxOutputSpinBox->setMinimum( 1 );
593 minOutputSpinBox->setShowClearButton(
false );
594 maxOutputSpinBox->setShowClearButton(
false );
598 minOutputSpinBox->setMinimum( 0 );
599 maxOutputSpinBox->setMinimum( 0 );
600 minOutputSpinBox->setMaximum( 1 );
601 maxOutputSpinBox->setMaximum( 1 );
602 minOutputSpinBox->setShowClearButton(
false );
603 maxOutputSpinBox->setShowClearButton(
false );
607 minOutputSpinBox->setMinimum( -99999999.000000 );
608 maxOutputSpinBox->setMinimum( -99999999.000000 );
609 minOutputSpinBox->setMaximum( 99999999.000000 );
610 maxOutputSpinBox->setMaximum( 99999999.000000 );
611 minOutputSpinBox->setShowClearButton(
false );
612 maxOutputSpinBox->setShowClearButton(
false );
617 minOutputSpinBox->setShowClearButton(
false );
618 maxOutputSpinBox->setShowClearButton(
false );
625 minOutputSpinBox->setValue( transform->minOutputValue() );
626 maxOutputSpinBox->setValue( transform->maxOutputValue() );
627 nullOutputSpinBox->setValue( transform->nullOutputValue() );
628 exponentSpinBox->setValue( transform->exponent() );
631 connect( minOutputSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
632 connect( maxOutputSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
633 connect( nullOutputSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
634 connect( exponentSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
642 minOutputSpinBox->value(),
643 maxOutputSpinBox->value(),
644 nullOutputSpinBox->value(),
645 exponentSpinBox->value() );