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 );
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 )
277 .setSubsetOfAttributes( referencedCols, mLayer->
fields() ) );
280 double min = std::numeric_limits<double>::max();
281 double max = std::numeric_limits<double>::lowest();
284 while ( fit.nextFeature( f ) )
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 );
338 layout()->setMargin( 0 );
353 minSizeSpinBox->setShowClearButton(
false );
354 maxSizeSpinBox->setShowClearButton(
false );
355 nullSizeSpinBox->setShowClearButton(
false );
359 minSizeSpinBox->setValue( sizeTransform->minSize() );
360 maxSizeSpinBox->setValue( sizeTransform->maxSize() );
361 nullSizeSpinBox->setValue( sizeTransform->nullSize() );
362 exponentSpinBox->setValue( sizeTransform->exponent() );
363 scaleMethodComboBox->setCurrentIndex( scaleMethodComboBox->findData( sizeTransform->type() ) );
368 connect( minSizeSpinBox, static_cast <
void (
QgsDoubleSpinBox::* )(
double ) > ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
369 connect( maxSizeSpinBox, static_cast <
void (
QgsDoubleSpinBox::* )(
double ) > ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
370 connect( nullSizeSpinBox, static_cast <
void (
QgsDoubleSpinBox::* )(
double ) > ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
371 connect( exponentSpinBox, static_cast <
void (
QgsDoubleSpinBox::* )(
double ) > ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
372 connect( scaleMethodComboBox, static_cast <
void ( QComboBox::* )(
int ) > ( &QComboBox::currentIndexChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
373 connect( scaleMethodComboBox, static_cast <
void ( QComboBox::* )(
int ) > ( &QComboBox::currentIndexChanged ),
this,
381 QgsSizeScaleTransformer *QgsPropertySizeAssistantWidget::createTransformer(
double minValue,
double maxValue )
const 384 static_cast< QgsSizeScaleTransformer::ScaleType >( scaleMethodComboBox->currentData().toInt() ),
387 minSizeSpinBox->value(),
388 maxSizeSpinBox->value(),
389 nullSizeSpinBox->value(),
390 exponentSpinBox->value() );
394 QList< QgsSymbolLegendNode * > QgsPropertySizeAssistantWidget::generatePreviews(
const QList<double> &breaks,
QgsLayerTreeLayer *parent,
const QgsSymbol *symbol,
double minValue,
double maxValue,
QgsCurveTransform *curve )
const 396 QList< QgsSymbolLegendNode * > nodes;
399 std::unique_ptr< QgsSymbol > tempSymbol;
411 legendSymbol = tempSymbol.get();
416 std::unique_ptr< QgsSizeScaleTransformer > t( createTransformer( minValue, maxValue ) );
420 for (
int i = 0; i < breaks.length(); i++ )
422 std::unique_ptr< QgsSymbolLegendNode > node;
423 if ( dynamic_cast<const QgsMarkerSymbol *>( legendSymbol ) )
425 std::unique_ptr< QgsMarkerSymbol > symbolClone( static_cast<QgsMarkerSymbol *>( legendSymbol->
clone() ) );
428 symbolClone->setSize( t->size( breaks[i] ) );
431 else if ( dynamic_cast<const QgsLineSymbol *>( legendSymbol ) )
433 std::unique_ptr< QgsLineSymbol > symbolClone( static_cast<QgsLineSymbol *>( legendSymbol->
clone() ) );
435 symbolClone->setWidth( t->size( breaks[i] ) );
439 nodes << node.release();
446 return QList< QgsSymbolLegendNode * >();
449 QgsPropertyColorAssistantWidget::QgsPropertyColorAssistantWidget( QWidget *parent,
const QgsPropertyDefinition &definition,
const QgsProperty &initialState )
450 : QgsPropertyAbstractTransformerWidget( parent, definition )
454 layout()->setContentsMargins( 0, 0, 0, 0 );
455 layout()->setMargin( 0 );
458 mNullColorButton->setAllowOpacity( supportsAlpha );
459 mNullColorButton->setShowNoColor(
true );
460 mNullColorButton->setColorDialogTitle( tr(
"Color For Null Values" ) );
461 mNullColorButton->setContext( QStringLiteral(
"symbology" ) );
462 mNullColorButton->setNoColorString( tr(
"Transparent" ) );
466 mNullColorButton->setColor( colorTransform->nullColor() );
467 if ( colorTransform->colorRamp() )
468 mColorRampButton->setColorRamp( colorTransform->colorRamp() );
474 if ( !mColorRampButton->colorRamp() )
478 std::unique_ptr< QgsColorRamp > defaultRamp(
QgsStyle::defaultStyle()->colorRamp( !defaultRampName.isEmpty() ? defaultRampName : QStringLiteral(
"Blues" ) ) );
480 mColorRampButton->setColorRamp( defaultRamp.get() );
484 QgsColorRampTransformer *QgsPropertyColorAssistantWidget::createTransformer(
double minValue,
double maxValue )
const 489 mColorRampButton->colorRamp(),
490 mNullColorButton->color() );
494 QList<QgsSymbolLegendNode *> QgsPropertyColorAssistantWidget::generatePreviews(
const QList<double> &breaks,
QgsLayerTreeLayer *parent,
const QgsSymbol *symbol,
double minValue,
double maxValue,
QgsCurveTransform *curve )
const 496 QList< QgsSymbolLegendNode * > nodes;
499 std::unique_ptr< QgsMarkerSymbol > tempSymbol;
504 legendSymbol = tempSymbol.get();
509 std::unique_ptr< QgsColorRampTransformer > t( createTransformer( minValue, maxValue ) );
513 for (
int i = 0; i < breaks.length(); i++ )
515 std::unique_ptr< QgsSymbolLegendNode > node;
516 std::unique_ptr< QgsMarkerSymbol > symbolClone( static_cast<QgsMarkerSymbol *>( legendSymbol->
clone() ) );
517 symbolClone->setColor( t->color( breaks[i] ) );
520 nodes << node.release();
525 QgsPropertyGenericNumericAssistantWidget::QgsPropertyGenericNumericAssistantWidget( QWidget *parent,
const QgsPropertyDefinition &definition,
const QgsProperty &initialState )
526 : QgsPropertyAbstractTransformerWidget( parent, definition )
530 layout()->setContentsMargins( 0, 0, 0, 0 );
531 layout()->setMargin( 0 );
533 nullOutputSpinBox->setShowClearButton(
false );
538 minOutputSpinBox->setMaximum( 360.0 );
539 minOutputSpinBox->setValue( 0.0 );
540 minOutputSpinBox->setShowClearButton(
true );
541 minOutputSpinBox->setClearValue( 0.0 );
542 minOutputSpinBox->setSuffix( tr(
" °" ) );
543 maxOutputSpinBox->setMaximum( 360.0 );
544 maxOutputSpinBox->setValue( 360.0 );
545 maxOutputSpinBox->setShowClearButton(
true );
546 maxOutputSpinBox->setClearValue( 360.0 );
547 maxOutputSpinBox->setSuffix( tr(
" °" ) );
548 exponentSpinBox->hide();
549 mExponentLabel->hide();
550 mLabelMinOutput->setText( tr(
"Angle from" ) );
551 mLabelNullOutput->setText( tr(
"Angle when NULL" ) );
555 minOutputSpinBox->setShowClearButton(
false );
556 maxOutputSpinBox->setShowClearButton(
false );
561 minOutputSpinBox->setValue( transform->minOutputValue() );
562 maxOutputSpinBox->setValue( transform->maxOutputValue() );
563 nullOutputSpinBox->setValue( transform->nullOutputValue() );
564 exponentSpinBox->setValue( transform->exponent() );
567 connect( minOutputSpinBox, static_cast <
void (
QgsDoubleSpinBox::* )(
double ) > ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
568 connect( maxOutputSpinBox, static_cast <
void (
QgsDoubleSpinBox::* )(
double ) > ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
569 connect( nullOutputSpinBox, static_cast <
void (
QgsDoubleSpinBox::* )(
double ) > ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
570 connect( exponentSpinBox, static_cast <
void (
QgsDoubleSpinBox::* )(
double ) > ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
578 minOutputSpinBox->value(),
579 maxOutputSpinBox->value(),
580 nullOutputSpinBox->value(),
581 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.
QVariant data(int role) const override
Returns data associated with the item. Must be implemented in derived class.
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.
void setIconSize(QSize sz)
Set the icon size.
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...
QSize minimumIconSize() const
Calculates the minimum icon size to prevent cropping.
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
Query 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.