QString QgsProcessingAlgorithm::invalidSinkError( const QVariantMap ¶meters, const QString &name ) { if ( !parameters.contains( name ) ) return QObject::tr( "Could not create destination layer for %1: no value specified for parameter" ).arg( name ); else { QVariant var = parameters.value( name ); if ( var.canConvert<QgsProcessingOutputLayerDefinition>() ) { QgsProcessingOutputLayerDefinition fromVar = qvariant_cast<QgsProcessingOutputLayerDefinition>( var ); var = fromVar.sink; } if ( var.canConvert<QgsProperty>() ) { QgsProperty p = var.value< QgsProperty >(); if ( p.propertyType() == QgsProperty::StaticProperty ) { var = p.staticValue(); } } if ( !var.toString().isEmpty() ) return QObject::tr( "Could not create destination layer for %1: %2" ).arg( name, var.toString() ); else return QObject::tr( "Could not create destination layer for %1: invalid value" ).arg( name ); } }
void QgsPropertyOverrideButton::setToProperty( const QgsProperty &property ) { if ( property ) { switch ( property.propertyType() ) { case QgsProperty::StaticProperty: case QgsProperty::InvalidProperty: break; case QgsProperty::FieldBasedProperty: { mFieldName = property.field(); break; } case QgsProperty::ExpressionBasedProperty: { mExpressionString = property.expressionString(); break; } } } else { mFieldName.clear(); mExpressionString.clear(); } mProperty = property; setActive( mProperty && mProperty.isActive() ); updateSiblingWidgets( isActive() ); updateGui(); }
QString QgsMapToolLabel::dataDefinedColumnName( QgsPalLayerSettings::Property p, const QgsPalLayerSettings &labelSettings ) const { if ( !labelSettings.dataDefinedProperties().isActive( p ) ) return QString(); QgsProperty prop = labelSettings.dataDefinedProperties().property( p ); if ( prop.propertyType() != QgsProperty::FieldBasedProperty ) return QString(); return prop.field(); }
void QgsLabelPropertyDialog::insertChangedValue( QgsPalLayerSettings::Property p, const QVariant &value ) { if ( mDataDefinedProperties.isActive( p ) ) { QgsProperty prop = mDataDefinedProperties.property( p ); if ( prop.propertyType() == QgsProperty::FieldBasedProperty ) { mChangedProperties.insert( mCurLabelFeat.fieldNameIndex( prop.field() ), value ); } } }
void QgsDataDefinedSizeLegend::updateFromSymbolAndProperty( const QgsMarkerSymbol *symbol, const QgsProperty &ddSize ) { mSymbol.reset( symbol->clone() ); mSymbol->setDataDefinedSize( QgsProperty() ); // original symbol may have had data-defined size associated const QgsSizeScaleTransformer *sizeTransformer = dynamic_cast< const QgsSizeScaleTransformer * >( ddSize.transformer() ); mSizeScaleTransformer.reset( sizeTransformer ? sizeTransformer->clone() : nullptr ); if ( mTitleLabel.isEmpty() ) mTitleLabel = ddSize.propertyType() == QgsProperty::ExpressionBasedProperty ? ddSize.expressionString() : ddSize.field(); // automatically generate classes if no classes are defined if ( sizeTransformer && mSizeClasses.isEmpty() ) { mSizeClasses.clear(); Q_FOREACH ( double v, QgsSymbolLayerUtils::prettyBreaks( sizeTransformer->minValue(), sizeTransformer->maxValue(), 4 ) ) { mSizeClasses << SizeClass( v, QString::number( v ) ); } }
bool QgsMapToolLabel::createAuxiliaryFields( LabelDetails &details, QgsPalIndexes &indexes ) const { bool newAuxiliaryLayer = false; QgsVectorLayer *vlayer = details.layer; QString providerId = details.pos.providerID; if ( !vlayer || !vlayer->labelsEnabled() ) return false; if ( !vlayer->auxiliaryLayer() ) { QgsNewAuxiliaryLayerDialog dlg( vlayer ); dlg.exec(); newAuxiliaryLayer = true; } if ( !vlayer->auxiliaryLayer() ) return false; for ( const QgsPalLayerSettings::Property &p : qgis::as_const( mPalProperties ) ) { int index = -1; // always use the default activated property QgsProperty prop = details.settings.dataDefinedProperties().property( p ); if ( prop.propertyType() == QgsProperty::FieldBasedProperty && prop.isActive() ) { index = vlayer->fields().lookupField( prop.field() ); } else { index = QgsAuxiliaryLayer::createProperty( p, vlayer ); } indexes[p] = index; } details.settings = vlayer->labeling()->settings( providerId ); return newAuxiliaryLayer; }
QString QgsProcessingAlgorithm::invalidRasterError( const QVariantMap ¶meters, const QString &name ) { if ( !parameters.contains( name ) ) return QObject::tr( "Could not load source layer for %1: no value specified for parameter" ).arg( name ); else { QVariant var = parameters.value( name ); if ( var.canConvert<QgsProperty>() ) { QgsProperty p = var.value< QgsProperty >(); if ( p.propertyType() == QgsProperty::StaticProperty ) { var = p.staticValue(); } } if ( !var.toString().isEmpty() ) return QObject::tr( "Could not load source layer for %1: %2 not found" ).arg( name, var.toString() ); else return QObject::tr( "Could not load source layer for %1: invalid value" ).arg( name ); } }
bool QgsMapToolLabel::createAuxiliaryFields( LabelDetails &details, QgsDiagramIndexes &indexes ) { bool newAuxiliaryLayer = false; QgsVectorLayer *vlayer = details.layer; if ( !vlayer ) return newAuxiliaryLayer; if ( !vlayer->auxiliaryLayer() ) { QgsNewAuxiliaryLayerDialog dlg( vlayer ); dlg.exec(); newAuxiliaryLayer = true; } if ( !vlayer->auxiliaryLayer() ) return false; for ( const QgsDiagramLayerSettings::Property &p : qgis::as_const( mDiagramProperties ) ) { int index = -1; // always use the default activated property QgsProperty prop = vlayer->diagramLayerSettings()->dataDefinedProperties().property( p ); if ( prop.propertyType() == QgsProperty::FieldBasedProperty && prop.isActive() ) { index = vlayer->fields().lookupField( prop.field() ); } else { index = QgsAuxiliaryLayer::createProperty( p, vlayer ); } indexes[p] = index; } return newAuxiliaryLayer; }
void QgsLabelPropertyDialog::enableDataDefinedWidgets( QgsVectorLayer *vlayer ) { //loop through data defined properties, this time setting whether or not the widgets are enabled //this can only be done for properties which are assigned to fields Q_FOREACH ( int key, mDataDefinedProperties.propertyKeys() ) { QgsProperty prop = mDataDefinedProperties.property( key ); if ( !prop || !prop.isActive() || prop.propertyType() != QgsProperty::FieldBasedProperty ) { continue; // can only modify attributes with an active data definition of a mapped field } QString ddField = prop.field(); if ( ddField.isEmpty() ) { continue; } int ddIndx = vlayer->fields().lookupField( ddField ); if ( ddIndx == -1 ) { continue; } QgsDebugMsg( QStringLiteral( "ddField: %1" ).arg( ddField ) ); switch ( key ) { case QgsPalLayerSettings::Show: mShowLabelChkbx->setEnabled( true ); break; case QgsPalLayerSettings::AlwaysShow: mAlwaysShowChkbx->setEnabled( true ); break; case QgsPalLayerSettings::MinimumScale: mMinScaleWidget->setEnabled( true ); break; case QgsPalLayerSettings::MaximumScale: mMaxScaleWidget->setEnabled( true ); break; case QgsPalLayerSettings::BufferSize: mBufferSizeSpinBox->setEnabled( true ); break; case QgsPalLayerSettings::PositionX: mXCoordSpinBox->setEnabled( true ); break; case QgsPalLayerSettings::PositionY: mYCoordSpinBox->setEnabled( true ); break; case QgsPalLayerSettings::LabelDistance: mLabelDistanceSpinBox->setEnabled( true ); break; case QgsPalLayerSettings::Hali: mHaliComboBox->setEnabled( true ); break; case QgsPalLayerSettings::Vali: mValiComboBox->setEnabled( true ); break; case QgsPalLayerSettings::BufferColor: mBufferColorButton->setEnabled( true ); break; case QgsPalLayerSettings::Color: mFontColorButton->setEnabled( true ); break; case QgsPalLayerSettings::LabelRotation: mRotationSpinBox->setEnabled( true ); break; //font related properties case QgsPalLayerSettings::Family: mFontFamilyCmbBx->setEnabled( true ); break; case QgsPalLayerSettings::FontStyle: mFontStyleCmbBx->setEnabled( true ); break; case QgsPalLayerSettings::Underline: mFontUnderlineBtn->setEnabled( true ); break; case QgsPalLayerSettings::Strikeout: mFontStrikethroughBtn->setEnabled( true ); break; case QgsPalLayerSettings::Bold: mFontBoldBtn->setEnabled( true ); break; case QgsPalLayerSettings::Italic: mFontItalicBtn->setEnabled( true ); break; case QgsPalLayerSettings::Size: mFontSizeSpinBox->setEnabled( true ); break; default: break; } } }