From c3cc76ca8bc612ca8409b0728b173e00c908c4f5 Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Fri, 16 Sep 2016 02:59:56 +0400 Subject: [PATCH] Pagination has been fixed --- limereport/lrpageitemdesignintf.cpp | 23 ++++++-- limereport/lrpageitemdesignintf.h | 5 ++ limereport/lrreportdesignwindow.cpp | 31 ++++++++++- limereport/lrreportdesignwindow.h | 3 +- limereport/lrreportengine.cpp | 4 +- limereport/lrreportrender.cpp | 81 ++++++++++++++++------------- limereport/lrreportrender.h | 6 ++- 7 files changed, 108 insertions(+), 45 deletions(-) diff --git a/limereport/lrpageitemdesignintf.cpp b/limereport/lrpageitemdesignintf.cpp index e009d5e..5ea814c 100644 --- a/limereport/lrpageitemdesignintf.cpp +++ b/limereport/lrpageitemdesignintf.cpp @@ -48,10 +48,10 @@ PageItemDesignIntf::PageItemDesignIntf(QObject *owner, QGraphicsItem *parent) : BaseDesignIntf("PageItem",owner,parent), m_topMargin(0), m_bottomMargin(0), m_leftMargin(0), m_rightMargin(0), 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); - setPosibleResizeDirectionFlags(Fixed); + setPossibleResizeDirectionFlags(Fixed); initPageSize(m_pageSize); } @@ -59,10 +59,10 @@ PageItemDesignIntf::PageItemDesignIntf(const PageSize pageSize, const QRectF &re BaseDesignIntf("PageItem",owner,parent), m_topMargin(0), m_bottomMargin(0), m_leftMargin(0), m_rightMargin(0), 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); - setPosibleResizeDirectionFlags(Fixed); + setPossibleResizeDirectionFlags(Fixed); initPageSize(rect.size()); } @@ -300,6 +300,21 @@ void PageItemDesignIntf::initColumnsPos(QVector &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 { return m_oldPrintMode; diff --git a/limereport/lrpageitemdesignintf.h b/limereport/lrpageitemdesignintf.h index ba01820..635655f 100644 --- a/limereport/lrpageitemdesignintf.h +++ b/limereport/lrpageitemdesignintf.h @@ -51,6 +51,7 @@ class PageItemDesignIntf : public LimeReport::BaseDesignIntf Q_PROPERTY(int gridStep READ gridStep WRITE setGridStep) Q_PROPERTY(bool fullPage READ fullPage WRITE setFullPage) Q_PROPERTY(bool oldPrintMode READ oldPrintMode WRITE setOldPrintMode) + Q_PROPERTY(bool resetPageNumber READ resetPageNumber WRITE setResetPageNumber) friend class ReportRender; public: enum Orientation { Portrait, Landscape }; @@ -112,6 +113,9 @@ public: bool oldPrintMode() const; void setOldPrintMode(bool oldPrintMode); bool canContainChildren(){ return true;} + bool resetPageNumber() const; + void setResetPageNumber(bool resetPageNumber); + protected slots: void bandDeleted(QObject* band); void bandGeometryChanged(QObject* object, QRectF newGeometry, QRectF oldGeometry); @@ -138,6 +142,7 @@ private: QList m_bands; bool m_fullPage; bool m_oldPrintMode; + bool m_resetPageNumber; }; typedef QList ReportPages; diff --git a/limereport/lrreportdesignwindow.cpp b/limereport/lrreportdesignwindow.cpp index b7a6d0b..dbe6f8d 100644 --- a/limereport/lrreportdesignwindow.cpp +++ b/limereport/lrreportdesignwindow.cpp @@ -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() { m_propertyModel->setObject(0); updateRedoUndo(); + updateAvaibleBands(); } 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); } diff --git a/limereport/lrreportdesignwindow.h b/limereport/lrreportdesignwindow.h index 474d212..5819a1c 100644 --- a/limereport/lrreportdesignwindow.h +++ b/limereport/lrreportdesignwindow.h @@ -117,7 +117,7 @@ private slots: void slotUseGrid(bool value); void slotUseMagnet(bool value); void slotLoadRecentFile(const QString fileName); - void slotPageAdded(PageDesignIntf* page); + void slotPageAdded(PageDesignIntf* ); void slotPageDeleted(); protected: void closeEvent(QCloseEvent *event); @@ -138,6 +138,7 @@ private: void createDataWindow(); void createScriptWindow(); void updateRedoUndo(); + void updateAvaibleBands(); void startNewReport(); void writePosition(); void writeState(); diff --git a/limereport/lrreportengine.cpp b/limereport/lrreportengine.cpp index 315b4a9..7ff4095 100644 --- a/limereport/lrreportengine.cpp +++ b/limereport/lrreportengine.cpp @@ -671,7 +671,9 @@ ReportPages ReportEnginePrivate::renderToPages() foreach(PageDesignIntf* page , m_pages){ m_pages.at(0)->setReportSettings(&m_reportSettings); result.append(m_reportRender->renderPageToPages(page)); - } + } + + m_reportRender->secondRenderPass(result); emit renderFinished(); m_reportRender.clear(); return result; diff --git a/limereport/lrreportrender.cpp b/limereport/lrreportrender.cpp index 9813b15..d902427 100644 --- a/limereport/lrreportrender.cpp +++ b/limereport/lrreportrender.cpp @@ -156,6 +156,8 @@ ReportRender::ReportRender(QObject *parent) void ReportRender::setDatasources(DataSourceManager *value) { m_datasources=value; + initVariables(); + resetPageNumber(BandReset); } void ReportRender::setScriptContext(ScriptEngineContext* scriptContext) @@ -175,7 +177,7 @@ void ReportRender::initDatasources(){ try{ datasources()->setAllDatasourcesToFirst(); } catch(ReportError &exception){ - //TODO posible should thow exeption + //TODO possible should thow exeption QMessageBox::critical(0,tr("Error"),exception.what()); return; } @@ -185,14 +187,16 @@ void ReportRender::renderPage(PageDesignIntf* patternPage) { m_curentNameIndex = 0; m_patternPageItem = patternPage->pageItem(); - m_pageCount = 1; + if (m_patternPageItem->resetPageNumber() && m_pageCount>0) { + resetPageNumber(PageReset); + + } + //m_pageCount = 1; m_renderCanceled = false; BandDesignIntf* reportFooter = m_patternPageItem->bandByType(BandDesignIntf::ReportFooter); m_reportFooterHeight = 0; if (reportFooter) m_reportFooterHeight = reportFooter->height(); - - initVariables(); initGroupFunctions(); #ifdef HAVE_UI_LOADER initDialogs(); @@ -204,33 +208,32 @@ void ReportRender::renderPage(PageDesignIntf* patternPage) try{ datasources()->setAllDatasourcesToFirst(); } catch(ReportError &exception){ - //TODO posible should thow exeption + //TODO possible should thow exeption QMessageBox::critical(0,tr("Error"),exception.what()); return; } - clearPageMap(); - resetPageNumber(); - startNewPage(); + clearPageMap(); - renderBand(m_patternPageItem->bandByType(BandDesignIntf::ReportHeader),StartNewPageAsNeeded); + startNewPage(); - BandDesignIntf* lastRenderedBand = 0; - for (int i=0;idataBandCount() && !m_renderCanceled;i++){ - lastRenderedBand = m_patternPageItem->dataBandAt(i); - initDatasources(); - renderDataBand(lastRenderedBand); - if (idataBandCount()-1) closeFooterGroup(lastRenderedBand); - } + renderBand(m_patternPageItem->bandByType(BandDesignIntf::ReportHeader),StartNewPageAsNeeded); - if (reportFooter) - renderBand(reportFooter,StartNewPageAsNeeded); - if (lastRenderedBand && lastRenderedBand->keepFooterTogether()) - closeFooterGroup(lastRenderedBand); + BandDesignIntf* lastRenderedBand = 0; + for (int i=0;idataBandCount() && !m_renderCanceled;i++){ + lastRenderedBand = m_patternPageItem->dataBandAt(i); + initDatasources(); + renderDataBand(lastRenderedBand); + if (idataBandCount()-1) closeFooterGroup(lastRenderedBand); + } + + if (reportFooter) + renderBand(reportFooter,StartNewPageAsNeeded); + if (lastRenderedBand && lastRenderedBand->keepFooterTogether()) + closeFooterGroup(lastRenderedBand); + + savePage(); - savePage(); - if (!m_renderCanceled) - secondRenderPass(); } } @@ -599,7 +602,7 @@ void ReportRender::renderGroupHeader(BandDesignIntf *parentBand, IDataSource* da gb->startGroup(m_datasources); openDataGroup(band); if (!firstTime && gb->startNewPage()){ - if (gb->resetPageNumber()) resetPageNumber(); + if (gb->resetPageNumber()) resetPageNumber(BandReset); renderBand(band,ForcedStartPage); } else { 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; isetReportVariable("#PAGE_COUNT",findLastPageNumber(i)); - foreach(BandDesignIntf* band, page->childBands()){ - band->updateItemSize(m_datasources, SecondPass); + foreach(BaseDesignIntf* item, page->childBaseItems()){ + 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); } -void ReportRender::resetPageNumber() +void ReportRender::resetPageNumber(ResetPageNuberType resetType) { PagesRange range; if (!m_ranges.isEmpty()){ - m_ranges.last().lastPage = m_pageCount; - range.firstPage = m_pageCount+1; + m_ranges.last().lastPage = (resetType == BandReset)? m_pageCount : m_pageCount-1; + range.firstPage = m_pageCount+((resetType == BandReset)? 1 : 0); } else { range.firstPage = m_pageCount; } - range.lastPage = 0; + range.lastPage = (resetType == BandReset)? 0 : m_pageCount; m_ranges.append(range); + if (resetType == PageReset) + m_datasources->setReportVariable("#PAGE",1); } int ReportRender::findLastPageNumber(int currentPage) { foreach (PagesRange range, m_ranges) { - if ( range.firstPage<= (currentPage+1) && range.lastPage>= (currentPage+1) ) - return range.lastPage-(range.firstPage-1); + if ( range.firstPage<= (currentPage) && range.lastPage>= (currentPage) ) + return (range.lastPage-(range.firstPage))+1; } return 0; } @@ -1068,8 +1076,9 @@ void ReportRender::savePage() BandDesignIntf* pageFooter = m_renderPageItem->bandByType(BandDesignIntf::PageFooter); if (pageFooter) pageFooter->setBandIndex(++m_currentIndex); m_renderedPages.append(PageItemDesignIntf::Ptr(m_renderPageItem)); - emit pageRendered(m_pageCount); m_pageCount++; + emit pageRendered(m_pageCount); + } QString ReportRender::toString() diff --git a/limereport/lrreportrender.h b/limereport/lrreportrender.h index ee583a4..4f39fb5 100644 --- a/limereport/lrreportrender.h +++ b/limereport/lrreportrender.h @@ -69,6 +69,7 @@ class ReportRender: public QObject public: enum DataRenderMode {StartNewPageAsNeeded, NotStartNewPage, ForcedStartPage}; enum BandPrintMode {PrintAlwaysPrintable, PrintNotAlwaysPrintable }; + enum ResetPageNuberType{BandReset, PageReset}; typedef QSharedPointer Ptr; ~ReportRender(); ReportRender(QObject *parent = 0); @@ -79,6 +80,7 @@ public: PageItemDesignIntf::Ptr pageAt(int index); QString renderPageToString(PageDesignIntf *patternPage); ReportPages renderPageToPages(PageDesignIntf *patternPage); + void secondRenderPass(ReportPages renderedPages); signals: void pageRendered(int renderedPageCount); public slots: @@ -127,12 +129,12 @@ private: BandDesignIntf* findEnclosingGroup(); bool registerBand(BandDesignIntf* band, bool registerInChildren=true); BandDesignIntf *sliceBand(BandDesignIntf* band, BandDesignIntf *patternBand, bool isLast); - void secondRenderPass(); + BandDesignIntf* saveUppperPartReturnBottom(BandDesignIntf *band, int height, BandDesignIntf *patternBand); BandDesignIntf* renderData(BandDesignIntf* patternBand); void startNewColumn(); void startNewPage(); - void resetPageNumber(); + void resetPageNumber(ResetPageNuberType resetType); int findLastPageNumber(int currentPage); void savePage(); QString toString();