Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Improve python bindings for adding legend groups (#3263). Patch from …
…Marco Bernasocchi

git-svn-id: http://svn.osgeo.org/qgis/trunk@15787 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Apr 21, 2011
1 parent 7cf6967 commit b885332
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 2 deletions.
4 changes: 4 additions & 0 deletions python/gui/qgslegendinterface.sip
Expand Up @@ -52,6 +52,10 @@ class QgsLegendInterface : QObject
//! Add a new group
//! @note added parent parameter in 1.7
virtual int addGroup( QString name, bool expand = true, QTreeWidgetItem* parent =0 ) = 0;

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

//! Remove group on index
virtual void removeGroup( int groupIndex ) =0;
Expand Down
5 changes: 5 additions & 0 deletions src/app/legend/qgsapplegendinterface.cpp
Expand Up @@ -37,6 +37,11 @@ int QgsAppLegendInterface::addGroup( QString name, bool expand, QTreeWidgetItem*
return mLegend->addGroup( name, expand, parent );
}

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

void QgsAppLegendInterface::removeGroup( int groupIndex )
{
mLegend->removeGroup( groupIndex );
Expand Down
3 changes: 3 additions & 0 deletions src/app/legend/qgsapplegendinterface.h
Expand Up @@ -67,6 +67,9 @@ class QgsAppLegendInterface : public QgsLegendInterface
//! Add a new group
int addGroup( QString name, bool expand = true, QTreeWidgetItem* parent = 0 );

//! Add a new group at a specified index
int addGroup( QString name, bool expand, int groupIndex );

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

Expand Down
13 changes: 11 additions & 2 deletions src/app/legend/qgslegend.cpp
Expand Up @@ -159,7 +159,8 @@ int QgsLegend::addGroupToCurrentItem( QString name, bool expand )

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

QgsLegendGroup *parentGroup = dynamic_cast<QgsLegendGroup *>( parent );
Expand All @@ -173,10 +174,18 @@ int QgsLegend::addGroup( QString name, bool expand, QTreeWidgetItem* parent )
QModelIndex groupIndex = indexFromItem( group );
setExpanded( groupIndex, expand );
setCurrentItem( group );
openEditor();
if ( nameEmpty )
openEditor();

return groupIndex.row();
}

int QgsLegend::addGroup( QString name, bool expand, int groupIndex )
{
QgsLegendGroup * lg = dynamic_cast<QgsLegendGroup *>( topLevelItem( groupIndex ) );
return addGroup( name, expand, lg );
}

void QgsLegend::removeAll()
{
clear();
Expand Down
9 changes: 9 additions & 0 deletions src/app/legend/qgslegend.h
Expand Up @@ -237,6 +237,15 @@ class QgsLegend : public QTreeWidget
*/
int addGroup( QString name = QString(), bool expand = true, QTreeWidgetItem* parent = 0 );

/*!
* Slot called when user wishes to add a new empty layer group to the legend.
* All parameter are mandatory to be used to programatically nest a new group
* @param name name of the new group
* @param expand expand the group
* @return index of inserted group
*/
int addGroup( QString name, bool expand, int parentIndex );

/*!
* Removes all groups with the given name.
* @param name name of the groups to remove
Expand Down
4 changes: 4 additions & 0 deletions src/gui/qgslegendinterface.h
Expand Up @@ -84,6 +84,10 @@ class GUI_EXPORT QgsLegendInterface : public QObject
//! a parent group can be given to nest the new group in it
virtual int addGroup( QString name, bool expand = true, QTreeWidgetItem* parent = 0 ) = 0;

//! Add a new group
//! a parent group index has to be given to nest the new group in it
virtual int addGroup( QString name, bool expand, int parentIndex ) = 0;

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

Expand Down

0 comments on commit b885332

Please sign in to comment.