KD Reports API Documentation  2.1
Public Types | Public Member Functions | Static Public Member Functions | Properties | List of all members
KDReports::Report Class Reference

#include <KDReportsReport.h>

Inheritance diagram for KDReports::Report:
Inheritance graph
[legend]
Collaboration diagram for KDReports::Report:
Collaboration graph
[legend]

Public Types

enum  ReportMode { WordProcessing = 0, SpreadSheet = 1 }
 
enum  TableBreakingPageOrder { DownThenRight, RightThenDown }
 

Public Member Functions

 Report (QObject *parent=nullptr)
 
 ~Report () override
 
void addElement (const Element &element, Qt::AlignmentFlag horizontalAlignment=Qt::AlignLeft, const QColor &backgroundColor=QColor())
 
void addFragment (const QTextDocumentFragment &fragment)
 
void addInlineElement (const Element &element)
 
void addPageBreak ()
 
void addVerticalSpacing (qreal space)
 
QString anchorAt (int pageNumber, QPoint pos) const
 
void associateImageValue (const QString &id, const QImage &value)
 
void associateImageValue (const QString &id, const QPixmap &value)
 
void associateModel (const QString &modelKey, QAbstractItemModel *model)
 
void associateTextValue (const QString &id, const QString &value)
 
QList< KDReports::AutoTableElement * > autoTableElements () const
 
void beginEdit ()
 
qreal bottomPageMargins () const
 
int currentPosition () const
 
QFont defaultFont () const
 
QString documentName () const
 
void dump () const
 
void endEdit ()
 
bool exportToFile (const QString &fileName, QWidget *parent=nullptr)
 
bool exportToHtml (const QString &fileName)
 
bool exportToImage (QSize size, const QString &fileName, const char *format)
 
int firstPageNumber () const
 
qreal fontScalingFactor () const
 
Footerfooter (HeaderLocations hl=AllPages)
 
qreal footerBodySpacing () const
 
KDReports::HeaderLocations footerLocation (KDReports::Footer *footer) const
 
void getMargins (qreal *top, qreal *left, qreal *bottom, qreal *right) const
 
Headerheader (HeaderLocations hl=AllPages)
 
qreal headerBodySpacing () const
 
KDReports::HeaderLocations headerLocation (Header *header) const
 
bool isTableBreakingEnabled () const
 
qreal leftPageMargins () const
 
bool loadFromXML (const QDomDocument &doc, ErrorDetails *details=nullptr)
 
bool loadFromXML (QIODevice *iodevice, ErrorDetails *details=nullptr)
 
MainTablemainTable () const
 
QTextDocumentmainTextDocument () const
 
int maximumNumberOfPagesForHorizontalScaling () const
 
int maximumNumberOfPagesForVerticalScaling () const
 
int numberOfPages () const
 
QPageLayout::Orientation pageOrientation () const
 
QPageSize pageSize () const
 
void paintPage (int pageNumber, QPainter &painter)
 
QSizeF paperSize () const
 
bool print (QPrinter *printer, QWidget *parent=nullptr)
 
bool printWithDialog (QWidget *parent)
 
void regenerateAutoTableForModel (QAbstractItemModel *model)
 
void regenerateAutoTables ()
 
ReportMode reportMode () const
 
qreal rightPageMargins () const
 
void scaleTo (int numPagesHorizontally, int numPagesVertically)
 Ensure that the report fits into a number of pages. More...
 
void setBottomPageMargin (qreal bottom)
 
void setCurrentRow (const QAbstractItemModel *model, int row)
 
void setDefaultFont (const QFont &font)
 
void setDocumentName (const QString &name)
 
void setFirstPageNumber (int num)
 
void setFixedRowHeight (qreal mm)
 
void setFontScalingFactor (qreal factor)
 Scale the fonts in the document by a given factor. More...
 
void setFooterBodySpacing (qreal spacing)
 
void setFooterLocation (HeaderLocations hl, Footer *footer)
 
void setHeaderBodySpacing (qreal spacing)
 
void setHeaderLocation (HeaderLocations hl, Header *header)
 
void setLeftPageMargin (qreal left)
 
void setMargins (qreal top, qreal left, qreal bottom, qreal right)
 
void setPageOrientation (QPageLayout::Orientation orientation)
 
void setPageSize (const QPageSize &size)
 
void setPageSize (QPageSize::PageSizeId size)
 
void setPaperSize (QSizeF paperSize, QPrinter::Unit unit)
 
void setParagraphMargins (qreal left, qreal top, qreal right, qreal bottom)
 
void setReportMode (ReportMode reportMode)
 
void setRightPageMargin (qreal right)
 
void setTableBreakingPageOrder (TableBreakingPageOrder pageOrder)
 
void setTabPositions (const QList< QTextOption::Tab > &tabs)
 
void setTopPageMargin (qreal top)
 
void setWatermarkImage (const QImage &image)
 
void setWatermarkPixmap (const QPixmap &pixmap, bool autoGrayOut=true)
 
void setWatermarkText (const QString &text, int rotation=0, const QColor &color=QColor(204, 204, 204), const QFont &font=QFont(QStringLiteral("Helvetica"), 48))
 
void setWidthForEndlessPrinter (qreal widthMM)
 
void setXmlElementHandler (KDReports::XmlElementHandler *handler)
 
TableBreakingPageOrder tableBreakingPageOrder () const
 
qreal topPageMargins () const
 
QColor watermarkColor () const
 
QFont watermarkFont () const
 
QImage watermarkImage () const
 
QPixmap watermarkPixmap () const
 
int watermarkRotation () const
 
QString watermarkText () const
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
virtual ~QObject ()
 
bool blockSignals (bool block)
 
const QObjectListchildren () const const
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectInfo ()
 
void dumpObjectInfo () const const
 
void dumpObjectTree ()
 
void dumpObjectTree () const const
 
QList< QByteArraydynamicPropertyNames () const const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
bool inherits (const char *className) const const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const const
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
QVariant property (const char *name) const const
 
 Q_CLASSINFO (Name, Value)
 
 Q_DISABLE_COPY (Class)
 
 Q_DISABLE_COPY_MOVE (Class)
 
 Q_DISABLE_MOVE (Class)
 
 Q_EMIT Q_EMIT
 
 Q_ENUM (...)
 
 Q_ENUM_NS (...)
 
 Q_ENUMS (...)
 
 Q_FLAG (...)
 
 Q_FLAG_NS (...)
 
 Q_FLAGS (...)
 
 Q_GADGET Q_GADGET
 
 Q_INTERFACES (...)
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 
 Q_OBJECT Q_OBJECT
 
 Q_PROPERTY (...)
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SLOT Q_SLOT
 
 Q_SLOTS Q_SLOTS
 
qFindChild (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
 
QList< T > qFindChildren (const QObject *obj, const QString &name)
 
qobject_cast (const QObject *object)
 
qobject_cast (QObject *object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const const
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds time, Qt::TimerType timerType)
 
QThreadthread () const const
 

Static Public Member Functions

static QTextOption::Tab middleAlignedTab ()
 
static QTextOption::Tab rightAlignedTab ()
 
- Static Public Member Functions inherited from QObject
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 

Properties

QString documentName
 
- Properties inherited from QObject
 objectName
 

Additional Inherited Members

- Public Attributes inherited from QObject
typedef QObjectList
 
- Protected Member Functions inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
int receivers (const char *signal) const const
 
QObjectsender () const const
 
int senderSignalIndex () const const
 
virtual void timerEvent (QTimerEvent *event)
 

Detailed Description

The Report class represents a report.

Initially the report is empty. Content can be added to the report using the addElement API, or using loadFromXML to load an equivalent definition from an XML file.

The report can then be previewed with PreviewDialog, printed, exported to PDF, or exported to an image.

Definition at line 80 of file KDReportsReport.h.

Member Enumeration Documentation

◆ ReportMode

Enumerator
WordProcessing 
SpreadSheet 

Definition at line 96 of file KDReportsReport.h.

◆ TableBreakingPageOrder

Enumerator
DownThenRight 
RightThenDown 

Definition at line 611 of file KDReportsReport.h.

Constructor & Destructor Documentation

◆ Report()

KDReports::Report::Report ( QObject parent = nullptr)
explicit

Constructs a report.

Parameters
parentoptional parent object, for memory management

Definition at line 445 of file KDReportsReport.cpp.

References QPageSize::A4, and setPageSize().

◆ ~Report()

KDReports::Report::~Report ( )
override

Destroys the report.

Definition at line 452 of file KDReportsReport.cpp.

Member Function Documentation

◆ addElement()

void KDReports::Report::addElement ( const Element element,
Qt::AlignmentFlag  horizontalAlignment = Qt::AlignLeft,
const QColor backgroundColor = QColor() 
)

Adds an element to the report, creating a new paragraph for it. You can specify the alignment of that paragraph.

An element defines what is added to the report. The report does not store the element, though. For this reason, any changes to the element after insertion will have no effect on the report. Set all settings in the element before calling addElement.

Parameters
elementthe definition of what to add to the report
horizontalAlignmentthe alignment of the paragraph created for this element
backgroundColorthe background color of the paragraph created for this element The difference with Element::setBackground is that it affects the whole paragraph, including any inline elements as well as the unused area up to the right margin of the page.

Definition at line 466 of file KDReportsReport.cpp.

◆ addFragment()

void KDReports::Report::addFragment ( const QTextDocumentFragment fragment)

Adds a piece of formatted text from a QTextDocument. This method is an optimization for the case where the initial text is in a QTextDocument (e.g. in a QTextEdit). In general you probably want to use addElement(HtmlElement()) instead.

Definition at line 956 of file KDReportsReport.cpp.

◆ addInlineElement()

void KDReports::Report::addInlineElement ( const Element element)

Adds an element to the report, next to the previous element, in the same paragraph.

An element defines what is added to the report. The report does not store the element, though. For this reason, any changes to the element after insertion will have no effect on the report. Set all settings in the element before calling addInlineElement.

Definition at line 456 of file KDReportsReport.cpp.

◆ addPageBreak()

void KDReports::Report::addPageBreak ( )

Adds a page break to the report. The next element added to the report will be at the top of a page.

Note that you cannot call addPageBreak twice in a row, it will only insert one page break. To get a completely empty page you need to insert an empty text element between both calls to addPageBreak.

Also note that exporting to an image, or using an endless printer, will remove all page breaks in the report.

Definition at line 928 of file KDReportsReport.cpp.

◆ addVerticalSpacing()

void KDReports::Report::addVerticalSpacing ( qreal  space)

Adds vertical spacing between paragraphs. Make sure to call addElement after that, not addInlineElement.

Parameters
spacethe space in millimeters

Definition at line 476 of file KDReportsReport.cpp.

◆ anchorAt()

QString KDReports::Report::anchorAt ( int  pageNumber,
QPoint  pos 
) const

Returns the target of the anchor at position pos, or an empty string if no anchor exists at that position.

Parameters
pageNumberThe page on which the mouse is, starting at 0
posThe position of the mouse, in pixels
Since
2.0

Definition at line 858 of file KDReportsReport.cpp.

References QRect::topLeft().

◆ associateImageValue() [1/2]

void KDReports::Report::associateImageValue ( const QString id,
const QImage value 
)

Associate an image with the id of an image element. This is only used if the report description is going to be loaded from an XML file, using loadFromXML. This method needs to be called before loadFromXML is called.

Parameters
idthe id of the image element, specified using id="foo" in the XML.
valuethe pixmap to use in the report. If associateImageValue was already called with the id id, the new value replaces the old one.

This overload is especially useful in threads.

Since
1.3

Definition at line 946 of file KDReportsReport.cpp.

◆ associateImageValue() [2/2]

void KDReports::Report::associateImageValue ( const QString id,
const QPixmap value 
)

Associate a pixmap with the id of an image element.

Parameters
idthe id of the image element, specified using id="foo" in the XML, or using ImageElement::setId().
valuethe pixmap to use in the report. If associateImageValue was already called with the id id, the new value replaces the old one.

Definition at line 941 of file KDReportsReport.cpp.

References QPixmap::toImage().

◆ associateModel()

void KDReports::Report::associateModel ( const QString modelKey,
QAbstractItemModel model 
)

Associates a model with a model key. This is only used if the report description is going to be loaded from an XML file, using loadFromXML. This method needs to be called before loadFromXML is called.

Definition at line 837 of file KDReportsReport.cpp.

◆ associateTextValue()

void KDReports::Report::associateTextValue ( const QString id,
const QString value 
)

Associate a text string with the id of a text or html element.

Parameters
idthe id of the text or html element, specified using id="foo" in the XML, or using TextElement::setId().
valuethe text for this element, which will appear in the report. The value can include newlines. If associateTextValue was already called with the id id, the new value replaces the old one.

Definition at line 933 of file KDReportsReport.cpp.

◆ autoTableElements()

QList< KDReports::AutoTableElement * > KDReports::Report::autoTableElements ( ) const

Returns a list of the auto-table elements that were used to create this report. You wouldn't normally need this method; this is only to be able to change some settings like showing table headers or table borders at runtime.

Since
1.1

Note: use mainTable() instead, in spreadsheet mode

Definition at line 1060 of file KDReportsReport.cpp.

◆ beginEdit()

void KDReports::Report::beginEdit ( )

Indicates that the elements are about to be added to the report. This makes report generation much faster, since the report doesn't have to be relayouted until endEdit() is called. It is possible to nest calls to beginEdit()/endEdit(), in which case only the topmost pair of calls will have an effect.

Since
1.6

Definition at line 848 of file KDReportsReport.cpp.

◆ bottomPageMargins()

qreal KDReports::Report::bottomPageMargins ( ) const
Returns
the bottom page margin in mm.
Since
1.4

Definition at line 630 of file KDReportsReport.cpp.

◆ currentPosition()

int KDReports::Report::currentPosition ( ) const

Definition at line 1155 of file KDReportsReport.cpp.

◆ defaultFont()

QFont KDReports::Report::defaultFont ( ) const
Returns
the default font used for text in this report
Since
1.4

Definition at line 967 of file KDReportsReport.cpp.

◆ documentName()

QString KDReports::Report::documentName ( ) const

Returns the name of the report.

Since
1.7

Definition at line 1083 of file KDReportsReport.cpp.

◆ dump()

void KDReports::Report::dump ( ) const

Definition at line 660 of file KDReportsReport.cpp.

◆ endEdit()

void KDReports::Report::endEdit ( )

Indicates that the end of a block of editing operations. It is possible to call beginEdit()/endEdit() again afterwards, for another block of editing operations.

Since
1.6

Definition at line 853 of file KDReportsReport.cpp.

◆ exportToFile()

bool KDReports::Report::exportToFile ( const QString fileName,
QWidget parent = nullptr 
)

Export the whole report to a PS or PDF file. If the file name has the suffix ".ps" then PostScript is automatically selected as output format. If the file name has the ".pdf" suffix PDF is generated.

Definition at line 713 of file KDReportsReport.cpp.

References QPrinter::setOutputFileName().

◆ exportToHtml()

bool KDReports::Report::exportToHtml ( const QString fileName)

Export the whole report to HTML. Note that HTML export does not include headers and footers, nor watermark.

Images are saved into separate files.

Since
1.2

Definition at line 724 of file KDReportsReport.cpp.

References QFile::open(), QString::toUtf8(), QIODevice::write(), and QIODevice::WriteOnly.

◆ exportToImage()

bool KDReports::Report::exportToImage ( QSize  size,
const QString fileName,
const char *  format 
)

Export the whole report to an image file.

Parameters
sizethe size of the image in pixels
fileNamethe name of the image file
formatthe format of the image, for instance: BMP, JPG, PNG.

Definition at line 736 of file KDReportsReport.cpp.

References QPainter::Antialiasing, QPainter::begin(), QImage::fill(), QPainter::fillRect(), QImage::Format_ARGB32_Premultiplied, QSize::height(), KDReports::mmToPixels(), QImage::save(), QPainter::scale(), QPainter::setRenderHint(), QImage::size(), QPainter::SmoothPixmapTransform, Qt::white, and QSize::width().

◆ firstPageNumber()

int KDReports::Report::firstPageNumber ( ) const
Returns
the number given to setFirstPageNumber

Definition at line 1165 of file KDReportsReport.cpp.

◆ fontScalingFactor()

qreal KDReports::Report::fontScalingFactor ( ) const
Returns
the font scaling factor given to setFontScalingFactor
Since
1.1

Definition at line 1019 of file KDReportsReport.cpp.

◆ footer()

KDReports::Header & KDReports::Report::footer ( HeaderLocations  hl = AllPages)
Returns
a reference to the footer object. Calling this method makes the report have a footer on the specified pages. See header() for caveats.

Specify the contents of the footer by calling Footer::addElement.

Definition at line 785 of file KDReportsReport.cpp.

◆ footerBodySpacing()

qreal KDReports::Report::footerBodySpacing ( ) const
Returns
the margin between the footer and the body of the report, in mm.
Since
1.4

Definition at line 989 of file KDReportsReport.cpp.

◆ footerLocation()

KDReports::HeaderLocations KDReports::Report::footerLocation ( KDReports::Footer footer) const
Returns
the location for the given footer.
Since
1.4

Definition at line 1150 of file KDReportsReport.cpp.

◆ getMargins()

void KDReports::Report::getMargins ( qreal *  top,
qreal *  left,
qreal *  bottom,
qreal *  right 
) const
Since
1.1

Definition at line 575 of file KDReportsReport.cpp.

◆ header()

KDReports::Header & KDReports::Report::header ( HeaderLocations  hl = AllPages)

Returns a reference to a header object. Calling this method makes the report have a header on the specified pages.

Calling the method with different sets of intersecting flags leads to undefined behavior. For instance header(EvenPages|FirstPage) and header(OddPages) is fine, but header(EvenPages|FirstPage) and header(FirstPage) leads to two headers being defined for the first page, anyone of the two could be picked. Calling the method with the same set multiple times, for instance header(EvenPages|FirstPage), is ok though: the same header instance will be returned every time.

Note that all headers will occupy the same height: the height of the tallest header.

Specify the contents of the header by calling Header::addElement.

Definition at line 770 of file KDReportsReport.cpp.

◆ headerBodySpacing()

qreal KDReports::Report::headerBodySpacing ( ) const
Returns
the margin between the header and the body of the report, in mm.
Since
1.4

Definition at line 978 of file KDReportsReport.cpp.

◆ headerLocation()

KDReports::HeaderLocations KDReports::Report::headerLocation ( KDReports::Header header) const
Returns
the location for the given header.
Since
1.4

Definition at line 1145 of file KDReportsReport.cpp.

◆ isTableBreakingEnabled()

bool KDReports::Report::isTableBreakingEnabled ( ) const
Returns
true when scaleTo was called with numPagesHorizontally > 0

Definition at line 1024 of file KDReportsReport.cpp.

◆ leftPageMargins()

qreal KDReports::Report::leftPageMargins ( ) const
Returns
the left page margin in mm.
Since
1.4

Definition at line 591 of file KDReportsReport.cpp.

◆ loadFromXML() [1/2]

bool KDReports::Report::loadFromXML ( const QDomDocument doc,
ErrorDetails details = nullptr 
)

This is an overloaded member function, provided for convenience. With this method you can modify the QDomDocument before giving it to KDReports.

Note: if the QDomDocument is simply created with a file or QIODevice as argument, it will ignore whitespace-only nodes like <text> </text>. The other loadFromXML takes care of this, while this overload requires that the QDomDocument has been properly set up.

Returns
true if the XML document was successfully loaded, false otherwise
Since
1.1

Definition at line 830 of file KDReportsReport.cpp.

References KDReports::XmlParser::processDocument().

◆ loadFromXML() [2/2]

bool KDReports::Report::loadFromXML ( QIODevice iodevice,
ErrorDetails details = nullptr 
)

Loads a report definition from an XML document. Notice that if the report definition contains Chart or Table elements, you need to call associate for each such element. iodevice needs to be open and readable. If you have any chart or table elements in your report, you must associate the models using associateModel() first, otherwise these elements will stay empty.

Returns
true if the XML document was successfully loaded, false otherwise

Definition at line 800 of file KDReportsReport.cpp.

References QIODevice::isOpen(), QIODevice::open(), QIODevice::ReadOnly, QIODevice::reset(), KDReports::ErrorDetails::setColumn(), QDomDocument::setContent(), KDReports::ErrorDetails::setDriverMessage(), and KDReports::ErrorDetails::setLine().

◆ mainTable()

KDReports::MainTable * KDReports::Report::mainTable ( ) const

Spreadsheet mode: returns the main table of the report.

Definition at line 1121 of file KDReportsReport.cpp.

◆ mainTextDocument()

QTextDocument * KDReports::Report::mainTextDocument ( ) const

Returns the QTextDocument that contains the main part of the report, assuming reportMode() is WordProcessing. Note that this does not include any headers or footers, nor watermark.

This method can be used to display the report in a readonly QTextEdit or in a QTextBrowser.

Modifying this QTextDocument will lead to undefined behaviour in KDReports. Returns nullptr if reportMode() is set to SpreadSheet.

Since
2.1

Definition at line 865 of file KDReportsReport.cpp.

◆ maximumNumberOfPagesForHorizontalScaling()

int KDReports::Report::maximumNumberOfPagesForHorizontalScaling ( ) const
Returns
the number of horizontal pages set with scaleTo, otherwise 1.
Since
1.1

Definition at line 999 of file KDReportsReport.cpp.

◆ maximumNumberOfPagesForVerticalScaling()

int KDReports::Report::maximumNumberOfPagesForVerticalScaling ( ) const
Returns
the number of vertical pages set with scaleTo, otherwise 0.
Since
1.1

Definition at line 1004 of file KDReportsReport.cpp.

◆ middleAlignedTab()

QTextOption::Tab KDReports::Report::middleAlignedTab ( )
static

Returns a tab position that is always center-aligned to the middle of the paper. This is convenient for having left-aligned, center-aligned (and potentially right-aligned) text on the same line.

Since
1.3, static
2.0

Definition at line 1136 of file KDReportsReport.cpp.

References QTextOption::CenterTab, and QChar::fromLatin1().

◆ numberOfPages()

int KDReports::Report::numberOfPages ( ) const
Returns
the report's number of pages (with the current page size).

Definition at line 654 of file KDReportsReport.cpp.

Referenced by KDReports::variableValue().

◆ pageOrientation()

QPageLayout::Orientation KDReports::Report::pageOrientation ( ) const
Returns
the orientation set by setPageOrientation. The default orientation is QPageLayout::Portrait.

Definition at line 559 of file KDReportsReport.cpp.

◆ pageSize()

QPageSize KDReports::Report::pageSize ( ) const
Returns
the page size set by setPageSize. The default page size is A4.

Definition at line 532 of file KDReportsReport.cpp.

◆ paintPage()

void KDReports::Report::paintPage ( int  pageNumber,
QPainter painter 
)

Paints a given page of the report into the painter. Note that this method can be used for printing and for on-screen rendering so it doesn't fill the background with white, the caller has do to that.

Parameters
pageNumberthe page to paint, starting at 0
painterthe QPainter to paint into

Definition at line 649 of file KDReportsReport.cpp.

◆ paperSize()

QSizeF KDReports::Report::paperSize ( ) const

Definition at line 951 of file KDReportsReport.cpp.

◆ print()

bool KDReports::Report::print ( QPrinter printer,
QWidget parent = nullptr 
)

Print directly using the setup values from a preexisting QPrinter object. Notice that this will only change settings like page sizes or orientation temporarily, during this particular print operation. After the operation, these values will be reset to their previous values.

Returns false if cancelled (not possible yet).

Parameters
printerthe printer to use for printing
parentthe parent widget for the progress dialog that appears when printing

Definition at line 686 of file KDReportsReport.cpp.

References QPageLayout::fullRectPixels(), QPrinter::pageLayout(), KDReports::pixelsToPointsMultiplier(), QPageSize::Point, QPrinter::resolution(), QPrinter::setFullPage(), QPrinter::setPageSize(), and QRect::size().

◆ printWithDialog()

bool KDReports::Report::printWithDialog ( QWidget parent)

Show the print dialog to let the user choose a printer, and print.

Parameters
parentthe parent widget for the progress dialog that appears when printing
Returns
false if the print dialog was cancelled

Definition at line 670 of file KDReportsReport.cpp.

References QDialog::Accepted.

◆ regenerateAutoTableForModel()

void KDReports::Report::regenerateAutoTableForModel ( QAbstractItemModel model)

Regenerate the contents of a single auto table. This can be useful if the data in this specific model changes frequently, to save time compared to recreating the full report.

Since
1.2

Definition at line 1054 of file KDReportsReport.cpp.

◆ regenerateAutoTables()

void KDReports::Report::regenerateAutoTables ( )

Regenerate the contents of auto tables. This can be useful if the data in the item model changes frequently, to save time compared to recreating the full report.

Since
1.1

Definition at line 1048 of file KDReportsReport.cpp.

◆ reportMode()

KDReports::Report::ReportMode KDReports::Report::reportMode ( ) const

Returns the mode set with setReportMode();

Since
1.3

Definition at line 1116 of file KDReportsReport.cpp.

◆ rightAlignedTab()

QTextOption::Tab KDReports::Report::rightAlignedTab ( )
static

Returns a tab position that is always right-aligned to the right edge of the paper. This is convenient for having left-aligned and right-aligned text on the same line.

Since
1.3, static
2.0

Definition at line 1127 of file KDReportsReport.cpp.

References QChar::fromLatin1(), and QTextOption::RightTab.

◆ rightPageMargins()

qreal KDReports::Report::rightPageMargins ( ) const
Returns
the right page margin in mm.
Since
1.4

Definition at line 604 of file KDReportsReport.cpp.

◆ scaleTo()

void KDReports::Report::scaleTo ( int  numPagesHorizontally,
int  numPagesVertically 
)

Ensure that the report fits into a number of pages.

By default tables are layouted so that all columns fit into the page width, but for large tables this can wrap the text too much. This method allows to scale the report so that it fits into a number of pages horizontally and vertically. For instance, 3 pages horizontally means that tables columns can span over 3 pages, arranged side by side. This is a maximum number of pages; if the table is really small it will still occupy only a single page.

Scaling also means that the font sizes can be reduced (similar to what setFontScalingFactor does) so that the report fits into the number of pages specified by this method.

Parameters
numPagesHorizontallynumber of pages in the horizontal direction, 1 for no table breaking in the horizontal direction.
numPagesVerticallynumber of pages in the vertical direction, 0 for no limit
Since
1.1

Definition at line 994 of file KDReportsReport.cpp.

◆ setBottomPageMargin()

void KDReports::Report::setBottomPageMargin ( qreal  bottom)

Sets the bottom page margins in mm. The default margin is 20 mm.

Since
1.4

Definition at line 622 of file KDReportsReport.cpp.

◆ setCurrentRow()

void KDReports::Report::setCurrentRow ( const QAbstractItemModel model,
int  row 
)

Sets the current row for the given model. When this value is set, it overrides the values of the 'row' attributes within XML tags

Since
1.3

Definition at line 1072 of file KDReportsReport.cpp.

◆ setDefaultFont()

void KDReports::Report::setDefaultFont ( const QFont font)

Sets the default font used for text in this report.

Since
1.1

Definition at line 961 of file KDReportsReport.cpp.

◆ setDocumentName()

void KDReports::Report::setDocumentName ( const QString name)

Sets the name of the report. This is used for QPrinter::setDocName(), which gives a name to the print job.

Since
1.7

Definition at line 1078 of file KDReportsReport.cpp.

◆ setFirstPageNumber()

void KDReports::Report::setFirstPageNumber ( int  num)

Sets the number of the first page, so that the variable PageNumber starts at another value than 1. This is useful when splitting a large report into smaller documents.

Definition at line 1160 of file KDReportsReport.cpp.

◆ setFixedRowHeight()

void KDReports::Report::setFixedRowHeight ( qreal  mm)

Sets a fixed row height. Only available in spreadsheet mode. The main use case is printing of fixed size labels.

Since
1.7

Definition at line 1009 of file KDReportsReport.cpp.

References KDReports::mmToPixels().

◆ setFontScalingFactor()

void KDReports::Report::setFontScalingFactor ( qreal  factor)

Scale the fonts in the document by a given factor.

Scale all the fonts used in the main part of the report (not headers and footers) by the given amount. Therefore setFontScalingFactor(1.0) is a no-op.

Since
1.1

Definition at line 1014 of file KDReportsReport.cpp.

◆ setFooterBodySpacing()

void KDReports::Report::setFooterBodySpacing ( qreal  spacing)

Sets the margin between the footer and the body of the report, in mm. This margin is 0 by default, i.e. the footer starts immediately under the body.

Since
1.1

Definition at line 983 of file KDReportsReport.cpp.

◆ setFooterLocation()

void KDReports::Report::setFooterLocation ( HeaderLocations  hl,
Footer footer 
)

Set the footer location

Since
1.4

Definition at line 792 of file KDReportsReport.cpp.

◆ setHeaderBodySpacing()

void KDReports::Report::setHeaderBodySpacing ( qreal  spacing)

Sets the margin between the header and the body of the report, in mm. This margin is 0 by default, i.e. the body starts immediately under the header.

Since
1.1

Definition at line 972 of file KDReportsReport.cpp.

◆ setHeaderLocation()

void KDReports::Report::setHeaderLocation ( HeaderLocations  hl,
Header header 
)

Set the header location

Since
1.4

Definition at line 777 of file KDReportsReport.cpp.

◆ setLeftPageMargin()

void KDReports::Report::setLeftPageMargin ( qreal  left)

Sets the left page margins in mm. The default margin is 20 mm.

Since
1.4

Definition at line 583 of file KDReportsReport.cpp.

◆ setMargins()

void KDReports::Report::setMargins ( qreal  top,
qreal  left,
qreal  bottom,
qreal  right 
)

Sets the page margins in mm. The default margins are 20 mm.

Definition at line 564 of file KDReportsReport.cpp.

◆ setPageOrientation()

void KDReports::Report::setPageOrientation ( QPageLayout::Orientation  orientation)

Sets the orientation, QPageLayout::Portrait or QPageLayout::Landscape.

Definition at line 552 of file KDReportsReport.cpp.

◆ setPageSize() [1/2]

void KDReports::Report::setPageSize ( const QPageSize size)

Sets the page size of the report. Example: setPageSize(QPageSize::A4) or setPageSize(QPageSize::Letter); Note that for performance reasons, it is recommended to do this after adding all the elements to the report rather than before.

Definition at line 497 of file KDReportsReport.cpp.

◆ setPageSize() [2/2]

void KDReports::Report::setPageSize ( QPageSize::PageSizeId  size)

Sets the page size of the report. Example: setPageSize(QPageSize::A4) or setPageSize(QPageSize::Letter); Note that for performance reasons, it is recommended to do this after adding all the elements to the report rather than before.

Definition at line 492 of file KDReportsReport.cpp.

Referenced by Report().

◆ setPaperSize()

void KDReports::Report::setPaperSize ( QSizeF  paperSize,
QPrinter::Unit  unit 
)

Sets a custom paper size for the report. Supported units are DevicePixel, Millimeter, Point and Inch.

Definition at line 504 of file KDReportsReport.cpp.

References QPrinter::DevicePixel, QSizeF::height(), QPrinter::Inch, QPrinter::Millimeter, KDReports::mmToPixels(), QPrinter::Point, qt_defaultDpi(), and QSizeF::width().

◆ setParagraphMargins()

void KDReports::Report::setParagraphMargins ( qreal  left,
qreal  top,
qreal  right,
qreal  bottom 
)

Sets the paragraph margins for all paragraph elements to be created from now on. The default margins are 0,0,0,0.

Since
1.3

Definition at line 1093 of file KDReportsReport.cpp.

◆ setReportMode()

void KDReports::Report::setReportMode ( ReportMode  reportMode)

Sets the main mode of the report: word-processing or spread-sheet (one large table). The word-processing mode is the most generic one, where text, images, tables etc. can be mixed into a single report. The spread-sheet mode is specific to "one large table", which gives additional features like table breaking over multiple pages horizontally. This is very similar to the difference between word processors and spreadsheets in most office suites.

A note about tables: in word-processing mode, the text of table cells can wrap, if the table is too wide for the page. In spread-sheet mode, table cells do not wrap. Instead, the font is adapted so that the table fits. In spread-sheet mode, the same font is used for all table cells, for layouting and performance reasons.

It is very important to set the mode of the report before doing anything else with the report.

Since
1.3

Definition at line 1098 of file KDReportsReport.cpp.

◆ setRightPageMargin()

void KDReports::Report::setRightPageMargin ( qreal  right)

Sets the right page margins in mm. The default margin is 20 mm.

Since
1.4

Definition at line 596 of file KDReportsReport.cpp.

◆ setTableBreakingPageOrder()

void KDReports::Report::setTableBreakingPageOrder ( TableBreakingPageOrder  pageOrder)

Sets the page order to use when breaking tables. This method is kept for compatibility, use mainTable()->setTableBreakingPageOrder() in new code, instead.

Since
1.1

Definition at line 1029 of file KDReportsReport.cpp.

◆ setTabPositions()

void KDReports::Report::setTabPositions ( const QList< QTextOption::Tab > &  tabs)

Set the list of tabs (tabulations) to use when adding paragraph elements. Those tabs will be set for any paragraph element that is added from now on, until calling this method again.

This method allows to align numbers based on their decimal separator, for instance. Example:

tab.position = 50; // in mm
tab.delimiter = QLatin1Char( '.' );
tabs.append( tab );
report.setTabPositions( tabs );
Then insert text using a tab, like TextElement("\t123.456").
Since
1.2

Definition at line 1088 of file KDReportsReport.cpp.

◆ setTopPageMargin()

void KDReports::Report::setTopPageMargin ( qreal  top)

Sets the top page margins in mm. The default margin is 20 mm.

Since
1.4

Definition at line 609 of file KDReportsReport.cpp.

◆ setWatermarkImage()

void KDReports::Report::setWatermarkImage ( const QImage image)

Same as setWatermarkPixmap but with a QImage. Especially useful in threads.

Since
1.2

Definition at line 918 of file KDReportsReport.cpp.

◆ setWatermarkPixmap()

void KDReports::Report::setWatermarkPixmap ( const QPixmap pixmap,
bool  autoGrayOut = true 
)

Sets the pixmap to be used as a watermark. By default, the image will be "grayed out" much like QIcon does for disabled pixmaps. If you do not want this behavior, set autoGrayOut to false. However, you need to ensure then that the image does prevent the legibility of the report. The pixmap will not be scaled, it will be centered on the page. You can set both a watermark text and a watermark image, but the two will overwrite each other so this is not recommended.

Definition at line 902 of file KDReportsReport.cpp.

References QIcon::Disabled, QGuiApplication::palette(), and QPixmap::toImage().

◆ setWatermarkText()

void KDReports::Report::setWatermarkText ( const QString text,
int  rotation = 0,
const QColor color = QColor(204, 204, 204),
const QFont font = QFont(QStringLiteral("Helvetica"), 48) 
)

Sets the text to be used as a watermark. By default, the text will be displayed with 0 degrees rotation, in a light gray, in a 48pt Helvetica font, centered on the page. You can set both a watermark text and a watermark image, but the two will overwrite each other so this is not recommended. Also notice that if you choose a watermark color that is too dark, this will make the reports less legible.

Definition at line 874 of file KDReportsReport.cpp.

◆ setWidthForEndlessPrinter()

void KDReports::Report::setWidthForEndlessPrinter ( qreal  widthMM)

Set a custom page size for an endless printer. The page width is known, the document is laid out without pagination within that width. The page height is set automatically so that the entire document fits within one page.

When calling setWidthForEndlessPrinter you don't have to call setPageSize or setOrientation.

Call setWidthForEndlessPrinter(0) to reset to normal (pagesize-dependent) behavior.

NOTE: with Qt-4.3, this feature only works reliably on Unix, using Qt compiled with CUPS support. With Qt-4.4, there is no such limitation and this feature should work everywhere.

Definition at line 635 of file KDReportsReport.cpp.

References KDReports::mmToPixels().

◆ setXmlElementHandler()

void KDReports::Report::setXmlElementHandler ( KDReports::XmlElementHandler handler)

Sets an xml element handler. The report does not take ownership of the xml element handler.

If you want it to be deleted with the report, derive from both QObject and XmlElementHandler and give the report as parent QObject.

Since
1.2

Definition at line 1067 of file KDReportsReport.cpp.

◆ tableBreakingPageOrder()

KDReports::Report::TableBreakingPageOrder KDReports::Report::tableBreakingPageOrder ( ) const
Returns
the table breaking page order given to setTableBreakingPageOrder
Since
1.1

Definition at line 1038 of file KDReportsReport.cpp.

◆ topPageMargins()

qreal KDReports::Report::topPageMargins ( ) const
Returns
the top page margin in mm.
Since
1.4

Definition at line 617 of file KDReportsReport.cpp.

◆ watermarkColor()

QColor KDReports::Report::watermarkColor ( ) const
Returns
the watermark text color.

Definition at line 892 of file KDReportsReport.cpp.

◆ watermarkFont()

QFont KDReports::Report::watermarkFont ( ) const
Returns
the watermark text font.

Definition at line 897 of file KDReportsReport.cpp.

◆ watermarkImage()

QImage KDReports::Report::watermarkImage ( ) const
Returns
the image to be used as watermark.
Since
1.2

Definition at line 923 of file KDReportsReport.cpp.

◆ watermarkPixmap()

QPixmap KDReports::Report::watermarkPixmap ( ) const
Returns
the image to be used as watermark. If autoGrayOut was used when calling setWatermarkPixmap, this is not the same pixmap as was passed to setWatermarkPixmap.

Definition at line 913 of file KDReportsReport.cpp.

References QPixmap::fromImage().

◆ watermarkRotation()

int KDReports::Report::watermarkRotation ( ) const
Returns
the watermark text rotation.

Definition at line 887 of file KDReportsReport.cpp.

◆ watermarkText()

QString KDReports::Report::watermarkText ( ) const
Returns
the watermark text.

Definition at line 882 of file KDReportsReport.cpp.

Property Documentation

◆ documentName

QString KDReports::Report::documentName
readwrite

Definition at line 50 of file KDReportsReport.h.


The documentation for this class was generated from the following files:
QList::append
void append(const T &value)
QTextOption::Tab
QTextOption::DelimiterTab
DelimiterTab
QList< QTextOption::Tab >
KDReports::Report::setTabPositions
void setTabPositions(const QList< QTextOption::Tab > &tabs)
Definition: KDReportsReport.cpp:1088
QLatin1Char

© 2007-2021 Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
https://www.kdab.com/development-resources/qt-tools/kd-reports/
Generated on Fri Jul 15 2022 13:09:07 for KD Reports API Documentation by doxygen 1.8.20