KD Reports  1.8
KDReportsReport.h
1 /****************************************************************************
2 ** Copyright (C) 2007-2020 Klaralvdalens Datakonsult AB. All rights reserved.
3 **
4 ** This file is part of the KD Reports library.
5 **
6 ** Licensees holding valid commercial KD Reports licenses may use this file in
7 ** accordance with the KD Reports Commercial License Agreement provided with
8 ** the Software.
9 **
10 **
11 ** This file may be distributed and/or modified under the terms of the
12 ** GNU Lesser General Public License version 2.1 and version 3 as published by the
13 ** Free Software Foundation and appearing in the file LICENSE.LGPL.txt included.
14 **
15 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 **
18 ** Contact info@kdab.com if any conditions of this licensing are not
19 ** clear to you.
20 **
21 **********************************************************************/
22 
23 #ifndef KDREPORTSREPORT_H
24 #define KDREPORTSREPORT_H
25 
26 #include "KDReportsErrorDetails.h"
27 #include "KDReportsGlobal.h"
28 #include <QtCore/QSizeF>
29 #include <QColor>
30 #include <QFont>
31 #include <QTextOption>
32 
33 #if (QT_VERSION >= QT_VERSION_CHECK(5,0,0))
34 #include <QtPrintSupport/QPrinter>
35 #else
36 #include <QPrinter>
37 #endif
38 
39 QT_BEGIN_NAMESPACE
40 class QDomDocument;
41 class QTextDocumentFragment;
42 class QTextDocument;
43 class QDomElement;
44 class QDomNode;
45 class QAbstractItemModel;
46 class QIODevice;
47 class QRect;
48 class QPainter;
49 class ReportData;
50 class EditorData;
51 QT_END_NAMESPACE
52 
53 namespace KDReports {
54 
55 class MainTable;
56 class XmlParser;
57 class Element;
58 class HeaderReportBuilder;
59 class Header;
60 typedef Header Footer;
61 class ReportPrivate;
62 class ReportBuilder;
63 class TextDocument;
64 class TableBreakingSettingsDialog;
65 class AutoTableElement;
66 class XmlElementHandler;
67 
92  FirstPage = 1,
93  EvenPages = 2,
94  OddPages = 4,
95  LastPage = 8,
97 };
98 Q_DECLARE_FLAGS( HeaderLocations, HeaderLocation )
99 
100 
109 class KDREPORTS_EXPORT Report : public QObject
110 {
111  Q_OBJECT
112  Q_PROPERTY(QString documentName READ documentName WRITE setDocumentName)
113 
114 public:
119  explicit Report( QObject* parent = 0 );
123  ~Report();
124 
125  enum ReportMode {
126  WordProcessing = 0,
127  SpreadSheet = 1
128  };
129 
149  void setReportMode( ReportMode reportMode );
150 
155  ReportMode reportMode() const;
156 
161  void setDefaultFont( const QFont& font );
162 
167  QFont defaultFont() const;
168 
172  MainTable* mainTable() const;
173 
181  void addInlineElement( const Element& element );
182 
197  void addElement( const Element& element, Qt::AlignmentFlag horizontalAlignment = Qt::AlignLeft,
198  const QColor& backgroundColor = QColor() );
199 
205  void addVerticalSpacing( qreal space );
206 
213  void addFragment( const QTextDocumentFragment& fragment );
214 
226  void addPageBreak();
227 
249  void setTabPositions( const QList<QTextOption::Tab>& tabs );
250 
256  QTextOption::Tab rightAlignedTab() const;
257 
264  QTextOption::Tab middleAlignedTab() const;
265 
271  void setParagraphMargins( qreal left, qreal top, qreal right, qreal bottom );
272 
278  void setPageSize( const QPrinter::PageSize& size );
279 
285  void setPaperSize( const QSizeF & paperSize, QPrinter::Unit unit );
286 
290  QPrinter::PageSize pageSize() const;
294  void setOrientation( QPrinter::Orientation orientation );
298  QPrinter::Orientation orientation() const;
299 
313  void setWidthForEndlessPrinter( qreal widthMM );
314 
318  void setMargins( qreal top, qreal left, qreal bottom, qreal right );
319 
324  void getMargins( qreal* top, qreal* left, qreal* bottom, qreal* right ) const;
325 
330  void setTopPageMargin( qreal top );
331 
336  qreal topPageMargins() const;
337 
342  void setLeftPageMargin( qreal left );
343 
348  qreal leftPageMargins() const;
349 
354  void setRightPageMargin( qreal right );
355 
360  qreal rightPageMargins() const;
361 
366  void setBottomPageMargin( qreal bottom );
367 
372  qreal bottomPageMargins() const;
373 
379  void setHeaderBodySpacing( qreal spacing );
380 
385  qreal headerBodySpacing() const;
386 
392  void setFooterBodySpacing( qreal spacing );
393 
398  qreal footerBodySpacing() const;
399 
416  Header& header( HeaderLocations hl = AllPages );
417 
425  Footer& footer( HeaderLocations hl = AllPages );
426 
433  void associateModel( const QString& modelKey, QAbstractItemModel* model );
434 
445  void associateTextValue( const QString& id, const QString& value );
446 
456  void associateImageValue( const QString& id, const QPixmap& value );
457 
471  void associateImageValue( const QString& id, const QImage& value );
472 
483  bool loadFromXML( QIODevice* iodevice, ErrorDetails* details = 0 );
484 
497  bool loadFromXML( const QDomDocument& doc, ErrorDetails* details = 0 );
498 
507  void setXmlElementHandler( KDReports::XmlElementHandler* handler );
508 
515  void setCurrentRow( const QAbstractItemModel *model, int row );
516 
522  void setDocumentName( const QString &name );
523 
528  QString documentName() const;
529 
535  bool printWithDialog( QWidget* parent );
536 
549  bool print( QPrinter* printer, QWidget* parent = 0 );
550 
557  bool exportToFile( const QString& fileName, QWidget* parent = 0 );
558 
565  bool exportToImage( const QSize& size, const QString& fileName, const char* format );
566 
574  bool exportToHtml( const QString& fileName );
575 
581  void paintPage( int pageNumber, QPainter& painter );
582 
588  void setFirstPageNumber( int num );
589 
593  int firstPageNumber() const;
594 
598  int numberOfPages() const;
599 
623  void setTableBreakingEnabled( bool tableBreakingEnabled );
624 
629  bool isTableBreakingEnabled() const;
630 
631  enum TableBreakingPageOrder { DownThenRight, RightThenDown };
632 
640  void setTableBreakingPageOrder( TableBreakingPageOrder pageOrder );
641 
646  TableBreakingPageOrder tableBreakingPageOrder() const;
647 
657  void setFontScalingFactor( qreal factor );
658 
663  qreal fontScalingFactor() const;
664 
687  void scaleTo( int numPagesHorizontally, int numPagesVertically );
688 
693  int maximumNumberOfPagesForHorizontalScaling() const;
698  int maximumNumberOfPagesForVerticalScaling() const;
699 
705  void setFixedRowHeight( qreal mm );
706 
715  QList<KDReports::AutoTableElement *> autoTableElements() const;
716 
722  void regenerateAutoTables();
723 
729  void regenerateAutoTableForModel( QAbstractItemModel* model );
730 
740  void setWatermarkText( const QString& text,
741  int rotation = 0,
742  const QColor& color = QColor( 204, 204, 204 ),
743  const QFont& font = QFont( QLatin1String( "Helvetica" ), 48 ) );
744 
748  QString watermarkText() const;
749 
753  int watermarkRotation() const;
754 
758  QColor watermarkColor() const;
759 
763  QFont watermarkFont() const;
764 
775  void setWatermarkPixmap( const QPixmap& pixmap, bool autoGrayOut = true );
776 
782  QPixmap watermarkPixmap() const;
783 
788  void setWatermarkImage( const QImage& image );
789 
794  QImage watermarkImage() const;
795 
800  KDReports::HeaderLocations headerLocation(Header* header) const;
801 
806  KDReports::HeaderLocations footerLocation(KDReports::Footer *footer) const;
807 
812  void setHeaderLocation(HeaderLocations hl, Header *header);
813 
818  void setFooterLocation(HeaderLocations hl, Footer *footer);
819 
823  QSizeF paperSize() const;
824 
828  void dump() const;
829 
833  int currentPosition() const;
834 
844  void beginEdit();
845 
853  void endEdit();
854 
855 private:
856  friend class Test;
857  friend class ::ReportData;
858  friend class ::EditorData;
859  KDReports::TextDocument& doc() const;
860 
861  QString asHtml() const;
862 
863  void setupPrinter( QPrinter* printer );
864 
865 private:
866  Q_DISABLE_COPY( Report )
867  friend class HeaderReportBuilder; // for headerChanged()
868  friend class ImageElement; // for textDocumentWidth()
869  friend class ChartElement; // for textDocumentWidth()
870  friend class XmlParser; // d->m_builder
871  friend class Header; // doc()
872  friend class PreviewDialogPrivate; // setupPrinter
873  friend class PreviewWidgetPrivate; // setupPrinter
874  friend class ReportPrivate; // setupPrinter
875  ReportPrivate* const d;
876 };
877 
878 }
879 
880 #endif /* KDREPORTSREPORT_H */
Definition: KDReportsReport.h:109
HeaderLocation
Definition: KDReportsReport.h:91
Definition: KDReportsXmlElementHandler.h:86
The first page of the report.
Definition: KDReportsReport.h:92
Definition: KDReportsMainTable.h:50
Definition: KDReportsHeader.h:54
Definition: KDReportsImageElement.h:41
All pages (except first and last if FirstPage or LastPage have their own headers) ...
Definition: KDReportsReport.h:96
Definition: KDReportsAbstractTableElement.h:36
The odd pages of the report: 1 (unless FirstPage has its own header), 3, 5, 7 etc.
Definition: KDReportsReport.h:94
The last page of the report.
Definition: KDReportsReport.h:95
Definition: KDReportsElement.h:45
The even pages of the report: 2, 4, 6 etc.
Definition: KDReportsReport.h:93
Definition: KDReportsErrorDetails.h:36
Definition: KDReportsChartElement.h:45
Definition: KDReportsAbstractTableElement.h:30

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/