コード例 #1
0
QgsSingleSymbolRenderer::QgsSingleSymbolRenderer( QGis::GeometryType type )
{
  mGeometryType = type;

  //initial setting based on random color
  QgsSymbol* sy = new QgsSymbol( mGeometryType );

  //random fill colors for points and polygons and pen colors for lines
  int red = 1 + ( int )( 255.0 * rand() / ( RAND_MAX + 1.0 ) );
  int green = 1 + ( int )( 255.0 * rand() / ( RAND_MAX + 1.0 ) );
  int blue = 1 + ( int )( 255.0 * rand() / ( RAND_MAX + 1.0 ) );

  if ( type == QGis::Line )
  {
    sy->setColor( QColor( red, green, blue ) );
  }
  else
  {
    sy->setFillColor( QColor( red, green, blue ) );
    sy->setFillStyle( Qt::SolidPattern );
    sy->setColor( QColor( 0, 0, 0 ) );
  }
  mSymbol = sy;
  updateSymbolAttributes();
}
コード例 #2
0
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
}