Skip to content

Commit

Permalink
Applied patch from #2672 by Andres Manz: more legend interface functi…
Browse files Browse the repository at this point in the history
…onality.

Thanks for contributing.


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13383 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Apr 25, 2010
1 parent c5ede41 commit 3b27f58
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 4 deletions.
32 changes: 30 additions & 2 deletions python/gui/qgslegendinterface.sip
Expand Up @@ -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:

Expand All @@ -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;
};

48 changes: 48 additions & 0 deletions src/app/legend/qgsapplegendinterface.cpp
Expand Up @@ -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;
Expand Down
23 changes: 22 additions & 1 deletion src/app/legend/qgsapplegendinterface.h
Expand Up @@ -38,7 +38,7 @@ class QgsAppLegendInterface : public QgsLegendInterface
/** Constructor */
explicit QgsAppLegendInterface( QgsLegend * legend );

/** Virtual destructor */
/** Destructor */
~QgsAppLegendInterface();

//! Return a string list of groups
Expand All @@ -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
Expand All @@ -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 );

Expand Down
17 changes: 17 additions & 0 deletions src/app/legend/qgslegend.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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 )
Expand Down
5 changes: 5 additions & 0 deletions src/app/legend/qgslegend.h
Expand Up @@ -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 ); }

Expand All @@ -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*/
Expand Down
30 changes: 29 additions & 1 deletion src/gui/qgslegendinterface.h
Expand Up @@ -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
Expand All @@ -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;
};

Expand Down

0 comments on commit 3b27f58

Please sign in to comment.