Sub-Report iteration
The Sub-Report feature is a repeated report generation process that iterates over a dedicated data source, whose opening role is Subreport iteration. This approach is similar to the classic sub-report model, but it supports only one level. It is particularly useful when a complex report or a multi-detail report needs to be repeated for different data records. The dedicated (master) data source is the source of the repetition: the whole report, including the report header and footer, is processed once for every record of this data source.
The Sub-Report function is a convenient way to create simple one-to-many relationship reports. Note that the other data sources must not be set as child data sources of the master data source; the report uses the sub-report data source to repeat the reports.
Sub-Report data source
To define the data source on which the iteration is based, add a data source to the report as usual and set its Opening/running role to Subreport iteration.
Reference to master data source
You can place any reference to the master data source in the SQL queries of the other data sources. For example:
SELECT product.name, product.code FROM product WHERE id=$D{master.id}
For non-SQL data sources, such as the Item Model data source, you can use the signal/slot mechanism. Use the following signal of the NCReport object to update the data of your data source:
signals:
void dataSourceUpdateRequest(const QString& dataSourceID, const QString& data);
|
All data sources except the master data source (and the data sources with the When group change role) are updated at the beginning of every sub-report cycle. This function is similar to a parent/child relation, but not the same. |
Sub-Report options
The following report options, found in on the General tab in the Working mode panel, affect sub-report iteration:
- Subreports start on new page
-
Each sub-report cycle starts on a new page.
- Subreport resets page number
-
The page numbering restarts from 1 for each sub-report cycle.
The subreport.xml and SubreportOrders.ncr demo reports show the sub-report iteration in practice.