30 , mDefinition( definition )
35 layout()->setContentsMargins( 0, 0, 0, 0 );
36 layout()->setMargin( 0 );
40 mLegendPreview->hide();
42 minValueSpinBox->setShowClearButton(
false );
43 maxValueSpinBox->setShowClearButton(
false );
46 mExpressionWidget->setLayer( const_cast< QgsVectorLayer * >( mLayer ) );
57 mTransformCurveCheckBox->setChecked(
true );
58 mTransformCurveCheckBox->setCollapsed(
false );
63 connect( computeValuesButton, &QPushButton::clicked,
this, &QgsPropertyAssistantWidget::computeValuesFromLayer );
67 mLayerTreeLayer =
new QgsLayerTreeLayer( const_cast< QgsVectorLayer * >( mLayer ) );
70 mLegendPreview->setModel( &mPreviewList );
71 mLegendPreview->setItemDelegate(
new QgsAssistantPreviewItemDelegate( &mPreviewList ) );
72 mLegendPreview->setHeaderHidden(
true );
73 mLegendPreview->expandAll();
74 mLegendVerticalFrame->setLayout(
new QVBoxLayout() );
75 mLegendVerticalFrame->layout()->setContentsMargins( 0, 0, 0, 0 );
76 mLegendVerticalFrame->layout()->setMargin( 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() )
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 );
229 widthMax = std::max( minSize.width(), widthMax );
230 QStandardItem *item =
new QStandardItem( node->
data( Qt::DecorationRole ).value<QPixmap>(), QString::number( breaks[i] ) );
231 item->setEditable(
false );
232 mPreviewList.appendRow( item );
238 for (
int i = 0; i < breaks.length(); i++ )
240 QPixmap img( mPreviewList.item( i )->icon().pixmap( mPreviewList.item( i )->icon().actualSize( QSize( 512, 512 ) ) ) );
241 QPixmap enlarged( widthMax, img.height() );
243 enlarged.fill( Qt::transparent );
244 QPainter p( &enlarged );
245 p.drawPixmap( QPoint( ( widthMax - img.width() ) / 2, 0 ), img );
247 mPreviewList.item( i )->setIcon( enlarged );
251 bool QgsPropertyAssistantWidget::computeValuesFromExpression(
const QString &expression,
double &minValue,
double &maxValue )
const 256 if ( mExpressionContextGenerator )
276 .setSubsetOfAttributes( referencedCols, mLayer->
fields() ) );
279 double min = std::numeric_limits<double>::max();
280 double max = std::numeric_limits<double>::lowest();
283 while ( fit.nextFeature( f ) )
287 const double value = e.
evaluate( &context ).toDouble( &ok );
290 max = std::max( max, value );
291 min = std::min( min, value );
303 bool QgsPropertyAssistantWidget::computeValuesFromField(
const QString &fieldName,
double &minValue,
double &maxValue )
const 306 if ( fieldIndex < 0 )
312 double minDouble = mLayer->
minimumValue( fieldIndex ).toDouble( &ok );
316 double maxDouble = mLayer->
maximumValue( fieldIndex ).toDouble( &ok );
320 minValue = minDouble;
321 maxValue = maxDouble;
332 : QgsPropertyAbstractTransformerWidget( parent, definition )
336 layout()->setContentsMargins( 0, 0, 0, 0 );
337 layout()->setMargin( 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 383 static_cast< QgsSizeScaleTransformer::ScaleType >( scaleMethodComboBox->currentData().toInt() ),
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;
422 if ( dynamic_cast<const QgsMarkerSymbol *>( legendSymbol ) )
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 );
454 layout()->setMargin( 0 );
457 mNullColorButton->setAllowOpacity( supportsAlpha );
458 mNullColorButton->setShowNoColor(
true );
459 mNullColorButton->setColorDialogTitle( tr(
"Color For Null Values" ) );
460 mNullColorButton->setContext( QStringLiteral(
"symbology" ) );
461 mNullColorButton->setNoColorString( tr(
"Transparent" ) );
465 mNullColorButton->setColor( colorTransform->nullColor() );
466 if ( colorTransform->colorRamp() )
467 mColorRampButton->setColorRamp( colorTransform->colorRamp() );
473 if ( !mColorRampButton->colorRamp() )
477 std::unique_ptr< QgsColorRamp > defaultRamp(
QgsStyle::defaultStyle()->colorRamp( !defaultRampName.isEmpty() ? defaultRampName : QStringLiteral(
"Blues" ) ) );
479 mColorRampButton->setColorRamp( defaultRamp.get() );
483 QgsColorRampTransformer *QgsPropertyColorAssistantWidget::createTransformer(
double minValue,
double maxValue )
const 488 mColorRampButton->colorRamp(),
489 mNullColorButton->color() );
493 QList<QgsSymbolLegendNode *> QgsPropertyColorAssistantWidget::generatePreviews(
const QList<double> &breaks,
QgsLayerTreeLayer *parent,
const QgsSymbol *symbol,
double minValue,
double maxValue,
QgsCurveTransform *curve )
const 495 QList< QgsSymbolLegendNode * > nodes;
498 std::unique_ptr< QgsMarkerSymbol > tempSymbol;
503 legendSymbol = tempSymbol.get();
508 std::unique_ptr< QgsColorRampTransformer > t( createTransformer( minValue, maxValue ) );
512 for (
int i = 0; i < breaks.length(); i++ )
514 std::unique_ptr< QgsSymbolLegendNode > node;
515 std::unique_ptr< QgsMarkerSymbol > symbolClone( static_cast<QgsMarkerSymbol *>( legendSymbol->
clone() ) );
516 symbolClone->setColor( t->color( breaks[i] ) );
519 nodes << node.release();
524 QgsPropertyGenericNumericAssistantWidget::QgsPropertyGenericNumericAssistantWidget( QWidget *parent,
const QgsPropertyDefinition &definition,
const QgsProperty &initialState )
525 : QgsPropertyAbstractTransformerWidget( parent, definition )
529 layout()->setContentsMargins( 0, 0, 0, 0 );
530 layout()->setMargin( 0 );
532 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" ) );
554 minOutputSpinBox->setShowClearButton(
false );
555 maxOutputSpinBox->setShowClearButton(
false );
560 minOutputSpinBox->setValue( transform->minOutputValue() );
561 maxOutputSpinBox->setValue( transform->maxOutputValue() );
562 nullOutputSpinBox->setValue( transform->nullOutputValue() );
563 exponentSpinBox->setValue( transform->exponent() );
566 connect( minOutputSpinBox, static_cast <
void (
QgsDoubleSpinBox::* )(
double ) > ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
567 connect( maxOutputSpinBox, static_cast <
void (
QgsDoubleSpinBox::* )(
double ) > ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
568 connect( nullOutputSpinBox, static_cast <
void (
QgsDoubleSpinBox::* )(
double ) > ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
569 connect( exponentSpinBox, static_cast <
void (
QgsDoubleSpinBox::* )(
double ) > ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
577 minOutputSpinBox->value(),
578 maxOutputSpinBox->value(),
579 nullOutputSpinBox->value(),
580 exponentSpinBox->value() );
int lookupField(const QString &fieldName) const
Look 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)
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.
QVariant minimumValue(int index) const override
Returns the minimum value for an attribute column or an invalid variant in case of error...
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)
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.
Type propertyType() const
Returns the property type.
QgsFields fields() const override
Returns the list of fields of this layer.
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)...
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.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const override
Query the layer for features specified in request.
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...
QVariant maximumValue(int index) const override
Returns the maximum value for an attribute column or an invalid variant in case of error...
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
Gets a deep copy of this symbol.
static QgsProject * instance()
Returns the QgsProject singleton instance.
void addChildNode(QgsLayerTreeNode *node)
Append an existing node.
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.
Represents a vector layer which manages a vector based data sets.
QgsMarkerSymbol * clone() const override
Gets 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.