37 , mDefinition( definition )
42 layout()->setContentsMargins( 0, 0, 0, 0 );
46 mLegendPreview->hide();
48 minValueSpinBox->setShowClearButton(
false );
49 maxValueSpinBox->setShowClearButton(
false );
52 mExpressionWidget->setLayer(
const_cast< QgsVectorLayer *
>( mLayer ) );
56 if (
auto *lTransformer = initialState.
transformer() )
58 minValueSpinBox->setValue( lTransformer->minValue() );
59 maxValueSpinBox->setValue( lTransformer->maxValue() );
61 if ( lTransformer->curveTransform() )
63 mTransformCurveCheckBox->setChecked(
true );
64 mTransformCurveCheckBox->setCollapsed(
false );
65 mCurveEditor->setCurve( *lTransformer->curveTransform() );
69 connect( computeValuesButton, &QPushButton::clicked,
this, &QgsPropertyAssistantWidget::computeValuesFromLayer );
76 mLegendPreview->setModel( &mPreviewList );
77 mLegendPreview->setItemDelegate(
new QgsAssistantPreviewItemDelegate( &mPreviewList ) );
78 mLegendPreview->setHeaderHidden(
true );
79 mLegendPreview->expandAll();
80 mLegendVerticalFrame->setLayout(
new QVBoxLayout() );
81 mLegendVerticalFrame->layout()->setContentsMargins( 0, 0, 0, 0 );
82 mLegendVerticalFrame->hide();
89 mTransformerWidget =
new QgsPropertySizeAssistantWidget(
this, mDefinition, initialState );
90 mLegendPreview->show();
97 mTransformerWidget =
new QgsPropertyColorAssistantWidget(
this, mDefinition, initialState );
98 mLegendPreview->show();
104 mTransformerWidget =
new QgsPropertyGenericNumericAssistantWidget(
this, mDefinition, initialState );
112 mTransformerWidget =
new QgsPropertyGenericNumericAssistantWidget(
this, mDefinition, initialState );
118 if ( mTransformerWidget )
120 mOutputWidget->layout()->addWidget( mTransformerWidget );
123 mCurveEditor->setMinHistogramValueRange( minValueSpinBox->value() );
124 mCurveEditor->setMaxHistogramValueRange( maxValueSpinBox->value() );
126 mCurveEditor->setHistogramSource( mLayer, mExpressionWidget->currentField() );
129 mCurveEditor->setHistogramSource( mLayer, expression );
135 mTransformCurveCheckBox->setVisible( mTransformerWidget );
148 mExpressionContextGenerator = generator;
149 mExpressionWidget->registerExpressionContextGenerator( generator );
154 property.setActive( !mExpressionWidget->currentText().isEmpty() );
155 if ( mExpressionWidget->isExpression() )
156 property.setExpressionString( mExpressionWidget->currentField() );
158 property.setField( mExpressionWidget->currentField() );
160 if ( mTransformerWidget )
162 std::unique_ptr< QgsPropertyTransformer> t( mTransformerWidget->createTransformer( minValueSpinBox->value(), maxValueSpinBox->value() ) );
163 if ( mTransformCurveCheckBox->isChecked() )
169 t->setCurveTransform(
nullptr );
171 property.setTransformer( t.release() );
179 if (
dockMode && mLegendVerticalFrame->isHidden() )
181 mLegendVerticalFrame->layout()->addWidget( mLegendPreview );
182 mLegendVerticalFrame->show();
186void QgsPropertyAssistantWidget::computeValuesFromLayer()
191 double minValue = 0.0;
192 double maxValue = 0.0;
194 if ( mExpressionWidget->isExpression() )
196 if ( !computeValuesFromExpression( mExpressionWidget->currentField(), minValue, maxValue ) )
201 if ( !computeValuesFromField( mExpressionWidget->currentField(), minValue, maxValue ) )
208 mCurveEditor->setMinHistogramValueRange( minValueSpinBox->value() );
209 mCurveEditor->setMaxHistogramValueRange( maxValueSpinBox->value() );
214void QgsPropertyAssistantWidget::updatePreview()
216 if ( mLegendPreview->isHidden() || !mTransformerWidget || !mLayer )
219 mLegendPreview->setIconSize( QSize( 512, 512 ) );
220 mPreviewList.clear();
223 maxValueSpinBox->value(), 8 );
226 const QList< QgsSymbolLegendNode * > nodes = mTransformerWidget->generatePreviews( breaks, mLayerTreeLayer, mSymbol.get(), minValueSpinBox->value(),
227 maxValueSpinBox->value(), mTransformCurveCheckBox->isChecked() ? &curve : nullptr );
231 const auto constNodes = nodes;
234 const QSize minSize( node->minimumIconSize() );
235 node->setIconSize( minSize );
236 widthMax = std::max( minSize.width(), widthMax );
237 QStandardItem *item =
new QStandardItem( node->data( Qt::DecorationRole ).value<QPixmap>(), QLocale().toString( breaks[i] ) );
238 item->setEditable(
false );
239 mPreviewList.appendRow( item );
245 for (
int i = 0; i < breaks.length(); i++ )
247 const QPixmap img( mPreviewList.item( i )->icon().pixmap( mPreviewList.item( i )->icon().actualSize( QSize( 512, 512 ) ) ) );
248 QPixmap enlarged( widthMax, img.height() );
250 enlarged.fill( Qt::transparent );
251 QPainter p( &enlarged );
252 p.drawPixmap( QPoint( ( widthMax - img.width() ) / 2, 0 ), img );
254 mPreviewList.item( i )->setIcon( enlarged );
258bool QgsPropertyAssistantWidget::computeValuesFromExpression(
const QString &expression,
double &minValue,
double &maxValue )
const
263 if ( mExpressionContextGenerator )
274 if ( !e.prepare( &context ) )
277 const QSet<QString> referencedCols( e.referencedColumns() );
282 :
Qgis::FeatureRequestFlag::NoGeometry )
283 .setSubsetOfAttributes( referencedCols, mLayer->fields() ) );
286 double min = std::numeric_limits<double>::max();
287 double max = std::numeric_limits<double>::lowest();
294 const double value = e.evaluate( &context ).toDouble( &ok );
297 max = std::max( max, value );
298 min = std::min( min, value );
310bool QgsPropertyAssistantWidget::computeValuesFromField(
const QString &fieldName,
double &minValue,
double &maxValue )
const
313 if ( fieldIndex < 0 )
323 const double minDouble = min.toDouble( &ok );
327 const double maxDouble = max.toDouble( &ok );
331 minValue = minDouble;
332 maxValue = maxDouble;
343 : QgsPropertyAbstractTransformerWidget( parent, definition )
347 layout()->setContentsMargins( 0, 0, 0, 0 );
362 minSizeSpinBox->setShowClearButton(
false );
363 maxSizeSpinBox->setShowClearButton(
false );
364 nullSizeSpinBox->setShowClearButton(
false );
368 minSizeSpinBox->setValue( sizeTransform->minSize() );
369 maxSizeSpinBox->setValue( sizeTransform->maxSize() );
370 nullSizeSpinBox->setValue( sizeTransform->nullSize() );
371 exponentSpinBox->setValue( sizeTransform->exponent() );
372 scaleMethodComboBox->setCurrentIndex( scaleMethodComboBox->findData( sizeTransform->type() ) );
377 connect( minSizeSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
378 connect( maxSizeSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
379 connect( nullSizeSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
380 connect( exponentSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
381 connect( scaleMethodComboBox,
static_cast < void ( QComboBox::* )(
int )
> ( &QComboBox::currentIndexChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
382 connect( scaleMethodComboBox,
static_cast < void ( QComboBox::* )(
int )
> ( &QComboBox::currentIndexChanged ),
this,
390QgsSizeScaleTransformer *QgsPropertySizeAssistantWidget::createTransformer(
double minValue,
double maxValue )
const
396 minSizeSpinBox->value(),
397 maxSizeSpinBox->value(),
398 nullSizeSpinBox->value(),
399 exponentSpinBox->value() );
403QList< QgsSymbolLegendNode * > QgsPropertySizeAssistantWidget::generatePreviews(
const QList<double> &breaks,
QgsLayerTreeLayer *parent,
const QgsSymbol *symbol,
double minValue,
double maxValue,
QgsCurveTransform *curve )
const
405 QList< QgsSymbolLegendNode * > nodes;
408 std::unique_ptr< QgsSymbol > tempSymbol;
420 legendSymbol = tempSymbol.get();
425 std::unique_ptr< QgsSizeScaleTransformer > t( createTransformer( minValue, maxValue ) );
429 for (
int i = 0; i < breaks.length(); i++ )
431 std::unique_ptr< QgsSymbolLegendNode > node;
434 std::unique_ptr< QgsMarkerSymbol > symbolClone(
static_cast<QgsMarkerSymbol *
>( legendSymbol->
clone() ) );
437 symbolClone->setSize( t->size( breaks[i] ) );
440 else if (
dynamic_cast<const QgsLineSymbol *
>( legendSymbol ) )
442 std::unique_ptr< QgsLineSymbol > symbolClone(
static_cast<QgsLineSymbol *
>( legendSymbol->
clone() ) );
444 symbolClone->setWidth( t->size( breaks[i] ) );
448 nodes << node.release();
455 return QList< QgsSymbolLegendNode * >();
458QgsPropertyColorAssistantWidget::QgsPropertyColorAssistantWidget( QWidget *parent,
const QgsPropertyDefinition &definition,
const QgsProperty &initialState )
459 : QgsPropertyAbstractTransformerWidget( parent, definition )
463 layout()->setContentsMargins( 0, 0, 0, 0 );
466 mNullColorButton->setAllowOpacity( supportsAlpha );
467 mNullColorButton->setShowNoColor(
true );
468 mNullColorButton->setColorDialogTitle( tr(
"Color For Null Values" ) );
469 mNullColorButton->setContext( QStringLiteral(
"symbology" ) );
470 mNullColorButton->setNoColorString( tr(
"Transparent" ) );
474 mNullColorButton->setColor( colorTransform->nullColor() );
475 if ( colorTransform->colorRamp() )
476 mColorRampButton->setColorRamp( colorTransform->colorRamp() );
482 if ( !mColorRampButton->colorRamp() )
485 std::unique_ptr< QgsColorRamp > colorRamp(
QgsProject::instance()->styleSettings()->defaultColorRamp() );
491 mColorRampButton->setColorRamp( colorRamp.get() );
495QgsColorRampTransformer *QgsPropertyColorAssistantWidget::createTransformer(
double minValue,
double maxValue )
const
500 mColorRampButton->colorRamp(),
501 mNullColorButton->color(),
502 mColorRampButton->colorRampName() );
506QList<QgsSymbolLegendNode *> QgsPropertyColorAssistantWidget::generatePreviews(
const QList<double> &breaks,
QgsLayerTreeLayer *parent,
const QgsSymbol *symbol,
double minValue,
double maxValue,
QgsCurveTransform *curve )
const
508 QList< QgsSymbolLegendNode * > nodes;
511 std::unique_ptr< QgsMarkerSymbol > tempSymbol;
516 legendSymbol = tempSymbol.get();
521 std::unique_ptr< QgsColorRampTransformer > t( createTransformer( minValue, maxValue ) );
525 for (
int i = 0; i < breaks.length(); i++ )
527 std::unique_ptr< QgsSymbolLegendNode > node;
528 std::unique_ptr< QgsMarkerSymbol > symbolClone(
static_cast<QgsMarkerSymbol *
>( legendSymbol->
clone() ) );
529 symbolClone->setColor( t->color( breaks[i] ) );
532 nodes << node.release();
537QgsPropertyGenericNumericAssistantWidget::QgsPropertyGenericNumericAssistantWidget( QWidget *parent,
const QgsPropertyDefinition &definition,
const QgsProperty &initialState )
538 : QgsPropertyAbstractTransformerWidget( parent, definition )
542 layout()->setContentsMargins( 0, 0, 0, 0 );
544 nullOutputSpinBox->setShowClearButton(
false );
551 minOutputSpinBox->setMaximum( 360.0 );
552 minOutputSpinBox->setValue( 0.0 );
553 minOutputSpinBox->setShowClearButton(
true );
554 minOutputSpinBox->setClearValue( 0.0 );
555 minOutputSpinBox->setSuffix( tr(
" °" ) );
556 maxOutputSpinBox->setMaximum( 360.0 );
557 maxOutputSpinBox->setValue( 360.0 );
558 maxOutputSpinBox->setShowClearButton(
true );
559 maxOutputSpinBox->setClearValue( 360.0 );
560 maxOutputSpinBox->setSuffix( tr(
" °" ) );
561 exponentSpinBox->hide();
562 mExponentLabel->hide();
563 mLabelMinOutput->setText( tr(
"Angle from" ) );
564 mLabelNullOutput->setText( tr(
"Angle when NULL" ) );
571 minOutputSpinBox->setMaximum( 100.0 );
572 minOutputSpinBox->setValue( 0.0 );
573 minOutputSpinBox->setShowClearButton(
true );
574 minOutputSpinBox->setClearValue( 0.0 );
575 minOutputSpinBox->setSuffix( tr(
" %" ) );
576 maxOutputSpinBox->setMaximum( 100.0 );
577 maxOutputSpinBox->setValue( 100.0 );
578 maxOutputSpinBox->setShowClearButton(
true );
579 maxOutputSpinBox->setClearValue( 100.0 );
580 maxOutputSpinBox->setSuffix( tr(
" %" ) );
581 mLabelMinOutput->setText( tr(
"Opacity from" ) );
582 mLabelNullOutput->setText( tr(
"Opacity when NULL" ) );
588 minOutputSpinBox->setMinimum( 0 );
589 maxOutputSpinBox->setMinimum( 0 );
590 minOutputSpinBox->setShowClearButton(
false );
591 maxOutputSpinBox->setShowClearButton(
false );
595 minOutputSpinBox->setMinimum( 1 );
596 maxOutputSpinBox->setMinimum( 1 );
597 minOutputSpinBox->setShowClearButton(
false );
598 maxOutputSpinBox->setShowClearButton(
false );
602 minOutputSpinBox->setMinimum( 0 );
603 maxOutputSpinBox->setMinimum( 0 );
604 minOutputSpinBox->setMaximum( 1 );
605 maxOutputSpinBox->setMaximum( 1 );
606 minOutputSpinBox->setShowClearButton(
false );
607 maxOutputSpinBox->setShowClearButton(
false );
611 minOutputSpinBox->setMinimum( -99999999.000000 );
612 maxOutputSpinBox->setMinimum( -99999999.000000 );
613 minOutputSpinBox->setMaximum( 99999999.000000 );
614 maxOutputSpinBox->setMaximum( 99999999.000000 );
615 minOutputSpinBox->setShowClearButton(
false );
616 maxOutputSpinBox->setShowClearButton(
false );
621 minOutputSpinBox->setShowClearButton(
false );
622 maxOutputSpinBox->setShowClearButton(
false );
629 minOutputSpinBox->setValue( transform->minOutputValue() );
630 maxOutputSpinBox->setValue( transform->maxOutputValue() );
631 nullOutputSpinBox->setValue( transform->nullOutputValue() );
632 exponentSpinBox->setValue( transform->exponent() );
635 connect( minOutputSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
636 connect( maxOutputSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
637 connect( nullOutputSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
638 connect( exponentSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
646 minOutputSpinBox->value(),
647 maxOutputSpinBox->value(),
648 nullOutputSpinBox->value(),
649 exponentSpinBox->value() );
The Qgis class provides global constants for use throughout the application.
@ NoFlags
No flags are set.
@ Expression
Expression based property.
@ TitleCase
Simple title case conversion - does not fully grammatically parse the text and uses simple rules only...
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)
Fetch next feature and stores in f, returns true on success.
This class wraps a request for features to a vector layer (or directly its vector data provider).
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
@ Numeric
All numeric fields.
Q_INVOKABLE int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
@ HigDialogTitleIsTitleCase
Dialog titles should be title case.
static QgsGui::HigFlags higFlags()
Returns the platform's HIG flags.
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.
QString expressionString() const
Returns the expression used for the property value.
Qgis::PropertyType propertyType() const
Returns the property type.
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,...
static QString capitalize(const QString &string, Qgis::Capitalization capitalization)
Converts a string by applying capitalization rules to the string.
static QgsStyle * defaultStyle(bool initialize=true)
Returns the 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.
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.