KD Reports  1.9
KDReportsReport.h
1 /****************************************************************************
2 **
3 ** This file is part of the KD Reports library.
4 **
5 ** SPDX-FileCopyrightText: 2007-2020 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 <QtCore/QSizeF>
23 #include <QColor>
24 #include <QFont>
25 #include <QTextOption>
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 
82  FirstPage = 1,
83  EvenPages = 2,
84  OddPages = 4,
85  LastPage = 8,
87 };
88 Q_DECLARE_FLAGS( HeaderLocations, HeaderLocation )
89 
90 
99 class KDREPORTS_EXPORT Report : public QObject
100 {
101  Q_OBJECT
102  Q_PROPERTY(QString documentName READ documentName WRITE setDocumentName)
103 
104 public:
109  explicit Report( QObject* parent = 0 );
113  ~Report() override;
114 
115  enum ReportMode {
116  WordProcessing = 0,
117  SpreadSheet = 1
118  };
119 
139  void setReportMode( ReportMode reportMode );
140 
145  ReportMode reportMode() const;
146 
151  void setDefaultFont( const QFont& font );
152 
157  QFont defaultFont() const;
158 
162  MainTable* mainTable() const;
163 
171  void addInlineElement( const Element& element );
172 
187  void addElement( const Element& element, Qt::AlignmentFlag horizontalAlignment = Qt::AlignLeft,
188  const QColor& backgroundColor = QColor() );
189 
195  void addVerticalSpacing( qreal space );
196 
203  void addFragment( const QTextDocumentFragment& fragment );
204 
216  void addPageBreak();
217 
239  void setTabPositions( const QList<QTextOption::Tab>& tabs );
240 
246  QTextOption::Tab rightAlignedTab() const;
247 
254  QTextOption::Tab middleAlignedTab() const;
255 
261  void setParagraphMargins( qreal left, qreal top, qreal right, qreal bottom );
262 
268  void setPageSize( const QPrinter::PageSize& size );
269 
274  void setPaperSize( const QSizeF & paperSize, QPrinter::Unit unit );
275 
279  QPrinter::PageSize pageSize() const;
283  void setOrientation( QPrinter::Orientation orientation );
287  QPrinter::Orientation orientation() const;
288 
302  void setWidthForEndlessPrinter( qreal widthMM );
303 
307  void setMargins( qreal top, qreal left, qreal bottom, qreal right );
308 
313  void getMargins( qreal* top, qreal* left, qreal* bottom, qreal* right ) const;
314 
319  void setTopPageMargin( qreal top );
320 
325  qreal topPageMargins() const;
326 
331  void setLeftPageMargin( qreal left );
332 
337  qreal leftPageMargins() const;
338 
343  void setRightPageMargin( qreal right );
344 
349  qreal rightPageMargins() const;
350 
355  void setBottomPageMargin( qreal bottom );
356 
361  qreal bottomPageMargins() const;
362 
368  void setHeaderBodySpacing( qreal spacing );
369 
374  qreal headerBodySpacing() const;
375 
381  void setFooterBodySpacing( qreal spacing );
382 
387  qreal footerBodySpacing() const;
388 
405  Header& header( HeaderLocations hl = AllPages );
406 
414  Footer& footer( HeaderLocations hl = AllPages );
415 
422  void associateModel( const QString& modelKey, QAbstractItemModel* model );
423 
434  void associateTextValue( const QString& id, const QString& value );
435 
445  void associateImageValue( const QString& id, const QPixmap& value );
446 
460  void associateImageValue( const QString& id, const QImage& value );
461 
472  bool loadFromXML( QIODevice* iodevice, ErrorDetails* details = 0 );
473 
486  bool loadFromXML( const QDomDocument& doc, ErrorDetails* details = 0 );
487 
496  void setXmlElementHandler( KDReports::XmlElementHandler* handler );
497 
504  void setCurrentRow( const QAbstractItemModel *model, int row );
505 
511  void setDocumentName( const QString &name );
512 
517  QString documentName() const;
518 
524  bool printWithDialog( QWidget* parent );
525 
538  bool print( QPrinter* printer, QWidget* parent = 0 );
539 
546  bool exportToFile( const QString& fileName, QWidget* parent = 0 );
547 
554  bool exportToImage( const QSize& size, const QString& fileName, const char* format );
555 
563  bool exportToHtml( const QString& fileName );
564 
570  void paintPage( int pageNumber, QPainter& painter );
571 
577  void setFirstPageNumber( int num );
578 
582  int firstPageNumber() const;
583 
587  int numberOfPages() const;
588 
612  void setTableBreakingEnabled( bool tableBreakingEnabled );
613 
618  bool isTableBreakingEnabled() const;
619 
620  enum TableBreakingPageOrder { DownThenRight, RightThenDown };
621 
629  void setTableBreakingPageOrder( TableBreakingPageOrder pageOrder );
630 
635  TableBreakingPageOrder tableBreakingPageOrder() const;
636 
646  void setFontScalingFactor( qreal factor );
647 
652  qreal fontScalingFactor() const;
653 
676  void scaleTo( int numPagesHorizontally, int numPagesVertically );
677 
682  int maximumNumberOfPagesForHorizontalScaling() const;
687  int maximumNumberOfPagesForVerticalScaling() const;
688 
694  void setFixedRowHeight( qreal mm );
695 
704  QList<KDReports::AutoTableElement *> autoTableElements() const;
705 
711  void regenerateAutoTables();
712 
718  void regenerateAutoTableForModel( QAbstractItemModel* model );
719 
729  void setWatermarkText( const QString& text,
730  int rotation = 0,
731  const QColor& color = QColor( 204, 204, 204 ),
732  const QFont& font = QFont( QLatin1String( "Helvetica" ), 48 ) );
733 
737  QString watermarkText() const;
738 
742  int watermarkRotation() const;
743 
747  QColor watermarkColor() const;
748 
752  QFont watermarkFont() const;
753 
764  void setWatermarkPixmap( const QPixmap& pixmap, bool autoGrayOut = true );
765 
771  QPixmap watermarkPixmap() const;
772 
777  void setWatermarkImage( const QImage& image );
778 
783  QImage watermarkImage() const;
784 
789  KDReports::HeaderLocations headerLocation(Header* header) const;
790 
795  KDReports::HeaderLocations footerLocation(KDReports::Footer *footer) const;
796 
801  void setHeaderLocation(HeaderLocations hl, Header *header);
802 
807  void setFooterLocation(HeaderLocations hl, Footer *footer);
808 
812  QSizeF paperSize() const;
813 
817  void dump() const;
818 
822  int currentPosition() const;
823 
833  void beginEdit();
834 
842  void endEdit();
843 
844 private:
845  friend class Test;
846  friend class ::ReportData;
847  friend class ::EditorData;
848  KDReports::TextDocument& doc() const;
849 
850  QString asHtml() const;
851 
852  void setupPrinter( QPrinter* printer );
853 
854 private:
855  Q_DISABLE_COPY( Report )
856  friend class HeaderReportBuilder; // for headerChanged()
857  friend class ImageElement; // for textDocumentWidth()
858  friend class ChartElement; // for textDocumentWidth()
859  friend class XmlParser; // d->m_builder
860  friend class Header; // doc()
861  friend class PreviewDialogPrivate; // setupPrinter
862  friend class PreviewWidgetPrivate; // setupPrinter
863  friend class ReportPrivate; // setupPrinter
864  ReportPrivate* const d;
865 };
866 
867 }
868 
869 #endif /* KDREPORTSREPORT_H */
Definition: KDReportsReport.h:99
HeaderLocation
Definition: KDReportsReport.h:81
Definition: KDReportsXmlElementHandler.h:80
The first page of the report.
Definition: KDReportsReport.h:82
Definition: KDReportsMainTable.h:44
Definition: KDReportsHeader.h:48
Definition: KDReportsImageElement.h:35
All pages (except first and last if FirstPage or LastPage have their own headers) ...
Definition: KDReportsReport.h:86
Definition: KDReportsAbstractTableElement.h:30
The odd pages of the report: 1 (unless FirstPage has its own header), 3, 5, 7 etc.
Definition: KDReportsReport.h:84
The last page of the report.
Definition: KDReportsReport.h:85
Definition: KDReportsElement.h:39
The even pages of the report: 2, 4, 6 etc.
Definition: KDReportsReport.h:83
Definition: KDReportsErrorDetails.h:30
Definition: KDReportsChartElement.h:39
Definition: KDReportsAbstractTableElement.h:24

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/