Skip to content
Permalink
Browse files
legend order: add checkboxes to control whether the legend or the lay…
…er order controls render order
  • Loading branch information
jef-n committed Nov 29, 2011
1 parent 376d45b commit ee9b8d7e66982ad1223911d929ece7cda1e6a02a
Showing with 55 additions and 17 deletions.
  1. +13 −9 src/app/legend/qgslayerorder.cpp
  2. +1 −1 src/app/legend/qgslayerorder.h
  3. +4 −2 src/app/legend/qgslegend.cpp
  4. +8 −2 src/app/legend/qgslegend.h
  5. +29 −3 src/app/qgisapp.cpp
@@ -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() ) );
@@ -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()
@@ -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 );
}
@@ -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;
@@ -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 );
}
@@ -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();
@@ -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 );
}

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

updateMapCanvasLayerSet();

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

bool QgsLegend::updateDrawingOrder()
@@ -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
@@ -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.
@@ -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
@@ -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
@@ -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;
}

0 comments on commit ee9b8d7

Please sign in to comment.