diff --git a/src/renderer/KReportHTMLCSSRenderer_p.cpp b/src/renderer/KReportHTMLCSSRenderer_p.cpp --- a/src/renderer/KReportHTMLCSSRenderer_p.cpp +++ b/src/renderer/KReportHTMLCSSRenderer_p.cpp @@ -54,7 +54,7 @@ QString tempFileName = fi.absoluteFilePath(); m_tempDirName = tempFileName + dirSuffix; - m_actualDirName = context.destinationUrl.fileName() + dirSuffix; + m_actualDirName = context.url().fileName() + dirSuffix; if (!tempDir.mkpath(m_tempDirName)) return false; diff --git a/src/renderer/KReportHTMLTableRenderer_p.cpp b/src/renderer/KReportHTMLTableRenderer_p.cpp --- a/src/renderer/KReportHTMLTableRenderer_p.cpp +++ b/src/renderer/KReportHTMLTableRenderer_p.cpp @@ -54,7 +54,7 @@ QString tempFileName = fi.absoluteFilePath(); m_tempDirName = tempFileName + dirSuffix; - m_actualDirName = context.destinationUrl.fileName() + dirSuffix; + m_actualDirName = context.url().fileName() + dirSuffix; if (!tempDir.mkpath(m_tempDirName)) return false; diff --git a/src/renderer/KReportPage.cpp b/src/renderer/KReportPage.cpp --- a/src/renderer/KReportPage.cpp +++ b/src/renderer/KReportPage.cpp @@ -109,7 +109,7 @@ QPainter qp(&d->pixmap); if (d->reportDocument) { KReportRendererContext cxt; - cxt.painter = &qp; + cxt.setPainter(&qp); d->renderer->render(cxt, d->reportDocument, d->page); } update(); diff --git a/src/renderer/KReportPrintRenderer_p.cpp b/src/renderer/KReportPrintRenderer_p.cpp --- a/src/renderer/KReportPrintRenderer_p.cpp +++ b/src/renderer/KReportPrintRenderer_p.cpp @@ -59,38 +59,38 @@ bool PrintRenderer::render(const KReportRendererContext &context, ORODocument *document, int page) { Q_UNUSED(page); - if (document == 0 || context.printer == 0 || context.painter == 0) + if (document == 0 || context.printer() == 0 || context.painter() == 0) return false; - setupPrinter(document, context.printer); + setupPrinter(document, context.printer()); bool endWhenComplete = false; - if (!context.painter->isActive()) { + if (!context.painter()->isActive()) { endWhenComplete = true; - if (!context.painter->begin(context.printer)) + if (!context.painter()->begin(context.printer())) return false; } - int fromPage = context.printer->fromPage(); + int fromPage = context.printer()->fromPage(); if (fromPage > 0) fromPage -= 1; - int toPage = context.printer->toPage(); + int toPage = context.printer()->toPage(); if (toPage == 0 || toPage > document->pageCount()) toPage = document->pageCount(); - qreal scaleX = context.printer->resolution() / qreal(KReportDpi::dpiX()); - qreal scaleY = context.printer->resolution() / qreal(KReportDpi::dpiY()); + qreal scaleX = context.printer()->resolution() / qreal(KReportDpi::dpiX()); + qreal scaleY = context.printer()->resolution() / qreal(KReportDpi::dpiY()); - for (int copy = 0; copy < context.printer->numCopies(); copy++) { + for (int copy = 0; copy < context.printer()->numCopies(); copy++) { for (int page = fromPage; page < toPage; page++) { if (page > fromPage) - context.printer->newPage(); + context.printer()->newPage(); OROPage * p = document->page(page); - if (context.printer->pageOrder() == QPrinter::LastPageFirst) + if (context.printer()->pageOrder() == QPrinter::LastPageFirst) p = document->page(toPage - 1 - page); // Render Page Objects @@ -109,42 +109,42 @@ QSizeF sz = tb->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); - context.painter->save(); + context.painter()->save(); //Background QColor bg = tb->textStyle().backgroundColor; bg.setAlphaF(0.01 * tb->textStyle().backgroundOpacity); - //_painter->setBackgroundMode(Qt::OpaqueMode); - context.painter->fillRect(rc, bg); + //_painter()->setBackgroundMode(Qt::OpaqueMode); + context.painter()->fillRect(rc, bg); //Text - context.painter->setBackgroundMode(Qt::TransparentMode); - context.painter->setFont(tb->textStyle().font); - context.painter->setPen(tb->textStyle().foregroundColor); - context.painter->drawText(rc, tb->flags(), tb->text()); + context.painter()->setBackgroundMode(Qt::TransparentMode); + context.painter()->setFont(tb->textStyle().font); + context.painter()->setPen(tb->textStyle().foregroundColor); + context.painter()->drawText(rc, tb->flags(), tb->text()); //outer line - context.painter->setPen(QPen(tb->lineStyle().color(), tb->lineStyle().width() * scaleX, tb->lineStyle().penStyle())); - context.painter->drawRect(rc); + context.painter()->setPen(QPen(tb->lineStyle().color(), tb->lineStyle().width() * scaleX, tb->lineStyle().penStyle())); + context.painter()->drawRect(rc); //Reset back to defaults for next element - context.painter->restore(); + context.painter()->restore(); } else if (dynamic_cast(prim)) { //kreportDebug() << "Line"; OROLine * ln = dynamic_cast(prim); QPointF s = ln->startPoint(); QPointF e(ln->endPoint().x() * scaleX, ln->endPoint().y() * scaleY); - //QPen pen ( _painter->pen() ); + //QPen pen ( _painter()->pen() ); QPen pen(ln->lineStyle().color(), ln->lineStyle().width() * scaleX, ln->lineStyle().penStyle()); - context.painter->save(); - context.painter->setRenderHint(QPainter::Antialiasing, true); - context.painter->setPen(pen); - context.painter->drawLine(QLineF(s.x(), s.y(), e.x(), e.y())); - context.painter->setRenderHint(QPainter::Antialiasing, false); - context.painter->restore(); + context.painter()->save(); + context.painter()->setRenderHint(QPainter::Antialiasing, true); + context.painter()->setPen(pen); + context.painter()->drawLine(QLineF(s.x(), s.y(), e.x(), e.y())); + context.painter()->setRenderHint(QPainter::Antialiasing, false); + context.painter()->restore(); } else if (dynamic_cast(prim)) { //kreportDebug() << "Image"; OROImage * im = dynamic_cast(prim); @@ -157,103 +157,103 @@ img = img.scaled(rc.size().toSize(), (Qt::AspectRatioMode) im->aspectRatioMode(), (Qt::TransformationMode) im->transformationMode()); QRectF sr = QRectF(QPointF(0.0, 0.0), rc.size().boundedTo(img.size())); - context.painter->drawImage(rc.topLeft(), img, sr); + context.painter()->drawImage(rc.topLeft(), img, sr); } else if (dynamic_cast(prim)) { //kreportDebug() << "Rect"; ORORect * re = dynamic_cast(prim); QPointF ps = re->position(); QSizeF sz = re->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); - context.painter->save(); - context.painter->setPen(re->pen()); - context.painter->setBrush(re->brush()); - context.painter->drawRect(rc); - context.painter->restore(); + context.painter()->save(); + context.painter()->setPen(re->pen()); + context.painter()->setBrush(re->brush()); + context.painter()->drawRect(rc); + context.painter()->restore(); } else if (dynamic_cast(prim)) { OROEllipse * re = dynamic_cast(prim); QPointF ps = re->position(); QSizeF sz = re->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); - context.painter->save(); - context.painter->setPen(re->pen()); - context.painter->setBrush(re->brush()); - context.painter->drawEllipse(rc); - context.painter->restore(); + context.painter()->save(); + context.painter()->setPen(re->pen()); + context.painter()->setBrush(re->brush()); + context.painter()->drawEllipse(rc); + context.painter()->restore(); } else if (dynamic_cast(prim)) { OROPicture * im = dynamic_cast(prim); QPointF ps = im->position(); QSizeF sz = im->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); - context.painter->drawPicture(rc.topLeft(), *(im->picture())); + context.painter()->drawPicture(rc.topLeft(), *(im->picture())); } else if (dynamic_cast(prim)) { OROCheckBox * chk = dynamic_cast(prim); QPointF ps = chk->position(); QSizeF sz = chk->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); - context.painter->save(); + context.painter()->save(); - context.painter->setBackgroundMode(Qt::OpaqueMode); - context.painter->setRenderHint(QPainter::Antialiasing); + context.painter()->setBackgroundMode(Qt::OpaqueMode); + context.painter()->setRenderHint(QPainter::Antialiasing); - context.painter->setPen(chk->foregroundColor()); + context.painter()->setPen(chk->foregroundColor()); if (chk->lineStyle().penStyle() == Qt::NoPen || chk->lineStyle().width() <= 0) { - context.painter->setPen(QPen(Qt::lightGray)); + context.painter()->setPen(QPen(Qt::lightGray)); } else { - context.painter->setPen(QPen(chk->lineStyle().color(), chk->lineStyle().width() * scaleX, chk->lineStyle().penStyle())); + context.painter()->setPen(QPen(chk->lineStyle().color(), chk->lineStyle().width() * scaleX, chk->lineStyle().penStyle())); } qreal ox = sz.width() / 5; qreal oy = sz.height() / 5; //Checkbox Style if (chk->checkType() == OROCheckBox::Cross) { - context.painter->drawRoundedRect(rc, sz.width() / 10 , sz.height() / 10); + context.painter()->drawRoundedRect(rc, sz.width() / 10 , sz.height() / 10); if (chk->value()) { QPen lp; lp.setColor(chk->foregroundColor()); lp.setWidth(ox > oy ? oy : ox); - context.painter->setPen(lp); - context.painter->drawLine(QPointF(ox, oy) + ps, QPointF(sz.width() - ox, sz.height() - oy) + ps); - context.painter->drawLine(QPointF(ox, sz.height() - oy) + ps, QPoint(sz.width() - ox, oy) + ps); + context.painter()->setPen(lp); + context.painter()->drawLine(QPointF(ox, oy) + ps, QPointF(sz.width() - ox, sz.height() - oy) + ps); + context.painter()->drawLine(QPointF(ox, sz.height() - oy) + ps, QPoint(sz.width() - ox, oy) + ps); } } else if (chk->checkType() == OROCheckBox::Dot) { //Radio Style - context.painter->drawEllipse(rc); + context.painter()->drawEllipse(rc); if (chk->value()) { QBrush lb(chk->foregroundColor()); - context.painter->setBrush(lb); - context.painter->setPen(Qt::NoPen); - context.painter->drawEllipse(rc.center(), sz.width() / 2 - ox, sz.height() / 2 - oy); + context.painter()->setBrush(lb); + context.painter()->setPen(Qt::NoPen); + context.painter()->drawEllipse(rc.center(), sz.width() / 2 - ox, sz.height() / 2 - oy); } } else { //Tickbox Style - context.painter->drawRoundedRect(rc, sz.width() / 10 , sz.height() / 10); + context.painter()->drawRoundedRect(rc, sz.width() / 10 , sz.height() / 10); if (chk->value()) { QPen lp; lp.setColor(chk->foregroundColor()); lp.setWidth(ox > oy ? oy : ox); - context.painter->setPen(lp); - context.painter->drawLine(QPointF(ox, sz.height() / 2) + ps, QPointF(sz.width() / 2, sz.height() - oy) + ps); - context.painter->drawLine(QPointF(sz.width() / 2, sz.height() - oy) + ps, QPointF(sz.width() - ox, oy) + ps); + context.painter()->setPen(lp); + context.painter()->drawLine(QPointF(ox, sz.height() / 2) + ps, QPointF(sz.width() / 2, sz.height() - oy) + ps); + context.painter()->drawLine(QPointF(sz.width() / 2, sz.height() - oy) + ps, QPointF(sz.width() - ox, oy) + ps); } } - context.painter->restore(); + context.painter()->restore(); } } } } if (endWhenComplete) - context.painter->end(); + context.painter()->end(); return true; } diff --git a/src/renderer/KReportRendererBase.h b/src/renderer/KReportRendererBase.h --- a/src/renderer/KReportRendererBase.h +++ b/src/renderer/KReportRendererBase.h @@ -33,9 +33,23 @@ { public: KReportRendererContext(); - QUrl destinationUrl; - QPainter *painter; - QPrinter *printer; + ~KReportRendererContext(); + + void setUrl(const QUrl& url); + void setPainter(QPainter* painter); + void setPrinter(QPrinter* printer); + + QPrinter *printer(); + QPainter *painter(); + QPrinter *printer() const; + QPainter *painter() const; + + QUrl url() const; + + private: + Q_DISABLE_COPY(KReportRendererContext) + class Private; + Private * const d; }; //! Base class for report renderers. @@ -57,8 +71,14 @@ { public: KReportRendererFactory(); - + ~KReportRendererFactory(); + KReportRendererBase* createInstance(const QString& key); + + private: + Q_DISABLE_COPY(KReportRendererFactory) + class Private; + Private * const d; }; #endif // KREPORTRENDERERBASE_H diff --git a/src/renderer/KReportRendererBase.cpp b/src/renderer/KReportRendererBase.cpp --- a/src/renderer/KReportRendererBase.cpp +++ b/src/renderer/KReportRendererBase.cpp @@ -26,21 +26,98 @@ //! @todo port #include "KReportODTRenderer.h" //! @todo port #include "KOdtFrameReportRenderer.h" +class Q_DECL_HIDDEN KReportRendererContext::Private +{ +public: + Private(); + ~Private(); + QUrl destinationUrl; + QPainter *painter = nullptr; + QPrinter *printer = nullptr; +}; + +KReportRendererContext::Private::Private() +{ +} + +KReportRendererContext::Private::~Private() +{ +} + + KReportRendererContext::KReportRendererContext() - : painter(0), printer(0) + : d(new Private()) +{ +} + +KReportRendererContext::~KReportRendererContext() +{ + delete d; +} + +QPainter * KReportRendererContext::painter() const +{ + return d->painter; +} + +QPrinter * KReportRendererContext::printer() const +{ + return d->printer; +} + + +QPainter * KReportRendererContext::painter() { + return d->painter; } +QPrinter * KReportRendererContext::printer() +{ + return d->printer; +} + +void KReportRendererContext::setUrl(const QUrl& url) +{ + d->destinationUrl = url; +} + +void KReportRendererContext::setPainter(QPainter* painter) +{ + d->painter = painter; +} + +void KReportRendererContext::setPrinter(QPrinter* printer) +{ + d->printer = printer; +} + +QUrl KReportRendererContext::url() const +{ + return d->destinationUrl; +} + + KReportRendererBase::KReportRendererBase() { } KReportRendererBase::~KReportRendererBase() { } -KReportRendererFactory::KReportRendererFactory() +class KReportRendererFactory::Private +{ +public: + bool dummy = true; +}; + +KReportRendererFactory::KReportRendererFactory() : d(new Private()) +{ +} + +KReportRendererFactory::~KReportRendererFactory() { + delete d; } KReportRendererBase* KReportRendererFactory::createInstance(const QString& key) diff --git a/src/renderer/KReportScreenRenderer_p.cpp b/src/renderer/KReportScreenRenderer_p.cpp --- a/src/renderer/KReportScreenRenderer_p.cpp +++ b/src/renderer/KReportScreenRenderer_p.cpp @@ -32,17 +32,12 @@ { } -//void KRScreenRender::setPainter(QPainter * pPainter) -//{ -// context.painter = pPainter; -//} - bool ScreenRenderer::render(const KReportRendererContext& context, ORODocument *document, int page) { if (!document) return false; - if (!context.painter) + if (!context.painter()) return false; OROPage *p = document->page(page); @@ -62,67 +57,67 @@ QSizeF sz = tb->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); - context.painter->save(); + context.painter()->save(); //Background - context.painter->setBackgroundMode(Qt::TransparentMode); + context.painter()->setBackgroundMode(Qt::TransparentMode); QColor bg = tb->textStyle().backgroundColor; bg.setAlphaF(0.01 * tb->textStyle().backgroundOpacity); - context.painter->fillRect(rc, bg); + context.painter()->fillRect(rc, bg); //Text - context.painter->setFont(tb->textStyle().font); - context.painter->setPen(tb->textStyle().foregroundColor); - context.painter->drawText(rc.adjusted(2, 2, 0, 0), tb->flags(), tb->text()); + context.painter()->setFont(tb->textStyle().font); + context.painter()->setPen(tb->textStyle().foregroundColor); + context.painter()->drawText(rc.adjusted(2, 2, 0, 0), tb->flags(), tb->text()); //outer line - context.painter->setPen(QPen(tb->lineStyle().color(), tb->lineStyle().width(), tb->lineStyle().penStyle())); - context.painter->drawRect(rc); + context.painter()->setPen(QPen(tb->lineStyle().color(), tb->lineStyle().width(), tb->lineStyle().penStyle())); + context.painter()->drawRect(rc); //Reset back to defaults for next element - context.painter->restore(); + context.painter()->restore(); } else if (dynamic_cast(prim)) { OROLine * ln = dynamic_cast(prim); QPointF s = ln->startPoint(); QPointF e = ln->endPoint(); //QPen pen ( _painter->pen() ); QPen pen(ln->lineStyle().color(), ln->lineStyle().width(), ln->lineStyle().penStyle()); - context.painter->save(); - context.painter->setRenderHint(QPainter::Antialiasing, true); - context.painter->setPen(pen); - context.painter->drawLine(QLineF(s.x(), s.y(), e.x(), e.y())); - context.painter->setRenderHint(QPainter::Antialiasing, false); - context.painter->restore(); + context.painter()->save(); + context.painter()->setRenderHint(QPainter::Antialiasing, true); + context.painter()->setPen(pen); + context.painter()->drawLine(QLineF(s.x(), s.y(), e.x(), e.y())); + context.painter()->setRenderHint(QPainter::Antialiasing, false); + context.painter()->restore(); } else if (dynamic_cast(prim)) { ORORect * re = dynamic_cast(prim); QPointF ps = re->position(); QSizeF sz = re->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); - context.painter->save(); - context.painter->setPen(re->pen()); - context.painter->setBrush(re->brush()); - context.painter->drawRect(rc); - context.painter->restore(); + context.painter()->save(); + context.painter()->setPen(re->pen()); + context.painter()->setBrush(re->brush()); + context.painter()->drawRect(rc); + context.painter()->restore(); } else if (dynamic_cast(prim)) { OROEllipse * re = dynamic_cast(prim); QPointF ps = re->position(); QSizeF sz = re->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); - context.painter->save(); - context.painter->setPen(re->pen()); - context.painter->setBrush(re->brush()); - context.painter->drawEllipse(rc); - context.painter->restore(); + context.painter()->save(); + context.painter()->setPen(re->pen()); + context.painter()->setBrush(re->brush()); + context.painter()->drawEllipse(rc); + context.painter()->restore(); } else if (dynamic_cast(prim)) { OROImage * im = dynamic_cast(prim); @@ -136,82 +131,82 @@ (Qt::TransformationMode) im->transformationMode()); QRectF sr = QRectF(QPointF(0.0, 0.0), rc.size().boundedTo(img.size())); - context.painter->drawImage(rc.topLeft(), img, sr); + context.painter()->drawImage(rc.topLeft(), img, sr); } else if (dynamic_cast(prim)) { OROPicture * im = dynamic_cast(prim); QPointF ps = im->position(); QSizeF sz = im->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); - context.painter->save(); - context.painter->drawPicture(rc.topLeft(), *(im->picture())); - context.painter->restore(); + context.painter()->save(); + context.painter()->drawPicture(rc.topLeft(), *(im->picture())); + context.painter()->restore(); } else if (dynamic_cast(prim)) { OROCheckBox * chk = dynamic_cast(prim); QPointF ps = chk->position(); QSizeF sz = chk->size(); QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); - context.painter->save(); + context.painter()->save(); - context.painter->setBackgroundMode(Qt::OpaqueMode); - context.painter->setRenderHint(QPainter::Antialiasing); + context.painter()->setBackgroundMode(Qt::OpaqueMode); + context.painter()->setRenderHint(QPainter::Antialiasing); - context.painter->setPen(chk->foregroundColor()); + context.painter()->setPen(chk->foregroundColor()); if (chk->lineStyle().penStyle() == Qt::NoPen || chk->lineStyle().width() <= 0) { - context.painter->setPen(QPen(Qt::lightGray)); + context.painter()->setPen(QPen(Qt::lightGray)); } else { - context.painter->setPen(QPen(chk->lineStyle().color(), chk->lineStyle().width(), chk->lineStyle().penStyle())); + context.painter()->setPen(QPen(chk->lineStyle().color(), chk->lineStyle().width(), chk->lineStyle().penStyle())); } qreal ox = sz.width() / 5; qreal oy = sz.height() / 5; //Checkbox Style if (chk->checkType() == OROCheckBox::Cross) { - context.painter->drawRoundedRect(rc, sz.width() / 10 , sz.height() / 10); + context.painter()->drawRoundedRect(rc, sz.width() / 10 , sz.height() / 10); if (chk->value()) { QPen lp; lp.setColor(chk->foregroundColor()); lp.setWidth(ox > oy ? oy : ox); - context.painter->setPen(lp); - context.painter->drawLine(QPointF(ox, oy) + ps, QPointF(sz.width() - ox, sz.height() - oy) + ps); - context.painter->drawLine(QPointF(ox, sz.height() - oy) + ps, QPoint(sz.width() - ox, oy) + ps); + context.painter()->setPen(lp); + context.painter()->drawLine(QPointF(ox, oy) + ps, QPointF(sz.width() - ox, sz.height() - oy) + ps); + context.painter()->drawLine(QPointF(ox, sz.height() - oy) + ps, QPoint(sz.width() - ox, oy) + ps); } } else if (chk->checkType() == OROCheckBox::Dot) { //Radio Style - context.painter->drawEllipse(rc); + context.painter()->drawEllipse(rc); if (chk->value()) { QBrush lb(chk->foregroundColor()); - context.painter->setBrush(lb); - context.painter->setPen(Qt::NoPen); - context.painter->drawEllipse(rc.center(), sz.width() / 2 - ox, sz.height() / 2 - oy); + context.painter()->setBrush(lb); + context.painter()->setPen(Qt::NoPen); + context.painter()->drawEllipse(rc.center(), sz.width() / 2 - ox, sz.height() / 2 - oy); } } else { //Tickbox Style - context.painter->drawRoundedRect(rc, sz.width() / 10 , sz.height() / 10); + context.painter()->drawRoundedRect(rc, sz.width() / 10 , sz.height() / 10); if (chk->value()) { QPen lp; lp.setColor(chk->foregroundColor()); lp.setWidth(ox > oy ? oy : ox); - context.painter->setPen(lp); - context.painter->drawLine( + context.painter()->setPen(lp); + context.painter()->drawLine( QPointF(ox, sz.height() / 2) + ps, QPointF(sz.width() / 2, sz.height() - oy) + ps); - context.painter->drawLine( + context.painter()->drawLine( QPointF(sz.width() / 2, sz.height() - oy) + ps, QPointF(sz.width() - ox, oy) + ps); } } - context.painter->restore(); + context.painter()->restore(); } else { kreportWarning() << "unrecognized primitive type";