mirror of
https://github.com/fralx/LimeReport.git
synced 2024-12-24 08:34:38 +03:00
Preview Widget refactored.
This commit is contained in:
parent
2aec1cfc26
commit
b315af26b9
@ -24,20 +24,25 @@ public:
|
|||||||
~PreviewReportWidget();
|
~PreviewReportWidget();
|
||||||
public slots:
|
public slots:
|
||||||
void refreshPages();
|
void refreshPages();
|
||||||
void slotZoomIn();
|
void zoomIn();
|
||||||
void slotZoomOut();
|
void zoomOut();
|
||||||
|
|
||||||
void slotFirstPage();
|
void firstPage();
|
||||||
void slotPriorPage();
|
void priorPage();
|
||||||
void slotNextPage();
|
void nextPage();
|
||||||
void slotLastPage();
|
void lastPage();
|
||||||
|
|
||||||
void slotPrint();
|
void print();
|
||||||
void slotPrintToPDF();
|
void printToPDF();
|
||||||
void slotPageNavigatorChanged(int value);
|
void pageNavigatorChanged(int value);
|
||||||
void slotSaveToFile();
|
void saveToFile();
|
||||||
|
void setScalePercent(int percent);
|
||||||
|
void fitWidth();
|
||||||
|
void fitPage();
|
||||||
signals:
|
signals:
|
||||||
void pageChanged(int page);
|
void pageChanged(int page);
|
||||||
|
void scalePercentChanged(int percent);
|
||||||
|
void pagesSet(int pageCount);
|
||||||
private slots:
|
private slots:
|
||||||
void slotSliderMoved(int value);
|
void slotSliderMoved(int value);
|
||||||
void reportEngineDestroyed(QObject* object);
|
void reportEngineDestroyed(QObject* object);
|
||||||
@ -45,6 +50,7 @@ private:
|
|||||||
void initPreview();
|
void initPreview();
|
||||||
void setErrorsMesagesVisible(bool visible);
|
void setErrorsMesagesVisible(bool visible);
|
||||||
void setErrorMessages(const QStringList &value);
|
void setErrorMessages(const QStringList &value);
|
||||||
|
void emitPageSet();
|
||||||
private:
|
private:
|
||||||
Ui::PreviewReportWidget *ui;
|
Ui::PreviewReportWidget *ui;
|
||||||
PreviewReportWidgetPrivate* d_ptr;
|
PreviewReportWidgetPrivate* d_ptr;
|
||||||
|
@ -46,9 +46,17 @@ void PreviewReportWidgetPrivate::setPages(ReportPages pages)
|
|||||||
if (pages.at(0)) pages.at(0)->setSelected(true);
|
if (pages.at(0)) pages.at(0)->setSelected(true);
|
||||||
m_changingPage = false;
|
m_changingPage = false;
|
||||||
q_ptr->initPreview();
|
q_ptr->initPreview();
|
||||||
|
q_ptr->emitPageSet();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PageItemDesignIntf::Ptr PreviewReportWidgetPrivate::currentPage()
|
||||||
|
{
|
||||||
|
if (m_reportPages.count()>m_currentPage)
|
||||||
|
return m_reportPages.at(m_currentPage-1);
|
||||||
|
else return PageItemDesignIntf::Ptr(0);
|
||||||
|
}
|
||||||
|
|
||||||
PreviewReportWidget::PreviewReportWidget(ReportEnginePrivate *report, QWidget *parent) :
|
PreviewReportWidget::PreviewReportWidget(ReportEnginePrivate *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))
|
||||||
@ -75,10 +83,11 @@ PreviewReportWidget::~PreviewReportWidget()
|
|||||||
|
|
||||||
void PreviewReportWidget::initPreview()
|
void PreviewReportWidget::initPreview()
|
||||||
{
|
{
|
||||||
|
if (ui->graphicsView->scene()!=d_ptr->m_previewPage)
|
||||||
|
ui->graphicsView->setScene(d_ptr->m_previewPage);
|
||||||
ui->graphicsView->resetMatrix();
|
ui->graphicsView->resetMatrix();
|
||||||
ui->graphicsView->setScene(d_ptr->m_previewPage);
|
|
||||||
ui->graphicsView->centerOn(0, 0);
|
ui->graphicsView->centerOn(0, 0);
|
||||||
ui->graphicsView->scale(0.5,0.5);
|
setScalePercent(d_ptr->m_scalePercent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewReportWidget::setErrorsMesagesVisible(bool visible)
|
void PreviewReportWidget::setErrorsMesagesVisible(bool visible)
|
||||||
@ -86,17 +95,20 @@ void PreviewReportWidget::setErrorsMesagesVisible(bool visible)
|
|||||||
ui->errorsView->setVisible(visible);
|
ui->errorsView->setVisible(visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewReportWidget::slotZoomIn()
|
void PreviewReportWidget::zoomIn()
|
||||||
{
|
{
|
||||||
ui->graphicsView->scale(1.2,1.2);
|
d_ptr->m_scalePercent += 10;
|
||||||
|
setScalePercent(d_ptr->m_scalePercent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewReportWidget::slotZoomOut()
|
void PreviewReportWidget::zoomOut()
|
||||||
{
|
{
|
||||||
ui->graphicsView->scale(1/1.2,1/1.2);
|
if (d_ptr->m_scalePercent>0)
|
||||||
|
d_ptr->m_scalePercent -= 10;
|
||||||
|
setScalePercent(d_ptr->m_scalePercent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewReportWidget::slotFirstPage()
|
void PreviewReportWidget::firstPage()
|
||||||
{
|
{
|
||||||
d_ptr->m_changingPage=true;
|
d_ptr->m_changingPage=true;
|
||||||
if ((!d_ptr->m_reportPages.isEmpty())&&(d_ptr->m_currentPage>1)){
|
if ((!d_ptr->m_reportPages.isEmpty())&&(d_ptr->m_currentPage>1)){
|
||||||
@ -107,7 +119,7 @@ void PreviewReportWidget::slotFirstPage()
|
|||||||
d_ptr->m_changingPage=false;
|
d_ptr->m_changingPage=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewReportWidget::slotPriorPage()
|
void PreviewReportWidget::priorPage()
|
||||||
{
|
{
|
||||||
d_ptr->m_changingPage=true;
|
d_ptr->m_changingPage=true;
|
||||||
if ((!d_ptr->m_reportPages.isEmpty())&&(d_ptr->m_currentPage>1)){
|
if ((!d_ptr->m_reportPages.isEmpty())&&(d_ptr->m_currentPage>1)){
|
||||||
@ -118,7 +130,7 @@ void PreviewReportWidget::slotPriorPage()
|
|||||||
d_ptr->m_changingPage=false;
|
d_ptr->m_changingPage=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewReportWidget::slotNextPage()
|
void PreviewReportWidget::nextPage()
|
||||||
{
|
{
|
||||||
d_ptr->m_changingPage=true;
|
d_ptr->m_changingPage=true;
|
||||||
if ((!d_ptr->m_reportPages.isEmpty())&&(d_ptr->m_reportPages.count()>(d_ptr->m_currentPage))){
|
if ((!d_ptr->m_reportPages.isEmpty())&&(d_ptr->m_reportPages.count()>(d_ptr->m_currentPage))){
|
||||||
@ -129,7 +141,7 @@ void PreviewReportWidget::slotNextPage()
|
|||||||
d_ptr->m_changingPage=false;
|
d_ptr->m_changingPage=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewReportWidget::slotLastPage()
|
void PreviewReportWidget::lastPage()
|
||||||
{
|
{
|
||||||
d_ptr->m_changingPage=true;
|
d_ptr->m_changingPage=true;
|
||||||
if ((!d_ptr->m_reportPages.isEmpty())&&(d_ptr->m_reportPages.count()>(d_ptr->m_currentPage))){
|
if ((!d_ptr->m_reportPages.isEmpty())&&(d_ptr->m_reportPages.count()>(d_ptr->m_currentPage))){
|
||||||
@ -140,7 +152,7 @@ void PreviewReportWidget::slotLastPage()
|
|||||||
d_ptr->m_changingPage=false;
|
d_ptr->m_changingPage=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewReportWidget::slotPrint()
|
void PreviewReportWidget::print()
|
||||||
{
|
{
|
||||||
QPrinter printer(QPrinter::HighResolution);
|
QPrinter printer(QPrinter::HighResolution);
|
||||||
QPrintDialog dialog(&printer,QApplication::activeWindow());
|
QPrintDialog dialog(&printer,QApplication::activeWindow());
|
||||||
@ -151,10 +163,13 @@ void PreviewReportWidget::slotPrint()
|
|||||||
printer,
|
printer,
|
||||||
PrintRange(dialog.printRange(),dialog.fromPage(),dialog.toPage())
|
PrintRange(dialog.printRange(),dialog.fromPage(),dialog.toPage())
|
||||||
);
|
);
|
||||||
|
foreach(PageItemDesignIntf::Ptr pageItem, d_ptr->m_reportPages){
|
||||||
|
d_ptr->m_previewPage->reactivatePageItem(pageItem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewReportWidget::slotPrintToPDF()
|
void PreviewReportWidget::printToPDF()
|
||||||
{
|
{
|
||||||
QString fileName = QFileDialog::getSaveFileName(this,tr("PDF file name"),"","PDF(*.pdf)" );
|
QString fileName = QFileDialog::getSaveFileName(this,tr("PDF file name"),"","PDF(*.pdf)" );
|
||||||
if (!fileName.isEmpty()){
|
if (!fileName.isEmpty()){
|
||||||
@ -170,7 +185,7 @@ void PreviewReportWidget::slotPrintToPDF()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewReportWidget::slotPageNavigatorChanged(int value)
|
void PreviewReportWidget::pageNavigatorChanged(int value)
|
||||||
{
|
{
|
||||||
if (d_ptr->m_changingPage) return;
|
if (d_ptr->m_changingPage) return;
|
||||||
d_ptr->m_changingPage = true;
|
d_ptr->m_changingPage = true;
|
||||||
@ -181,7 +196,7 @@ void PreviewReportWidget::slotPageNavigatorChanged(int value)
|
|||||||
d_ptr->m_changingPage=false;
|
d_ptr->m_changingPage=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewReportWidget::slotSaveToFile()
|
void PreviewReportWidget::saveToFile()
|
||||||
{
|
{
|
||||||
QString fileName = QFileDialog::getSaveFileName(this,tr("Report file name"));
|
QString fileName = QFileDialog::getSaveFileName(this,tr("Report file name"));
|
||||||
if (!fileName.isEmpty()){
|
if (!fileName.isEmpty()){
|
||||||
@ -193,6 +208,31 @@ void PreviewReportWidget::slotSaveToFile()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PreviewReportWidget::setScalePercent(int percent)
|
||||||
|
{
|
||||||
|
ui->graphicsView->resetMatrix();
|
||||||
|
qreal scaleSize = percent/100.0;
|
||||||
|
ui->graphicsView->scale(scaleSize, scaleSize);
|
||||||
|
emit scalePercentChanged(percent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PreviewReportWidget::fitWidth()
|
||||||
|
{
|
||||||
|
if (d_ptr->currentPage()){
|
||||||
|
qreal scalePercent = ui->graphicsView->viewport()->width() / ui->graphicsView->scene()->width();
|
||||||
|
setScalePercent(scalePercent*100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PreviewReportWidget::fitPage()
|
||||||
|
{
|
||||||
|
if (d_ptr->currentPage()){
|
||||||
|
qreal vScale = ui->graphicsView->viewport()->width() / ui->graphicsView->scene()->width();
|
||||||
|
qreal hScale = ui->graphicsView->viewport()->height() / d_ptr->currentPage()->height();
|
||||||
|
setScalePercent(qMin(vScale,hScale)*100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PreviewReportWidget::setErrorMessages(const QStringList &value)
|
void PreviewReportWidget::setErrorMessages(const QStringList &value)
|
||||||
{
|
{
|
||||||
foreach (QString line, value) {
|
foreach (QString line, value) {
|
||||||
@ -200,6 +240,11 @@ void PreviewReportWidget::setErrorMessages(const QStringList &value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PreviewReportWidget::emitPageSet()
|
||||||
|
{
|
||||||
|
emit pagesSet(d_ptr->m_reportPages.count());
|
||||||
|
}
|
||||||
|
|
||||||
void PreviewReportWidget::refreshPages()
|
void PreviewReportWidget::refreshPages()
|
||||||
{
|
{
|
||||||
if (d_ptr->m_report){
|
if (d_ptr->m_report){
|
||||||
@ -209,14 +254,6 @@ void PreviewReportWidget::refreshPages()
|
|||||||
d_ptr->m_report->dataManager()->setDesignTime(true);
|
d_ptr->m_report->dataManager()->setDesignTime(true);
|
||||||
if (pages.count()>0){
|
if (pages.count()>0){
|
||||||
d_ptr->setPages(pages);
|
d_ptr->setPages(pages);
|
||||||
if (!d_ptr->m_reportPages.isEmpty()){
|
|
||||||
d_ptr->m_previewPage->setPageItems(d_ptr->m_reportPages);
|
|
||||||
d_ptr->m_changingPage = true;
|
|
||||||
d_ptr->m_currentPage = 1;
|
|
||||||
if (pages.at(0)) pages.at(0)->setSelected(true);
|
|
||||||
d_ptr->m_changingPage = false;
|
|
||||||
}
|
|
||||||
ui->graphicsView->centerOn(0, 0);
|
|
||||||
}
|
}
|
||||||
} catch (ReportError &exception){
|
} catch (ReportError &exception){
|
||||||
d_ptr->m_report->saveError(exception.what());
|
d_ptr->m_report->saveError(exception.what());
|
||||||
|
@ -24,20 +24,25 @@ public:
|
|||||||
~PreviewReportWidget();
|
~PreviewReportWidget();
|
||||||
public slots:
|
public slots:
|
||||||
void refreshPages();
|
void refreshPages();
|
||||||
void slotZoomIn();
|
void zoomIn();
|
||||||
void slotZoomOut();
|
void zoomOut();
|
||||||
|
|
||||||
void slotFirstPage();
|
void firstPage();
|
||||||
void slotPriorPage();
|
void priorPage();
|
||||||
void slotNextPage();
|
void nextPage();
|
||||||
void slotLastPage();
|
void lastPage();
|
||||||
|
|
||||||
void slotPrint();
|
void print();
|
||||||
void slotPrintToPDF();
|
void printToPDF();
|
||||||
void slotPageNavigatorChanged(int value);
|
void pageNavigatorChanged(int value);
|
||||||
void slotSaveToFile();
|
void saveToFile();
|
||||||
|
void setScalePercent(int percent);
|
||||||
|
void fitWidth();
|
||||||
|
void fitPage();
|
||||||
signals:
|
signals:
|
||||||
void pageChanged(int page);
|
void pageChanged(int page);
|
||||||
|
void scalePercentChanged(int percent);
|
||||||
|
void pagesSet(int pageCount);
|
||||||
private slots:
|
private slots:
|
||||||
void slotSliderMoved(int value);
|
void slotSliderMoved(int value);
|
||||||
void reportEngineDestroyed(QObject* object);
|
void reportEngineDestroyed(QObject* object);
|
||||||
@ -45,6 +50,7 @@ private:
|
|||||||
void initPreview();
|
void initPreview();
|
||||||
void setErrorsMesagesVisible(bool visible);
|
void setErrorsMesagesVisible(bool visible);
|
||||||
void setErrorMessages(const QStringList &value);
|
void setErrorMessages(const QStringList &value);
|
||||||
|
void emitPageSet();
|
||||||
private:
|
private:
|
||||||
Ui::PreviewReportWidget *ui;
|
Ui::PreviewReportWidget *ui;
|
||||||
PreviewReportWidgetPrivate* d_ptr;
|
PreviewReportWidgetPrivate* d_ptr;
|
||||||
|
@ -12,11 +12,13 @@ class PreviewReportWidget;
|
|||||||
class PreviewReportWidgetPrivate
|
class PreviewReportWidgetPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PreviewReportWidgetPrivate(PreviewReportWidget* previewReportWidget): q_ptr(previewReportWidget),
|
PreviewReportWidgetPrivate(PreviewReportWidget* previewReportWidget):
|
||||||
m_currentPage(1), m_changingPage(false), m_priorScrolValue(0){}
|
m_currentPage(1), m_changingPage(false), m_priorScrolValue(0), m_scalePercent(50),
|
||||||
|
q_ptr(previewReportWidget) {}
|
||||||
bool pageIsVisible();
|
bool pageIsVisible();
|
||||||
QRectF calcPageShift();
|
QRectF calcPageShift();
|
||||||
void setPages( ReportPages pages);
|
void setPages( ReportPages pages);
|
||||||
|
PageItemDesignIntf::Ptr currentPage();
|
||||||
public:
|
public:
|
||||||
PageDesignIntf* m_previewPage;
|
PageDesignIntf* m_previewPage;
|
||||||
ReportPages m_reportPages;
|
ReportPages m_reportPages;
|
||||||
@ -25,6 +27,7 @@ public:
|
|||||||
int m_currentPage;
|
int m_currentPage;
|
||||||
bool m_changingPage;
|
bool m_changingPage;
|
||||||
int m_priorScrolValue;
|
int m_priorScrolValue;
|
||||||
|
int m_scalePercent;
|
||||||
PreviewReportWidget* q_ptr;
|
PreviewReportWidget* q_ptr;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -203,32 +203,32 @@ void PreviewReportWindow::moveEvent(QMoveEvent* e)
|
|||||||
|
|
||||||
void PreviewReportWindow::slotPrint()
|
void PreviewReportWindow::slotPrint()
|
||||||
{
|
{
|
||||||
m_previewReportWidget->slotPrint();
|
m_previewReportWidget->print();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewReportWindow::slotPriorPage()
|
void PreviewReportWindow::slotPriorPage()
|
||||||
{
|
{
|
||||||
m_previewReportWidget->slotPriorPage();
|
m_previewReportWidget->priorPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewReportWindow::slotNextPage()
|
void PreviewReportWindow::slotNextPage()
|
||||||
{
|
{
|
||||||
m_previewReportWidget->slotNextPage();
|
m_previewReportWidget->nextPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewReportWindow::slotZoomIn()
|
void PreviewReportWindow::slotZoomIn()
|
||||||
{
|
{
|
||||||
m_previewReportWidget->slotZoomIn();
|
m_previewReportWidget->zoomIn();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewReportWindow::slotZoomOut()
|
void PreviewReportWindow::slotZoomOut()
|
||||||
{
|
{
|
||||||
m_previewReportWidget->slotZoomOut();
|
m_previewReportWidget->zoomOut();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewReportWindow::slotPageNavigatorChanged(int value)
|
void PreviewReportWindow::slotPageNavigatorChanged(int value)
|
||||||
{
|
{
|
||||||
m_previewReportWidget->slotPageNavigatorChanged(value);
|
m_previewReportWidget->pageNavigatorChanged(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewReportWindow::slotShowErrors()
|
void PreviewReportWindow::slotShowErrors()
|
||||||
@ -243,22 +243,22 @@ ItemsReaderIntf *PreviewReportWindow::reader()
|
|||||||
|
|
||||||
void PreviewReportWindow::on_actionSaveToFile_triggered()
|
void PreviewReportWindow::on_actionSaveToFile_triggered()
|
||||||
{
|
{
|
||||||
m_previewReportWidget->slotSaveToFile();
|
m_previewReportWidget->saveToFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewReportWindow::slotFirstPage()
|
void PreviewReportWindow::slotFirstPage()
|
||||||
{
|
{
|
||||||
m_previewReportWidget->slotFirstPage();
|
m_previewReportWidget->firstPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewReportWindow::slotLastPage()
|
void PreviewReportWindow::slotLastPage()
|
||||||
{
|
{
|
||||||
m_previewReportWidget->slotLastPage();
|
m_previewReportWidget->lastPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewReportWindow::slotPrintToPDF()
|
void PreviewReportWindow::slotPrintToPDF()
|
||||||
{
|
{
|
||||||
m_previewReportWidget->slotPrintToPDF();
|
m_previewReportWidget->printToPDF();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewReportWindow::slotPageChanged(int pageIndex)
|
void PreviewReportWindow::slotPageChanged(int pageIndex)
|
||||||
|
Loading…
Reference in New Issue
Block a user