summaryrefslogtreecommitdiffstats
path: root/kugar/lib/mreportengine.h
blob: 846d0a3a519213f710757154c7a03751b86d9dc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/***************************************************************************
             mreportengine.h  -  Kugar report engine
             -------------------
   begin     : Sun Aug 15 1999
   copyright : (C) 1999 by Mutiny Bay Software
   email     : info@mutinybaysoftware.com
   copyright : (C) 2002 Alexander Dymo
   email     : cloudtemple@mksat.net
***************************************************************************/

#ifndef MREPORTENGINE_H
#define MREPORTENGINE_H

#include <tqobject.h>
#include <tqpicture.h>
#include <tqpaintdevicemetrics.h>
#include <tqsize.h>
#include <tqmemarray.h>
#include <tqdom.h>
#include <tqguardedptr.h>

#include "mlineobject.h"
#include "mlabelobject.h"
#include "mspecialobject.h"
#include "mfieldobject.h"
#include "mreportsection.h"
#include "mreportdetail.h"
#include "mpagecollection.h"

/**Kugar report engine
  *@author Mutiny Bay Software
  */

namespace Kugar
{

class MReportEngine : public TQObject
{
    Q_OBJECT
  TQ_OBJECT

public:
    enum PageOrientation { Portrait, Landscape };

    enum PageSize {
        A4, B5, Letter, Legal, Executive,
        A0, A1, A2, A3, A5, A6, A7, A8, A9, B0, B1,
        B10, B2, B3, B4, B6, B7, B8, B9, C5E, Comm10E,
        DLE, Folio, Ledger, Tabloid, NPageSize
    };

    MReportEngine();
    MReportEngine( const MReportEngine& mReportEngine );
    MReportEngine operator=( const MReportEngine& mReportEngine );
    virtual ~MReportEngine();

    bool setReportData( const TQString & );
    bool setReportData( TQIODevice * );
    bool setReportData( const TQDomDocument& );
    bool setReportTemplate( const TQString & );
    bool setReportTemplate( TQIODevice * );
    int getRenderSteps()
    {
        return records.length() / 2;
    }
    MPageCollection* renderReport();

    void addRef();
    void removeRef();
public slots:
    void slotCancelRendering();

signals:
    void signalRenderStatus( int );
    void preferedTemplate( const TQString & );

protected:
    void recalcDimensions();
    void recalcAttribute( const TQString& name, TQDomNamedNodeMap attributes );

private:

    MPageCollection *m_pageCollection;
    bool m_needRegeneration;
    /** Report data document */
    TQDomDocument rd;
    /** Report template document */
    TQDomDocument rt;

    /** Report painter */
    TQPainter p;

    /** Report page size */
    int pageSize;
    /** Report page orientation */
    int pageOrientation;
    /** Report top margin */
    int topMargin;
    /** Report top margin */
    int bottomMargin;
    /** Report top margin */
    int leftMargin;
    /** Report top margin */
    int rightMargin;

    /** Report page width */
    int pageWidth;
    /** Report page height */
    int pageHeight;

    float widthDelta;
    float heightDelta;

    /** Report header */
    MReportSection rHeader;
    /** Page header */
    MReportSection pHeader;
    /** Detail headers */
    TQPtrList<MReportSection> dHeaders;
    /** Detail sections */
    TQPtrList<MReportDetail> details;
    /** Detail footers */
    TQPtrList<MReportSection> dFooters;
    /** Page footer */
    MReportSection pFooter;
    /** Report footer */
    MReportSection rFooter;

    /** Stores the combined heights of the detail levels */
    int heightOfDetails;

    /** Current y position on page */
    int currY;
    /** Current height of page excluding margins */
    int currHeight;
    /** Current page number */
    int currPage;
    /** Current report date */
    TQDate currDate;

    /** Grand total array */
    TQPtrList<TQMemArray<double> > grandTotal;

    /** Cancel rendering flag */
    bool cancelRender;
    int m_refCount;
private:
    // The set of records being rendered.
    TQDomNodeList records;
    /** Clears report formatting */
    void clearFormatting();
    /** Starts a new page of the report */
    void startPage( MPageCollection* pages );
    /** Finishes the current page of the report */
    void endPage( MPageCollection* pages );
    /** Finishes the current page and adds a new page */
    void newPage( MPageCollection* pages );
    /** Draws the report header object to the current page */
    void drawReportHeader( MPageCollection* pages );
    /** Draws the page header to the current page */
    void drawPageHeader( MPageCollection* pages );
    /** Draws the page footer to the current page */
    void drawPageFooter( MPageCollection* pages );
    /** Draws the report footer to the current page */
    void drawReportFooter( MPageCollection* pages );

    /** Gets the metrics for the selected page size */
    TQSize getPageMetrics( int size, int orientation );

    void initData();
    void initTemplate();

    /** Sets the main layout attributes for the report */
    void setReportAttributes( TQDomNode* report );

    int scaleDeltaWidth( int width ) const;
    int scaleDeltaHeight( int width ) const;

    /** Sets the layout attributes for the given report section */
    void setSectionAttributes( MReportSection* section, TQDomNode* report );
    /** Sets the layout attributes for the detail headers and footers */
    void setDetMiscAttributes( MReportSection* section, TQDomNode* report );
    /** Sets the layout attributes for the detail section */
    void setDetailAttributes( TQDomNode* report );
    /** Sets a line's layout attributes */
    void setLineAttributes( MLineObject* line, TQDomNamedNodeMap* attr );
    /** Sets a label's layout attributes */
    void setLabelAttributes( MLabelObject* label, TQDomNamedNodeMap* attr );
    /** Sets a special field's layout attributes */
    void setSpecialAttributes( MSpecialObject* field, TQDomNamedNodeMap* attr );
    /** Sets a field's layout attributes */
    void setFieldAttributes( MFieldObject* field, TQDomNamedNodeMap* attr );
    /** Sets a calculated field's layout attributes */
    void setCalculatedFieldAttributes( MCalcObject* field, TQDomNamedNodeMap* attr );

    /** Copies member data from one object to another.
      * Used by the copy constructor and assignment operator
      */
    void copy( const MReportEngine* mReportEngine );

    /** Finds the detail header object, which is apropriate for the given level */
    MReportSection *findDetailHeader( int level );
    /** Finds the detail object, which is apropriate for the given level */
    MReportDetail *findDetail( int level );
    /** Finds the detail footer object, which is apropriate for the given level */
    MReportSection *findDetailFooter( int level );
};

}

#endif