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

PreviewReportWindow now uses PreviewReportWidget to show render result

This commit is contained in:
Arin Alexander 2016-03-31 00:19:05 +04:00
parent 9c57bb772f
commit a7192c350c
3 changed files with 41 additions and 228 deletions

View File

@ -32,6 +32,8 @@
#include "serializators/lrxmlreader.h"
#include "serializators/lrxmlwriter.h"
#include "lrreportengine_p.h"
#include "lrpreviewreportwidget.h"
#include "lrpreviewreportwidget_p.h"
#include <QPrinter>
#include <QPrintDialog>
@ -43,24 +45,22 @@ namespace LimeReport{
PreviewReportWindow::PreviewReportWindow(ReportEnginePrivate *report,QWidget *parent, QSettings *settings, Qt::WindowFlags flags) :
QMainWindow(parent,flags),
ui(new Ui::PreviewReportWindow), m_currentPage(1), m_changingPage(false), m_settings(settings), m_ownedSettings(false),
m_priorScrolValue(0)
ui(new Ui::PreviewReportWindow), m_settings(settings), m_ownedSettings(false)
{
ui->setupUi(this);
setWindowTitle("Lime Report Preview");
m_previewPage = report->createPreviewPage();
m_previewPage->setItemMode( LimeReport::PreviewMode );
m_pagesNavigator = new QSpinBox(this);
m_pagesNavigator->setMaximum(10000000);
m_pagesNavigator->setPrefix(tr("Page: "));
m_pagesNavigator->setMinimumWidth(120);
ui->toolBar->insertWidget(ui->actionNextPage,m_pagesNavigator);
m_simpleScene = new QGraphicsScene(this);
ui->actionShowMessages->setVisible(false);
ui->errorsView->setVisible(false);
connect(m_pagesNavigator,SIGNAL(valueChanged(int)),this,SLOT(slotPageNavigatorChanged(int)));
connect(ui->graphicsView->verticalScrollBar(),SIGNAL(valueChanged(int)), this, SLOT(slotSliderMoved(int)));
connect(ui->actionShowMessages, SIGNAL(triggered()), this, SLOT(slotShowErrors()));
m_previewReportWidget = new PreviewReportWidget(report,this);
setCentralWidget(m_previewReportWidget);
layout()->setContentsMargins(1,1,1,1);
connect(m_previewReportWidget,SIGNAL(pageChanged(int)), this,SLOT(slotPageChanged(int)) );
restoreSetting();
}
@ -102,7 +102,7 @@ PreviewReportWindow::~PreviewReportWindow()
{
if (m_ownedSettings)
delete m_settings;
delete m_previewPage;
//delete m_previewPage;
delete ui;
}
@ -111,11 +111,7 @@ void PreviewReportWindow::initPreview(int pagesCount)
m_pagesNavigator->setSuffix(tr(" of %1").arg(pagesCount));
m_pagesNavigator->setMinimum(1);
m_pagesNavigator->setMaximum(pagesCount);
ui->graphicsView->setScene(m_previewPage);
ui->graphicsView->centerOn(0, 0);
ui->graphicsView->scale(0.5,0.5);
m_currentPage=1;
m_pagesNavigator->setValue(m_currentPage);
m_pagesNavigator->setValue(1);
}
void PreviewReportWindow::setSettings(QSettings* value)
@ -129,9 +125,7 @@ void PreviewReportWindow::setSettings(QSettings* value)
void PreviewReportWindow::setErrorMessages(const QStringList &value){
ui->actionShowMessages->setVisible(true);
foreach (QString line, value) {
ui->errorsView->append(line);
}
m_previewReportWidget->setErrorMessages(value);
}
QSettings*PreviewReportWindow::settings()
@ -147,26 +141,20 @@ QSettings*PreviewReportWindow::settings()
void PreviewReportWindow::setReportReader(ItemsReaderIntf::Ptr reader)
{
m_reader=reader;
if (!reader.isNull()){
if (reader->first()) reader->readItem(m_previewPage->pageItem());
int pagesCount = reader->firstLevelItemsCount();
m_previewPage->pageItem()->setItemMode(PreviewMode);
initPreview(pagesCount);
}
// m_reader=reader;
// if (!reader.isNull()){
// if (reader->first()) reader->readItem(m_previewPage->pageItem());
// int pagesCount = reader->firstLevelItemsCount();
// m_previewPage->pageItem()->setItemMode(PreviewMode);
// initPreview(pagesCount);
// }
}
void PreviewReportWindow::setPages(ReportPages pages)
{
m_reportPages = pages;
if (!m_reportPages.isEmpty()){
//m_previewPage->setPageItem(m_reportPages.at(0));
m_previewPage->setPageItems(m_reportPages);
m_changingPage = true;
initPreview(m_reportPages.count());
m_currentPage = 1;
if (pages.at(0)) pages.at(0)->setSelected(true);
m_changingPage = false;
m_previewReportWidget->d_ptr->setPages(pages);
if (!pages.isEmpty()){
initPreview(pages.count());
}
}
@ -215,104 +203,37 @@ void PreviewReportWindow::moveEvent(QMoveEvent* e)
void PreviewReportWindow::slotPrint()
{
QPrinter printer(QPrinter::HighResolution);
QPrintDialog dialog(&printer,QApplication::activeWindow());
if (dialog.exec()==QDialog::Accepted){
if (!m_reportPages.isEmpty())
ReportEnginePrivate::printReport(
m_reportPages,
printer,
PrintRange(dialog.printRange(),dialog.fromPage(),dialog.toPage())
);
else ReportEnginePrivate::printReport(m_reader,printer);
foreach(PageItemDesignIntf::Ptr pageItem, m_reportPages){
m_previewPage->reactivatePageItem(pageItem);
}
}
m_previewReportWidget->slotPrint();
}
void PreviewReportWindow::slotPriorPage()
{
m_changingPage=true;
if ((!m_reportPages.isEmpty())&&(m_currentPage>1)){
m_currentPage--;
//m_previewPage->setPageItem(m_reportPages.at(m_currentPage-1));
ui->graphicsView->ensureVisible(
calcPageShift(m_reportPages.at(m_currentPage-1)), 0, 0
);
m_pagesNavigator->setValue(m_currentPage);
} else {
if (reader() && reader()->prior()){
m_previewPage->removeAllItems();
reader()->readItem(m_previewPage->pageItem());
m_currentPage--;
m_pagesNavigator->setValue(m_currentPage);
}
}
m_changingPage=false;
m_previewReportWidget->slotPriorPage();
}
void PreviewReportWindow::slotNextPage()
{
m_changingPage=true;
if ((!m_reportPages.isEmpty())&&(m_reportPages.count()>(m_currentPage))){
m_currentPage++;
//m_previewPage->setPageItem(m_reportPages.at(m_currentPage-1));
ui->graphicsView->ensureVisible(
calcPageShift(m_reportPages.at(m_currentPage-1)), 0, 0
);
m_pagesNavigator->setValue(m_currentPage);
} else {
if (reader() && reader()->next()){
m_previewPage->removeAllItems();
reader()->readItem(m_previewPage->pageItem());
m_currentPage++;
m_pagesNavigator->setValue(m_currentPage);
}
}
m_changingPage=false;
m_previewReportWidget->slotNextPage();
}
void PreviewReportWindow::slotZoomIn()
{
ui->graphicsView->scale(1.2,1.2);
m_previewReportWidget->slotZoomIn();
}
void PreviewReportWindow::slotZoomOut()
{
ui->graphicsView->scale(1/1.2,1/1.2);
m_previewReportWidget->slotZoomOut();
}
void PreviewReportWindow::slotPageNavigatorChanged(int value)
{
if (m_changingPage) return;
m_changingPage = true;
if ((!m_reportPages.isEmpty())&&(m_reportPages.count() >= value)){
m_currentPage = value;
//m_previewPage->setPageItem(m_reportPages.at(m_currentPage-1));
ui->graphicsView->ensureVisible(
calcPageShift(m_reportPages.at(m_currentPage-1)), 0, 0
);
} else {
if (reader()){
int direction = (m_currentPage>value)?-1:1;
while (m_currentPage != value){
if (direction == 1) reader()->next();
else reader()->prior();
m_currentPage += direction;
}
m_previewPage->removeAllItems();
reader()->readItem(m_previewPage->pageItem());
m_pagesNavigator->setValue(m_currentPage);
}
}
m_changingPage=false;
m_previewReportWidget->slotPageNavigatorChanged(value);
}
void PreviewReportWindow::slotShowErrors()
{
ui->errorsView->setVisible(ui->actionShowMessages->isChecked());
m_previewReportWidget->setErrorsMesagesVisible(ui->actionShowMessages->isChecked());
}
ItemsReaderIntf *PreviewReportWindow::reader()
@ -320,127 +241,29 @@ ItemsReaderIntf *PreviewReportWindow::reader()
return m_reader.data();
}
bool PreviewReportWindow::pageIsVisible(PageItemDesignIntf::Ptr page)
{
return page->mapToScene(page->rect()).boundingRect().intersects(
ui->graphicsView->mapToScene(ui->graphicsView->viewport()->geometry()).boundingRect()
);
}
QRectF PreviewReportWindow::calcPageShift(PageItemDesignIntf::Ptr page)
{
qreal pageHeight = page->mapToScene(page->boundingRect()).boundingRect().height();
qreal viewHeight = ui->graphicsView->mapToScene(
0,ui->graphicsView->viewport()->height()
).y()-ui->graphicsView->mapToScene(0,0).y();
viewHeight = (pageHeight<viewHeight)?pageHeight:viewHeight;
QRectF pageStartPos = m_reportPages.at(m_currentPage-1)->mapRectToScene(
m_reportPages.at(m_currentPage-1)->rect()
);
return QRectF(0,pageStartPos.y(),0,viewHeight);
}
void PreviewReportWindow::on_actionSaveToFile_triggered()
{
QString fileName = QFileDialog::getSaveFileName(this,tr("Report file name"));
if (!fileName.isEmpty()){
QScopedPointer< ItemsWriterIntf > writer(new XMLWriter());
foreach (PageItemDesignIntf::Ptr page, m_reportPages){
writer->putItem(page.data());
}
writer->saveToFile(fileName);
}
m_previewReportWidget->slotSaveToFile();
}
void PreviewReportWindow::slotFirstPage()
{
m_changingPage=true;
if ((!m_reportPages.isEmpty())&&(m_currentPage>1)){
m_currentPage=1;
//m_previewPage->setPageItem(m_reportPages.at(m_currentPage-1));
ui->graphicsView->ensureVisible(
calcPageShift(m_reportPages.at(m_currentPage-1)), 0, 0
);
m_pagesNavigator->setValue(m_currentPage);
} else {
if (reader() && reader()->prior()){
while (reader()->prior()) {
}
m_previewPage->removeAllItems();
reader()->readItem(m_previewPage->pageItem());
m_currentPage=1;
m_pagesNavigator->setValue(m_currentPage);
}
}
m_changingPage=false;
m_previewReportWidget->slotFirstPage();
}
void PreviewReportWindow::slotLastPage()
{
m_changingPage=true;
if ((!m_reportPages.isEmpty())&&(m_reportPages.count()>(m_currentPage))){
m_currentPage=m_reportPages.count();
//m_previewPage->setPageItem(m_reportPages.at(m_currentPage-1));
ui->graphicsView->ensureVisible(
calcPageShift(m_reportPages.at(m_currentPage-1)), 0, 0
);
m_pagesNavigator->setValue(m_currentPage);
} else {
if (reader() && reader()->next()){
m_currentPage++;
while (reader()->next()) {
m_currentPage++;
}
m_previewPage->removeAllItems();
reader()->readItem(m_previewPage->pageItem());
m_pagesNavigator->setValue(m_currentPage);
}
}
m_changingPage=false;
m_previewReportWidget->slotLastPage();
}
void PreviewReportWindow::slotPrintToPDF()
{
QString fileName = QFileDialog::getSaveFileName(this,tr("PDF file name"),"","PDF(*.pdf)" );
qDebug()<<fileName;
if (!fileName.isEmpty()){
QPrinter printer;
printer.setOutputFileName(fileName);
printer.setOutputFormat(QPrinter::PdfFormat);
if (!m_reportPages.isEmpty()){
ReportEnginePrivate::printReport(m_reportPages,printer,PrintRange());
} else {
ReportEnginePrivate::printReport(m_reader,printer);
}
foreach(PageItemDesignIntf::Ptr pageItem, m_reportPages){
m_previewPage->reactivatePageItem(pageItem);
}
}
m_previewReportWidget->slotPrintToPDF();
}
void PreviewReportWindow::slotSliderMoved(int value)
void PreviewReportWindow::slotPageChanged(int pageIndex)
{
if (ui->graphicsView->verticalScrollBar()->minimum()==value){
m_currentPage = 1;
} else if (ui->graphicsView->verticalScrollBar()->maximum()==value){
m_currentPage = m_reportPages.count();
}
if (!pageIsVisible(m_reportPages.at(m_currentPage-1))){
if (value>m_priorScrolValue){
m_currentPage++;
} else {
m_currentPage--;
}
}
m_changingPage = true;
m_pagesNavigator->setValue(m_currentPage);
m_changingPage = false;
m_priorScrolValue = value;
m_pagesNavigator->setValue(pageIndex);
}
}// namespace LimeReport

View File

@ -38,6 +38,7 @@
#include "lrreportrender.h"
#include "serializators/lrstorageintf.h"
#include "serializators/lrxmlreader.h"
#include "lrpreviewreportwidget.h"
namespace LimeReport {
@ -76,25 +77,20 @@ public slots:
void slotFirstPage();
void slotLastPage();
void slotPrintToPDF();
private slots:
void slotSliderMoved(int value);
void slotPageChanged(int pageIndex);
private:
ItemsReaderIntf* reader();
bool pageIsVisible(PageItemDesignIntf::Ptr page);
QRectF calcPageShift(PageItemDesignIntf::Ptr page);
//bool pageIsVisible(PageItemDesignIntf::Ptr page);
//QRectF calcPageShift(PageItemDesignIntf::Ptr page);
private:
Ui::PreviewReportWindow *ui;
QSpinBox* m_pagesNavigator;
QSharedPointer<ItemsReaderIntf> m_reader;
int m_currentPage;
PageDesignIntf* m_previewPage;
QGraphicsScene* m_simpleScene;
ReportPages m_reportPages;
QEventLoop m_eventLoop;
bool m_changingPage;
QSettings* m_settings;
bool m_ownedSettings;
int m_priorScrolValue;
PreviewReportWidget* m_previewReportWidget;
};
} //namespace LimeReport
#endif // LRPREVIEWREPORTWINDOW_H

View File

@ -27,12 +27,6 @@
<property name="bottomMargin">
<number>1</number>
</property>
<item>
<widget class="QGraphicsView" name="graphicsView"/>
</item>
<item>
<widget class="QTextEdit" name="errorsView"/>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">
@ -41,7 +35,7 @@
<x>0</x>
<y>0</y>
<width>800</width>
<height>20</height>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="menuView">
@ -232,8 +226,8 @@
</action>
</widget>
<resources>
<include location="report.qrc"/>
<include location="databrowser/lrdatabrowser.qrc"/>
<include location="report.qrc"/>
</resources>
<connections>
<connection>