KD Reports  1.7
KDReportsReport.h
1 /****************************************************************************
2 ** Copyright (C) 2007-2015 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 class QDomDocument;
40 class QTextDocumentFragment;
41 class QTextDocument;
42 class QDomElement;
43 class QDomNode;
44 class QAbstractItemModel;
45 class QIODevice;
46 class QRect;
47 class QPainter;
48 class ReportData;
49 class EditorData;
50 
51 namespace KDReports {
52 
53 class MainTable;
54 class XmlParser;
55 class Element;
56 class HeaderReportBuilder;
57 class Header;
58 typedef Header Footer;
59 class ReportPrivate;
60 class ReportBuilder;
61 class TextDocument;
62 class TableBreakingSettingsDialog;
63 class AutoTableElement;
64 class XmlElementHandler;
65 
90  FirstPage = 1,
91  EvenPages = 2,
92  OddPages = 4,
93  LastPage = 8,
95 };
96 Q_DECLARE_FLAGS( HeaderLocations, HeaderLocation )
97 
98 
107 class KDREPORTS_EXPORT Report : public QObject
108 {
109  Q_OBJECT
110  Q_PROPERTY(QString documentName READ documentName WRITE setDocumentName)
111 
112 public:
117  explicit Report( QObject* parent = 0 );
121  ~Report();
122 
123  enum ReportMode {
124  WordProcessing = 0,
125  SpreadSheet = 1
126  };
127 
147  void setReportMode( ReportMode reportMode );
148 
153  ReportMode reportMode() const;
154 
159  void setDefaultFont( const QFont& font );
160 
165  QFont defaultFont() const;
166 
170  MainTable* mainTable() const;
171 
179  void addInlineElement( const Element& element );
180 
195  void addElement( const Element& element, Qt::AlignmentFlag horizontalAlignment = Qt::AlignLeft,
196  const QColor& backgroundColor = QColor() );
197 
203  void addVerticalSpacing( qreal space );
204 
211  void addFragment( const QTextDocumentFragment& fragment );
212 
224  void addPageBreak();
225 
247  void setTabPositions( const QList<QTextOption::Tab>& tabs );
248 
254  QTextOption::Tab rightAlignedTab() const;
255 
262  QTextOption::Tab middleAlignedTab() const;
263 
269  void setParagraphMargins( qreal left, qreal top, qreal right, qreal bottom );
270 
276  void setPageSize( const QPrinter::PageSize& size );
277 
283  void setPaperSize( const QSizeF & paperSize, QPrinter::Unit unit );
284 
288  QPrinter::PageSize pageSize() const;
292  void setOrientation( QPrinter::Orientation orientation );
296  QPrinter::Orientation orientation() const;
297 
311  void setWidthForEndlessPrinter( qreal widthMM );
312 
316  void setMargins( qreal top, qreal left, qreal bottom, qreal right );
317 
322  void getMargins( qreal* top, qreal* left, qreal* bottom, qreal* right ) const;
323 
328  void setTopPageMargin( qreal top );
329 
334  qreal topPageMargins() const;
335 
340  void setLeftPageMargin( qreal left );
341 
346  qreal leftPageMargins() const;
347 
352  void setRightPageMargin( qreal right );
353 
358  qreal rightPageMargins() const;
359 
364  void setBottomPageMargin( qreal bottom );
365 
370  qreal bottomPageMargins() const;
371 
377  void setHeaderBodySpacing( qreal spacing );
378 
383  qreal headerBodySpacing() const;
384 
390  void setFooterBodySpacing( qreal spacing );
391 
396  qreal footerBodySpacing() const;
397 
414  Header& header( HeaderLocations hl = AllPages );
415 
423  Footer& footer( HeaderLocations hl = AllPages );
424 
431  void associateModel( const QString& modelKey, QAbstractItemModel* model );
432 
443  void associateTextValue( const QString& id, const QString& value );
444 
454  void associateImageValue( const QString& id, const QPixmap& value );
455 
469  void associateImageValue( const QString& id, const QImage& value );
470 
481  bool loadFromXML( QIODevice* iodevice, ErrorDetails* details = 0 );
482 
495  bool loadFromXML( const QDomDocument& doc, ErrorDetails* details = 0 );
496 
505  void setXmlElementHandler( KDReports::XmlElementHandler* handler );
506 
513  void setCurrentRow( const QAbstractItemModel *model, int row );
514 
520  void setDocumentName( const QString &name );
521 
526  QString documentName() const;
527 
533  bool printWithDialog( QWidget* parent );
534 
547  bool print( QPrinter* printer, QWidget* parent = 0 );
548 
555  bool exportToFile( const QString& fileName, QWidget* parent = 0 );
556 
563  bool exportToImage( const QSize& size, const QString& fileName, const char* format );
564 
572  bool exportToHtml( const QString& fileName );
573 
579  void paintPage( int pageNumber, QPainter& painter );
580 
586  void setFirstPageNumber( int num );
587 
591  int firstPageNumber() const;
592 
596  int numberOfPages() const;
597 
621  void setTableBreakingEnabled( bool tableBreakingEnabled );
622 
627  bool isTableBreakingEnabled() const;
628 
629  enum TableBreakingPageOrder { DownThenRight, RightThenDown };
630 
638  void setTableBreakingPageOrder( TableBreakingPageOrder pageOrder );
639 
644  TableBreakingPageOrder tableBreakingPageOrder() const;
645 
655  void setFontScalingFactor( qreal factor );
656 
661  qreal fontScalingFactor() const;
662 
685  void scaleTo( int numPagesHorizontally, int numPagesVertically );
686 
691  int maximumNumberOfPagesForHorizontalScaling() const;
696  int maximumNumberOfPagesForVerticalScaling() const;
697 
703  void setFixedRowHeight( qreal mm );
704 
713  QList<KDReports::AutoTableElement *> autoTableElements() const;
714 
720  void regenerateAutoTables();
721 
727  void regenerateAutoTableForModel( QAbstractItemModel* model );
728 
738  void setWatermarkText( const QString& text,
739  int rotation = 0,
740  const QColor& color = QColor( 204, 204, 204 ),
741  const QFont& font = QFont( QLatin1String( "Helvetica" ), 48 ) );
742 
746  QString watermarkText() const;
747 
751  int watermarkRotation() const;
752 
756  QColor watermarkColor() const;
757 
761  QFont watermarkFont() const;
762 
773  void setWatermarkPixmap( const QPixmap& pixmap, bool autoGrayOut = true );
774 
780  QPixmap watermarkPixmap() const;
781 
786  void setWatermarkImage( const QImage& image );
787 
792  QImage watermarkImage() const;
793 
798  KDReports::HeaderLocations headerLocation(Header* header) const;
799 
804  KDReports::HeaderLocations footerLocation(KDReports::Footer *footer) const;
805 
810  void setHeaderLocation(HeaderLocations hl, Header *header);
811 
816  void setFooterLocation(HeaderLocations hl, Footer *footer);
817 
821  QSizeF paperSize() const;
822 
826  void dump() const;
827 
831  int currentPosition() const;
832 
842  void beginEdit();
843 
851  void endEdit();
852 
853 private:
854  friend class Test;
855  friend class ::ReportData;
856  friend class ::EditorData;
857  KDReports::TextDocument& doc() const;
858 
859  QString asHtml() const;
860 
861  void setupPrinter( QPrinter* printer );
862 
863 private:
864  Q_DISABLE_COPY( Report )
865  friend class HeaderReportBuilder; // for headerChanged()
866  friend class ImageElement; // for textDocumentWidth()
867  friend class ChartElement; // for textDocumentWidth()
868  friend class XmlParser; // d->m_builder
869  friend class Header; // doc()
870  friend class PreviewDialogPrivate; // setupPrinter
871  friend class PreviewWidgetPrivate; // setupPrinter
872  friend class ReportPrivate; // setupPrinter
873  ReportPrivate* const d;
874 };
875 
876 }
877 
878 #endif /* KDREPORTSREPORT_H */
Definition: KDReportsReport.h:107
HeaderLocation
Definition: KDReportsReport.h:89
Definition: KDReportsXmlElementHandler.h:83
The first page of the report.
Definition: KDReportsReport.h:90
Definition: KDReportsMainTable.h:50
Definition: KDReportsHeader.h:52
Definition: KDReportsImageElement.h:38
All pages (except first and last if FirstPage or LastPage have their own headers) ...
Definition: KDReportsReport.h:94
Definition: KDReportsAbstractTableElement.h:33
The odd pages of the report: 1 (unless FirstPage has its own header), 3, 5, 7 etc.
Definition: KDReportsReport.h:92
The last page of the report.
Definition: KDReportsReport.h:93
Definition: KDReportsElement.h:42
The even pages of the report: 2, 4, 6 etc.
Definition: KDReportsReport.h:91
Definition: KDReportsErrorDetails.h:36
Definition: KDReportsChartElement.h:42
Definition: KDReportsAbstractTableElement.h:29

Klarälvdalens Datakonsult AB (KDAB)
Qt-related services and products
http://www.kdab.com/
http://www.kdab.com/products/kd-reports/