NC Report Book
NC Report Book
NC Report Book
Norbert Szabo
This work is dedicated to you, the tireless explorers of the digital realm. Your curiosity drives
innovation, your perseverance overcomes countless challenges, and your creativity brings life to
technology in ways unimaginable. Whether you are troubleshooting, coding, designing, or simply
navigating the complexities of the virtual world, your efforts shape the future of our digital
landscape.
Thank you for your resilience, your passion, and your relentless pursuit of excellence. This is for
you.
Norbert Szabo
This book is designed to be the clear, concise, normal reference to the NCReport reporting software.
This we can use as the official documentation for NCReport. We hope to answer, definitively, all the
questions you might have about all the elements, features and entities in NCReport. It is essentially
a comprehensive user documentation, definitive guide of the NCReport Reporting System. It also
contains installation instructions, tutorials and information about the contents of the distribution.
In particular, we cover the following subjects:
• The general nature of NCReport. We quickly get you up to speed on how the pieces fit together.
• How to create NCReport reports. Where should you start and what should you do?
• Understanding all of the report elements. Each element is extensively documented, including
the intended semantics and the purpose of all its attributes. An example of proper usage is
given for every element.
• How to run NCReport reports. After you’ve created one, what do you do with it?
If you want to hold this book in your hand and flip through its pages, unfortunately it is not yet
possible unless you print it for yourself. You can also get this book in electronic form, as PDF, from
our web site: https://www.ncreportsoftware.com/download
All of the examples are included on our web site. You can get the most up-to-date information about
this documentation from our web site: https://www.ncreportsoftware.com/download
Please help us improve future editions of this book by reporting any errors, inaccuracies, bugs,
misleading or confusing statements, and plain old typos that you find. An online errata list is
maintained at https://tracker.ncreport.org Email your bug reports and comments to us at
support@ncreportsoftware.com
1
In general a report generator software tool, often referred to as a report generator or reporting
tool, is a computer program or software application designed to automate the process of creating,
designing, and producing various types of reports. These reports can encompass a wide range of
data and information, such as financial statements, business intelligence reports, marketing
analytics, inventory reports, and more.
Key features and functionalities of report generator software tools typically include:
• Data Extraction: They can extract data from various sources, such as databases, spreadsheets,
and external APIs.
• Report Design: Report generators often provide tools for designing the layout and formatting of
reports, including the ability to add tables, charts, graphs, and other visual elements.
• Template Creation: Users can create report templates or use pre-designed templates to maintain
consistency in the look and feel of reports.
• Data Manipulation: These tools allow users to manipulate and transform data before it is
included in a report, which can involve calculations, filtering, sorting, and grouping.
• Automation: Report generators automate the process of report generation, saving time and
reducing the potential for human error.
• Export Options: They support various output formats, including PDF, Excel, HTML, CSV, and
more, so that users can choose the format that best suits their needs.
• Integration: Many report generators can integrate with other software applications and
databases, enabling seamless data extraction and reporting.
• Scheduling: Some report generators allow for the scheduling of report generation at specific
intervals, which is particularly useful for recurring reports.
• Collaboration: Report generators may facilitate collaboration among team members by allowing
them to work on reports simultaneously and share them with others.
Report generator software is commonly used in business environments to streamline the reporting
process and provide decision-makers with timely and accurate information. It can be particularly
valuable in industries such as finance, healthcare, marketing, and manufacturing where regular
reporting and data analysis are essential for operations and decision-making.
2
Basics
This part covers the basic steps of the NCReport usage in practice.
3
Chapter 1. About NCReport in general
1.1. A short history
NCReport’s history is more than 10 years old. The project has been started in 2002 as a joint project
of a Qt3 application and later the tool has become a unique GPL project. The reason why the system
was started to plan the urgent needs of data printing as a very missing function in Qt/C++
programming environment. In 2007 the full project has been rewritten into a new commercial
project by following the well formatted fully object oriented design concept. This version was
named 2.0 version.
1.3. Features
NCReport provides the following features and functions
• Wide range of data source types: SQL Database, Text, QAbstractItemModel, XML, any user defined
data source class
• Output formats: Preview, Printer, Postscript, PDF, SVG, Image, HTML, Text
• Items: Label (simple text), Field, HTML/Rich text, Line, Rectangle, Ellipse, Image, Barcode,
Custom content item
• Page header/footer
• Report header/footer
4
• Barcode rendering with at least 50 types of available barcodes thanks to the Zint barcode
library.
• Zones
The NCReport project represents thousands of development hours and is continuously maintained.
By integrating this reporting tool into your application, you will save a significant amount of
development time and eliminate the need to develop any printing functions for your application.
This is especially true for software written in C++ using the Qt multi-platform toolkit/library.
Additionally, NCReport is a fully portable, native C plus plus multi-platform solution.
5
1.7. Report template file
NCReport uses Extensible Markup Language (XML) format for report definition. This is a universal
standard file format, which simplifies also the human reading and processing the report definition
templates.
6
Chapter 2. Installing NCReport
2.1. Requirements
• Linux or any Unix like operation systems or ™Microsoft Windows or MacOS 10.5 or above.
NCReport is officially supported on Windows XP/Vista/10/11, on Linux >=2.6 and on MacOSX >=10.4.
It is also possible to use it on other platforms that are supported by Qt but with limited support or
without getting support from us.
• Qt4.5-Qt6.4 under Linux (Ubuntu 10.04, 12.04, 16.04, 18.04, 20.04, 22.04)
$ cd ncreport
tar xzvf ncreport2.x.x.tar.gz
$ cd ncreport/bin
NCReport binary files are intended to be used directly from the ncreport-2.x.x/bin` directory. That
is, you can start NCReport binaries by simply executing: To start the report designer:
$ ./NCReportDesigner
$ ./ncreport
7
already installed on your Linux system. In addition, you need to be compiled/installed appropriate
Qt’s database drivers. Example reports mostly use QMYSQL and QSQLITE database drivers.
Unpack the NCReport Linux source package inside any directory you want:
$ cd directory
$ tar xzvf ncreport2.x.x.tar.gz
$ cd NCReport2.x.x
$ qmake
$ make
To start NCReport binary files just do the same as it’s written in previous section.
Just simply run the setup executable file and follow the setup wizard instructions. To start
NCReport Designer use the Start menu
Make sure that the appropriate version of Qt development environment is already installed on your
Windows system. In addition, you need to be compiled/installed appropriate Qt’s database drivers.
Example reports are mostly use QMYSQL and QSQLITE database drivers.
Simply unpack the downloaded ncreport2.x.x.zip or .tar.gz or .7z source package. Use a tool like
Winzip or 7-Zip Windows has built-in support for .zip archives. To unzip the NCReport distribution
inside any directory:
mkdir ncreport
cd ncreport
unzip ncreport_2.x.x_src.zip
qmake
nmake
8
2.7. Contents of the installation directory
• /bin Contains the NCReport executable files
• /doc Contains the User Guide and API documentation in html format
• /sql Contains the sql script files are required for some of example reports
• /testdata Contains test files for demonstration purposes. defaulttestdata.xml file is used by
Designer application for storing test parametersdata. If want to use it, please copy this file to
/bin directory before starting NCReportDesigner.
• /src Contains the source codes of NCReport system. The binary package contains only the
source of demo and sample applications. The full source code is available for commercial
license holders only.
2.8. Acknowledgements
On Windows, the NCReport installer is built using Inno Setup by https://www.jrsoftware.org, Jordan
Russell’s software. We highly recommend this excellent and free-to-use tool.
9
Chapter 3. Getting started
This chapter is intended to provide a quick introduction to NCReport system. If you’re already
familiar with using the tool, you only need to skim this chapter. To work with NCReport, you need
to understand a few basic concepts of structured editing in general, and NCReport, in particular.
That’s covered here. You also need some concrete experience with the way a NCReport report
definition is structured. That’s covered in the next chapter.
Page options of the current report can be specified in Report and Page settings dialog. Open the
Report › Report and page settings In the report page settings dialog you can specify the following
options:
10
Report name
Type the name of the report. It’s just an informative option, it’s not used by report generator.
Report type
There are two type of reports available. Report represents a normal report, Text document is a
limited report mode. In this mode the report can contain HTML text items only. The generated
report will be a paginated html document.
File encoding
The encoding of the XML file. When user opens or saves the report definition file, this will be the
default encoding. In most cases UTF-8 fulfils the requirements, but for special international
characters you can choose any specified encoding.
Default font
The font name and size are basically used for the text labels and fields in the whole report. Unique
object settings may overwrite this option.
Page size
The size of the page. The size names are listed in the combobox and their names are the standard
size names. Currently the standard page sizes are supported.
Background color
The check boxes can be used to enable or disable page header/footer and report header/footer. To
alter the height of theese sections you may use spin boxes corresponding to their check boxes. You
can also change these height properties by mouse dragging or by geometry editor
Margins
margin properties represent the top, bottom, left and right margins of the page in millimeters. To
alter the margin values just use the spin boxes.
Orientation
This radio button option represents the orientation of the page, Portrait or Landscape orientation
can be selected.
Specify the page’s properties by this example and click [ OK ] button for saving data source settings.
We add the report’s name only, other default properties we don’t change.
11
Page settings dialog
First, you see an empty new report that contains a page header, a detail and a page footer sections
by default. Before starting to add report items we define the data source that represents a definition
where the data will come from. In our example the data source is a Text. To specify a data source in
your report open the Report menu and select Report › Data sources… menu item. Then appears a
dialog on you can add and or remove data sources. To add a new data source click the [ Add ]
button in dialog and then select the QStringList data source type from the list of available data
source types. [ Create ] button
12
Data source ID
Location type
Location type is a property that describes where the data can be found. In this report we will use
static Text which is a statically pasted text. The text will be saved into the report.
Specify the data source properties by this example and click btn::[OK] to save the data source
settings.
To assign the data source we defined before, open the Report › Report menu and select Report ›
Details and grouping… menu item, then appears a dialog on you may manage the detail sections
of the report. A default detail ID is Detail1, you may change it to whatever you want. Select the
previously defined data source from Report › data source combo box.
13
Click [ OK ] button to apply detail settings.
To try or test our report from Designer application we need some test data. This step is not
necessary if you test the report from your application. Test data editor in designer makes easier the
designing, debugging and testing of reports. In our example we create a simple product list
included the following columns:
• category as 0. column
• active as 3. column
• weight as 4. column
• price as 5. column
To open the test data editor form open the Report › Test data editor… menu item, then appears a
14
dialog on you can edit and setup test data. There are three types of data source are available to use
for testing. We need test data as QStringList, so we have to check the Store as QStringList check
box and specify the ID.
Click [ OK ] button to apply detail settings. The checked types with their corresponding ID will effect
the desiger to add the test data to report test runner as a specified by ID data before running the
report.
Geometry editor is a small property tool window in designer for showing or editing the position
and size of objects in focus. To enable/disableGeometry editor just use Report › View menu and
enable/disable Report › Geometry editor menu item. Then the tool window will appear in the
right side. The current objects or sections are always activated by a mouse click. You can type the
numeric size or position values into the spin boxes. Any changes made to the object’s properties
cause it to be updated immediately.
Page headers is used to contain page headings. First, we will add column titles as labels to page
header section. Labels are simple texts. Label items are used to display descriptive information on a
report, such as titles, headings, etc. Labels are static items, their value never change.
Select the Label tool button or menu item in Tools menu. After that the cursor changes to a cross
beam, then click in the page header of the report definition where you want the Label to be located.
Doing so will create the Label object in that section and opens the Label settings dialog.
15
Add labels to page header for column titles and move them to positions by example. Then select
"Weight" and "Price" (multiple selecting is available) and align them right by clicking [ Right
alignment ] tool button.
Increase the height of page header section by dragging the resizer bar at the bottom of the section.
Another way for resizing to type Section height value in Geometry editor.
To underline the labels, let’s draw a Line by selecting the Line button in the tool bar or menu item
in Tools menu. After that the cursor changes to a cross beam, then click in the section of the report
definition where you want the line to be started and simply drag the line to the end position. (To
move the line just drag and drop by left mouse button.)
16
3.2.10. Designing Detail section
The core information in a report is displayed in its Detail section. This section is the most important
section of the report since it contains the row by row data from the data source.
Select the Field tool button or menu item in Tools menu. After that the cursor changes to a cross
beam, then click in the detail section where you want the Field to be located. Doing so will create
the Field object in that section and opens the Field settings dialog. The following properties must be
specified:
The combo box contains the possible sources from where the field can pull data.
Field column/expression
This property represents the name of the data column from where field’s value is loaded from. To
identifying data columns specify:
The field’s base data type. The following data types are supported: Text,Numeric,Date,Boolean
17
Add Fields to Detail and move them to positions by example. Field column names are: col0, col1,
col2, col3, col4, col5 (alternative naming: 0, 1, 2, 3, 4, 5) Select col4 and col5 field item and
align them right by clicking [ Right alignment ] tool button. After, in the field’s dialog set Data type
to Numeric and use the Numeric tab page to set number formatting properties.
18
Resize the detail section to 4.5 mm height. After also a title label added to the page header section
and formatted, the report should look like this:
Page footer is usually used to display informations such as number of the page. In our example we
only add two system variable fields: Application info and the current page number.
Select the Field tool button or menu item in Tools menu. After that the cursor changes to a cross
19
beam, then click in the detail section where you want the Field to be located. Doing so will create
the Field object in that section and opens the Field settings dialog.
Add again a new field to page footer and specify the field’s properties by this, similar to the
previous: Field source type: System variable Field column expression: appinfo
Derease the height of page footer section by dragging the resizer bar at the bottom of the section.
Another way for resizing to type Section height value in Geometry editor. After setting the
alignments and moved fields to the right positions, the report should look like this:
20
3.3. Testing report in Designer
Our sample report now is ready for testing. To run report from designer there are at least two
ways: Select Report › Report/Run report… menu and after the report runner dialog appears you
can choose the report’s output. To start running report just click [ OK ] button.
For fast preview just select Report › Report/Run report to preview… menu and then the Designer
will run report to print preview immediately. In this state the preview of our example report
appears like this:
21
3.4. Variables and Groups
The following section describes how to use some advanced feature of NCReport. We will define a
group and after we will add summary variables to our example report.
Variables are special numeric items used for providing counts and totals. Each of them have name,
function type, data type, and have an assigned data source column the variable based on. To add a
variable open the Report › Report menu and select Report › Variables… menu item. Then appears
a dialog on you can manage variables.
Variable ID
Variable expression
Function type
The function type of the variable. Supported function types: Sum, Count
Reset scope
Specifies the scope after report engine resets the variable. Group level resets also must be set by
group settings dialog.
22
Initial value
Let’s create a var0 which will summarize col4 column. (weight) It provides variable to summarize
col4 values in 'Group' Reset scope. Specify the field’s properties by this example:
Reports often require summary data by band. In our example we will add weight summary by
product category to report. First, open the Report › Report menu and select Report › Details and
grouping… menu item, then appears a dialog on you may manage the detail sections and groups of
the detail. Select "Detail1" detail and click the [ Data grouping… ] button, then the Group settings
dialog will appear. The following properties are available for a group:
Group ID
Group expression
The name of the data source column the group is based on. Group expression can be data source
column or any data expression or constant. Let’s set a constant group expression: %CONST Constant
groups have only one group header and footer.
To enable or disable group header and footer, check on or off the specified check box. To set initial
23
height of these sections you can use spin boxes near the check boxes.
Reset variables
This list contains the 'Group' scope variables. You can specify which variable the report generator
has to reset when a group level run out.
We want the grouping to be based on col0 column (product category column). Specify the field’s
properties by this example:
To apply settings click [ OK ] button on Group dialog and then click [ OK ] button on Detail dialog.
After doing so group header and footer of the detail will appear.
24
3.4.3. Adding summary field to group footer
To add a Field based on var0 variable just add again a new field to group footer and specify the
field’s properties by example:
25
After adding variable field and some labels and a line to group header and footer our report should
look like this:
Now we are ready! For preview testing just select again Report › Report/Run report to preview…
menu and then the Designer will run our report to print preview. In this state the preview of our
example report appears like this:
Congratulations! We have created a simple one level group report. In the next step we will describe
how to run this report from your application.
26
3.5. Integrating NCReport into a Qt application
3.5.1. Adding NCReport library to an application
In order to using NCReport from your application, first you have to integrate NCReport into your
application project using the NCReport API classes. There are at least two ways to do this:
• Adding the whole sources statically to your project and build it together with your application.
In this case you don’t need NCReport shared libraries. Doing so open your .pro project file and
add the full source package to the project as testapp/testapp.pro does.
• Using NCReport engine as shared library. For using NCReport library like other libraries in your
project you need to specify them in your project file. The following project example shows the
necessary settings:
TARGET = MyApplication
INCLUDEPATH = ../ncreport/includes
HEADERS += ...
SOURCES += ...
win32 {
LIBS += ../lib/ncreport2.lib
}
unix {
LIBS += -lncreport -L../lib -L/usr/local/bin
target.path = /usr/local/bin
}
For more information see the Qt documentation in qmake manual at chapter Declaring Other
Libraries.
This step shows you how to initialize NCReport class. Includes. First we have to add includes. To
include the definitions of the module’s classes, use the following includes:
27
#include "ncreport.h"
#include "ncreportoutput.h"
#include "ncreportpreviewoutput.h"
#include "ncreportpreviewwindow.h"
Creating NCReport class. We create the report class just like as another QObject based class:
If NCReport object has been created earlier and passed as a parameter, you should inititalize the
report by calling reset() method:
report->reset();
//or
report->reset(true);
NCReport::reset() function will delete all object references, and makes report engine able to run a
report again. If parameter is set TRUE, also report parameters, added data sources such as
QStringLists, custom items will be deleted.
Report source means the way of NCReport handles XML report definitions. Report definitions may
opened from a file - in most cases it is suitable, but also it can be loaded from an SQL database’s
table. In our example we apply File as report source:
report->setReportFile( fileName );
report->setReportSource( NCReportSource::File );
report->reportSource()->setFileName( fileName );
Adding parameters To add a parameter to NCReport use addParameter method. The parameter ID
is a string, the value is a QVariant object.
28
3.5.4. Running the Report
Now we are ready to run the Report to different outputs. Doing so just use one of runReportTo…
functions. Running report to printer
report->runReportToPrinter();
QString fileName("mypdffile.pdf");
report->runReportToPDF( fileName );
report->runReportToPreview();
If you run report to preview, result will be stored in an NCReportPreviewOutput object. Report
engine does not run the preview form automatically. After the report engine successfully done we
need to initialize an NCReportPreviewWindow object for previewing. Before doing so we check if a
report error occurred.
if ( !report->hasError() ) {
NCReportPreviewWindow *pv = new NCReportPreviewWindow();
pv->setOutput( (NCReportPreviewOutput*)report->output() );
pv->setWindowModality( Qt::ApplicationModal );
pv->setAttribute( Qt::WA_DeleteOnClose );
pv->show();
} else {
QMessageBox::warning( tr("Error");
}
When you run report to preview the report output object won’t be deleted by
NCReport. When the NCReportPreviewWindow object is destroyed, output is deleted
automatically by it’s destructor.
29
Deleting Report object After report running action you may delete the report object. When
NCReport object is deleted all child objects are also deleted.
delete report;
Don’t delete NCReport object if NCReportPreviewWindow object still exists. If you want
to use report object again without deleting just use NCReport::reset() function.
30
Chapter 4. Report Items
The report items are the element objects we can put to the report sections. Our report content is
built from using these elements We have the following item types:
• Data Field
• Line
• Rectangle
• Ellipse / Circle
• Image
• Barcode
• Cross Table
To change the text font format and attributes in the Designer select one or more static text item and
use the text formatting toolbars to change settings.
31
4.4. Line
Graphical line that has a start point and an end point. The line characteristics are configurable, you
can change the line type and width and the color. Lines are static objects.
4.5. Rectangle
Graphical rectangle that has a 4 corner points, specified by height and width. The rectangle
characteristics are configurable, you can change the line type and width and the color. Rectangles
can be transparent or filled. Rectangles are basically static objects, but with the Dynamic Position
feature the height and the width can be managed dynamically using a data expression
4.6. Ellipse
Graphical ellipse that is specified by height and width. The ellipse characteristics are configurable,
you can change the line type and width and the color. Ellipses can be transparent or filled. Ellipses
are basically static objects, but with the Dynamic Position feature the height and the width can be
managed dynamically using a data expression.
4.7. Image
Image file or embedded image content with PNG, JPEG, BMP, SVG supported formats. You can assign
a direct link to a file or use a static, in-report stored image. The image is specified by height and
width, many characteristics are configurable: Alignment, Aspect ratio, Transformation mode. There
can be dynamic and static images in reports so the image element is very flexible.
4.8. Barcode
NCReport provides the barcode rendering with almost all symbology features thanks to the Zint
back-end 3rd party library. Barcode item can render a barcode from static or dynamic source.
32
4.11. Custom Graphics Content
Graph/Custom item is a special member of NCReport items. This option enables you to render a
QPainter drawn contents in reports using C++/Qt code. The typical field of application is using this
feature for rendering graphs or similar user defined content
33
Chapter 5. Parameters
Parameters are data obtained from outside of the report generator. The application that calls the
NCReport object passes information as parameters to the NCReport class using the
NCReport::addParameter(…) method. Parameters get evaluated within SQL queries and script
expressions. Field objects can also have a parameter data source type, so they can be presented as
data in the report. Parameters are mostly used in SQL queries and data/script expressions.
$P{parameterID}
"$P{firstname}" + "$P{lastname}"
Add a Parameter with the ID/name prodID to NCReport. NCReport Designer has a test runner dialog
with a parameter adding feature. To open the runner dialog, select the Run report… menu item
from the Report menu. Click the Add button and specify the name as prodID and the value to 70.
After running the report to Preview, we get the following result:
34
In all reports, Parameters are always evaluated within SQL queries, scripts, and PrintWhen
expressions.
35
Designer
The NCReport Designer is a standalone GUI application to create and modify report templates. This
part makes possible to learn how to use the designer, how to design a report.
36
Chapter 6. Getting Started with NCReport
Designer
This chapter covers the fundamental steps that most users will take when creating reports with
NCReport Designer. We will introduce the main features of the tool by creating a simple report that
we can use with NCReport engine.
• On Windows, click the Start button, open the Programs submenu, open the NCReport2
submenu, and click NCReport Designer.
• On Unix or Linux, you may find a NCReport Designer icon on the desktop background or in the
desktop start menu under the NCReport submenu. You can launch Designer from this icon.
Alternatively, you can enter ./NCReportDesigner in a terminal window in NCReport/bin directory
37
6.3. NCReport Designer Main Window
The menu bar provides all the standard actions for opening and saving report files, managing
report sections, using the clipboard, and so on. The tool bar displays common actions that are used
when editing a report. These are also available via the main menu. File menu provides the file
operation actions, Report menu contains the report and it’s sections settings that belong to the
current/active report. View menu displays the specified items can be enabled or disabled in MDI
area. The Tool menu provides common report objects that are used to build a report. The Align
menu holds the alignment actions for the specified report items can be aligned. With the Window
menu you can manage the windows are opened concurrently.
Most features of NCReport Designer are accessible via the menu bar or the tool bar. Some features
are also available through context menus that can be opened over the report sections. On most
platforms, the right mouse button is used to open context menus.
38
6.5. Data Source Tree
Data Source Tree (or data source manager) is a dock window widget in the main designer desktop.
The widget helps to add fields to the report very easily by a simple drag and drop action. The data
source tree is updated when you add or modify a data source in the report. Therefore it is
recommended to start the report building with defining the data source first. If the data columns
are available at design time they will appear in the widget under the appropriate data source item.
To add a field to any report section just drag the selected column and drop onto the section at the
position whatever you want. The Field item will be created at the drop position. Note that mouse
pointer target position is considered.
39
6.6. Field Expression Builder
When you work with Field items you get a useful helper tool for creating the correct Field
expression. You find the Expression builder button in the Filed settings dialog labeled Build
Expression… and besides the Print When logical expression editor controls. You can choose the
combo boxes to select the desired expression and you can add it by simple clicking on the small add
buttons. Then the expression will be inserted into the text area at the cursor position. Depending on
what type of expression you insert the expression builder will apply the correct syntax. You have
also the data source tree in the dialog that can be used for the same purpose if you just simply
select a Data Source column, a Parameter or a Variable. Double clicking on the appropriate item
will insert it from the data source tree.
The following description helps to understand what combo box widgets are found on the dialog and
what they are good for.
Data source
Selects the data source from all available data sources of the report. To add a data source click
on the add item beside the widget.
Column
Selects the data source column. To add a data column click on the add item beside the widget.
Variable
You can select here all available variables including the system variables. To add a variable click
on the add item beside the widget.
Value function
You can select the available data source value functions here. To add a function expression click
on the add item beside the widget.
Parameter
You can select the design time defined parameters here. To add a parameter click on the add
item beside the widget.
You find also logical operation buttons on the dialog that boosts editing of a script or a logical
expression. When you click on a button it will insert the named logical operation into the text area.
40
6.6.3. Expression Builder Dialog
• Composing the user interface by adding report objects to the report sections.
Users may find that they prefer to perform these activities in a different order, However, we
present each of the activities in the above order, and leave it up to the user to find the approach
that suits them best. To demonstrate the processes used to create a new report, we will take a look
at the steps needed to create a simple report with NCReport Designer. We use a report that engages
SQL database data source to illustrate certain features of the tool.
41
6.8. Connecting to database from Designer
NCReport Designer now enables you to test the report from inside the designer. Since this report
requires internal MySQL database connection, first we should connect to "northwind" database.
SQL database connections can be managed by the Connection manager within the designer
application. Open the Report menu and then select SQL connection manager… After the
Connection manager dialog will appear. By this dialog you can add one or more SQL connections.
• Connection name The name of the database connection. Qt uses this name in addDatabase(…)
function. For identifying the corresponding connection this value have to be specified.
• Port Connection’s port number. If empty, the default port is used in connection.
42
• OK Select to save your connection settings.
• Cancel Closes the dialog without saving any changes, returning you to the desktop.
After you specified connection parameters to the added connection use the Connect button to
establish connection. If the connection is succeeded then your report is ready to run. Before
running the report we rename our connection to northwind and then also our data source’s
connection name must be renamed to northwind. Doing so just open again the data sources…
dialog and then rename the connection ID to northwind too
You don’t need any SQL connection if you use non SQL data source in your report,
for example Text, Stringlist or other data source
43
important section is called Detail since details can contain the fields are changed row by row. Each
sections can contain all kinds of report items. Item’s coordinates are always relative to their parent
section. One report can contain the following sections: Report header, report footer, page headers,
page footers, group headers and footers and details
To change the height of a section just drag the bottom resizer bar under the section area and resize
to the size you want or type the height value in millimeter at Geometry editor’s spinbox if that is
enabled. To activate the current section just click onto the empty area of a section
6.10.1. Detail
The core information in a report is displayed in its Detail section. This section is the most important
section of the report since it contains the row by row data from the data source. Detail section have
the following characteristics:
• Multiple independent details are allowed in one report, each detail after the other
Page headers is used to contain page headings. Page headers have the following characteristics:
In most cases you need page header in reports. To add or remove page header select Report/Page
options… menu, then appears a dialog on you can set the page options of the current report. To
enable or disable page header just use Page header check box.
Page Footer are commonly used to close the pages. Page footers have the following characteristics:
Page footer is usually used to display informations such as number of the page, report titles and so
on. In most cases you need page footer in reports. To enable or disable page footer just use Page
footer check box in Report/Page options… menu.
44
6.10.4. Report header
Report header is a section used to contain report headings. Report header has the following
characteristics: * Always printed after the page header * Report header is printed only once at the
begining of the report * Displays only one (current) row of data returned by a data source
To enable or disable report header use Report header check box in Page options dialog can be
activated by opening Report menu and selecting Page Options…
Report footer is a section commonly used to close the report. Report footer has the following
characteristics:
• Always printed before the page footer at the end of the report
To enable or disable report footer use Report foter check box in Page options dialog can be
activated by opening Report menu and selecting Page Options…
• Report name Type the name of the report. It’s just an informative option, it’s not used by report
generator.
• File encoding The encoding of the XML file. When user opens or saves the report definition file,
this will be the default encoding. In most cases UTF-8 encoding suit the requirements, but for
special international characters you may choose the specified encoding.
• Page size The size of the page. The size names are listed in the combobox and their names are
the standard size names. Currently the standard page sizes are supported.
• Default font The font name and size are basically used for the text labels and fields in the whole
report. Each object may change this option.
• Background color The background color of the report. This option currently is not used.
• Header and footer settings The check boxes can be used to enable or disable page
header/footer and report header/footer. To alter the height of theese sections you may use spin
boxes corresponding to their check boxes. You can also change these height properties by
mouse dragging or by geometry editor
• Margins margin properties represent the top, bottom, left and right margins of the page in
millimeters. To alter the margin values just use the spin boxes.
• Orientation This radio button option represents the orientation of the page, Portrait or
Landscape orientation can be selected
45
The following buttons are available for apply or cancel settings:
• Cancel Closes the screen without saving any changes, returning you to the designer desktop.
Specify the report page properties by using Page options dialog and validate the settings by clicking
the OK button.
To specify a data source to your report open the Report menu and select Data sources… menu
item. Then appears a dialog on you can add and remove data sources. To add a new data source
click the Add button and then select the data source type from the list of available data soure types.
46
In our example we choose SQL query data source type. After you click OK button a new SQL query
data source will be added to the list in dialog panel. Then you can specify the data source options.
The following properties are available for data sources:
• data source ID. This string property is very important for identification purposes. You can refer
to the data source by this ID string.
• data source type The type of the data source you’ve chosen before. It is cannot be changed after
the data source added to the list
• Location type Location type is a property that describes where the data or the sql query can be
found, inside the report file or inside an external file. It’s value may be: Static, File, HTTP, FTP,
Parameter. HTTP and FTP type currently is not supported for SQL queries. For the different type
of data sources it means a bit different. For SQL query the Static location type is suitable, it
means that SQL query will be saved statically into the report file. Parameter type provides that
the data is added to NCReport by NCReportParamer. For example a QString Text or an SQL
query can be added as parameter to NCReport depending on the data source type.
• File name/URL In case non Static location type is selected, here you can specify the name of the
file that contains data. (URL address currently is not supported.)
• Connection ID This string property represents the ID of an SQL database connection. This name
just the same ID that is used in QSqlDatabase::addDatabase() function for identifying database
connection. When you add database connection in your application before running report, this
connection name you should specify.
• Use external connection If you want to make available the SQL data source to use it’s own
database connection, you may enable this checkbox. After, the external connection panel
becomes enabled and you can specify the required properties of sql connection: hostname,
database, username, password, port (optional).
• SQL query This text area in which you can edit the sql query expression. Almost every cases it is
a SELECT…FROM expression applying the SQL syntax of the specified database. Only one sql query
is allowed for the data source. SQL expression can contain Parameters, see later.
47
In our example we set the data source ID to data source1 (the default name) and choose Static
location type. We name the Connection ID Con0. After the SQL query must be specified.
This example requires a running MySQL database server with existing northwind
demo database and tables. For generating sample database and tables SQL script
file is attached with NCReport project
The following buttons are available for apply or cancel settings: * OK Select to apply your data
source settings. * Cancel Closes the screen without saving any changes, returning you to the
designer desktop.
Validate the data source settings by clicking the OK button. === Assigning data source to the Detail
To assign the data source we defined before, open the Report menu and select Details and
grouping… menu item, then appears a dialog on you may manage the detail sections of the report.
A default Detail1 named detail is already defined. You can rename it to the name you want if you
change Detail ID. Select the previously defined data source from data source combo box. The combo
48
box contains all of defined data sources. This option must be specified for working of the report.
Here we summarize the options of Detail dialog: - Detail ID The name of the detail section. - Height
Height of the detail section in millimeters. To alter the height of theese sections you may use this
spin box. You can also change the height by mouse dragging or by geometry editor - data source
data source name assigned to the detail. Previously defined data sources can be selected in the
combo box - Data grouping By clicking this button the group management dialog of the
corresponding detail can be opened.
You can add more details by Add button or remove existing detail by Remove button. One detail
section must be existed, so it does not construe to remove the only one detail.
• Cancel Closes the screen without saving any changes, returning you to the designer desktop.
Text label
The Label represents simple text or label items. Label items are used to display descriptive
information on a report definition, such as titles, headings, etc. Labels are static item, it’s values
49
don’t change when rendering the report.
Field
The Field is the matter of report items. It represents the data Field objects. By data type Fields
may be text, numeric and date. Field items are used for pulling dynamically generated data into
a report from the specified data source such as database the report generator uses. For example,
a Field item may be used to present SQL data, variables and parameters. NCReport handles data
formatting for the different type of fields like numbers or texts.
Line
The Line option enables you to create Line items. In general, Line items are used for drawing
vertical, horizontal lines for headings, underlining titles or so on. Lines are defined by it’s start
and the end point coordinates
Rectangle
The Rectangle enables you to create Rectangle items. Rectangles are usually used for drawing
boxes or borders around a specified area. Rectangle makes easier the box drawings instead of
drawing four lines.
Ellipse
The Ellipse item enables you to create circle or ellipse in report. Ellipses are mostly used for
drawing charts or borders around a text.
Image
The Image option enables you to create Image items. Image items are used to insert either static
or dynamic into a report definition. Static images such as a company logo often displayed in the
Report Header can be loaded from a static file or from report definition. Dynamic images can be
loaded from the specified SQL data source.
Barcode
The Barcode option enables you to create barcodes. Currently the EAN13 code format is
supported. Barcodes might be either static or dynamic items similar to images. Static barcodes
read it’s value from the report definition, dynamic barcodes are loaded from the specified data
source.
First let’s add the labels that represent the column header of data rows. To create a new Label
object, first select the Label tool button or menu item in Tools menu. After that the cursor changes
to a cross beam, then click in the section of the report definition where you want the Label to be
located. (i.e. we add label to the report header.) Doing so will create the Label object in that section
and opens the Object settings dialog. On the dialog you may then set the Label object’s properties.
50
The following options are available for labels:
• Automatic word wrapping If this check box is enabled the text will be wrapped fitting to it’s size.
• Print when expression This is a logical expression which enables you to define when the Label
object is shown or not. See the details later.
The following buttons are available for apply or cancel settings: * OK Select to apply your label
settings. * Cancel Closes the screen without saving any changes, returning you to the designer
desktop.
Add the following labels to the Page Header: Product ID, Product name, Unit Qty, Unit price, Value
and move them by drag and drop to the place you want to be located. To move the added Label just
drag (select) it with left mouse button and drop it to the location you want. To delete a Label, select
it and press Delete button
51
6.13.4. Adding Line
To create a new Line object select the Line button in the tool bar or menu item in Tools menu. After
that the cursor changes to a cross beam, then click in the section of the report definition where you
want the line to be started and simply drag the line to the end position. To move the added line just
drag (select) it with left mouse button and drop it to the location you want. To delete the line just
select it and press Delete button
To open the line properties dialog just double click on the line, on the dialog you may then set the
object’s properties. In the dialog you are presented with the following options are available:
Now we have to add the most important items to the report. Field objects contain dynamic
information retrieved from a data source, parameter or a variable. To create a new Field object,
first select the Field tool button or the menu item in Tools menu. After that the cursor changes to a
cross beam, then click in the section onto you want the Field to be located. This section is in
generally the Detail section. Doing so will create the Field object in the specified section at that
position and opens the Field property dialog. On the dialog you may then set the Field’s properties.
Field column/expression
This property represents the name of the data column from where field’s value are pulled.
When SQL query data source is used by the field, this name equals the corresponding SQL
column name included in SQL query. When other data sources such as Text, this value is often
the number of the data column.
52
Data type
The field’s base data type. The following data types are supported: Text, Numeric, Date, Boolean
QString::arg() expression
This is a string expression with %1 symbol for the same purpose what ::QString("String
%1").arg(value):: code does. The field’s value will be embedded into this expression.
Call function
This feature currently is unavailable.
53
The following table summarizes the various formulas you can specify in fields as field column
expression. The formula depends on what field source type you use.
54
Parameter parameterName The name/ID of the parameter
Some properties are available for different data types only. They are located on separated tab
widgets within the dialog. The following additive options are available for numeric fields:
Number formating
If this option is checked, the number formating will be turned on
Decimal precision
The number of digits after the decimal point.
Field width
Width of number in digits. Specifies the minimum amount of space that a is padded to and
filled with the character fillChar. A positive value will produce right-aligned text, whereas a
negative value will produce left-aligned text.
Format character
This one digit option specifies the format code for numbers. Possibly values are: e,E,f. With e,
E and f, precision is the number of digits after the decimal point. With 'g' and 'G', precision is
the maximum number of significant digits. Used by ::QString::arg( double a, int fieldWidth =
0, char format = 'g', int precision = -1, const QChar fillChar):: function.
55
Fill character
specifies the character the numeric value is filled with when formating. See QString::arg()
fillChar parameter.
• Cancel Closes the screen without saving any changes, returning you to the designer desktop.
To continue our instance report, add the following (four) fields to the detail section. Use the
following names and data types in field column expression: ProductID (Numeric), ProductName
(Text), QuantityPerUnit (Numeric), UnitPrice (Numeric), Value (Numeric)
56
6.13.10. Adding Variables for totals
Before we add variable field to the report, let’s see the handling of variables in NCReport. Variables
are special items used for providing counts and totals. Each of the variables have name, function
type, data type, and have an assigned data source column the variable based on. To add a variable
open the Report menu and select Variables… menu item. Then appears a dialog on you can
manage variables.
• Variable expression This property represents the name of the data column from where
variable’s value is pulled from.
• Function type The function type of the variable. Supported function types: Sum, Count Count:
The COUNT type of variable will increment by 1 for every detail row. Sum: The SUM (summary)
variable will summarize the value of the specified data column returned by the field
• Reset scope If this check box is enabled the field will be wrapped fitting to it’s size.
The variables added to report are shown in the variable list view. Clicking on the list items the
selected item becomes active. To delete the selected item just select the Remove button. The
following buttons are available in the dialog:
57
Add
Adds a new variable and enable the variable options to edit.
Remove
Deletes the variable selected from the list
• Cancel Closes the dialog without saving any changes, returning you to the designer desktop.
Add a new variable by clicking the Add button and then specify the options by followings: Variable
ID: total_value, Variable expression: value, Function type: SUM, Reset scope: Group To add total
first, we should add a new group to the detail. In the next section we explain how to use the
grouping feature. ==== Adding group to detail While most reports can be defined using a single
Detail section having multiple columns and rows of data, others - just like our example report -
require summary data, totals as subtotals. For reports requiring summary data, NCReport supports
Group sections. Group sections have the following characteristics:
• Reference database column on which Group Headers and Group Footers will break
• Force new Group Header each time the value of the referenced column changes
• Force a new Group Footer each time the value of the referenced column changes
In the group dialog the groups added to the report are shown in the order you have added. The
added group sections will appear in the designer after you applied the group settings. Groups are
structured hierarchically. The first group will be the primary level of group, the second one is the
second level and so on.
To add a new group to the detail, open the Report menu and select Details and grouping…. Then
the Detail settings dialog will appear. Select the Detail1 detail in the list, then to open the grouping
dialog click on Data grouping… button. The Group settings dialog appeared, always belongs to the
previously selected detail. To add a new group click on the Add button.
• Group expression The name of the data source column the group is based on. If the value of this
referenced column changes, the group breaks. Also constant values such as 0 or 1 can be used
as group expression. Then the group will never break just ends. This could be very useful for
end-total fields.
• Header and Footer To enable or disable group header and footer, check on or off the specified
check box. To set initial height of these sections you can use spin boxes near the check boxes.
58
• Reset variables This list contains the variable names are available to reset when the group
ends. The variables that have Report reset scope status are visible only in the list.
The groups added to a detail appear in the group list. Clicking on the list items the selected item
becomes active. To delete the selected group just select the Remove button. The following buttons
are available in the dialog:
• Cancel Closes the dialog without saving any changes, returning you to the Detail settings dialog.
So, let’s add a new group with the following specification: Group ID: Group0, Group expression: 0,
Show group header and footer, Reset total_value variable. After you select OK button, the new
group sections (header and footer) will appear in report document. Close the Detail settings dialog
by clickink OK button.
59
Field source type
Variable, Field column: total_value, Data type: Numeric
Now we have got almost all of fields we need. What we have to do also is just adding some missing
lines, labels and adjusting the report.
• Add a Total value: Label to the report footer section near the total field.
• Add a Line to the Page footer similar to the line in the Page header
• Add a Field to the Page footer: Field source type: System variable, Field column: pageno, Data
type: Numeric, QString::arg() expression: Page: %1
• Adjust the height of the sections for the fitting size by mouse dragging the base line of section or
by geometry editor. The height of the detail is important, since it is often recurred many times.
• Select the labels in Page header and set the font weight to bold by clicking the Bold tool button
in tool bar. Item multi-selection may used.
• Select ProductID field in Detail section and set its font weight to bold.
• Select and align right all of numeric fields to right by clicking the Align right tool button in tool
bar.
• Set the number format options for numeric fields: Number formatting: on, Decimal precision: 2
• Set also Use localized settings on for value and total_value fields
Save the report. Now you should get something similar this:
60
6.18. Adding Variables for Totals
Before we add variable field to the report, let’s see the handling of variables in NCReport. Variables
are special items used for providing counts and totals. Each of the variables have name, function
type, data type, and have an assigned data source column the variable based on. To add a variable
open the Report menu and select Variables… menu item. Then appears a dialog on you can
manage variables.
Variable ID
The name/ID of the variable.
Variable expression
This property represents the name of the data column from where variable’s value is pulled
from.
Function type
The function type of the variable. Supported function types: Sum, Count
Aggregate functions:
Count
The COUNT type of variable will increment by 1 for every detail row.
Sum
The SUM (summary) variable will summarize the value of the specified data column returned by
the field Reset scope` If this check box is enabled the field will be wrapped fitting to it’s size.
Initial value` Initial value of the Variable
61
6.18.1. Variable dialog
The variables added to report are shown in the variable list view. Clicking on the list items the
selected item becomes active. To delete the selected item just select the Remove button. The
following buttons are available in the dialog:
Add Adds a new variable and enable the variable options to edit. Remove: Deletes the variable
selected from the list
• Cancel Closes the dialog without saving any changes, returning you to the designer desktop.
Add a new variable by clicking the Add button and then specify the options by followings: Variable
ID: total_value, Variable expression: value, Function type: SUM, Reset scope: Group
To add total first, we should add a new group to the detail. In the next section we explain how to
use the grouping feature.
62
Running the report to Preview window now you should see something similar:
63
64
Advanced Features
To create more complex, professional reports, we need additional features and functions. This
section describes these important advanced functions of the NCReport reporting system.
65
Chapter 7. Data/Script Expressions
NCReport since 2.0 version can handle data or script expressions using Qt Script module the new
powerful feature of Qt>=4.3. Qt Script is based on the ECMAScript scripting language, as defined in
standard ECMA-262. Fields can even contain script codes instead of a simple data source column,
parameter or variable. In this case the report engine evaluates the specified script code each time
when the fields are refreshed. Report items can also have Print only when expression is true
(short name: printWhen) property. Print when expressions are script expressions too but they
must always return boolean result. To use script expression in fields you have to set Expression
field source type in the Field property dialog
In Qt6 version the Qt Script module is no longer available. Instead, the QJSScript
can be used, so the report script expressions are going to be based on QJSScript
(Qt’s Javascript Engine). The Javascript grammar is a little bit different than Qt
Script grammar. You may need to upgrade some script expressions in your report
if you migrate to Qt6
Syntax Description
If an expression contains any inserted reference with string/text type, quote marks
are needed at the beginning and the end of the token. For example:
"$D{ds.lastname}"=="Smith" You don’t need quote marks for numeric or boolean
values, for example $D{price}==750.0 is correct formula
66
7.2. References in templates
Template is a text in which you can simply embed any data reference without using script
formulas. Templates can be used in fields as a source type or in rich texts if template mode is on.
Example of using script expression as "Print only when expression is true" property. The
expression must return logical value.
$D{productPrice}<1500
67
In this case the report engine first replaces the references in the code and then evaluates the script
code before each rendering action. Close the dialog by clicking OK button and then save the report.
Now we just run report to preview window. Let’s see the result:
This example is spectacular but not the most effective way of using expressions. In most cases when
you use expressions in fields you don’t need too complex code. If you need a condition by your field
should be visible or not, we recommend to use "Print only when expression is true" feature
instead. We test this feature in the next section.
Examples:
Hide an item when DataSource1.intcolumn data source value is less than 10:
68
$D{DataSource1.intcolumn}>=10
$D{DataSource1.boolcolumn}
"$D{DataSource1.stringcolumn}">""
$D{ProductID}>40
"Product: "+"$D{ProductName}"
After you validate the settings and save the report run the report again. We have to get the same
result.
69
evaluation but a simple insertion only.
If you want to use a direct script as group expression you can write a script expression between <%
%> markers. Having a single line property it’s not recommended to build too complex expression
here. Example:
You don’t need the markers if you assign to a pre-defined script expression:
$S{myscript}
The HTML text item has many flexible feature in terms of scripting. You can embed data references
or expressions if template mode is turned on. When you want to include a script expression within
a text you need to use the <% %> markers. Within the markers you can write a script, the result of
the script will be inserted into the text at the script location.
DataSourceId.function()
In scripts or templates:
$D{DataSourceId.function()}
70
rowCount()
Returns the number of rows of the data source.
Example:
products.rowCount() or $D{products.rowCount()}
isAvailable()
Returns the isAvailable() method result of the data source class.
Example:
products.isAvailable() or $D{products.rowCount()}
isValid()
Returns the isValid() method result of the data source class.
Example:
products.isValid() or $D{products.isValid()}
isEmpty()
Returns true if the data source has no data record.
Example:
products.isEmpty() or $D{products.isEmpty()}
isNotEmpty()
Returns true if the data source has at least 1 data record.
Example:
products.isNotEmpty() or $D{products.isNotEmpty()}
update()
Forces the update() function on the data source. This can be useful if you may want to manually
update a user defined data source. This function use carefully.
Example:
products.update() or $D{products.update()}
71
7.14. Data Source Column related (Value) functions
The data source column functions are introduced for helping some basic text operation.
DataSourceId.column.function()
column.function()
In scripts or templates:
$D{DataSourceId.column.function()}
$D{column.function()}
MID(n,m)
Returns a string that contains n characters of this string, starting at the specified m position
index.
Example:
DataSource1.firstname.MID(2,5) or $D{DataSource1.firstname.MID(2,5)}
LEFT(n)
Returns a substring that contains the n leftmost characters of the string.
Example:
DataSource1.firstname.LEFT(3) or $D{DataSource1.firstname.LEFT(3)}
RIGHT(n)
Returns the isValid() method result of the data source class.
Example:
DataSource1.firstname.RIGHT(2) or $D{DataSource1.firstname.RIGHT(2)}
72
USERFUNC()
Executes the NCReportDataSource::getUserFunctionValue(value, arguments) method and returns
its value. You may want to use it a custom implemented data source.
Example:
DataSource1.lastname.USERFUNC() or $D{DataSource1.lastname.USERFUNC()}
73
Chapter 8. Script Editor
This function provides the ability to store predefined custom script functions within the report. The
goal of storing scripts in the report is to avoid duplicating script code assigned to report items or
anywhere in the report’s scope. For example, it can be used efficiently for "print when" expressions.
To reference the script anywhere in the report, use the following token: $S{scriptId} Where
scriptId is the ID you assigned to the script.
Use predefined scripts when you need to define complex code or use a script
expression more than once in a report. This is typically useful for multiple
instances of the same "print when" expression.
To define your scripts in the designer, open the Report > Scripts… menu item (the equivalent tool
button is found on the toolbar). A dialog will appear where you can add, edit, and remove scripts.
To add a new script, click the Add button and type the script ID. To remove a script, choose Remove.
If you want to use the expression builder, select Expression builder… to open the expression builder
dialog.
8.1. Script ID
The script identifier. When you call the script anywhere in the report, you can reference it with this
ID. For example: $S{myscript1}
74
OK
Select to apply your settings and close the dialog.
Cancel
Closes the editor without saving any changes, returning you to the designer desktop.
75
Chapter 9. Data Formatting
You can specify formatting options within fields. Fields support string, integer, float, date,
datetime data types. All of them often require formatting. NCReport can format data in fields, you
can set the format options in the Designer at the Field Settings Dialog → Text, Numeric,
Date/Time tabs depending on what data type we specify in the Data type option combo box.
Vertical alignment
The vertical alignment of the text block: Top, Center, Bottom
Character length
We can explicitly set the string width (number of characters) if the fill character is going to be
used.
Rotation angle
The data can be rotated. 0 is the default position, 90 or 270 make the text vertical
Fill character
It’s possible to fill the empty characters with a specified character.
Capitalization
Mixed case (default), All uppercase, All lowercase, Small caps, Capitalize
Letter spacing
Spacing between letters in pixels: 0px is the default.
Numeric formatting
You can enable or disable the number formatting. It’s turned of by default.
76
Use localized settings
If this is turned on the number formatting gets based on the QLocale settings
Substitution string
You can specify the substitution string here.
Decimal precision
This integer number holds the number of decimal places. It is considered only if the formatting
is turned on.
Field width
Number field width in characters
Format character
Formatting character: f or g
77
9.3.1. Static Date Format
Expressio Output
n
ddd The abbreviated localized day name (e.g. 'Mon' to 'Sun'). Uses the system locale to
localize the name, i.e. QLocale::system().
dddd The long localized day name (e.g. 'Monday' to 'Sunday'). Uses the system locale to
localize the name, i.e. QLocale::system().
MMM The abbreviated localized month name (e.g. 'Jan' to 'Dec'). Uses the system locale to
localize the name, i.e. QLocale::system().
MMMM The long localized month name (e.g. 'January' to 'December'). Uses the system locale to
localize the name, i.e. QLocale::system().
yyyy The year as a four digit number. If the year is negative, a minus sign is prepended,
making five characters.
The dynamic date format uses a format string from one of the data source types, it can be a
parameter, data source reference. Use one the normal data embedding formulas:
Example:
$D{ds.dformat} or $P{mydateformatparam}
78
The dynamic date format is recognized by the report engine and evaluated during rendering. It’s up
to you to use parameter or data source for storing a dynamic date format.
79
Chapter 10. Zones
This feature is available since version 2.2.0. Zones are virtual bands within a report section. All
items can have a specified Zone ID. Items with the same zone id, just like a group, represent a
horizontal zone as a virtual band inside the section. When the section’s automatic height option is
enabled, the report engine will process the rendering of zones in order by zone ID sequentially, one
after another. If a content of a zone is empty for example because the printWhen expression of all
items in the zone return false, then the zone won’t be printed and the section will be shrunken. The
rendering order of zones matches the order of zone IDs.
To set the Zone ID of a report item use the item property dialogs.
80
Example 1. Information
Zones are not visible in design mode. The specified region is determined by only the zone IDs
of the report items
81
Chapter 11. Dynamic data driven size and
position
This feature makes it easy for you to manage the position and the size of the report items
dynamically, driven by a data source, parameter or a variable or even a script expression.
For example it is possible to define the x, y coordinates of objects in the data source, then the
positions will be managed by data source. If you want to show graphical objects such as bar, line,
you can even use them for generating vertical charts.
To set the item’s dynamic position and size management in designer open any report item’s setting
dialog by double clicking on a report item. Then appears the item settings dialog. Choose the
[ Dynamic position ] tab of the bottom side property panel.
You can set the following properties. If you leave an option empty - this is the default - the setting is
turned off and not considered. The values are always counted in millimeter and relative to their
container band’s coordinate system.
• Offset mode If this option is enabled then the positions are relative to the original static position,
otherwise they are explicit values.
82
Chapter 12. Dynamic data driven shape style
The shapes like line, rectangle, ellipse can also have dynamic style. It is possible for you to manage
the line width, line color and background color dynamically, driven by a data source, parameter or
a variable or even a script expression.
To set the shape item’s dynamic style in designer open any shape item’s setting dialog by double
clicking on an existing item. Then appears the item settings dialog. Choose the [ Dynamic style ] tab
of the bottom side property panel.
You can set the following properties. If you leave an option empty - this is the default - the setting is
turned off and not considered. The width is counted in millimeter.
83
Chapter 13. Page Breaks
Normally the paging is automatic procedure of the report engine but there are various ways to
force a page break by an event or a logical expression in the report result. We have the following
options to do that:
84
Chapter 14. Text Document printout mode
TextDocument mode feature allows to render and print multi-page HTML QTextDocument based rich
texts. The text source can be a file or any data source, so the text can be static, dynamic or even a
static template filled with dynamic data. In this mode you can use only a page header, page footer
and one or more detail sections in the report definition. The result will be a multi page HTML text
correctly broken to pages, printer ready document. document. In TextDocument mode the
pagecount system variable can be used by default without any additional setting
• In the Designer select the menu:[ReportPage options] menu. Then the report page settings
dialog will appear. Set the menu:[Report type] combobox to [ Text document ]
• Add a text report item into (the only one) Detail section. Set the text’s properties by using its
property dialog. The text may come from any source as usual.
In this mode, only one detail section within a single text item is supported. The
horizontal position and the width of the text item are maintained during
rendering.
85
Chapter 15. Data Relation system
This feature is also named as Sub-Query or Sub-Data Source system Database systems almost
always have master/detail data relation between tables. When defining reports for a typical kind of
documents such as invoices, orders etc. There are at least one header and a related detail data is
used which are linked via primary and foreign key. The goal of the data relation system that child
data sources are updated runtime row by row driven by a parent data source. This works by an ID
column which is the primary key of the parent and the foreign key of the child. The data source
relation is very useful option for SQL data sources where the data are fetched from database tables
via SQL command and for Item Model data sources as well where you can manage the data source
content from code.
The data source relation system currently works for SQL data source and Item
Model data source only. The other data source types are not supported by this
feature, expect the [ Item model ] data source.
In the the next section you can overview how to define the data sources of master/detail relation.
We will create a three level data source relation in the following example.
86
15.1. Defining a parent data source
You can add the master data source in Data Source settings Dialog. In the Designer select
menu:[ReportData sources…] and add a new SQL data source. Set the Opening role to [ Beginning
of the report ]. It means that the query will be executed only once at the beginning of the report.
Type the data source ID, set the connection properties and edit the SQL query in the SQL editor text
box.
This is our Northwind database example master query that queries the customers:
Warning
The [ Parent datasource id ] is case sensitive. It must be equal to the already existed parent
data source ID
Edit the SQL query in the sql editor text box. This is the 1st child query, it queries the order headers
between a date period and is related to a customer:
SELECT OrderID,CustomerID,EmployeeID,OrderDate,ShipName
FROM orders
WHERE CustomerID='$D{customers.CustomerID}'
AND OrderDate between '2005-03-01' and '2005-03-31'
ORDER BY OrderID
As here can be seen, the data relation is managed by a data reference expression:
$D{customers.CustomerID} We have to insert the key value of parent data source into the SQL
command.
After comes the second child data source. This is the third level of the relation. Set the Opening role
to [ Child data source (sub-query) ] too and type the [ Parent data source id ] which is the ID of
87
its parent data source (orders). Edit the SQL query in the SQL editor text box. This query retrieves
order items are related to a specified order ID:
At this level the data relation is managed by the following data reference expression:
$D{orders.OrderID} Accordingly the parent key will always be evaluated and the query is executed
when the parent key change occurs. (When its parent row is changed by report processor)
When defining a sub-query, always the lowest level child query should be assigned
to the actual Detail section. This because the report engine handles sub-queries by
iterating on child level data source records.
Add the other report sections and report items and set the alignments. The following figure appears
the ready to run report. (The name of this example report file: list_of_orders_complex.xml)
88
The report preview result of our example looks like this: (The name of this example report file:
list_of_orders_complex.xml)
89
15.7. Changes in 2.13 version
Data Source Relations has been extended from version 2.13. This is now much better supported
general feature. The function has been extended to Item Models. The reports that is created by the
old sub-query/relation system are not compatible anymore with the new version of data source
relation function.
The reports that uses sub-query function and created in previous version of
NCReport, must be upgraded. This function is not compatible with the old report
versions.
90
• The detail’s data source must be the root parent data source
• All fields and expressions must have its data source identifier i.e: datasource.column
To use the new data source relation system follow these rules:
• A data source relation can be defined by simply set "child data source" and giving the parent
data source id. (as usual)
• You can specify the primary key column index. If a primary key column is defined for the
parent data source, you can use {PK} or {ID} expression in the child data source query. (This is
useful only in SQL data sources)
• If you assign a data source relation to a detail section always set the root parent data source to
the detail. In earlier version we had to set the last child data source, but it is outdated in 2.13.
• Use !$D{datasource.isEmpty()} print when expression of a detail section to hide the empty
children data
91
Chapter 16. Double pass mode
Double pass mode is a report option that influences the running mode of report engine. When
double pass mode is enabled the report is executed two times - this two running cycle is called
primary (test) and secondary (real) pass. When the two pass mode is necessary? In normal (1 pass)
mode the report generator simply runs the report without anticipatory counting and calculations
such as determining the total page numbers.
The pagecount system variable always returns zero in 1 pass (normal) mode. If the
pagecount system variable is needed you have to enable the double pass mode
option.
92
Chapter 17. Internationalization
Since version 2.5, reports have the ability to support multiple languages. This is an important aspect
for international applications. The goal of this feature is to allow fields and labels to store multiple
texts according to predefined languages.
• To add more languages select the language from combo box and add to language list using
[ Add ] button
Leave the Default language first in the list. This represents the original language
of the report.
• Set the Multi language role. If not all labels or fields are translated and the current language
translation is missing, two options can be chosen. In order to choose Use default language the
default text will appear otherwise the label or field will not be printed (This is the Leave blank
option)
93
17.3. Setting up the current language
The current language of the report can be set both in design mode and in running mode. In
Designer select Report language from the Report menu or the Languages tool button from the
toolbar and select the language what you want from the submenu
To set the language from application code use setCurrentLanguage( const QString & langcode )
function where langcode is the international two letter language code.
To set the language from console running mode use -l command line parameter the international
two letter language code.
ncreport -f myreport.ncr -l de
94
Chapter 18. Sub-Report iteration
The feature called 'sub-report' means here the whole repeated report process by traversing through
a dedicated data source. This is similar to the 'classic sub-report' model but supports only 1 level.
This function is very useful when a complex report or a multi detail report has to be repeated by
processing different data records. The function uses a dedicated 'parent' data source as a repeation
source.
Sub-Report function is a great opportunity for creating simple one-to-many relation reports.
For non SQL data sources such as Item Model data source it is possible to use the SIGNAL/SLOT
mechanism. Use the following signal of NCReport object:
signals:
void dataSourceUpdateRequest(const QString& dataSourceID, const QString&
data);
All data sources are updated repeatedly when a sub-report cycle begins, after the
last cycle finished, except the master data source. The function is similar to a
parent/child relation
95
Chapter 19. Table View Rendering
Table View item is a report item destined to rendering QTableView tables with full WYSIWYG print
support or rendering an item model content. The function is originally aimed to print the tables in
the same rate as the existed QTableView screen widget. The table view item should follow the
formats of the original QTableView widget. The cells gets display outlook information from the
table’s item model. Some basic table settings such as header background, line type, line color, etc.
are currently fixed.
It is strongly recommended to add Table View to a Detail section, not into the
headers or footers. Since the table may fill the available space both horizontally
and vertically, no other report items should add to this section. The table view has
its own data source assignment so it is independent from the data source of the
detail which should be unique and should have 1 record. You can use an 1 row
static text data in a detail section for tables.
Specify the same ID values in the Table View settings dialog that you will apply when setting the
table view and the model from code. The report engine will identify the objects by the specified IDs.
96
The dialog options are as follows:
• Item Model ID Identifies the model object pointer related to the QTableView.
• Table View ID Identifies the QTableView object pointer you want to render.
• Show horizontal header If enabled then the horizontal table header will appear.
• Show vertical header If enabled then the vertical table header will appear.
• Elided text mode When this option is enabled the multi-line texts will not be rendered, but
partially the first line only with three dots.
• Pin to left The table will automatically be adjusted to the left margin.
• Pin to right The table will automatically be adjusted to the right margin.
97
19.4. Example
The following example shows how a printed QTableView widget looks like on the screen. The table
is filled with test data and even images.
98
19.7. Printing Item Model Based Table without
QTableView
It is also possible to render a table without having an existing QTableView widget (or any other
item view). In this scenario you have to set at least the item model Id you assign from code. The
table view ID you can leave empty. Without an item view the report engine tries to calculate the
optimal cell width and height based on the content.
Example code:
99
void setCellGraphRenderer(const QString id, int column);
#include "ncreportgraphrenderer.h"
#include "mycustomcellrenderer.h"
#include <QPainter>
MyCustomCellRenderer::MyCustomCellRenderer() {}
MyCustomCellRenderer::~MyCustomCellRenderer() {}
MyLogoPainter cp;
cp.setMyProperty(50);
cp.setState(MyLogoPainter::Basic);
painter->save();
cp.paint(painter, rect.toRect());
painter->restore();
}
In the table setting dialog you need set the ID for the table item in the report:
100
19.9. Handle progress signal of table rendering
It is possible to connect the progress signal of the table rendering into a slot in your application.
This option can be useful in order to printing large tables. The signal is emitted row by row:
NCReport::dataRowProgress(int row)
101
Chapter 20. Cross-Tab Tables
Reports often contain tables or data presented in a tabular layout. Sometimes it’s necessary to
rotate results so that columns are displayed horizontally and rows are displayed vertically. This is
known as creating a PivotTable, a cross-tab report, or rotating data. In cross-tab tables, the data
source records are represented as horizontal columns, and the cross-tab rows are printed as data
source columns. Tables often include horizontal and/or vertical summarization as well.
A cross-table has a unique data source assigned. In the report, a unique data source needs to be
defined for the table. When the report generator renders cross tables, they behave as follows:
• Horizontally expandable: If the table is wider than the available space, it continues in a new
table below. Table columns are represented as data source records.
• Vertically expandable: Each row represents a data column from the specified data source and
can break into multiple pages.
102
Table Rows
Table Columns
Cell Structure
The cell structure of cross-tables is as follows:
0 Corner header
1 Column header
3 Row header
4 Data
103
20.2. Using Cross-Table in Designer
To add a cross-tab to a report, select the Cross table item from the toolbar or the Insert menu.
Cross-tab in Designer
This creates a new Cross tab object in the selected section at the clicked position and opens the
Cross table property dialog. In this dialog, you can set all the table’s properties.
104
The property dialog is divided into the following tabs: Table properties and Cell properties. You can
find the "Print only when expression" option at the bottom of the dialog. If a logical expression is
defined, the table will be shown or hidden based on the result of the expression.
• Table data source: ID of the defined data source related to the table. The selected data source
should be unique and independent from the data source of any detail because cross tables have
their own data processing.
• Hidden columns: Comma-separated list of valid data source columns we don’t want to show in
the table.
• Column title source: Data column ID of column header titles. If not specified, the column
numbers appear.
◦ Cell padding: Gap size inside the cells, equal to internal cell margin
◦ Table spacing: Spacing between the tables when the cross-tab is multi-line.
◦ Total column width: Width of total/summary column, mostly the last, rightmost column
◦ Total row height: Height of the total/bottom summary row, mostly the last row of the table.
◦ Break table when page breaks: If enabled, the table can break within its rows when the page
breaks.
The cell properties are related to the specified cells, represented by their function.
105
106
Chapter 21. Conditional Formatting
This feature enables the use of dynamic, data-driven text styles in reports based on the current
value of any data source columns, parameters, variables, or script expressions. Conditional
formatting is available for Labels or Fields only.
HTML texts can be dynamically formatted by embedding dynamic tags within HTML code. The
format definition is a code text with style tag symbols and expressions similar to generic CSS style
code. The style tag and its value/expression are divided by a colon. Each row represents one style
definition. Script expressions must be enclosed in curly braces.
107
21.2. Editing Style Code in Designer
To define conditional text formatting for a Label or a Field, click on the "Conditional formatting…"
button at the bottom of the item property dialog. Then the conditional format code dialog will
appear. Type or paste the format code while adhering to the syntax rules. Click [ OK ] to save the
code.
NOTE
Style tag and its corresponding value should be in one line! Multiple lines of style definitions
are not evaluated.
TEXT output is generated very fast, because data is processed and substituted
directly into the text template without any graphical rendering.
108
21.4. Text template manager tags
The following manager keywords/tags are available when you create a text template. Each start and
end tags represents a specified section. Tags are enclosed in standard HTML comment tokens,
according to HTML
21.6. Examples
The following example shows how a typical usage of text template
109
SIMPLE TEXT REPORT OUTPUT
<!-- END -->
<!-- BEGIN {PH} -->
Customer ID Name Address
-----------------------------------------------
<!-- END -->
<!-- BEGIN {D.Detail1} -->
$D{custid} $D{custname} $D{address}
<!-- END -->
110
Chapter 22. Batch Report Mode
Batch report mode is a feature that enables running multiple reports into one output. Read more at
Part Using NCReport API [batch]
111
Chapter 23. Special Detail Sections
There are special features can be done with detail sections that might be is very useful sometimes.
It is possible to render some special details at non normal location, these functions are subdetail,
repeated detail or odd even content.
The sub section will appear just after its assigned parent regardless of the other details.
112
23.4. Odd / Even Pages
Odd / even page feature is a special use case of the sub-section. It is possible to create a report that
have have odd and even page after each other, especially another page content gets inserted at
every n or n+1 page. You can specify a dedicated detail section for representing an odd page or an
even page for this purpose.
To create odd or even page, add a new detail to your report and set one of the following identifiers
at Detail settings → Special tab Parent section ID It’s recommended to assign a dummy / one row
data source to such details, to ensure that their content gets printed only once.
{INSERT_EVEN} or {INSERT_ODD}
113
{INSERT_EVEN}
Represents a content that gets inserted at every even page
{INSERT_ODD}
Represents a content that gets inserted at every odd page
114
Command Line Tool
This part specifies the report engine command line tool
115
Chapter 24. Command line client
NCReport engine is also available in command line client executable.
NCReport [options]
-v, --version
NCReport version
q, --sql-driver [driver]
Qt sql driver name for database connection. Avaible drivers: QDB2, QIBASE, QMYSQL, QOCI,
QODBC, QPSQL, QSQLITE, QTDS
116
-co, --connect-option [opt]
Connect option string/id
--copies [1..50]
Number of copies in case output is printer
--force-copy
Use forced copy printing method. This is useful for documents in which has to be known the
number of current copy.
--nodialog
Runs report to default printer without showing printer dialog.
-hs, --htmlstrategy
HTML output generation strategy. 1 = section is translated as one table (default) 2 = sections are
always unique tables
-css, --css-file
HTML output style sheet file to be generated. If not set, the stylesheet is included in the target
HTML file.
117
Using NCReport API
This part shows how to implement NCReport API code in your application
118
Chapter 25. Using NCReport API
This chapter shows you how to use the report API from a C++ (Qt) application, how to create an
NCReport object and how to use it from your application. As we described earlier NCReport system
consists of two parts: Report renderer library and a report designer GUI application. Of course the
report engine can be used separately from Designer.
If you want to call NCReport from your application, first you have to integrate NCReport in your
project. There are several ways to do so:
• To add the whole sources to your project and build it together with your application.
• To use NCReport engine as shared library. For using NCReport library like other libraries in your
project you need to specify them in your project file. For more information see the Qt
documentation in qmake manual at chapter Declaring Other Libraries.
• Statically linking NCReport library for your project. For more information see the Qt
documentation in qmake manual at chapter Declaring Other Libraries
NCREPORT_LIBPATH = /home/ncreport/lib
CONFIG(release, debug|release) {
win32|win64: LIBS += -L$$NCREPORT_LIBPATH -lNCReport2
unix:!macx: LIBS += -L$$NCREPORT_LIBPATH -lNCReport
else:macx: LIBS += -framework NCReport
}
CONFIG(debug, debug|release) {
win32|win64: LIBS += -L$$NCREPORT_LIBPATH -lNCReportDebug2
unix:!macx: LIBS += -L$$NCREPORT_LIBPATH -lNCReportDebug
else:macx: LIBS += -framework NCReportDebug
}
INCLUDEPATH += /home/ncreport/include
...
119
#include "ncreport.h"
#include "ncreportoutput.h"
#include "ncreportpreviewoutput.h"
#include "ncreportpreviewwindow.h"
If the class has created earlier and passed as a parameter to your method in which you use the
report object you should initialize the report by calling reset() method. Otherwise, if creating a
new object in the scope, you don’t need to call the reset.
report->reset();
This example code shows a typical SQL database connection with error handling:
if ( !defaultDB.isValid() ) {
QMessageBox::warning( 0, "Report error", QObject::tr("Could not load database
driver.") );
delete report;
return;
}
defaultDB.setHostName( "host" );
defaultDB.setDatabaseName( "database" );
defaultDB.setUserName( "user" );
defaultDB.setPassword( "password" );
if ( !defaultDB.open() ) {
QMessageBox::warning( 0, "Report error", QObject::tr("Cannot open database:")
+defaultDB.lastError().databaseText() );
return;
}
120
25.6. Setting the Report’s source
Report source means the way of NCReport handles XML report definitions, in other words the
source of report definition XML data. Report definitions may opened from a file - in most cases it is
suitable, but it can be loaded also from an SQL database’s table. For information of configuring and
using the different report sources see the parts 1-7
report->setReportFile( fileName );
report->setReportSource( NCReportSource::File );
report->reportSource()->setFileName( fileName );
121
// run report to QPrintPreview dialog
bool result = report->runReportToQtPreview();
This way, if we want to preview the report we also have to create and show NCReportPreviewWindow.
See the next section.
• NCReportPrinterOutput
• NCReportPreviewOutput
• NCReportPdfOutput
NCReportOutput *output=0;
if ( rbPreview->isChecked() ) {
output = new NCReportPreviewOutput();
output->setAutoDelete( FALSE );
report->setOutput( output );
} else if ( rbPrinter->isChecked() ) {
output = new NCReportPrinterOutput();
output->setCopies(1);
output->setShowPrintDialog(TRUE);
report->setOutput( output );
} else if ( rbPdf->isChecked() ) {
QString fileName = QFileDialog::getSaveFileName(this, tr("Save PDF File"),
"report.pdf", tr("Pdf files (*.pdf)"));
if ( fileName.isEmpty() ) {
delete report;
return;
} else {
output = new NCReportPdfOutput();
output->setFileName( fileName );
report->setOutput( output );
}
}
122
25.12. Running the Report
Now we are ready to run the Report and catch the error message if an error occurs:
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
report->runReport();
bool error = report->hasError();
QString err = report->lastErrorMsg();
QApplication::restoreOverrideCursor();
if ( error ) {}
QMessageBox::information( 0, "Report error", err );
} else {
if ( rbPreview->isChecked() ) {
//-----------------------------
// PRINT PREVIEW
//-----------------------------
NCReportPreviewWindow *pv = new NCReportPreviewWindow();
pv->setReport( report );
pv->setOutput( (NCReportPreviewOutput*)output );
pv->setWindowModality(Qt::ApplicationModal );
pv->setAttribute( Qt::WA_DeleteOnClose );
pv->exec();
}
}
For the best performance and code quality we should not delete NCReport object
until we close preview dialog. Add the report object to the preview object by
If it’s done the printing from preview will result the original printout quality, since it will run
report again instead of printing the lower quality preview pages.
123
Since 2.8.4 version it’s possible to show the preview widget in dialog mode, just
like QDialog. NCReportPreviewMainWindow::exec() function shows the preview
window and keeps application event loop while preview. This is good when you
use a locally defined report object, because the report object will not be deleted
until user closes the preview window.
delete report;
NCReport allows to use QString texts as simplest data source. Each text row represents one data
record (rows are separated by the linefeed character) and the data columns are separated by a
specified delimiter character. For column identification in fields use the number of the column as
reference in the report by the following:
0 for 1st column, 1 for 2nd column … etc. or col0 for 1st column, col1 for 2nd column … etc.
For using text data sources add a Text data source to your report in Designer. You have the
following ways:
• Storing a static text in report definition. For doing so, in Designer select Static location type and
add static text to the edit box by using the specified delimiter character.
• Using an existed text file. For doing so, in Designer select File location type and specify the name
of the text file you want to use. Also you must specify the delimiter character.
• Adding text to NCReport by NCReportParameter. For doing so, first add the data text as a
parameter to NCReport by addParameter() function. Select Parameter location type in Designer
and specify the ID of the parameter you have added. Also you must specify the delimiter
character.
Example of adding a QString text to NCReport as parameter and Tab character as column delimiter:
NCReport report;
124
QString data;
NCReport allows you to use also QStringList as a data source. First you should define a QStringList.
Each QStringList item represents one data record and the data columns are separated by a specified
delimiter character.
For column identification in fields use the number of the column as reference in the report by the
following:
0 for 1st column, 1 for 2nd column … etc. or col0 for 1st column, col1 for 2nd column … etc.
For using QStringList data sources add a StringList data source to your report in Designer. You can
only use Static location type since QStringList can be added to NCReport by one mode only: using
addStringList() function. You have to specify an id with the list for identifying purposes.
NCReport report;
QStringList list;
list << "24|Renate Moulding|Desert Hot Springs,CA|1|2008-01-01";
list << "78|Alfred Muller|Miami Beach, FL|1|2008-01-03";
list << "140|Angela Merkel|Munchen, Germany|1|2008-01-07";
list << "139|Bob Larson|Dallas, TX|0|2008-01-20";
125
25.15.3. Item Model data source
Item/Model/View architecture is a very useful new feature of Qt4. NCReport allows you to use a
data source based on QAbstractItemModel. First you have to create your item model. Each model
row represents one data record. For column identification in fields use the number of the column
as reference in the report by the following:
0 for 1st column, 1 for 2nd column … etc. or col0 for 1st column, col1 for 2nd column … etc.
For using Item Model data sources add an Item Model data source to your report in Designer. You
can only use Static location type, other locations are undefined. In your code add the Item model to
NCReport using addItemModel(…) function. You have to specify an id to the model for identifying
purposes. The same ID you must specify for item model data source in the designer.
// -----------------------------------
item = new QStandardItem();
item->setData( 1, Qt::EditRole );
model->setItem( 0, 0, item);
// -----------------------------------
item = new QStandardItem();
item->setData( 2, Qt::EditRole );
model->setItem( 1, 0, item);
126
item->setData( 1230.0, Qt::EditRole );
model->setItem( 1, 3, item);
25.16.1. Declaration
#include "ncreportdatasource.h"
#include <QDate>
struct TestData {
int id;
QString name;
QString address;
bool valid;
QDate date;
};
bool open();
bool close();
bool first();
bool last();
bool next();
bool previous();
int size() const;
QVariant value( const QString& ) const;
QVariant value( int ) const;
bool read( NCReportXMLReader* );
bool write( NCReportXMLWriter* );
private:
QList<TestData> list;
127
};
25.16.2. Implementation
bool TestDataSource::open()
{
if ( list.isEmpty() ) {
error->setError( tr("No data in TestDataSource data source") );
return false;
}
recno =0;
m_opened = true;
return true;
}
bool TestDataSource::close()
{
recno =0;
m_opened = false;
return true;
}
bool TestDataSource::next()
{
recno++;
flagBegin = false;
return true;
}
128
bool TestDataSource::prevoius()
{
recno--;
if ( recno < 0 ) {
recno = 0;
flagBegin = true;
}
return true;
}
bool TestDataSource::first()
{
recno=0;
return true;
}
bool TestDataSource::last()
{
recno = list.count()-1;
return true;
}
129
bool TestDataSource::read(NCReportXMLReader *)
{
return true;
}
bool TestDataSource::write(NCReportXMLWriter *)
{
return true;
}
Now we have to take our TestDataSource class. For using the TestDataSource data source add a
Custom data source to your report in Designer. You can only use Static location type for this data
source. Specify the class ID id with the list for identifying purposes both in Designer and in the class
by setID() function.
NCReport report;
TestData d1;
d1.id = 123;
d1.name = "Alexander Henry";
d1.address = "HOT SPRINGS VILLAGE, AR";
d1.valid = true;
d1.date = QDate(2008,01,10);
ds->addData( d1 );
TestData d2;
d2.id = 157;
d2.name = "Julius Coleman";
d2.address = "Coronado, CA";
d2.valid = false;
d2.date = QDate(2008,01,12);
ds->addData( d2 );
TestData d3;
d3.id = 157;
d3.name = "Peter Moulding";
d3.address = "San francisco, CA";
d3.valid = true;
130
d3.date = QDate(2008,01,07);
ds->addData( d3 );
report.addCustomDataSource( ds );
• Add a Graph (Custom) item into your report in the designer and specify the size and the location
of the object. Specify the class ID of the item. This ID is used for identification.
25.17.1. Declaration
#include "ncreportabstractitemrendering.h"
25.17.2. Implementation
#include "testitemrendering.h"
#include "ncreportoutput.h"
#include <QPainter>
#include <QColor>
TestItemRendering::TestItemRendering()
{
}
TestItemRendering::~ TestItemRendering()
131
{
}
painter->setPen( QPen(Qt::black) );
painter->setBrush( Qt::NoBrush );
painter->drawRect( rect );
painter->setFont( QFont("Arial",8) );
painter->drawText( rect, Qt::AlignHCenter | Qt::AlignVCenter | Qt::TextWordWrap,
QString("GRAPH EXAMPLE: %1").arg(itemdata) );
}
132
25.17.3. Using the class
NCReport report;
Batch mode is enabled when a report XML definition string is added by addReportToBatch(…)
function. This example shows how we can easily prepare a batch report from existing report files.
...
report->clearBatch();
QString report1;
Utils::fileToString( "/home/anywhere/report1.xml", report1 );
report->addReportToBatch( report1 );
QString report2;
Utils::fileToString( "/home/anywhere/report2.xml", report2 );
report->addReportToBatch( report2 );
QString report3;
Utils::fileToString( "/home/anywhere/report3.xml", report3 );
report->addReportToBatch( report3 );
The order of reports in batch equals the order of applied addReportToBatch(…) commands
133
Specification
This document is essentially a specification of NCReport Reporting System XML template structure.
This is a brief documentation of report definition XML file structure.
134
Chapter 26. Specification
Report XML template structure specification
SQL queries (sql data source) are the most common and widely used data sources for NCReport. It
requires an SQL database connection using Qt’s database driver plugins. The database connection
can be either internal or external.
For an internal connection (the default), a valid database connection must be established by the
application using NCReport before running the report. If an external connection is used, the
connection parameters must be specified accordingly.
XML syntax
<datasource>[SQL query]</datasource>
<datasource>[query filename]</datasource>
======= Tag properties id:: data source ID. Identification name of the data source. Details are
assigned to data source by this ID. type:: Specifies the data source type. Equals SQL for SQL data
sources. Possible values are: SQL,txt,xml,list,model,custom source:: The source of the data source
definition. Depending on this option the SQL query is stored and read from the report definition or
from a specified file. Possibly values are: static,file,parameter connection:: Specifies the SQL
database connection handling method. Possibly values are: internal,external With internal (the
default) connection a valid database connection must be established by the application uses
NCReport before running the report. If external connection is specified, the report generator
connects to the database when opening the data source. If this occurs the
host,database,user,password,port possible connection parameters are used. connID:: The
database connection’s name that is used when the QSQLDatabase::addDatabase(…) method is
called in the report engine. This ID is required for running SQL query which is assigned to the data
source parentID:: If the data source is a sub-item of a parent data source (sub-query system) then
this ID equals to the ID of parent data source. Valid for SQL data sources only driver:: The name of
the Qt’s SQL database driver. The possible values are: QDB2, QIBASE, QMYSQL, QOCI, QODBC,
QPSQL, QSQLITE2, QSQLITE, QTDS host:: Host name for SQL database connection. Used only
when external connection is defined. database:: Database name for SQL database connection. Used
only when external connection is defined. user:: Host name for SQL database connection. Used only
135
when external connection is defined. password:: Password for SQL database connection. Used only
when external connection is defined. port:: Port number for SQL database connection. Used only
when external connection is defined.
Texts, text files, are able to be as a data source for NCReport. The data columns of a text are usually
delimited by tab or other delimiter character. Even it’s possible to avoid SQL database connection
when using this kind of data source. It’s necessary to set the delimiter type, this delimiter separates
the columns and each row represents a data record. Text data sources can be static, stored in XML
definition or can be a file
XML syntax
<datasource>[static text]</datasource>
<datasource>[filename]</datasource>
Tag properties
id
data source ID. Identification name of the data source. Details are assigned to data source by this
ID.
type
Specifies the data source type. Equals txt for text data sources.
source
The source of the data source definition. Depending on this option the text is stored and read
from the report definition or from a specified file. Possibly values are: static,file
Extensible Markup Language (XML) format is also can be a data source for NCReport. If using
The following example shows how the data structure should look like
Example
XML syntax
<datasource>...</datasource>
136
Tag properties
id
data source ID. Identification name of the data source. Details are assigned to data source by this
ID.
type
Specifies the data source type. Equals xml for XML data sources.
It’s possible to use also QStringList as data source for NCReport. Before running report, a
QStringList must be assigned to the specified data source and also is necessary to set a delimiter
character for separating columns in each list item that represents a data record.
XML syntax
<datasource></datasource>
Tag properties
id
data source ID. Identification name of the data source. Details are assigned to data source by this
ID.
listID
ID of the list. This identification name specifies the id of the
<classname>QStringList</classname> added to NCReport.
type
Specifies the data source type. Equals **list for string list data sources.
Qt’s item model classes provide a generic model for storing custom data. For example
<classname>QStandardItemModel</classname> can be used as a repository for standard Qt data
types. It is one of the Model/View Classes and is part of Qt’s model/view framework. It’s possible to
use item models as data source for NCReport. Before running report, a
<classname>QAbstractItemModel</classname> based class must be created and assigned to the
specified data source.
XML syntax
<datasource></datasource>
137
Tag properties
id
data source ID. Identification name of the data source. Details are assigned to data source by this
ID.
modelID
ID of the model. This identification name specifies the id of the Model added to NCReport.
type
Specifies the data source type. Equals model for item model data sources.
Often data is stored in special repository such as lists, arrays etc. You can build your custom data
source class derived from <classname>NCReportdata source</classname> base class. It is an abstract
class - you just have to implement the required methods.
One report can contain the following sections: Report header, report footer, page headers, page
footers, group headers and footers and details
Page headers is used to contain page headings. Page headers have the following characteristics: *
Always print at the top of a page* Always contain the first information printed on a page* Only
display one (current) row of data returned by a data source * Only one allowed per page
XML syntax
<pageheader>...</pageheader>
Tag properties
height
The height of the page header section in millimeters
Page Footer are commonly used to close the pages. Page footers have the following characteristics:
138
• Always print at the bottom of a page* Only display one (current) row of data returned by a data
source* Only one allowed per page
• Page footer is usually used to display informations like number of the page, report titles and so
on.
XML syntax
<pagefooter>...</pagefooter>
Tag properties
height
The height of the page footer section in millimeters
Report header is used to contain report headings. Report header has the following characteristics:
XML syntax
<reportheader>...</reportheader>
Tag properties
height
The height of the report header section in millimeters
Report footer is commonly used to close the report. Report footer has the following characteristics:
• Always printed before the page footer at the end of the report
XML syntax
<reportfooter>...</reportfooter>
139
Tag properties
height
The height of the report footer section in millimeters
26.2.5. Details
The core information in a report is displayed in its Detail section. This section is the most important
part of the report since it contains the row by row data from the data source Detail section have the
following issues:
• Generally print in the middle of a page* Always contain the core information for a report
• Display multiple rows of data returned by a data source* The detail sections generally contains
fields or dynamic objects.
• Multiple independent details are allowed in one report, each detail after the other* Each detail
is assigned to one specified data source
XML syntax
<detail>...</detail>
Structure:
<details>
<detail>
<items>...</items>
<groups>...</groups>
</detail>
<detail>
<items>...</items>
<groups>...</groups>
</detail>
...
</details>
Tag properties
id
Name/ID of the detail for identification purposes
height
The height of the group header section in millimeters
data source
The data source name/id the detail section is assigned to
140
26.2.6. Group sections
While most reports can be defined using a single Detail section having multiple columns and rows
of data, others require summary data - such as subtotals. For reports requiring summary data, the
report writer supports Group sections. Group sections have the following characteristics:
• Always associated with a Detail section* Defined by Group Headers and Group Footers
• Group Headers always print above it’s Detail section* Group Footers always print below it’s
Detail section
• Reference database column on which Group Headers and Group Footers will break
• Force new Group Header each time the value of the referenced column changes
• Force a new Group Footer each time the value of the referenced column changes
The groups added to XML definition are shown in the order you have added. They are structured
hierarchically. The first group will be the primary level of group, the second one is the second level
and so on. The added group sections will appear in the designer after you applied the group
settings.
XML syntax
<groups>
<group>
<groupheader>...</groupheader>
<groupfooter>...</groupfooter>
</group>
</groups>
Tag properties
id
Identification label for naming the group
groupExp
Group expression or data source column. Specifies the name of the data source column on
which Group Headers and Group Footers will break. The expression also can be a constant
value, in this case the detail row won’t break. The constant group expression: %CONST
resetVariables
The variable list appears the existed variables in the report. Just select the items represent the
variables will be reset when the current group ends. Selecting the specified variables is very
useful when for example you want to reset a total or a count variable.
reprintHeader
Item’s Y coordinate in millimeter within the current section.
141
26.2.7. Group header
Group headers are used to contain group heading items such as column head titles or so on. They
are always printed above it’s Detail section. A new Group Header is forced each time the value of
the referenced column changes.
XML syntax
<groupheader>...items...</groupheader>
Tag properties
height
The height of the group header section in millimeters
Group footers are used to contain group footing items such as totals, subtotals. They are always
printed below it’s Detail section. A new Group Footer is forced each time the value of the referenced
column changes.
XML syntax
<groupfooter>...items...</groupfooter>
Tag properties
height
The height of the group footer section in millimeters
$P{parametername}
142
26.4. Variables
Variables are specific items of the report. Variables are special fields used for providing counts and
totals. Each of the variables have name, function type, data type, and have an assigned data source
column the variable based on. We will explain what the different function types mean:
Count
The [ COUNT ] type of variable will increment by 1 for every row returned by a query.
Sum
The [ SUM ] (summary) variable will summarize the value of the specified data source column. It
requires numeric field type. To embed a parameter into an expression use this syntax:
$V{variablename}
pageno
Returns the current page number
pagecount
Returns the count of total pages of the report. Works only for Text document printout mode.
forcecopies
Returns the number of total force copies
currentcopy
Returns the current number of force copy
currentrow
Returns the current detail row number
date
Returns the current date
time
Returns the current time
datetime
Returns the timestamp
appname
Returns the name of this application
143
applongname
Returns the long name of this application
appinfo
Returns the full info string of this application
appversion
Returns the version of this application
appcopyright
Returns the copyright info of this application
qtversion
Returns the Qt version
os
Returns the operation system
For variable fields or to embed a parameter into an expression use this syntax:
$V{systemvariablename}
26.6. Expressions
NCReport since 2.0 version handles script expressions using Qt Script the new powerful feature of
Qt 4.3. Qt Script is based on the ECMAScript scripting language, as defined in standard ECMA-262.
Fields and group expressions may are script codes instead of data source column. The report
engine evaluates the specified script code in each time when fields are refreshed. Report items can
have printWhen property. They are also script expressions that return boolean result. To use script
expression in fields the ftype="exp" field property must be specified.
• parameter
• variable
The references are always replaced to their current value before the exression is evaluated. The
syntax of referneces are the following: $D{[data source.]column[,n]} data source column reference.
Returns the current value of the data source column from the current row/record. If data source. is
not specified the current data source (assigned to the current detail) is interpreted.
144
appropriate data source class.
$P{paramatername}
Parameter reference. Returns the value of the parameter by name/ID
$V{variablename}
Variable reference. Returns the current value of the variable by name/ID.
$D{price}<1500
Quotation mark in expressions is required only if a string data are applied. Otherwise (i.e for
number) the quotation mark is not necessary.
The Label represents simple text or label items. Label items are used to display descriptive
information on a report definition, such as titles, headings, etc. Labels are static item, it’s values
don’t change when rendering the report.
XML syntax
<label>Text label...</label>
Tag properties
id
Identification number for internal purposes (temporarily not used)
posX
Item’s X coordinate in millimeter within the current section.
posY
Item’s Y coordinate in millimeter within the current section.
width
Label’s width in millimeter.
145
height
Label’s height in millimeter.
resource
Resource of the label. Not used for labels since they are always static.
fontName
Font style/face name
fontSize
Font size in points.
fontWeight
Font weight. Possible values are: bold,demibold
alignmentH
Label’s horizontal alignment. Possible values: left,right,center
alignmentV
Label’s vertical alignment. Possible values: top,center,bottom
forecolor
The foreground color of the label in #RRGGBB format
zValue
This integer number specifies Z-order value of the item. This value decides the stacking order of
sibling (neighboring) items.
printWhen
This logical script expression specifies the item’s visibility. If this expression is not empty, the
report engine evaluates it each time before rendering. If the logical expression returns true (or
1) the item is shown, otherwise the item is hidden.
26.10. Fields
Field is the matter of report items. It represents the data Field objects. By data type Fields may be
text, numeric and date. Field items are used for pulling dynamically generated data into a report
from the specified data source such as database the report generator uses. For example, a Field
item may be used to present SQL data, variables and parameters. NCReport handles data formatting
for the different type of fields like numbers or texts.
<field>[data sourcename.]column</field>
<field>[expression]</field>
<field>[parametername]</field>
<field>[variablename]</field>
146
<field>[system variablename]</field>
id
Identification number for internal purposes (temporarily not used)
type
The field’s base data type. The following data types are handled:
txt
Text data* num Numeric data. All numeric formatting options are valid only when this option is
set* date Date data. The date formatting options are valid for date type data only* bool Boolean
data. It’s value might be Yes/True or Not/False
ftype
This property represents what kind of field source expression is used by the field. Field’s value
are pulled from the specified source is set by this property. The possible sources are:
ds/SQL
The field gets data from the default or the specified data source* par The field gets data from the
specified parameter* var The field gets data from the specified variable* sys The field gets data
from the specified system variable* exp The field evaluates the script expression and it’s result
will be rendered
posX
Item’s X coordinate in millimeter within the current section.
posY
Item’s Y coordinate in millimeter within the current section.
width
Field’s width in millimeter.
height
Field’s height in millimeter.
resource
Not used for fields since they are always dynamic.
fontName
Font style/face name
fontSize
Font size in points.
147
fontWeight
Font weight. Possible values are: bold, demibold
alignmentH
Field’s horizontal alignment. Possible values: left, right, center
alignmentV
Field’s vertical alignment. Possible values: top, center, bottom
forecolor
The foreground color of the field in #RRGGBB format
formatting
If the field’s data type is numeric, this option tells the report engine if number formatting is
turned on or off. The possible values are: true,false
numwidth
Width of number in digits. The fieldWidth value specifies the minimum amount of space that a
is padded to and filled with the character fillChar. A positive value will produce right-aligned
text, whereas a negative value will produce left-aligned text. Works only when the number
formatting is turned on
format
This one digit option specifies the format code for numbers. Possibly values are: e,E,f. With e,E
and f, precision is the number of digits after the decimal point. With 'g' and 'G', precision is the
maximum number of significant digits. Used by <function>QString::arg( double a, int fieldWidth
= 0, char format = 'g', int precision = -1, const QChar & fillChar)</function> function.
precision
The number of digits after the decimal point for numeric data.
fillchar
The numwidth value specifies the minimum amount of space that a is padded to and filled with
the character fillchar. A positive value will produce right-aligned text, whereas a negative value
will produce left-aligned text.
callFunction
Specifies the Field level custom function is called when the field is evaluated. Not used currently.
lookupClass
Similar to callFunction. Temporarily is not used.
dateFormat
Date formatting expression. This expression uses the same format QDate::fromString() uses.
Works only when the field’s type is date
localized
Specifies if localization is turned on or off. Works for numeric data only. The possible values are:
148
true, false
blankifzero
If true, If the field’s value equals zero, the field will not be displayed.
arg
This expression specifies the QString::arg(…) string of field’s value to be replaced or formatted.
The field gets a copy of this string where a replaces the first occurrence of %1. The '%' can be
followed by an 'L', in which case the sequence is replaced with a localized representation of a.
The conversion uses the default locale, set by QLocale::setDefault(). If no default locale was
specified, the "C" locale is used.
zValue
This integer number specifies Z-order value of the item. This value decides the stacking order of
sibling (neighboring) items.
printWhen
This logical script expression specifies the item’s visibility. If this expression is not empty, the
report engine evaluates it each time before rendering. If the logical expression returns true (or
1) the item is shown, otherwise the item is hidden.
id
Identification number for internal purposes (temporarily not used)
posX
Item’s X coordinate in millimeter within the current section.
posY
Item’s Y coordinate in millimeter within the current section.
width
width in millimeter.
149
height
height in millimeter.
resource
Resource of the text. Not used for labels since they are always static.
fontName
Font style/face name. Effects only if system settings is enabled.
fontSize
Font size in points. Effects only if system settings is enabled.
fontWeight
Font weight. Possible values are: bold,demibold Effects only if system settings is enabled.
forecolor
The foreground color of the label in #RRGGBB format. Effects only if system settings is enabled.
zValue
This integer number specifies Z-order value of the item. This value decides the stacking order of
sibling (neighboring) items.
printWhen
This logical script expression specifies the item’s visibility. If this expression is not empty, the
report engine evaluates it each time before rendering. If the logical expression returns true (or
1) the item is shown, otherwise the item is hidden.
26.12. Line
The Line option enables you to create Line items. In general, Line items are used for drawing
vertical, horizontal lines for headings, underlining titles or so on. Lines are defined by it’s start and
the end point coordinates
<line></line>
id
Identification number for internal purposes (temporarily not used)
lineStyle
Specifies the line drawing style of the item. Possible values are: solid Solid line, dash Dashed
line, dot Dotted line, dashdot Dash+dotted line, dashdotdot Dash+dot+dot line, nopen No line
painted. Unavailable for lines
150
fromX
X coordinate of the start point of line in millimeters within the current section.
fromY
Y coordinate of the start point of line in millimeters within the current section.
toX
X coordinate of the end point of line in millimeters within the current section.
toY
Y coordinate of the end point of line in millimeters within the current section.
resource
Not used for lines since they are always static.
lineWidth
The width of the line in millimeters
lineColor
The color of the line in #RRGGBB format
zValue
This integer number specifies Z-order value of the item. This value decides the stacking order of
sibling (neighboring) items.
printWhen
This logical script expression specifies the item’s visibility. If this expression is not empty, the
report engine evaluates it each time before rendering. If the logical expression returns true (or
1) the item is shown, otherwise the item is hidden.
26.13. Rectangle
The Rectangle enables you to create Rectangle items. Rectangles are usually used for drawing boxes
or borders around a specified area. Rectangle makes easier the box drawings instead of drawing
four lines.
<rectangle></rectangle>
id
Identification number for internal purposes (temporarily not used)
151
lineStyle
Specifies the line drawing style of the rectangle. Possible values are:
solid
Solid line* dash Dashed line* dot Dotted line* dashdot Dash+dotted line* dashdotdot
Dash+dot+dot line* nopen No line painted. The rectange is rendered without outline
fillStyle
Specifies the fill style or painting brush of the rectangle. Possible values are:
no
Rectangle is not filled.* solid Solid fill* dense1 Extremely dense brush pattern fill* dense2 Very
dense brush pattern fill dense3* Somewhat dense brush pattern fill* dense4 Half dense brush
pattern fill* dense5 Half dense brush pattern fill* dense6 Somewhat sparse brush pattern fill*
dense7 Very sparse brush pattern fill* hor Horizontal lines pattern fill* ver Vertical lines
pattern fill* cross Cross lines pattern fill* bdiag Backward diagonal lines pattern fill* fdiag
Foreword diagonal lines pattern fill* diagcross Crossing diagonal lines pattern fill
posX
Rectangle’s X coordinate in millimeters within the current section.
posY
Rectangle’s Y coordinate in millimeters within the current section.
width
Rectangle’s width in millimeters.
height
Rectangle’s height in millimeters.
resource
Not used for rectangles since they are always static.
lineWidth
The width of the outline in millimeters
lineColor
The color of the rectangle’s outline in #RRGGBB format
fillColor
The fill color of the rectangle in #RRGGBB format
zValue
This integer number specifies Z-order value of the item. This value decides the stacking order of
sibling (neighboring) items.
printWhen
This logical script expression specifies the item’s visibility. If this expression is not empty, the
152
report engine evaluates it each time before rendering. If the logical expression returns true (or
1) the item is shown, otherwise the item is hidden.
26.14. Image
The Image option enables you to create Image items. Image items are used to insert either static or
dynamic into a report definition. Static images such as a company logo often displayed in the
Report Header can be loaded from a static file or from report definition. Dynamic images can be
loaded from the specified SQL data source.
id
Identification number for internal purposes (temporarily not used)
resource
Specifies the resource of the image item. Possible values are:
static
Image is loaded from report definition. The image must be saved into XML definition in Base64
encoded format* data source Image is loaded from data source (SQL database)* *file*Image is
loaded from the specified file. File might be with full path or relative to the program’s directory
posX
Image’s X coordinate in millimeters within the current section.
posY
Image’s Y coordinate in millimeters within the current section.
width
Image’s width in millimeters.
height
Image’s height in millimeters.
scaling
Logical option that specifies the image if is scaled or not. Possible values: true,false
aspectRatio
If scaling option is switched on, this property specifies the scaling method. Possible values:
153
ignore
The size of image is scaled freely. The aspect ratio is not preserved.* keep The size is scaled to a
rectangle as large as possible inside a given rectangle, preserving the aspect ratio.* expand The
size is scaled to a rectangle as small as possible outside a given rectangle, preserving the aspect
ratio.
zValue
This integer number specifies Z-order value of the item. This value decides the stacking order of
sibling (neighboring) items.
printWhen
This logical script expression specifies the item’s visibility. If this expression is not empty, the
report engine evaluates it each time before rendering. If the logical expression returns true (or
1) the item is shown, otherwise the item is hidden.
26.15. Barcode
The Barcode option enables you to create barcodes. Currently the EAN13 code format is supported.
Barcodes might be either static or dynamic items similar to images. Static barcodes read it’s value
from the report definition, dynamic barcodes are loaded from the specified data source.
<barcode>[code]</barcode>
<barcode>[data source.]column</barcode>
id
Identification number for internal purposes (temporarily not used)
resource
Specifies the resource of the barcode item. Possible values are:
static
Barcode is loaded from report definition. The barcode’s code must be specified in XML
definition* data source Barcode is loaded from data source
posX
Barcode’s X coordinate in millimeters within the current section.
posY
Barcode’s Y coordinate in millimeters within the current section.
width
Barcode’s width in millimeters.
154
height
Barcode’s height in millimeters.
barcodeType
The type name of the barcode. Possible values: EAN13
showCode
The logical property specifies if the code is shown under the barcode or not. Possible values:
true, false
sizeFactor
This integer property specifies the zooming factor of the barcode when it is rendering. This
property is very useful when we print barcodes to a high resolution device such as printer.
(Suggested value=10)
fontSize
The font size of the barcode’s text in points.
zValue
This integer number specifies Z-order value of the item. This value decides the stacking order of
sibling (neighboring) items.
printWhen
This logical script expression specifies the item’s visibility. If this expression is not empty, the
report engine evaluates it each time before rendering. If the logical expression returns true (or
1) the item is shown, otherwise the item is hidden.
• Add a Graph (Custom) item into your report in the designer and specify the size and the location
of this object.
• If need, add a static item definition for the object. If you set it’s resource to data source and fill
out the data source column, this information will come from the specified data source column.*
Derive the <classname>NCReportAbstractItemRendering</classname> class implementing it’s
paintItem method. You may 'stick' this class to your graph or any kind of rendering class by
multiple inheritance. The paintItem method gets the following parameters:
QPainter* painter
this is the painter pointer.
NCReportOutput* output
the output object pointer.
155
const QRectF& rect
the rectangle of the object in the specified output. The geometry of the rectangle is depending
on the output’s resolution.
<graph></graph>
id
Identification number for internal purposes (temporarily not used)
classID
Class ID text for custom item class identification
resourceSpecifies
the resource of the graph item. Possible values are:
static
Graph definition is loaded from report definition. The definition text must be existed in XML
definition* data source Graph definition text is loaded from data source
posX
Graph’s X coordinate in millimeters within the current section.
posY
Graph’s Y coordinate in millimeters within the current section.
width
Graph’s width in millimeters.
height
Graph’s height in millimeters.
zValue
This integer number specifies Z-order value of the item. This value decides the stacking order of
156
sibling (neighboring) items.
printWhen
This logical script expression specifies the item’s visibility. If this expression is not empty, the
report engine evaluates it each time before rendering. If the logical expression returns true (or
1) the item is shown, otherwise the item is hidden.
157