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

Progress bars have been added to Design and Preview windows

This commit is contained in:
Arin Alexander 2019-10-16 02:08:45 +03:00
parent ccec7b4164
commit e3981cfd88
11 changed files with 150 additions and 28 deletions

View File

@ -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}\\\"

View File

@ -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()
{
if (report->isShowProgressDialog()){
m_currentPage = 0;
m_progressDialog = new QProgressDialog(tr("Start render"),tr("Cancel"),0,0,this);
m_progressDialog->setWindowModality(Qt::WindowModal);
//m_progressDialog->setWindowModality(Qt::WindowModal);
connect(m_progressDialog, SIGNAL(canceled()), report, SLOT(cancelRender()));
m_progressDialog->show();
QApplication::processEvents();
m_progressDialog->show();
}
}
void MainWindow::renderPageFinished(int renderedPageCount)

View File

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

View File

@ -42,6 +42,9 @@
#include <QFileDialog>
#include <QScrollBar>
#include <QDesktopWidget>
#include <QLabel>
#include <QMessageBox>
#include <QToolButton>
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

View File

@ -37,6 +37,7 @@
#include <QSettings>
#include <QEventLoop>
#include <QPrinter>
#include <QProgressBar>
#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

View File

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

View File

@ -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<QObject*>(m_reportDesignWidget->report()), SIGNAL(renderStarted()), this, SLOT(renderStarted()));
connect(dynamic_cast<QObject*>(m_reportDesignWidget->report()), SIGNAL(renderPageFinished(int)), this, SLOT(renderPageFinished(int)));
connect(dynamic_cast<QObject*>(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();
@ -101,6 +134,7 @@ ReportDesignWindow::ReportDesignWindow(ReportEnginePrivateInterface* report, QWi
restoreSetting();
m_hideLeftPanel->setChecked(isDockAreaVisible(Qt::LeftDockWidgetArea));
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<QObject*>(report), SIGNAL(renderStarted()), this, SLOT(renderStarted()));
connect(dynamic_cast<QObject*>(report), SIGNAL(renderPageFinished(int)), this, SLOT(renderPageFinished(int)));
connect(dynamic_cast<QObject*>(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<QObject*>(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();

View File

@ -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<QDockWidget*, bool> m_leftDocVisibleState;
QMap<QDockWidget*, bool> m_rightDocVisibleState;
QSortFilterProxyModel* m_filterModel;
QWidget* m_progressWidget;
QProgressBar* m_progressBar;
QLabel* m_progressLabel;
void createProgressBar();
};
class ObjectNameValidator : public ValidatorIntf{

View File

@ -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<QString, QSharedPointer<PrintProcessor> > printProcessors;
printProcessors.insert("default",QSharedPointer<PrintProcessor>(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);

View File

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

View File

@ -110,6 +110,9 @@ public:
virtual QList<QLocale::Language> 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 = "");