Skip to content

Commit

Permalink
Project file conversion for paletted color
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Apr 14, 2012
1 parent cc62d75 commit cf431b1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/core/qgsprojectfiletransform.cpp
Expand Up @@ -582,7 +582,34 @@ void QgsProjectFileTransform::transform1800to1900()
}
}
}
else
else if ( drawingStyle == "PalettedColor" )
{
rasterRendererElem.setAttribute( "type", "paletted" );
rasterRendererElem.setAttribute( "band", grayBand );
QDomElement customColorRampElem = rasterPropertiesElem.firstChildElement( "customColorRamp" );
QDomNodeList colorRampEntryList = customColorRampElem.elementsByTagName( "colorRampEntry" );
QDomElement newColorPaletteElem = mDom.createElement( "colorPalette" );

int red = 0;
int green = 0;
int blue = 0;
int value = 0;
QDomElement colorRampEntryElem;
for ( int i = 0; i < colorRampEntryList.size(); ++i )
{
colorRampEntryElem = colorRampEntryList.at( i ).toElement();
QDomElement newPaletteElem = mDom.createElement( "paletteEntry" );
int value = ( int )( colorRampEntryElem.attribute( "value" ).toDouble() );
newPaletteElem.setAttribute( "value", value );
red = colorRampEntryElem.attribute( "red" ).toInt();
green = colorRampEntryElem.attribute( "green" ).toInt();
blue = colorRampEntryElem.attribute( "blue" ).toInt();
newPaletteElem.setAttribute( "color", QColor( red, green, blue ).name() );
newColorPaletteElem.appendChild( newPaletteElem );
}
rasterRendererElem.appendChild( newColorPaletteElem );
}
else //todo: multiband color
{
return;
}
Expand All @@ -593,6 +620,7 @@ void QgsProjectFileTransform::transform1800to1900()
layerNode.replaceChild( rasterRendererElem, rasterPropertiesElem );
}
}
QgsDebugMsg( mDom.toString() );
}

void QgsProjectFileTransform::transformContrastEnhancement( QDomDocument& doc, const QDomElement& rasterproperties, QDomElement& rendererElem )
Expand Down
1 change: 1 addition & 0 deletions src/core/raster/qgspalettedrasterrenderer.cpp
Expand Up @@ -58,6 +58,7 @@ QgsRasterRenderer* QgsPalettedRasterRenderer::create( const QDomElement& elem, Q
{
entryElem = paletteEntries.at( i ).toElement();
value = entryElem.attribute( "value", "0" ).toInt();
QgsDebugMsg( entryElem.attribute( "color", "#000000" ) );
colors[value] = QColor( entryElem.attribute( "color", "#000000" ) );
}
}
Expand Down

0 comments on commit cf431b1

Please sign in to comment.