This commit is contained in:
Arin Alexander 2017-04-21 23:04:24 +03:00
commit c7a5b638e8
5 changed files with 17 additions and 25 deletions

View File

@ -73,7 +73,7 @@ public:
explicit ReportEngine(QObject *parent = 0); explicit ReportEngine(QObject *parent = 0);
~ReportEngine(); ~ReportEngine();
bool printReport(QPrinter *printer=0); 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); void printToFile(const QString& fileName);
PageDesignIntf *createPreviewScene(QObject *parent = 0); PageDesignIntf *createPreviewScene(QObject *parent = 0);
bool printToPDF(const QString& fileName); bool printToPDF(const QString& fileName);

View File

@ -163,8 +163,7 @@ void PreviewReportWidget::print()
if (!d_ptr->m_reportPages.isEmpty()) if (!d_ptr->m_reportPages.isEmpty())
ReportEnginePrivate::printReport( ReportEnginePrivate::printReport(
d_ptr->m_reportPages, d_ptr->m_reportPages,
printer, printer
PrintRange(dialog.printRange(),dialog.fromPage(),dialog.toPage())
); );
foreach(PageItemDesignIntf::Ptr pageItem, d_ptr->m_reportPages){ foreach(PageItemDesignIntf::Ptr pageItem, d_ptr->m_reportPages){
d_ptr->m_previewPage->reactivatePageItem(pageItem); d_ptr->m_previewPage->reactivatePageItem(pageItem);
@ -184,7 +183,7 @@ void PreviewReportWidget::printToPDF()
printer.setOutputFileName(fileName); printer.setOutputFileName(fileName);
printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFormat(QPrinter::PdfFormat);
if (!d_ptr->m_reportPages.isEmpty()){ 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){ foreach(PageItemDesignIntf::Ptr pageItem, d_ptr->m_reportPages){
d_ptr->m_previewPage->reactivatePageItem(pageItem); d_ptr->m_previewPage->reactivatePageItem(pageItem);

View File

@ -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; LimeReport::PageDesignIntf renderPage;
renderPage.setItemMode(PrintMode); renderPage.setItemMode(PrintMode);
@ -216,13 +216,13 @@ void ReportEnginePrivate::printReport(ReportPages pages, QPrinter &printer, cons
bool isFirst = true; bool isFirst = true;
int currenPage = 1; int currenPage = 1;
foreach(PageItemDesignIntf::Ptr page,pages){ foreach(PageItemDesignIntf::Ptr page, pages){
if ( if (
(printRange.rangeType()==QPrintDialog::AllPages) || (printer.printRange() == QPrinter::AllPages) ||
( (printRange.rangeType()==QPrintDialog::PageRange) && ( (printer.printRange()==QPrinter::PageRange) &&
(currenPage>=printRange.fromPage()) && (currenPage>=printer.fromPage()) &&
(currenPage<=printRange.toPage()) (currenPage<=printer.toPage())
) )
) )
{ {
@ -286,7 +286,7 @@ bool ReportEnginePrivate::printReport(QPrinter* printer)
ReportPages pages = renderToPages(); ReportPages pages = renderToPages();
dataManager()->setDesignTime(true); dataManager()->setDesignTime(true);
if (pages.count()>0){ if (pages.count()>0){
printReport(pages,*printer,PrintRange()); printReport(pages,*printer);
} }
} catch(ReportError &exception){ } catch(ReportError &exception){
saveError(exception.what()); saveError(exception.what());
@ -295,18 +295,12 @@ bool ReportEnginePrivate::printReport(QPrinter* printer)
} else return false; } else return false;
} }
bool ReportEnginePrivate::printPages(ReportPages pages, QPrinter *printer, PrintRange printRange) bool ReportEnginePrivate::printPages(ReportPages pages, QPrinter *printer)
{ {
if (!printer&&!m_printerSelected){ if (!printer&&!m_printerSelected){
QPrintDialog dialog(m_printer.data(),QApplication::activeWindow()); QPrintDialog dialog(m_printer.data(),QApplication::activeWindow());
m_printerSelected = dialog.exec()!=QDialog::Rejected; 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; if (!printer&&!m_printerSelected) return false;
@ -316,8 +310,7 @@ bool ReportEnginePrivate::printPages(ReportPages pages, QPrinter *printer, Print
if (pages.count()>0){ if (pages.count()>0){
printReport( printReport(
pages, pages,
*printer, *printer
printRange
); );
} }
} catch(ReportError &exception){ } catch(ReportError &exception){
@ -828,9 +821,9 @@ bool ReportEngine::printReport(QPrinter *printer)
return d->printReport(printer); return d->printReport(printer);
} }
bool ReportEngine::printPages(ReportPages pages, QPrinter *printer, PrintRange printRange){ bool ReportEngine::printPages(ReportPages pages, QPrinter *printer){
Q_D(ReportEngine); Q_D(ReportEngine);
return d->printPages(pages,printer, printRange); return d->printPages(pages,printer);
} }
void ReportEngine::printToFile(const QString &fileName) void ReportEngine::printToFile(const QString &fileName)

View File

@ -73,7 +73,7 @@ public:
explicit ReportEngine(QObject *parent = 0); explicit ReportEngine(QObject *parent = 0);
~ReportEngine(); ~ReportEngine();
bool printReport(QPrinter *printer=0); 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); void printToFile(const QString& fileName);
PageDesignIntf *createPreviewScene(QObject *parent = 0); PageDesignIntf *createPreviewScene(QObject *parent = 0);
bool printToPDF(const QString& fileName); bool printToPDF(const QString& fileName);

View File

@ -63,7 +63,7 @@ class ReportEnginePrivate : public QObject, public ICollectionContainer
friend class PreviewReportWidget; friend class PreviewReportWidget;
public: public:
static void printReport(ItemsReaderIntf::Ptr reader, QPrinter &printer); 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: public:
explicit ReportEnginePrivate(QObject *parent = 0); explicit ReportEnginePrivate(QObject *parent = 0);
virtual ~ReportEnginePrivate(); virtual ~ReportEnginePrivate();
@ -85,7 +85,7 @@ public:
void clearReport(); void clearReport();
bool printReport(QPrinter *printer=0); 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); void printToFile(const QString& fileName);
bool printToPDF(const QString& fileName); bool printToPDF(const QString& fileName);
void previewReport(PreviewHints hints = PreviewBarsUserSetting); void previewReport(PreviewHints hints = PreviewBarsUserSetting);