0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 08:34:38 +03:00

getPageFreeSpace(page) has been added to script function manager

This commit is contained in:
Arin Alexander 2021-04-12 20:22:34 +03:00
parent 3376ea7c08
commit 03963f3685
4 changed files with 59 additions and 33 deletions

View File

@ -133,7 +133,7 @@ RCC_DIR = $${ARCH_DIR}/$${BUILD_TYPE}/rcc
LIMEREPORT_VERSION_MAJOR = 1 LIMEREPORT_VERSION_MAJOR = 1
LIMEREPORT_VERSION_MINOR = 5 LIMEREPORT_VERSION_MINOR = 5
LIMEREPORT_VERSION_RELEASE = 82 LIMEREPORT_VERSION_RELEASE = 83
LIMEREPORT_VERSION = '$${LIMEREPORT_VERSION_MAJOR}.$${LIMEREPORT_VERSION_MINOR}.$${LIMEREPORT_VERSION_RELEASE}' LIMEREPORT_VERSION = '$${LIMEREPORT_VERSION_MAJOR}.$${LIMEREPORT_VERSION_MINOR}.$${LIMEREPORT_VERSION_RELEASE}'
DEFINES *= LIMEREPORT_VERSION_STR=\\\"$${LIMEREPORT_VERSION}\\\" DEFINES *= LIMEREPORT_VERSION_STR=\\\"$${LIMEREPORT_VERSION}\\\"

View File

@ -208,12 +208,14 @@ void ReportRender::analizeItem(ContentItemDesignIntf* contentItem, BandDesignInt
} }
void ReportRender::analizeContainer(BaseDesignIntf* item, BandDesignIntf* band){ void ReportRender::analizeContainer(BaseDesignIntf* item, BandDesignIntf* band){
if (item){
foreach(BaseDesignIntf* child, item->childBaseItems()){ foreach(BaseDesignIntf* child, item->childBaseItems()){
ContentItemDesignIntf* contentItem = dynamic_cast<ContentItemDesignIntf*>(child); ContentItemDesignIntf* contentItem = dynamic_cast<ContentItemDesignIntf*>(child);
if (contentItem) analizeItem(contentItem, band); if (contentItem) analizeItem(contentItem, band);
else analizeContainer(child, band); else analizeContainer(child, band);
} }
} }
}
void ReportRender::analizePage(PageItemDesignIntf* patternPage){ void ReportRender::analizePage(PageItemDesignIntf* patternPage){
m_groupfunctionItems.clear(); m_groupfunctionItems.clear();
@ -407,12 +409,13 @@ void ReportRender::extractGroupFuntionsFromItem(ContentItemDesignIntf* contentIt
} }
void ReportRender::extractGroupFunctionsFromContainer(BaseDesignIntf* baseItem, BandDesignIntf* band){ void ReportRender::extractGroupFunctionsFromContainer(BaseDesignIntf* baseItem, BandDesignIntf* band){
if (baseItem){
foreach (BaseDesignIntf* item, baseItem->childBaseItems()) { foreach (BaseDesignIntf* item, baseItem->childBaseItems()) {
ContentItemDesignIntf* contentItem = dynamic_cast<ContentItemDesignIntf*>(item); ContentItemDesignIntf* contentItem = dynamic_cast<ContentItemDesignIntf*>(item);
if (contentItem) extractGroupFuntionsFromItem(contentItem, band); if (contentItem) extractGroupFuntionsFromItem(contentItem, band);
else extractGroupFunctionsFromContainer(item, band); else extractGroupFunctionsFromContainer(item, band);
} }
}
} }
void ReportRender::extractGroupFunctions(BandDesignIntf *band) void ReportRender::extractGroupFunctions(BandDesignIntf *band)
@ -436,11 +439,12 @@ void ReportRender::replaceGroupFunctionsInItem(ContentItemDesignIntf* contentIte
if (captures.size()<5){ if (captures.size()<5){
content.replace(captures.at(0),QString("%1(%2,%3)").arg(functionName).arg('"'+expressionIndex+'"').arg('"'+band->objectName()+'"')); content.replace(captures.at(0),QString("%1(%2,%3)").arg(functionName).arg('"'+expressionIndex+'"').arg('"'+band->objectName()+'"'));
} else { } else {
content.replace(captures.at(0),QString("%1(%2,%3,%4)") content.replace(captures.at(0),QString("%1(%2,%3,%4)").arg(
.arg(functionName) functionName,
.arg('"'+expressionIndex+'"') '"'+expressionIndex+'"',
.arg('"'+band->objectName()+'"') '"'+band->objectName()+'"',
.arg(captures.at(4))); captures.at(4)
));
} }
} }
pos += rx.matchedLength(); pos += rx.matchedLength();
@ -454,12 +458,14 @@ void ReportRender::replaceGroupFunctionsInItem(ContentItemDesignIntf* contentIte
void ReportRender::replaceGroupFunctionsInContainer(BaseDesignIntf* baseItem, BandDesignIntf* band) void ReportRender::replaceGroupFunctionsInContainer(BaseDesignIntf* baseItem, BandDesignIntf* band)
{ {
if (baseItem){
foreach(BaseDesignIntf* item, baseItem->childBaseItems()){ foreach(BaseDesignIntf* item, baseItem->childBaseItems()){
ContentItemDesignIntf* contentItem = dynamic_cast<ContentItemDesignIntf*>(item); ContentItemDesignIntf* contentItem = dynamic_cast<ContentItemDesignIntf*>(item);
if (contentItem) replaceGroupFunctionsInItem(contentItem, band); if (contentItem) replaceGroupFunctionsInItem(contentItem, band);
else replaceGroupFunctionsInContainer(item, band); else replaceGroupFunctionsInContainer(item, band);
} }
} }
}
void ReportRender::replaceGroupsFunction(BandDesignIntf *band) void ReportRender::replaceGroupsFunction(BandDesignIntf *band)
{ {
@ -574,8 +580,10 @@ BandDesignIntf* ReportRender::renderBand(BandDesignIntf *patternBand, BandDesign
return 0; return 0;
} }
if (patternBand->isFooter()) if (patternBand->isFooter()){
datasources()->clearGroupFunctionValues(patternBand->objectName()); datasources()->clearGroupFunctionValues(patternBand->objectName());
}
emit(patternBand->afterRender()); emit(patternBand->afterRender());
return bandClone; return bandClone;
} }
@ -1301,7 +1309,7 @@ void ReportRender::startNewPage(bool isFirst)
m_newPageStarted = true; m_newPageStarted = true;
initColumns(); initColumns();
initRenderPage(); initRenderPage();
m_scriptEngineContext->setCurrentPage(m_renderPageItem);
m_scriptEngineContext->baseDesignIntfToScript(m_renderPageItem->patternName(), m_renderPageItem); m_scriptEngineContext->baseDesignIntfToScript(m_renderPageItem->patternName(), m_renderPageItem);
emit m_patternPageItem->beforeRender(); emit m_patternPageItem->beforeRender();
@ -1343,7 +1351,8 @@ void ReportRender::cutGroups()
{ {
m_popupedExpression.clear(); m_popupedExpression.clear();
m_popupedValues.clear(); m_popupedValues.clear();
foreach(BandDesignIntf* groupBand,m_childBands.keys()){ //foreach(BandDesignIntf* groupBand,m_childBands.keys()){
for(BandDesignIntf* groupBand : m_childBands.keys()){
if (m_childBands.value(groupBand)->tryToKeepTogether()){ if (m_childBands.value(groupBand)->tryToKeepTogether()){
foreach(BandDesignIntf* band, *m_childBands.value(groupBand)){ foreach(BandDesignIntf* band, *m_childBands.value(groupBand)){
m_renderPageItem->removeBand(band); m_renderPageItem->removeBand(band);
@ -1419,7 +1428,8 @@ void ReportRender::checkLostHeadersOnPrevPage()
if (lostHeaders.size() > 0){ if (lostHeaders.size() > 0){
m_lostHeadersMoved = true; m_lostHeadersMoved = true;
qSort(lostHeaders.begin(), lostHeaders.end(), bandLessThen); //qSort(lostHeaders.begin(), lostHeaders.end(), bandLessThen);
std::sort(lostHeaders.begin(), lostHeaders.end(), bandLessThen);
foreach(BandDesignIntf* header, lostHeaders){ foreach(BandDesignIntf* header, lostHeaders){
registerBand(header); registerBand(header);
} }
@ -1456,7 +1466,8 @@ void ReportRender::checkLostHeadersInPrevColumn()
if (lostHeaders.size() > 0){ if (lostHeaders.size() > 0){
m_lostHeadersMoved = true; m_lostHeadersMoved = true;
qSort(lostHeaders.begin(), lostHeaders.end(), bandLessThen); // qSort(lostHeaders.begin(), lostHeaders.end(), bandLessThen);
std::sort(lostHeaders.begin(), lostHeaders.end(), bandLessThen);
foreach(BandDesignIntf* header, lostHeaders){ foreach(BandDesignIntf* header, lostHeaders){
registerBand(header); registerBand(header);
} }
@ -1538,7 +1549,7 @@ void ReportRender::savePage(bool isLast)
} }
m_renderPageItem->placeTearOffBand(); m_renderPageItem->placeTearOffBand();
m_scriptEngineContext->setCurrentPage(m_renderPageItem); //m_scriptEngineContext->setCurrentPage(m_renderPageItem);
emit m_patternPageItem->afterRender(); emit m_patternPageItem->afterRender();
if (isLast) if (isLast)
emit m_patternPageItem->afterLastPageRendered(); emit m_patternPageItem->afterLastPageRendered();

View File

@ -547,14 +547,13 @@ QVariant ScriptEngineManager::evaluateScript(const QString& script){
void ScriptEngineManager::addBookMark(const QString& uniqKey, const QString& content){ void ScriptEngineManager::addBookMark(const QString& uniqKey, const QString& content){
Q_ASSERT(m_context != 0); Q_ASSERT(m_context != 0);
if (m_context){ if (m_context){
BandDesignIntf* currentBand = m_context->getCurrentBand(); BandDesignIntf* currentBand = m_context->currentBand();
if (currentBand) if (currentBand)
currentBand->addBookmark(uniqKey, content); currentBand->addBookmark(uniqKey, content);
else if (m_context->getCurrentPage()) { else if (m_context->currentPage()) {
m_context->getCurrentPage()->addBookmark(uniqKey, content); m_context->currentPage()->addBookmark(uniqKey, content);
} }
} }
} }
int ScriptEngineManager::findPageIndexByBookmark(const QString &uniqKey) int ScriptEngineManager::findPageIndexByBookmark(const QString &uniqKey)
@ -570,6 +569,16 @@ int ScriptEngineManager::findPageIndexByBookmark(const QString &uniqKey)
return -1; return -1;
} }
int ScriptEngineManager::getPageFreeSpace(PageItemDesignIntf* page){
if (page){
int height = 0;
foreach(BandDesignIntf* band, page->bands()){
height += band->height();
}
return page->height() - height;
} else return -1;
}
void ScriptEngineManager::addTableOfContentsItem(const QString& uniqKey, const QString& content, int indent) void ScriptEngineManager::addTableOfContentsItem(const QString& uniqKey, const QString& content, int indent)
{ {
Q_ASSERT(m_context != 0); Q_ASSERT(m_context != 0);
@ -1306,7 +1315,7 @@ void ScriptEngineContext::setTableOfContents(TableOfContents* tableOfContents)
m_tableOfContents = tableOfContents; m_tableOfContents = tableOfContents;
} }
PageItemDesignIntf* ScriptEngineContext::getCurrentPage() const PageItemDesignIntf* ScriptEngineContext::currentPage() const
{ {
return m_currentPage; return m_currentPage;
} }
@ -1317,7 +1326,7 @@ void ScriptEngineContext::setCurrentPage(PageItemDesignIntf* currentPage)
m_currentBand = 0; m_currentBand = 0;
} }
BandDesignIntf* ScriptEngineContext::getCurrentBand() const BandDesignIntf* ScriptEngineContext::currentBand() const
{ {
return m_currentBand; return m_currentBand;
} }
@ -1693,6 +1702,10 @@ int ScriptFunctionsManager::findPageIndexByBookmark(const QString &uniqKey)
return scriptEngineManager()->findPageIndexByBookmark(uniqKey); return scriptEngineManager()->findPageIndexByBookmark(uniqKey);
} }
int ScriptFunctionsManager::getPageFreeSpace(QObject* page){
return scriptEngineManager()->getPageFreeSpace(dynamic_cast<PageItemDesignIntf*>(page));
}
void ScriptFunctionsManager::addTableOfContentsItem(const QString& uniqKey, const QString& content, int indent) void ScriptFunctionsManager::addTableOfContentsItem(const QString& uniqKey, const QString& content, int indent)
{ {
scriptEngineManager()->addTableOfContentsItem(uniqKey, content, indent); scriptEngineManager()->addTableOfContentsItem(uniqKey, content, indent);

View File

@ -199,9 +199,9 @@ public:
void setInitScript(const QString& initScript); void setInitScript(const QString& initScript);
bool runInitScript(); bool runInitScript();
BandDesignIntf* getCurrentBand() const; BandDesignIntf* currentBand() const;
void setCurrentBand(BandDesignIntf* currentBand); void setCurrentBand(BandDesignIntf* currentBand);
PageItemDesignIntf* getCurrentPage() const; PageItemDesignIntf* currentPage() const;
void setCurrentPage(PageItemDesignIntf* currentPage); void setCurrentPage(PageItemDesignIntf* currentPage);
TableOfContents* tableOfContents() const; TableOfContents* tableOfContents() const;
void setTableOfContents(TableOfContents* tableOfContents); void setTableOfContents(TableOfContents* tableOfContents);
@ -389,6 +389,7 @@ public:
Q_INVOKABLE QScriptValue createWrapper(QScriptValue item); Q_INVOKABLE QScriptValue createWrapper(QScriptValue item);
#endif #endif
Q_INVOKABLE QFont font(QVariantMap params); Q_INVOKABLE QFont font(QVariantMap params);
Q_INVOKABLE int getPageFreeSpace(QObject *page);
ScriptEngineManager *scriptEngineManager() const; ScriptEngineManager *scriptEngineManager() const;
void setScriptEngineManager(ScriptEngineManager *scriptEngineManager); void setScriptEngineManager(ScriptEngineManager *scriptEngineManager);
static QColor createQColor(const QString& color){ return QColor(color);} static QColor createQColor(const QString& color){ return QColor(color);}
@ -473,6 +474,7 @@ public:
int findPageIndexByBookmark(const QString& uniqKey); int findPageIndexByBookmark(const QString& uniqKey);
void addTableOfContentsItem(const QString& uniqKey, const QString& content, int indent); void addTableOfContentsItem(const QString& uniqKey, const QString& content, int indent);
void clearTableOfContents(); void clearTableOfContents();
int getPageFreeSpace(PageItemDesignIntf *page);
ScriptValueType moveQObjectToScript(QObject* object, const QString objectName); ScriptValueType moveQObjectToScript(QObject* object, const QString objectName);
protected: protected:
void updateModel(); void updateModel();