mirror of
https://github.com/fralx/LimeReport.git
synced 2024-12-24 00:33:02 +03:00
Pagination has been fixed
This commit is contained in:
parent
5832d77112
commit
c3cc76ca8b
@ -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<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
|
||||
{
|
||||
return m_oldPrintMode;
|
||||
|
@ -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<BandDesignIntf*> m_bands;
|
||||
bool m_fullPage;
|
||||
bool m_oldPrintMode;
|
||||
bool m_resetPageNumber;
|
||||
};
|
||||
|
||||
typedef QList<PageItemDesignIntf::Ptr> ReportPages;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -672,6 +672,8 @@ ReportPages ReportEnginePrivate::renderToPages()
|
||||
m_pages.at(0)->setReportSettings(&m_reportSettings);
|
||||
result.append(m_reportRender->renderPageToPages(page));
|
||||
}
|
||||
|
||||
m_reportRender->secondRenderPass(result);
|
||||
emit renderFinished();
|
||||
m_reportRender.clear();
|
||||
return result;
|
||||
|
@ -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;i<m_patternPageItem->dataBandCount() && !m_renderCanceled;i++){
|
||||
lastRenderedBand = m_patternPageItem->dataBandAt(i);
|
||||
initDatasources();
|
||||
renderDataBand(lastRenderedBand);
|
||||
if (i<m_patternPageItem->dataBandCount()-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;i<m_patternPageItem->dataBandCount() && !m_renderCanceled;i++){
|
||||
lastRenderedBand = m_patternPageItem->dataBandAt(i);
|
||||
initDatasources();
|
||||
renderDataBand(lastRenderedBand);
|
||||
if (i<m_patternPageItem->dataBandCount()-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; i<m_renderedPages.count(); ++i){
|
||||
PageItemDesignIntf::Ptr page = m_renderedPages.at(i);
|
||||
for(int i=0; i<renderedPages.count(); ++i){
|
||||
PageItemDesignIntf::Ptr page = renderedPages.at(i);
|
||||
m_datasources->setReportVariable("#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()
|
||||
|
@ -69,6 +69,7 @@ class ReportRender: public QObject
|
||||
public:
|
||||
enum DataRenderMode {StartNewPageAsNeeded, NotStartNewPage, ForcedStartPage};
|
||||
enum BandPrintMode {PrintAlwaysPrintable, PrintNotAlwaysPrintable };
|
||||
enum ResetPageNuberType{BandReset, PageReset};
|
||||
typedef QSharedPointer<ReportRender> 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();
|
||||
|
Loading…
Reference in New Issue
Block a user