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 );
537 minOutputSpinBox->setMaximum( 360.0 );
538 minOutputSpinBox->setValue( 0.0 );
539 minOutputSpinBox->setShowClearButton(
true );
540 minOutputSpinBox->setClearValue( 0.0 );
541 minOutputSpinBox->setSuffix( tr(
" °" ) );
542 maxOutputSpinBox->setMaximum( 360.0 );
543 maxOutputSpinBox->setValue( 360.0 );
544 maxOutputSpinBox->setShowClearButton(
true );
545 maxOutputSpinBox->setClearValue( 360.0 );
546 maxOutputSpinBox->setSuffix( tr(
" °" ) );
547 exponentSpinBox->hide();
548 mExponentLabel->hide();
549 mLabelMinOutput->setText( tr(
"Angle from" ) );
550 mLabelNullOutput->setText( tr(
"Angle when NULL" ) );
557 minOutputSpinBox->setMaximum( 100.0 );
558 minOutputSpinBox->setValue( 0.0 );
559 minOutputSpinBox->setShowClearButton(
true );
560 minOutputSpinBox->setClearValue( 0.0 );
561 minOutputSpinBox->setSuffix( tr(
" %" ) );
562 maxOutputSpinBox->setMaximum( 100.0 );
563 maxOutputSpinBox->setValue( 100.0 );
564 maxOutputSpinBox->setShowClearButton(
true );
565 maxOutputSpinBox->setClearValue( 100.0 );
566 maxOutputSpinBox->setSuffix( tr(
" %" ) );
567 mLabelMinOutput->setText( tr(
"Opacity from" ) );
568 mLabelNullOutput->setText( tr(
"Opacity when NULL" ) );
574 minOutputSpinBox->setShowClearButton(
false );
575 maxOutputSpinBox->setShowClearButton(
false );
582 minOutputSpinBox->setValue( transform->minOutputValue() );
583 maxOutputSpinBox->setValue( transform->maxOutputValue() );
584 nullOutputSpinBox->setValue( transform->nullOutputValue() );
585 exponentSpinBox->setValue( transform->exponent() );
588 connect( minOutputSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
589 connect( maxOutputSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
590 connect( nullOutputSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
591 connect( exponentSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
599 minOutputSpinBox->value(),
600 maxOutputSpinBox->value(),
601 nullOutputSpinBox->value(),
602 exponentSpinBox->value() );
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value.
Abstract interface for generating an expression context.
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
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").
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
This class wraps a request for features to a vector layer (or directly its vector data provider).
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
@ Numeric
All numeric fields.
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
void addChildNode(QgsLayerTreeNode *node)
Append an existing node.
Layer tree node points to a map layer.
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
A line symbol type, for rendering LineString and MultiLineString geometries.
static QgsLineSymbol * createSimple(const QVariantMap &properties)
Create a line symbol with one symbol layer: SimpleLine with specified properties.
A marker symbol type, for rendering Point and MultiPoint geometries.
static QgsMarkerSymbol * createSimple(const QVariantMap &properties)
Create a marker symbol with one symbol layer: SimpleMarker with specified properties.
QgsMarkerSymbol * clone() const override
Returns a deep copy of this symbol.
static QgsProject * instance()
Returns the QgsProject singleton instance.
QString readEntry(const QString &scope, const QString &key, const QString &def=QString(), bool *ok=nullptr) const
Reads a string from the specified scope and key.
Definition for a property.
StandardPropertyTemplate standardTemplate() const
Returns the property's standard template, if applicable.
DataType dataType() const
Returns the allowable field/value data type for the property.
QString description() const
Descriptive name of the property.
@ StrokeWidth
Line stroke width.
@ ColorNoAlpha
Color with no alpha channel.
@ Rotation
Rotation (value between 0-360 degrees)
@ Size
1D size (eg marker radius, or square marker height/width)
@ ColorWithAlpha
Color with alpha channel.
@ DataTypeNumeric
Property requires a numeric value.
A store for object properties.
@ ExpressionBasedProperty
Expression based property (QgsExpressionBasedProperty)
QString expressionString() const
Returns the expression used for the property value.
QString field() const
Returns the current field name the property references.
const QgsPropertyTransformer * transformer() const
Returns the existing transformer used for manipulating the calculated values for the property,...
Type propertyType() const
Returns the property type.
static QgsStyle * defaultStyle()
Returns default application-wide style.
static QList< double > prettyBreaks(double minimum, double maximum, int classes)
Computes a sequence of about 'classes' equally spaced round values which cover the range of values fr...
Implementation of legend node interface for displaying preview of vector symbols and their labels and...
Abstract base class for all rendered symbols.
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
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.
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.
QVariant minimumValue(int index) const FINAL
Returns the minimum value for an attribute column or an invalid variant in case of error.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.