0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 16:44:39 +03:00

previewReport(QPrinter* printer, PreviewHints hints = PreviewBarsUserSetting) has been added to the report engine.

This commit is contained in:
Arin Alexander 2019-02-20 13:54:26 +03:00
parent b5f2f50993
commit c30bfc9a06
9 changed files with 110 additions and 56 deletions

View File

@ -3,6 +3,7 @@
#include <QWidget> #include <QWidget>
#include <QTimer> #include <QTimer>
#include <QPrinter>
#include "lrglobal.h" #include "lrglobal.h"
namespace LimeReport { namespace LimeReport {
@ -31,6 +32,8 @@ public:
void setScaleType(const ScaleType &scaleType, int percent = 0); void setScaleType(const ScaleType &scaleType, int percent = 0);
void setPreviewPageBackgroundColor(QColor color); void setPreviewPageBackgroundColor(QColor color);
QColor previewPageBackgroundColor(); QColor previewPageBackgroundColor();
QPrinter *defaultPrinter() const;
void setDefaultPrinter(QPrinter *defaultPrinter);
public slots: public slots:
void refreshPages(); void refreshPages();
void zoomIn(); void zoomIn();
@ -71,6 +74,8 @@ private:
int m_scalePercent; int m_scalePercent;
QTimer m_resizeTimer; QTimer m_resizeTimer;
QColor m_previewPageBackgroundColor; QColor m_previewPageBackgroundColor;
QPrinter* m_defaultPrinter;
void printPages(QPrinter *printer);
}; };
} // namespace LimeReport } // namespace LimeReport

View File

@ -87,6 +87,7 @@ public:
bool printToPDF(const QString& fileName); bool printToPDF(const QString& fileName);
bool exportReport(QString exporterName, const QString &fileName = "", const QMap<QString, QVariant>& params = QMap<QString, QVariant>()); bool exportReport(QString exporterName, const QString &fileName = "", const QMap<QString, QVariant>& params = QMap<QString, QVariant>());
void previewReport(PreviewHints hints = PreviewBarsUserSetting); void previewReport(PreviewHints hints = PreviewBarsUserSetting);
void previewReport(QPrinter* printer, PreviewHints hints = PreviewBarsUserSetting);
void designReport(); void designReport();
ReportDesignWindowInterface* getDesignerWindow(); ReportDesignWindowInterface* getDesignerWindow();
void setShowProgressDialog(bool value); void setShowProgressDialog(bool value);

View File

@ -71,7 +71,8 @@ QList<QString> PreviewReportWidgetPrivate::aviableExporters()
PreviewReportWidget::PreviewReportWidget(ReportEngine *report, QWidget *parent) : PreviewReportWidget::PreviewReportWidget(ReportEngine *report, QWidget *parent) :
QWidget(parent), QWidget(parent),
ui(new Ui::PreviewReportWidget), d_ptr(new PreviewReportWidgetPrivate(this)), 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); ui->setupUi(this);
d_ptr->m_report = report->d_ptr; d_ptr->m_report = report->d_ptr;
@ -193,8 +194,23 @@ void PreviewReportWidget::lastPage()
d_ptr->m_changingPage=false; d_ptr->m_changingPage=false;
} }
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);
}
}
void PreviewReportWidget::print() void PreviewReportWidget::print()
{ {
if (m_defaultPrinter){
printPages(m_defaultPrinter);
} else {
QPrinterInfo pi; QPrinterInfo pi;
QPrinter printer(QPrinter::HighResolution); QPrinter printer(QPrinter::HighResolution);
@ -212,13 +228,7 @@ void PreviewReportWidget::print()
#endif #endif
QPrintDialog dialog(&printer,QApplication::activeWindow()); QPrintDialog dialog(&printer,QApplication::activeWindow());
if (dialog.exec()==QDialog::Accepted){ if (dialog.exec()==QDialog::Accepted){
if (!d_ptr->m_reportPages.isEmpty()) printPages(&printer);
ReportEnginePrivate::printReport(
d_ptr->m_reportPages,
printer
);
foreach(PageItemDesignIntf::Ptr pageItem, d_ptr->m_reportPages){
d_ptr->m_previewPage->reactivatePageItem(pageItem);
} }
} }
} }
@ -307,6 +317,16 @@ void PreviewReportWidget::emitPageSet()
emit pagesSet(d_ptr->m_reportPages.count()); 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 ScaleType PreviewReportWidget::scaleType() const
{ {
return m_scaleType; return m_scaleType;

View File

@ -3,6 +3,7 @@
#include <QWidget> #include <QWidget>
#include <QTimer> #include <QTimer>
#include <QPrinter>
#include "lrglobal.h" #include "lrglobal.h"
namespace LimeReport { namespace LimeReport {
@ -31,6 +32,8 @@ public:
void setScaleType(const ScaleType &scaleType, int percent = 0); void setScaleType(const ScaleType &scaleType, int percent = 0);
void setPreviewPageBackgroundColor(QColor color); void setPreviewPageBackgroundColor(QColor color);
QColor previewPageBackgroundColor(); QColor previewPageBackgroundColor();
QPrinter *defaultPrinter() const;
void setDefaultPrinter(QPrinter *defaultPrinter);
public slots: public slots:
void refreshPages(); void refreshPages();
void zoomIn(); void zoomIn();
@ -71,6 +74,8 @@ private:
int m_scalePercent; int m_scalePercent;
QTimer m_resizeTimer; QTimer m_resizeTimer;
QColor m_previewPageBackgroundColor; QColor m_previewPageBackgroundColor;
QPrinter* m_defaultPrinter;
void printPages(QPrinter *printer);
}; };
} // namespace LimeReport } // namespace LimeReport

View File

@ -209,6 +209,11 @@ void PreviewReportWindow::setPages(ReportPages pages)
} }
} }
void PreviewReportWindow::setDefaultPrinter(QPrinter *printer)
{
m_previewReportWidget->setDefaultPrinter(printer);
}
void PreviewReportWindow::exec() void PreviewReportWindow::exec()
{ {
bool deleteOnClose = testAttribute(Qt::WA_DeleteOnClose); bool deleteOnClose = testAttribute(Qt::WA_DeleteOnClose);

View File

@ -36,6 +36,7 @@
#include <QComboBox> #include <QComboBox>
#include <QSettings> #include <QSettings>
#include <QEventLoop> #include <QEventLoop>
#include <QPrinter>
#include "serializators/lrxmlreader.h" #include "serializators/lrxmlreader.h"
@ -61,6 +62,7 @@ public:
~PreviewReportWindow(); ~PreviewReportWindow();
void setReportReader(ItemsReaderIntf::Ptr reader); void setReportReader(ItemsReaderIntf::Ptr reader);
void setPages(ReportPages pages); void setPages(ReportPages pages);
void setDefaultPrinter(QPrinter* printer);
void exec(); void exec();
void initPreview(int pagesCount); void initPreview(int pagesCount);
void reloadPreview(); void reloadPreview();

View File

@ -496,7 +496,12 @@ bool ReportEnginePrivate::exportReport(QString exporterName, const QString &file
void ReportEnginePrivate::previewReport(PreviewHints hints) void ReportEnginePrivate::previewReport(PreviewHints hints)
{ {
// QTime start = QTime::currentTime(); previewReport(0, hints);
}
void ReportEnginePrivate::previewReport(QPrinter *printer, PreviewHints hints)
{
// QTime start = QTime::currentTime();
try{ try{
dataManager()->setDesignTime(false); dataManager()->setDesignTime(false);
ReportPages pages = renderToPages(); ReportPages pages = renderToPages();
@ -508,6 +513,7 @@ void ReportEnginePrivate::previewReport(PreviewHints hints)
w->setWindowFlags(Qt::Dialog|Qt::WindowMaximizeButtonHint|Qt::WindowCloseButtonHint| Qt::WindowMinMaxButtonsHint); w->setWindowFlags(Qt::Dialog|Qt::WindowMaximizeButtonHint|Qt::WindowCloseButtonHint| Qt::WindowMinMaxButtonsHint);
w->setAttribute(Qt::WA_DeleteOnClose,true); w->setAttribute(Qt::WA_DeleteOnClose,true);
w->setWindowModality(Qt::ApplicationModal); w->setWindowModality(Qt::ApplicationModal);
w->setDefaultPrinter(printer);
//w->setWindowIcon(QIcon(":/report/images/main.ico")); //w->setWindowIcon(QIcon(":/report/images/main.ico"));
w->setWindowIcon(m_previewWindowIcon); w->setWindowIcon(m_previewWindowIcon);
w->setWindowTitle(m_previewWindowTitle); w->setWindowTitle(m_previewWindowTitle);
@ -1323,6 +1329,14 @@ void ReportEngine::previewReport(PreviewHints hints)
d->previewReport(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() void ReportEngine::designReport()
{ {
Q_D(ReportEngine); Q_D(ReportEngine);

View File

@ -87,6 +87,7 @@ public:
bool printToPDF(const QString& fileName); bool printToPDF(const QString& fileName);
bool exportReport(QString exporterName, const QString &fileName = "", const QMap<QString, QVariant>& params = QMap<QString, QVariant>()); bool exportReport(QString exporterName, const QString &fileName = "", const QMap<QString, QVariant>& params = QMap<QString, QVariant>());
void previewReport(PreviewHints hints = PreviewBarsUserSetting); void previewReport(PreviewHints hints = PreviewBarsUserSetting);
void previewReport(QPrinter* printer, PreviewHints hints = PreviewBarsUserSetting);
void designReport(); void designReport();
ReportDesignWindowInterface* getDesignerWindow(); ReportDesignWindowInterface* getDesignerWindow();
void setShowProgressDialog(bool value); void setShowProgressDialog(bool value);

View File

@ -154,6 +154,7 @@ public:
bool printToPDF(const QString& fileName); bool printToPDF(const QString& fileName);
bool exportReport(QString exporterName, const QString &fileName = "", const QMap<QString, QVariant>& params = QMap<QString, QVariant>()); bool exportReport(QString exporterName, const QString &fileName = "", const QMap<QString, QVariant>& params = QMap<QString, QVariant>());
void previewReport(PreviewHints hints = PreviewBarsUserSetting); void previewReport(PreviewHints hints = PreviewBarsUserSetting);
void previewReport(QPrinter* printer, PreviewHints hints = PreviewBarsUserSetting);
ReportDesignWindowInterface* getDesignerWindow(); ReportDesignWindowInterface* getDesignerWindow();
void designReport(); void designReport();