[QGIS Commit] r15127 - in trunk/qgis/src: core/composer mapserver

svn_qgis at osgeo.org svn_qgis at osgeo.org
Fri Feb 4 07:50:47 EST 2011


Author: mhugent
Date: 2011-02-04 04:50:47 -0800 (Fri, 04 Feb 2011)
New Revision: 15127

Modified:
   trunk/qgis/src/core/composer/qgscomposerlegenditem.cpp
   trunk/qgis/src/core/composer/qgscomposerlegenditem.h
   trunk/qgis/src/core/composer/qgslegendmodel.cpp
   trunk/qgis/src/mapserver/qgsprojectparser.cpp
Log:
Read composer legend content from project file for WMS print (ignoring the possibility of dynamically added layers for now)

Modified: trunk/qgis/src/core/composer/qgscomposerlegenditem.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgscomposerlegenditem.cpp	2011-02-04 10:28:05 UTC (rev 15126)
+++ trunk/qgis/src/core/composer/qgscomposerlegenditem.cpp	2011-02-04 12:50:47 UTC (rev 15127)
@@ -105,7 +105,7 @@
   elem.appendChild( vectorClassElem );
 }
 
-void QgsComposerSymbolItem::readXML( const QDomElement& itemElem )
+void QgsComposerSymbolItem::readXML( const QDomElement& itemElem, bool xServerAvailable )
 {
   if ( itemElem.isNull() )
   {
@@ -123,6 +123,10 @@
       QgsSymbol* symbol = new QgsSymbol( vLayer->geometryType() );
       symbol->readXML( symbolElem, vLayer );
       setSymbol( symbol );
+      if ( !xServerAvailable ) //don't read icon without GUI
+      {
+        return;
+      }
 
       //add icon
       switch ( symbol->type() )
@@ -193,7 +197,7 @@
   elem.appendChild( vectorClassElem );
 }
 
-void QgsComposerSymbolV2Item::readXML( const QDomElement& itemElem )
+void QgsComposerSymbolV2Item::readXML( const QDomElement& itemElem, bool xServerAvailable )
 {
   if ( itemElem.isNull() )
   {
@@ -213,7 +217,10 @@
       if ( symbolNg )
       {
         setSymbolV2( symbolNg );
-        setIcon( QgsSymbolLayerV2Utils::symbolPreviewIcon( symbolNg, QSize( 30, 30 ) ) );
+        if ( xServerAvailable )
+        {
+          setIcon( QgsSymbolLayerV2Utils::symbolPreviewIcon( symbolNg, QSize( 30, 30 ) ) );
+        }
       }
     }
   }
@@ -259,7 +266,7 @@
   elem.appendChild( rasterClassElem );
 }
 
-void QgsComposerRasterSymbolItem::readXML( const QDomElement& itemElem )
+void QgsComposerRasterSymbolItem::readXML( const QDomElement& itemElem, bool xServerAvailable )
 {
   if ( itemElem.isNull() )
   {
@@ -269,7 +276,7 @@
   setLayerID( itemElem.attribute( "layerId", "" ) );
 
   QgsRasterLayer* rLayer = qobject_cast<QgsRasterLayer*>( QgsMapLayerRegistry::instance()->mapLayer( mLayerID ) );
-  if ( rLayer )
+  if ( rLayer && xServerAvailable )
   {
     setIcon( QIcon( rLayer->legendAsPixmap( true ) ) );
   }
@@ -306,7 +313,7 @@
   elem.appendChild( layerItemElem );
 }
 
-void QgsComposerLayerItem::readXML( const QDomElement& itemElem )
+void QgsComposerLayerItem::readXML( const QDomElement& itemElem, bool xServerAvailable )
 {
   if ( itemElem.isNull() )
   {
@@ -348,7 +355,7 @@
     {
       continue; //unsupported child type
     }
-    currentChildItem->readXML( currentElem );
+    currentChildItem->readXML( currentElem, xServerAvailable );
     appendRow( currentChildItem );
   }
 }
@@ -382,7 +389,7 @@
   elem.appendChild( layerGroupElem );
 }
 
-void QgsComposerGroupItem::readXML( const QDomElement& itemElem )
+void QgsComposerGroupItem::readXML( const QDomElement& itemElem, bool xServerAvailable )
 {
   if ( itemElem.isNull() )
   {
@@ -420,7 +427,7 @@
     {
       continue; //unsupported child item type
     }
-    currentChildItem->readXML( currentElem );
+    currentChildItem->readXML( currentElem, xServerAvailable );
     appendRow( currentChildItem );
   }
 }

Modified: trunk/qgis/src/core/composer/qgscomposerlegenditem.h
===================================================================
--- trunk/qgis/src/core/composer/qgscomposerlegenditem.h	2011-02-04 10:28:05 UTC (rev 15126)
+++ trunk/qgis/src/core/composer/qgscomposerlegenditem.h	2011-02-04 12:50:47 UTC (rev 15127)
@@ -42,7 +42,9 @@
     };
 
     virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const = 0;
-    virtual void readXML( const QDomElement& itemElem ) = 0;
+    /**Read item content from xml
+      @param xServerAvailable Read item icons if true (QIcon needs x-server)*/
+    virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true ) = 0;
 
     virtual ItemType itemType() const = 0;
     virtual QStandardItem* clone() const = 0;
@@ -64,7 +66,7 @@
     virtual QStandardItem* clone() const;
 
     virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const;
-    virtual void readXML( const QDomElement& itemElem );
+    virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true );
 
     /**Set symbol (takes ownership)*/
     void setSymbol( QgsSymbol* s );
@@ -93,7 +95,7 @@
     virtual QStandardItem* clone() const;
 
     virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const;
-    virtual void readXML( const QDomElement& itemElem );
+    virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true );
 
     /**Set symbol (takes ownership)*/
     void setSymbolV2( QgsSymbolV2* s );
@@ -116,7 +118,7 @@
     virtual QStandardItem* clone() const;
 
     virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const;
-    virtual void readXML( const QDomElement& itemElem );
+    virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true );
 
     void setLayerID( const QString& id ) { mLayerID = id; }
     QString layerID() const { return mLayerID; }
@@ -135,7 +137,7 @@
     virtual QStandardItem* clone() const;
 
     virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const;
-    virtual void readXML( const QDomElement& itemElem );
+    virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true );
 
     ItemType itemType() const { return LayerItem; }
 
@@ -155,7 +157,7 @@
     virtual QStandardItem* clone() const;
 
     virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const;
-    virtual void readXML( const QDomElement& itemElem );
+    virtual void readXML( const QDomElement& itemElem, bool xServerAvailable = true );
 
     ItemType itemType() const { return GroupItem; }
 };

Modified: trunk/qgis/src/core/composer/qgslegendmodel.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgslegendmodel.cpp	2011-02-04 10:28:05 UTC (rev 15126)
+++ trunk/qgis/src/core/composer/qgslegendmodel.cpp	2011-02-04 12:50:47 UTC (rev 15127)
@@ -507,7 +507,7 @@
     {
       currentItem = new QgsComposerGroupItem();
     }
-    currentItem->readXML( currentElem );
+    currentItem->readXML( currentElem, mHasTopLevelWindow );
     appendRow( currentItem );
   }
 

Modified: trunk/qgis/src/mapserver/qgsprojectparser.cpp
===================================================================
--- trunk/qgis/src/mapserver/qgsprojectparser.cpp	2011-02-04 10:28:05 UTC (rev 15126)
+++ trunk/qgis/src/mapserver/qgsprojectparser.cpp	2011-02-04 12:50:47 UTC (rev 15127)
@@ -904,9 +904,14 @@
     {
       //legend needs to be loaded indirectly to have generic content
       //and to avoid usage of x-server with pixmap icons
+
+      //read full legend from xml
       QgsComposerLegend* legend = new QgsComposerLegend( composition );
-      legend->_readXML( currentElem.firstChildElement( "ComposerItem" ), *mXMLDoc );
-      legend->updateLegend();
+      legend->readXML( currentElem, *mXMLDoc );
+
+      //dynamic legend (would be interesting in case of layers dynamically defined in SLD)
+      //legend->_readXML( currentElem.firstChildElement( "ComposerItem" ), *mXMLDoc );
+      //legend->updateLegend();
       composition->addItem( legend );
     }
     else if ( elemName == "ComposerShape" )



More information about the QGIS-commit mailing list