Apply patch #3263 to fix adding of groups to Legend. Provided by Marco Bernasocchi

git-svn-id: http://svn.osgeo.org/qgis/trunk@15561 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
mhugent 2011-03-22 15:39:10 +00:00
parent 272bbddb0e
commit 855601c3d6
6 changed files with 18 additions and 14 deletions

View File

@ -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;

View File

@ -21,6 +21,7 @@
#include "qgslegendlayer.h"
#include "qgsmaplayer.h"
QgsAppLegendInterface::QgsAppLegendInterface( QgsLegend * legend )
: mLegend( legend )
{
@ -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 )

View File

@ -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 );

View File

@ -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 );
@ -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() ) );
}
}

View File

@ -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.

View File

@ -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)
@ -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;