31 , mDefinition( definition )
36 layout()->setContentsMargins( 0, 0, 0, 0 );
37 layout()->setMargin( 0 );
41 mLegendPreview->hide();
43 minValueSpinBox->setShowClearButton(
false );
44 maxValueSpinBox->setShowClearButton(
false );
47 mExpressionWidget->setLayer( const_cast< QgsVectorLayer * >( mLayer ) );
58 mTransformCurveCheckBox->setChecked(
true );
59 mTransformCurveCheckBox->setCollapsed(
false );
64 connect( computeValuesButton, &QPushButton::clicked,
this, &QgsPropertyAssistantWidget::computeValuesFromLayer );
68 mLayerTreeLayer =
new QgsLayerTreeLayer( const_cast< QgsVectorLayer * >( mLayer ) );
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->layout()->setMargin( 0 );
78 mLegendVerticalFrame->hide();
85 mTransformerWidget =
new QgsPropertySizeAssistantWidget(
this, mDefinition, initialState );
86 mLegendPreview->show();
93 mTransformerWidget =
new QgsPropertyColorAssistantWidget(
this, mDefinition, initialState );
94 mLegendPreview->show();
100 mTransformerWidget =
new QgsPropertyGenericNumericAssistantWidget(
this, mDefinition, initialState );
108 mTransformerWidget =
new QgsPropertyGenericNumericAssistantWidget(
this, mDefinition, initialState );
114 if ( mTransformerWidget )
116 mOutputWidget->layout()->addWidget( mTransformerWidget );
119 mCurveEditor->setMinHistogramValueRange( minValueSpinBox->value() );
120 mCurveEditor->setMaxHistogramValueRange( maxValueSpinBox->value() );
122 mCurveEditor->setHistogramSource( mLayer, mExpressionWidget->currentField() );
125 mCurveEditor->setHistogramSource( mLayer, expression );
131 mTransformCurveCheckBox->setVisible( mTransformerWidget );
143 mExpressionContextGenerator = generator;
144 mExpressionWidget->registerExpressionContextGenerator( generator );
149 property.setActive( !mExpressionWidget->currentText().isEmpty() );
150 if ( mExpressionWidget->isExpression() )
153 property.setField( mExpressionWidget->currentField() );
155 if ( mTransformerWidget )
157 std::unique_ptr< QgsPropertyTransformer> t( mTransformerWidget->createTransformer( minValueSpinBox->value(), maxValueSpinBox->value() ) );
158 if ( mTransformCurveCheckBox->isChecked() )
164 t->setCurveTransform(
nullptr );
166 property.setTransformer( t.release() );
174 if ( dockMode && mLegendVerticalFrame->isHidden() )
176 mLegendVerticalFrame->layout()->addWidget( mLegendPreview );
177 mLegendVerticalFrame->show();
181 void QgsPropertyAssistantWidget::computeValuesFromLayer()
186 double minValue = 0.0;
187 double maxValue = 0.0;
189 if ( mExpressionWidget->isExpression() )
191 if ( !computeValuesFromExpression( mExpressionWidget->currentField(), minValue, maxValue ) )
196 if ( !computeValuesFromField( mExpressionWidget->currentField(), minValue, maxValue ) )
203 mCurveEditor->setMinHistogramValueRange( minValueSpinBox->value() );
204 mCurveEditor->setMaxHistogramValueRange( maxValueSpinBox->value() );
209 void QgsPropertyAssistantWidget::updatePreview()
211 if ( mLegendPreview->isHidden() || !mTransformerWidget || !mLayer )
214 mLegendPreview->setIconSize( QSize( 512, 512 ) );
215 mPreviewList.clear();
218 maxValueSpinBox->value(), 8 );
221 QList< QgsSymbolLegendNode * > nodes = mTransformerWidget->generatePreviews( breaks, mLayerTreeLayer, mSymbol.get(), minValueSpinBox->value(),
222 maxValueSpinBox->value(), mTransformCurveCheckBox->isChecked() ? &curve : nullptr );
226 const auto constNodes = nodes;
229 const QSize minSize( node->minimumIconSize() );
230 node->setIconSize( minSize );
231 widthMax = std::max( minSize.width(), widthMax );
232 QStandardItem *item =
new QStandardItem( node->data( Qt::DecorationRole ).value<QPixmap>(), QString::number( breaks[i] ) );
233 item->setEditable(
false );
234 mPreviewList.appendRow( item );
240 for (
int i = 0; i < breaks.length(); i++ )
242 QPixmap img( mPreviewList.item( i )->icon().pixmap( mPreviewList.item( i )->icon().actualSize( QSize( 512, 512 ) ) ) );
243 QPixmap enlarged( widthMax, img.height() );
245 enlarged.fill( Qt::transparent );
246 QPainter p( &enlarged );
247 p.drawPixmap( QPoint( ( widthMax - img.width() ) / 2, 0 ), img );
249 mPreviewList.item( i )->setIcon( enlarged );
253 bool QgsPropertyAssistantWidget::computeValuesFromExpression(
const QString &expression,
double &minValue,
double &maxValue )
const 258 if ( mExpressionContextGenerator )
278 .setSubsetOfAttributes( referencedCols, mLayer->
fields() ) );
281 double min = std::numeric_limits<double>::max();
282 double max = std::numeric_limits<double>::lowest();
285 while ( fit.nextFeature( f ) )
289 const double value = e.
evaluate( &context ).toDouble( &ok );
292 max = std::max( max, value );
293 min = std::min( min, value );
305 bool QgsPropertyAssistantWidget::computeValuesFromField(
const QString &fieldName,
double &minValue,
double &maxValue )
const 308 if ( fieldIndex < 0 )
314 double minDouble = mLayer->
minimumValue( fieldIndex ).toDouble( &ok );
318 double maxDouble = mLayer->
maximumValue( fieldIndex ).toDouble( &ok );
322 minValue = minDouble;
323 maxValue = maxDouble;
334 : QgsPropertyAbstractTransformerWidget( parent, definition )
338 layout()->setContentsMargins( 0, 0, 0, 0 );
339 layout()->setMargin( 0 );
354 minSizeSpinBox->setShowClearButton(
false );
355 maxSizeSpinBox->setShowClearButton(
false );
356 nullSizeSpinBox->setShowClearButton(
false );
360 minSizeSpinBox->setValue( sizeTransform->minSize() );
361 maxSizeSpinBox->setValue( sizeTransform->maxSize() );
362 nullSizeSpinBox->setValue( sizeTransform->nullSize() );
363 exponentSpinBox->setValue( sizeTransform->exponent() );
364 scaleMethodComboBox->setCurrentIndex( scaleMethodComboBox->findData( sizeTransform->type() ) );
369 connect( minSizeSpinBox, static_cast <
void (
QgsDoubleSpinBox::* )(
double ) > ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
370 connect( maxSizeSpinBox, static_cast <
void (
QgsDoubleSpinBox::* )(
double ) > ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
371 connect( nullSizeSpinBox, static_cast <
void (
QgsDoubleSpinBox::* )(
double ) > ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
372 connect( exponentSpinBox, static_cast <
void (
QgsDoubleSpinBox::* )(
double ) > ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
373 connect( scaleMethodComboBox, static_cast <
void ( QComboBox::* )(
int ) > ( &QComboBox::currentIndexChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
374 connect( scaleMethodComboBox, static_cast <
void ( QComboBox::* )(
int ) > ( &QComboBox::currentIndexChanged ),
this,
382 QgsSizeScaleTransformer *QgsPropertySizeAssistantWidget::createTransformer(
double minValue,
double maxValue )
const 385 static_cast< QgsSizeScaleTransformer::ScaleType >( scaleMethodComboBox->currentData().toInt() ),
388 minSizeSpinBox->value(),
389 maxSizeSpinBox->value(),
390 nullSizeSpinBox->value(),
391 exponentSpinBox->value() );
395 QList< QgsSymbolLegendNode * > QgsPropertySizeAssistantWidget::generatePreviews(
const QList<double> &breaks,
QgsLayerTreeLayer *parent,
const QgsSymbol *symbol,
double minValue,
double maxValue,
QgsCurveTransform *curve )
const 397 QList< QgsSymbolLegendNode * > nodes;
400 std::unique_ptr< QgsSymbol > tempSymbol;
412 legendSymbol = tempSymbol.get();
417 std::unique_ptr< QgsSizeScaleTransformer > t( createTransformer( minValue, maxValue ) );
421 for (
int i = 0; i < breaks.length(); i++ )
423 std::unique_ptr< QgsSymbolLegendNode > node;
424 if ( dynamic_cast<const QgsMarkerSymbol *>( legendSymbol ) )
426 std::unique_ptr< QgsMarkerSymbol > symbolClone( static_cast<QgsMarkerSymbol *>( legendSymbol->
clone() ) );
429 symbolClone->setSize( t->size( breaks[i] ) );
432 else if ( dynamic_cast<const QgsLineSymbol *>( legendSymbol ) )
434 std::unique_ptr< QgsLineSymbol > symbolClone( static_cast<QgsLineSymbol *>( legendSymbol->
clone() ) );
436 symbolClone->setWidth( t->size( breaks[i] ) );
440 nodes << node.release();
447 return QList< QgsSymbolLegendNode * >();
450 QgsPropertyColorAssistantWidget::QgsPropertyColorAssistantWidget( QWidget *parent,
const QgsPropertyDefinition &definition,
const QgsProperty &initialState )
451 : QgsPropertyAbstractTransformerWidget( parent, definition )
455 layout()->setContentsMargins( 0, 0, 0, 0 );
456 layout()->setMargin( 0 );
459 mNullColorButton->setAllowOpacity( supportsAlpha );
460 mNullColorButton->setShowNoColor(
true );
461 mNullColorButton->setColorDialogTitle( tr(
"Color For Null Values" ) );
462 mNullColorButton->setContext( QStringLiteral(
"symbology" ) );
463 mNullColorButton->setNoColorString( tr(
"Transparent" ) );
467 mNullColorButton->setColor( colorTransform->nullColor() );
468 if ( colorTransform->colorRamp() )
469 mColorRampButton->setColorRamp( colorTransform->colorRamp() );
475 if ( !mColorRampButton->colorRamp() )
479 std::unique_ptr< QgsColorRamp > defaultRamp(
QgsStyle::defaultStyle()->colorRamp( !defaultRampName.isEmpty() ? defaultRampName : QStringLiteral(
"Blues" ) ) );
481 mColorRampButton->setColorRamp( defaultRamp.get() );
485 QgsColorRampTransformer *QgsPropertyColorAssistantWidget::createTransformer(
double minValue,
double maxValue )
const 490 mColorRampButton->colorRamp(),
491 mNullColorButton->color() );
495 QList<QgsSymbolLegendNode *> QgsPropertyColorAssistantWidget::generatePreviews(
const QList<double> &breaks,
QgsLayerTreeLayer *parent,
const QgsSymbol *symbol,
double minValue,
double maxValue,
QgsCurveTransform *curve )
const 497 QList< QgsSymbolLegendNode * > nodes;
500 std::unique_ptr< QgsMarkerSymbol > tempSymbol;
505 legendSymbol = tempSymbol.get();
510 std::unique_ptr< QgsColorRampTransformer > t( createTransformer( minValue, maxValue ) );
514 for (
int i = 0; i < breaks.length(); i++ )
516 std::unique_ptr< QgsSymbolLegendNode > node;
517 std::unique_ptr< QgsMarkerSymbol > symbolClone( static_cast<QgsMarkerSymbol *>( legendSymbol->
clone() ) );
518 symbolClone->setColor( t->color( breaks[i] ) );
521 nodes << node.release();
526 QgsPropertyGenericNumericAssistantWidget::QgsPropertyGenericNumericAssistantWidget( QWidget *parent,
const QgsPropertyDefinition &definition,
const QgsProperty &initialState )
527 : QgsPropertyAbstractTransformerWidget( parent, definition )
531 layout()->setContentsMargins( 0, 0, 0, 0 );
532 layout()->setMargin( 0 );
534 nullOutputSpinBox->setShowClearButton(
false );
539 minOutputSpinBox->setMaximum( 360.0 );
540 minOutputSpinBox->setValue( 0.0 );
541 minOutputSpinBox->setShowClearButton(
true );
542 minOutputSpinBox->setClearValue( 0.0 );
543 minOutputSpinBox->setSuffix( tr(
" °" ) );
544 maxOutputSpinBox->setMaximum( 360.0 );
545 maxOutputSpinBox->setValue( 360.0 );
546 maxOutputSpinBox->setShowClearButton(
true );
547 maxOutputSpinBox->setClearValue( 360.0 );
548 maxOutputSpinBox->setSuffix( tr(
" °" ) );
549 exponentSpinBox->hide();
550 mExponentLabel->hide();
551 mLabelMinOutput->setText( tr(
"Angle from" ) );
552 mLabelNullOutput->setText( tr(
"Angle when NULL" ) );
556 minOutputSpinBox->setShowClearButton(
false );
557 maxOutputSpinBox->setShowClearButton(
false );
562 minOutputSpinBox->setValue( transform->minOutputValue() );
563 maxOutputSpinBox->setValue( transform->maxOutputValue() );
564 nullOutputSpinBox->setValue( transform->nullOutputValue() );
565 exponentSpinBox->setValue( transform->exponent() );
568 connect( minOutputSpinBox, static_cast <
void (
QgsDoubleSpinBox::* )(
double ) > ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
569 connect( maxOutputSpinBox, static_cast <
void (
QgsDoubleSpinBox::* )(
double ) > ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
570 connect( nullOutputSpinBox, static_cast <
void (
QgsDoubleSpinBox::* )(
double ) > ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
571 connect( exponentSpinBox, static_cast <
void (
QgsDoubleSpinBox::* )(
double ) > ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
579 minOutputSpinBox->value(),
580 maxOutputSpinBox->value(),
581 nullOutputSpinBox->value(),
582 exponentSpinBox->value() );
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
The QgsSpinBox is a spin box with a clear button that will set the value to the defined clear value...
Class for parsing and evaluation of expressions (formerly called "search strings").
Wrapper for iterator of features from vector data provider or vector layer.
QString readEntry(const QString &scope, const QString &key, const QString &def=QString(), bool *ok=nullptr) const
1D size (eg marker radius, or square marker height/width)
Abstract base class for all rendered symbols.
Expression based property (QgsExpressionBasedProperty)
static QgsLineSymbol * createSimple(const QgsStringMap &properties)
Create a line symbol with one symbol layer: SimpleLine with specified properties. ...
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
QVariant evaluate()
Evaluate the feature and return the result.
Implementation of legend node interface for displaying preview of vector symbols and their labels and...
bool needsGeometry() const
Returns true if the expression uses feature geometry for some computation.
Color with alpha channel.
static QgsExpressionContextScope * projectScope(const QgsProject *project)
Creates a new scope which contains variables and functions relating to a QGIS project.
QSet< QString > referencedColumns() const
Gets list of columns referenced by the expression.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QMap< QString, QString > QgsStringMap
Rotation (value between 0-360 degrees)
A marker symbol type, for rendering Point and MultiPoint geometries.
static QgsStyle * defaultStyle()
Returns default application-wide style.
const QgsPropertyTransformer * transformer() const
Returns the existing transformer used for manipulating the calculated values for the property...
QString expressionString() const
Returns the expression used for the property value.
virtual QgsExpressionContext createExpressionContext() const =0
This method needs to be reimplemented in all classes which implement this interface and return an exp...
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
DataType dataType() const
Returns the allowable field/value data type for the property.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
Type propertyType() const
Returns the property type.
QString description() const
Descriptive name of the property.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Property requires a numeric value.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QVariant minimumValue(int index) const FINAL
Returns the minimum value for an attribute column or an invalid variant in case of error...
A store for object properties.
void setExpressionString(const QString &expression)
Sets the expression to use for the property value.
Definition for a property.
QString field() const
Returns the current field name the property references.
Abstract interface for generating an expression context.
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...
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
bool prepare(const QgsExpressionContext *context)
Gets the expression ready for evaluation - find out column indexes.
virtual QgsSymbol * clone() const =0
Returns a deep copy of this symbol.
static QgsProject * instance()
Returns the QgsProject singleton instance.
void addChildNode(QgsLayerTreeNode *node)
Append an existing node.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
static QgsMarkerSymbol * createSimple(const QgsStringMap &properties)
Create a marker symbol with one symbol layer: SimpleMarker with specified properties.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
Geometry is not required. It may still be returned if e.g. required for a filter condition.
QVariant maximumValue(int index) const FINAL
Returns the maximum value for an attribute column or an invalid variant in case of error...
Represents a vector layer which manages a vector based data sets.
QgsMarkerSymbol * clone() const override
Returns a deep copy of this symbol.
StandardPropertyTemplate standardTemplate() const
Returns the property's standard template, if applicable.
Layer tree node points to a map layer.
Color with no alpha channel.