Skip to content

Commit f4a99b6

Browse files
committedJan 5, 2018
Add a row method to QgsAbstractReportSection
1 parent b862db0 commit f4a99b6

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed
 

‎python/core/layout/qgsabstractreportsection.sip

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ Return the number of child sections for this report section. The child
216216
sections form the body of the report section.
217217

218218
.. seealso:: :py:func:`children()`
219+
%End
220+
221+
int row() const;
222+
%Docstring
223+
Returns the row number of the section within it's parent section.
219224
%End
220225

221226
QList< QgsAbstractReportSection * > childSections() const;

‎src/core/layout/qgsabstractreportsection.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,14 @@ void QgsAbstractReportSection::setFooter( QgsLayout *footer )
319319
mFooter.reset( footer );
320320
}
321321

322+
int QgsAbstractReportSection::row() const
323+
{
324+
if ( mParent )
325+
return mParent->childSections().indexOf( const_cast<QgsAbstractReportSection *>( this ) );
326+
327+
return 0;
328+
}
329+
322330
QgsAbstractReportSection *QgsAbstractReportSection::childSection( int index )
323331
{
324332
return mChildren.value( index );

‎src/core/layout/qgsabstractreportsection.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ class CORE_EXPORT QgsAbstractReportSection : public QgsAbstractLayoutIterator
203203
*/
204204
int childCount() const { return mChildren.count(); }
205205

206+
/**
207+
* Returns the row number of the section within it's parent section.
208+
*/
209+
int row() const;
210+
206211
/**
207212
* Return all child sections for this report section. The child
208213
* sections form the body of the report section.

‎tests/src/python/test_qgsreport.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,15 @@ def testchildSections(self):
7575
self.assertEqual(r.childSections(), [child1])
7676
self.assertEqual(r.childSection(0), child1)
7777
self.assertEqual(child1.parentSection(), r)
78+
self.assertEqual(child1.row(), 0)
7879
self.assertEqual(child1.project(), p)
7980
child2 = QgsReportSectionLayout()
8081
r.appendChild(child2)
8182
self.assertEqual(r.childCount(), 2)
8283
self.assertEqual(r.childSections(), [child1, child2])
8384
self.assertEqual(r.childSection(1), child2)
8485
self.assertEqual(child2.parentSection(), r)
86+
self.assertEqual(child2.row(), 1)
8587

8688
def testInsertChild(self):
8789
p = QgsProject()
@@ -92,11 +94,14 @@ def testInsertChild(self):
9294
self.assertEqual(r.childCount(), 1)
9395
self.assertEqual(r.childSections(), [child1])
9496
self.assertEqual(child1.parentSection(), r)
97+
self.assertEqual(child1.row(), 0)
9598
child2 = QgsReportSectionLayout()
9699
r.insertChild(-1, child2)
97100
self.assertEqual(r.childCount(), 2)
98101
self.assertEqual(r.childSections(), [child2, child1])
99102
self.assertEqual(child2.parentSection(), r)
103+
self.assertEqual(child2.row(), 0)
104+
self.assertEqual(child1.row(), 1)
100105

101106
def testRemoveChild(self):
102107
p = QgsProject()

0 commit comments

Comments
 (0)
Please sign in to comment.