Skip to content
Permalink
Browse files

Merge branch 'release-1_7_0' of github.com:qgis/Quantum-GIS into rele…

…ase-1_7_0
  • Loading branch information
timlinux committed Jul 4, 2011
2 parents bb06a7f + 92df029 commit 9164946a12ff458997e31c31a0d2db6f6a618b76
@@ -20,6 +20,7 @@
#include "qgscomposerlegenditemdialog.h"
#include "qgscomposerlegendlayersdialog.h"
#include "qgscomposeritemwidget.h"
#include "qgscomposermap.h"
#include <QFontDialog>

#include "qgsapplegendinterface.h"
@@ -88,6 +89,17 @@ void QgsComposerLegendWidget::setGuiElements()
{
mCheckBoxAutoUpdate->setChecked( mLegend->model()->autoUpdate() );
}
refreshMapComboBox();

const QgsComposerMap* map = mLegend->composerMap();
if ( map )
{
mMapComboBox->setCurrentIndex( mMapComboBox->findData( map->id() ) );
}
else
{
mMapComboBox->setCurrentIndex( mMapComboBox->findData( -1 ) );
}

blockAllSignals( false );
}
@@ -391,6 +403,43 @@ void QgsComposerLegendWidget::on_mCheckBoxAutoUpdate_stateChanged( int state )
}
}

void QgsComposerLegendWidget::on_mMapComboBox_currentIndexChanged( int index )
{
if ( !mLegend )
{
return;
}

QVariant itemData = mMapComboBox->itemData( index );
if ( itemData.type() == QVariant::Invalid )
{
return;
}

const QgsComposition* comp = mLegend->composition();
if ( !comp )
{
return;
}

int mapNr = itemData.toInt();
if ( mapNr < 0 )
{
mLegend->setComposerMap( 0 );
}
else
{
const QgsComposerMap* map = comp->getComposerMapById( mapNr );
if ( map )
{
mLegend->beginCommand( tr( "Legend map changed" ) );
mLegend->setComposerMap( map );
mLegend->update();
mLegend->endCommand();
}
}
}

void QgsComposerLegendWidget::on_mAddToolButton_clicked()
{
if ( !mLegend )
@@ -442,16 +491,21 @@ void QgsComposerLegendWidget::on_mRemoveToolButton_clicked()
return;
}

QModelIndex currentIndex = mItemTreeView->currentIndex();
if ( !currentIndex.isValid() )
mLegend->beginCommand( "Legend item removed" );

QItemSelectionModel* selectionModel = mItemTreeView->selectionModel();
if ( !selectionModel )
{
return;
}

QModelIndex parentIndex = currentIndex.parent();
QModelIndexList selection = selectionModel->selectedIndexes();
for ( int i = selection.size() - 1; i >= 0; --i )
{
QModelIndex parentIndex = selection.at( i ).parent();
itemModel->removeRow( selection.at( i ).row(), parentIndex );
}

mLegend->beginCommand( "Legend item removed" );
itemModel->removeRow( currentIndex.row(), parentIndex );
mLegend->adjustBoxSize();
mLegend->update();
mLegend->endCommand();
@@ -583,4 +637,47 @@ void QgsComposerLegendWidget::blockAllSignals( bool b )
{
mItemTreeView->blockSignals( b );
mCheckBoxAutoUpdate->blockSignals( b );
mMapComboBox->blockSignals( b );
}

void QgsComposerLegendWidget::refreshMapComboBox()
{
if ( !mLegend )
{
return;
}

const QgsComposition* composition = mLegend->composition();
if ( !composition )
{
return;
}

//save current entry
int currentMapId = mMapComboBox->itemData( mMapComboBox->currentIndex() ).toInt();
mMapComboBox->clear();

QList<const QgsComposerMap*> availableMaps = composition->composerMapItems();
QList<const QgsComposerMap*>::const_iterator mapItemIt = availableMaps.constBegin();
for ( ; mapItemIt != availableMaps.constEnd(); ++mapItemIt )
{
mMapComboBox->addItem( tr( "Map %1" ).arg(( *mapItemIt )->id() ), ( *mapItemIt )->id() );
}
mMapComboBox->addItem( tr( "None" ), -1 );

//the former entry is not there anymore
int entry = mMapComboBox->findData( currentMapId );
if ( entry == -1 )
{
}
else
{
mMapComboBox->setCurrentIndex( entry );
}
}

void QgsComposerLegendWidget::showEvent( QShowEvent * event )
{
refreshMapComboBox();
QWidget::showEvent( event );
}
@@ -51,6 +51,7 @@ class QgsComposerLegendWidget: public QWidget, private Ui::QgsComposerLegendWidg
void on_mItemFontButton_clicked();
void on_mBoxSpaceSpinBox_valueChanged( double d );
void on_mCheckBoxAutoUpdate_stateChanged( int state );
void on_mMapComboBox_currentIndexChanged( int index );

//item manipulation
void on_mMoveDownToolButton_clicked();
@@ -62,13 +63,17 @@ class QgsComposerLegendWidget: public QWidget, private Ui::QgsComposerLegendWidg
void on_mUpdateAllPushButton_clicked();
void on_mAddGroupButton_clicked();

protected:
void showEvent( QShowEvent * event );

private slots:
/**Sets GUI according to state of mLegend*/
void setGuiElements();

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


QgsComposerLegend* mLegend;

0 comments on commit 9164946

Please sign in to comment.
You can’t perform that action at this time.