20#include "moc_qgspropertyassistantwidget.cpp"
38 , mDefinition( definition )
43 layout()->setContentsMargins( 0, 0, 0, 0 );
47 mLegendPreview->hide();
49 minValueSpinBox->setShowClearButton(
false );
50 maxValueSpinBox->setShowClearButton(
false );
53 mExpressionWidget->setLayer(
const_cast< QgsVectorLayer *
>( mLayer ) );
57 if (
auto *lTransformer = initialState.
transformer() )
59 minValueSpinBox->setValue( lTransformer->minValue() );
60 maxValueSpinBox->setValue( lTransformer->maxValue() );
62 if ( lTransformer->curveTransform() )
64 mTransformCurveCheckBox->setChecked(
true );
65 mTransformCurveCheckBox->setCollapsed(
false );
66 mCurveEditor->setCurve( *lTransformer->curveTransform() );
70 connect( computeValuesButton, &QPushButton::clicked,
this, &QgsPropertyAssistantWidget::computeValuesFromLayer );
77 mLegendPreview->setModel( &mPreviewList );
78 mLegendPreview->setItemDelegate(
new QgsAssistantPreviewItemDelegate( &mPreviewList ) );
79 mLegendPreview->setHeaderHidden(
true );
80 mLegendPreview->expandAll();
81 mLegendVerticalFrame->setLayout(
new QVBoxLayout() );
82 mLegendVerticalFrame->layout()->setContentsMargins( 0, 0, 0, 0 );
83 mLegendVerticalFrame->hide();
90 mTransformerWidget =
new QgsPropertySizeAssistantWidget(
this, mDefinition, initialState );
91 mLegendPreview->show();
98 mTransformerWidget =
new QgsPropertyColorAssistantWidget(
this, mDefinition, initialState );
99 mLegendPreview->show();
105 mTransformerWidget =
new QgsPropertyGenericNumericAssistantWidget(
this, mDefinition, initialState );
113 mTransformerWidget =
new QgsPropertyGenericNumericAssistantWidget(
this, mDefinition, initialState );
119 if ( mTransformerWidget )
121 mOutputWidget->layout()->addWidget( mTransformerWidget );
124 mCurveEditor->setMinHistogramValueRange( minValueSpinBox->value() );
125 mCurveEditor->setMaxHistogramValueRange( maxValueSpinBox->value() );
127 mCurveEditor->setHistogramSource( mLayer, mExpressionWidget->currentField() );
130 mCurveEditor->setHistogramSource( mLayer, expression );
136 mTransformCurveCheckBox->setVisible( mTransformerWidget );
149 mExpressionContextGenerator = generator;
150 mExpressionWidget->registerExpressionContextGenerator( generator );
155 property.setActive( !mExpressionWidget->currentText().isEmpty() );
156 if ( mExpressionWidget->isExpression() )
157 property.setExpressionString( mExpressionWidget->currentField() );
159 property.setField( mExpressionWidget->currentField() );
161 if ( mTransformerWidget )
163 std::unique_ptr< QgsPropertyTransformer> t( mTransformerWidget->createTransformer( minValueSpinBox->value(), maxValueSpinBox->value() ) );
164 if ( mTransformCurveCheckBox->isChecked() )
170 t->setCurveTransform(
nullptr );
172 property.setTransformer( t.release() );
180 if (
dockMode && mLegendVerticalFrame->isHidden() )
182 mLegendVerticalFrame->layout()->addWidget( mLegendPreview );
183 mLegendVerticalFrame->show();
187void QgsPropertyAssistantWidget::computeValuesFromLayer()
192 double minValue = 0.0;
193 double maxValue = 0.0;
195 if ( mExpressionWidget->isExpression() )
197 if ( !computeValuesFromExpression( mExpressionWidget->currentField(), minValue, maxValue ) )
202 if ( !computeValuesFromField( mExpressionWidget->currentField(), minValue, maxValue ) )
209 mCurveEditor->setMinHistogramValueRange( minValueSpinBox->value() );
210 mCurveEditor->setMaxHistogramValueRange( maxValueSpinBox->value() );
215void QgsPropertyAssistantWidget::updatePreview()
217 if ( mLegendPreview->isHidden() || !mTransformerWidget || !mLayer )
220 mLegendPreview->setIconSize( QSize( 512, 512 ) );
221 mPreviewList.clear();
224 maxValueSpinBox->value(), 8 );
227 const QList< QgsSymbolLegendNode * > nodes = mTransformerWidget->generatePreviews( breaks, mLayerTreeLayer, mSymbol.get(), minValueSpinBox->value(),
228 maxValueSpinBox->value(), mTransformCurveCheckBox->isChecked() ? &curve : nullptr );
232 const auto constNodes = nodes;
235 const QSize minSize( node->minimumIconSize() );
236 node->setIconSize( minSize );
237 widthMax = std::max( minSize.width(), widthMax );
238 QStandardItem *item =
new QStandardItem( node->data( Qt::DecorationRole ).value<QPixmap>(), QLocale().toString( breaks[i] ) );
239 item->setEditable(
false );
240 mPreviewList.appendRow( item );
246 for (
int i = 0; i < breaks.length(); i++ )
248 const QPixmap img( mPreviewList.item( i )->icon().pixmap( mPreviewList.item( i )->icon().actualSize( QSize( 512, 512 ) ) ) );
249 QPixmap enlarged( widthMax, img.height() );
251 enlarged.fill( Qt::transparent );
252 QPainter p( &enlarged );
253 p.drawPixmap( QPoint( ( widthMax - img.width() ) / 2, 0 ), img );
255 mPreviewList.item( i )->setIcon( enlarged );
259bool QgsPropertyAssistantWidget::computeValuesFromExpression(
const QString &expression,
double &minValue,
double &maxValue )
const
264 if ( mExpressionContextGenerator )
275 if ( !e.prepare( &context ) )
278 const QSet<QString> referencedCols( e.referencedColumns() );
283 :
Qgis::FeatureRequestFlag::NoGeometry )
284 .setSubsetOfAttributes( referencedCols, mLayer->fields() ) );
287 double min = std::numeric_limits<double>::max();
288 double max = std::numeric_limits<double>::lowest();
295 const double value = e.evaluate( &context ).toDouble( &ok );
298 max = std::max( max, value );
299 min = std::min( min, value );
311bool QgsPropertyAssistantWidget::computeValuesFromField(
const QString &fieldName,
double &minValue,
double &maxValue )
const
314 if ( fieldIndex < 0 )
324 const double minDouble = min.toDouble( &ok );
328 const double maxDouble = max.toDouble( &ok );
332 minValue = minDouble;
333 maxValue = maxDouble;
344 : QgsPropertyAbstractTransformerWidget( parent, definition )
348 layout()->setContentsMargins( 0, 0, 0, 0 );
363 minSizeSpinBox->setShowClearButton(
false );
364 maxSizeSpinBox->setShowClearButton(
false );
365 nullSizeSpinBox->setShowClearButton(
false );
369 minSizeSpinBox->setValue( sizeTransform->minSize() );
370 maxSizeSpinBox->setValue( sizeTransform->maxSize() );
371 nullSizeSpinBox->setValue( sizeTransform->nullSize() );
372 exponentSpinBox->setValue( sizeTransform->exponent() );
373 scaleMethodComboBox->setCurrentIndex( scaleMethodComboBox->findData( sizeTransform->type() ) );
378 connect( minSizeSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
379 connect( maxSizeSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
380 connect( nullSizeSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
381 connect( exponentSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
382 connect( scaleMethodComboBox,
static_cast < void ( QComboBox::* )(
int )
> ( &QComboBox::currentIndexChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
383 connect( scaleMethodComboBox,
static_cast < void ( QComboBox::* )(
int )
> ( &QComboBox::currentIndexChanged ),
this,
391QgsSizeScaleTransformer *QgsPropertySizeAssistantWidget::createTransformer(
double minValue,
double maxValue )
const
397 minSizeSpinBox->value(),
398 maxSizeSpinBox->value(),
399 nullSizeSpinBox->value(),
400 exponentSpinBox->value() );
404QList< QgsSymbolLegendNode * > QgsPropertySizeAssistantWidget::generatePreviews(
const QList<double> &breaks,
QgsLayerTreeLayer *parent,
const QgsSymbol *symbol,
double minValue,
double maxValue,
QgsCurveTransform *curve )
const
406 QList< QgsSymbolLegendNode * > nodes;
409 std::unique_ptr< QgsSymbol > tempSymbol;
421 legendSymbol = tempSymbol.get();
426 std::unique_ptr< QgsSizeScaleTransformer > t( createTransformer( minValue, maxValue ) );
430 for (
int i = 0; i < breaks.length(); i++ )
432 std::unique_ptr< QgsSymbolLegendNode > node;
435 std::unique_ptr< QgsMarkerSymbol > symbolClone(
static_cast<QgsMarkerSymbol *
>( legendSymbol->
clone() ) );
438 symbolClone->setSize( t->size( breaks[i] ) );
441 else if (
dynamic_cast<const QgsLineSymbol *
>( legendSymbol ) )
443 std::unique_ptr< QgsLineSymbol > symbolClone(
static_cast<QgsLineSymbol *
>( legendSymbol->
clone() ) );
445 symbolClone->setWidth( t->size( breaks[i] ) );
449 nodes << node.release();
456 return QList< QgsSymbolLegendNode * >();
459QgsPropertyColorAssistantWidget::QgsPropertyColorAssistantWidget( QWidget *parent,
const QgsPropertyDefinition &definition,
const QgsProperty &initialState )
460 : QgsPropertyAbstractTransformerWidget( parent, definition )
464 layout()->setContentsMargins( 0, 0, 0, 0 );
467 mNullColorButton->setAllowOpacity( supportsAlpha );
468 mNullColorButton->setShowNoColor(
true );
469 mNullColorButton->setColorDialogTitle( tr(
"Color For Null Values" ) );
470 mNullColorButton->setContext( QStringLiteral(
"symbology" ) );
471 mNullColorButton->setNoColorString( tr(
"Transparent" ) );
475 mNullColorButton->setColor( colorTransform->nullColor() );
476 if ( colorTransform->colorRamp() )
477 mColorRampButton->setColorRamp( colorTransform->colorRamp() );
483 if ( !mColorRampButton->colorRamp() )
486 std::unique_ptr< QgsColorRamp > colorRamp(
QgsProject::instance()->styleSettings()->defaultColorRamp() );
492 mColorRampButton->setColorRamp( colorRamp.get() );
496QgsColorRampTransformer *QgsPropertyColorAssistantWidget::createTransformer(
double minValue,
double maxValue )
const
501 mColorRampButton->colorRamp(),
502 mNullColorButton->color(),
503 mColorRampButton->colorRampName() );
507QList<QgsSymbolLegendNode *> QgsPropertyColorAssistantWidget::generatePreviews(
const QList<double> &breaks,
QgsLayerTreeLayer *parent,
const QgsSymbol *symbol,
double minValue,
double maxValue,
QgsCurveTransform *curve )
const
509 QList< QgsSymbolLegendNode * > nodes;
512 std::unique_ptr< QgsMarkerSymbol > tempSymbol;
517 legendSymbol = tempSymbol.get();
522 std::unique_ptr< QgsColorRampTransformer > t( createTransformer( minValue, maxValue ) );
526 for (
int i = 0; i < breaks.length(); i++ )
528 std::unique_ptr< QgsSymbolLegendNode > node;
529 std::unique_ptr< QgsMarkerSymbol > symbolClone(
static_cast<QgsMarkerSymbol *
>( legendSymbol->
clone() ) );
530 symbolClone->setColor( t->color( breaks[i] ) );
533 nodes << node.release();
538QgsPropertyGenericNumericAssistantWidget::QgsPropertyGenericNumericAssistantWidget( QWidget *parent,
const QgsPropertyDefinition &definition,
const QgsProperty &initialState )
539 : QgsPropertyAbstractTransformerWidget( parent, definition )
543 layout()->setContentsMargins( 0, 0, 0, 0 );
545 nullOutputSpinBox->setShowClearButton(
false );
552 minOutputSpinBox->setMaximum( 360.0 );
553 minOutputSpinBox->setValue( 0.0 );
554 minOutputSpinBox->setShowClearButton(
true );
555 minOutputSpinBox->setClearValue( 0.0 );
556 minOutputSpinBox->setSuffix( tr(
" °" ) );
557 maxOutputSpinBox->setMaximum( 360.0 );
558 maxOutputSpinBox->setValue( 360.0 );
559 maxOutputSpinBox->setShowClearButton(
true );
560 maxOutputSpinBox->setClearValue( 360.0 );
561 maxOutputSpinBox->setSuffix( tr(
" °" ) );
562 exponentSpinBox->hide();
563 mExponentLabel->hide();
564 mLabelMinOutput->setText( tr(
"Angle from" ) );
565 mLabelNullOutput->setText( tr(
"Angle when NULL" ) );
572 minOutputSpinBox->setMaximum( 100.0 );
573 minOutputSpinBox->setValue( 0.0 );
574 minOutputSpinBox->setShowClearButton(
true );
575 minOutputSpinBox->setClearValue( 0.0 );
576 minOutputSpinBox->setSuffix( tr(
" %" ) );
577 maxOutputSpinBox->setMaximum( 100.0 );
578 maxOutputSpinBox->setValue( 100.0 );
579 maxOutputSpinBox->setShowClearButton(
true );
580 maxOutputSpinBox->setClearValue( 100.0 );
581 maxOutputSpinBox->setSuffix( tr(
" %" ) );
582 mLabelMinOutput->setText( tr(
"Opacity from" ) );
583 mLabelNullOutput->setText( tr(
"Opacity when NULL" ) );
589 minOutputSpinBox->setMinimum( 0 );
590 maxOutputSpinBox->setMinimum( 0 );
591 minOutputSpinBox->setShowClearButton(
false );
592 maxOutputSpinBox->setShowClearButton(
false );
596 minOutputSpinBox->setMinimum( 1 );
597 maxOutputSpinBox->setMinimum( 1 );
598 minOutputSpinBox->setShowClearButton(
false );
599 maxOutputSpinBox->setShowClearButton(
false );
603 minOutputSpinBox->setMinimum( 0 );
604 maxOutputSpinBox->setMinimum( 0 );
605 minOutputSpinBox->setMaximum( 1 );
606 maxOutputSpinBox->setMaximum( 1 );
607 minOutputSpinBox->setShowClearButton(
false );
608 maxOutputSpinBox->setShowClearButton(
false );
612 minOutputSpinBox->setMinimum( -99999999.000000 );
613 maxOutputSpinBox->setMinimum( -99999999.000000 );
614 minOutputSpinBox->setMaximum( 99999999.000000 );
615 maxOutputSpinBox->setMaximum( 99999999.000000 );
616 minOutputSpinBox->setShowClearButton(
false );
617 maxOutputSpinBox->setShowClearButton(
false );
622 minOutputSpinBox->setShowClearButton(
false );
623 maxOutputSpinBox->setShowClearButton(
false );
630 minOutputSpinBox->setValue( transform->minOutputValue() );
631 maxOutputSpinBox->setValue( transform->maxOutputValue() );
632 nullOutputSpinBox->setValue( transform->nullOutputValue() );
633 exponentSpinBox->setValue( transform->exponent() );
636 connect( minOutputSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
637 connect( maxOutputSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
638 connect( nullOutputSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
639 connect( exponentSpinBox,
static_cast < void (
QgsDoubleSpinBox::* )(
double )
> ( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
647 minOutputSpinBox->value(),
648 maxOutputSpinBox->value(),
649 nullOutputSpinBox->value(),
650 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.