Skip to content
Permalink
Browse files

Synchronize check states between legend and layer order widget

  • Loading branch information
mhugent committed Nov 20, 2012
1 parent de2c671 commit 32e981db00dcc92e9d24f51a32a8622dadc20da0
Showing with 22 additions and 32 deletions.
  1. +21 −30 src/app/legend/qgslayerorder.cpp
  2. +0 −1 src/app/legend/qgslayerorder.h
  3. +1 −1 src/app/legend/qgslegend.cpp
@@ -20,6 +20,8 @@
#include "qgsmaplayer.h"
#include "qgslogger.h"
#include "qgslegend.h"
#include "qgslegendgroup.h"
#include "qgslegendlayer.h"
#include "qgslegendlayer.h"
#include "qgsproject.h"

@@ -33,10 +35,6 @@ QgsLayerOrder::QgsLayerOrder( QgsLegend *legend, QWidget * parent, const char *n
{
setObjectName( name );

// track visibility changed in legend
connect( mLegend, SIGNAL( itemChanged( QTreeWidgetItem *, int ) ),
this, SLOT( legendItemChanged( QTreeWidgetItem *, int ) ) );

// track if legend mode changes
connect( mLegend, SIGNAL( updateDrawingOrderChecked( bool ) ),
this, SLOT( updateDrawingOrderChecked( bool ) ) );
@@ -114,35 +112,28 @@ QListWidgetItem *QgsLayerOrder::layerItem( QgsMapLayer *layer ) const

void QgsLayerOrder::itemChanged( QListWidgetItem *item )
{
QgsDebugMsg( "Entering." );
QgsDebugMsg( QString( "item=%1" ).arg( item ? item->text() : "(null item)" ) );

QgsMapLayer *layer = qobject_cast<QgsMapLayer *>( item->data( Qt::UserRole ).value<QObject*>() );
mLegend->setLayerVisible( layer, item->checkState() == Qt::Checked );

QString name = item->text();
QString id = item->data( Qt::UserRole ).toString();
bool embeddedGroup = item->data( Qt::UserRole + 1 ).toBool();
if ( embeddedGroup )
{
QgsLegendGroup* grp = mLegend->findLegendGroup( name, id );
if ( grp )
{
grp->setCheckState( 0, item->checkState() );
}
}
else
{
QgsLegendLayer* ll = mLegend->findLegendLayer( id );
if ( ll )
{
ll->setCheckState( 0, item->checkState() );
}
}
updateLayerOrder();
}

void QgsLayerOrder::legendItemChanged( QTreeWidgetItem *item, int col )
{
QgsDebugMsg( "Entering." );

if ( col != 0 )
return;

QgsDebugMsg( QString( "legendItem changed=%1" ).arg( item ? item->text( 0 ) : "(null item)" ) );

QgsLegendLayer *ll = dynamic_cast< QgsLegendLayer * >( item );
if ( !ll )
return;

QListWidgetItem *lwi = layerItem( ll->layer() );
if ( !lwi )
return;

lwi->setCheckState( item->checkState( col ) );
}

void QgsLayerOrder::mousePressEvent( QMouseEvent * e )
{
QgsDebugMsg( "Entering." );
@@ -48,7 +48,6 @@ class QgsLayerOrder : public QListWidget
private slots:
void updateDrawingOrderChecked( bool );
void itemChanged( QListWidgetItem * );
void legendItemChanged( QTreeWidgetItem *, int );
void refreshLayerList();

private:
@@ -1193,7 +1193,7 @@ QList<DrawingOrderInfo> QgsLegend::drawingOrder()
DrawingOrderInfo dInfo;
dInfo.name = lgroup->text( 0 );
dInfo.id = lgroup->projectPath();
dInfo.checked = ( lgroup->checkState( 0 ) == Qt::Checked );
dInfo.checked = ( lgroup->checkState( 0 ) != Qt::Unchecked );
dInfo.embeddedGroup = true;
if ( mUpdateDrawingOrder )
{

0 comments on commit 32e981d

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