Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix patch #14951. Read/Write auto update to xml, initialize mAutoUpda…
…te and guard against multiple connections

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14957 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Dec 21, 2010
1 parent ebd47cd commit 29f71cd
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 21 deletions.
37 changes: 26 additions & 11 deletions src/app/composer/qgscomposerlegendwidget.cpp
Expand Up @@ -34,7 +34,7 @@ QgsComposerLegendWidget::QgsComposerLegendWidget( QgsComposerLegend* legend ): m
{
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" ) ) );
Expand Down Expand Up @@ -76,16 +76,20 @@ void QgsComposerLegendWidget::setGuiElements()
return;
}

blockSignals( true );
blockAllSignals( true );
mTitleLineEdit->setText( mLegend->title() );
mSymbolWidthSpinBox->setValue( mLegend->symbolWidth() );
mSymbolHeightSpinBox->setValue( mLegend->symbolHeight() );
mLayerSpaceSpinBox->setValue( mLegend->layerSpace() );
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 )
Expand Down Expand Up @@ -370,8 +374,13 @@ void QgsComposerLegendWidget::on_mMoveUpToolButton_clicked()
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 );
Expand Down Expand Up @@ -409,13 +418,13 @@ void QgsComposerLegendWidget::on_mAddToolButton_clicked()
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();
}
}
}
}
Expand Down Expand Up @@ -569,3 +578,9 @@ void QgsComposerLegendWidget::updateLegend()
mLegend->endCommand();
}
}

void QgsComposerLegendWidget::blockAllSignals( bool b )
{
mItemTreeView->blockSignals( b );
mCheckBoxAutoUpdate->blockSignals( b );
}
3 changes: 2 additions & 1 deletion src/app/composer/qgscomposerlegendwidget.h
Expand Up @@ -50,7 +50,7 @@ class QgsComposerLegendWidget: public QWidget, private Ui::QgsComposerLegendWidg
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();
Expand All @@ -68,6 +68,7 @@ class QgsComposerLegendWidget: public QWidget, private Ui::QgsComposerLegendWidg

private:
QgsComposerLegendWidget();
void blockAllSignals( bool b );


QgsComposerLegend* mLegend;
Expand Down
22 changes: 14 additions & 8 deletions src/core/composer/qgslegendmodel.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -318,14 +317,13 @@ void QgsLegendModel::removeLayer( const QString& layerId )
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();
Expand Down Expand Up @@ -461,6 +459,7 @@ bool QgsLegendModel::writeXML( QDomElement& composerLegendElem, QDomDocument& do
}

QDomElement legendModelElem = doc.createElement( "Model" );
legendModelElem.setAttribute( "autoUpdate", mAutoUpdate );
int nTopLevelItems = invisibleRootItem()->rowCount();
QStandardItem* currentItem = 0;
QgsComposerLegendItem* currentLegendItem = 0;
Expand Down Expand Up @@ -513,6 +512,8 @@ bool QgsLegendModel::readXML( const QDomElement& legendModelElem, const QDomDocu
currentItem->readXML( currentElem );
appendRow( currentItem );
}

setAutoUpdate( legendModelElem.attribute( "autoUpdate", "1" ).toInt() );
return true;
}

Expand Down Expand Up @@ -677,8 +678,13 @@ bool QgsLegendModel::dropMimeData( const QMimeData *data, Qt::DropAction action,
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 )
{
Expand All @@ -696,4 +702,4 @@ void QgsLegendModel::setAutoUpdate(bool autoUpdate)
disconnect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( addLayer( QgsMapLayer* ) ) );
}
}
}
}
2 changes: 1 addition & 1 deletion src/core/composer/qgslegendmodel.h
Expand Up @@ -85,7 +85,7 @@ class CORE_EXPORT QgsLegendModel: public QStandardItemModel
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 );
Expand Down

0 comments on commit 29f71cd

Please sign in to comment.