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,32 +194,41 @@ 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);
if (!pi.defaultPrinter().isNull()) if (!pi.defaultPrinter().isNull())
#ifdef HAVE_QT4 #ifdef HAVE_QT4
printer.setPrinterName(pi.defaultPrinter().printerName()); printer.setPrinterName(pi.defaultPrinter().printerName());
#endif #endif
#ifdef HAVE_QT5 #ifdef HAVE_QT5
#if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0))
printer.setPrinterName(pi.defaultPrinterName()); printer.setPrinterName(pi.defaultPrinterName());
#else #else
printer.setPrinterName(pi.defaultPrinter().printerName()); printer.setPrinterName(pi.defaultPrinter().printerName());
#endif #endif
#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,48 +496,54 @@ 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);
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);
if (!dataManager()->errorsList().isEmpty()){ void ReportEnginePrivate::previewReport(QPrinter *printer, PreviewHints hints)
w->setErrorMessages(dataManager()->errorsList()); {
// 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();
} }
} catch (ReportError &exception){
if (!hints.testFlag(PreviewBarsUserSetting)){ saveError(exception.what());
w->setMenuVisible(!hints.testFlag(HidePreviewMenuBar)); showError(exception.what());
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());
}
} }
ReportDesignWindowInterface*ReportEnginePrivate::getDesignerWindow() ReportDesignWindowInterface*ReportEnginePrivate::getDesignerWindow()
@ -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();