KD Reports API Documentation  2.2
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 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6 **
7 ** SPDX-License-Identifier: MIT
8 **
9 ****************************************************************************/
10 
11 #ifndef KDREPORTSREPORT_H
12 #define KDREPORTSREPORT_H
13 
14 #include "KDReportsErrorDetails.h"
15 #include "KDReportsGlobal.h"
16 
17 #include <QColor>
18 #include <QFont>
19 #include <QObject>
20 #include <QPrinter>
21 #include <QSizeF>
22 #include <QTextOption>
23 
24 #include <functional>
25 
26 QT_BEGIN_NAMESPACE
27 class QDomDocument;
28 class QTextDocumentFragment;
29 class QTextDocument;
30 class QDomElement;
31 class QDomNode;
32 class QAbstractItemModel;
33 class QIODevice;
34 class QRect;
35 class QPainter;
36 class ReportData;
37 class EditorData;
38 QT_END_NAMESPACE
39 
40 namespace KDReports {
41 
42 class MainTable;
43 class XmlParser;
44 class Element;
45 class HeaderReportBuilder;
46 class Header;
47 typedef Header Footer;
48 class ReportPrivate;
49 class ReportBuilder;
50 class TextDocument;
52 class AutoTableElement;
53 class XmlElementHandler;
54 
60 {
61  FirstPage = 1,
62  EvenPages = 2,
63  OddPages = 4,
64  LastPage = 8,
66 };
67 Q_DECLARE_FLAGS(HeaderLocations, HeaderLocation)
68 
69 
78 class KDREPORTS_EXPORT Report : public QObject
79 {
80  Q_OBJECT
81  Q_PROPERTY(QString documentName READ documentName WRITE setDocumentName)
82 
83 public:
88  explicit Report(QObject *parent = nullptr);
92  ~Report() override;
93 
95  {
96  WordProcessing = 0,
97  SpreadSheet = 1
98  };
99 
119  void setReportMode(ReportMode reportMode);
120 
125  ReportMode reportMode() const;
126 
131  void setDefaultFont(const QFont &font);
132 
137  QFont defaultFont() const;
138 
142  MainTable *mainTable() const;
143 
151  void addInlineElement(const Element &element);
152 
167  void addElement(const Element &element, Qt::AlignmentFlag horizontalAlignment = Qt::AlignLeft, const QColor &backgroundColor = QColor());
168 
174  void addVerticalSpacing(qreal space);
175 
182  void addFragment(const QTextDocumentFragment &fragment);
183 
195  void addPageBreak();
196 
218  void setTabPositions(const QList<QTextOption::Tab> &tabs);
219 
225  static QTextOption::Tab rightAlignedTab();
226 
233  static QTextOption::Tab middleAlignedTab();
234 
240  void setParagraphMargins(qreal left, qreal top, qreal right, qreal bottom);
241 
242 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
249  void setPageSize(QPrinter::PageSize size);
250 #endif
251 
257  void setPageSize(QPageSize::PageSizeId size);
258 
264  void setPageSize(const QPageSize &size);
265 
266 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
270  QPrinter::PageSize pageSize() const;
271 #else
275  QPageSize pageSize() const;
276 #endif
277 
282  void setPaperSize(QSizeF paperSize, QPrinter::Unit unit);
283 
284 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
289  Q_DECL_DEPRECATED void setOrientation(QPrinter::Orientation orientation);
294  Q_DECL_DEPRECATED QPrinter::Orientation orientation() const;
295 #endif
296 
300  void setPageOrientation(QPageLayout::Orientation orientation);
304  QPageLayout::Orientation pageOrientation() const;
305 
319  void setWidthForEndlessPrinter(qreal widthMM);
320 
324  void setMargins(qreal top, qreal left, qreal bottom, qreal right);
325 
329  void getMargins(qreal *top, qreal *left, qreal *bottom, qreal *right) const;
330 
335  void setTopPageMargin(qreal top);
336 
341  qreal topPageMargins() const;
342 
347  void setLeftPageMargin(qreal left);
348 
353  qreal leftPageMargins() const;
354 
359  void setRightPageMargin(qreal right);
360 
365  qreal rightPageMargins() const;
366 
371  void setBottomPageMargin(qreal bottom);
372 
377  qreal bottomPageMargins() const;
378 
384  void setHeaderBodySpacing(qreal spacing);
385 
390  qreal headerBodySpacing() const;
391 
397  void setFooterBodySpacing(qreal spacing);
398 
403  qreal footerBodySpacing() const;
404 
421  Header &header(HeaderLocations hl = AllPages);
422 
430  Footer &footer(HeaderLocations hl = AllPages);
431 
438  void associateModel(const QString &modelKey, QAbstractItemModel *model);
439 
450  void associateTextValue(const QString &id, const QString &value);
451 
461  void associateImageValue(const QString &id, const QPixmap &value);
462 
476  void associateImageValue(const QString &id, const QImage &value);
477 
488  bool loadFromXML(QIODevice *iodevice, ErrorDetails *details = nullptr);
489 
502  bool loadFromXML(const QDomDocument &doc, ErrorDetails *details = nullptr);
503 
512  void setXmlElementHandler(KDReports::XmlElementHandler *handler);
513 
520  void setCurrentRow(const QAbstractItemModel *model, int row);
521 
527  void setDocumentName(const QString &name);
528 
533  QString documentName() const;
534 
545  void setProgressDialogEnabled(bool enable);
546 
553  bool printWithDialog(QWidget *parent);
554 
568  bool print(QPrinter *printer, QWidget *parent = nullptr);
569 
578  bool exportToFile(const QString &fileName, QWidget *parent = nullptr);
579 
586  bool exportToImage(QSize size, const QString &fileName, const char *format);
587 
595  bool exportToHtml(const QString &fileName);
596 
604  void paintPage(int pageNumber, QPainter &painter);
605 
611  void setFirstPageNumber(int num);
612 
616  int firstPageNumber() const;
617 
621  int numberOfPages() const;
622 
626  bool isTableBreakingEnabled() const;
627 
629  {
631  RightThenDown
632  };
633 
641  void setTableBreakingPageOrder(TableBreakingPageOrder pageOrder);
642 
647  TableBreakingPageOrder tableBreakingPageOrder() const;
648 
658  void setFontScalingFactor(qreal factor);
659 
664  qreal fontScalingFactor() const;
665 
686  void scaleTo(int numPagesHorizontally, int numPagesVertically);
687 
692  int maximumNumberOfPagesForHorizontalScaling() const;
697  int maximumNumberOfPagesForVerticalScaling() const;
698 
704  void setFixedRowHeight(qreal mm);
705 
714  QList<KDReports::AutoTableElement *> autoTableElements() const;
715 
721  void regenerateAutoTables();
722 
728  void regenerateAutoTableForModel(QAbstractItemModel *model);
729 
739  void setWatermarkText(const QString &text, int rotation = 0, const QColor &color = QColor(204, 204, 204), const QFont &font = QFont(QStringLiteral("Helvetica"), 48));
740 
744  QString watermarkText() const;
745 
749  int watermarkRotation() const;
750 
754  QColor watermarkColor() const;
755 
759  QFont watermarkFont() const;
760 
771  void setWatermarkPixmap(const QPixmap &pixmap, bool autoGrayOut = true);
772 
778  QPixmap watermarkPixmap() const;
779 
784  void setWatermarkImage(const QImage &image);
785 
790  QImage watermarkImage() const;
791 
792  using WatermarkFunction = std::function<void(QPainter &, int)>;
800  void setWatermarkFunction(WatermarkFunction function);
801 
806  WatermarkFunction watermarkFunction() const;
807 
812  KDReports::HeaderLocations headerLocation(Header *header) const;
813 
818  KDReports::HeaderLocations footerLocation(KDReports::Footer *footer) const;
819 
824  void setHeaderLocation(HeaderLocations hl, Header *header);
825 
830  void setFooterLocation(HeaderLocations hl, Footer *footer);
831 
838  static qreal mmToPixels(qreal mm);
839 
843  QSizeF paperSize() const;
844 
848  void dump() const;
849 
853  int currentPosition() const;
854 
864  void beginEdit();
865 
873  void endEdit();
874 
883  QString anchorAt(int pageNumber, QPoint pos) const;
884 
897  QTextDocument *mainTextDocument() const;
898 
899 signals:
906  void printingProgress(int pageIndex);
907 
908 private:
909  friend class Test;
910  friend class ::ReportData;
911  friend class ::EditorData;
912  KDReports::TextDocument &doc() const;
913 
914  QString asHtml() const;
915 
916  void setupPrinter(QPrinter *printer);
917 
918 private:
919  Q_DISABLE_COPY(Report)
920  friend class HeaderReportBuilder; // for headerChanged()
921  friend class ImageElement; // for textDocumentWidth()
922  friend class ChartElement; // for textDocumentWidth()
923  friend class XmlParser; // d->m_builder
924  friend class Header; // doc()
925  friend class PreviewDialogPrivate; // setupPrinter
926  friend class PreviewWidgetPrivate; // setupPrinter
927  friend class ReportPrivate; // setupPrinter
928  std::unique_ptr<ReportPrivate> d;
929 };
930 
931 }
932 
933 #endif /* KDREPORTSREPORT_H */
#define KDREPORTS_EXPORT
std::function< void(QPainter &, int)> WatermarkFunction
void printingProgress(int pageIndex)
KDREPORTS_EXPORT qreal mmToPixels(qreal mm)
@ AllPages
All pages (except first and last if FirstPage or LastPage have their own headers)
@ FirstPage
The first page of the report.
@ EvenPages
The even pages of the report: 2, 4, 6 etc.
@ LastPage
The last page of the report.
@ OddPages
The odd pages of the report: 1 (unless FirstPage has its own header), 3, 5, 7 etc.

© 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 by doxygen 1.9.1