20#include "moc_qgspropertyassistantwidget.cpp"
36 , mDefinition( definition )
41 layout()->setContentsMargins( 0, 0, 0, 0 );
45 mLegendPreview->hide();
47 minValueSpinBox->setShowClearButton(
false );
48 maxValueSpinBox->setShowClearButton(
false );
51 mExpressionWidget->setLayer(
const_cast<QgsVectorLayer *
>( mLayer ) );
55 if (
auto *lTransformer = initialState.
transformer() )
57 minValueSpinBox->setValue( lTransformer->minValue() );
58 maxValueSpinBox->setValue( lTransformer->maxValue() );
60 if ( lTransformer->curveTransform() )
62 mTransformCurveCheckBox->setChecked(
true );
63 mTransformCurveCheckBox->setCollapsed(
false );
64 mCurveEditor->setCurve( *lTransformer->curveTransform() );
68 connect( computeValuesButton, &QPushButton::clicked,
this, &QgsPropertyAssistantWidget::computeValuesFromLayer );
75 mLegendPreview->setModel( &mPreviewList );
76 mLegendPreview->setItemDelegate(
new QgsAssistantPreviewItemDelegate( &mPreviewList ) );
77 mLegendPreview->setHeaderHidden(
true );
78 mLegendPreview->expandAll();
79 mLegendVerticalFrame->setLayout(
new QVBoxLayout() );
80 mLegendVerticalFrame->layout()->setContentsMargins( 0, 0, 0, 0 );
81 mLegendVerticalFrame->hide();
88 mTransformerWidget =
new QgsPropertySizeAssistantWidget(
this, mDefinition, initialState );
89 mLegendPreview->show();
96 mTransformerWidget =
new QgsPropertyColorAssistantWidget(
this, mDefinition, initialState );
97 mLegendPreview->show();
103 mTransformerWidget =
new QgsPropertyGenericNumericAssistantWidget(
this, mDefinition, initialState );
111 mTransformerWidget =
new QgsPropertyGenericNumericAssistantWidget(
this, mDefinition, initialState );
117 if ( mTransformerWidget )
119 mOutputWidget->layout()->addWidget( mTransformerWidget );
122 mCurveEditor->setMinHistogramValueRange( minValueSpinBox->value() );
123 mCurveEditor->setMaxHistogramValueRange( maxValueSpinBox->value() );
125 mCurveEditor->setHistogramSource( mLayer, mExpressionWidget->currentField() );
127 mCurveEditor->setHistogramSource( mLayer, expression );
132 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();
222 const QList<QgsSymbolLegendNode *> nodes = mTransformerWidget->generatePreviews( breaks, mLayerTreeLayer, mSymbol.get(), minValueSpinBox->value(), maxValueSpinBox->value(), mTransformCurveCheckBox->isChecked() ? &curve : nullptr );
226 const auto constNodes = nodes;
229 const QSize minSize( node->minimumIconSize() );
230 node->setIconSize( minSize );
231 widthMax = std::max( minSize.width(), widthMax );
232 QStandardItem *item =
new QStandardItem( node->data( Qt::DecorationRole ).value<QPixmap>(), QLocale().toString( breaks[i] ) );
233 item->setEditable(
false );
234 mPreviewList.appendRow( item );
240 for (
int i = 0; i < breaks.length(); i++ )
242 const QPixmap img( mPreviewList.item( i )->icon().pixmap( mPreviewList.item( i )->icon().actualSize( QSize( 512, 512 ) ) ) );
243 QPixmap enlarged( widthMax, img.height() );
245 enlarged.fill( Qt::transparent );
246 QPainter p( &enlarged );
247 p.drawPixmap( QPoint( ( widthMax - img.width() ) / 2, 0 ), img );
249 mPreviewList.item( i )->setIcon( enlarged );
253bool QgsPropertyAssistantWidget::computeValuesFromExpression(
const QString &expression,
double &minValue,
double &maxValue )
const
258 if ( mExpressionContextGenerator )
269 if ( !e.prepare( &context ) )
272 const QSet<QString> referencedCols( e.referencedColumns() );
279 double min = std::numeric_limits<double>::max();
280 double max = std::numeric_limits<double>::lowest();
287 const double value = e.evaluate( &context ).toDouble( &ok );
290 max = std::max( max, value );
291 min = std::min( min, value );
303bool QgsPropertyAssistantWidget::computeValuesFromField(
const QString &fieldName,
double &minValue,
double &maxValue )
const
306 if ( fieldIndex < 0 )
316 const double minDouble = min.toDouble( &ok );
320 const double maxDouble = max.toDouble( &ok );
324 minValue = minDouble;
325 maxValue = maxDouble;
336 : QgsPropertyAbstractTransformerWidget( parent, definition )
340 layout()->setContentsMargins( 0, 0, 0, 0 );
355 minSizeSpinBox->setShowClearButton(
false );
356 maxSizeSpinBox->setShowClearButton(
false );
357 nullSizeSpinBox->setShowClearButton(
false );
361 minSizeSpinBox->setValue( sizeTransform->minSize() );
362 maxSizeSpinBox->setValue( sizeTransform->maxSize() );
363 nullSizeSpinBox->setValue( sizeTransform->nullSize() );
364 exponentSpinBox->setValue( sizeTransform->exponent() );
365 scaleMethodComboBox->setCurrentIndex( scaleMethodComboBox->findData( sizeTransform->type() ) );
370 connect( minSizeSpinBox,
static_cast<void (
QgsDoubleSpinBox::* )(
double )
>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
371 connect( maxSizeSpinBox,
static_cast<void (
QgsDoubleSpinBox::* )(
double )
>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
372 connect( nullSizeSpinBox,
static_cast<void (
QgsDoubleSpinBox::* )(
double )
>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
373 connect( exponentSpinBox,
static_cast<void (
QgsDoubleSpinBox::* )(
double )
>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
374 connect( scaleMethodComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsPropertySizeAssistantWidget::widgetChanged );
375 connect( scaleMethodComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, [=] {
380QgsSizeScaleTransformer *QgsPropertySizeAssistantWidget::createTransformer(
double minValue,
double maxValue )
const
386 minSizeSpinBox->value(),
387 maxSizeSpinBox->value(),
388 nullSizeSpinBox->value(),
389 exponentSpinBox->value()
394QList<QgsSymbolLegendNode *> QgsPropertySizeAssistantWidget::generatePreviews(
const QList<double> &breaks,
QgsLayerTreeLayer *parent,
const QgsSymbol *symbol,
double minValue,
double maxValue,
QgsCurveTransform *curve )
const
396 QList<QgsSymbolLegendNode *> nodes;
399 std::unique_ptr<QgsSymbol> tempSymbol;
411 legendSymbol = tempSymbol.get();
416 std::unique_ptr<QgsSizeScaleTransformer> t( createTransformer( minValue, maxValue ) );
420 for (
int i = 0; i < breaks.length(); i++ )
422 std::unique_ptr<QgsSymbolLegendNode> node;
425 std::unique_ptr<QgsMarkerSymbol> symbolClone(
static_cast<QgsMarkerSymbol *
>( legendSymbol->
clone() ) );
428 symbolClone->setSize( t->size( breaks[i] ) );
431 else if (
dynamic_cast<const QgsLineSymbol *
>( legendSymbol ) )
433 std::unique_ptr<QgsLineSymbol> symbolClone(
static_cast<QgsLineSymbol *
>( legendSymbol->
clone() ) );
435 symbolClone->setWidth( t->size( breaks[i] ) );
439 nodes << node.release();
446 return QList<QgsSymbolLegendNode *>();
449QgsPropertyColorAssistantWidget::QgsPropertyColorAssistantWidget( QWidget *parent,
const QgsPropertyDefinition &definition,
const QgsProperty &initialState )
450 : QgsPropertyAbstractTransformerWidget( parent, definition )
454 layout()->setContentsMargins( 0, 0, 0, 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() )
476 std::unique_ptr<QgsColorRamp> colorRamp(
QgsProject::instance()->styleSettings()->defaultColorRamp() );
482 mColorRampButton->setColorRamp( colorRamp.get() );
486QgsColorRampTransformer *QgsPropertyColorAssistantWidget::createTransformer(
double minValue,
double maxValue )
const
491 mColorRampButton->colorRamp(),
492 mNullColorButton->color(),
493 mColorRampButton->colorRampName()
498QList<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();
529QgsPropertyGenericNumericAssistantWidget::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 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.