KD Reports API Documentation  2.0
KDReportsReport.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** This file is part of the KD Reports library.
4 **
5 ** SPDX-FileCopyrightText: 2007-2022 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6 **
7 ** SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDAB-KDReports OR LicenseRef-KDAB-KDReports-US
8 **
9 ** Licensees holding valid commercial KD Reports licenses may use this file in
10 ** accordance with the KD Reports Commercial License Agreement provided with
11 ** the Software.
12 **
13 ** Contact info@kdab.com if any conditions of this licensing are not clear to you.
14 **
15 ****************************************************************************/
16 
17 #ifndef KDREPORTSREPORT_H
18 #define KDREPORTSREPORT_H
19 
20 #include "KDReportsErrorDetails.h"
21 #include "KDReportsGlobal.h"
22 #include <QColor>
23 #include <QFont>
24 #include <QTextOption>
25 #include <QtCore/QSizeF>
26 
27 #include <QtPrintSupport/QPrinter>
28 
29 QT_BEGIN_NAMESPACE
30 class QDomDocument;
31 class QTextDocumentFragment;
32 class QTextDocument;
33 class QDomElement;
34 class QDomNode;
35 class QAbstractItemModel;
36 class QIODevice;
37 class QRect;
38 class QPainter;
39 class ReportData;
40 class EditorData;
41 QT_END_NAMESPACE
42 
43 namespace KDReports {
44 
45 class MainTable;
46 class XmlParser;
47 class Element;
48 class HeaderReportBuilder;
49 class Header;
50 typedef Header Footer;
51 class ReportPrivate;
52 class ReportBuilder;
53 class TextDocument;
54 class TableBreakingSettingsDialog;
55 class AutoTableElement;
56 class XmlElementHandler;
57 
63  FirstPage = 1,
64  EvenPages = 2,
65  OddPages = 4,
66  LastPage = 8,
68 };
69 Q_DECLARE_FLAGS(HeaderLocations, HeaderLocation)
70 
71 
80 class KDREPORTS_EXPORT Report : public QObject
81 {
82  Q_OBJECT
83  Q_PROPERTY(QString documentName READ documentName WRITE setDocumentName)
84 
85 public:
90  explicit Report(QObject *parent = nullptr);
94  ~Report() override;
95 
96  enum ReportMode { WordProcessing = 0,
97  SpreadSheet = 1 };
98 
118  void setReportMode(ReportMode reportMode);
119 
124  ReportMode reportMode() const;
125 
130  void setDefaultFont(const QFont &font);
131 
136  QFont defaultFont() const;
137 
141  MainTable *mainTable() const;
142 
150  void addInlineElement(const Element &element);
151 
166  void addElement(const Element &element, Qt::AlignmentFlag horizontalAlignment = Qt::AlignLeft, const QColor &backgroundColor = QColor());
167 
173  void addVerticalSpacing(qreal space);
174 
181  void addFragment(const QTextDocumentFragment &fragment);
182 
194  void addPageBreak();
195 
217  void setTabPositions(const QList<QTextOption::Tab> &tabs);
218 
224  static QTextOption::Tab rightAlignedTab();
225 
232  static QTextOption::Tab middleAlignedTab();
233 
239  void setParagraphMargins(qreal left, qreal top, qreal right, qreal bottom);
240 
241 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
242 
248  void setPageSize(QPrinter::PageSize size);
249 #endif
250 
256  void setPageSize(QPageSize::PageSizeId size);
257 
263  void setPageSize(const QPageSize &size);
264 
265 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
266 
269  QPrinter::PageSize pageSize() const;
270 #else
271 
274  QPageSize pageSize() const;
275 #endif
276 
281  void setPaperSize(QSizeF paperSize, QPrinter::Unit unit);
282 
283 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
284 
288  Q_DECL_DEPRECATED void setOrientation(QPrinter::Orientation orientation);
293  Q_DECL_DEPRECATED QPrinter::Orientation orientation() const;
294 #endif
295 
299  void setPageOrientation(QPageLayout::Orientation orientation);
303  QPageLayout::Orientation pageOrientation() const;
304 
318  void setWidthForEndlessPrinter(qreal widthMM);
319 
323  void setMargins(qreal top, qreal left, qreal bottom, qreal right);
324 
328  void getMargins(qreal *top, qreal *left, qreal *bottom, qreal *right) const;
329 
334  void setTopPageMargin(qreal top);
335 
340  qreal topPageMargins() const;
341 
346  void setLeftPageMargin(qreal left);
347 
352  qreal leftPageMargins() const;
353 
358  void setRightPageMargin(qreal right);
359 
364  qreal rightPageMargins() const;
365 
370  void setBottomPageMargin(qreal bottom);
371 
376  qreal bottomPageMargins() const;
377 
383  void setHeaderBodySpacing(qreal spacing);
384 
389  qreal headerBodySpacing() const;
390 
396  void setFooterBodySpacing(qreal spacing);
397 
402  qreal footerBodySpacing() const;
403 
420  Header &header(HeaderLocations hl = AllPages);
421 
429  Footer &footer(HeaderLocations hl = AllPages);
430 
437  void associateModel(const QString &modelKey, QAbstractItemModel *model);
438 
449  void associateTextValue(const QString &id, const QString &value);
450 
460  void associateImageValue(const QString &id, const QPixmap &value);
461 
475  void associateImageValue(const QString &id, const QImage &value);
476 
487  bool loadFromXML(QIODevice *iodevice, ErrorDetails *details = nullptr);
488 
501  bool loadFromXML(const QDomDocument &doc, ErrorDetails *details = nullptr);
502 
511  void setXmlElementHandler(KDReports::XmlElementHandler *handler);
512 
519  void setCurrentRow(const QAbstractItemModel *model, int row);
520 
526  void setDocumentName(const QString &name);
527 
532  QString documentName() const;
533 
539  bool printWithDialog(QWidget *parent);
540 
553  bool print(QPrinter *printer, QWidget *parent = nullptr);
554 
561  bool exportToFile(const QString &fileName, QWidget *parent = nullptr);
562 
569  bool exportToImage(QSize size, const QString &fileName, const char *format);
570 
578  bool exportToHtml(const QString &fileName);
579 
587  void paintPage(int pageNumber, QPainter &painter);
588 
594  void setFirstPageNumber(int num);
595 
599  int firstPageNumber() const;
600 
604  int numberOfPages() const;
605 
609  bool isTableBreakingEnabled() const;
610 
611  enum TableBreakingPageOrder { DownThenRight,
612  RightThenDown };
613 
621  void setTableBreakingPageOrder(TableBreakingPageOrder pageOrder);
622 
627  TableBreakingPageOrder tableBreakingPageOrder() const;
628 
638  void setFontScalingFactor(qreal factor);
639 
644  qreal fontScalingFactor() const;
645 
666  void scaleTo(int numPagesHorizontally, int numPagesVertically);
667 
672  int maximumNumberOfPagesForHorizontalScaling() const;
677  int maximumNumberOfPagesForVerticalScaling() const;
678 
684  void setFixedRowHeight(qreal mm);
685 
694  QList<KDReports::AutoTableElement *> autoTableElements() const;
695 
701  void regenerateAutoTables();
702 
708  void regenerateAutoTableForModel(QAbstractItemModel *model);
709 
719  void setWatermarkText(const QString &text, int rotation = 0, const QColor &color = QColor(204, 204, 204), const QFont &font = QFont(QStringLiteral("Helvetica"), 48));
720 
724  QString watermarkText() const;
725 
729  int watermarkRotation() const;
730 
734  QColor watermarkColor() const;
735 
739  QFont watermarkFont() const;
740 
751  void setWatermarkPixmap(const QPixmap &pixmap, bool autoGrayOut = true);
752 
758  QPixmap watermarkPixmap() const;
759 
764  void setWatermarkImage(const QImage &image);
765 
770  QImage watermarkImage() const;
771 
776  KDReports::HeaderLocations headerLocation(Header *header) const;
777 
782  KDReports::HeaderLocations footerLocation(KDReports::Footer *footer) const;
783 
788  void setHeaderLocation(HeaderLocations hl, Header *header);
789 
794  void setFooterLocation(HeaderLocations hl, Footer *footer);
795 
799  QSizeF paperSize() const;
800 
804  void dump() const;
805 
809  int currentPosition() const;
810 
820  void beginEdit();
821 
829  void endEdit();
830 
839  QString anchorAt(int pageNumber, QPoint pos) const;
840 
841 private:
842  friend class Test;
843  friend class ::ReportData;
844  friend class ::EditorData;
845  KDReports::TextDocument &doc() const;
846 
847  QString asHtml() const;
848 
849  void setupPrinter(QPrinter *printer);
850 
851 private:
852  Q_DISABLE_COPY(Report)
853  friend class HeaderReportBuilder; // for headerChanged()
854  friend class ImageElement; // for textDocumentWidth()
855  friend class ChartElement; // for textDocumentWidth()
856  friend class XmlParser; // d->m_builder
857  friend class Header; // doc()
858  friend class PreviewDialogPrivate; // setupPrinter
859  friend class PreviewWidgetPrivate; // setupPrinter
860  friend class ReportPrivate; // setupPrinter
861  ReportPrivate *const d;
862 };
863 
864 }
865 
866 #endif /* KDREPORTSREPORT_H */
KDReports::XmlParser
Definition: KDReportsXmlParser_p.h:52
KDReports::HeaderReportBuilder
Definition: KDReportsHeader_p.h:69
KDReports::FirstPage
@ FirstPage
The first page of the report.
Definition: KDReportsReport.h:63
QList< QTextOption::Tab >
KDReports::Element
Definition: KDReportsElement.h:39
KDReportsErrorDetails.h
KDReports::ReportPrivate
Definition: KDReportsReport_p.h:107
KDReports::XmlElementHandler
Definition: KDReportsXmlElementHandler.h:84
KDReports::Report
Definition: KDReportsReport.h:80
KDReports::TextDocument
Definition: KDReportsTextDocument_p.h:55
KDReports::AllPages
@ AllPages
All pages (except first and last if FirstPage or LastPage have their own headers)
Definition: KDReportsReport.h:67
KDReports::HeaderLocation
HeaderLocation
Definition: KDReportsReport.h:62
KDReports::EvenPages
@ EvenPages
The even pages of the report: 2, 4, 6 etc.
Definition: KDReportsReport.h:64
KDReports::Unit
Unit
Definition: KDReportsUnit.h:39
KDReports::OddPages
@ OddPages
The odd pages of the report: 1 (unless FirstPage has its own header), 3, 5, 7 etc.
Definition: KDReportsReport.h:65
KDReports::LastPage
@ LastPage
The last page of the report.
Definition: KDReportsReport.h:66
KDReports::ChartElement
Definition: KDReportsChartElement.h:41
KDReportsGlobal.h
KDReports::Report::ReportMode
ReportMode
Definition: KDReportsReport.h:96
KDReports::MainTable
Definition: KDReportsMainTable.h:57
KDReports::ErrorDetails
Definition: KDReportsErrorDetails.h:44
KDREPORTS_EXPORT
#define KDREPORTS_EXPORT
Definition: KDReportsGlobal.h:29
KDReports::Header
Definition: KDReportsHeader.h:49
KDReports::Footer
Header Footer
Definition: KDReportsHeader.h:127
KDReports::ImageElement
Definition: KDReportsImageElement.h:35
KDReports::Report::TableBreakingPageOrder
TableBreakingPageOrder
Definition: KDReportsReport.h:611
KDReports
Definition: KDReportsAbstractReportLayout_p.h:30

© 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 Sat Jan 8 2022 02:38:32 for KD Reports API Documentation by doxygen 1.8.17