KD Reports 1.4
|
00001 /**************************************************************************** 00002 ** Copyright (C) 2007-2012 Klaralvdalens Datakonsult AB. All rights reserved. 00003 ** 00004 ** This file is part of the KD Reports library. 00005 ** 00006 ** Licensees holding valid commercial KD Reports licenses may use this file in 00007 ** accordance with the KD Reports Commercial License Agreement provided with 00008 ** the Software. 00009 ** 00010 ** 00011 ** This file may be distributed and/or modified under the terms of the 00012 ** GNU General Public License version 2 and version 3 as published by the 00013 ** Free Software Foundation and appearing in the file LICENSE.GPL included. 00014 ** 00015 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00016 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00017 ** 00018 ** Contact info@kdab.com if any conditions of this licensing are not 00019 ** clear to you. 00020 ** 00021 **********************************************************************/ 00022 00023 #ifndef KDREPORTSREPORT_H 00024 #define KDREPORTSREPORT_H 00025 00026 #include "KDReportsErrorDetails.h" 00027 #include "KDReportsGlobal.h" 00028 #include <QtCore/QSizeF> 00029 #include <QtGui/QPrinter> 00030 #include <QtGui/QColor> 00031 #include <QtGui/QFont> 00032 #include <QtGui/QTextOption> 00033 00034 class QDomDocument; 00035 class QTextDocumentFragment; 00036 class QTextDocument; 00037 class QDomElement; 00038 class QDomNode; 00039 class QAbstractItemModel; 00040 class QIODevice; 00041 class QRect; 00042 class QPainter; 00043 class ReportData; 00044 class EditorData; 00045 00046 namespace KDReports { 00047 00048 class MainTable; 00049 class XmlParser; 00050 class Element; 00051 class HeaderReportBuilder; 00052 class Header; 00053 typedef Header Footer; 00054 class ReportPrivate; 00055 class ReportBuilder; 00056 class PreviewDialog; 00057 class TextDocument; 00058 class TableBreakingSettingsDialog; 00059 class AutoTableElement; 00060 class XmlElementHandler; 00061 00085 enum HeaderLocation { 00086 FirstPage = 1, 00087 EvenPages = 2, 00088 OddPages = 4, 00089 LastPage = 8, 00090 AllPages = OddPages | EvenPages 00091 }; 00092 Q_DECLARE_FLAGS( HeaderLocations, HeaderLocation ) 00093 00094 00103 class KDREPORTS_EXPORT Report : public QObject 00104 { 00105 Q_OBJECT 00106 00107 public: 00112 Report( QObject* parent = 0 ); 00116 ~Report(); 00117 00118 enum ReportMode { 00119 WordProcessing = 0, 00120 SpreadSheet = 1 00121 }; 00122 00142 void setReportMode( ReportMode reportMode ); 00143 00148 ReportMode reportMode() const; 00149 00154 void setDefaultFont( const QFont& font ); 00155 00160 QFont defaultFont() const; 00161 00165 MainTable* mainTable() const; 00166 00174 void addInlineElement( const Element& element ); 00175 00190 void addElement( const Element& element, Qt::AlignmentFlag horizontalAlignment = Qt::AlignLeft, 00191 const QColor& backgroundColor = QColor() ); 00192 00198 void addVerticalSpacing( qreal space ); 00199 00206 void addFragment( const QTextDocumentFragment& fragment ); 00207 00219 void addPageBreak(); 00220 00242 void setTabPositions( const QList<QTextOption::Tab>& tabs ); 00243 00249 QTextOption::Tab rightAlignedTab() const; 00250 00257 QTextOption::Tab middleAlignedTab() const; 00258 00264 void setParagraphMargins( qreal left, qreal top, qreal right, qreal bottom ); 00265 00271 void setPageSize( const QPrinter::PageSize& size ); 00272 00278 void setPaperSize( const QSizeF & paperSize, QPrinter::Unit unit ); 00279 00283 QPrinter::PageSize pageSize() const; 00287 void setOrientation( QPrinter::Orientation orientation ); 00291 QPrinter::Orientation orientation() const; 00292 00306 void setWidthForEndlessPrinter( qreal widthMM ); 00307 00311 void setMargins( qreal top, qreal left, qreal bottom, qreal right ); 00312 00317 void getMargins( qreal* top, qreal* left, qreal* bottom, qreal* right ) const; 00318 00323 void setTopPageMargin( qreal top ); 00324 00329 qreal topPageMargins() const; 00330 00335 void setLeftPageMargin( qreal left ); 00336 00341 qreal leftPageMargins() const; 00342 00347 void setRightPageMargin( qreal right ); 00348 00353 qreal rightPageMargins() const; 00354 00359 void setBottomPageMargin( qreal bottom ); 00360 00365 qreal bottomPageMargins() const; 00366 00372 void setHeaderBodySpacing( qreal spacing ); 00373 00378 qreal headerBodySpacing() const; 00379 00385 void setFooterBodySpacing( qreal spacing ); 00386 00391 qreal footerBodySpacing() const; 00392 00409 Header& header( HeaderLocations hl = AllPages ); 00410 00418 Footer& footer( HeaderLocations hl = AllPages ); 00419 00426 void associateModel( const QString& modelKey, QAbstractItemModel* model ); 00427 00438 void associateTextValue( const QString& id, const QString& value ); 00439 00449 void associateImageValue( const QString& id, const QPixmap& value ); 00450 00464 void associateImageValue( const QString& id, const QImage& value ); 00465 00476 bool loadFromXML( QIODevice* iodevice, ErrorDetails* details = 0 ); 00477 00490 bool loadFromXML( const QDomDocument& doc, ErrorDetails* details = 0 ); 00491 00500 void setXmlElementHandler( KDReports::XmlElementHandler* handler ); 00501 00508 void setCurrentRow( const QAbstractItemModel *model, int row ); 00509 00515 bool printWithDialog( QWidget* parent ); 00516 00529 bool print( QPrinter* printer, QWidget* parent = 0 ); 00530 00537 bool exportToFile( const QString& fileName, QWidget* parent = 0 ); 00538 00545 bool exportToImage( const QSize& size, const QString& fileName, const char* format ); 00546 00554 bool exportToHtml( const QString& fileName ); 00555 00561 void paintPage( int pageNumber, QPainter& painter ); 00562 00568 void setFirstPageNumber( int num ); 00569 00573 int firstPageNumber() const; 00574 00578 int numberOfPages() const; 00579 00603 void setTableBreakingEnabled( bool tableBreakingEnabled ); 00604 00609 bool isTableBreakingEnabled() const; 00610 00611 enum TableBreakingPageOrder { DownThenRight, RightThenDown }; 00612 00620 void setTableBreakingPageOrder( TableBreakingPageOrder pageOrder ); 00621 00626 TableBreakingPageOrder tableBreakingPageOrder() const; 00627 00637 void setFontScalingFactor( qreal factor ); 00638 00643 qreal fontScalingFactor() const; 00644 00667 void scaleTo( int numPagesHorizontally, int numPagesVertically ); 00668 00673 int maximumNumberOfPagesForHorizontalScaling() const; 00678 int maximumNumberOfPagesForVerticalScaling() const; 00679 00688 QList<KDReports::AutoTableElement *> autoTableElements() const; 00689 00695 void regenerateAutoTables(); 00696 00702 void regenerateAutoTableForModel( QAbstractItemModel* model ); 00703 00713 void setWatermarkText( const QString& text, 00714 int rotation = 0, 00715 const QColor& color = QColor( 204, 204, 204 ), 00716 const QFont& font = QFont( QLatin1String( "Helvetica" ), 48 ) ); 00717 00721 QString watermarkText() const; 00722 00726 int watermarkRotation() const; 00727 00731 QColor watermarkColor() const; 00732 00736 QFont watermarkFont() const; 00737 00748 void setWatermarkPixmap( const QPixmap& pixmap, bool autoGrayOut = true ); 00749 00755 QPixmap watermarkPixmap() const; 00756 00761 void setWatermarkImage( const QImage& image ); 00762 00767 QImage watermarkImage() const; 00768 00773 KDReports::HeaderLocations headerLocation(Header* header) const; 00774 00779 KDReports::HeaderLocations footerLocation(KDReports::Footer *footer) const; 00780 00785 void setHeaderLocation(HeaderLocations hl, Header *header); 00786 00791 void setFooterLocation(HeaderLocations hl, Footer *footer); 00792 00796 QSizeF paperSize() const; 00797 00801 void dump() const; 00802 00806 int currentPosition() const; 00807 00808 private: 00809 friend class Test; 00810 friend class ::ReportData; 00811 friend class ::EditorData; 00812 KDReports::TextDocument& doc() const; 00813 00814 QString asHtml() const; 00815 00816 private: 00817 Q_DISABLE_COPY( Report ) 00818 friend class HeaderReportBuilder; // for headerChanged() 00819 friend class ImageElement; // for textDocumentWidth() 00820 friend class ChartElement; // for textDocumentWidth() 00821 friend class XmlParser; // d->m_builder 00822 friend class Header; // doc() 00823 ReportPrivate* const d; 00824 }; 00825 00826 } 00827 00828 #endif /* KDREPORTSREPORT_H */