Skip to content
Permalink
Browse files
Fix raster item in composer legend
git-svn-id: http://svn.osgeo.org/qgis/trunk@13526 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed May 18, 2010
1 parent bd89a91 commit 0d262808db33c00157450199b030419a6a3454b7
@@ -17,6 +17,7 @@

#include "qgscomposerlegenditem.h"
#include "qgsmaplayerregistry.h"
#include "qgsrasterlayer.h"
#include "qgssymbol.h"
#include "qgssymbolv2.h"
#include "qgssymbollayerv2utils.h"
@@ -220,6 +221,56 @@ void QgsComposerSymbolV2Item::setSymbolV2( QgsSymbolV2* s )
mSymbolV2 = s;
}

////////////////////QgsComposerRasterSymbolItem

QgsComposerRasterSymbolItem::QgsComposerRasterSymbolItem(): QgsComposerLegendItem()
{
}

QgsComposerRasterSymbolItem::QgsComposerRasterSymbolItem( const QString& text ): QgsComposerLegendItem( text )
{
}

QgsComposerRasterSymbolItem::QgsComposerRasterSymbolItem( const QIcon& icon, const QString& text ): QgsComposerLegendItem( icon, text )
{
}

QgsComposerRasterSymbolItem::~QgsComposerRasterSymbolItem()
{
}

QStandardItem* QgsComposerRasterSymbolItem::clone() const
{
QgsComposerRasterSymbolItem* cloneItem = new QgsComposerRasterSymbolItem();
*cloneItem = *this;
cloneItem->setLayerID( mLayerID );
return cloneItem;
}

void QgsComposerRasterSymbolItem::writeXML( QDomElement& elem, QDomDocument& doc ) const
{
QDomElement rasterClassElem = doc.createElement( "RasterClassificationItem" );
rasterClassElem.setAttribute( "layerId", mLayerID );
rasterClassElem.setAttribute( "text", text() );
elem.appendChild( rasterClassElem );
}

void QgsComposerRasterSymbolItem::readXML( const QDomElement& itemElem )
{
if ( itemElem.isNull() )
{
return;
}
setText( itemElem.attribute( "text", "" ) );
setLayerID( itemElem.attribute( "layerId", "" ) );

QgsRasterLayer* rLayer = qobject_cast<QgsRasterLayer*>( QgsMapLayerRegistry::instance()->mapLayer( mLayerID ) );
if ( rLayer )
{
setIcon( QIcon( rLayer->legendAsPixmap( true ) ) );
}
}

////////////////////QgsComposerLayerItem

QgsComposerLayerItem::QgsComposerLayerItem(): QgsComposerLegendItem()
@@ -285,6 +336,10 @@ void QgsComposerLayerItem::readXML( const QDomElement& itemElem )
{
currentChildItem = new QgsComposerSymbolV2Item();
}
else if ( elemTag == "RasterClassificationItem" )
{
currentChildItem = new QgsComposerRasterSymbolItem();
}
else
{
continue; //unsupported child type
@@ -37,7 +37,8 @@ class CORE_EXPORT QgsComposerLegendItem: public QStandardItem
GroupItem = QStandardItem::UserType,
LayerItem,
SymbologyItem,
SymbologyV2Item
SymbologyV2Item,
RasterSymbolItem
};

virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const = 0;
@@ -104,6 +105,27 @@ class CORE_EXPORT QgsComposerSymbolV2Item: public QgsComposerLegendItem
QgsSymbolV2* mSymbolV2;
};

class CORE_EXPORT QgsComposerRasterSymbolItem: public QgsComposerLegendItem
{
public:
QgsComposerRasterSymbolItem();
QgsComposerRasterSymbolItem( const QString& text );
QgsComposerRasterSymbolItem( const QIcon& icon, const QString& text );
virtual ~QgsComposerRasterSymbolItem();

virtual QStandardItem* clone() const;

virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const;
virtual void readXML( const QDomElement& itemElem );

void setLayerID( const QString& id ) { mLayerID = id; }
QString layerID() const { return mLayerID; }
ItemType itemType() const { return RasterSymbolItem; }

private:
QString mLayerID;
};

class CORE_EXPORT QgsComposerLayerItem: public QgsComposerLegendItem
{
public:
@@ -260,9 +260,9 @@ int QgsLegendModel::addRasterLayerItem( QStandardItem* layerItem, QgsMapLayer* r
return 2;
}

QStandardItem* currentSymbolItem = new QStandardItem( QIcon( rasterLayer->legendAsPixmap( true ) ), "" );
currentSymbolItem->setData( QgsLegendModel::ClassificationItem, Qt::UserRole + 1 ); //first user data stores the item type

//use a vector symbol item without symbol
QgsComposerRasterSymbolItem* currentSymbolItem = new QgsComposerRasterSymbolItem( QIcon( rasterLayer->legendAsPixmap( true ) ), "" );
currentSymbolItem->setLayerID( rasterLayer->getLayerID() );
int currentRowCount = layerItem->rowCount();
layerItem->setChild( currentRowCount, 0, currentSymbolItem );

@@ -478,6 +478,7 @@ void QgsLegendModel::updateRasterClassificationItem( QStandardItem* classificati
}

QStandardItem* currentSymbolItem = new QStandardItem( QIcon( rl->legendAsPixmap( true ) ), "" );

currentSymbolItem->setData( QgsLegendModel::ClassificationItem, Qt::UserRole + 1 ); //first user data stores the item type
parentItem->insertRow( 0, currentSymbolItem );
parentItem->removeRow( 1 );

0 comments on commit 0d26280

Please sign in to comment.