Skip to content

Commit

Permalink
Add a row method to QgsAbstractReportSection
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 5, 2018
1 parent b862db0 commit f4a99b6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions python/core/layout/qgsabstractreportsection.sip
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ Return the number of child sections for this report section. The child
sections form the body of the report section.

.. seealso:: :py:func:`children()`
%End

int row() const;
%Docstring
Returns the row number of the section within it's parent section.
%End

QList< QgsAbstractReportSection * > childSections() const;
Expand Down
8 changes: 8 additions & 0 deletions src/core/layout/qgsabstractreportsection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,14 @@ void QgsAbstractReportSection::setFooter( QgsLayout *footer )
mFooter.reset( footer );
}

int QgsAbstractReportSection::row() const
{
if ( mParent )
return mParent->childSections().indexOf( const_cast<QgsAbstractReportSection *>( this ) );

return 0;
}

QgsAbstractReportSection *QgsAbstractReportSection::childSection( int index )
{
return mChildren.value( index );
Expand Down
5 changes: 5 additions & 0 deletions src/core/layout/qgsabstractreportsection.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ class CORE_EXPORT QgsAbstractReportSection : public QgsAbstractLayoutIterator
*/
int childCount() const { return mChildren.count(); }

/**
* Returns the row number of the section within it's parent section.
*/
int row() const;

/**
* Return all child sections for this report section. The child
* sections form the body of the report section.
Expand Down
5 changes: 5 additions & 0 deletions tests/src/python/test_qgsreport.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ def testchildSections(self):
self.assertEqual(r.childSections(), [child1])
self.assertEqual(r.childSection(0), child1)
self.assertEqual(child1.parentSection(), r)
self.assertEqual(child1.row(), 0)
self.assertEqual(child1.project(), p)
child2 = QgsReportSectionLayout()
r.appendChild(child2)
self.assertEqual(r.childCount(), 2)
self.assertEqual(r.childSections(), [child1, child2])
self.assertEqual(r.childSection(1), child2)
self.assertEqual(child2.parentSection(), r)
self.assertEqual(child2.row(), 1)

def testInsertChild(self):
p = QgsProject()
Expand All @@ -92,11 +94,14 @@ def testInsertChild(self):
self.assertEqual(r.childCount(), 1)
self.assertEqual(r.childSections(), [child1])
self.assertEqual(child1.parentSection(), r)
self.assertEqual(child1.row(), 0)
child2 = QgsReportSectionLayout()
r.insertChild(-1, child2)
self.assertEqual(r.childCount(), 2)
self.assertEqual(r.childSections(), [child2, child1])
self.assertEqual(child2.parentSection(), r)
self.assertEqual(child2.row(), 0)
self.assertEqual(child1.row(), 1)

def testRemoveChild(self):
p = QgsProject()
Expand Down

0 comments on commit f4a99b6

Please sign in to comment.