Skip to content

Commit

Permalink
Apply patch #3263 to fix adding of groups to Legend. Provided by Marc…
Browse files Browse the repository at this point in the history
…o Bernasocchi

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15561 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Mar 22, 2011
1 parent 53f9207 commit 44fc315
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
3 changes: 2 additions & 1 deletion python/gui/qgslegendinterface.sip
Expand Up @@ -50,7 +50,8 @@ class QgsLegendInterface : QObject
public slots:

//! Add a new group
virtual int addGroup( QString name, bool expand = true ) =0;
//! @note added parent parameter in 1.7
virtual int addGroup( QString name, bool expand = true, QTreeWidgetItem* parent =0 ) =0;

//! Remove group on index
virtual void removeGroup( int groupIndex ) =0;
Expand Down
5 changes: 3 additions & 2 deletions src/app/legend/qgsapplegendinterface.cpp
Expand Up @@ -21,6 +21,7 @@
#include "qgslegendlayer.h"
#include "qgsmaplayer.h"


QgsAppLegendInterface::QgsAppLegendInterface( QgsLegend * legend )
: mLegend( legend )
{
Expand All @@ -31,9 +32,9 @@ QgsAppLegendInterface::~QgsAppLegendInterface()
{
}

int QgsAppLegendInterface::addGroup( QString name, bool expand )
int QgsAppLegendInterface::addGroup( QString name, bool expand, QTreeWidgetItem* parent )
{
return mLegend->addGroup( name, expand );
return mLegend->addGroup( name, expand, parent );
}

void QgsAppLegendInterface::removeGroup( int groupIndex )
Expand Down
2 changes: 1 addition & 1 deletion src/app/legend/qgsapplegendinterface.h
Expand Up @@ -65,7 +65,7 @@ class QgsAppLegendInterface : public QgsLegendInterface
public slots:

//! Add a new group
int addGroup( QString name, bool expand = true );
int addGroup( QString name, bool expand = true, QTreeWidgetItem* parent = 0 );

//! Remove all groups with the given name
void removeGroup( int groupIndex );
Expand Down
16 changes: 8 additions & 8 deletions src/app/legend/qgslegend.cpp
Expand Up @@ -151,16 +151,16 @@ void QgsLegend::handleCurrentItemChanged( QTreeWidgetItem* current, QTreeWidgetI
emit currentLayerChanged( layer );
}

int QgsLegend::addGroup( QString name, bool expand )
int QgsLegend::addGroup( QString name, bool expand, QTreeWidgetItem* parent )
{
if ( name.isEmpty() )
name = tr( "group" ); // some default name if none specified

QgsLegendGroup *parent = dynamic_cast<QgsLegendGroup *>( currentItem() );
QgsLegendGroup *parentGroup = dynamic_cast<QgsLegendGroup *>( parent );

QgsLegendGroup *group;
if ( parent )
group = new QgsLegendGroup( parent, name );
if ( parentGroup )
group = new QgsLegendGroup( parentGroup, name );
else
group = new QgsLegendGroup( this, name );

Expand Down Expand Up @@ -1792,10 +1792,10 @@ void QgsLegend::legendLayerZoomNative()
QgsDebugMsg( "Raster units per pixel : " + QString::number( layer->rasterUnitsPerPixel() ) );
QgsDebugMsg( "MapUnitsPerPixel before : " + QString::number( mMapCanvas->mapUnitsPerPixel() ) );

layer->setCacheImage( NULL );
mMapCanvas->zoomByFactor( qAbs( layer->rasterUnitsPerPixel() / mMapCanvas->mapUnitsPerPixel() ) );
mMapCanvas->refresh();
QgsDebugMsg( "MapUnitsPerPixel after : " + QString::number( mMapCanvas->mapUnitsPerPixel() ) );
layer->setCacheImage( NULL );
mMapCanvas->zoomByFactor( qAbs( layer->rasterUnitsPerPixel() / mMapCanvas->mapUnitsPerPixel() ) );
mMapCanvas->refresh();
QgsDebugMsg( "MapUnitsPerPixel after : " + QString::number( mMapCanvas->mapUnitsPerPixel() ) );
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/legend/qgslegend.h
Expand Up @@ -221,7 +221,7 @@ class QgsLegend : public QTreeWidget
* @param expand expand the group
* @return void
*/
int addGroup( QString name = QString(), bool expand = true );
int addGroup( QString name = QString(), bool expand = true, QTreeWidgetItem* parent = 0 );

/*!
* Removes all groups with the given name.
Expand Down
4 changes: 3 additions & 1 deletion src/gui/qgslegendinterface.h
Expand Up @@ -23,6 +23,7 @@
#include <QStringList>

class QgsMapLayer;
class QTreeWidgetItem;

//Information about relationship between groups and layers
//key: group name (or null strings for single layers without groups)
Expand Down Expand Up @@ -80,7 +81,8 @@ class GUI_EXPORT QgsLegendInterface : public QObject
public slots:

//! Add a new group
virtual int addGroup( QString name, bool expand = true ) = 0;
//! forceAtEnd forces the new group to be created at the end of the legend
virtual int addGroup( QString name, bool expand = true, QTreeWidgetItem* parent = 0 ) = 0;

//! Remove group on index
virtual void removeGroup( int groupIndex ) = 0;
Expand Down

0 comments on commit 44fc315

Please sign in to comment.