Skip to content
Permalink
Browse files
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 b8853323acc25a9e8eeb290b103f4a74e31d7f05
@@ -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;
@@ -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 );
@@ -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 );

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

0 comments on commit b885332

Please sign in to comment.