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

svn_qgis at osgeo.org svn_qgis at osgeo.org
Tue Dec 21 06:25:30 EST 2010


Author: mhugent
Date: 2010-12-21 03:25:30 -0800 (Tue, 21 Dec 2010)
New Revision: 14957

Modified:
   trunk/qgis/src/app/composer/qgscomposerlegendwidget.cpp
   trunk/qgis/src/app/composer/qgscomposerlegendwidget.h
   trunk/qgis/src/core/composer/qgslegendmodel.cpp
   trunk/qgis/src/core/composer/qgslegendmodel.h
Log:
Fix patch #14951. Read/Write auto update to xml, initialize mAutoUpdate and guard against multiple connections

Modified: trunk/qgis/src/app/composer/qgscomposerlegendwidget.cpp
===================================================================
--- trunk/qgis/src/app/composer/qgscomposerlegendwidget.cpp	2010-12-21 10:59:46 UTC (rev 14956)
+++ trunk/qgis/src/app/composer/qgscomposerlegendwidget.cpp	2010-12-21 11:25:30 UTC (rev 14957)
@@ -34,7 +34,7 @@
 {
   setupUi( this );
 
-   // setup icons
+  // setup icons
   mAddToolButton->setIcon( QIcon( QgsApplication::iconPath( "symbologyAdd.png" ) ) );
   mEditPushButton->setIcon( QIcon( QgsApplication::iconPath( "symbologyEdit.png" ) ) );
   mRemoveToolButton->setIcon( QIcon( QgsApplication::iconPath( "symbologyRemove.png" ) ) );
@@ -76,7 +76,7 @@
     return;
   }
 
-  blockSignals( true );
+  blockAllSignals( true );
   mTitleLineEdit->setText( mLegend->title() );
   mSymbolWidthSpinBox->setValue( mLegend->symbolWidth() );
   mSymbolHeightSpinBox->setValue( mLegend->symbolHeight() );
@@ -84,8 +84,12 @@
   mSymbolSpaceSpinBox->setValue( mLegend->symbolSpace() );
   mIconLabelSpaceSpinBox->setValue( mLegend->iconLabelSpace() );
   mBoxSpaceSpinBox->setValue( mLegend->boxSpace() );
+  if ( mLegend->model() )
+  {
+    mCheckBoxAutoUpdate->setChecked( mLegend->model()->autoUpdate() );
+  }
 
-  blockSignals( false );
+  blockAllSignals( false );
 }
 
 void QgsComposerLegendWidget::on_mTitleLineEdit_textChanged( const QString& text )
@@ -370,8 +374,13 @@
   mLegend->endCommand();
 }
 
-void QgsComposerLegendWidget::on_mCheckBoxAutoUpdate_stateChanged ( int state )
+void QgsComposerLegendWidget::on_mCheckBoxAutoUpdate_stateChanged( int state )
 {
+  if ( !mLegend->model() )
+  {
+    return;
+  }
+
   if ( state == Qt::Checked )
   {
     mLegend->model()->setAutoUpdate( true );
@@ -409,13 +418,13 @@
     QgsComposerLegendLayersDialog addDialog( layers );
     if ( addDialog.exec() == QDialog::Accepted )
     {
-       QgsMapLayer* layer = addDialog.selectedLayer();
-       if ( layer )
-       {
-          mLegend->beginCommand( "Legend item added" );
-          mLegend->model()->addLayer( layer );
-          mLegend->endCommand();
-       }
+      QgsMapLayer* layer = addDialog.selectedLayer();
+      if ( layer )
+      {
+        mLegend->beginCommand( "Legend item added" );
+        mLegend->model()->addLayer( layer );
+        mLegend->endCommand();
+      }
     }
   }
 }
@@ -569,3 +578,9 @@
     mLegend->endCommand();
   }
 }
+
+void QgsComposerLegendWidget::blockAllSignals( bool b )
+{
+  mItemTreeView->blockSignals( b );
+  mCheckBoxAutoUpdate->blockSignals( b );
+}

Modified: trunk/qgis/src/app/composer/qgscomposerlegendwidget.h
===================================================================
--- trunk/qgis/src/app/composer/qgscomposerlegendwidget.h	2010-12-21 10:59:46 UTC (rev 14956)
+++ trunk/qgis/src/app/composer/qgscomposerlegendwidget.h	2010-12-21 11:25:30 UTC (rev 14957)
@@ -50,7 +50,7 @@
     void on_mLayerFontButton_clicked();
     void on_mItemFontButton_clicked();
     void on_mBoxSpaceSpinBox_valueChanged( double d );
-    void on_mCheckBoxAutoUpdate_stateChanged (int state ); 
+    void on_mCheckBoxAutoUpdate_stateChanged( int state );
 
     //item manipulation
     void on_mMoveDownToolButton_clicked();
@@ -68,6 +68,7 @@
 
   private:
     QgsComposerLegendWidget();
+    void blockAllSignals( bool b );
 
 
     QgsComposerLegend* mLegend;

Modified: trunk/qgis/src/core/composer/qgslegendmodel.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgslegendmodel.cpp	2010-12-21 10:59:46 UTC (rev 14956)
+++ trunk/qgis/src/core/composer/qgslegendmodel.cpp	2010-12-21 11:25:30 UTC (rev 14957)
@@ -34,14 +34,13 @@
 #include <QSettings>
 #include <QMessageBox>
 
-QgsLegendModel::QgsLegendModel(): QStandardItemModel()
+QgsLegendModel::QgsLegendModel(): QStandardItemModel(), mAutoUpdate( true )
 {
   if ( QgsMapLayerRegistry::instance() )
   {
     connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( removeLayer( const QString& ) ) );
     connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( addLayer( QgsMapLayer* ) ) );
   }
-
   setItemPrototype( new QgsComposerSymbolItem() );
 
   QWidgetList topLevelWidgets = QApplication::topLevelWidgets();
@@ -318,14 +317,13 @@
   int numRootItems = rowCount();
   for ( int i = 0; i < numRootItems ; ++i )
   {
-    currentLayerItem = item( i );
-    if ( !currentLayerItem )
+    QgsComposerLayerItem* lItem = dynamic_cast<QgsComposerLayerItem*>( item( i ) );
+    if ( !lItem )
     {
       continue;
     }
 
-    QString currentId = currentLayerItem->data( Qt::UserRole + 2 ).toString();
-    if ( currentId == layerId )
+    if ( layerId == lItem->layerID() )
     {
       removeRow( i ); //todo: also remove the subitems and their symbols...
       emit layersChanged();
@@ -461,6 +459,7 @@
   }
 
   QDomElement legendModelElem = doc.createElement( "Model" );
+  legendModelElem.setAttribute( "autoUpdate", mAutoUpdate );
   int nTopLevelItems = invisibleRootItem()->rowCount();
   QStandardItem* currentItem = 0;
   QgsComposerLegendItem* currentLegendItem = 0;
@@ -513,6 +512,8 @@
     currentItem->readXML( currentElem );
     appendRow( currentItem );
   }
+
+  setAutoUpdate( legendModelElem.attribute( "autoUpdate", "1" ).toInt() );
   return true;
 }
 
@@ -677,8 +678,13 @@
   return true;
 }
 
-void QgsLegendModel::setAutoUpdate(bool autoUpdate)
+void QgsLegendModel::setAutoUpdate( bool autoUpdate )
 {
+  if ( mAutoUpdate == autoUpdate ) //prevent multiple signal/slot connections
+  {
+    return;
+  }
+
   mAutoUpdate = autoUpdate;
   if ( autoUpdate )
   {
@@ -696,4 +702,4 @@
       disconnect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( addLayer( QgsMapLayer* ) ) );
     }
   }
-}
\ No newline at end of file
+}

Modified: trunk/qgis/src/core/composer/qgslegendmodel.h
===================================================================
--- trunk/qgis/src/core/composer/qgslegendmodel.h	2010-12-21 10:59:46 UTC (rev 14956)
+++ trunk/qgis/src/core/composer/qgslegendmodel.h	2010-12-21 11:25:30 UTC (rev 14957)
@@ -85,7 +85,7 @@
     bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent );
 
     void setAutoUpdate( bool autoUpdate );
-    bool AutoUpdaet() { return mAutoUpdate; }
+    bool autoUpdate() { return mAutoUpdate; }
 
   public slots:
     void removeLayer( const QString& layerId );



More information about the QGIS-commit mailing list