Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

rtkreport.h

00001 /*<<<<<COPYRIGHT*/
00002 /*
00003  * RTK The report toolkit
00004  * Copyright (C) 2003 Francisco Santiago Capel Torres
00005 
00006  * rtkreport.h RTK report object
00007  * 
00008  * This program is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  */
00019 /*>>>>>COPYRIGHT*/
00020 #ifndef RTKREPORT_H
00021 #define RTKREPORT_H
00022 
00023 #include "rtknamespace.h"
00024 #include "rtkvariant.h"
00025 #include "rtkformatter.h"
00026 #include "rtkregconfig.h"
00027 #include "rtkstyle.h"
00028 #include "rtkformula.h"
00029 #include "rtkoutput.h"
00030 #include "rtkinput.h"
00031 #include "rtkobject.h"
00032 #include "rtksection.h"
00033 
00034 #include <qmap.h>
00035 
00036 namespace RTK
00037 {
00038 
00039 typedef Variant ( CFunction ) ( const class Report &, const class Object &, const String & );
00040 typedef CFunction *CFunctionPtr;
00041 
00042 
00043 class Report: public Object
00044 {
00045 
00046         friend class Section;
00047         friend class Object;
00048 
00049 /*<<<<<REPORT_CONSTRUCTOR*/
00050 public:
00051         Report(const String& title = String::null, UnitsType units = chars, 
00052                 String stylespath = String::null, String imagespath = String::null,
00053         const String& name = String::null, Variant value = 0, 
00054                 AggregateType aggregate = AggNone, String posx = 0, String posy = 0, 
00055                 String sizex = 0, String sizey = 0, const String& style = String::null, 
00056                 const String& url = String::null, const String& tag = String::null, Variant marginleft = 0, 
00057                 Variant marginright = 0, Variant margintop = 0, Variant marginbottom = 0, 
00058                 Variant visible = true, Variant supressed = false, Variant fontfamily = String::null, 
00059                 Variant fontsize = 12, Variant fontweight = 0, Variant fontitalic = false, 
00060                 Variant mask = String::null, Variant format = String::null, Variant halignment = AlignAuto, 
00061                 Variant valignment = AlignTop, Variant maxlines = 0, Variant minfontsize = 8, 
00062                 Variant adjustment = AdjustTrim, Variant textcolor = Qt::black, Variant backcolor = Qt::white, 
00063                 Variant bordercolor = Qt::black, Variant borderwidth = 0, Variant borderstyle = BorderNone, Variant backgroundimage = String::null)
00064         :Object(name, value, 
00065                 aggregate, posx, posy, 
00066                 sizex, sizey, style, 
00067                 url, tag, marginleft, 
00068                 marginright, margintop, marginbottom, 
00069                 visible, supressed, fontfamily, 
00070                 fontsize, fontweight, fontitalic, 
00071                 mask, format, halignment, 
00072                 valignment, maxlines, minfontsize, 
00073                 adjustment, textcolor, backcolor, 
00074                 bordercolor, borderwidth, borderstyle, backgroundimage),
00075         mTitle(title), mUnits(units), 
00076                 mStylesPath(stylespath), mImagesPath(imagespath)
00077 /*>>>>>REPORT_CONSTRUCTOR*/
00078                         , pInput( 0 ), pOutput( 0 ), mGroupLevels( uint( -1 ) )
00079                         , mFinished( false ), mStarted( false )
00080         { initLocale(); }
00081         ~Report();
00082         bool readXml( const String &filename, const String &defaultinput = String::null );
00083         int print( Input &in, Output &out );
00084         int print( Output &out );
00085 
00087         Input *getInput() const { return pInput; }
00089         void setInput( Input *input );
00090 
00092         Image *findImage( const String &name ) const;
00094         bool eraseImage( const String &name );
00096         int insertImage( Image *image );
00097 /*<<<<<REPORT_INSERTIMAGE*/
00098         int insertImage(String name = String::null, String url = String::null, String mimetype = String::null, String imagestyle = String::null);
00099 /*>>>>>REPORT_INSERTIMAGE*/
00100 
00102         int insertSection( Section *section );
00104         /*<<<<<REPORT_INSERTSECTION*/
00105         int insertSection(SectionType type = SectionDetails, String groupname = "", Variant groupvalue = Variant(), uint grouplevel = 0, bool pagebefore = false, bool pageafter = false, bool resetnpage = false, bool supifblank = false, bool repeatheader = false);
00106 /*>>>>>REPORT_INSERTSECTION*/
00108         int insertStyle( Style *style );
00110         bool eraseStyle( const String &name );
00112         /*<<<<<REPORT_INSERTSTYLE*/
00113         int insertStyle(String name = String::null, String marginleft = 0, String marginright = 0, String margintop = 0, String marginbottom = 0, bool visible = true, bool supressed = false, String fontfamily = String::null, int fontsize = 12, int fontweight = 0, bool fontitalic = false, String mask = String::null, String format = String::null, AlignmentType halignment = AlignAuto, AlignmentType valignment = AlignTop, int maxlines = 0, int minfontsize = 8, AdjustmentType adjustment = AdjustTrim, Color textcolor = Qt::black, Color backcolor = Qt::white, Color bordercolor = Qt::black, int borderwidth = 0, BorderStyle borderstyle = BorderNone, String backgroundimage = String::null);
00114 /*>>>>>REPORT_INSERTSTYLE*/
00116         int insertFormula( Formula *formula );
00118         /*<<<<<REPORT_INSERTFORMULA*/
00119         int insertFormula(String name = String::null, String code = String::null);
00120 /*>>>>>REPORT_INSERTFORMULA*/
00121 
00122         
00123         Section *getSection( const String &name ) const;
00125         Section *getSection( uint nsection ) const;
00127         Style *getStyle( const String &name ) const;
00129         Style *getStyle( uint nstyle ) const;
00130 
00131         const Formatter &getFormatter() const { return *pLocalFormatter; }
00132         
00133         void setImagesPath(const QString &path);
00134         void setStylesPath(const QString &path);
00135         const QString &getCWD() const { return mCWD; }
00136         /*<<<<<REPORT_GETSET*/
00137 public:
00139         const String& getTitle() const { return mTitle; };
00141         void setTitle(const String& title) { mTitle = title; };
00143         UnitsType getUnits() const { return mUnits; };
00145         void setUnits(UnitsType units) { mUnits = units; };
00147         String getStylesPath() const { return mStylesPath; };
00149         String getImagesPath() const { return mImagesPath; };
00150 protected:
00151         String mTitle;
00152         UnitsType mUnits;
00153         String mStylesPath;
00154         String mImagesPath;
00155 /*>>>>>REPORT_GETSET*/
00156 
00157 private:
00158         int readNext( Input &in );
00159         bool applyStyle( Object *object );
00160         uint getGroupLevels() const
00161         {
00162                 return mGroupLevels;
00163         }
00164         void calcAggregateValues( uint level );
00165         void fixReportMeasures( const Output &out );
00166         bool isPageHeader( unsigned int nsect )
00167         {
00168                 return mSections[ nsect ] ->getType() == SectionPageHeader;
00169         }
00170         bool isPageHeader( const Section &section )
00171         {
00172                 return section.getType() == SectionPageHeader;
00173         }
00174         bool isPageFooter( unsigned int nsect )
00175         {
00176                 return mSections[ nsect ] ->getType() == SectionPageFooter;
00177         }
00178         bool isPageFooter( const Section &section )
00179         {
00180                 return section.getType() == SectionPageFooter;
00181         }
00182         bool isGroupHeader( unsigned int nsect )
00183         {
00184                 return mSections[ nsect ] ->getType() == SectionGroupHeader;
00185         }
00186         bool isGroupHeader( const Section &section )
00187         {
00188                 return section.getType() == SectionPageFooter;
00189         }
00190         bool isGroupFooter( unsigned int nsect )
00191         {
00192                 return mSections[ nsect ] ->getType() == SectionGroupFooter;
00193         }
00194         bool isGroupFooter( const Section &section )
00195         {
00196                 return section.getType() == SectionGroupFooter;
00197         }
00198         bool isDetails( unsigned int nsect )
00199         {
00200                 return mSections[ nsect ] ->getType() == SectionDetails;
00201         }
00202         bool isDetails( const Section &section )
00203         {
00204                 return section.getType() == SectionDetails;
00205         }
00206         int printPageHeaders( Output &out );
00207         int printPageFooters( Output &out );
00208         int printPageFooterIfNeeded( Output &out, Section &section );
00209         int printGroup( Input &in, Output &out, uint nsection = 0 );
00210         int printSection( Output &out, Section & );
00211         int printObject( Output &out, const Section &section,
00212                          const Object &object );
00213         Measure calcSizeYSections( SectionType type ) const;
00214         Variant calcConstValue( const Variant& );
00215         void calcConstValues();
00216         Variant calcNonConstValue( const Variant&, Input &in );
00217         void calcNonConstValues( Input &in );
00218         bool changedGroupValue( uint level );
00219         int resetAggregateValues( uint level );
00220         int incRecordCount( uint level );
00221         void resetRecordCount( uint level );
00222         virtual CFunction mCFunction;
00223         Variant execCFunction( const Object &, const String &code );
00224         // { return Variant(); }
00225 
00226         Input *pInput;
00227         Output *pOutput;
00228         uint mGroupLevels;
00229         Measure mFootersHeight;
00230         String mInputName;
00231         QValueList<Section *>mSections;
00232         QValueList<Style *>mStyles;
00233         QValueList<BorderStyle *>mBorderStyles;
00234         QValueList<Formula *>mFormulas;
00235         QValueList<Image *>mImages;
00236         bool mFinished;
00237         bool mStarted;
00238 
00239         // Report variables
00240 public:
00241         const QDateTime getReportDate() const
00242         {
00243                 return mReportDate.toDateTime();
00244         }
00245         unsigned int getRecordCount() const
00246         {
00247                 return mRecordCount.toUInt();
00248         }
00249         unsigned int getRecordNumber() const
00250         {
00251                 return mRecordNumber.toUInt();
00252         }
00253         unsigned int getPageCount() const
00254         {
00255                 return mPageCount.toUInt();
00256         }
00257         unsigned int getPageNumber() const
00258         {
00259                 return mPageNumber.toUInt();
00260         }
00261 private:
00262         Variant mReportDate;
00263         Variant mPageNumber, mPageCount;
00264         Variant mRecordNumber, mRecordCount;
00265         String mReportTitle;
00266 
00267 #ifndef NDEBUG
00268 public:
00269         int debug_print() const;
00270 #endif
00271 
00272 public:
00273         typedef Input* ( *InputCreatorFuncPtr ) ( const String &name, const String &driver );
00274         static int registerInput( const String &name, InputCreatorFuncPtr creator );
00275         static Input *createRegisteredInput( const String &name, const String &driver );
00276 private:
00277         void initLocale();
00278         static QMap<String, InputCreatorFuncPtr> mRegisteredInputs;
00279         RegConfig mLocalRegConfig;
00280         Formatter *pLocalFormatter;
00281         QString mCWD;
00282 };
00283 
00284 }; // namespace
00285 
00286 #endif // RTKREPORT_H
00287 
00288 

Generated on Tue Feb 22 14:44:37 2005 for RTK. Report ToolKit by  doxygen 1.3.9.1