示例#1
0
static QgsFeatureRenderer* readOldGraduatedSymbolRenderer( const QDomNode& rnode, QgsWkbTypes::GeometryType geomType )
{
  QDomNode modeNode = rnode.namedItem( "mode" );
  QString modeValue = modeNode.toElement().text();
  QDomNode classnode = rnode.namedItem( "classificationfield" );
  QString classificationField = classnode.toElement().text();

  QgsGraduatedSymbolRenderer::Mode m = QgsGraduatedSymbolRenderer::Custom;
  if ( modeValue == "Empty" )
  {
    m = QgsGraduatedSymbolRenderer::Custom;
  }
  else if ( modeValue == "Quantile" )
  {
    m = QgsGraduatedSymbolRenderer::Quantile;
  }
  else //default
  {
    m = QgsGraduatedSymbolRenderer::EqualInterval;
  }

  // load ranges and symbols
  QgsRangeList ranges;
  QDomNode symbolnode = rnode.namedItem( "symbol" );
  while ( !symbolnode.isNull() )
  {
    QgsSymbol* symbol = readOldSymbol( symbolnode, geomType );
    if ( symbol )
    {
      QgsOldSymbolMeta meta = readSymbolMeta( symbolnode );
      double lowerValue = meta.lowerValue.toDouble();
      double upperValue = meta.upperValue.toDouble();
      QString label = meta.label;
      if ( label.isEmpty() )
        label = QString( "%1 - %2" ).arg( lowerValue, -1, 'f', 3 ).arg( upperValue, -1, 'f', 3 );
      ranges.append( QgsRendererRange( lowerValue, upperValue, symbol, label ) );
    }

    symbolnode = symbolnode.nextSibling();
  }

  // create renderer
  QgsGraduatedSymbolRenderer* r = new QgsGraduatedSymbolRenderer( classificationField, ranges );
  r->setMode( m );
  return r;
}
QgsGraduatedSymbolRenderer::QgsGraduatedSymbolRenderer( const QgsGraduatedSymbolRenderer& other )
{
  mMode = other.mMode;
  mGeometryType = other.mGeometryType;
  mClassificationField = other.mClassificationField;
  const QList<QgsSymbol*> s = other.symbols();
  for ( QList<QgsSymbol*>::const_iterator it = s.begin(); it != s.end(); ++it )
  {
    addSymbol( new QgsSymbol( **it ) );
  }
  updateSymbolAttributes();
}
QgsGraduatedSymbolRenderer *QgsGraduatedSymbolRenderer::clone() const
{
  QgsGraduatedSymbolRenderer *r = new QgsGraduatedSymbolRenderer( mAttrName, mRanges );
  r->setMode( mMode );
  if ( mSourceSymbol )
    r->setSourceSymbol( mSourceSymbol->clone() );
  if ( mSourceColorRamp )
  {
    r->setSourceColorRamp( mSourceColorRamp->clone() );
  }
  r->setUsingSymbolLevels( usingSymbolLevels() );
  r->setDataDefinedSizeLegend( mDataDefinedSizeLegend ? new QgsDataDefinedSizeLegend( *mDataDefinedSizeLegend ) : nullptr );
  r->setLabelFormat( labelFormat() );
  r->setGraduatedMethod( graduatedMethod() );
  copyRendererData( r );
  return r;
}
QgsGraduatedSymbolRenderer* QgsGraduatedSymbolRenderer::clone() const
{
  QgsGraduatedSymbolRenderer* r = new QgsGraduatedSymbolRenderer( mAttrName, mRanges );
  r->setMode( mMode );
  if ( mSourceSymbol.data() )
    r->setSourceSymbol( mSourceSymbol->clone() );
  if ( mSourceColorRamp.data() )
  {
    r->setSourceColorRamp( mSourceColorRamp->clone() );
    r->setInvertedColorRamp( mInvertedColorRamp );
  }
  r->setUsingSymbolLevels( usingSymbolLevels() );
  r->setLabelFormat( labelFormat() );
  r->setGraduatedMethod( graduatedMethod() );
  copyRendererData( r );
  return r;
}