35 , mDefinition( definition )
40 layout()->setContentsMargins( 0, 0, 0, 0 );
44 mLegendPreview->hide();
46 minValueSpinBox->setShowClearButton(
false );
47 maxValueSpinBox->setShowClearButton(
false );
50 mExpressionWidget->setLayer(
const_cast< QgsVectorLayer *
>( mLayer ) );
54 if (
auto *lTransformer = initialState.
transformer() )
56 minValueSpinBox->setValue( lTransformer->minValue() );
57 maxValueSpinBox->setValue( lTransformer->maxValue() );
59 if ( lTransformer->curveTransform() )
61 mTransformCurveCheckBox->setChecked(
true );
62 mTransformCurveCheckBox->setCollapsed(
false );
63 mCurveEditor->setCurve( *lTransformer->curveTransform() );
67 connect( computeValuesButton, &QPushButton::clicked,
this, &QgsPropertyAssistantWidget::computeValuesFromLayer );
74 mLegendPreview->setModel( &mPreviewList );
75 mLegendPreview->setItemDelegate(
new QgsAssistantPreviewItemDelegate( &mPreviewList ) );
76 mLegendPreview->setHeaderHidden(
true );
77 mLegendPreview->expandAll();
78 mLegendVerticalFrame->setLayout(
new QVBoxLayout() );
79 mLegendVerticalFrame->layout()->setContentsMargins( 0, 0, 0, 0 );
80 mLegendVerticalFrame->hide();
87 mTransformerWidget =
new QgsPropertySizeAssistantWidget(
this, mDefinition, initialState );
88 mLegendPreview->show();
95 mTransformerWidget =
new QgsPropertyColorAssistantWidget(
this, mDefinition, initialState );
96 mLegendPreview->show();
102 mTransformerWidget =
new QgsPropertyGenericNumericAssistantWidget(
this, mDefinition, initialState );
110 mTransformerWidget =
new QgsPropertyGenericNumericAssistantWidget(
this, mDefinition, initialState );
116 if ( mTransformerWidget )
118 mOutputWidget->layout()->addWidget( mTransformerWidget );
121 mCurveEditor->setMinHistogramValueRange( minValueSpinBox->value() );
122 mCurveEditor->setMaxHistogramValueRange( maxValueSpinBox->value() );
124 mCurveEditor->setHistogramSource( mLayer, mExpressionWidget->currentField() );
127 mCurveEditor->setHistogramSource( mLayer, expression );
133 mTransformCurveCheckBox->setVisible( mTransformerWidget );
145 mExpressionContextGenerator = generator;
146 mExpressionWidget->registerExpressionContextGenerator( generator );
151 property.setActive( !mExpressionWidget->currentText().isEmpty() );
152 if ( mExpressionWidget->isExpression() )
153 property.setExpressionString( mExpressionWidget->currentField() );
155 property.setField( mExpressionWidget->currentField() );
157 if ( mTransformerWidget )
159 std::unique_ptr< QgsPropertyTransformer> t( mTransformerWidget->createTransformer( minValueSpinBox->value(), maxValueSpinBox->value() ) );
160 if ( mTransformCurveCheckBox->isChecked() )
166 t->setCurveTransform(
nullptr );
168 property.setTransformer( t.release() );
176 if (
dockMode && mLegendVerticalFrame->isHidden() )
178 mLegendVerticalFrame->layout()->addWidget( mLegendPreview );
179 mLegendVerticalFrame->show();
183void QgsPropertyAssistantWidget::computeValuesFromLayer()
188 double minValue = 0.0;
189 double maxValue = 0.0;
191 if ( mExpressionWidget->isExpression() )
193 if ( !computeValuesFromExpression( mExpressionWidget->currentField(), minValue, maxValue ) )
198 if ( !computeValuesFromField( mExpressionWidget->currentField(), minValue, maxValue ) )
205 mCurveEditor->setMinHistogramValueRange( minValueSpinBox->value() );
206 mCurveEditor->setMaxHistogramValueRange( maxValueSpinBox->value() );
211void QgsPropertyAssistantWidget::updatePreview()
213 if ( mLegendPreview->isHidden() || !mTransformerWidget || !mLayer )
216 mLegendPreview->setIconSize( QSize( 512, 512 ) );
217 mPreviewList.clear();
220 maxValueSpinBox->value(), 8 );
223 const QList< QgsSymbolLegendNode * > nodes = mTransformerWidget->generatePreviews( breaks, mLayerTreeLayer, mSymbol.get(), minValueSpinBox->value(),
224 maxValueSpinBox->value(), mTransformCurveCheckBox->isChecked() ? &curve :
nullptr );
228 const auto constNodes = nodes;
231 const QSize minSize( node->minimumIconSize() );
232 node->setIconSize( minSize );
233 widthMax = std::max( minSize.width(), widthMax );
234 QStandardItem *item =
new QStandardItem( node->data( Qt::DecorationRole ).value<QPixmap>(), QLocale().toString( breaks[i] ) );
235 item->setEditable(
false );
236 mPreviewList.appendRow( item );
242 for (
int i = 0; i < breaks.length(); i++ )
244 const QPixmap img( mPreviewList.item( i )->icon().pixmap( mPreviewList.item( i )->icon().actualSize( QSize( 512, 512 ) ) ) );
245 QPixmap enlarged( widthMax, img.height() );
247 enlarged.fill( Qt::transparent );
248 QPainter p( &enlarged );
249 p.drawPixmap( QPoint( ( widthMax - img.width() ) / 2, 0 ), img );
251 mPreviewList.item( i )->setIcon( enlarged );
255bool QgsPropertyAssistantWidget::computeValuesFromExpression(
const QString &expression,
double &minValue,
double &maxValue )
const
260 if ( mExpressionContextGenerator )
271 if ( !e.prepare( &context ) )
274 const QSet<QString> referencedCols( e.referencedColumns() );
283 double min = std::numeric_limits<double>::max();
284 double max = std::numeric_limits<double>::lowest();
291 const double value = e.evaluate( &context ).toDouble( &ok );
294 max = std::max( max, value );
295 min = std::min( min, value );
307bool QgsPropertyAssistantWidget::computeValuesFromField(
const QString &fieldName,
double &minValue,
double &maxValue )
const
310 if ( fieldIndex < 0 )
320 const double minDouble = min.toDouble( &ok );
324 const double maxDouble = max.toDouble( &ok );
328 minValue = minDouble;
329 maxValue = maxDouble;
340 : QgsPropertyAbstractTransformerWidget( parent, definition )
344 layout()->setContentsMargins( 0, 0, 0, 0 );
359 minSizeSpinBox->setShowClearButton(
false );
360 maxSizeSpinBox->setShowClearButton(
false );
361 nullSizeSpinBox->setShowClearButton(
false );
365 minSizeSpinBox->setValue( sizeTransform->minSize() );
366 maxSizeSpinBox->setValue( sizeTransform->maxSize() );
367 nullSizeSpinBox->setValue( sizeTransform->nullSize() );
368 exponentSpinBox->setValue( sizeTransform->exponent() );
369 scaleMethodComboBox->setCurrentIndex( scaleMethodComboBox->findData( sizeTransform->type() ) );
374 connect( minSizeSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
375 connect( maxSizeSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
376 connect( nullSizeSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
377 connect( exponentSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
378 connect( scaleMethodComboBox,
static_cast < void ( QComboBox::* )(
int )
> ( &QComboBox::currentIndexChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
379 connect( scaleMethodComboBox,
static_cast < void ( QComboBox::* )(
int )
> ( &QComboBox::currentIndexChanged ),
this,
387QgsSizeScaleTransformer *QgsPropertySizeAssistantWidget::createTransformer(
double minValue,
double maxValue )
const
393 minSizeSpinBox->value(),
394 maxSizeSpinBox->value(),
395 nullSizeSpinBox->value(),
396 exponentSpinBox->value() );
400QList< QgsSymbolLegendNode * > QgsPropertySizeAssistantWidget::generatePreviews(
const QList<double> &breaks,
QgsLayerTreeLayer *parent,
const QgsSymbol *symbol,
double minValue,
double maxValue,
QgsCurveTransform *curve )
const
402 QList< QgsSymbolLegendNode * > nodes;
405 std::unique_ptr< QgsSymbol > tempSymbol;
417 legendSymbol = tempSymbol.get();
422 std::unique_ptr< QgsSizeScaleTransformer > t( createTransformer( minValue, maxValue ) );
426 for (
int i = 0; i < breaks.length(); i++ )
428 std::unique_ptr< QgsSymbolLegendNode > node;
431 std::unique_ptr< QgsMarkerSymbol > symbolClone(
static_cast<QgsMarkerSymbol *
>( legendSymbol->
clone() ) );
434 symbolClone->setSize( t->size( breaks[i] ) );
437 else if (
dynamic_cast<const QgsLineSymbol *
>( legendSymbol ) )
439 std::unique_ptr< QgsLineSymbol > symbolClone(
static_cast<QgsLineSymbol *
>( legendSymbol->
clone() ) );
441 symbolClone->setWidth( t->size( breaks[i] ) );
445 nodes << node.release();
452 return QList< QgsSymbolLegendNode * >();
455QgsPropertyColorAssistantWidget::QgsPropertyColorAssistantWidget( QWidget *parent,
const QgsPropertyDefinition &definition,
const QgsProperty &initialState )
456 : QgsPropertyAbstractTransformerWidget( parent, definition )
460 layout()->setContentsMargins( 0, 0, 0, 0 );
463 mNullColorButton->setAllowOpacity( supportsAlpha );
464 mNullColorButton->setShowNoColor(
true );
465 mNullColorButton->setColorDialogTitle( tr(
"Color For Null Values" ) );
466 mNullColorButton->setContext( QStringLiteral(
"symbology" ) );
467 mNullColorButton->setNoColorString( tr(
"Transparent" ) );
471 mNullColorButton->setColor( colorTransform->nullColor() );
472 if ( colorTransform->colorRamp() )
473 mColorRampButton->setColorRamp( colorTransform->colorRamp() );
479 if ( !mColorRampButton->colorRamp() )
482 std::unique_ptr< QgsColorRamp > colorRamp(
QgsProject::instance()->styleSettings()->defaultColorRamp() );
488 mColorRampButton->setColorRamp( colorRamp.get() );
492QgsColorRampTransformer *QgsPropertyColorAssistantWidget::createTransformer(
double minValue,
double maxValue )
const
497 mColorRampButton->colorRamp(),
498 mNullColorButton->color() );
502QList<QgsSymbolLegendNode *> QgsPropertyColorAssistantWidget::generatePreviews(
const QList<double> &breaks,
QgsLayerTreeLayer *parent,
const QgsSymbol *symbol,
double minValue,
double maxValue,
QgsCurveTransform *curve )
const
504 QList< QgsSymbolLegendNode * > nodes;
507 std::unique_ptr< QgsMarkerSymbol > tempSymbol;
512 legendSymbol = tempSymbol.get();
517 std::unique_ptr< QgsColorRampTransformer > t( createTransformer( minValue, maxValue ) );
521 for (
int i = 0; i < breaks.length(); i++ )
523 std::unique_ptr< QgsSymbolLegendNode > node;
524 std::unique_ptr< QgsMarkerSymbol > symbolClone(
static_cast<QgsMarkerSymbol *
>( legendSymbol->
clone() ) );
525 symbolClone->setColor( t->color( breaks[i] ) );
528 nodes << node.release();
533QgsPropertyGenericNumericAssistantWidget::QgsPropertyGenericNumericAssistantWidget( QWidget *parent,
const QgsPropertyDefinition &definition,
const QgsProperty &initialState )
534 : QgsPropertyAbstractTransformerWidget( parent, definition )
538 layout()->setContentsMargins( 0, 0, 0, 0 );
540 nullOutputSpinBox->setShowClearButton(
false );
547 minOutputSpinBox->setMaximum( 360.0 );
548 minOutputSpinBox->setValue( 0.0 );
549 minOutputSpinBox->setShowClearButton(
true );
550 minOutputSpinBox->setClearValue( 0.0 );
551 minOutputSpinBox->setSuffix( tr(
" °" ) );
552 maxOutputSpinBox->setMaximum( 360.0 );
553 maxOutputSpinBox->setValue( 360.0 );
554 maxOutputSpinBox->setShowClearButton(
true );
555 maxOutputSpinBox->setClearValue( 360.0 );
556 maxOutputSpinBox->setSuffix( tr(
" °" ) );
557 exponentSpinBox->hide();
558 mExponentLabel->hide();
559 mLabelMinOutput->setText( tr(
"Angle from" ) );
560 mLabelNullOutput->setText( tr(
"Angle when NULL" ) );
567 minOutputSpinBox->setMaximum( 100.0 );
568 minOutputSpinBox->setValue( 0.0 );
569 minOutputSpinBox->setShowClearButton(
true );
570 minOutputSpinBox->setClearValue( 0.0 );
571 minOutputSpinBox->setSuffix( tr(
" %" ) );
572 maxOutputSpinBox->setMaximum( 100.0 );
573 maxOutputSpinBox->setValue( 100.0 );
574 maxOutputSpinBox->setShowClearButton(
true );
575 maxOutputSpinBox->setClearValue( 100.0 );
576 maxOutputSpinBox->setSuffix( tr(
" %" ) );
577 mLabelMinOutput->setText( tr(
"Opacity from" ) );
578 mLabelNullOutput->setText( tr(
"Opacity when NULL" ) );
584 minOutputSpinBox->setMinimum( 0 );
585 maxOutputSpinBox->setMinimum( 0 );
586 minOutputSpinBox->setShowClearButton(
false );
587 maxOutputSpinBox->setShowClearButton(
false );
591 minOutputSpinBox->setMinimum( 1 );
592 maxOutputSpinBox->setMinimum( 1 );
593 minOutputSpinBox->setShowClearButton(
false );
594 maxOutputSpinBox->setShowClearButton(
false );
598 minOutputSpinBox->setMinimum( 0 );
599 maxOutputSpinBox->setMinimum( 0 );
600 minOutputSpinBox->setMaximum( 1 );
601 maxOutputSpinBox->setMaximum( 1 );
602 minOutputSpinBox->setShowClearButton(
false );
603 maxOutputSpinBox->setShowClearButton(
false );
607 minOutputSpinBox->setMinimum( -99999999.000000 );
608 maxOutputSpinBox->setMinimum( -99999999.000000 );
609 minOutputSpinBox->setMaximum( 99999999.000000 );
610 maxOutputSpinBox->setMaximum( 99999999.000000 );
611 minOutputSpinBox->setShowClearButton(
false );
612 maxOutputSpinBox->setShowClearButton(
false );
617 minOutputSpinBox->setShowClearButton(
false );
618 maxOutputSpinBox->setShowClearButton(
false );
625 minOutputSpinBox->setValue( transform->minOutputValue() );
626 maxOutputSpinBox->setValue( transform->maxOutputValue() );
627 nullOutputSpinBox->setValue( transform->nullOutputValue() );
628 exponentSpinBox->setValue( transform->exponent() );
631 connect( minOutputSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
632 connect( maxOutputSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
633 connect( nullOutputSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
634 connect( exponentSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
642 minOutputSpinBox->value(),
643 maxOutputSpinBox->value(),
644 nullOutputSpinBox->value(),
645 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.
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.