Skip to content

Commit 9164946

Browse files
committed
Merge branch 'release-1_7_0' of github.com:qgis/Quantum-GIS into release-1_7_0
2 parents bb06a7f + 92df029 commit 9164946

9 files changed

+265
-40
lines changed

src/app/composer/qgscomposerlegendwidget.cpp

+102-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "qgscomposerlegenditemdialog.h"
2121
#include "qgscomposerlegendlayersdialog.h"
2222
#include "qgscomposeritemwidget.h"
23+
#include "qgscomposermap.h"
2324
#include <QFontDialog>
2425

2526
#include "qgsapplegendinterface.h"
@@ -88,6 +89,17 @@ void QgsComposerLegendWidget::setGuiElements()
8889
{
8990
mCheckBoxAutoUpdate->setChecked( mLegend->model()->autoUpdate() );
9091
}
92+
refreshMapComboBox();
93+
94+
const QgsComposerMap* map = mLegend->composerMap();
95+
if ( map )
96+
{
97+
mMapComboBox->setCurrentIndex( mMapComboBox->findData( map->id() ) );
98+
}
99+
else
100+
{
101+
mMapComboBox->setCurrentIndex( mMapComboBox->findData( -1 ) );
102+
}
91103

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

406+
void QgsComposerLegendWidget::on_mMapComboBox_currentIndexChanged( int index )
407+
{
408+
if ( !mLegend )
409+
{
410+
return;
411+
}
412+
413+
QVariant itemData = mMapComboBox->itemData( index );
414+
if ( itemData.type() == QVariant::Invalid )
415+
{
416+
return;
417+
}
418+
419+
const QgsComposition* comp = mLegend->composition();
420+
if ( !comp )
421+
{
422+
return;
423+
}
424+
425+
int mapNr = itemData.toInt();
426+
if ( mapNr < 0 )
427+
{
428+
mLegend->setComposerMap( 0 );
429+
}
430+
else
431+
{
432+
const QgsComposerMap* map = comp->getComposerMapById( mapNr );
433+
if ( map )
434+
{
435+
mLegend->beginCommand( tr( "Legend map changed" ) );
436+
mLegend->setComposerMap( map );
437+
mLegend->update();
438+
mLegend->endCommand();
439+
}
440+
}
441+
}
442+
394443
void QgsComposerLegendWidget::on_mAddToolButton_clicked()
395444
{
396445
if ( !mLegend )
@@ -442,16 +491,21 @@ void QgsComposerLegendWidget::on_mRemoveToolButton_clicked()
442491
return;
443492
}
444493

445-
QModelIndex currentIndex = mItemTreeView->currentIndex();
446-
if ( !currentIndex.isValid() )
494+
mLegend->beginCommand( "Legend item removed" );
495+
496+
QItemSelectionModel* selectionModel = mItemTreeView->selectionModel();
497+
if ( !selectionModel )
447498
{
448499
return;
449500
}
450501

451-
QModelIndex parentIndex = currentIndex.parent();
502+
QModelIndexList selection = selectionModel->selectedIndexes();
503+
for ( int i = selection.size() - 1; i >= 0; --i )
504+
{
505+
QModelIndex parentIndex = selection.at( i ).parent();
506+
itemModel->removeRow( selection.at( i ).row(), parentIndex );
507+
}
452508

453-
mLegend->beginCommand( "Legend item removed" );
454-
itemModel->removeRow( currentIndex.row(), parentIndex );
455509
mLegend->adjustBoxSize();
456510
mLegend->update();
457511
mLegend->endCommand();
@@ -583,4 +637,47 @@ void QgsComposerLegendWidget::blockAllSignals( bool b )
583637
{
584638
mItemTreeView->blockSignals( b );
585639
mCheckBoxAutoUpdate->blockSignals( b );
640+
mMapComboBox->blockSignals( b );
641+
}
642+
643+
void QgsComposerLegendWidget::refreshMapComboBox()
644+
{
645+
if ( !mLegend )
646+
{
647+
return;
648+
}
649+
650+
const QgsComposition* composition = mLegend->composition();
651+
if ( !composition )
652+
{
653+
return;
654+
}
655+
656+
//save current entry
657+
int currentMapId = mMapComboBox->itemData( mMapComboBox->currentIndex() ).toInt();
658+
mMapComboBox->clear();
659+
660+
QList<const QgsComposerMap*> availableMaps = composition->composerMapItems();
661+
QList<const QgsComposerMap*>::const_iterator mapItemIt = availableMaps.constBegin();
662+
for ( ; mapItemIt != availableMaps.constEnd(); ++mapItemIt )
663+
{
664+
mMapComboBox->addItem( tr( "Map %1" ).arg(( *mapItemIt )->id() ), ( *mapItemIt )->id() );
665+
}
666+
mMapComboBox->addItem( tr( "None" ), -1 );
667+
668+
//the former entry is not there anymore
669+
int entry = mMapComboBox->findData( currentMapId );
670+
if ( entry == -1 )
671+
{
672+
}
673+
else
674+
{
675+
mMapComboBox->setCurrentIndex( entry );
676+
}
677+
}
678+
679+
void QgsComposerLegendWidget::showEvent( QShowEvent * event )
680+
{
681+
refreshMapComboBox();
682+
QWidget::showEvent( event );
586683
}

src/app/composer/qgscomposerlegendwidget.h

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class QgsComposerLegendWidget: public QWidget, private Ui::QgsComposerLegendWidg
5151
void on_mItemFontButton_clicked();
5252
void on_mBoxSpaceSpinBox_valueChanged( double d );
5353
void on_mCheckBoxAutoUpdate_stateChanged( int state );
54+
void on_mMapComboBox_currentIndexChanged( int index );
5455

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

66+
protected:
67+
void showEvent( QShowEvent * event );
68+
6569
private slots:
6670
/**Sets GUI according to state of mLegend*/
6771
void setGuiElements();
6872

6973
private:
7074
QgsComposerLegendWidget();
7175
void blockAllSignals( bool b );
76+
void refreshMapComboBox();
7277

7378

7479
QgsComposerLegend* mLegend;

0 commit comments

Comments
 (0)