KD Reports  1.5
 All Classes Namespaces Functions Enumerations Enumerator Pages
KDReportsReport.h
1 /****************************************************************************
2 ** Copyright (C) 2007-2014 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 PreviewDialog;
62 class TextDocument;
63 class TableBreakingSettingsDialog;
64 class AutoTableElement;
65 class XmlElementHandler;
66 
91  FirstPage = 1,
92  EvenPages = 2,
93  OddPages = 4,
94  LastPage = 8,
96 };
97 Q_DECLARE_FLAGS( HeaderLocations, HeaderLocation )
98 
99 
108 class KDREPORTS_EXPORT Report : public QObject
109 {
110  Q_OBJECT
111 
112 public:
117  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  bool printWithDialog( QWidget* parent );
521 
534  bool print( QPrinter* printer, QWidget* parent = 0 );
535 
542  bool exportToFile( const QString& fileName, QWidget* parent = 0 );
543 
550  bool exportToImage( const QSize& size, const QString& fileName, const char* format );
551 
559  bool exportToHtml( const QString& fileName );
560 
566  void paintPage( int pageNumber, QPainter& painter );
567 
573  void setFirstPageNumber( int num );
574 
578  int firstPageNumber() const;
579 
583  int numberOfPages() const;
584 
608  void setTableBreakingEnabled( bool tableBreakingEnabled );
609 
614  bool isTableBreakingEnabled() const;
615 
616  enum TableBreakingPageOrder { DownThenRight, RightThenDown };
617 
625  void setTableBreakingPageOrder( TableBreakingPageOrder pageOrder );
626 
631  TableBreakingPageOrder tableBreakingPageOrder() const;
632 
642  void setFontScalingFactor( qreal factor );
643 
648  qreal fontScalingFactor() const;
649 
672  void scaleTo( int numPagesHorizontally, int numPagesVertically );
673 
678  int maximumNumberOfPagesForHorizontalScaling() const;
683  int maximumNumberOfPagesForVerticalScaling() const;
684 
693  QList<KDReports::AutoTableElement *> autoTableElements() const;
694 
700  void regenerateAutoTables();
701 
707  void regenerateAutoTableForModel( QAbstractItemModel* model );
708 
718  void setWatermarkText( const QString& text,
719  int rotation = 0,
720  const QColor& color = QColor( 204, 204, 204 ),
721  const QFont& font = QFont( QLatin1String( "Helvetica" ), 48 ) );
722 
726  QString watermarkText() const;
727 
731  int watermarkRotation() const;
732 
736  QColor watermarkColor() const;
737 
741  QFont watermarkFont() const;
742 
753  void setWatermarkPixmap( const QPixmap& pixmap, bool autoGrayOut = true );
754 
760  QPixmap watermarkPixmap() const;
761 
766  void setWatermarkImage( const QImage& image );
767 
772  QImage watermarkImage() const;
773 
778  KDReports::HeaderLocations headerLocation(Header* header) const;
779 
784  KDReports::HeaderLocations footerLocation(KDReports::Footer *footer) const;
785 
790  void setHeaderLocation(HeaderLocations hl, Header *header);
791 
796  void setFooterLocation(HeaderLocations hl, Footer *footer);
797 
801  QSizeF paperSize() const;
802 
806  void dump() const;
807 
811  int currentPosition() const;
812 
813 private:
814  friend class Test;
815  friend class ::ReportData;
816  friend class ::EditorData;
817  KDReports::TextDocument& doc() const;
818 
819  QString asHtml() const;
820 
821 private:
822  Q_DISABLE_COPY( Report )
823  friend class HeaderReportBuilder; // for headerChanged()
824  friend class ImageElement; // for textDocumentWidth()
825  friend class ChartElement; // for textDocumentWidth()
826  friend class XmlParser; // d->m_builder
827  friend class Header; // doc()
828  ReportPrivate* const d;
829 };
830 
831 }
832 
833 #endif /* KDREPORTSREPORT_H */
Definition: KDReportsReport.h:108
HeaderLocation
Definition: KDReportsReport.h:90
Definition: KDReportsXmlElementHandler.h:83
The first page of the report.
Definition: KDReportsReport.h:91
Definition: KDReportsMainTable.h:49
Definition: KDReportsHeader.h:51
Definition: KDReportsImageElement.h:37
All pages (except first and last if FirstPage or LastPage have their own headers) ...
Definition: KDReportsReport.h:95
The odd pages of the report: 1 (unless FirstPage has its own header), 3, 5, 7 etc.
Definition: KDReportsReport.h:93
The last page of the report.
Definition: KDReportsReport.h:94
Definition: KDReportsElement.h:41
The even pages of the report: 2, 4, 6 etc.
Definition: KDReportsReport.h:92
Definition: KDReportsErrorDetails.h:36
Definition: KDReportsChartElement.h:41
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/