Skip to content

Commit

Permalink
legend order: add checkboxes to control whether the legend or the lay…
Browse files Browse the repository at this point in the history
…er order controls render order
  • Loading branch information
jef-n committed Nov 29, 2011
1 parent 376d45b commit ee9b8d7
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 17 deletions.
22 changes: 13 additions & 9 deletions src/app/legend/qgslayerorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ QgsLayerOrder::QgsLayerOrder( QgsLegend *legend, QWidget * parent, const char *n
this, SLOT( legendItemChanged( QTreeWidgetItem *, int ) ) );

// track if legend mode changes
connect( mLegend, SIGNAL( updateDrawingOrderChanged( bool ) ),
this, SLOT( updateDrawingOrderChanged( bool ) ) );
connect( mLegend, SIGNAL( updateDrawingOrderChecked( bool ) ),
this, SLOT( updateDrawingOrderChecked( bool ) ) );

connect( mLegend, SIGNAL( zOrderChanged() ),
this, SLOT( refreshLayerList() ) );
Expand All @@ -64,13 +64,13 @@ QgsLayerOrder::QgsLayerOrder( QgsLegend *legend, QWidget * parent, const char *n
setSelectionMode( QAbstractItemView::ExtendedSelection );
setDragEnabled( false );
setAutoScroll( true );
QFont f( "Arial", 12, QFont::Bold );
QFont f( "Arial", 11, QFont::Bold );
setFont( f );
QPalette palette;
palette.setColor( backgroundRole(), QColor( 192, 192, 192 ) );
setPalette( palette );

updateDrawingOrderChanged( mLegend->updateDrawingOrder() );
updateDrawingOrderChecked( mLegend->updateDrawingOrder() );
}

QgsLayerOrder::~QgsLayerOrder()
Expand All @@ -82,11 +82,12 @@ void QgsLayerOrder::refreshLayerList()
{
clear();

foreach( QgsMapLayer *layer, mLegend->layers() )
foreach( QgsLegendLayer *layer, mLegend->legendLayers() )
{
QListWidgetItem *item = new QListWidgetItem( layer->name() );
item->setData( Qt::UserRole, qVariantFromValue( qobject_cast<QObject*>( layer ) ) );
item->setCheckState( mLegend->layerCheckState( layer ) );
QListWidgetItem *item = new QListWidgetItem( layer->layer()->name() );
item->setData( 1, QString::number( layer->drawingOrder() ) );
item->setData( Qt::UserRole, qVariantFromValue( qobject_cast<QObject*>( layer->layer() ) ) );
item->setCheckState( layer->isVisible() ? Qt::Checked : Qt::Unchecked );
QgsDebugMsg( QString( "add item=%1 at %2" ).arg( item ? item->text() : "(null item)" ).arg( count() ) );
addItem( item );
}
Expand Down Expand Up @@ -189,16 +190,19 @@ void QgsLayerOrder::mouseMoveEvent( QMouseEvent * e )
{
mInsertRow = row( rowItem );
QgsDebugMsg( QString( "Move to row %1" ).arg( mInsertRow ) );
scrollToItem( rowItem );
}
else if ( e->pos().y() < visualItemRect( item( 0 ) ).bottom() )
{
mInsertRow = 0;
QgsDebugMsg( QString( "Insert top row %1" ).arg( mInsertRow ) );
scrollToTop();
}
else
{
mInsertRow = count();
QgsDebugMsg( QString( "Append bottom row %1" ).arg( mInsertRow ) );
scrollToBottom();
}

int y;
Expand Down Expand Up @@ -269,7 +273,7 @@ void QgsLayerOrder::hideLine()
mInsertionLine->setGeometry( 0, -100, 1, 1 );
}

void QgsLayerOrder::updateDrawingOrderChanged( bool enabled )
void QgsLayerOrder::updateDrawingOrderChecked( bool enabled )
{
setDisabled( enabled );
}
2 changes: 1 addition & 1 deletion src/app/legend/qgslayerorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class QgsLayerOrder : public QListWidget
void mouseReleaseEvent( QMouseEvent * e );

private slots:
void updateDrawingOrderChanged( bool );
void updateDrawingOrderChecked( bool );
void itemChanged( QListWidgetItem * );
void legendItemChanged( QTreeWidgetItem *, int );
void refreshLayerList();
Expand Down
6 changes: 4 additions & 2 deletions src/app/legend/qgslegend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1403,7 +1403,8 @@ bool QgsLegend::readXML( QDomNode& legendnode )
clear(); //remove all items first
mEmbeddedGroups.clear();
mUpdateDrawingOrder = legendnode.toElement().attribute( "updateDrawingOrder", "true" ) == "true";
emit updateDrawingOrderChanged( mUpdateDrawingOrder );
emit updateDrawingOrderChecked( mUpdateDrawingOrder );
emit updateDrawingOrderUnchecked( !mUpdateDrawingOrder );
return readXML( 0, legendnode );
}

Expand Down Expand Up @@ -2356,7 +2357,8 @@ void QgsLegend::setUpdateDrawingOrder( bool updateDrawingOrder )

updateMapCanvasLayerSet();

emit updateDrawingOrderChanged( mUpdateDrawingOrder );
emit updateDrawingOrderChecked( mUpdateDrawingOrder );
emit updateDrawingOrderUnchecked( !mUpdateDrawingOrder );
}

bool QgsLegend::updateDrawingOrder()
Expand Down
10 changes: 8 additions & 2 deletions src/app/legend/qgslegend.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ class QgsLegend : public QTreeWidget
Else, an empty list is returned.*/
QList<QgsMapLayer *> layers();

//!Return all layers in drawing order
QList<QgsLegendLayer *> legendLayers();

void setDrawingOrder( QList<QgsMapLayer *> );

/*!set the current layer
Expand Down Expand Up @@ -307,6 +310,9 @@ class QgsLegend : public QTreeWidget
/** Update drawing order */
void setUpdateDrawingOrder( bool updateDrawingOrder );

/** Update drawing order */
void unsetUpdateDrawingOrder( bool dontUpdateDrawingOrder ) { setUpdateDrawingOrder( !dontUpdateDrawingOrder ); }

protected:

/*!Event handler for mouse movements.
Expand Down Expand Up @@ -432,7 +438,6 @@ class QgsLegend : public QTreeWidget
bool writeXML( QList<QTreeWidgetItem *> items, QDomNode &node, QDomDocument &document );

QList<QgsMapCanvasLayer> canvasLayers();
QList<QgsLegendLayer *> legendLayers();

/*! Prevent the copying of QgsLegends
* @todo See if this is really required - we may want multiple map, canvas and
Expand Down Expand Up @@ -511,7 +516,8 @@ class QgsLegend : public QTreeWidget

void zOrderChanged();

void updateDrawingOrderChanged( bool );
void updateDrawingOrderChecked( bool );
void updateDrawingOrderUnchecked( bool );

//! Emitted whenever current (selected) layer changes
// the pointer to layer can be null if no layer is selected
Expand Down
32 changes: 29 additions & 3 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1716,19 +1716,45 @@ void QgisApp::initLegend()
mLegendDock = new QDockWidget( tr( "Layers" ), this );
mLegendDock->setObjectName( "Legend" );
mLegendDock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );
mLegendDock->setWidget( mMapLegend );

QCheckBox *legendCb = new QCheckBox( tr( "Control rendering order" ) );
legendCb->setChecked( true );

QCheckBox *orderCb = new QCheckBox( tr( "Control rendering order" ) );
orderCb->setChecked( false );

connect( legendCb, SIGNAL( toggled( bool ) ), mMapLegend, SLOT( setUpdateDrawingOrder( bool ) ) );
connect( orderCb, SIGNAL( toggled( bool ) ), mMapLegend, SLOT( unsetUpdateDrawingOrder( bool ) ) );
connect( mMapLegend, SIGNAL( updateDrawingOrderChecked( bool ) ), legendCb, SLOT( setChecked( bool ) ) );
connect( mMapLegend, SIGNAL( updateDrawingOrderUnchecked( bool ) ), orderCb, SLOT( setChecked( bool ) ) );

QWidget *w = new QWidget( this );
QLayout *l = new QVBoxLayout;
l->addWidget( mMapLegend );
l->addWidget( legendCb );
w->setLayout( l );
mLegendDock->setWidget( w );
addDockWidget( Qt::LeftDockWidgetArea, mLegendDock );

// add to the Panel submenu
mPanelMenu->addAction( mLegendDock->toggleViewAction() );

mMapLayerOrder->setWhatsThis( tr( "Map layer list that displays all layers in drawing order." ) );
mLayerOrderDock = new QDockWidget( tr( "Layerorder" ), this );
mLayerOrderDock = new QDockWidget( tr( "Layer order" ), this );
mLayerOrderDock->setObjectName( "Legend" );
mLayerOrderDock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );
mLayerOrderDock->setWidget( mMapLayerOrder );

w = new QWidget( this );
l = new QVBoxLayout;
l->addWidget( mMapLayerOrder );
l->addWidget( orderCb );
w->setLayout( l );
mLayerOrderDock->setWidget( w );
addDockWidget( Qt::LeftDockWidgetArea, mLayerOrderDock );

// add to the Panel submenu
mPanelMenu->addAction( mLayerOrderDock->toggleViewAction() );

return;
}

Expand Down

0 comments on commit ee9b8d7

Please sign in to comment.