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,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;

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

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

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