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

Pagination has been fixed

This commit is contained in:
Arin Alexander 2016-09-16 02:59:56 +04:00
parent 5832d77112
commit c3cc76ca8b
7 changed files with 108 additions and 45 deletions

View File

@ -48,10 +48,10 @@ PageItemDesignIntf::PageItemDesignIntf(QObject *owner, QGraphicsItem *parent) :
BaseDesignIntf("PageItem",owner,parent), BaseDesignIntf("PageItem",owner,parent),
m_topMargin(0), m_bottomMargin(0), m_leftMargin(0), m_rightMargin(0), m_topMargin(0), m_bottomMargin(0), m_leftMargin(0), m_rightMargin(0),
m_pageOrientaion(Portrait), m_pageSize(A4), m_sizeChainging(false), m_pageOrientaion(Portrait), m_pageSize(A4), m_sizeChainging(false),
m_fullPage(false), m_oldPrintMode(false) m_fullPage(false), m_oldPrintMode(false), m_resetPageNumber(false)
{ {
setFixedPos(true); setFixedPos(true);
setPosibleResizeDirectionFlags(Fixed); setPossibleResizeDirectionFlags(Fixed);
initPageSize(m_pageSize); initPageSize(m_pageSize);
} }
@ -59,10 +59,10 @@ PageItemDesignIntf::PageItemDesignIntf(const PageSize pageSize, const QRectF &re
BaseDesignIntf("PageItem",owner,parent), BaseDesignIntf("PageItem",owner,parent),
m_topMargin(0), m_bottomMargin(0), m_leftMargin(0), m_rightMargin(0), m_topMargin(0), m_bottomMargin(0), m_leftMargin(0), m_rightMargin(0),
m_pageOrientaion(Portrait), m_pageSize(pageSize), m_sizeChainging(false), m_pageOrientaion(Portrait), m_pageSize(pageSize), m_sizeChainging(false),
m_fullPage(false), m_oldPrintMode(false) m_fullPage(false), m_oldPrintMode(false), m_resetPageNumber(false)
{ {
setFixedPos(true); setFixedPos(true);
setPosibleResizeDirectionFlags(Fixed); setPossibleResizeDirectionFlags(Fixed);
initPageSize(rect.size()); initPageSize(rect.size());
} }
@ -300,6 +300,21 @@ void PageItemDesignIntf::initColumnsPos(QVector<qreal> &posByColumns, qreal pos,
} }
} }
bool PageItemDesignIntf::resetPageNumber() const
{
return m_resetPageNumber;
}
void PageItemDesignIntf::setResetPageNumber(bool resetPageNumber)
{
if (m_resetPageNumber!=resetPageNumber){
m_resetPageNumber = resetPageNumber;
if (!isLoading()){
notify("resetPageNumber",!m_resetPageNumber,m_resetPageNumber);
}
}
}
bool PageItemDesignIntf::oldPrintMode() const bool PageItemDesignIntf::oldPrintMode() const
{ {
return m_oldPrintMode; return m_oldPrintMode;

View File

@ -51,6 +51,7 @@ class PageItemDesignIntf : public LimeReport::BaseDesignIntf
Q_PROPERTY(int gridStep READ gridStep WRITE setGridStep) Q_PROPERTY(int gridStep READ gridStep WRITE setGridStep)
Q_PROPERTY(bool fullPage READ fullPage WRITE setFullPage) Q_PROPERTY(bool fullPage READ fullPage WRITE setFullPage)
Q_PROPERTY(bool oldPrintMode READ oldPrintMode WRITE setOldPrintMode) Q_PROPERTY(bool oldPrintMode READ oldPrintMode WRITE setOldPrintMode)
Q_PROPERTY(bool resetPageNumber READ resetPageNumber WRITE setResetPageNumber)
friend class ReportRender; friend class ReportRender;
public: public:
enum Orientation { Portrait, Landscape }; enum Orientation { Portrait, Landscape };
@ -112,6 +113,9 @@ public:
bool oldPrintMode() const; bool oldPrintMode() const;
void setOldPrintMode(bool oldPrintMode); void setOldPrintMode(bool oldPrintMode);
bool canContainChildren(){ return true;} bool canContainChildren(){ return true;}
bool resetPageNumber() const;
void setResetPageNumber(bool resetPageNumber);
protected slots: protected slots:
void bandDeleted(QObject* band); void bandDeleted(QObject* band);
void bandGeometryChanged(QObject* object, QRectF newGeometry, QRectF oldGeometry); void bandGeometryChanged(QObject* object, QRectF newGeometry, QRectF oldGeometry);
@ -138,6 +142,7 @@ private:
QList<BandDesignIntf*> m_bands; QList<BandDesignIntf*> m_bands;
bool m_fullPage; bool m_fullPage;
bool m_oldPrintMode; bool m_oldPrintMode;
bool m_resetPageNumber;
}; };
typedef QList<PageItemDesignIntf::Ptr> ReportPages; typedef QList<PageItemDesignIntf::Ptr> ReportPages;

View File

@ -1078,10 +1078,39 @@ void ReportDesignWindow::slotBandDeleted(PageDesignIntf *, BandDesignIntf *band)
} }
} }
void ReportDesignWindow::updateAvaibleBands(){
if (!m_reportDesignWidget || !m_reportDesignWidget->activePage()) return;
m_newPageHeader->setEnabled(true);
m_newPageFooter->setEnabled(true);
m_newReportHeader->setEnabled(true);
m_newReportFooter->setEnabled(true);
foreach(BandDesignIntf* band, m_reportDesignWidget->activePage()->pageItem()->bands()){
switch (band->bandType()) {
case BandDesignIntf::PageHeader:
m_newPageHeader->setEnabled(false);
break;
case BandDesignIntf::PageFooter:
m_newPageFooter->setEnabled(false);
break;
case BandDesignIntf::ReportHeader:
m_newReportHeader->setEnabled(false);
break;
case BandDesignIntf::ReportFooter:
m_newReportFooter->setEnabled(false);
default:
break;
}
}
}
void ReportDesignWindow::slotActivePageChanged() void ReportDesignWindow::slotActivePageChanged()
{ {
m_propertyModel->setObject(0); m_propertyModel->setObject(0);
updateRedoUndo(); updateRedoUndo();
updateAvaibleBands();
} }
void ReportDesignWindow::renderStarted() void ReportDesignWindow::renderStarted()
@ -1178,7 +1207,7 @@ void ReportDesignWindow::slotLoadRecentFile(const QString fileName)
} }
} }
void ReportDesignWindow::slotPageAdded(PageDesignIntf *page) void ReportDesignWindow::slotPageAdded(PageDesignIntf *)
{ {
m_deletePageAction->setEnabled(m_reportDesignWidget->report()->pageCount()>1); m_deletePageAction->setEnabled(m_reportDesignWidget->report()->pageCount()>1);
} }

View File

@ -117,7 +117,7 @@ private slots:
void slotUseGrid(bool value); void slotUseGrid(bool value);
void slotUseMagnet(bool value); void slotUseMagnet(bool value);
void slotLoadRecentFile(const QString fileName); void slotLoadRecentFile(const QString fileName);
void slotPageAdded(PageDesignIntf* page); void slotPageAdded(PageDesignIntf* );
void slotPageDeleted(); void slotPageDeleted();
protected: protected:
void closeEvent(QCloseEvent *event); void closeEvent(QCloseEvent *event);
@ -138,6 +138,7 @@ private:
void createDataWindow(); void createDataWindow();
void createScriptWindow(); void createScriptWindow();
void updateRedoUndo(); void updateRedoUndo();
void updateAvaibleBands();
void startNewReport(); void startNewReport();
void writePosition(); void writePosition();
void writeState(); void writeState();

View File

@ -672,6 +672,8 @@ ReportPages ReportEnginePrivate::renderToPages()
m_pages.at(0)->setReportSettings(&m_reportSettings); m_pages.at(0)->setReportSettings(&m_reportSettings);
result.append(m_reportRender->renderPageToPages(page)); result.append(m_reportRender->renderPageToPages(page));
} }
m_reportRender->secondRenderPass(result);
emit renderFinished(); emit renderFinished();
m_reportRender.clear(); m_reportRender.clear();
return result; return result;

View File

@ -156,6 +156,8 @@ ReportRender::ReportRender(QObject *parent)
void ReportRender::setDatasources(DataSourceManager *value) void ReportRender::setDatasources(DataSourceManager *value)
{ {
m_datasources=value; m_datasources=value;
initVariables();
resetPageNumber(BandReset);
} }
void ReportRender::setScriptContext(ScriptEngineContext* scriptContext) void ReportRender::setScriptContext(ScriptEngineContext* scriptContext)
@ -175,7 +177,7 @@ void ReportRender::initDatasources(){
try{ try{
datasources()->setAllDatasourcesToFirst(); datasources()->setAllDatasourcesToFirst();
} catch(ReportError &exception){ } catch(ReportError &exception){
//TODO posible should thow exeption //TODO possible should thow exeption
QMessageBox::critical(0,tr("Error"),exception.what()); QMessageBox::critical(0,tr("Error"),exception.what());
return; return;
} }
@ -185,14 +187,16 @@ void ReportRender::renderPage(PageDesignIntf* patternPage)
{ {
m_curentNameIndex = 0; m_curentNameIndex = 0;
m_patternPageItem = patternPage->pageItem(); m_patternPageItem = patternPage->pageItem();
m_pageCount = 1; if (m_patternPageItem->resetPageNumber() && m_pageCount>0) {
resetPageNumber(PageReset);
}
//m_pageCount = 1;
m_renderCanceled = false; m_renderCanceled = false;
BandDesignIntf* reportFooter = m_patternPageItem->bandByType(BandDesignIntf::ReportFooter); BandDesignIntf* reportFooter = m_patternPageItem->bandByType(BandDesignIntf::ReportFooter);
m_reportFooterHeight = 0; m_reportFooterHeight = 0;
if (reportFooter) if (reportFooter)
m_reportFooterHeight = reportFooter->height(); m_reportFooterHeight = reportFooter->height();
initVariables();
initGroupFunctions(); initGroupFunctions();
#ifdef HAVE_UI_LOADER #ifdef HAVE_UI_LOADER
initDialogs(); initDialogs();
@ -204,13 +208,13 @@ void ReportRender::renderPage(PageDesignIntf* patternPage)
try{ try{
datasources()->setAllDatasourcesToFirst(); datasources()->setAllDatasourcesToFirst();
} catch(ReportError &exception){ } catch(ReportError &exception){
//TODO posible should thow exeption //TODO possible should thow exeption
QMessageBox::critical(0,tr("Error"),exception.what()); QMessageBox::critical(0,tr("Error"),exception.what());
return; return;
} }
clearPageMap(); clearPageMap();
resetPageNumber();
startNewPage(); startNewPage();
renderBand(m_patternPageItem->bandByType(BandDesignIntf::ReportHeader),StartNewPageAsNeeded); renderBand(m_patternPageItem->bandByType(BandDesignIntf::ReportHeader),StartNewPageAsNeeded);
@ -229,8 +233,7 @@ void ReportRender::renderPage(PageDesignIntf* patternPage)
closeFooterGroup(lastRenderedBand); closeFooterGroup(lastRenderedBand);
savePage(); savePage();
if (!m_renderCanceled)
secondRenderPass();
} }
} }
@ -599,7 +602,7 @@ void ReportRender::renderGroupHeader(BandDesignIntf *parentBand, IDataSource* da
gb->startGroup(m_datasources); gb->startGroup(m_datasources);
openDataGroup(band); openDataGroup(band);
if (!firstTime && gb->startNewPage()){ if (!firstTime && gb->startNewPage()){
if (gb->resetPageNumber()) resetPageNumber(); if (gb->resetPageNumber()) resetPageNumber(BandReset);
renderBand(band,ForcedStartPage); renderBand(band,ForcedStartPage);
} else { } else {
renderBand(band,StartNewPageAsNeeded); renderBand(band,StartNewPageAsNeeded);
@ -849,14 +852,17 @@ BandDesignIntf* ReportRender::sliceBand(BandDesignIntf *band, BandDesignIntf* pa
} }
void ReportRender::secondRenderPass() void ReportRender::secondRenderPass(ReportPages renderedPages)
{ {
for(int i=0; i<m_renderedPages.count(); ++i){ for(int i=0; i<renderedPages.count(); ++i){
PageItemDesignIntf::Ptr page = m_renderedPages.at(i); PageItemDesignIntf::Ptr page = renderedPages.at(i);
m_datasources->setReportVariable("#PAGE_COUNT",findLastPageNumber(i)); m_datasources->setReportVariable("#PAGE_COUNT",findLastPageNumber(i));
foreach(BandDesignIntf* band, page->childBands()){ foreach(BaseDesignIntf* item, page->childBaseItems()){
band->updateItemSize(m_datasources, SecondPass); item->updateItemSize(m_datasources, SecondPass);
} }
// foreach(BandDesignIntf* band, page->childBands()){
// band->updateItemSize(m_datasources, SecondPass);
// }
} }
} }
@ -938,24 +944,26 @@ void ReportRender::startNewPage()
renderPageItems(m_patternPageItem); renderPageItems(m_patternPageItem);
} }
void ReportRender::resetPageNumber() void ReportRender::resetPageNumber(ResetPageNuberType resetType)
{ {
PagesRange range; PagesRange range;
if (!m_ranges.isEmpty()){ if (!m_ranges.isEmpty()){
m_ranges.last().lastPage = m_pageCount; m_ranges.last().lastPage = (resetType == BandReset)? m_pageCount : m_pageCount-1;
range.firstPage = m_pageCount+1; range.firstPage = m_pageCount+((resetType == BandReset)? 1 : 0);
} else { } else {
range.firstPage = m_pageCount; range.firstPage = m_pageCount;
} }
range.lastPage = 0; range.lastPage = (resetType == BandReset)? 0 : m_pageCount;
m_ranges.append(range); m_ranges.append(range);
if (resetType == PageReset)
m_datasources->setReportVariable("#PAGE",1);
} }
int ReportRender::findLastPageNumber(int currentPage) int ReportRender::findLastPageNumber(int currentPage)
{ {
foreach (PagesRange range, m_ranges) { foreach (PagesRange range, m_ranges) {
if ( range.firstPage<= (currentPage+1) && range.lastPage>= (currentPage+1) ) if ( range.firstPage<= (currentPage) && range.lastPage>= (currentPage) )
return range.lastPage-(range.firstPage-1); return (range.lastPage-(range.firstPage))+1;
} }
return 0; return 0;
} }
@ -1068,8 +1076,9 @@ void ReportRender::savePage()
BandDesignIntf* pageFooter = m_renderPageItem->bandByType(BandDesignIntf::PageFooter); BandDesignIntf* pageFooter = m_renderPageItem->bandByType(BandDesignIntf::PageFooter);
if (pageFooter) pageFooter->setBandIndex(++m_currentIndex); if (pageFooter) pageFooter->setBandIndex(++m_currentIndex);
m_renderedPages.append(PageItemDesignIntf::Ptr(m_renderPageItem)); m_renderedPages.append(PageItemDesignIntf::Ptr(m_renderPageItem));
emit pageRendered(m_pageCount);
m_pageCount++; m_pageCount++;
emit pageRendered(m_pageCount);
} }
QString ReportRender::toString() QString ReportRender::toString()

View File

@ -69,6 +69,7 @@ class ReportRender: public QObject
public: public:
enum DataRenderMode {StartNewPageAsNeeded, NotStartNewPage, ForcedStartPage}; enum DataRenderMode {StartNewPageAsNeeded, NotStartNewPage, ForcedStartPage};
enum BandPrintMode {PrintAlwaysPrintable, PrintNotAlwaysPrintable }; enum BandPrintMode {PrintAlwaysPrintable, PrintNotAlwaysPrintable };
enum ResetPageNuberType{BandReset, PageReset};
typedef QSharedPointer<ReportRender> Ptr; typedef QSharedPointer<ReportRender> Ptr;
~ReportRender(); ~ReportRender();
ReportRender(QObject *parent = 0); ReportRender(QObject *parent = 0);
@ -79,6 +80,7 @@ public:
PageItemDesignIntf::Ptr pageAt(int index); PageItemDesignIntf::Ptr pageAt(int index);
QString renderPageToString(PageDesignIntf *patternPage); QString renderPageToString(PageDesignIntf *patternPage);
ReportPages renderPageToPages(PageDesignIntf *patternPage); ReportPages renderPageToPages(PageDesignIntf *patternPage);
void secondRenderPass(ReportPages renderedPages);
signals: signals:
void pageRendered(int renderedPageCount); void pageRendered(int renderedPageCount);
public slots: public slots:
@ -127,12 +129,12 @@ private:
BandDesignIntf* findEnclosingGroup(); BandDesignIntf* findEnclosingGroup();
bool registerBand(BandDesignIntf* band, bool registerInChildren=true); bool registerBand(BandDesignIntf* band, bool registerInChildren=true);
BandDesignIntf *sliceBand(BandDesignIntf* band, BandDesignIntf *patternBand, bool isLast); BandDesignIntf *sliceBand(BandDesignIntf* band, BandDesignIntf *patternBand, bool isLast);
void secondRenderPass();
BandDesignIntf* saveUppperPartReturnBottom(BandDesignIntf *band, int height, BandDesignIntf *patternBand); BandDesignIntf* saveUppperPartReturnBottom(BandDesignIntf *band, int height, BandDesignIntf *patternBand);
BandDesignIntf* renderData(BandDesignIntf* patternBand); BandDesignIntf* renderData(BandDesignIntf* patternBand);
void startNewColumn(); void startNewColumn();
void startNewPage(); void startNewPage();
void resetPageNumber(); void resetPageNumber(ResetPageNuberType resetType);
int findLastPageNumber(int currentPage); int findLastPageNumber(int currentPage);
void savePage(); void savePage();
QString toString(); QString toString();