addGroupNestingPython.diff

This patch creates the python binding to addGroup. For the moment it allows only one level of nesting like removeGroup - Marco Bernasocchi, 2011-04-20 04:53 AM

Download (4.16 KB)

View differences:

python/gui/qgslegendinterface.sip (working copy)
52 52
    //! Add a new group
53 53
    //! @note added parent parameter in 1.7
54 54
    virtual int addGroup( QString name, bool expand = true, QTreeWidgetItem* parent =0 ) = 0;
55
    
56
    //! Add a new group
57
    //! @note added parentIndex parameter in 1.7
58
    virtual int addGroup( QString name, bool expand, int parentIndex ) = 0;
55 59

  
56 60
    //! Remove group on index
57 61
    virtual void removeGroup( int groupIndex ) =0;
src/app/legend/qgsapplegendinterface.h (working copy)
66 66

  
67 67
    //! Add a new group
68 68
    int addGroup( QString name, bool expand = true, QTreeWidgetItem* parent = 0 );
69
    
70
    //! Add a new group at a specified index
71
    int addGroup( QString name, bool expand, int groupIndex  );
69 72

  
70 73
    //! Remove all groups with the given name
71 74
    void removeGroup( int groupIndex );
src/app/legend/qgslegend.cpp (working copy)
159 159

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

  
165 166
  QgsLegendGroup *parentGroup = dynamic_cast<QgsLegendGroup *>( parent );
......
173 174
  QModelIndex groupIndex = indexFromItem( group );
174 175
  setExpanded( groupIndex, expand );
175 176
  setCurrentItem( group );
176
  openEditor();
177
  if (nameEmpty)
178
    openEditor();
179

  
177 180
  return groupIndex.row();
178 181
}
179 182

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

  
180 189
void QgsLegend::removeAll()
181 190
{
182 191
  clear();
src/app/legend/qgslegend.h (working copy)
236 236
     * @return index of inserted group
237 237
     */
238 238
    int addGroup( QString name = QString(), bool expand = true, QTreeWidgetItem* parent = 0 );
239
    
240
    /*!
241
     * Slot called when user wishes to add a new empty layer group to the legend.
242
     * All parameter are mandatory to be used to programatically nest a new group
243
     * @param name name of the new group
244
     * @param expand expand the group
245
     * @return index of inserted group
246
     */
247
    int addGroup( QString name, bool expand, int parentIndex );
239 248

  
240 249
    /*!
241 250
     * Removes all groups with the given name.
src/app/legend/qgsapplegendinterface.cpp (working copy)
37 37
  return mLegend->addGroup( name, expand, parent );
38 38
}
39 39

  
40
int QgsAppLegendInterface::addGroup( QString name, bool expand, int parentIndex )
41
{
42
  return mLegend->addGroup( name, expand, parentIndex );
43
}
44

  
40 45
void QgsAppLegendInterface::removeGroup( int groupIndex )
41 46
{
42 47
  mLegend->removeGroup( groupIndex );
src/gui/qgslegendinterface.h (working copy)
83 83
    //! Add a new group
84 84
    //! a parent group can be given to nest the new group in it
85 85
    virtual int addGroup( QString name, bool expand = true, QTreeWidgetItem* parent = 0 ) = 0;
86
    
87
    //! Add a new group
88
    //! a parent group index has to be given to nest the new group in it
89
    virtual int addGroup( QString name, bool expand, int parentIndex ) = 0;
86 90

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