[QGIS Commit] r9190 - in trunk/qgis/src: app/composer core/composer ui

svn_qgis at osgeo.org svn_qgis at osgeo.org
Wed Aug 27 09:21:17 EDT 2008


Author: mhugent
Date: 2008-08-27 09:21:17 -0400 (Wed, 27 Aug 2008)
New Revision: 9190

Modified:
   trunk/qgis/src/app/composer/qgscomposerlegendwidget.cpp
   trunk/qgis/src/app/composer/qgscomposerlegendwidget.h
   trunk/qgis/src/core/composer/qgscomposerlegend.cpp
   trunk/qgis/src/core/composer/qgscomposerlegend.h
   trunk/qgis/src/core/composer/qgslegendmodel.cpp
   trunk/qgis/src/core/composer/qgslegendmodel.h
   trunk/qgis/src/ui/qgscomposerlegendwidgetbase.ui
Log:
update composer legend on layer level

Modified: trunk/qgis/src/app/composer/qgscomposerlegendwidget.cpp
===================================================================
--- trunk/qgis/src/app/composer/qgscomposerlegendwidget.cpp	2008-08-27 12:57:47 UTC (rev 9189)
+++ trunk/qgis/src/app/composer/qgscomposerlegendwidget.cpp	2008-08-27 13:21:17 UTC (rev 9190)
@@ -340,3 +340,42 @@
     mLegend->update();
   }
 }
+
+void QgsComposerLegendWidget::on_mUpdatePushButton_clicked()
+{
+  //get current item
+  QStandardItemModel* itemModel = dynamic_cast<QStandardItemModel*>( mItemTreeView->model() );
+  if ( !itemModel )
+  {
+    return;
+  }
+
+  //get current item
+  QModelIndex currentIndex = mItemTreeView->currentIndex();
+  if ( !currentIndex.isValid() )
+  {
+    return;
+  }
+
+  QStandardItem* currentItem = itemModel->itemFromIndex( currentIndex );
+  if ( !currentItem )
+  {
+    return;
+  }
+  
+  QModelIndex parentIndex = currentIndex.parent();
+  if ( !parentIndex.isValid() ) // a layer item
+    {
+      QString mapLayerId = currentItem->data().toString();
+      mLegend->model()->updateLayer(mapLayerId);
+      mLegend->update();
+    }
+}
+
+void QgsComposerLegendWidget::on_mUpdateAllPushButton_clicked()
+{
+  if(mLegend)
+    {
+      mLegend->updateLegend();
+    }
+}

Modified: trunk/qgis/src/app/composer/qgscomposerlegendwidget.h
===================================================================
--- trunk/qgis/src/app/composer/qgscomposerlegendwidget.h	2008-08-27 12:57:47 UTC (rev 9189)
+++ trunk/qgis/src/app/composer/qgscomposerlegendwidget.h	2008-08-27 13:21:17 UTC (rev 9190)
@@ -52,6 +52,8 @@
     void on_mMoveUpPushButton_clicked();
     void on_mRemovePushButton_clicked();
     void on_mEditPushButton_clicked();
+    void on_mUpdatePushButton_clicked();
+    void on_mUpdateAllPushButton_clicked();
 
   private:
     QgsComposerLegendWidget();

Modified: trunk/qgis/src/core/composer/qgscomposerlegend.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgscomposerlegend.cpp	2008-08-27 12:57:47 UTC (rev 9189)
+++ trunk/qgis/src/core/composer/qgscomposerlegend.cpp	2008-08-27 13:21:17 UTC (rev 9190)
@@ -438,6 +438,13 @@
   return mItemFont;
 }
 
+void QgsComposerLegend::updateLegend()
+{
+  mLegendModel.setLayerSet(layerIdList());
+  adjustBoxSize();
+  update();
+}
+
 bool QgsComposerLegend::writeXML( QDomElement& elem, QDomDocument & doc )
 {
   if ( elem.isNull() )

Modified: trunk/qgis/src/core/composer/qgscomposerlegend.h
===================================================================
--- trunk/qgis/src/core/composer/qgscomposerlegend.h	2008-08-27 12:57:47 UTC (rev 9189)
+++ trunk/qgis/src/core/composer/qgscomposerlegend.h	2008-08-27 13:21:17 UTC (rev 9190)
@@ -78,6 +78,9 @@
     double symbolHeight() const {return mSymbolHeight;}
     void setSymbolHeight( double h ) {mSymbolHeight = h;}
 
+    /**Updates the model and all legend entries*/
+    void updateLegend();
+
     /** stores state in Dom node
        * @param elem is Dom element corresponding to 'Composer' tag
        * @param temp write template file

Modified: trunk/qgis/src/core/composer/qgslegendmodel.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgslegendmodel.cpp	2008-08-27 12:57:47 UTC (rev 9189)
+++ trunk/qgis/src/core/composer/qgslegendmodel.cpp	2008-08-27 13:21:17 UTC (rev 9190)
@@ -230,6 +230,7 @@
   mSymbols.clear();
 }
 
+#if 0
 void QgsLegendModel::updateLayerEntries( const QStringList& newLayerIds )
 {
   if ( !invisibleRootItem() )
@@ -276,7 +277,58 @@
 
   mLayerIds = newLayerIds;
 }
+#endif //0
 
+void QgsLegendModel::updateLayer(const QString& layerId)
+{
+  //find layer item
+  QStandardItem* layerItem = 0;
+  QStandardItem* currentLayerItem = 0;
+  
+  int numRootItems = rowCount();
+  for ( int i = 0; i < numRootItems ; ++i )
+    {
+    currentLayerItem = item( i );
+    if ( !currentLayerItem )
+    {
+      continue;
+    }
+
+    QString currentId = currentLayerItem->data().toString();
+    if ( currentId == layerId )
+      {
+	layerItem = currentLayerItem;
+	break;
+      }
+    }
+
+  if(layerItem)
+    {
+      QgsMapLayer* mapLayer = QgsMapLayerRegistry::instance()->mapLayer(layerId);
+      if(mapLayer)
+	{
+	  //delete all the entries under layer item
+	  for(int i = rowCount() - 1; i >= 0; --i)
+	    {
+	      layerItem->removeRow(i);
+	    }
+      
+	  //and add the new ones...
+	  switch(mapLayer->type())
+	    {
+	    case QgsMapLayer::VECTOR:
+	      addVectorLayerItems(layerItem, mapLayer);
+	      break;
+	    case QgsMapLayer::RASTER:
+	      addRasterLayerItem(layerItem, mapLayer);
+	      break;
+	    default:
+	      break;
+	    }
+	}
+    }
+}
+
 void QgsLegendModel::removeLayer( const QString& layerId )
 {
   QStandardItem* currentLayerItem = 0;

Modified: trunk/qgis/src/core/composer/qgslegendmodel.h
===================================================================
--- trunk/qgis/src/core/composer/qgslegendmodel.h	2008-08-27 12:57:47 UTC (rev 9189)
+++ trunk/qgis/src/core/composer/qgslegendmodel.h	2008-08-27 13:21:17 UTC (rev 9190)
@@ -41,8 +41,11 @@
 
     void setLayerSet( const QStringList& layerIds );
     /**Apply added or removed layers to the model*/
-    void updateLayerEntries( const QStringList& newLayerIds );
+    //void updateLayerEntries( const QStringList& newLayerIds );
 
+    /**Updates the symbology of a single layer*/
+    void updateLayer(const QString& layerId);
+
     bool writeXML( QDomElement& composerLegendElem, QDomDocument& doc );
     bool readXML( const QDomElement& legendModelElem, const QDomDocument& doc );
 

Modified: trunk/qgis/src/ui/qgscomposerlegendwidgetbase.ui
===================================================================
--- trunk/qgis/src/ui/qgscomposerlegendwidgetbase.ui	2008-08-27 12:57:47 UTC (rev 9189)
+++ trunk/qgis/src/ui/qgscomposerlegendwidgetbase.ui	2008-08-27 13:21:17 UTC (rev 9190)
@@ -5,8 +5,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>496</width>
-    <height>626</height>
+    <width>560</width>
+    <height>537</height>
    </rect>
   </property>
   <property name="sizePolicy" >
@@ -183,19 +183,20 @@
        </widget>
       </item>
       <item row="0" column="4" >
-       <spacer>
-        <property name="orientation" >
-         <enum>Qt::Horizontal</enum>
+       <widget class="QPushButton" name="mUpdatePushButton" >
+        <property name="text" >
+         <string>update</string>
         </property>
-        <property name="sizeHint" >
-         <size>
-          <width>121</width>
-          <height>33</height>
-         </size>
+       </widget>
+      </item>
+      <item row="0" column="5" >
+       <widget class="QPushButton" name="mUpdateAllPushButton" >
+        <property name="text" >
+         <string>update all</string>
         </property>
-       </spacer>
+       </widget>
       </item>
-      <item row="1" column="0" colspan="5" >
+      <item row="1" column="0" colspan="6" >
        <widget class="QTreeView" name="mItemTreeView" >
         <property name="headerHidden" stdset="0" >
          <bool>true</bool>



More information about the QGIS-commit mailing list