Applied patch from #2672 by Andres Manz: more legend interface functionality.

Thanks for contributing.


git-svn-id: http://svn.osgeo.org/qgis/trunk@13383 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
wonder 2010-04-25 17:26:12 +00:00
parent 1cbc7afef0
commit 8a394ab070
6 changed files with 151 additions and 4 deletions

View File

@ -21,7 +21,23 @@ class QgsLegendInterface : QObject
//! Return all layers in the project in legend order
//! @note added in 1.5
virtual QList< QgsMapLayer * > layers() const = 0;
virtual QList< QgsMapLayer * > layers() const =0;
//! Check if a group exists
//! @note added in 1.5
virtual bool groupExists( int groupIndex ) =0;
//! Check if a group is expanded
//! @note added in 1.5
virtual bool isGroupExpanded( int groupIndex ) =0;
//! Check if a group is visible
//! @note added in 1.5
virtual bool isGroupVisible( int groupIndex ) =0;
//! Check if a layer is visible
//! @note added in 1.5
virtual bool isLayerVisible( QgsMapLayer * ml ) =0;
signals:
@ -39,8 +55,20 @@ class QgsLegendInterface : QObject
//! Move a layer to a group
virtual void moveLayer( QgsMapLayer * layer, int groupIndex ) =0;
//! Collapse or expand a group
//! @note added in 1.5
virtual void setGroupExpanded( int groupIndex, bool expand ) =0;
//! Set the visibility of a group
//! @note added in 1.5
virtual void setGroupVisible( int groupIndex, bool visible ) =0;
//! Set the visibility of a layer
//! @note added in 1.5
virtual void setLayerVisible( QgsMapLayer * ml, bool visible ) =0;
//! refresh layer symbology
//! \note added in 1.5
//! @note added in 1.5
virtual void refreshLayerSymbology( QgsMapLayer *layer ) =0;
};

View File

@ -54,11 +54,59 @@ void QgsAppLegendInterface::updateIndex( QModelIndex oldIndex, QModelIndex newIn
}
}
void QgsAppLegendInterface::setGroupExpanded( int groupIndex, bool expand )
{
mLegend->setExpanded( mLegend->model()->index( groupIndex, 0 ), expand );
}
void QgsAppLegendInterface::setGroupVisible( int groupIndex, bool visible )
{
if ( !groupExists( groupIndex ) )
{
return;
}
Qt::CheckState state = visible ? Qt::Checked : Qt::Unchecked;
mLegend->topLevelItem( groupIndex )->setCheckState( 0, state );
}
void QgsAppLegendInterface::setLayerVisible( QgsMapLayer * ml, bool visible )
{
mLegend->setLayerVisible( ml, visible );
}
QStringList QgsAppLegendInterface::groups()
{
return mLegend->groups();
}
bool QgsAppLegendInterface::groupExists( int groupIndex )
{
QModelIndex mi = mLegend->model()->index( groupIndex, 0 );
return ( mi.isValid() &&
mLegend->isLegendGroup( mi ) );
}
bool QgsAppLegendInterface::isGroupExpanded( int groupIndex )
{
return mLegend->isExpanded( mLegend->model()->index( groupIndex, 0 ) );
}
bool QgsAppLegendInterface::isGroupVisible( int groupIndex )
{
if ( !groupExists( groupIndex ) )
{
return false;
}
return ( Qt::Checked == mLegend->topLevelItem( groupIndex )->checkState( 0 ) );
}
bool QgsAppLegendInterface::isLayerVisible( QgsMapLayer * ml )
{
return ( Qt::Checked == mLegend->layerCheckState( ml ) );
}
QList< QgsMapLayer * > QgsAppLegendInterface::layers() const
{
QList< QgsMapLayer * > items;

View File

@ -38,7 +38,7 @@ class QgsAppLegendInterface : public QgsLegendInterface
/** Constructor */
explicit QgsAppLegendInterface( QgsLegend * legend );
/** Virtual destructor */
/** Destructor */
~QgsAppLegendInterface();
//! Return a string list of groups
@ -47,6 +47,18 @@ class QgsAppLegendInterface : public QgsLegendInterface
//! Return all layers in the project in legend order
QList< QgsMapLayer * > layers() const;
//! Check if a group exists
bool groupExists( int groupIndex );
//! Check if a group is expanded
bool isGroupExpanded( int groupIndex );
//! Check if a group is visible
bool isGroupVisible( int groupIndex );
//! Check if a layer is visible
bool isLayerVisible( QgsMapLayer * ml );
public slots:
//! Add a new group
@ -61,6 +73,15 @@ class QgsAppLegendInterface : public QgsLegendInterface
//! Update an index
void updateIndex( QModelIndex oldIndex, QModelIndex newIndex );
//! Collapse or expand a group
virtual void setGroupExpanded( int groupIndex, bool expand );
//! Set the visibility of a group
virtual void setGroupVisible( int groupIndex, bool visible );
//! Set the visibility of a layer
virtual void setLayerVisible( QgsMapLayer * ml, bool visible );
//! refresh layer symbology
void refreshLayerSymbology( QgsMapLayer *ml );

View File

@ -480,6 +480,13 @@ void QgsLegend::initPixmaps()
mPixmaps.mProjectionErrorPixmap = QgisApp::getThemePixmap( "/mIconProjectionProblem.png" );
}
Qt::CheckState QgsLegend::layerCheckState( QgsMapLayer * layer )
{
QgsLegendLayer * ll = findLegendLayer( layer );
return ll ? ll->checkState( 0 ) : Qt::Unchecked;
}
int QgsLegend::getItemPos( QTreeWidgetItem* item )
{
int counter = 1;
@ -548,6 +555,16 @@ void QgsLegend::addLayer( QgsMapLayer * layer )
doItemsLayout();
}
void QgsLegend::setLayerVisible( QgsMapLayer * layer, bool visible )
{
QgsLegendLayer * ll = findLegendLayer( layer );
if ( ll )
{
Qt::CheckState cs = visible ? Qt::Checked : Qt::Unchecked;
ll->setCheckState( 0, cs );
}
}
void QgsLegend::setMapCanvas( QgsMapCanvas * canvas )
{
if ( mMapCanvas )

View File

@ -179,6 +179,9 @@ class QgsLegend : public QTreeWidget
/**Returns structure with legend pixmaps*/
QgsLegendPixmaps& pixmaps() { return mPixmaps; }
/**Returns a layers check state*/
Qt::CheckState layerCheckState( QgsMapLayer * layer );
void updateCheckStates( QTreeWidgetItem* item, Qt::CheckState state ) { item->setData( 0, Qt::UserRole, state ); }
@ -187,6 +190,8 @@ class QgsLegend : public QTreeWidget
/*!Adds a new layer group with the maplayer to the canvas*/
void addLayer( QgsMapLayer * layer );
void setLayerVisible( QgsMapLayer * layer, bool visible );
void setMapCanvas( QgsMapCanvas * canvas );
/**Updates symbology items for a layer*/

View File

@ -48,6 +48,22 @@ class GUI_EXPORT QgsLegendInterface : public QObject
//! @note added in 1.5
virtual QList< QgsMapLayer * > layers() const = 0;
//! Check if a group exists
//! @note added in 1.5
virtual bool groupExists( int groupIndex ) = 0;
//! Check if a group is expanded
//! @note added in 1.5
virtual bool isGroupExpanded( int groupIndex ) = 0;
//! Check if a group is visible
//! @note added in 1.5
virtual bool isGroupVisible( int groupIndex ) = 0;
//! Check if a layer is visible
//! @note added in 1.5
virtual bool isLayerVisible( QgsMapLayer * ml ) = 0;
signals:
//! emitted when a group index has changed
@ -64,8 +80,20 @@ class GUI_EXPORT QgsLegendInterface : public QObject
//! Move a layer to a group
virtual void moveLayer( QgsMapLayer * ml, int groupIndex ) = 0;
//! Collapse or expand a group
//! @note added in 1.5
virtual void setGroupExpanded( int groupIndex, bool expand ) = 0;
//! Set the visibility of a group
//! @note added in 1.5
virtual void setGroupVisible( int groupIndex, bool visible ) = 0;
//! Set the visibility of a layer
//! @note added in 1.5
virtual void setLayerVisible( QgsMapLayer * ml, bool visible ) = 0;
//! Refresh layer symbology
// @noted added in 1.5
//! @note added in 1.5
virtual void refreshLayerSymbology( QgsMapLayer *ml ) = 0;
};