0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 08:34:38 +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/lrxmlreader.h"
#include "serializators/lrxmlwriter.h" #include "serializators/lrxmlwriter.h"
#include "lrreportengine_p.h" #include "lrreportengine_p.h"
#include "lrpreviewreportwidget.h"
#include "lrpreviewreportwidget_p.h"
#include <QPrinter> #include <QPrinter>
#include <QPrintDialog> #include <QPrintDialog>
@ -43,24 +45,22 @@ namespace LimeReport{
PreviewReportWindow::PreviewReportWindow(ReportEnginePrivate *report,QWidget *parent, QSettings *settings, Qt::WindowFlags flags) : PreviewReportWindow::PreviewReportWindow(ReportEnginePrivate *report,QWidget *parent, QSettings *settings, Qt::WindowFlags flags) :
QMainWindow(parent,flags), QMainWindow(parent,flags),
ui(new Ui::PreviewReportWindow), m_currentPage(1), m_changingPage(false), m_settings(settings), m_ownedSettings(false), ui(new Ui::PreviewReportWindow), m_settings(settings), m_ownedSettings(false)
m_priorScrolValue(0)
{ {
ui->setupUi(this); ui->setupUi(this);
setWindowTitle("Lime Report Preview"); setWindowTitle("Lime Report Preview");
m_previewPage = report->createPreviewPage();
m_previewPage->setItemMode( LimeReport::PreviewMode );
m_pagesNavigator = new QSpinBox(this); m_pagesNavigator = new QSpinBox(this);
m_pagesNavigator->setMaximum(10000000); m_pagesNavigator->setMaximum(10000000);
m_pagesNavigator->setPrefix(tr("Page: ")); m_pagesNavigator->setPrefix(tr("Page: "));
m_pagesNavigator->setMinimumWidth(120); m_pagesNavigator->setMinimumWidth(120);
ui->toolBar->insertWidget(ui->actionNextPage,m_pagesNavigator); ui->toolBar->insertWidget(ui->actionNextPage,m_pagesNavigator);
m_simpleScene = new QGraphicsScene(this);
ui->actionShowMessages->setVisible(false); ui->actionShowMessages->setVisible(false);
ui->errorsView->setVisible(false);
connect(m_pagesNavigator,SIGNAL(valueChanged(int)),this,SLOT(slotPageNavigatorChanged(int))); connect(m_pagesNavigator,SIGNAL(valueChanged(int)),this,SLOT(slotPageNavigatorChanged(int)));
connect(ui->graphicsView->verticalScrollBar(),SIGNAL(valueChanged(int)), this, SLOT(slotSliderMoved(int))); m_previewReportWidget = new PreviewReportWidget(report,this);
connect(ui->actionShowMessages, SIGNAL(triggered()), this, SLOT(slotShowErrors())); setCentralWidget(m_previewReportWidget);
layout()->setContentsMargins(1,1,1,1);
connect(m_previewReportWidget,SIGNAL(pageChanged(int)), this,SLOT(slotPageChanged(int)) );
restoreSetting(); restoreSetting();
} }
@ -102,7 +102,7 @@ PreviewReportWindow::~PreviewReportWindow()
{ {
if (m_ownedSettings) if (m_ownedSettings)
delete m_settings; delete m_settings;
delete m_previewPage; //delete m_previewPage;
delete ui; delete ui;
} }
@ -111,11 +111,7 @@ void PreviewReportWindow::initPreview(int pagesCount)
m_pagesNavigator->setSuffix(tr(" of %1").arg(pagesCount)); m_pagesNavigator->setSuffix(tr(" of %1").arg(pagesCount));
m_pagesNavigator->setMinimum(1); m_pagesNavigator->setMinimum(1);
m_pagesNavigator->setMaximum(pagesCount); m_pagesNavigator->setMaximum(pagesCount);
ui->graphicsView->setScene(m_previewPage); m_pagesNavigator->setValue(1);
ui->graphicsView->centerOn(0, 0);
ui->graphicsView->scale(0.5,0.5);
m_currentPage=1;
m_pagesNavigator->setValue(m_currentPage);
} }
void PreviewReportWindow::setSettings(QSettings* value) void PreviewReportWindow::setSettings(QSettings* value)
@ -129,9 +125,7 @@ void PreviewReportWindow::setSettings(QSettings* value)
void PreviewReportWindow::setErrorMessages(const QStringList &value){ void PreviewReportWindow::setErrorMessages(const QStringList &value){
ui->actionShowMessages->setVisible(true); ui->actionShowMessages->setVisible(true);
foreach (QString line, value) { m_previewReportWidget->setErrorMessages(value);
ui->errorsView->append(line);
}
} }
QSettings*PreviewReportWindow::settings() QSettings*PreviewReportWindow::settings()
@ -147,26 +141,20 @@ QSettings*PreviewReportWindow::settings()
void PreviewReportWindow::setReportReader(ItemsReaderIntf::Ptr reader) void PreviewReportWindow::setReportReader(ItemsReaderIntf::Ptr reader)
{ {
m_reader=reader; // m_reader=reader;
if (!reader.isNull()){ // if (!reader.isNull()){
if (reader->first()) reader->readItem(m_previewPage->pageItem()); // if (reader->first()) reader->readItem(m_previewPage->pageItem());
int pagesCount = reader->firstLevelItemsCount(); // int pagesCount = reader->firstLevelItemsCount();
m_previewPage->pageItem()->setItemMode(PreviewMode); // m_previewPage->pageItem()->setItemMode(PreviewMode);
initPreview(pagesCount); // initPreview(pagesCount);
} // }
} }
void PreviewReportWindow::setPages(ReportPages pages) void PreviewReportWindow::setPages(ReportPages pages)
{ {
m_reportPages = pages; m_previewReportWidget->d_ptr->setPages(pages);
if (!m_reportPages.isEmpty()){ if (!pages.isEmpty()){
//m_previewPage->setPageItem(m_reportPages.at(0)); initPreview(pages.count());
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;
} }
} }
@ -215,104 +203,37 @@ void PreviewReportWindow::moveEvent(QMoveEvent* e)
void PreviewReportWindow::slotPrint() void PreviewReportWindow::slotPrint()
{ {
QPrinter printer(QPrinter::HighResolution); m_previewReportWidget->slotPrint();
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);
}
}
} }
void PreviewReportWindow::slotPriorPage() void PreviewReportWindow::slotPriorPage()
{ {
m_changingPage=true; m_previewReportWidget->slotPriorPage();
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;
} }
void PreviewReportWindow::slotNextPage() void PreviewReportWindow::slotNextPage()
{ {
m_changingPage=true; m_previewReportWidget->slotNextPage();
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;
} }
void PreviewReportWindow::slotZoomIn() void PreviewReportWindow::slotZoomIn()
{ {
ui->graphicsView->scale(1.2,1.2); m_previewReportWidget->slotZoomIn();
} }
void PreviewReportWindow::slotZoomOut() void PreviewReportWindow::slotZoomOut()
{ {
ui->graphicsView->scale(1/1.2,1/1.2); m_previewReportWidget->slotZoomOut();
} }
void PreviewReportWindow::slotPageNavigatorChanged(int value) void PreviewReportWindow::slotPageNavigatorChanged(int value)
{ {
if (m_changingPage) return; m_previewReportWidget->slotPageNavigatorChanged(value);
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;
} }
void PreviewReportWindow::slotShowErrors() void PreviewReportWindow::slotShowErrors()
{ {
ui->errorsView->setVisible(ui->actionShowMessages->isChecked()); m_previewReportWidget->setErrorsMesagesVisible(ui->actionShowMessages->isChecked());
} }
ItemsReaderIntf *PreviewReportWindow::reader() ItemsReaderIntf *PreviewReportWindow::reader()
@ -320,127 +241,29 @@ ItemsReaderIntf *PreviewReportWindow::reader()
return m_reader.data(); 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() void PreviewReportWindow::on_actionSaveToFile_triggered()
{ {
QString fileName = QFileDialog::getSaveFileName(this,tr("Report file name")); m_previewReportWidget->slotSaveToFile();
if (!fileName.isEmpty()){
QScopedPointer< ItemsWriterIntf > writer(new XMLWriter());
foreach (PageItemDesignIntf::Ptr page, m_reportPages){
writer->putItem(page.data());
}
writer->saveToFile(fileName);
}
} }
void PreviewReportWindow::slotFirstPage() void PreviewReportWindow::slotFirstPage()
{ {
m_changingPage=true; m_previewReportWidget->slotFirstPage();
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;
} }
void PreviewReportWindow::slotLastPage() void PreviewReportWindow::slotLastPage()
{ {
m_changingPage=true; m_previewReportWidget->slotLastPage();
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;
} }
void PreviewReportWindow::slotPrintToPDF() void PreviewReportWindow::slotPrintToPDF()
{ {
QString fileName = QFileDialog::getSaveFileName(this,tr("PDF file name"),"","PDF(*.pdf)" ); m_previewReportWidget->slotPrintToPDF();
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);
}
}
} }
void PreviewReportWindow::slotSliderMoved(int value) void PreviewReportWindow::slotPageChanged(int pageIndex)
{ {
if (ui->graphicsView->verticalScrollBar()->minimum()==value){ m_pagesNavigator->setValue(pageIndex);
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;
} }
}// namespace LimeReport }// namespace LimeReport

View File

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

View File

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