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();
}
Example #2
0
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 ) );
    }
  }