~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to libs/koreport/renderer/renderobjects.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * OpenRPT report writer and rendering engine
 
3
 * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
 
4
 * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
 
5
 *
 
6
 * This library is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU Lesser General Public
 
8
 * License as published by the Free Software Foundation; either
 
9
 * version 2.1 of the License, or (at your option) any later version.
 
10
 *
 
11
 * This library is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
14
 * Lesser General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Lesser General Public
 
17
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
#include "renderobjects.h"
 
20
 
 
21
 
 
22
//
 
23
// ORODocument
 
24
//
 
25
ORODocument::ORODocument(const QString & pTitle)
 
26
        : m_title(pTitle)
 
27
{
 
28
}
 
29
 
 
30
ORODocument::~ORODocument()
 
31
{
 
32
    while (!m_pages.isEmpty()) {
 
33
        OROPage * p = m_pages.takeFirst();
 
34
        p->m_document = 0;
 
35
        delete p;
 
36
    }
 
37
}
 
38
 
 
39
void ORODocument::setTitle(const QString & pTitle)
 
40
{
 
41
    m_title = pTitle;
 
42
}
 
43
 
 
44
OROPage* ORODocument::page(int pnum)
 
45
{
 
46
    return m_pages.at(pnum);
 
47
}
 
48
 
 
49
void ORODocument::addPage(OROPage* p)
 
50
{
 
51
    if (p == 0)
 
52
        return;
 
53
 
 
54
    // check that this page is not already in another document
 
55
 
 
56
    p->m_document = this;
 
57
    m_pages.append(p);
 
58
}
 
59
 
 
60
OROSection* ORODocument::section(int pnum)
 
61
{
 
62
    return m_sections.at(pnum);
 
63
}
 
64
 
 
65
void ORODocument::addSection(OROSection* s)
 
66
{
 
67
    if (s == 0)
 
68
        return;
 
69
 
 
70
    // check that this page is not already in another document
 
71
 
 
72
    s->m_document = this;
 
73
    m_sections.append(s);
 
74
}
 
75
 
 
76
void ORODocument::setPageOptions(const ReportPageOptions & options)
 
77
{
 
78
    m_pageOptions = options;
 
79
}
 
80
 
 
81
//
 
82
// OROPage
 
83
//
 
84
OROPage::OROPage(ORODocument * pDocument)
 
85
        : m_document(pDocument)
 
86
{
 
87
 
 
88
}
 
89
 
 
90
OROPage::~OROPage()
 
91
{
 
92
    if (m_document) {
 
93
        m_document->m_pages.removeAt(page());
 
94
        m_document = 0;
 
95
    }
 
96
 
 
97
    while (!m_primitives.isEmpty()) {
 
98
        OROPrimitive* p = m_primitives.takeFirst();
 
99
        p->m_page = 0;
 
100
        delete p;
 
101
    }
 
102
}
 
103
 
 
104
int OROPage::page() const
 
105
{
 
106
    if (m_document) {
 
107
        for (int i = 0; i < m_document->m_pages.size(); i++) {
 
108
            if (m_document->m_pages.at(i) == this)
 
109
                return i;
 
110
        }
 
111
    }
 
112
    return -1;
 
113
}
 
114
 
 
115
OROPrimitive* OROPage::primitive(int idx)
 
116
{
 
117
    return m_primitives.at(idx);
 
118
}
 
119
 
 
120
void OROPage::addPrimitive(OROPrimitive* p, bool atBeginning)
 
121
{
 
122
    if (p == 0)
 
123
        return;
 
124
 
 
125
    // check that this primitve is not already in another page
 
126
 
 
127
    p->m_page = this;
 
128
    if (atBeginning) {
 
129
        m_primitives.prepend(p);
 
130
    } else {
 
131
        m_primitives.append(p);
 
132
    }
 
133
}
 
134
 
 
135
//
 
136
// OROSection
 
137
//
 
138
OROSection::OROSection(ORODocument * pDocument)
 
139
        : m_document(pDocument)
 
140
{
 
141
    m_height = 0;
 
142
    m_backgroundColor = Qt::white;
 
143
}
 
144
 
 
145
OROSection::~OROSection()
 
146
{
 
147
    if (m_document) {
 
148
        m_document->m_sections.removeAt(row());
 
149
        m_document = 0;
 
150
    }
 
151
 
 
152
    while (!m_primitives.isEmpty()) {
 
153
        OROPrimitive* p = m_primitives.takeFirst();
 
154
        delete p;
 
155
    }
 
156
}
 
157
 
 
158
long OROSection::row() const
 
159
{
 
160
    return m_row;
 
161
}
 
162
 
 
163
OROPrimitive* OROSection::primitive(int idx)
 
164
{
 
165
    return m_primitives.at(idx);
 
166
}
 
167
 
 
168
void OROSection::addPrimitive(OROPrimitive* p)
 
169
{
 
170
    if (p == 0)
 
171
        return;
 
172
 
 
173
    m_primitives.append(p);
 
174
}
 
175
 
 
176
void OROSection::setHeight(int h)
 
177
{
 
178
    m_height = h;
 
179
}
 
180
 
 
181
int OROSection::height()
 
182
{
 
183
    return m_height;
 
184
}
 
185
 
 
186
void OROSection::setBackgroundColor(const QColor &c)
 
187
{
 
188
    m_backgroundColor = c;
 
189
}
 
190
 
 
191
QColor OROSection::backgroundColor()
 
192
{
 
193
    return m_backgroundColor;
 
194
}
 
195
 
 
196
void OROSection::sortPrimatives(Sort s)
 
197
{
 
198
    if (s == SortX) {
 
199
        qSort(m_primitives.begin(), m_primitives.end(), xLessThan);
 
200
    }
 
201
}
 
202
 
 
203
bool OROSection::xLessThan(OROPrimitive* s1, OROPrimitive* s2)
 
204
{
 
205
    return s1->position().x() < s2->position().x();
 
206
}
 
207
 
 
208
//
 
209
// OROPrimitive
 
210
//
 
211
OROPrimitive::OROPrimitive(int pType)
 
212
        : m_type(pType)
 
213
{
 
214
    m_page = 0;
 
215
}
 
216
 
 
217
OROPrimitive::~OROPrimitive()
 
218
{
 
219
    if (m_page) {
 
220
        m_page->m_primitives.removeAt(m_page->m_primitives.indexOf(this));
 
221
        m_page = 0;
 
222
    }
 
223
}
 
224
 
 
225
void OROPrimitive::setPosition(const QPointF & p)
 
226
{
 
227
    m_position = p;
 
228
}
 
229
 
 
230
//
 
231
// OROTextBox
 
232
//
 
233
const int OROTextBox::TextBox = 1;
 
234
OROTextBox::OROTextBox()
 
235
        : OROPrimitive(OROTextBox::TextBox)
 
236
{
 
237
    m_flags = 0;
 
238
 
 
239
    m_lineStyle.lineColor = Qt::black;
 
240
    m_lineStyle.weight = 0;
 
241
    m_lineStyle.style = Qt::NoPen;
 
242
}
 
243
 
 
244
OROTextBox::~OROTextBox()
 
245
{
 
246
}
 
247
 
 
248
void OROTextBox::setSize(const QSizeF & s)
 
249
{
 
250
    m_size = s;
 
251
}
 
252
 
 
253
void OROTextBox::setText(const QString & s)
 
254
{
 
255
    m_text = s;
 
256
}
 
257
 
 
258
void OROTextBox::setTextStyle(const KRTextStyleData & ts)
 
259
{
 
260
    m_textStyle = ts;
 
261
}
 
262
 
 
263
void OROTextBox::setLineStyle(const KRLineStyleData & ls)
 
264
{
 
265
    m_lineStyle = ls;
 
266
}
 
267
 
 
268
void OROTextBox::setFont(const QFont & f)
 
269
{
 
270
    m_textStyle.font = f;
 
271
}
 
272
 
 
273
void OROTextBox::setFlags(int f)
 
274
{
 
275
    m_flags = f;
 
276
}
 
277
 
 
278
OROPrimitive* OROTextBox::clone()
 
279
{
 
280
    OROTextBox *theClone = new OROTextBox();
 
281
    theClone->setSize(m_size);
 
282
    theClone->setPosition(m_position);
 
283
    theClone->setText(m_text);
 
284
    theClone->setTextStyle(m_textStyle);
 
285
    theClone->setLineStyle(m_lineStyle);
 
286
    theClone->setFlags(m_alignment);
 
287
    return theClone;
 
288
}
 
289
 
 
290
 
 
291
//
 
292
// OROLine
 
293
//
 
294
const int OROLine::Line = 2;
 
295
 
 
296
OROLine::OROLine()
 
297
        : OROPrimitive(OROLine::Line)
 
298
{
 
299
 
 
300
}
 
301
 
 
302
OROLine::~OROLine()
 
303
{
 
304
}
 
305
 
 
306
void OROLine::setStartPoint(const QPointF & p)
 
307
{
 
308
    setPosition(p);
 
309
}
 
310
 
 
311
void OROLine::setEndPoint(const QPointF & p)
 
312
{
 
313
    m_endPoint = p;
 
314
}
 
315
 
 
316
void OROLine::setLineStyle(const KRLineStyleData& ls)
 
317
{
 
318
    m_lineStyle = ls;
 
319
}
 
320
 
 
321
 
 
322
OROPrimitive* OROLine::clone()
 
323
{
 
324
    OROLine *theClone = new OROLine();
 
325
    theClone->setStartPoint(m_position);
 
326
    theClone->setEndPoint(m_endPoint);
 
327
    theClone->setLineStyle(m_lineStyle);
 
328
    return theClone;
 
329
}
 
330
 
 
331
//
 
332
// OROImage
 
333
//
 
334
const int OROImage::Image = 3;
 
335
 
 
336
OROImage::OROImage()
 
337
        : OROPrimitive(OROImage::Image)
 
338
{
 
339
    m_scaled = false;
 
340
    m_transformFlags = Qt::FastTransformation;
 
341
    m_aspectFlags = Qt::IgnoreAspectRatio;
 
342
}
 
343
 
 
344
OROImage::~OROImage()
 
345
{
 
346
}
 
347
 
 
348
void OROImage::setImage(const QImage & img)
 
349
{
 
350
    m_image = img;
 
351
}
 
352
 
 
353
void OROImage::setSize(const QSizeF & sz)
 
354
{
 
355
    m_size = sz;
 
356
}
 
357
 
 
358
void OROImage::setScaled(bool b)
 
359
{
 
360
    m_scaled = b;
 
361
}
 
362
 
 
363
void OROImage::setTransformationMode(int tm)
 
364
{
 
365
    m_transformFlags = tm;
 
366
}
 
367
 
 
368
void OROImage::setAspectRatioMode(int arm)
 
369
{
 
370
    m_aspectFlags = arm;
 
371
}
 
372
 
 
373
OROPrimitive* OROImage::clone()
 
374
{
 
375
    OROImage *theClone = new OROImage();
 
376
    theClone->setSize(m_size);
 
377
    theClone->setPosition(m_position);
 
378
    theClone->setImage(m_image);
 
379
    theClone->setScaled(m_scaled);
 
380
    theClone->setTransformationMode(m_transformFlags);
 
381
    theClone->setAspectRatioMode(m_aspectFlags);
 
382
    return theClone;
 
383
}
 
384
 
 
385
//
 
386
// OROPicture
 
387
//
 
388
const int OROPicture::Picture = 6;
 
389
 
 
390
OROPicture::OROPicture()
 
391
        : OROPrimitive(OROPicture::Picture)
 
392
{
 
393
 
 
394
}
 
395
 
 
396
OROPicture::~OROPicture()
 
397
{
 
398
}
 
399
 
 
400
void OROPicture::setSize(const QSizeF & sz)
 
401
{
 
402
    m_size = sz;
 
403
}
 
404
 
 
405
OROPrimitive* OROPicture::clone()
 
406
{
 
407
    OROPicture *theClone = new OROPicture();
 
408
    theClone->setSize(m_size);
 
409
    theClone->setPosition(m_position);
 
410
    theClone->setPicture(m_picture);
 
411
    return theClone;
 
412
}
 
413
 
 
414
//
 
415
// ORORect
 
416
//
 
417
const int ORORect::Rect = 4;
 
418
 
 
419
ORORect::ORORect()
 
420
        : OROPrimitive(ORORect::Rect)
 
421
{
 
422
}
 
423
 
 
424
ORORect::~ORORect()
 
425
{
 
426
}
 
427
 
 
428
void ORORect::setSize(const QSizeF & s)
 
429
{
 
430
    m_size = s;
 
431
}
 
432
 
 
433
void ORORect::setRect(const QRectF & r)
 
434
{
 
435
    setPosition(r.topLeft());
 
436
    setSize(r.size());
 
437
}
 
438
 
 
439
void ORORect::setPen(const QPen & p)
 
440
{
 
441
    m_pen = p;
 
442
}
 
443
 
 
444
void ORORect::setBrush(const QBrush & b)
 
445
{
 
446
    m_brush = b;
 
447
}
 
448
 
 
449
OROPrimitive* ORORect::clone()
 
450
{
 
451
    ORORect *theClone = new ORORect();
 
452
    theClone->setSize(m_size);
 
453
    theClone->setPosition(m_position);
 
454
    theClone->setPen(m_pen);
 
455
    theClone->setBrush(m_brush);
 
456
    return theClone;
 
457
}
 
458
//
 
459
// OROEllipse
 
460
//
 
461
const int OROEllipse::Ellipse = 5;
 
462
 
 
463
OROEllipse::OROEllipse()
 
464
        : OROPrimitive(OROEllipse::Ellipse)
 
465
{
 
466
}
 
467
 
 
468
OROEllipse::~OROEllipse()
 
469
{
 
470
}
 
471
 
 
472
void OROEllipse::setSize(const QSizeF & s)
 
473
{
 
474
    m_size = s;
 
475
}
 
476
 
 
477
void OROEllipse::setRect(const QRectF & r)
 
478
{
 
479
    setPosition(r.topLeft());
 
480
    setSize(r.size());
 
481
}
 
482
 
 
483
void OROEllipse::setPen(const QPen & p)
 
484
{
 
485
    m_pen = p;
 
486
}
 
487
 
 
488
void OROEllipse::setBrush(const QBrush & b)
 
489
{
 
490
    m_brush = b;
 
491
}
 
492
 
 
493
OROPrimitive* OROEllipse::clone()
 
494
{
 
495
    OROEllipse *theClone = new OROEllipse();
 
496
    theClone->setSize(m_size);
 
497
    theClone->setPosition(m_position);
 
498
    theClone->setPen(m_pen);
 
499
    theClone->setBrush(m_brush);
 
500
    return theClone;
 
501
}
 
502
 
 
503
const int OROCheck::Check = 7;
 
504
 
 
505
OROCheck::OROCheck()
 
506
        : OROPrimitive(OROCheck::Check)
 
507
{
 
508
 
 
509
}
 
510
 
 
511
OROCheck::~OROCheck()
 
512
{
 
513
 
 
514
}
 
515
 
 
516
OROPrimitive* OROCheck::clone()
 
517
{
 
518
    OROCheck *theClone = new OROCheck();
 
519
    theClone->setSize(m_size);
 
520
    theClone->setPosition(m_position);
 
521
    theClone->setLineStyle(m_lineStyle);
 
522
    theClone->setForegroundColor(m_fgColor);
 
523
    theClone->setValue(m_value);
 
524
    return theClone;
 
525
}