diff --git a/include/lrpreviewreportwidget.h b/include/lrpreviewreportwidget.h index 306af9c..9c50adb 100644 --- a/include/lrpreviewreportwidget.h +++ b/include/lrpreviewreportwidget.h @@ -3,6 +3,7 @@ #include #include +#include #include "lrglobal.h" namespace LimeReport { @@ -31,6 +32,8 @@ public: void setScaleType(const ScaleType &scaleType, int percent = 0); void setPreviewPageBackgroundColor(QColor color); QColor previewPageBackgroundColor(); + QPrinter *defaultPrinter() const; + void setDefaultPrinter(QPrinter *defaultPrinter); public slots: void refreshPages(); void zoomIn(); @@ -71,6 +74,8 @@ private: int m_scalePercent; QTimer m_resizeTimer; QColor m_previewPageBackgroundColor; + QPrinter* m_defaultPrinter; + void printPages(QPrinter *printer); }; } // namespace LimeReport diff --git a/include/lrreportengine.h b/include/lrreportengine.h index a36d1b0..00185d8 100644 --- a/include/lrreportengine.h +++ b/include/lrreportengine.h @@ -87,6 +87,7 @@ public: bool printToPDF(const QString& fileName); bool exportReport(QString exporterName, const QString &fileName = "", const QMap& params = QMap()); void previewReport(PreviewHints hints = PreviewBarsUserSetting); + void previewReport(QPrinter* printer, PreviewHints hints = PreviewBarsUserSetting); void designReport(); ReportDesignWindowInterface* getDesignerWindow(); void setShowProgressDialog(bool value); diff --git a/limereport/lrpreviewreportwidget.cpp b/limereport/lrpreviewreportwidget.cpp index 6799a62..7b3290d 100644 --- a/limereport/lrpreviewreportwidget.cpp +++ b/limereport/lrpreviewreportwidget.cpp @@ -71,7 +71,8 @@ QList PreviewReportWidgetPrivate::aviableExporters() PreviewReportWidget::PreviewReportWidget(ReportEngine *report, QWidget *parent) : QWidget(parent), ui(new Ui::PreviewReportWidget), d_ptr(new PreviewReportWidgetPrivate(this)), - m_scaleType(FitWidth), m_scalePercent(0), m_previewPageBackgroundColor(Qt::white) + m_scaleType(FitWidth), m_scalePercent(0), m_previewPageBackgroundColor(Qt::white), + m_defaultPrinter(0) { ui->setupUi(this); d_ptr->m_report = report->d_ptr; @@ -193,32 +194,41 @@ void PreviewReportWidget::lastPage() d_ptr->m_changingPage=false; } -void PreviewReportWidget::print() +void PreviewReportWidget::printPages(QPrinter* printer) { + if (!d_ptr->m_reportPages.isEmpty()) + ReportEnginePrivate::printReport( + d_ptr->m_reportPages, + *printer + ); + foreach(PageItemDesignIntf::Ptr pageItem, d_ptr->m_reportPages){ + d_ptr->m_previewPage->reactivatePageItem(pageItem); + } +} - QPrinterInfo pi; - QPrinter printer(QPrinter::HighResolution); +void PreviewReportWidget::print() +{ + if (m_defaultPrinter){ + printPages(m_defaultPrinter); + } else { - if (!pi.defaultPrinter().isNull()) + QPrinterInfo pi; + QPrinter printer(QPrinter::HighResolution); + + if (!pi.defaultPrinter().isNull()) #ifdef HAVE_QT4 - printer.setPrinterName(pi.defaultPrinter().printerName()); + printer.setPrinterName(pi.defaultPrinter().printerName()); #endif #ifdef HAVE_QT5 #if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)) - printer.setPrinterName(pi.defaultPrinterName()); + printer.setPrinterName(pi.defaultPrinterName()); #else - printer.setPrinterName(pi.defaultPrinter().printerName()); + printer.setPrinterName(pi.defaultPrinter().printerName()); #endif #endif - QPrintDialog dialog(&printer,QApplication::activeWindow()); - if (dialog.exec()==QDialog::Accepted){ - if (!d_ptr->m_reportPages.isEmpty()) - ReportEnginePrivate::printReport( - d_ptr->m_reportPages, - printer - ); - foreach(PageItemDesignIntf::Ptr pageItem, d_ptr->m_reportPages){ - d_ptr->m_previewPage->reactivatePageItem(pageItem); + QPrintDialog dialog(&printer,QApplication::activeWindow()); + if (dialog.exec()==QDialog::Accepted){ + printPages(&printer); } } } @@ -307,6 +317,16 @@ void PreviewReportWidget::emitPageSet() emit pagesSet(d_ptr->m_reportPages.count()); } +QPrinter *PreviewReportWidget::defaultPrinter() const +{ + return m_defaultPrinter; +} + +void PreviewReportWidget::setDefaultPrinter(QPrinter *defaultPrinter) +{ + m_defaultPrinter = defaultPrinter; +} + ScaleType PreviewReportWidget::scaleType() const { return m_scaleType; diff --git a/limereport/lrpreviewreportwidget.h b/limereport/lrpreviewreportwidget.h index 306af9c..9c50adb 100644 --- a/limereport/lrpreviewreportwidget.h +++ b/limereport/lrpreviewreportwidget.h @@ -3,6 +3,7 @@ #include #include +#include #include "lrglobal.h" namespace LimeReport { @@ -31,6 +32,8 @@ public: void setScaleType(const ScaleType &scaleType, int percent = 0); void setPreviewPageBackgroundColor(QColor color); QColor previewPageBackgroundColor(); + QPrinter *defaultPrinter() const; + void setDefaultPrinter(QPrinter *defaultPrinter); public slots: void refreshPages(); void zoomIn(); @@ -71,6 +74,8 @@ private: int m_scalePercent; QTimer m_resizeTimer; QColor m_previewPageBackgroundColor; + QPrinter* m_defaultPrinter; + void printPages(QPrinter *printer); }; } // namespace LimeReport diff --git a/limereport/lrpreviewreportwindow.cpp b/limereport/lrpreviewreportwindow.cpp index 71fed64..035a5e0 100644 --- a/limereport/lrpreviewreportwindow.cpp +++ b/limereport/lrpreviewreportwindow.cpp @@ -209,6 +209,11 @@ void PreviewReportWindow::setPages(ReportPages pages) } } +void PreviewReportWindow::setDefaultPrinter(QPrinter *printer) +{ + m_previewReportWidget->setDefaultPrinter(printer); +} + void PreviewReportWindow::exec() { bool deleteOnClose = testAttribute(Qt::WA_DeleteOnClose); diff --git a/limereport/lrpreviewreportwindow.h b/limereport/lrpreviewreportwindow.h index dc210ce..eb5b2e6 100644 --- a/limereport/lrpreviewreportwindow.h +++ b/limereport/lrpreviewreportwindow.h @@ -36,6 +36,7 @@ #include #include #include +#include #include "serializators/lrxmlreader.h" @@ -61,6 +62,7 @@ public: ~PreviewReportWindow(); void setReportReader(ItemsReaderIntf::Ptr reader); void setPages(ReportPages pages); + void setDefaultPrinter(QPrinter* printer); void exec(); void initPreview(int pagesCount); void reloadPreview(); diff --git a/limereport/lrreportengine.cpp b/limereport/lrreportengine.cpp index da6a32e..e83aadf 100644 --- a/limereport/lrreportengine.cpp +++ b/limereport/lrreportengine.cpp @@ -496,48 +496,54 @@ bool ReportEnginePrivate::exportReport(QString exporterName, const QString &file void ReportEnginePrivate::previewReport(PreviewHints hints) { -// QTime start = QTime::currentTime(); - try{ - dataManager()->setDesignTime(false); - ReportPages pages = renderToPages(); - dataManager()->setDesignTime(true); - if (pages.count()>0){ - Q_Q(ReportEngine); - PreviewReportWindow* w = new PreviewReportWindow(q,0,settings()); - w->setPreviewPageBackgroundColor(m_previewPageBackgroundColor); - w->setWindowFlags(Qt::Dialog|Qt::WindowMaximizeButtonHint|Qt::WindowCloseButtonHint| Qt::WindowMinMaxButtonsHint); - w->setAttribute(Qt::WA_DeleteOnClose,true); - w->setWindowModality(Qt::ApplicationModal); - //w->setWindowIcon(QIcon(":/report/images/main.ico")); - w->setWindowIcon(m_previewWindowIcon); - w->setWindowTitle(m_previewWindowTitle); - w->setSettings(settings()); - w->setPages(pages); - w->setLayoutDirection(m_previewLayoutDirection); + previewReport(0, hints); +} - if (!dataManager()->errorsList().isEmpty()){ - w->setErrorMessages(dataManager()->errorsList()); +void ReportEnginePrivate::previewReport(QPrinter *printer, PreviewHints hints) +{ + // QTime start = QTime::currentTime(); + try{ + dataManager()->setDesignTime(false); + ReportPages pages = renderToPages(); + dataManager()->setDesignTime(true); + if (pages.count()>0){ + Q_Q(ReportEngine); + PreviewReportWindow* w = new PreviewReportWindow(q,0,settings()); + w->setPreviewPageBackgroundColor(m_previewPageBackgroundColor); + w->setWindowFlags(Qt::Dialog|Qt::WindowMaximizeButtonHint|Qt::WindowCloseButtonHint| Qt::WindowMinMaxButtonsHint); + w->setAttribute(Qt::WA_DeleteOnClose,true); + w->setWindowModality(Qt::ApplicationModal); + w->setDefaultPrinter(printer); + //w->setWindowIcon(QIcon(":/report/images/main.ico")); + w->setWindowIcon(m_previewWindowIcon); + w->setWindowTitle(m_previewWindowTitle); + w->setSettings(settings()); + w->setPages(pages); + w->setLayoutDirection(m_previewLayoutDirection); + + if (!dataManager()->errorsList().isEmpty()){ + w->setErrorMessages(dataManager()->errorsList()); + } + + if (!hints.testFlag(PreviewBarsUserSetting)){ + w->setMenuVisible(!hints.testFlag(HidePreviewMenuBar)); + w->setStatusBarVisible(!hints.testFlag(HidePreviewStatusBar)); + w->setToolBarVisible(!hints.testFlag(HidePreviewToolBar)); + } + + w->setHideResultEditButton(resultIsEditable()); + w->setStyleSheet(m_styleSheet); + m_activePreview = w; + + w->setPreviewScaleType(m_previewScaleType, m_previewScalePercent); + + connect(w,SIGNAL(destroyed(QObject*)), this, SLOT(slotPreviewWindowDestroyed(QObject*))); + w->exec(); } - - if (!hints.testFlag(PreviewBarsUserSetting)){ - w->setMenuVisible(!hints.testFlag(HidePreviewMenuBar)); - w->setStatusBarVisible(!hints.testFlag(HidePreviewStatusBar)); - w->setToolBarVisible(!hints.testFlag(HidePreviewToolBar)); - } - - w->setHideResultEditButton(resultIsEditable()); - w->setStyleSheet(m_styleSheet); - m_activePreview = w; - - w->setPreviewScaleType(m_previewScaleType, m_previewScalePercent); - - connect(w,SIGNAL(destroyed(QObject*)), this, SLOT(slotPreviewWindowDestroyed(QObject*))); - w->exec(); + } catch (ReportError &exception){ + saveError(exception.what()); + showError(exception.what()); } - } catch (ReportError &exception){ - saveError(exception.what()); - showError(exception.what()); - } } ReportDesignWindowInterface*ReportEnginePrivate::getDesignerWindow() @@ -1323,6 +1329,14 @@ void ReportEngine::previewReport(PreviewHints hints) d->previewReport(hints); } +void ReportEngine::previewReport(QPrinter *printer, PreviewHints hints) +{ + Q_D(ReportEngine); + if (m_settings) + d->setSettings(m_settings); + d->previewReport(printer, hints); +} + void ReportEngine::designReport() { Q_D(ReportEngine); diff --git a/limereport/lrreportengine.h b/limereport/lrreportengine.h index a36d1b0..00185d8 100644 --- a/limereport/lrreportengine.h +++ b/limereport/lrreportengine.h @@ -87,6 +87,7 @@ public: bool printToPDF(const QString& fileName); bool exportReport(QString exporterName, const QString &fileName = "", const QMap& params = QMap()); void previewReport(PreviewHints hints = PreviewBarsUserSetting); + void previewReport(QPrinter* printer, PreviewHints hints = PreviewBarsUserSetting); void designReport(); ReportDesignWindowInterface* getDesignerWindow(); void setShowProgressDialog(bool value); diff --git a/limereport/lrreportengine_p.h b/limereport/lrreportengine_p.h index 1813f81..69831b7 100644 --- a/limereport/lrreportengine_p.h +++ b/limereport/lrreportengine_p.h @@ -154,6 +154,7 @@ public: bool printToPDF(const QString& fileName); bool exportReport(QString exporterName, const QString &fileName = "", const QMap& params = QMap()); void previewReport(PreviewHints hints = PreviewBarsUserSetting); + void previewReport(QPrinter* printer, PreviewHints hints = PreviewBarsUserSetting); ReportDesignWindowInterface* getDesignerWindow(); void designReport();