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

PagesRanges object has been added

This commit is contained in:
Arin Alexander 2019-01-16 03:58:54 +03:00
parent 10015ed783
commit 83fd13589e
4 changed files with 134 additions and 8 deletions

View File

@ -82,7 +82,7 @@ ReportEnginePrivate::ReportEnginePrivate(QObject *parent) :
m_reportRendering(false), m_resultIsEditable(true), m_passPhrase("HjccbzHjlbyfCkjy"), m_reportRendering(false), m_resultIsEditable(true), m_passPhrase("HjccbzHjlbyfCkjy"),
m_fileWatcher( new QFileSystemWatcher( this ) ), m_reportLanguage(QLocale::AnyLanguage), m_fileWatcher( new QFileSystemWatcher( this ) ), m_reportLanguage(QLocale::AnyLanguage),
m_previewLayoutDirection(Qt::LayoutDirectionAuto), m_designerFactory(0), m_previewLayoutDirection(Qt::LayoutDirectionAuto), m_designerFactory(0),
m_previewScaleType(FitWidth), m_previewScalePercent(0) m_previewScaleType(FitWidth), m_previewScalePercent(0), m_startTOCPage(0)
{ {
#ifdef HAVE_STATIC_BUILD #ifdef HAVE_STATIC_BUILD
initResources(); initResources();
@ -1140,6 +1140,9 @@ void ReportEnginePrivate::paintByExternalPainter(const QString& objectName, QPai
ReportPages ReportEnginePrivate::renderToPages() ReportPages ReportEnginePrivate::renderToPages()
{ {
int startTOCPage = -1;
int pageAfterTOCIndex = -1;
if (m_reportRendering) return ReportPages(); if (m_reportRendering) return ReportPages();
initReport(); initReport();
m_reportRender = ReportRender::Ptr(new ReportRender); m_reportRender = ReportRender::Ptr(new ReportRender);
@ -1176,10 +1179,15 @@ ReportPages ReportEnginePrivate::renderToPages()
activateLanguage(m_reportLanguage); activateLanguage(m_reportLanguage);
emit renderStarted(); emit renderStarted();
foreach(PageItemDesignIntf* page , m_renderingPages){ for(int i = 0; i < m_renderingPages.count(); ++i){
PageItemDesignIntf* page = m_renderingPages.at(i);
if (!page->isTOC() && page->isPrintable()){ if (!page->isTOC() && page->isPrintable()){
page->setReportSettings(&m_reportSettings); page->setReportSettings(&m_reportSettings);
result.append(m_reportRender->renderPageToPages(page)); result.append(m_reportRender->renderPageToPages(page));
} else {
startTOCPage = result.count();
pageAfterTOCIndex = i+1;
m_reportRender->createTOCMarker(page->resetPageNumber());
} }
} }
@ -1187,16 +1195,17 @@ ReportPages ReportEnginePrivate::renderToPages()
PageItemDesignIntf* page = m_renderingPages.at(i); PageItemDesignIntf* page = m_renderingPages.at(i);
if (page->isTOC()){ if (page->isTOC()){
page->setReportSettings(&m_reportSettings); page->setReportSettings(&m_reportSettings);
if (i==0){ if (i < m_renderingPages.count()){
PageItemDesignIntf* secondPage = 0; PageItemDesignIntf* secondPage = 0;
if (m_pages.count()>1) secondPage = m_renderingPages.at(1); if ( m_renderingPages.count() > (pageAfterTOCIndex))
secondPage = m_renderingPages.at(pageAfterTOCIndex);
ReportPages pages = m_reportRender->renderTOC( ReportPages pages = m_reportRender->renderTOC(
page, page,
true, true,
secondPage && secondPage->resetPageNumber() secondPage && secondPage->resetPageNumber()
); );
for (int j=0; j<pages.count(); ++j){ for (int j=0; j<pages.count(); ++j){
result.insert(j,pages.at(j)); result.insert(startTOCPage+j,pages.at(j));
} }
} else { } else {

View File

@ -283,6 +283,7 @@ private:
QMap<QString, ReportExporterInterface*> exporters; QMap<QString, ReportExporterInterface*> exporters;
ScaleType m_previewScaleType; ScaleType m_previewScaleType;
int m_previewScalePercent; int m_previewScalePercent;
int m_startTOCPage;
}; };
} }

View File

@ -193,11 +193,14 @@ void ReportRender::renderPage(PageItemDesignIntf* patternPage, bool isTOC, bool
m_currentNameIndex = 0; m_currentNameIndex = 0;
m_patternPageItem = patternPage; m_patternPageItem = patternPage;
m_renderingFirstTOC = isTOC && isFirst; m_renderingFirstTOC = isTOC && isFirst;
if (m_patternPageItem->resetPageNumber() && m_pageCount>0 && !isTOC) { if (m_patternPageItem->resetPageNumber() && m_pageCount>0 && !isTOC) {
resetPageNumber(PageReset); resetPageNumber(PageReset);
} }
if (m_patternPageItem->resetPageNumber() && !isTOC && m_pageCount == 0){
m_pagesRanges.startNewRange();
}
if (m_renderingFirstTOC && resetPageNumbers){ if (m_renderingFirstTOC && resetPageNumbers){
PagesRange range; PagesRange range;
range.firstPage = 0; range.firstPage = 0;
@ -249,8 +252,8 @@ void ReportRender::renderPage(PageItemDesignIntf* patternPage, bool isTOC, bool
savePage(true); savePage(true);
if (m_renderingFirstTOC && resetPageNumbers && m_ranges.count()>1){ if (m_renderingFirstTOC && resetPageNumbers && m_ranges.count()>1){
m_ranges[1].firstPage = m_ranges.at(0).lastPage+1; m_ranges[1].firstPage = m_ranges.first().lastPage+1;
m_ranges[1].lastPage += m_ranges.at(0).lastPage+1; m_ranges[1].lastPage += m_ranges.first().lastPage+1;
} }
#ifndef USE_QJSENGINE #ifndef USE_QJSENGINE
@ -1153,6 +1156,11 @@ void ReportRender::secondRenderPass(ReportPages renderedPages)
} }
} }
void ReportRender::createTOCMarker(bool startNewRange)
{
m_pagesRanges.addTOCMarker(startNewRange);
}
BandDesignIntf *ReportRender::saveUppperPartReturnBottom(BandDesignIntf *band, int height, BandDesignIntf* patternBand) BandDesignIntf *ReportRender::saveUppperPartReturnBottom(BandDesignIntf *band, int height, BandDesignIntf* patternBand)
{ {
int sliceHeight = height; int sliceHeight = height;
@ -1256,6 +1264,7 @@ void ReportRender::startNewPage(bool isFirst)
void ReportRender::resetPageNumber(ResetPageNuberType resetType) void ReportRender::resetPageNumber(ResetPageNuberType resetType)
{ {
m_pagesRanges.startNewRange();
PagesRange range; PagesRange range;
if (!m_ranges.isEmpty()){ if (!m_ranges.isEmpty()){
currentRange().lastPage = (resetType == BandReset)? m_pageCount : m_pageCount-1; currentRange().lastPage = (resetType == BandReset)? m_pageCount : m_pageCount-1;
@ -1406,6 +1415,10 @@ void ReportRender::moveTearOffBand(){
void ReportRender::savePage(bool isLast) void ReportRender::savePage(bool isLast)
{ {
if (m_renderPageItem->isTOC())
m_pagesRanges.addTOCPage();
else
m_pagesRanges.addPage();
m_datasources->setReportVariable("#IS_LAST_PAGEFOOTER",isLast); m_datasources->setReportVariable("#IS_LAST_PAGEFOOTER",isLast);
m_datasources->setReportVariable("#IS_FIRST_PAGEFOOTER",m_datasources->variable("#PAGE").toInt()==1); m_datasources->setReportVariable("#IS_FIRST_PAGEFOOTER",m_datasources->variable("#PAGE").toInt()==1);
@ -1478,4 +1491,87 @@ void ReportRender::cancelRender(){
m_renderCanceled = true; m_renderCanceled = true;
} }
int PagesRanges::findLastPageNumber(int index)
{
foreach (PagesRange range, m_ranges) {
if ( range.firstPage<= (index) && range.lastPage>= (index) )
return (range.lastPage-(range.firstPage))+1;
}
return 0;
}
int PagesRanges::findPageNumber(int index)
{
foreach (PagesRange range, m_ranges) {
if ( range.firstPage <= (index) && range.lastPage >= (index) )
return (index - range.firstPage)+1;
}
return 0;
}
void PagesRanges::startNewRange(bool isTOC)
{
PagesRange range;
if (!m_ranges.isEmpty()){
range.firstPage = 0;
range.lastPage = m_ranges.last().lastPage + 1;
} else {
range.firstPage = 0;
range.lastPage = 0;
}
range.isTOC = isTOC;
m_ranges.append(range);
if (isTOC) m_TOCRangeIndex = m_ranges.size()-1;
}
void PagesRanges::addTOCMarker(bool addNewRange)
{
if ( addNewRange || m_ranges.isEmpty()){
startNewRange(true);
} else {
m_TOCRangeIndex = m_ranges.size()-1;
m_ranges.last().isTOC = true;
}
}
void PagesRanges::addPage()
{
if (m_ranges.isEmpty()) startNewRange();
if (m_ranges.last().firstPage == 0){
m_ranges.last().firstPage = m_ranges.last().lastPage == 0 ? 1 : m_ranges.last().lastPage;
m_ranges.last().lastPage = m_ranges.last().lastPage == 0 ? 1 : m_ranges.last().lastPage;
} else {
m_ranges.last().lastPage++;
}
}
void PagesRanges::shiftRangesNextToTOC(){
for(int i = m_TOCRangeIndex+1; i < m_ranges.size(); ++i){
m_ranges[i].firstPage++;
m_ranges[i].lastPage++;
}
}
void PagesRanges::addTOCPage()
{
Q_ASSERT(m_TOCRangeIndex != -1);
if (m_TOCRangeIndex != -1){
PagesRange& tocRange = m_ranges[m_TOCRangeIndex];
if (tocRange.firstPage == 0) {
tocRange.firstPage = tocRange.lastPage == 0 ? 1 : tocRange.lastPage;
tocRange.lastPage = tocRange.lastPage == 0 ? 1 : tocRange.lastPage;
if (tocRange.lastPage == 1 and tocRange.lastPage == 1)
shiftRangesNextToTOC();
} else {
tocRange.lastPage++;
shiftRangesNextToTOC();
}
}
}
void PagesRanges::clear()
{
m_ranges.clear();
}
} // namespace LimeReport } // namespace LimeReport

View File

@ -61,6 +61,24 @@ private:
struct PagesRange{ struct PagesRange{
int firstPage; int firstPage;
int lastPage; int lastPage;
bool isTOC;
};
class PagesRanges{
public:
PagesRanges(): m_TOCRangeIndex(-1) {}
int findLastPageNumber(int index);
int findPageNumber(int index);
void startNewRange(bool isTOC = false);
void addTOCMarker(bool addNewRange);
void addPage();
void addTOCPage();
void clear();
private:
void shiftRangesNextToTOC();
private:
QVector<PagesRange> m_ranges;
int m_TOCRangeIndex;
}; };
class ReportRender: public QObject class ReportRender: public QObject
@ -84,6 +102,7 @@ public:
ReportPages renderPageToPages(PageItemDesignIntf *patternPage); ReportPages renderPageToPages(PageItemDesignIntf *patternPage);
ReportPages renderTOC(PageItemDesignIntf *patternPage, bool first, bool resetPages); ReportPages renderTOC(PageItemDesignIntf *patternPage, bool first, bool resetPages);
void secondRenderPass(ReportPages renderedPages); void secondRenderPass(ReportPages renderedPages);
void createTOCMarker(bool startNewRange);
signals: signals:
void pageRendered(int renderedPageCount); void pageRendered(int renderedPageCount);
public slots: public slots:
@ -191,6 +210,7 @@ private:
QVector<qreal> m_currentStartDataPos; QVector<qreal> m_currentStartDataPos;
int m_currentColumn; int m_currentColumn;
QList<PagesRange> m_ranges; QList<PagesRange> m_ranges;
PagesRanges m_pagesRanges;
QVector<BandDesignIntf*> m_columnedBandItems; QVector<BandDesignIntf*> m_columnedBandItems;
unsigned long long m_currentNameIndex; unsigned long long m_currentNameIndex;
bool m_newPageStarted; bool m_newPageStarted;