KReport

KReportRenderObjects.cpp
1 /* This file is part of the KDE project
2  * Copyright (C) 2001-2007 by OpenMFG, LLC ([email protected])
3  * Copyright (C) 2007-2008 by Adam Pigg ([email protected])
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
24 static bool xLessThan(OROPrimitive* s1, OROPrimitive* s2)
25 {
26  return s1->position().x() < s2->position().x();
27 }
28 
29 //
30 // ORODocument
31 //
32 
33 class Q_DECL_HIDDEN ORODocument::Private
34 {
35 public:
36  Private();
37  ~Private();
38  QString title;
39  QList<OROPage*> pages;
40  QList<OROSection*> sections;
41  KReportPrivate::PageLayout pageLayout;
42 };
43 
44 ORODocument::Private::Private()
45 {
46 
47 }
48 
49 ORODocument::Private::~Private()
50 {
51  qDeleteAll(pages);
52  qDeleteAll(sections);
53 }
54 
55 
56 ORODocument::ORODocument(const QString& title) : d(new Private())
57 {
58  d->title = title;
59 }
60 
61 ORODocument::~ORODocument()
62 {
63  delete d;
64 }
65 
66 void ORODocument::setTitle(const QString &title)
67 {
68  d->title = title;
69 }
70 
72 {
73  return d->pages.value(index);
74 }
75 
76 const 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 
100 const 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 
118 void ORODocument::setPageLayout(const QPageLayout & options)
119 {
120  d->pageLayout = options;
121 }
122 
123 void ORODocument::notifyChange(int pageNo)
124 {
125  emit(updated(pageNo));
126 }
127 
128 QPageLayout 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 
143 QString 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 
170 int ORODocument::pageIndex(const OROPage* page) const
171 {
172  return d->pages.indexOf(const_cast<OROPage*>(page));
173 }
174 
175 //
176 // OROPage
177 //
178 class Q_DECL_HIDDEN OROPage::Private
179 {
180 public:
181  Private();
182  ~Private();
183  ORODocument *document;
184  QList<OROPrimitive*> primitives;
185 };
186 
187 OROPage::Private::Private()
188 {
189 }
190 
191 OROPage::Private::~Private()
192 {
193  qDeleteAll(primitives);
194 }
195 
196 OROPage::OROPage(ORODocument * pDocument)
197  : d(new Private())
198 {
199  d->document = pDocument;
200 }
201 
202 OROPage::~OROPage()
203 {
204  if (d->document) {
205  d->document->takePage(this);
206  }
207  delete d;
208 }
209 
210 int OROPage::pageNumber() const
211 {
212  if (d->document) {
213  return d->document->pageIndex(this);
214  }
215  return -1;
216 }
217 
218 OROPrimitive* OROPage::primitive(int index)
219 {
220  return d->primitives.value(index);
221 }
222 
223 const OROPrimitive * OROPage::primitive(int index) const
224 {
225  return d->primitives.value(index);
226 }
227 
228 
229 void 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 
252 ORODocument * OROPage::document()
253 {
254  return d->document;
255 }
256 
257 const ORODocument * OROPage::document() const
258 {
259  return d->document;
260 }
261 
262 int OROPage::primitiveCount() const
263 {
264  return d->primitives.count();
265 }
266 
267 void OROPage::setDocument(ORODocument* doc)
268 {
269  d->document = doc;
270 }
271 
272 void OROPage::removePrimitive(OROPrimitive* primitive)
273 {
274  d->primitives.removeOne(primitive);
275  delete primitive;
276 }
277 
278 void OROPage::takePrimitive(OROPrimitive* primitive)
279 {
280  d->primitives.removeOne(primitive);
281 }
282 
283 //
284 // OROSection
285 //
286 
287 class Q_DECL_HIDDEN OROSection::Private
288 {
289 public:
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 
300 OROSection::Private::Private()
301 {
302 
303 }
304 
305 OROSection::Private::~Private()
306 {
307  qDeleteAll(primitives);
308  primitives.clear();
309 }
310 
311 OROSection::OROSection(ORODocument* doc) : d(new Private())
312 {
313  d->document = doc;
314 }
315 
316 OROSection::~OROSection()
317 {
318  if (d->document) {
319  d->document->takeSection(this);
320  }
321 
322  delete d;
323 }
324 
325 OROPrimitive* OROSection::primitive(int index)
326 {
327  return d->primitives.value(index);
328 }
329 
330 const OROPrimitive * OROSection::primitive(int index) const
331 {
332  return d->primitives.value(index);
333 }
334 
335 void OROSection::addPrimitive(OROPrimitive* primitive)
336 {
337  if (primitive == nullptr)
338  return;
339 
340  d->primitives.append(primitive);
341 }
342 
343 void OROSection::setHeight(int h)
344 {
345  d->height = h;
346 }
347 
348 int OROSection::height() const
349 {
350  return d->height;
351 }
352 
353 void OROSection::setBackgroundColor(const QColor& color)
354 {
355  d->backgroundColor = color;
356 }
357 
358 QColor OROSection::backgroundColor() const
359 {
360  return d->backgroundColor;
361 }
362 
363 void OROSection::sortPrimitives(Qt::Orientation orientation)
364 {
365  if (orientation == Qt::Horizontal) {
366  qSort(d->primitives.begin(), d->primitives.end(), xLessThan);
367  }
368 }
369 
370 ORODocument * OROSection::document()
371 {
372  return d->document;
373 }
374 
375 const ORODocument * OROSection::document() const
376 {
377  return d->document;
378 }
379 
380 
381 int OROSection::primitiveCount() const
382 {
383  return d->primitives.count();
384 }
385 
386 void OROSection::setType(KReportSectionData::Type type)
387 {
388  d->type = type;
389 }
390 
391 KReportSectionData::Type OROSection::type() const
392 {
393  return d->type;
394 }
395 
396 void OROSection::setDocument(ORODocument* doc)
397 {
398  d->document = doc;
399 }
400 
401 //
402 // OROPrimitive
403 //
404 
405 class Q_DECL_HIDDEN OROPrimitive::Private
406 {
407 public:
408  OROPage * page = nullptr;
409  QPointF position;
410  QSizeF size;
411 };
412 
413 OROPrimitive::OROPrimitive()
414  : d(new Private())
415 {
416 }
417 
418 OROPrimitive::~OROPrimitive()
419 {
420  if (d->page) {
421  d->page->takePrimitive(this);
422  }
423 
424  delete d;
425 }
426 
427 void OROPrimitive::setPosition(const QPointF& pos)
428 {
429  d->position = pos;
430 }
431 
432 void OROPrimitive::setSize(const QSizeF & s)
433 {
434  d->size = s;
435 }
436 
437 OROPage * OROPrimitive::page()
438 {
439  return d->page;
440 }
441 
442 const OROPage * OROPrimitive::page() const
443 {
444  return d->page;
445 }
446 
447 QPointF OROPrimitive::position() const
448 {
449  return d->position;
450 }
451 
452 QSizeF OROPrimitive::size() const
453 {
454  return d->size;
455 }
456 
457 void OROPrimitive::setPage(OROPage* page)
458 {
459  d->page = page;
460 }
461 
462 //
463 // OROTextBox
464 //
465 
466 class Q_DECL_HIDDEN OROTextBox::Private
467 {
468 public:
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 
482 OROTextBox::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 
494 OROTextBox::Private::~Private()
495 {
496 }
497 
498 OROTextBox::OROTextBox() : d(new Private())
499 {
500 
501 }
502 
503 OROTextBox::~OROTextBox()
504 {
505  delete d;
506 }
507 
508 void OROTextBox::setText(const QString & s)
509 {
510  d->text = s;
511 }
512 
513 void OROTextBox::setTextStyle(const KReportTextStyleData & ts)
514 {
515  d->textStyle = ts;
516 }
517 
518 void OROTextBox::setLineStyle(const KReportLineStyle & ls)
519 {
520  d->lineStyle = ls;
521 }
522 
523 void OROTextBox::setFont(const QFont & f)
524 {
525  d->textStyle.font = f;
526 }
527 
528 void OROTextBox::setFlags(int f)
529 {
530  d->flags = f;
531 }
532 
533 bool OROTextBox::canGrow() const
534 {
535  return d->canGrow;
536 }
537 
538 int OROTextBox::flags() const
539 {
540  return d->flags;
541 }
542 
543 KReportLineStyle OROTextBox::lineStyle() const
544 {
545  return d->lineStyle;
546 }
547 
548 bool OROTextBox::requiresPostProcessing() const
549 {
550  return d->requiresPostProcessing;
551 }
552 
553 void OROTextBox::setCanGrow(bool grow)
554 {
555  d->canGrow = grow;
556 }
557 
558 void OROTextBox::setRequiresPostProcessing(bool pp)
559 {
560  d->requiresPostProcessing = pp;
561 }
562 
563 void OROTextBox::setWordWrap(bool ww)
564 {
565  d->wordWrap = ww;
566 }
567 
568 QString OROTextBox::text() const
569 {
570  return d->text;
571 }
572 
573 KReportTextStyleData OROTextBox::textStyle() const
574 {
575  return d->textStyle;
576 }
577 
578 bool OROTextBox::wordWrap() const
579 {
580  return d->wordWrap;
581 }
582 
583 OROPrimitive* 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 
603 class Q_DECL_HIDDEN OROLine::Private
604 {
605 public:
606  QPointF endPoint;
607  KReportLineStyle lineStyle;
608 };
609 
610 OROLine::OROLine() : d(new Private())
611 {
612 
613 }
614 
615 OROLine::~OROLine()
616 {
617  delete d;
618 }
619 
620 void OROLine::setStartPoint(const QPointF & p)
621 {
622  setPosition(p);
623 }
624 
625 void OROLine::setEndPoint(const QPointF & p)
626 {
627  d->endPoint = p;
628 }
629 
630 void OROLine::setLineStyle(const KReportLineStyle& style)
631 {
632  d->lineStyle = style;
633 }
634 
635 QPointF OROLine::endPoint() const
636 {
637  return d->endPoint;
638 }
639 
640 KReportLineStyle OROLine::lineStyle() const
641 {
642  return d->lineStyle;
643 }
644 
645 OROPrimitive* 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 
658 class Q_DECL_HIDDEN OROImage::Private
659 {
660 public:
661  QImage image;
662  bool scaled;
663  Qt::TransformationMode transformFlags;
664  Qt::AspectRatioMode aspectFlags;
665 };
666 
667 OROImage::OROImage() : d(new Private())
668 {
669  d->scaled = false;
670  d->transformFlags = Qt::FastTransformation;
671  d->aspectFlags = Qt::IgnoreAspectRatio;
672 }
673 
674 OROImage::~OROImage()
675 {
676  delete d;
677 }
678 
679 void OROImage::setImage(const QImage & img)
680 {
681  d->image = img;
682 }
683 
684 void OROImage::setScaled(bool b)
685 {
686  d->scaled = b;
687 }
688 
689 void OROImage::setTransformationMode(Qt::TransformationMode transformation)
690 {
691  d->transformFlags = transformation;
692 }
693 
694 void OROImage::setAspectRatioMode(Qt::AspectRatioMode aspectRatioMode)
695 {
696  d->aspectFlags = aspectRatioMode;
697 }
698 
699 Qt::AspectRatioMode OROImage::aspectRatioMode() const
700 {
701  return d->aspectFlags;
702 }
703 
704 QImage OROImage::image() const
705 {
706  return d->image;
707 }
708 
709 bool OROImage::isScaled() const
710 {
711  return d->scaled;
712 }
713 
714 Qt::TransformationMode OROImage::transformationMode() const
715 {
716  return d->transformFlags;
717 }
718 
719 OROPrimitive* 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 
735 class Q_DECL_HIDDEN OROPicture::Private
736 {
737 public:
738  QPicture picture;
739 };
740 
741 OROPicture::OROPicture() : d(new Private())
742 {
743 
744 }
745 
746 OROPicture::~OROPicture()
747 {
748  delete d;
749 }
750 
751 OROPrimitive* 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 
760 QPicture* OROPicture::picture()
761 {
762  return &d->picture;
763 }
764 
765 void OROPicture::setPicture(const QPicture& p)
766 {
767  d->picture = p;
768 }
769 
770 //
771 // ORORect
772 //
773 
774 class Q_DECL_HIDDEN ORORect::Private
775 {
776 public:
777  QPen pen;
778  QBrush brush;
779 };
780 
781 ORORect::ORORect() : d(new Private())
782 {
783 }
784 
785 ORORect::~ORORect()
786 {
787  delete d;
788 }
789 
790 void ORORect::setRect(const QRectF & r)
791 {
792  setPosition(r.topLeft());
793  setSize(r.size());
794 }
795 
796 void ORORect::setPen(const QPen & p)
797 {
798  d->pen = p;
799 }
800 
801 void ORORect::setBrush(const QBrush & b)
802 {
803  d->brush = b;
804 }
805 
806 QBrush ORORect::brush() const
807 {
808  return d->brush;
809 }
810 
811 QPen ORORect::pen() const
812 {
813  return d->pen;
814 }
815 
816 QRectF ORORect::rect() const
817 {
818  return QRectF(position(), size());
819 }
820 
821 OROPrimitive* 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 
834 class Q_DECL_HIDDEN OROEllipse::Private
835 {
836 public:
837  QPen pen;
838  QBrush brush;
839 };
840 
841 OROEllipse::OROEllipse() : d(new Private())
842 {
843 }
844 
845 OROEllipse::~OROEllipse()
846 {
847  delete d;
848 }
849 
850 void OROEllipse::setRect(const QRectF & r)
851 {
852  setPosition(r.topLeft());
853  setSize(r.size());
854 }
855 
856 void OROEllipse::setPen(const QPen & p)
857 {
858  d->pen = p;
859 }
860 
861 void OROEllipse::setBrush(const QBrush & b)
862 {
863  d->brush = b;
864 }
865 
866 QBrush OROEllipse::brush() const
867 {
868  return d->brush;
869 }
870 
871 QPen OROEllipse::pen() const
872 {
873  return d->pen;
874 }
875 
876 QRectF OROEllipse::rect() const
877 {
878  return QRectF(position(), size());
879 }
880 
881 OROPrimitive* 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 
895 class Q_DECL_HIDDEN OROCheckBox::Private
896 {
897 public:
898  OROCheckBox::Type checkType;
899  bool value;
900  KReportLineStyle lineStyle;
901  QColor foregroundColor;
902 };
903 
904 OROCheckBox::OROCheckBox() : d(new Private())
905 {
906  d->value = false;
907 }
908 
909 OROCheckBox::~OROCheckBox()
910 {
911  delete d;
912 }
913 
914 OROCheckBox::Type OROCheckBox::checkType() const
915 {
916  return d->checkType;
917 }
918 
919 QColor OROCheckBox::foregroundColor() const
920 {
921  return d->foregroundColor;
922 }
923 
924 KReportLineStyle OROCheckBox::lineStyle() const
925 {
926  return d->lineStyle;
927 }
928 
929 void OROCheckBox::setForegroundColor(const QColor& fg)
930 {
931  d->foregroundColor = fg;
932 }
933 
934 void OROCheckBox::setLineStyle(const KReportLineStyle& ls)
935 {
936  d->lineStyle = ls;
937 }
938 
939 void OROCheckBox::setValue(bool v)
940 {
941  d->value = v;
942 }
943 
944 bool OROCheckBox::value() const
945 {
946  return d->value;
947 }
948 
949 void 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 
958 OROPrimitive* 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 }
OROPage * page(int index)
Return a pointer to a given page.
typedef Alignment
A text box primitive it defines a box region and text that will be rendered inside that region,...
The KReportLineStyle class represents line style.
OROSection * section(int index)
Return a pointer to a given section.
Defines an image. An image is a bitmap.
Type type(const QSqlDatabase &db)
int pageIndex(const OROPage *page) const
Returns the index of the supplied page in the document.
void takePage(OROPage *page)
Takes the page from the document but does not delete it.
Represents a single page in a document and may contain zero or more OROPrimitive objects all of which...
Defines a rectangle.
AspectRatioMode
QPointF topLeft() const const
Orientation
Represents a single document containing one or more OROPage elements.
Defines a picture. A picture is different to an image, in that it is drawn using commands.
Defines checkbox.
qreal x() const const
Represents a single a single row in a document and may contain zero or more OROPrimitives.
void addPage(OROPage *page)
Adds the supplied page to this document.
void removeSection(OROSection *section)
Removes the supplied section from the document.
Defines an ellipse.
int sectionCount() const
Return the total number of sections in the document.
int pageCount() const
Return the total number of pages in the document.
QSizeF size() const const
Represents the basic primitive with a position and type. Other primitives are subclasses with a defin...
void removePage(OROPage *page)
Removes the given page from the document.
Defines a line with a width/weight.
TransformationMode
void takeSection(OROSection *section)
Takes the section from the document but does not delete it.
void addSection(OROSection *section)
Adds the supplied sectin to the document.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Jun 27 2022 04:26:40 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.