34 , mDefinition( definition )
39 layout()->setContentsMargins( 0, 0, 0, 0 );
43 mLegendPreview->hide();
45 minValueSpinBox->setShowClearButton(
false );
46 maxValueSpinBox->setShowClearButton(
false );
49 mExpressionWidget->setLayer(
const_cast< QgsVectorLayer *
>( mLayer ) );
53 if (
auto *lTransformer = initialState.
transformer() )
55 minValueSpinBox->setValue( lTransformer->minValue() );
56 maxValueSpinBox->setValue( lTransformer->maxValue() );
58 if ( lTransformer->curveTransform() )
60 mTransformCurveCheckBox->setChecked(
true );
61 mTransformCurveCheckBox->setCollapsed(
false );
62 mCurveEditor->setCurve( *lTransformer->curveTransform() );
66 connect( computeValuesButton, &QPushButton::clicked,
this, &QgsPropertyAssistantWidget::computeValuesFromLayer );
73 mLegendPreview->setModel( &mPreviewList );
74 mLegendPreview->setItemDelegate(
new QgsAssistantPreviewItemDelegate( &mPreviewList ) );
75 mLegendPreview->setHeaderHidden(
true );
76 mLegendPreview->expandAll();
77 mLegendVerticalFrame->setLayout(
new QVBoxLayout() );
78 mLegendVerticalFrame->layout()->setContentsMargins( 0, 0, 0, 0 );
79 mLegendVerticalFrame->hide();
86 mTransformerWidget =
new QgsPropertySizeAssistantWidget(
this, mDefinition, initialState );
87 mLegendPreview->show();
94 mTransformerWidget =
new QgsPropertyColorAssistantWidget(
this, mDefinition, initialState );
95 mLegendPreview->show();
101 mTransformerWidget =
new QgsPropertyGenericNumericAssistantWidget(
this, mDefinition, initialState );
109 mTransformerWidget =
new QgsPropertyGenericNumericAssistantWidget(
this, mDefinition, initialState );
115 if ( mTransformerWidget )
117 mOutputWidget->layout()->addWidget( mTransformerWidget );
120 mCurveEditor->setMinHistogramValueRange( minValueSpinBox->value() );
121 mCurveEditor->setMaxHistogramValueRange( maxValueSpinBox->value() );
123 mCurveEditor->setHistogramSource( mLayer, mExpressionWidget->currentField() );
126 mCurveEditor->setHistogramSource( mLayer, expression );
132 mTransformCurveCheckBox->setVisible( mTransformerWidget );
144 mExpressionContextGenerator = generator;
145 mExpressionWidget->registerExpressionContextGenerator( generator );
150 property.setActive( !mExpressionWidget->currentText().isEmpty() );
151 if ( mExpressionWidget->isExpression() )
152 property.setExpressionString( mExpressionWidget->currentField() );
154 property.setField( mExpressionWidget->currentField() );
156 if ( mTransformerWidget )
158 std::unique_ptr< QgsPropertyTransformer> t( mTransformerWidget->createTransformer( minValueSpinBox->value(), maxValueSpinBox->value() ) );
159 if ( mTransformCurveCheckBox->isChecked() )
165 t->setCurveTransform(
nullptr );
167 property.setTransformer( t.release() );
175 if (
dockMode && mLegendVerticalFrame->isHidden() )
177 mLegendVerticalFrame->layout()->addWidget( mLegendPreview );
178 mLegendVerticalFrame->show();
182 void QgsPropertyAssistantWidget::computeValuesFromLayer()
187 double minValue = 0.0;
188 double maxValue = 0.0;
190 if ( mExpressionWidget->isExpression() )
192 if ( !computeValuesFromExpression( mExpressionWidget->currentField(), minValue, maxValue ) )
197 if ( !computeValuesFromField( mExpressionWidget->currentField(), minValue, maxValue ) )
204 mCurveEditor->setMinHistogramValueRange( minValueSpinBox->value() );
205 mCurveEditor->setMaxHistogramValueRange( maxValueSpinBox->value() );
210 void QgsPropertyAssistantWidget::updatePreview()
212 if ( mLegendPreview->isHidden() || !mTransformerWidget || !mLayer )
215 mLegendPreview->setIconSize( QSize( 512, 512 ) );
216 mPreviewList.clear();
219 maxValueSpinBox->value(), 8 );
222 const QList< QgsSymbolLegendNode * > nodes = mTransformerWidget->generatePreviews( breaks, mLayerTreeLayer, mSymbol.get(), minValueSpinBox->value(),
223 maxValueSpinBox->value(), mTransformCurveCheckBox->isChecked() ? &curve :
nullptr );
227 const auto constNodes = nodes;
230 const QSize minSize( node->minimumIconSize() );
231 node->setIconSize( minSize );
232 widthMax = std::max( minSize.width(), widthMax );
233 QStandardItem *item =
new QStandardItem( node->data( Qt::DecorationRole ).value<QPixmap>(), QLocale().toString( breaks[i] ) );
234 item->setEditable(
false );
235 mPreviewList.appendRow( item );
241 for (
int i = 0; i < breaks.length(); i++ )
243 const QPixmap img( mPreviewList.item( i )->icon().pixmap( mPreviewList.item( i )->icon().actualSize( QSize( 512, 512 ) ) ) );
244 QPixmap enlarged( widthMax, img.height() );
246 enlarged.fill( Qt::transparent );
247 QPainter p( &enlarged );
248 p.drawPixmap( QPoint( ( widthMax - img.width() ) / 2, 0 ), img );
250 mPreviewList.item( i )->setIcon( enlarged );
254 bool QgsPropertyAssistantWidget::computeValuesFromExpression(
const QString &expression,
double &minValue,
double &maxValue )
const
259 if ( mExpressionContextGenerator )
270 if ( !e.prepare( &context ) )
273 const QSet<QString> referencedCols( e.referencedColumns() );
282 double min = std::numeric_limits<double>::max();
283 double max = std::numeric_limits<double>::lowest();
290 const double value = e.evaluate( &context ).toDouble( &ok );
293 max = std::max( max, value );
294 min = std::min( min, value );
306 bool QgsPropertyAssistantWidget::computeValuesFromField(
const QString &fieldName,
double &minValue,
double &maxValue )
const
309 if ( fieldIndex < 0 )
319 const double minDouble = min.toDouble( &ok );
323 const double maxDouble = max.toDouble( &ok );
327 minValue = minDouble;
328 maxValue = maxDouble;
339 : QgsPropertyAbstractTransformerWidget( parent, definition )
343 layout()->setContentsMargins( 0, 0, 0, 0 );
358 minSizeSpinBox->setShowClearButton(
false );
359 maxSizeSpinBox->setShowClearButton(
false );
360 nullSizeSpinBox->setShowClearButton(
false );
364 minSizeSpinBox->setValue( sizeTransform->minSize() );
365 maxSizeSpinBox->setValue( sizeTransform->maxSize() );
366 nullSizeSpinBox->setValue( sizeTransform->nullSize() );
367 exponentSpinBox->setValue( sizeTransform->exponent() );
368 scaleMethodComboBox->setCurrentIndex( scaleMethodComboBox->findData( sizeTransform->type() ) );
373 connect( minSizeSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
374 connect( maxSizeSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
375 connect( nullSizeSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
376 connect( exponentSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
377 connect( scaleMethodComboBox,
static_cast < void ( QComboBox::* )(
int )
> ( &QComboBox::currentIndexChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
378 connect( scaleMethodComboBox,
static_cast < void ( QComboBox::* )(
int )
> ( &QComboBox::currentIndexChanged ),
this,
386 QgsSizeScaleTransformer *QgsPropertySizeAssistantWidget::createTransformer(
double minValue,
double maxValue )
const
392 minSizeSpinBox->value(),
393 maxSizeSpinBox->value(),
394 nullSizeSpinBox->value(),
395 exponentSpinBox->value() );
399 QList< QgsSymbolLegendNode * > QgsPropertySizeAssistantWidget::generatePreviews(
const QList<double> &breaks,
QgsLayerTreeLayer *parent,
const QgsSymbol *symbol,
double minValue,
double maxValue,
QgsCurveTransform *curve )
const
401 QList< QgsSymbolLegendNode * > nodes;
404 std::unique_ptr< QgsSymbol > tempSymbol;
416 legendSymbol = tempSymbol.get();
421 std::unique_ptr< QgsSizeScaleTransformer > t( createTransformer( minValue, maxValue ) );
425 for (
int i = 0; i < breaks.length(); i++ )
427 std::unique_ptr< QgsSymbolLegendNode > node;
430 std::unique_ptr< QgsMarkerSymbol > symbolClone(
static_cast<QgsMarkerSymbol *
>( legendSymbol->
clone() ) );
433 symbolClone->setSize( t->size( breaks[i] ) );
436 else if (
dynamic_cast<const QgsLineSymbol *
>( legendSymbol ) )
438 std::unique_ptr< QgsLineSymbol > symbolClone(
static_cast<QgsLineSymbol *
>( legendSymbol->
clone() ) );
440 symbolClone->setWidth( t->size( breaks[i] ) );
444 nodes << node.release();
451 return QList< QgsSymbolLegendNode * >();
454 QgsPropertyColorAssistantWidget::QgsPropertyColorAssistantWidget( QWidget *parent,
const QgsPropertyDefinition &definition,
const QgsProperty &initialState )
455 : QgsPropertyAbstractTransformerWidget( parent, definition )
459 layout()->setContentsMargins( 0, 0, 0, 0 );
462 mNullColorButton->setAllowOpacity( supportsAlpha );
463 mNullColorButton->setShowNoColor(
true );
464 mNullColorButton->setColorDialogTitle( tr(
"Color For Null Values" ) );
465 mNullColorButton->setContext( QStringLiteral(
"symbology" ) );
466 mNullColorButton->setNoColorString( tr(
"Transparent" ) );
470 mNullColorButton->setColor( colorTransform->nullColor() );
471 if ( colorTransform->colorRamp() )
472 mColorRampButton->setColorRamp( colorTransform->colorRamp() );
478 if ( !mColorRampButton->colorRamp() )
481 const QString defaultRampName =
QgsProject::instance()->
readEntry( QStringLiteral(
"DefaultStyles" ), QStringLiteral(
"/ColorRamp" ), QString() );
482 const std::unique_ptr< QgsColorRamp > defaultRamp(
QgsStyle::defaultStyle()->colorRamp( !defaultRampName.isEmpty() ? defaultRampName : QStringLiteral(
"Blues" ) ) );
484 mColorRampButton->setColorRamp( defaultRamp.get() );
488 QgsColorRampTransformer *QgsPropertyColorAssistantWidget::createTransformer(
double minValue,
double maxValue )
const
493 mColorRampButton->colorRamp(),
494 mNullColorButton->color() );
498 QList<QgsSymbolLegendNode *> QgsPropertyColorAssistantWidget::generatePreviews(
const QList<double> &breaks,
QgsLayerTreeLayer *parent,
const QgsSymbol *symbol,
double minValue,
double maxValue,
QgsCurveTransform *curve )
const
500 QList< QgsSymbolLegendNode * > nodes;
503 std::unique_ptr< QgsMarkerSymbol > tempSymbol;
508 legendSymbol = tempSymbol.get();
513 std::unique_ptr< QgsColorRampTransformer > t( createTransformer( minValue, maxValue ) );
517 for (
int i = 0; i < breaks.length(); i++ )
519 std::unique_ptr< QgsSymbolLegendNode > node;
520 std::unique_ptr< QgsMarkerSymbol > symbolClone(
static_cast<QgsMarkerSymbol *
>( legendSymbol->
clone() ) );
521 symbolClone->setColor( t->color( breaks[i] ) );
524 nodes << node.release();
529 QgsPropertyGenericNumericAssistantWidget::QgsPropertyGenericNumericAssistantWidget( QWidget *parent,
const QgsPropertyDefinition &definition,
const QgsProperty &initialState )
530 : QgsPropertyAbstractTransformerWidget( parent, definition )
534 layout()->setContentsMargins( 0, 0, 0, 0 );
536 nullOutputSpinBox->setShowClearButton(
false );
543 minOutputSpinBox->setMaximum( 360.0 );
544 minOutputSpinBox->setValue( 0.0 );
545 minOutputSpinBox->setShowClearButton(
true );
546 minOutputSpinBox->setClearValue( 0.0 );
547 minOutputSpinBox->setSuffix( tr(
" °" ) );
548 maxOutputSpinBox->setMaximum( 360.0 );
549 maxOutputSpinBox->setValue( 360.0 );
550 maxOutputSpinBox->setShowClearButton(
true );
551 maxOutputSpinBox->setClearValue( 360.0 );
552 maxOutputSpinBox->setSuffix( tr(
" °" ) );
553 exponentSpinBox->hide();
554 mExponentLabel->hide();
555 mLabelMinOutput->setText( tr(
"Angle from" ) );
556 mLabelNullOutput->setText( tr(
"Angle when NULL" ) );
563 minOutputSpinBox->setMaximum( 100.0 );
564 minOutputSpinBox->setValue( 0.0 );
565 minOutputSpinBox->setShowClearButton(
true );
566 minOutputSpinBox->setClearValue( 0.0 );
567 minOutputSpinBox->setSuffix( tr(
" %" ) );
568 maxOutputSpinBox->setMaximum( 100.0 );
569 maxOutputSpinBox->setValue( 100.0 );
570 maxOutputSpinBox->setShowClearButton(
true );
571 maxOutputSpinBox->setClearValue( 100.0 );
572 maxOutputSpinBox->setSuffix( tr(
" %" ) );
573 mLabelMinOutput->setText( tr(
"Opacity from" ) );
574 mLabelNullOutput->setText( tr(
"Opacity when NULL" ) );
580 minOutputSpinBox->setMinimum( 0 );
581 maxOutputSpinBox->setMinimum( 0 );
582 minOutputSpinBox->setShowClearButton(
false );
583 maxOutputSpinBox->setShowClearButton(
false );
587 minOutputSpinBox->setMinimum( 1 );
588 maxOutputSpinBox->setMinimum( 1 );
589 minOutputSpinBox->setShowClearButton(
false );
590 maxOutputSpinBox->setShowClearButton(
false );
594 minOutputSpinBox->setMinimum( 0 );
595 maxOutputSpinBox->setMinimum( 0 );
596 minOutputSpinBox->setMaximum( 1 );
597 maxOutputSpinBox->setMaximum( 1 );
598 minOutputSpinBox->setShowClearButton(
false );
599 maxOutputSpinBox->setShowClearButton(
false );
603 minOutputSpinBox->setMinimum( -99999999.000000 );
604 maxOutputSpinBox->setMinimum( -99999999.000000 );
605 minOutputSpinBox->setMaximum( 99999999.000000 );
606 maxOutputSpinBox->setMaximum( 99999999.000000 );
607 minOutputSpinBox->setShowClearButton(
false );
608 maxOutputSpinBox->setShowClearButton(
false );
613 minOutputSpinBox->setShowClearButton(
false );
614 maxOutputSpinBox->setShowClearButton(
false );
621 minOutputSpinBox->setValue( transform->minOutputValue() );
622 maxOutputSpinBox->setValue( transform->maxOutputValue() );
623 nullOutputSpinBox->setValue( transform->nullOutputValue() );
624 exponentSpinBox->setValue( transform->exponent() );
627 connect( minOutputSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
628 connect( maxOutputSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
629 connect( nullOutputSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
630 connect( exponentSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
638 minOutputSpinBox->value(),
639 maxOutputSpinBox->value(),
640 nullOutputSpinBox->value(),
641 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 unique ID, geometry and a list of field...
@ 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.
@ Double
Double value (including negative values)
@ Double0To1
Double value between 0-1 (inclusive)
@ StrokeWidth
Line stroke width.
@ IntegerPositiveGreaterZero
Non-zero positive integer values.
@ IntegerPositive
Positive integer values (including 0)
@ 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.
@ DoublePositive
Positive double value (including 0)
@ 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.
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.
void minimumAndMaximumValue(int index, QVariant &minimum, QVariant &maximum) const
Calculates both the minimum and maximum value for an attribute column.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.