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 <QTimer>
#include <QPrinter>
#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

View File

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

View File

@ -71,7 +71,8 @@ QList<QString> 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,8 +194,23 @@ void PreviewReportWidget::lastPage()
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()
{
if (m_defaultPrinter){
printPages(m_defaultPrinter);
} else {
QPrinterInfo pi;
QPrinter printer(QPrinter::HighResolution);
@ -212,13 +228,7 @@ void PreviewReportWidget::print()
#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);
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;

View File

@ -3,6 +3,7 @@
#include <QWidget>
#include <QTimer>
#include <QPrinter>
#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

View File

@ -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);

View File

@ -36,6 +36,7 @@
#include <QComboBox>
#include <QSettings>
#include <QEventLoop>
#include <QPrinter>
#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();

View File

@ -495,6 +495,11 @@ bool ReportEnginePrivate::exportReport(QString exporterName, const QString &file
}
void ReportEnginePrivate::previewReport(PreviewHints hints)
{
previewReport(0, hints);
}
void ReportEnginePrivate::previewReport(QPrinter *printer, PreviewHints hints)
{
// QTime start = QTime::currentTime();
try{
@ -508,6 +513,7 @@ void ReportEnginePrivate::previewReport(PreviewHints hints)
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);
@ -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);

View File

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

View File

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