Skip to content

Commit 44fc315

Browse files
author
mhugent
committed
Apply patch #3263 to fix adding of groups to Legend. Provided by Marco Bernasocchi
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15561 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 53f9207 commit 44fc315

File tree

6 files changed

+18
-14
lines changed

6 files changed

+18
-14
lines changed

python/gui/qgslegendinterface.sip

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ class QgsLegendInterface : QObject
5050
public slots:
5151

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

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

src/app/legend/qgsapplegendinterface.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "qgslegendlayer.h"
2222
#include "qgsmaplayer.h"
2323

24+
2425
QgsAppLegendInterface::QgsAppLegendInterface( QgsLegend * legend )
2526
: mLegend( legend )
2627
{
@@ -31,9 +32,9 @@ QgsAppLegendInterface::~QgsAppLegendInterface()
3132
{
3233
}
3334

34-
int QgsAppLegendInterface::addGroup( QString name, bool expand )
35+
int QgsAppLegendInterface::addGroup( QString name, bool expand, QTreeWidgetItem* parent )
3536
{
36-
return mLegend->addGroup( name, expand );
37+
return mLegend->addGroup( name, expand, parent );
3738
}
3839

3940
void QgsAppLegendInterface::removeGroup( int groupIndex )

src/app/legend/qgsapplegendinterface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class QgsAppLegendInterface : public QgsLegendInterface
6565
public slots:
6666

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

7070
//! Remove all groups with the given name
7171
void removeGroup( int groupIndex );

src/app/legend/qgslegend.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,16 @@ void QgsLegend::handleCurrentItemChanged( QTreeWidgetItem* current, QTreeWidgetI
151151
emit currentLayerChanged( layer );
152152
}
153153

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

159-
QgsLegendGroup *parent = dynamic_cast<QgsLegendGroup *>( currentItem() );
159+
QgsLegendGroup *parentGroup = dynamic_cast<QgsLegendGroup *>( parent );
160160

161161
QgsLegendGroup *group;
162-
if ( parent )
163-
group = new QgsLegendGroup( parent, name );
162+
if ( parentGroup )
163+
group = new QgsLegendGroup( parentGroup, name );
164164
else
165165
group = new QgsLegendGroup( this, name );
166166

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

1795-
layer->setCacheImage( NULL );
1796-
mMapCanvas->zoomByFactor( qAbs( layer->rasterUnitsPerPixel() / mMapCanvas->mapUnitsPerPixel() ) );
1797-
mMapCanvas->refresh();
1798-
QgsDebugMsg( "MapUnitsPerPixel after : " + QString::number( mMapCanvas->mapUnitsPerPixel() ) );
1795+
layer->setCacheImage( NULL );
1796+
mMapCanvas->zoomByFactor( qAbs( layer->rasterUnitsPerPixel() / mMapCanvas->mapUnitsPerPixel() ) );
1797+
mMapCanvas->refresh();
1798+
QgsDebugMsg( "MapUnitsPerPixel after : " + QString::number( mMapCanvas->mapUnitsPerPixel() ) );
17991799
}
18001800
}
18011801

src/app/legend/qgslegend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ class QgsLegend : public QTreeWidget
221221
* @param expand expand the group
222222
* @return void
223223
*/
224-
int addGroup( QString name = QString(), bool expand = true );
224+
int addGroup( QString name = QString(), bool expand = true, QTreeWidgetItem* parent = 0 );
225225

226226
/*!
227227
* Removes all groups with the given name.

src/gui/qgslegendinterface.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <QStringList>
2424

2525
class QgsMapLayer;
26+
class QTreeWidgetItem;
2627

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

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

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

0 commit comments

Comments
 (0)