コード例 #1
0
void QgsRasterShader::writeXML( QDomDocument& doc, QDomElement& parent ) const
{
  if ( parent.isNull() || !mRasterShaderFunction )
  {
    return;
  }

  QDomElement rasterShaderElem = doc.createElement( "rastershader" );
  QgsColorRampShader* colorRampShader = dynamic_cast<QgsColorRampShader*>( mRasterShaderFunction );
  if ( colorRampShader )
  {
    QDomElement colorRampShaderElem = doc.createElement( "colorrampshader" );
    colorRampShaderElem.setAttribute( "colorRampType", colorRampShader->colorRampTypeAsQString() );
    colorRampShaderElem.setAttribute( "clip", colorRampShader->clip() );
    //items
    QList<QgsColorRampShader::ColorRampItem> itemList = colorRampShader->colorRampItemList();
    QList<QgsColorRampShader::ColorRampItem>::const_iterator itemIt = itemList.constBegin();
    for ( ; itemIt != itemList.constEnd(); ++itemIt )
    {
      QDomElement itemElem = doc.createElement( "item" );
      itemElem.setAttribute( "label", itemIt->label );
      itemElem.setAttribute( "value", QString::number( itemIt->value ) );
      itemElem.setAttribute( "color", itemIt->color.name() );
      colorRampShaderElem.appendChild( itemElem );
    }
    rasterShaderElem.appendChild( colorRampShaderElem );
  }
  parent.appendChild( rasterShaderElem );
}
コード例 #2
0
void QgsRasterShader::writeXml( QDomDocument& doc, QDomElement& parent ) const
{
    if ( parent.isNull() || !mRasterShaderFunction )
    {
        return;
    }

    QDomElement rasterShaderElem = doc.createElement( QStringLiteral( "rastershader" ) );
    QgsColorRampShader* colorRampShader = dynamic_cast<QgsColorRampShader*>( mRasterShaderFunction );
    if ( colorRampShader )
    {
        QDomElement colorRampShaderElem = doc.createElement( QStringLiteral( "colorrampshader" ) );
        colorRampShaderElem.setAttribute( "colorRampType", colorRampShader->colorRampTypeAsQString() );
        colorRampShaderElem.setAttribute( "classificationMode", colorRampShader->classificationMode() );
        colorRampShaderElem.setAttribute( QStringLiteral( "clip" ), colorRampShader->clip() );

        // save source color ramp
        if ( colorRampShader->sourceColorRamp() )
        {
            QDomElement colorRampElem = QgsSymbolLayerUtils::saveColorRamp( QStringLiteral( "[source]" ), colorRampShader->sourceColorRamp(), doc );
            colorRampShaderElem.appendChild( colorRampElem );
        }

        //items
        QList<QgsColorRampShader::ColorRampItem> itemList = colorRampShader->colorRampItemList();
        QList<QgsColorRampShader::ColorRampItem>::const_iterator itemIt = itemList.constBegin();
        for ( ; itemIt != itemList.constEnd(); ++itemIt )
        {
            QDomElement itemElem = doc.createElement( QStringLiteral( "item" ) );
            itemElem.setAttribute( QStringLiteral( "label" ), itemIt->label );
            itemElem.setAttribute( QStringLiteral( "value" ), QgsRasterBlock::printValue( itemIt->value ) );
            itemElem.setAttribute( QStringLiteral( "color" ), itemIt->color.name() );
            itemElem.setAttribute( QStringLiteral( "alpha" ), itemIt->color.alpha() );
            colorRampShaderElem.appendChild( itemElem );
        }
        rasterShaderElem.appendChild( colorRampShaderElem );
    }
    parent.appendChild( rasterShaderElem );
}