From e3981cfd8899fdd1ba149047ca8cfa5f24f3206e Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Wed, 16 Oct 2019 02:08:45 +0300 Subject: [PATCH] Progress bars have been added to Design and Preview windows --- common.pri | 2 +- demo_r1/mainwindow.cpp | 17 +++++--- include/lrreportengine.h | 1 + limereport/lrpreviewreportwindow.cpp | 54 ++++++++++++++++++++++- limereport/lrpreviewreportwindow.h | 7 +++ limereport/lrreportdesignwidget.cpp | 3 ++ limereport/lrreportdesignwindow.cpp | 64 +++++++++++++++++++++------- limereport/lrreportdesignwindow.h | 8 ++++ limereport/lrreportengine.cpp | 17 ++++++-- limereport/lrreportengine.h | 1 + limereport/lrreportengine_p.h | 4 ++ 11 files changed, 150 insertions(+), 28 deletions(-) diff --git a/common.pri b/common.pri index 6a5f6d5..c7b5359 100644 --- a/common.pri +++ b/common.pri @@ -127,7 +127,7 @@ RCC_DIR = $${ARCH_DIR}/$${BUILD_TYPE}/rcc LIMEREPORT_VERSION_MAJOR = 1 LIMEREPORT_VERSION_MINOR = 5 -LIMEREPORT_VERSION_RELEASE = 19 +LIMEREPORT_VERSION_RELEASE = 20 LIMEREPORT_VERSION = '$${LIMEREPORT_VERSION_MAJOR}.$${LIMEREPORT_VERSION_MINOR}.$${LIMEREPORT_VERSION_RELEASE}' DEFINES *= LIMEREPORT_VERSION_STR=\\\"$${LIMEREPORT_VERSION}\\\" diff --git a/demo_r1/mainwindow.cpp b/demo_r1/mainwindow.cpp index 05488ce..348cbb1 100644 --- a/demo_r1/mainwindow.cpp +++ b/demo_r1/mainwindow.cpp @@ -77,7 +77,7 @@ MainWindow::MainWindow(QWidget *parent) : int index = m_customers->record().indexOf("CustomerID"); m_orders->bindValue(":id",m_customers->value(index)); m_orders->exec(); - }; + } } LimeReport::ICallbackDatasource * callbackDatasource = report->dataManager()->createCallbackDatasource("master"); @@ -156,18 +156,21 @@ void MainWindow::on_pushButton_2_clicked() // printers.insert("default",printer); // report->printReport(printers); // } + report->setShowProgressDialog(true); report->previewReport(); } } void MainWindow::renderStarted() { - m_currentPage = 0; - m_progressDialog = new QProgressDialog(tr("Start render"),tr("Cancel"),0,0,this); - m_progressDialog->setWindowModality(Qt::WindowModal); - connect(m_progressDialog, SIGNAL(canceled()), report, SLOT(cancelRender())); - m_progressDialog->show(); - QApplication::processEvents(); + if (report->isShowProgressDialog()){ + m_currentPage = 0; + m_progressDialog = new QProgressDialog(tr("Start render"),tr("Cancel"),0,0,this); + //m_progressDialog->setWindowModality(Qt::WindowModal); + connect(m_progressDialog, SIGNAL(canceled()), report, SLOT(cancelRender())); + QApplication::processEvents(); + m_progressDialog->show(); + } } void MainWindow::renderPageFinished(int renderedPageCount) diff --git a/include/lrreportengine.h b/include/lrreportengine.h index 289a9e9..8ef7ff0 100644 --- a/include/lrreportengine.h +++ b/include/lrreportengine.h @@ -164,6 +164,7 @@ public: void designReport(); ReportDesignWindowInterface* getDesignerWindow(); void setShowProgressDialog(bool value); + bool isShowProgressDialog(); IDataSourceManager* dataManager(); IScriptEngineManager* scriptManager(); bool loadFromFile(const QString& fileName, bool autoLoadPreviewOnChange = false); diff --git a/limereport/lrpreviewreportwindow.cpp b/limereport/lrpreviewreportwindow.cpp index ee00a86..01d42cb 100644 --- a/limereport/lrpreviewreportwindow.cpp +++ b/limereport/lrpreviewreportwindow.cpp @@ -42,6 +42,9 @@ #include #include #include +#include +#include +#include namespace LimeReport{ @@ -51,6 +54,25 @@ PreviewReportWindow::PreviewReportWindow(ReportEngine *report, QWidget *parent, m_scalePercentChanging(false) { ui->setupUi(this); + + m_progressWidget = new QWidget(ui->statusbar); + QHBoxLayout* progressLayout = new QHBoxLayout(); + progressLayout->setMargin(0); + progressLayout->addWidget(new QLabel(tr("Printing"))); + m_progressBar = new QProgressBar(ui->statusbar); + m_progressBar->setMaximumWidth(100); + m_progressBar->setMaximumHeight(ui->statusbar->fontMetrics().height()); + progressLayout->addWidget(m_progressBar); + QToolButton* tbCancel = new QToolButton(); + tbCancel->setIcon(QIcon(":/report/images/closebox")); + tbCancel->setAutoRaise(true); + connect(tbCancel, SIGNAL(clicked(bool)), this, SLOT(slotCancelPrinting(bool))); + progressLayout->addWidget(tbCancel); + progressLayout->setSizeConstraint(QLayout::SetFixedSize); + m_progressWidget->setLayout(progressLayout); + m_progressWidget->setVisible(false); + ui->statusbar->addPermanentWidget(m_progressWidget); + setWindowTitle("Lime Report Preview"); m_pagesNavigator = new QSpinBox(this); m_pagesNavigator->setMaximum(10000000); @@ -73,6 +95,10 @@ PreviewReportWindow::PreviewReportWindow(ReportEngine *report, QWidget *parent, connect(m_previewReportWidget, SIGNAL(onSave(bool&, LimeReport::IPreparedPages*)), this, SIGNAL(onSave(bool&, LimeReport::IPreparedPages*))); + connect(m_previewReportWidget->d_ptr->m_report, SIGNAL(printingStarted(int)), this, SLOT(slotPrintingStarted(int))); + connect(m_previewReportWidget->d_ptr->m_report, SIGNAL(pagePrintingFinished(int)), this, SLOT(slotPagePrintingFinished(int))); + connect(m_previewReportWidget->d_ptr->m_report, SIGNAL(printingFinished()), this, SLOT(slotPrintingFinished())); + m_fontEditor = new FontEditorWidgetForPage(m_previewReportWidget->d_ptr->m_previewPage,tr("Font"),this); m_fontEditor->setObjectName("fontTools"); m_fontEditor->setIconSize(ui->toolBar->iconSize()); @@ -260,8 +286,12 @@ void PreviewReportWindow::exec() if (deleteOnClose) delete this; } -void PreviewReportWindow::closeEvent(QCloseEvent *) +void PreviewReportWindow::closeEvent(QCloseEvent* e) { + if (m_progressBar->isVisible()){ + QMessageBox::critical(this, tr("Attention"), tr("The printing is in process")); + e->setAccepted(false); + } #ifdef Q_OS_WIN writeSetting(); #endif @@ -515,5 +545,27 @@ void PreviewReportWindow::slotItemInserted(PageDesignIntf *, QPointF, const QStr slotActivateItemSelectionMode(); } +void PreviewReportWindow::slotPrintingStarted(int pageCount) +{ + m_progressBar->setMinimum(1); + m_progressBar->setMaximum(pageCount); + m_progressWidget->setVisible(true); +} + +void PreviewReportWindow::slotPagePrintingFinished(int pageIndex) +{ + m_progressBar->setValue(pageIndex); +} + +void PreviewReportWindow::slotPrintingFinished() +{ + m_progressWidget->setVisible(false); +} + +void PreviewReportWindow::slotCancelPrinting(bool) +{ + m_previewReportWidget->d_ptr->m_report->cancelPrinting(); +} + }// namespace LimeReport diff --git a/limereport/lrpreviewreportwindow.h b/limereport/lrpreviewreportwindow.h index 4935201..98808a3 100644 --- a/limereport/lrpreviewreportwindow.h +++ b/limereport/lrpreviewreportwindow.h @@ -37,6 +37,7 @@ #include #include #include +#include #include "serializators/lrxmlreader.h" #include "lrpreparedpagesintf.h" @@ -118,6 +119,10 @@ private slots: void on_actionShow_Toolbar_triggered(); void slotCurrentPageChanged(int page); void slotItemInserted(LimeReport::PageDesignIntf* report, QPointF pos, const QString& ItemType); + void slotPrintingStarted(int pageCount); + void slotPagePrintingFinished(int pageIndex); + void slotPrintingFinished(); + void slotCancelPrinting(bool); signals: void onSave(bool& saved, LimeReport::IPreparedPages* pages); private: @@ -139,6 +144,8 @@ private: ScaleType m_previewScaleType; int m_previewScalePercent; bool m_scalePercentChanging; + QProgressBar* m_progressBar; + QWidget* m_progressWidget; }; } //namespace LimeReport #endif // LRPREVIEWREPORTWINDOW_H diff --git a/limereport/lrreportdesignwidget.cpp b/limereport/lrreportdesignwidget.cpp index cd09abc..a1e8a3b 100644 --- a/limereport/lrreportdesignwidget.cpp +++ b/limereport/lrreportdesignwidget.cpp @@ -726,7 +726,10 @@ void ReportDesignWidget::previewReport() #ifdef HAVE_QTDESIGNER_INTEGRATION updateDialogs(); #endif + bool showProgressDialog = report()->isShowProgressDialog(); + report()->setShowProgressDialog(false); report()->previewReport(); + report()->setShowProgressDialog(showProgressDialog); } void ReportDesignWidget::printReport() diff --git a/limereport/lrreportdesignwindow.cpp b/limereport/lrreportdesignwindow.cpp index d98af07..5181c7b 100644 --- a/limereport/lrreportdesignwindow.cpp +++ b/limereport/lrreportdesignwindow.cpp @@ -65,6 +65,38 @@ namespace LimeReport{ ReportDesignWindow* ReportDesignWindow::m_instance=0; +void ReportDesignWindow::createProgressBar() +{ + m_progressWidget = new QWidget(m_statusBar); + QHBoxLayout* progressLayout = new QHBoxLayout(); + progressLayout->setMargin(0); + m_progressLabel = new QLabel(tr("Rendered %1 pages").arg(0)); + progressLayout->addWidget(m_progressLabel); + m_progressBar = new QProgressBar(m_statusBar); + m_progressBar->setFormat("%v pages"); + m_progressBar->setAlignment(Qt::AlignCenter); + m_progressBar->setMaximumWidth(100); + m_progressBar->setMaximumHeight(m_statusBar->fontMetrics().height()); + m_progressBar->setMinimum(0); + m_progressBar->setMaximum(0); + m_progressBar->setTextVisible(true); + progressLayout->addWidget(m_progressBar); + QToolButton* tbCancel = new QToolButton(); + tbCancel->setToolTip(tr("Cancel report rendering")); + tbCancel->setIcon(QIcon(":/report/images/closebox")); + tbCancel->setAutoRaise(true); + connect(tbCancel, SIGNAL(clicked(bool)), this, SLOT(slotCancelRendering(bool))); + progressLayout->addWidget(tbCancel); + progressLayout->setSizeConstraint(QLayout::SetFixedSize); + m_progressWidget->setLayout(progressLayout); + m_progressWidget->setVisible(false); + m_statusBar->addPermanentWidget(m_progressWidget); + + connect(dynamic_cast(m_reportDesignWidget->report()), SIGNAL(renderStarted()), this, SLOT(renderStarted())); + connect(dynamic_cast(m_reportDesignWidget->report()), SIGNAL(renderPageFinished(int)), this, SLOT(renderPageFinished(int))); + connect(dynamic_cast(m_reportDesignWidget->report()), SIGNAL(renderFinished()), this, SLOT(renderFinished())); +} + ReportDesignWindow::ReportDesignWindow(ReportEnginePrivateInterface* report, QWidget *parent, QSettings* settings) : ReportDesignWindowInterface(parent), m_textAttibutesIsChanging(false), m_settings(settings), m_ownedSettings(false), m_progressDialog(0), m_showProgressDialog(true), m_editorTabType(ReportDesignWidget::Page), m_reportItemIsLocked(false) @@ -77,6 +109,7 @@ ReportDesignWindow::ReportDesignWindow(ReportEnginePrivateInterface* report, QWi createDataWindow(); createScriptWindow(); createObjectsBrowser(); + #ifdef HAVE_QTDESIGNER_INTEGRATION createDialogWidgetBox(); createDialogPropertyEditor(); @@ -100,7 +133,8 @@ ReportDesignWindow::ReportDesignWindow(ReportEnginePrivateInterface* report, QWi showDefaultToolBars(); restoreSetting(); m_hideLeftPanel->setChecked(isDockAreaVisible(Qt::LeftDockWidgetArea)); - m_hideRightPanel->setChecked(isDockAreaVisible(Qt::RightDockWidgetArea)); + m_hideRightPanel->setChecked(isDockAreaVisible(Qt::RightDockWidgetArea)); + createProgressBar(); } ReportDesignWindow::~ReportDesignWindow() @@ -515,9 +549,6 @@ void ReportDesignWindow::initReportEditor(ReportEnginePrivateInterface* report) this, SLOT(slotBandAdded(LimeReport::PageDesignIntf*,LimeReport::BandDesignIntf*))); connect(m_reportDesignWidget, SIGNAL(bandDeleted(LimeReport::PageDesignIntf*,LimeReport::BandDesignIntf*)), this, SLOT(slotBandDeleted(LimeReport::PageDesignIntf*,LimeReport::BandDesignIntf*))); - connect(dynamic_cast(report), SIGNAL(renderStarted()), this, SLOT(renderStarted())); - connect(dynamic_cast(report), SIGNAL(renderPageFinished(int)), this, SLOT(renderPageFinished(int))); - connect(dynamic_cast(report), SIGNAL(renderFinished()), this, SLOT(renderFinished())); connect(m_reportDesignWidget, SIGNAL(pageAdded(PageDesignIntf*)), this, SLOT(slotPageAdded(PageDesignIntf*))); connect(m_reportDesignWidget, SIGNAL(pageDeleted()), this, SLOT(slotPageDeleted())); } @@ -1377,26 +1408,17 @@ void ReportDesignWindow::slotActivePageChanged() void ReportDesignWindow::renderStarted() { - if (m_showProgressDialog){ - m_progressDialog = new QProgressDialog(tr("Rendering report"),tr("Abort"),0,0,this); - m_progressDialog->open(dynamic_cast(m_reportDesignWidget->report()), SLOT(cancelRender())); - QApplication::processEvents(); - } + m_progressWidget->setVisible(true); } void ReportDesignWindow::renderPageFinished(int renderedPageCount) { - if (m_progressDialog) - m_progressDialog->setLabelText(QString::number(renderedPageCount)+tr(" page rendered")); + m_progressLabel->setText(tr("Rendered %1 pages").arg(renderedPageCount)); } void ReportDesignWindow::renderFinished() { - if (m_progressDialog){ - m_progressDialog->close(); - delete m_progressDialog; - } - m_progressDialog = 0; + m_progressWidget->setVisible(false); } void ReportDesignWindow::slotShowAbout() @@ -1536,8 +1558,18 @@ void ReportDesignWindow::slotSelectOneLevelItems() m_reportDesignWidget->selectOneLevelItems(); } +void ReportDesignWindow::slotCancelRendering(bool) +{ + m_reportDesignWidget->report()->cancelRender(); +} + void ReportDesignWindow::closeEvent(QCloseEvent * event) { + if (m_progressWidget->isVisible()){ + QMessageBox::critical(this, tr("Attention"), tr("The rendering is in process")); + event->ignore(); + return; + } if (checkNeedToSave()){ m_dataBrowser->closeAllDataWindows(); writeState(); diff --git a/limereport/lrreportdesignwindow.h b/limereport/lrreportdesignwindow.h index 5701894..b0ab082 100644 --- a/limereport/lrreportdesignwindow.h +++ b/limereport/lrreportdesignwindow.h @@ -128,6 +128,8 @@ private slots: void slotLockSelectedItems(); void slotUnlockSelectedItems(); void slotSelectOneLevelItems(); + void slotCancelRendering(bool); + protected: void closeEvent(QCloseEvent *event); void resizeEvent(QResizeEvent *); @@ -281,6 +283,12 @@ private: QMap m_leftDocVisibleState; QMap m_rightDocVisibleState; QSortFilterProxyModel* m_filterModel; + + QWidget* m_progressWidget; + QProgressBar* m_progressBar; + QLabel* m_progressLabel; + + void createProgressBar(); }; class ObjectNameValidator : public ValidatorIntf{ diff --git a/limereport/lrreportengine.cpp b/limereport/lrreportengine.cpp index 2c977f9..1717f3f 100644 --- a/limereport/lrreportengine.cpp +++ b/limereport/lrreportengine.cpp @@ -302,11 +302,16 @@ bool ReportEnginePrivate::printPages(ReportPages pages, QPrinter *printer) void ReportEnginePrivate::internalPrintPages(ReportPages pages, QPrinter &printer) { - m_cancelPrinting = false; int currenPage = 1; + m_cancelPrinting = false; QMap > printProcessors; printProcessors.insert("default",QSharedPointer(new PrintProcessor(&printer))); - emit printingStarted(printer.toPage() - printer.fromPage()); + + int pageCount = (printer.printRange() == QPrinter::AllPages) ? + pages.size() : + printer.toPage() - printer.fromPage(); + + emit printingStarted(pageCount); foreach(PageItemDesignIntf::Ptr page, pages){ if ( !m_cancelPrinting && ((printer.printRange() == QPrinter::AllPages) || @@ -708,7 +713,7 @@ bool ReportEnginePrivate::slotLoadFromFile(const QString &fileName) } EASY_END_BLOCK; return true; - }; + } } m_lastError = reader->lastError(); EASY_END_BLOCK; @@ -1652,6 +1657,12 @@ void ReportEngine::setShowProgressDialog(bool value) d->setShowProgressDialog(value); } +bool ReportEngine::isShowProgressDialog() +{ + Q_D(ReportEngine); + return d->isShowProgressDialog(); +} + IDataSourceManager *ReportEngine::dataManager() { Q_D(ReportEngine); diff --git a/limereport/lrreportengine.h b/limereport/lrreportengine.h index 289a9e9..8ef7ff0 100644 --- a/limereport/lrreportengine.h +++ b/limereport/lrreportengine.h @@ -164,6 +164,7 @@ public: void designReport(); ReportDesignWindowInterface* getDesignerWindow(); void setShowProgressDialog(bool value); + bool isShowProgressDialog(); IDataSourceManager* dataManager(); IScriptEngineManager* scriptManager(); bool loadFromFile(const QString& fileName, bool autoLoadPreviewOnChange = false); diff --git a/limereport/lrreportengine_p.h b/limereport/lrreportengine_p.h index 17cacd7..3196f4e 100644 --- a/limereport/lrreportengine_p.h +++ b/limereport/lrreportengine_p.h @@ -110,6 +110,9 @@ public: virtual QList designerLanguages() = 0; virtual QLocale::Language currentDesignerLanguage() = 0; virtual void setCurrentDesignerLanguage(QLocale::Language language) = 0; + virtual void cancelRender() = 0; + virtual void setShowProgressDialog(bool value) = 0; + virtual bool isShowProgressDialog() const = 0; }; class PrintProcessor{ @@ -179,6 +182,7 @@ public: void designReport(); void setSettings(QSettings* value); void setShowProgressDialog(bool value){m_showProgressDialog = value;} + bool isShowProgressDialog() const {return m_showProgressDialog;} QSettings* settings(); bool loadFromFile(const QString& fileName, bool autoLoadPreviewOnChange); bool loadFromByteArray(QByteArray *data, const QString& name = "");