QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2::clone() const
{
  QgsSvgMarkerSymbolLayerV2* m = new QgsSvgMarkerSymbolLayerV2( mPath, mSize, mAngle );
  m->setFillColor( mFillColor );
  m->setOutlineColor( mOutlineColor );
  m->setOutlineWidth( mOutlineWidth );
  m->setOffset( mOffset );
  return m;
}
Пример #2
0
QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2::clone() const
{
  QgsSvgMarkerSymbolLayerV2* m = new QgsSvgMarkerSymbolLayerV2( mPath, mSize, mAngle );
  m->setFillColor( mFillColor );
  m->setOutlineColor( mOutlineColor );
  m->setOutlineWidth( mOutlineWidth );
  m->setOutlineWidthUnit( mOutlineWidthUnit );
  m->setOffset( mOffset );
  m->setOffsetUnit( mOffsetUnit );
  m->setSizeUnit( mSizeUnit );
  m->setHorizontalAnchorPoint( mHorizontalAnchorPoint );
  m->setVerticalAnchorPoint( mVerticalAnchorPoint );
  copyDataDefinedProperties( m );
  return m;
}
Пример #3
0
QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2::createFromSld( QDomElement &element )
{
  QgsDebugMsg( "Entered." );

  QDomElement graphicElem = element.firstChildElement( "Graphic" );
  if ( graphicElem.isNull() )
    return NULL;

  QString path, mimeType;
  QColor fillColor;
  double size;

  if ( !QgsSymbolLayerV2Utils::externalGraphicFromSld( graphicElem, path, mimeType, fillColor, size ) )
    return NULL;

  if ( mimeType != "image/svg+xml" )
    return NULL;

  double angle = 0.0;
  QString angleFunc;
  if ( QgsSymbolLayerV2Utils::rotationFromSldElement( graphicElem, angleFunc ) )
  {
    bool ok;
    double d = angleFunc.toDouble( &ok );
    if ( ok )
      angle = d;
  }

  QPointF offset;
  QgsSymbolLayerV2Utils::displacementFromSldElement( graphicElem, offset );

  QgsSvgMarkerSymbolLayerV2* m = new QgsSvgMarkerSymbolLayerV2( path, size );
  m->setFillColor( fillColor );
  //m->setOutlineColor( outlineColor );
  //m->setOutlineWidth( outlineWidth );
  m->setAngle( angle );
  m->setOffset( offset );
  return m;
}
QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2::create( const QgsStringMap& props )
{
  QString name = DEFAULT_SVGMARKER_NAME;
  double size = DEFAULT_SVGMARKER_SIZE;
  double angle = DEFAULT_SVGMARKER_ANGLE;

  if ( props.contains( "name" ) )
    name = props["name"];
  if ( props.contains( "size" ) )
    size = props["size"].toDouble();
  if ( props.contains( "angle" ) )
    angle = props["angle"].toDouble();

  QgsSvgMarkerSymbolLayerV2* m = new QgsSvgMarkerSymbolLayerV2( name, size, angle );

  //we only check the svg default parameters if necessary, since it could be expensive
  if ( !props.contains( "fill" ) && !props.contains( "outline" ) && !props.contains( "outline-width" ) )
  {
    QColor fillColor, outlineColor;
    double outlineWidth;
    bool hasFillParam, hasOutlineParam, hasOutlineWidthParam;
    QgsSvgCache::instance()->containsParams( name, hasFillParam, fillColor, hasOutlineParam, outlineColor, hasOutlineWidthParam, outlineWidth );
    if ( hasFillParam )
    {
      m->setFillColor( fillColor );
    }
    if ( hasOutlineParam )
    {
      m->setOutlineColor( outlineColor );
    }
    if ( hasOutlineWidthParam )
    {
      m->setOutlineWidth( outlineWidth );
    }
  }

  if ( props.contains( "offset" ) )
    m->setOffset( QgsSymbolLayerV2Utils::decodePoint( props["offset"] ) );
  if ( props.contains( "fill" ) )
    m->setFillColor( QColor( props["fill"] ) );
  if ( props.contains( "outline" ) )
    m->setOutlineColor( QColor( props["outline"] ) );
  if ( props.contains( "outline-width" ) )
    m->setOutlineWidth( props["outline-width"].toDouble() );
  return m;
}
Пример #5
0
QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2::create( const QgsStringMap& props )
{
  QString name = DEFAULT_SVGMARKER_NAME;
  double size = DEFAULT_SVGMARKER_SIZE;
  double angle = DEFAULT_SVGMARKER_ANGLE;

  if ( props.contains( "name" ) )
    name = props["name"];
  if ( props.contains( "size" ) )
    size = props["size"].toDouble();
  if ( props.contains( "angle" ) )
    angle = props["angle"].toDouble();

  QgsSvgMarkerSymbolLayerV2* m = new QgsSvgMarkerSymbolLayerV2( name, size, angle );

  //we only check the svg default parameters if necessary, since it could be expensive
  if ( !props.contains( "fill" ) && !props.contains( "outline" ) && !props.contains( "outline-width" ) )
  {
    QColor fillColor, outlineColor;
    double outlineWidth;
    bool hasFillParam, hasOutlineParam, hasOutlineWidthParam;
    QgsSvgCache::instance()->containsParams( name, hasFillParam, fillColor, hasOutlineParam, outlineColor, hasOutlineWidthParam, outlineWidth );
    if ( hasFillParam )
    {
      m->setFillColor( fillColor );
    }
    if ( hasOutlineParam )
    {
      m->setOutlineColor( outlineColor );
    }
    if ( hasOutlineWidthParam )
    {
      m->setOutlineWidth( outlineWidth );
    }
  }

  if ( props.contains( "size_unit" ) )
    m->setSizeUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["size_unit"] ) );
  if ( props.contains( "offset" ) )
    m->setOffset( QgsSymbolLayerV2Utils::decodePoint( props["offset"] ) );
  if ( props.contains( "offset_unit" ) )
    m->setOffsetUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["offset_unit"] ) );
  if ( props.contains( "fill" ) )
    m->setFillColor( QColor( props["fill"] ) );
  if ( props.contains( "outline" ) )
    m->setOutlineColor( QColor( props["outline"] ) );
  if ( props.contains( "outline-width" ) )
    m->setOutlineWidth( props["outline-width"].toDouble() );
  if ( props.contains( "outline_width_unit" ) )
    m->setOutlineWidthUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["outline_width_unit"] ) );

  if ( props.contains( "horizontal_anchor_point" ) )
  {
    m->setHorizontalAnchorPoint( QgsMarkerSymbolLayerV2::HorizontalAnchorPoint( props[ "horizontal_anchor_point" ].toInt() ) );
  }
  if ( props.contains( "vertical_anchor_point" ) )
  {
    m->setVerticalAnchorPoint( QgsMarkerSymbolLayerV2::VerticalAnchorPoint( props[ "vertical_anchor_point" ].toInt() ) );
  }

  //data defined properties
  if ( props.contains( "size_expression" ) )
  {
    m->setDataDefinedProperty( "size", props["size_expression"] );
  }
  if ( props.contains( "outline-width_expression" ) )
  {
    m->setDataDefinedProperty( "outline-width", props["outline-width_expression"] );
  }
  if ( props.contains( "angle_expression" ) )
  {
    m->setDataDefinedProperty( "angle", props["angle_expression"] );
  }
  if ( props.contains( "offset_expression" ) )
  {
    m->setDataDefinedProperty( "offset", props["offset_expression"] );
  }
  if ( props.contains( "name_expression" ) )
  {
    m->setDataDefinedProperty( "name", props["name_expression"] );
  }
  if ( props.contains( "fill_expression" ) )
  {
    m->setDataDefinedProperty( "fill", props["fill_expression"] );
  }
  if ( props.contains( "outline_expression" ) )
  {
    m->setDataDefinedProperty( "outline", props["outline_expression"] );
  }
  if ( props.contains( "horizontal_anchor_point_expression" ) )
  {
    m->setDataDefinedProperty( "horizontal_anchor_point", props[ "horizontal_anchor_point_expression" ] );
  }
  if ( props.contains( "vertical_anchor_point_expression" ) )
  {
    m->setDataDefinedProperty( "vertical_anchor_point", props[ "vertical_anchor_point_expression" ] );
  }
  return m;
}
QgsSymbol* QgsSymbologyV2Conversion::symbolV2toV1( QgsSymbolV2* s )
{
  if ( s == NULL || s->symbolLayerCount() == 0 )
    return NULL;

  // we will use only the first symbol layer
  QgsSymbolLayerV2* sl = s->symbolLayer( 0 );

  switch ( sl->type() )
  {
    case QgsSymbolV2::Marker:
    {
      QgsMarkerSymbolLayerV2* msl = static_cast<QgsMarkerSymbolLayerV2*>( sl );
      QgsSymbol* sOld = new QgsSymbol( QGis::Point );
      sOld->setFillColor( sl->color() );
      sOld->setFillStyle( Qt::SolidPattern );
      sOld->setPointSize( msl->size() );
      if ( sl->layerType() == "SimpleMarker" )
      {
        QgsSimpleMarkerSymbolLayerV2* smsl = static_cast<QgsSimpleMarkerSymbolLayerV2*>( sl );
        sOld->setColor( smsl->borderColor() );
        sOld->setNamedPointSymbol( "hard:" + smsl->name() );
      }
      else if ( sl->layerType() == "SvgMarker" )
      {
        QgsSvgMarkerSymbolLayerV2* smsl = static_cast<QgsSvgMarkerSymbolLayerV2*>( sl );
        sOld->setNamedPointSymbol( "svg:" + smsl->path() );
      }
      return sOld;
    }
    break;

    case QgsSymbolV2::Line:
    {
      QgsLineSymbolLayerV2* lsl = static_cast<QgsLineSymbolLayerV2*>( sl );
      QgsSymbol* sOld = new QgsSymbol( QGis::Line );
      sOld->setColor( sl->color() );
      sOld->setLineWidth( lsl->width() );
      if ( sl->layerType() == "SimpleLine" )
      {
        // add specific settings
        QgsSimpleLineSymbolLayerV2* slsl = static_cast<QgsSimpleLineSymbolLayerV2*>( sl );
        sOld->setLineStyle( slsl->penStyle() );
      }
      return sOld;
    }

    case QgsSymbolV2::Fill:
    {
      QgsSymbol* sOld = new QgsSymbol( QGis::Polygon );
      sOld->setFillColor( sl->color() );
      if ( sl->layerType() == "SimpleFill" )
      {
        // add specifc settings
        QgsSimpleFillSymbolLayerV2* sfsl = static_cast<QgsSimpleFillSymbolLayerV2*>( sl );
        sOld->setColor( sfsl->borderColor() );
        sOld->setLineWidth( sfsl->borderWidth() );
        sOld->setLineStyle( sfsl->borderStyle() );
        sOld->setFillStyle( sfsl->brushStyle() );
      }
      return sOld;
    }
  }

  return NULL; // should never get here
}