[QGIS Commit] r13526 - trunk/qgis/src/core/composer

svn_qgis at osgeo.org svn_qgis at osgeo.org
Tue May 18 11:18:36 EDT 2010


Author: mhugent
Date: 2010-05-18 11:18:35 -0400 (Tue, 18 May 2010)
New Revision: 13526

Modified:
   trunk/qgis/src/core/composer/qgscomposerlegenditem.cpp
   trunk/qgis/src/core/composer/qgscomposerlegenditem.h
   trunk/qgis/src/core/composer/qgslegendmodel.cpp
Log:
Fix raster item in composer legend

Modified: trunk/qgis/src/core/composer/qgscomposerlegenditem.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgscomposerlegenditem.cpp	2010-05-18 14:26:45 UTC (rev 13525)
+++ trunk/qgis/src/core/composer/qgscomposerlegenditem.cpp	2010-05-18 15:18:35 UTC (rev 13526)
@@ -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 @@
   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 @@
     {
       currentChildItem = new QgsComposerSymbolV2Item();
     }
+    else if ( elemTag == "RasterClassificationItem" )
+    {
+      currentChildItem = new QgsComposerRasterSymbolItem();
+    }
     else
     {
       continue; //unsupported child type

Modified: trunk/qgis/src/core/composer/qgscomposerlegenditem.h
===================================================================
--- trunk/qgis/src/core/composer/qgscomposerlegenditem.h	2010-05-18 14:26:45 UTC (rev 13525)
+++ trunk/qgis/src/core/composer/qgscomposerlegenditem.h	2010-05-18 15:18:35 UTC (rev 13526)
@@ -37,7 +37,8 @@
       GroupItem = QStandardItem::UserType,
       LayerItem,
       SymbologyItem,
-      SymbologyV2Item
+      SymbologyV2Item,
+      RasterSymbolItem
     };
 
     virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const = 0;
@@ -104,6 +105,27 @@
     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:

Modified: trunk/qgis/src/core/composer/qgslegendmodel.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgslegendmodel.cpp	2010-05-18 14:26:45 UTC (rev 13525)
+++ trunk/qgis/src/core/composer/qgslegendmodel.cpp	2010-05-18 15:18:35 UTC (rev 13526)
@@ -260,9 +260,9 @@
     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 @@
   }
 
   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 );



More information about the QGIS-commit mailing list