From e3df7c88d16632f43b031965f66445c41bfa91db Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Fri, 21 Apr 2017 23:03:56 +0300 Subject: [PATCH] Print range from QPrinter fix --- include/lrreportengine.h | 2 +- limereport/lrpreviewreportwidget.cpp | 5 ++--- limereport/lrreportengine.cpp | 29 +++++++++++----------------- limereport/lrreportengine.h | 2 +- limereport/lrreportengine_p.h | 4 ++-- 5 files changed, 17 insertions(+), 25 deletions(-) diff --git a/include/lrreportengine.h b/include/lrreportengine.h index 99728e1..564dabd 100644 --- a/include/lrreportengine.h +++ b/include/lrreportengine.h @@ -73,7 +73,7 @@ public: explicit ReportEngine(QObject *parent = 0); ~ReportEngine(); bool printReport(QPrinter *printer=0); - bool printPages(ReportPages pages, QPrinter *printer, PrintRange printRange = PrintRange()); + bool printPages(ReportPages pages, QPrinter *printer); void printToFile(const QString& fileName); PageDesignIntf *createPreviewScene(QObject *parent = 0); bool printToPDF(const QString& fileName); diff --git a/limereport/lrpreviewreportwidget.cpp b/limereport/lrpreviewreportwidget.cpp index 986e95d..4e36335 100644 --- a/limereport/lrpreviewreportwidget.cpp +++ b/limereport/lrpreviewreportwidget.cpp @@ -163,8 +163,7 @@ void PreviewReportWidget::print() if (!d_ptr->m_reportPages.isEmpty()) ReportEnginePrivate::printReport( d_ptr->m_reportPages, - printer, - PrintRange(dialog.printRange(),dialog.fromPage(),dialog.toPage()) + printer ); foreach(PageItemDesignIntf::Ptr pageItem, d_ptr->m_reportPages){ d_ptr->m_previewPage->reactivatePageItem(pageItem); @@ -184,7 +183,7 @@ void PreviewReportWidget::printToPDF() printer.setOutputFileName(fileName); printer.setOutputFormat(QPrinter::PdfFormat); if (!d_ptr->m_reportPages.isEmpty()){ - ReportEnginePrivate::printReport(d_ptr->m_reportPages,printer,PrintRange()); + ReportEnginePrivate::printReport(d_ptr->m_reportPages,printer); } foreach(PageItemDesignIntf::Ptr pageItem, d_ptr->m_reportPages){ d_ptr->m_previewPage->reactivatePageItem(pageItem); diff --git a/limereport/lrreportengine.cpp b/limereport/lrreportengine.cpp index dbd1882..4d3aa3d 100644 --- a/limereport/lrreportengine.cpp +++ b/limereport/lrreportengine.cpp @@ -208,7 +208,7 @@ void ReportEnginePrivate::printReport(ItemsReaderIntf::Ptr reader, QPrinter& pri } } -void ReportEnginePrivate::printReport(ReportPages pages, QPrinter &printer, const PrintRange& printRange) +void ReportEnginePrivate::printReport(ReportPages pages, QPrinter &printer) { LimeReport::PageDesignIntf renderPage; renderPage.setItemMode(PrintMode); @@ -216,13 +216,13 @@ void ReportEnginePrivate::printReport(ReportPages pages, QPrinter &printer, cons bool isFirst = true; int currenPage = 1; - foreach(PageItemDesignIntf::Ptr page,pages){ + foreach(PageItemDesignIntf::Ptr page, pages){ if ( - (printRange.rangeType()==QPrintDialog::AllPages) || - ( (printRange.rangeType()==QPrintDialog::PageRange) && - (currenPage>=printRange.fromPage()) && - (currenPage<=printRange.toPage()) + (printer.printRange() == QPrinter::AllPages) || + ( (printer.printRange()==QPrinter::PageRange) && + (currenPage>=printer.fromPage()) && + (currenPage<=printer.toPage()) ) ) { @@ -286,7 +286,7 @@ bool ReportEnginePrivate::printReport(QPrinter* printer) ReportPages pages = renderToPages(); dataManager()->setDesignTime(true); if (pages.count()>0){ - printReport(pages,*printer,PrintRange()); + printReport(pages,*printer); } } catch(ReportError &exception){ saveError(exception.what()); @@ -295,18 +295,12 @@ bool ReportEnginePrivate::printReport(QPrinter* printer) } else return false; } -bool ReportEnginePrivate::printPages(ReportPages pages, QPrinter *printer, PrintRange printRange) +bool ReportEnginePrivate::printPages(ReportPages pages, QPrinter *printer) { if (!printer&&!m_printerSelected){ QPrintDialog dialog(m_printer.data(),QApplication::activeWindow()); m_printerSelected = dialog.exec()!=QDialog::Rejected; - if (m_printerSelected){ - printRange.setRangeType(dialog.printRange()); - printRange.setFromPage(dialog.fromPage()); - printRange.setToPage(dialog.toPage()); - } - } if (!printer&&!m_printerSelected) return false; @@ -316,8 +310,7 @@ bool ReportEnginePrivate::printPages(ReportPages pages, QPrinter *printer, Print if (pages.count()>0){ printReport( pages, - *printer, - printRange + *printer ); } } catch(ReportError &exception){ @@ -828,9 +821,9 @@ bool ReportEngine::printReport(QPrinter *printer) return d->printReport(printer); } -bool ReportEngine::printPages(ReportPages pages, QPrinter *printer, PrintRange printRange){ +bool ReportEngine::printPages(ReportPages pages, QPrinter *printer){ Q_D(ReportEngine); - return d->printPages(pages,printer, printRange); + return d->printPages(pages,printer); } void ReportEngine::printToFile(const QString &fileName) diff --git a/limereport/lrreportengine.h b/limereport/lrreportengine.h index 99728e1..564dabd 100644 --- a/limereport/lrreportengine.h +++ b/limereport/lrreportengine.h @@ -73,7 +73,7 @@ public: explicit ReportEngine(QObject *parent = 0); ~ReportEngine(); bool printReport(QPrinter *printer=0); - bool printPages(ReportPages pages, QPrinter *printer, PrintRange printRange = PrintRange()); + bool printPages(ReportPages pages, QPrinter *printer); void printToFile(const QString& fileName); PageDesignIntf *createPreviewScene(QObject *parent = 0); bool printToPDF(const QString& fileName); diff --git a/limereport/lrreportengine_p.h b/limereport/lrreportengine_p.h index f900217..ade298e 100644 --- a/limereport/lrreportengine_p.h +++ b/limereport/lrreportengine_p.h @@ -63,7 +63,7 @@ class ReportEnginePrivate : public QObject, public ICollectionContainer friend class PreviewReportWidget; public: static void printReport(ItemsReaderIntf::Ptr reader, QPrinter &printer); - static void printReport(ReportPages pages, QPrinter &printer, const PrintRange &printRange); + static void printReport(ReportPages pages, QPrinter &printer); public: explicit ReportEnginePrivate(QObject *parent = 0); virtual ~ReportEnginePrivate(); @@ -85,7 +85,7 @@ public: void clearReport(); bool printReport(QPrinter *printer=0); - bool printPages(ReportPages pages, QPrinter *printer, PrintRange printRange = PrintRange()); + bool printPages(ReportPages pages, QPrinter *printer); void printToFile(const QString& fileName); bool printToPDF(const QString& fileName); void previewReport(PreviewHints hints = PreviewBarsUserSetting);