Skip to content
Permalink
Browse files

Add a row method to QgsAbstractReportSection

  • Loading branch information
nyalldawson committed Dec 30, 2017
1 parent b862db0 commit f4a99b65bbae2a86da0bd3a99e7eb3504341f215
@@ -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;
@@ -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 );
@@ -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.
@@ -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()
@@ -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()

0 comments on commit f4a99b6

Please sign in to comment.
You can’t perform that action at this time.