KReport

KReportRenderObjects.cpp
1/* This file is part of the KDE project
2 * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
3 * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
17 */
18#include "KReportRenderObjects.h"
19#include "KReportUtils_p.h"
20
21#include "kreport_debug.h"
22
23// Helper functions
24static bool xLessThan(OROPrimitive* s1, OROPrimitive* s2)
25{
26 return s1->position().x() < s2->position().x();
27}
28
29//
30// ORODocument
31//
32
33class Q_DECL_HIDDEN ORODocument::Private
34{
35public:
36 Private();
37 ~Private();
38 QString title;
39 QList<OROPage*> pages;
40 QList<OROSection*> sections;
41 KReportPrivate::PageLayout pageLayout;
42};
43
44ORODocument::Private::Private()
45{
46
47}
48
49ORODocument::Private::~Private()
50{
51 qDeleteAll(pages);
52 qDeleteAll(sections);
53}
54
55
56ORODocument::ORODocument(const QString& title) : d(new Private())
57{
58 d->title = title;
59}
60
61ORODocument::~ORODocument()
62{
63 delete d;
64}
65
66void ORODocument::setTitle(const QString &title)
67{
68 d->title = title;
69}
70
72{
73 return d->pages.value(index);
74}
75
76const OROPage * ORODocument::page(int index) const
77{
78 return d->pages.value(index);
79}
80
82{
83 if (p == nullptr) {
84 return;
85 }
86
87 if (p->document() != nullptr && p->document() != this) {
88 return;
89 }
90
91 p->setDocument(this);
92 d->pages.append(p);
93}
94
96{
97 return d->sections.value(pnum);
98}
99
100const OROSection * ORODocument::section(int index) const
101{
102 return d->sections.value(index);
103}
104
105
107{
108 if (s == nullptr)
109 return;
110
111 if (s->document() != nullptr && s->document() != this) {
112 return;
113 }
114 s->setDocument(this);
115 d->sections.append(s);
116}
117
118void ORODocument::setPageLayout(const QPageLayout & options)
119{
120 d->pageLayout = options;
121}
122
123void ORODocument::notifyChange(int pageNo)
124{
125 emit(updated(pageNo));
126}
127
128QPageLayout ORODocument::pageLayout() const
129{
130 return d->pageLayout;
131}
132
134{
135 return d->pages.count();
136}
137
139{
140 return d->sections.count();
141}
142
143QString ORODocument::title() const
144{
145 return d->title;
146}
147
149{
150 d->pages.removeOne(page);
151 delete page;
152}
153
155{
156 d->pages.removeOne(page);
157}
158
160{
161 d->sections.removeOne(section);
162 delete section;
163}
164
166{
167 d->sections.removeOne(section);
168}
169
170int ORODocument::pageIndex(const OROPage* page) const
171{
172 return d->pages.indexOf(const_cast<OROPage*>(page));
173}
174
175//
176// OROPage
177//
178class Q_DECL_HIDDEN OROPage::Private
179{
180public:
181 Private();
182 ~Private();
183 ORODocument *document;
184 QList<OROPrimitive*> primitives;
185};
186
187OROPage::Private::Private()
188{
189}
190
191OROPage::Private::~Private()
192{
193 qDeleteAll(primitives);
194}
195
196OROPage::OROPage(ORODocument * pDocument)
197 : d(new Private())
198{
199 d->document = pDocument;
200}
201
202OROPage::~OROPage()
203{
204 if (d->document) {
205 d->document->takePage(this);
206 }
207 delete d;
208}
209
210int OROPage::pageNumber() const
211{
212 if (d->document) {
213 return d->document->pageIndex(this);
214 }
215 return -1;
216}
217
218OROPrimitive* OROPage::primitive(int index)
219{
220 return d->primitives.value(index);
221}
222
223const OROPrimitive * OROPage::primitive(int index) const
224{
225 return d->primitives.value(index);
226}
227
228
229void OROPage::insertPrimitive(OROPrimitive* p, int index)
230{
231 //kreportDebug() << "Adding primitive" << p->type() << "to page" << page();
232 if (p == nullptr)
233 return;
234
235 p->setPage(this);
236 if (index == -1) {
237 d->primitives.append(p);
238 } else {
239 d->primitives.insert(index, p);
240 }
241
242#if 0
243//TODO
244 if (notify) {
245 if (d->document) {
246 d->document->notifyChange(pageNumber());
247 }
248 }
249#endif
250}
251
252ORODocument * OROPage::document()
253{
254 return d->document;
255}
256
257const ORODocument * OROPage::document() const
258{
259 return d->document;
260}
261
262int OROPage::primitiveCount() const
263{
264 return d->primitives.count();
265}
266
267void OROPage::setDocument(ORODocument* doc)
268{
269 d->document = doc;
270}
271
272void OROPage::removePrimitive(OROPrimitive* primitive)
273{
274 d->primitives.removeOne(primitive);
275 delete primitive;
276}
277
278void OROPage::takePrimitive(OROPrimitive* primitive)
279{
280 d->primitives.removeOne(primitive);
281}
282
283//
284// OROSection
285//
286
287class Q_DECL_HIDDEN OROSection::Private
288{
289public:
290 Private();
291 ~Private();
292 ORODocument * document;
293 QList<OROPrimitive*> primitives;
294 qint64 row = 0;
295 int height = 0;
296 KReportSectionData::Type type = KReportSectionData::Type::None;
297 QColor backgroundColor = Qt::white;
298};
299
300OROSection::Private::Private()
301{
302
303}
304
305OROSection::Private::~Private()
306{
307 qDeleteAll(primitives);
308 primitives.clear();
309}
310
311OROSection::OROSection(ORODocument* doc) : d(new Private())
312{
313 d->document = doc;
314}
315
316OROSection::~OROSection()
317{
318 if (d->document) {
319 d->document->takeSection(this);
320 }
321
322 delete d;
323}
324
325OROPrimitive* OROSection::primitive(int index)
326{
327 return d->primitives.value(index);
328}
329
330const OROPrimitive * OROSection::primitive(int index) const
331{
332 return d->primitives.value(index);
333}
334
335void OROSection::addPrimitive(OROPrimitive* primitive)
336{
337 if (primitive == nullptr)
338 return;
339
340 d->primitives.append(primitive);
341}
342
343void OROSection::setHeight(int h)
344{
345 d->height = h;
346}
347
348int OROSection::height() const
349{
350 return d->height;
351}
352
353void OROSection::setBackgroundColor(const QColor& color)
354{
355 d->backgroundColor = color;
356}
357
358QColor OROSection::backgroundColor() const
359{
360 return d->backgroundColor;
361}
362
363void OROSection::sortPrimitives(Qt::Orientation orientation)
364{
365 if (orientation == Qt::Horizontal) {
366 std::sort(d->primitives.begin(), d->primitives.end(), xLessThan);
367 }
368}
369
370ORODocument * OROSection::document()
371{
372 return d->document;
373}
374
375const ORODocument * OROSection::document() const
376{
377 return d->document;
378}
379
380
381int OROSection::primitiveCount() const
382{
383 return d->primitives.count();
384}
385
386void OROSection::setType(KReportSectionData::Type type)
387{
388 d->type = type;
389}
390
391KReportSectionData::Type OROSection::type() const
392{
393 return d->type;
394}
395
396void OROSection::setDocument(ORODocument* doc)
397{
398 d->document = doc;
399}
400
401//
402// OROPrimitive
403//
404
405class Q_DECL_HIDDEN OROPrimitive::Private
406{
407public:
408 OROPage * page = nullptr;
409 QPointF position;
410 QSizeF size;
411};
412
413OROPrimitive::OROPrimitive()
414 : d(new Private())
415{
416}
417
418OROPrimitive::~OROPrimitive()
419{
420 if (d->page) {
421 d->page->takePrimitive(this);
422 }
423
424 delete d;
425}
426
427void OROPrimitive::setPosition(const QPointF& pos)
428{
429 d->position = pos;
430}
431
432void OROPrimitive::setSize(const QSizeF & s)
433{
434 d->size = s;
435}
436
437OROPage * OROPrimitive::page()
438{
439 return d->page;
440}
441
442const OROPage * OROPrimitive::page() const
443{
444 return d->page;
445}
446
447QPointF OROPrimitive::position() const
448{
449 return d->position;
450}
451
452QSizeF OROPrimitive::size() const
453{
454 return d->size;
455}
456
457void OROPrimitive::setPage(OROPage* page)
458{
459 d->page = page;
460}
461
462//
463// OROTextBox
464//
465
466class Q_DECL_HIDDEN OROTextBox::Private
467{
468public:
469 Private();
470 ~Private();
471 QString text;
472 KReportTextStyleData textStyle;
473 KReportLineStyle lineStyle;
474 Qt::Alignment alignment;
475 int flags; // Qt::AlignmentFlag and Qt::TextFlag OR'd
476 bool wordWrap;
477 bool canGrow;
478 bool requiresPostProcessing;
479
480};
481
482OROTextBox::Private::Private()
483{
484 flags = 0;
485 wordWrap = false;
486 canGrow = false;
487 requiresPostProcessing = false;
488
489 lineStyle.setColor(Qt::black);
490 lineStyle.setWeight(0);
491 lineStyle.setPenStyle(Qt::NoPen);
492}
493
494OROTextBox::Private::~Private()
495{
496}
497
498OROTextBox::OROTextBox() : d(new Private())
499{
500
501}
502
503OROTextBox::~OROTextBox()
504{
505 delete d;
506}
507
508void OROTextBox::setText(const QString & s)
509{
510 d->text = s;
511}
512
513void OROTextBox::setTextStyle(const KReportTextStyleData & ts)
514{
515 d->textStyle = ts;
516}
517
518void OROTextBox::setLineStyle(const KReportLineStyle & ls)
519{
520 d->lineStyle = ls;
521}
522
523void OROTextBox::setFont(const QFont & f)
524{
525 d->textStyle.font = f;
526}
527
528void OROTextBox::setFlags(int f)
529{
530 d->flags = f;
531}
532
533bool OROTextBox::canGrow() const
534{
535 return d->canGrow;
536}
537
538int OROTextBox::flags() const
539{
540 return d->flags;
541}
542
543KReportLineStyle OROTextBox::lineStyle() const
544{
545 return d->lineStyle;
546}
547
548bool OROTextBox::requiresPostProcessing() const
549{
550 return d->requiresPostProcessing;
551}
552
553void OROTextBox::setCanGrow(bool grow)
554{
555 d->canGrow = grow;
556}
557
558void OROTextBox::setRequiresPostProcessing(bool pp)
559{
560 d->requiresPostProcessing = pp;
561}
562
563void OROTextBox::setWordWrap(bool ww)
564{
565 d->wordWrap = ww;
566}
567
568QString OROTextBox::text() const
569{
570 return d->text;
571}
572
573KReportTextStyleData OROTextBox::textStyle() const
574{
575 return d->textStyle;
576}
577
578bool OROTextBox::wordWrap() const
579{
580 return d->wordWrap;
581}
582
583OROPrimitive* OROTextBox::clone() const
584{
585 OROTextBox *theClone = new OROTextBox();
586 theClone->setSize(size());
587 theClone->setPosition(position());
588 theClone->setText(text());
589 theClone->setTextStyle(textStyle());
590 theClone->setLineStyle(lineStyle());
591 theClone->setFlags(flags());
592 theClone->setCanGrow(canGrow());
593 theClone->setWordWrap(wordWrap());
594 theClone->setRequiresPostProcessing(requiresPostProcessing());
595 return theClone;
596}
597
598
599//
600// OROLine
601//
602
603class Q_DECL_HIDDEN OROLine::Private
604{
605public:
606 QPointF endPoint;
607 KReportLineStyle lineStyle;
608};
609
610OROLine::OROLine() : d(new Private())
611{
612
613}
614
615OROLine::~OROLine()
616{
617 delete d;
618}
619
620void OROLine::setStartPoint(const QPointF & p)
621{
622 setPosition(p);
623}
624
625void OROLine::setEndPoint(const QPointF & p)
626{
627 d->endPoint = p;
628}
629
630void OROLine::setLineStyle(const KReportLineStyle& style)
631{
632 d->lineStyle = style;
633}
634
635QPointF OROLine::endPoint() const
636{
637 return d->endPoint;
638}
639
640KReportLineStyle OROLine::lineStyle() const
641{
642 return d->lineStyle;
643}
644
645OROPrimitive* OROLine::clone() const
646{
647 OROLine *theClone = new OROLine();
648 theClone->setStartPoint(position());
649 theClone->setEndPoint(endPoint());
650 theClone->setLineStyle(lineStyle());
651 return theClone;
652}
653
654//
655// OROImage
656//
657
658class Q_DECL_HIDDEN OROImage::Private
659{
660public:
661 QImage image;
662 bool scaled;
663 Qt::TransformationMode transformFlags;
664 Qt::AspectRatioMode aspectFlags;
665};
666
667OROImage::OROImage() : d(new Private())
668{
669 d->scaled = false;
670 d->transformFlags = Qt::FastTransformation;
671 d->aspectFlags = Qt::IgnoreAspectRatio;
672}
673
674OROImage::~OROImage()
675{
676 delete d;
677}
678
679void OROImage::setImage(const QImage & img)
680{
681 d->image = img;
682}
683
684void OROImage::setScaled(bool b)
685{
686 d->scaled = b;
687}
688
689void OROImage::setTransformationMode(Qt::TransformationMode transformation)
690{
691 d->transformFlags = transformation;
692}
693
694void OROImage::setAspectRatioMode(Qt::AspectRatioMode aspectRatioMode)
695{
696 d->aspectFlags = aspectRatioMode;
697}
698
699Qt::AspectRatioMode OROImage::aspectRatioMode() const
700{
701 return d->aspectFlags;
702}
703
704QImage OROImage::image() const
705{
706 return d->image;
707}
708
709bool OROImage::isScaled() const
710{
711 return d->scaled;
712}
713
714Qt::TransformationMode OROImage::transformationMode() const
715{
716 return d->transformFlags;
717}
718
719OROPrimitive* OROImage::clone() const
720{
721 OROImage *theClone = new OROImage();
722 theClone->setSize(size());
723 theClone->setPosition(position());
724 theClone->setImage(image());
725 theClone->setScaled(isScaled());
726 theClone->setTransformationMode(transformationMode());
727 theClone->setAspectRatioMode(aspectRatioMode());
728 return theClone;
729}
730
731//
732// OROPicture
733//
734
735class Q_DECL_HIDDEN OROPicture::Private
736{
737public:
738 QPicture picture;
739};
740
741OROPicture::OROPicture() : d(new Private())
742{
743
744}
745
746OROPicture::~OROPicture()
747{
748 delete d;
749}
750
751OROPrimitive* OROPicture::clone() const
752{
753 OROPicture *theClone = new OROPicture();
754 theClone->setSize(size());
755 theClone->setPosition(position());
756// theClone->setPicture(*(picture()ddddddds));
757 return theClone;
758}
759
760QPicture* OROPicture::picture()
761{
762 return &d->picture;
763}
764
765void OROPicture::setPicture(const QPicture& p)
766{
767 d->picture = p;
768}
769
770//
771// ORORect
772//
773
774class Q_DECL_HIDDEN ORORect::Private
775{
776public:
777 QPen pen;
778 QBrush brush;
779};
780
781ORORect::ORORect() : d(new Private())
782{
783}
784
785ORORect::~ORORect()
786{
787 delete d;
788}
789
790void ORORect::setRect(const QRectF & r)
791{
792 setPosition(r.topLeft());
793 setSize(r.size());
794}
795
796void ORORect::setPen(const QPen & p)
797{
798 d->pen = p;
799}
800
801void ORORect::setBrush(const QBrush & b)
802{
803 d->brush = b;
804}
805
806QBrush ORORect::brush() const
807{
808 return d->brush;
809}
810
811QPen ORORect::pen() const
812{
813 return d->pen;
814}
815
816QRectF ORORect::rect() const
817{
818 return QRectF(position(), size());
819}
820
821OROPrimitive* ORORect::clone() const
822{
823 ORORect *theClone = new ORORect();
824 theClone->setSize(size());
825 theClone->setPosition(position());
826 theClone->setPen(pen());
827 theClone->setBrush(brush());
828 return theClone;
829}
830//
831// OROEllipse
832//
833
834class Q_DECL_HIDDEN OROEllipse::Private
835{
836public:
837 QPen pen;
838 QBrush brush;
839};
840
841OROEllipse::OROEllipse() : d(new Private())
842{
843}
844
845OROEllipse::~OROEllipse()
846{
847 delete d;
848}
849
850void OROEllipse::setRect(const QRectF & r)
851{
852 setPosition(r.topLeft());
853 setSize(r.size());
854}
855
856void OROEllipse::setPen(const QPen & p)
857{
858 d->pen = p;
859}
860
861void OROEllipse::setBrush(const QBrush & b)
862{
863 d->brush = b;
864}
865
866QBrush OROEllipse::brush() const
867{
868 return d->brush;
869}
870
871QPen OROEllipse::pen() const
872{
873 return d->pen;
874}
875
876QRectF OROEllipse::rect() const
877{
878 return QRectF(position(), size());
879}
880
881OROPrimitive* OROEllipse::clone() const
882{
883 OROEllipse *theClone = new OROEllipse();
884 theClone->setSize(size());
885 theClone->setPosition(position());
886 theClone->setPen(pen());
887 theClone->setBrush(brush());
888 return theClone;
889}
890
891//
892// OROCheck
893//
894
895class Q_DECL_HIDDEN OROCheckBox::Private
896{
897public:
898 OROCheckBox::Type checkType;
899 bool value;
900 KReportLineStyle lineStyle;
901 QColor foregroundColor;
902};
903
904OROCheckBox::OROCheckBox() : d(new Private())
905{
906 d->value = false;
907}
908
909OROCheckBox::~OROCheckBox()
910{
911 delete d;
912}
913
914OROCheckBox::Type OROCheckBox::checkType() const
915{
916 return d->checkType;
917}
918
919QColor OROCheckBox::foregroundColor() const
920{
921 return d->foregroundColor;
922}
923
924KReportLineStyle OROCheckBox::lineStyle() const
925{
926 return d->lineStyle;
927}
928
929void OROCheckBox::setForegroundColor(const QColor& fg)
930{
931 d->foregroundColor = fg;
932}
933
934void OROCheckBox::setLineStyle(const KReportLineStyle& ls)
935{
936 d->lineStyle = ls;
937}
938
939void OROCheckBox::setValue(bool v)
940{
941 d->value = v;
942}
943
944bool OROCheckBox::value() const
945{
946 return d->value;
947}
948
949void OROCheckBox::setCheckType(Type type)
950{
951 if (type == Type::Cross || type == Type::Tick || type == Type::Dot) {
952 d->checkType = type;
953 } else {
954 d->checkType = Type::Cross;
955 }
956}
957
958OROPrimitive* OROCheckBox::clone() const
959{
960 OROCheckBox *theClone = new OROCheckBox();
961 theClone->setSize(size());
962 theClone->setPosition(position());
963 theClone->setLineStyle(lineStyle());
964 theClone->setForegroundColor(foregroundColor());
965 theClone->setValue(value());
966 theClone->setCheckType(checkType());
967 return theClone;
968}
The KReportLineStyle class represents line style.
Defines checkbox.
Represents a single document containing one or more OROPage elements.
void takePage(OROPage *page)
Takes the page from the document but does not delete it.
int pageCount() const
Return the total number of pages in the document.
void removePage(OROPage *page)
Removes the given page from the document.
void addPage(OROPage *page)
Adds the supplied page to this document.
void addSection(OROSection *section)
Adds the supplied sectin to the document.
int pageIndex(const OROPage *page) const
Returns the index of the supplied page in the document.
OROPage * page(int index)
Return a pointer to a given page.
OROSection * section(int index)
Return a pointer to a given section.
void removeSection(OROSection *section)
Removes the supplied section from the document.
void takeSection(OROSection *section)
Takes the section from the document but does not delete it.
int sectionCount() const
Return the total number of sections in the document.
Defines an ellipse.
Defines an image. An image is a bitmap.
Defines a line with a width/weight.
Represents a single page in a document and may contain zero or more OROPrimitive objects all of which...
Defines a picture. A picture is different to an image, in that it is drawn using commands.
Represents the basic primitive with a position and type. Other primitives are subclasses with a defin...
Defines a rectangle.
Represents a single a single row in a document and may contain zero or more OROPrimitives.
A text box primitive it defines a box region and text that will be rendered inside that region,...
Type type(const QSqlDatabase &db)
void append(QList< T > &&value)
iterator begin()
qsizetype count() const const
iterator end()
qsizetype indexOf(const AT &value, qsizetype from) const const
iterator insert(const_iterator before, parameter_type value)
bool removeOne(const AT &t)
T value(qsizetype i) const const
qreal x() const const
QSizeF size() const const
QPointF topLeft() const const
typedef Alignment
AspectRatioMode
Orientation
TransformationMode
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:19:58 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.