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

Finish agg_functions_in_header

This commit is contained in:
Arin Alex 2017-04-05 01:19:01 +03:00
commit 3ec2e22952
8 changed files with 131 additions and 21 deletions

View File

@ -64,6 +64,7 @@ class SubDetailHeaderBand : public BandDesignIntf
public: public:
SubDetailHeaderBand(QObject* owner = 0, QGraphicsItem* parent=0); SubDetailHeaderBand(QObject* owner = 0, QGraphicsItem* parent=0);
bool isUnique() const; bool isUnique() const;
bool isHeader() const {return true;}
protected: protected:
QColor bandColor() const; QColor bandColor() const;
private: private:

View File

@ -436,6 +436,19 @@ void BandDesignIntf::processPopUpAction(QAction *action)
} }
} }
void BandDesignIntf::recalcItems(DataSourceManager* dataManager)
{
foreach(BaseDesignIntf* bi, childBaseItems()){
ContentItemDesignIntf* ci = dynamic_cast<ContentItemDesignIntf*>(bi);
if (bi){
ContentItemDesignIntf* pci = dynamic_cast<ContentItemDesignIntf*>(bi->patternItem());
ci->setContent(pci->content());
}
}
updateItemSize(dataManager,FirstPass,height());
}
BaseDesignIntf* BandDesignIntf::cloneUpperPart(int height, QObject *owner, QGraphicsItem *parent) BaseDesignIntf* BandDesignIntf::cloneUpperPart(int height, QObject *owner, QGraphicsItem *parent)
{ {
int maxBottom = 0; int maxBottom = 0;
@ -855,6 +868,17 @@ void BandDesignIntf::updateItemSize(DataSourceManager* dataManager, RenderPass p
BaseDesignIntf::updateItemSize(dataManager, pass, maxHeight); BaseDesignIntf::updateItemSize(dataManager, pass, maxHeight);
} }
void BandDesignIntf::restoreItems()
{
foreach(BaseDesignIntf* bi, childBaseItems()){
ContentItemDesignIntf* ci = dynamic_cast<ContentItemDesignIntf*>(bi);
if (ci){
ContentItemDesignIntf* pci = dynamic_cast<ContentItemDesignIntf*>(bi->patternItem());
ci->setContent(pci->content());
}
}
}
void BandDesignIntf::updateBandNameLabel() void BandDesignIntf::updateBandNameLabel()
{ {
if (m_bandNameLabel) m_bandNameLabel->updateLabel(); if (m_bandNameLabel) m_bandNameLabel->updateLabel();

View File

@ -126,6 +126,8 @@ public:
virtual QIcon bandIcon() const; virtual QIcon bandIcon() const;
virtual bool isUnique() const; virtual bool isUnique() const;
void updateItemSize(DataSourceManager *dataManager, RenderPass pass=FirstPass, int maxHeight=0); void updateItemSize(DataSourceManager *dataManager, RenderPass pass=FirstPass, int maxHeight=0);
void restoreItems();
void recalcItems(DataSourceManager* dataManager);
void updateBandNameLabel(); void updateBandNameLabel();
virtual QColor selectionColor() const; virtual QColor selectionColor() const;
@ -219,7 +221,7 @@ public:
void setAlternateBackgroundColor(const QColor &alternateBackgroundColor); void setAlternateBackgroundColor(const QColor &alternateBackgroundColor);
bool useAlternateBackgroundColor() const; bool useAlternateBackgroundColor() const;
void setUseAlternateBackgroundColor(bool useAlternateBackgroundColor); void setUseAlternateBackgroundColor(bool useAlternateBackgroundColor);
void replaceGroupsFunction(BandDesignIntf *band);
signals: signals:
void bandRendered(BandDesignIntf* band); void bandRendered(BandDesignIntf* band);
protected: protected:
@ -242,6 +244,7 @@ protected:
void moveItemsDown(qreal startPos, qreal offset); void moveItemsDown(qreal startPos, qreal offset);
void preparePopUpMenu(QMenu &menu); void preparePopUpMenu(QMenu &menu);
void processPopUpAction(QAction *action); void processPopUpAction(QAction *action);
private slots: private slots:
void childBandDeleted(QObject* band); void childBandDeleted(QObject* band);
private: private:

View File

@ -78,7 +78,8 @@ BaseDesignIntf::BaseDesignIntf(const QString &storageTypeName, QObject *owner, Q
m_changingItemAlign(false), m_changingItemAlign(false),
m_borderColor(Qt::black), m_borderColor(Qt::black),
m_reportSettings(0), m_reportSettings(0),
m_patternName("") m_patternName(""),
m_patternItem(0)
{ {
setGeometry(QRectF(0, 0, m_width, m_height)); setGeometry(QRectF(0, 0, m_width, m_height));
if (BaseDesignIntf *item = dynamic_cast<BaseDesignIntf *>(parent)) { if (BaseDesignIntf *item = dynamic_cast<BaseDesignIntf *>(parent)) {
@ -711,6 +712,16 @@ void BaseDesignIntf::setPatternName(const QString &patternName)
m_patternName = patternName; m_patternName = patternName;
} }
BaseDesignIntf* BaseDesignIntf::patternItem() const
{
return m_patternItem;
}
void BaseDesignIntf::setPatternItem(BaseDesignIntf *patternItem)
{
m_patternItem = patternItem;
}
ReportSettings *BaseDesignIntf::reportSettings() const ReportSettings *BaseDesignIntf::reportSettings() const
{ {
return m_reportSettings; return m_reportSettings;
@ -1329,6 +1340,7 @@ BaseDesignIntf *BaseDesignIntf::cloneItem(ItemMode mode, QObject *owner, QGraphi
{ {
BaseDesignIntf *clone = cloneItemWOChild(mode, owner, parent); BaseDesignIntf *clone = cloneItemWOChild(mode, owner, parent);
clone->setPatternName(this->objectName()); clone->setPatternName(this->objectName());
clone->setPatternItem(this);
#ifdef HAVE_QT5 #ifdef HAVE_QT5
foreach(QObject * child, children()) { foreach(QObject * child, children()) {
#else #else

View File

@ -272,6 +272,8 @@ public:
void setZValueProperty(qreal value); void setZValueProperty(qreal value);
QString patternName() const; QString patternName() const;
void setPatternName(const QString &patternName); void setPatternName(const QString &patternName);
BaseDesignIntf* patternItem() const;
void setPatternItem(BaseDesignIntf* patternItem);
Q_INVOKABLE QString setItemWidth(qreal width); Q_INVOKABLE QString setItemWidth(qreal width);
Q_INVOKABLE QString setItemHeight(qreal height); Q_INVOKABLE QString setItemHeight(qreal height);
@ -397,6 +399,7 @@ private:
QColor m_borderColor; QColor m_borderColor;
ReportSettings* m_reportSettings; ReportSettings* m_reportSettings;
QString m_patternName; QString m_patternName;
BaseDesignIntf* m_patternItem;
signals: signals:
void geometryChanged(QObject* object, QRectF newGeometry, QRectF oldGeometry); void geometryChanged(QObject* object, QRectF newGeometry, QRectF oldGeometry);
void posChanged(QObject* object, QPointF newPos, QPointF oldPos); void posChanged(QObject* object, QPointF newPos, QPointF oldPos);

View File

@ -258,7 +258,11 @@ void DataSourceManager::clearGroupFuntionsExpressions()
QString DataSourceManager::getExpression(QString index) QString DataSourceManager::getExpression(QString index)
{ {
bool ok = false;
int i = index.toInt(&ok);
if (ok && m_groupFunctionsExpressions.size()>i)
return m_groupFunctionsExpressions.at(index.toInt()); return m_groupFunctionsExpressions.at(index.toInt());
else return "";
} }
bool DataSourceManager::designTime() const bool DataSourceManager::designTime() const

View File

@ -259,11 +259,8 @@ void ReportRender::renderPage(PageDesignIntf* patternPage)
clearPageMap(); clearPageMap();
startNewPage(true); startNewPage(true);
renderReportHeader(m_patternPageItem, AfterPageHeader); renderReportHeader(m_patternPageItem, AfterPageHeader);
// renderBand(m_patternPageItem->bandByType(BandDesignIntf::ReportHeader), 0, StartNewPageAsNeeded);
BandDesignIntf* lastRenderedBand = 0; BandDesignIntf* lastRenderedBand = 0;
for (int i=0;i<m_patternPageItem->dataBandCount() && !m_renderCanceled;i++){ for (int i=0;i<m_patternPageItem->dataBandCount() && !m_renderCanceled;i++){
lastRenderedBand = m_patternPageItem->dataBandAt(i); lastRenderedBand = m_patternPageItem->dataBandAt(i);
@ -318,6 +315,7 @@ void ReportRender::initRenderPage()
m_renderPageItem->initFromItem(m_patternPageItem); m_renderPageItem->initFromItem(m_patternPageItem);
m_renderPageItem->setItemMode(PreviewMode); m_renderPageItem->setItemMode(PreviewMode);
m_renderPageItem->setPatternName(m_patternPageItem->objectName()); m_renderPageItem->setPatternName(m_patternPageItem->objectName());
m_renderPageItem->setPatternItem(m_patternPageItem);
} }
} }
@ -393,6 +391,21 @@ void ReportRender::extractGroupsFunction(BandDesignIntf *band)
} }
} }
bool ReportRender::containsGroupsFunction(BandDesignIntf *band){
foreach(BaseDesignIntf* item,band->childBaseItems()){
ContentItemDesignIntf* contentItem = dynamic_cast<ContentItemDesignIntf*>(item);
if (contentItem){
QString content = contentItem->content();
foreach(QString functionName, m_datasources->groupFunctionNames()){
QRegExp rx(QString(Const::GROUP_FUNCTION_RX).arg(functionName));
if (rx.indexIn(content)>=0){
return true;
}
}
}
}
return false;
}
void ReportRender::replaceGroupsFunction(BandDesignIntf *band) void ReportRender::replaceGroupsFunction(BandDesignIntf *band)
{ {
@ -517,20 +530,20 @@ void ReportRender::renderDataBand(BandDesignIntf *dataBand)
BandDesignIntf* header = dataBand->bandHeader(); BandDesignIntf* header = dataBand->bandHeader();
BandDesignIntf* footer = dataBand->bandFooter(); BandDesignIntf* footer = dataBand->bandFooter();
if (header && header->printAlways()) renderBand(header, 0); if (header && header->printAlways()) renderDataHeader(header);
if(bandDatasource && !bandDatasource->eof() && !m_renderCanceled){ if(bandDatasource && !bandDatasource->eof() && !m_renderCanceled){
QString varName = QLatin1String("line_")+dataBand->objectName().toLower(); QString varName = QLatin1String("line_")+dataBand->objectName().toLower();
datasources()->setReportVariable(varName,1); datasources()->setReportVariable(varName,1);
if (header && !header->printAlways()) if (header && header->reprintOnEachPage())
renderBand(header, 0);
if (dataBand->bandHeader() && dataBand->bandHeader()->reprintOnEachPage())
m_reprintableBands.append(dataBand->bandHeader()); m_reprintableBands.append(dataBand->bandHeader());
renderChildHeader(dataBand,PrintNotAlwaysPrintable); if (header && !header->printAlways())
renderDataHeader(header);
//renderChildHeader(dataBand,PrintNotAlwaysPrintable);
renderGroupHeader(dataBand, bandDatasource, true); renderGroupHeader(dataBand, bandDatasource, true);
bool firstTime = true; bool firstTime = true;
@ -578,7 +591,8 @@ void ReportRender::renderDataBand(BandDesignIntf *dataBand)
firstTime = false; firstTime = false;
} }
m_reprintableBands.removeOne(dataBand->bandHeader()); m_reprintableBands.removeOne(header);
if (header) recalcIfNeeded(header);
renderGroupFooter(dataBand); renderGroupFooter(dataBand);
@ -703,13 +717,48 @@ void ReportRender::renderChildBands(BandDesignIntf *parentBand)
} }
} }
BandDesignIntf* ReportRender::findRecalcableBand(BandDesignIntf* patternBand){
QList<BandDesignIntf*>::iterator it = m_recalcBands.begin();
for (;it !=m_recalcBands.end() ;++it){
if ((*it)->patternItem() == patternBand){
BandDesignIntf* result = (*it);
m_recalcBands.erase(it);
return result;
}
}
return 0;
}
void ReportRender::recalcIfNeeded(BandDesignIntf* band){
BandDesignIntf* recalcBand = findRecalcableBand(band);
if (recalcBand){
QString bandName = recalcBand->objectName();
recalcBand->restoreItems();
recalcBand->setObjectName(recalcBand->patternItem()->objectName());
replaceGroupsFunction(recalcBand);
recalcBand->updateItemSize(datasources());
recalcBand->setObjectName(bandName);
datasources()->clearGroupFunctionValues(recalcBand->patternItem()->objectName());
}
}
void ReportRender::renderDataHeader(BandDesignIntf *header)
{
recalcIfNeeded(header);
BandDesignIntf* renderedHeader = renderBand(header, 0);
if (containsGroupsFunction(header))
m_recalcBands.append(renderedHeader);
}
void ReportRender::renderGroupHeader(BandDesignIntf *parentBand, IDataSource* dataSource, bool firstTime) void ReportRender::renderGroupHeader(BandDesignIntf *parentBand, IDataSource* dataSource, bool firstTime)
{ {
foreach(BandDesignIntf* band,parentBand->childrenByType(BandDesignIntf::GroupHeader)){ foreach(BandDesignIntf* band,parentBand->childrenByType(BandDesignIntf::GroupHeader)){
IGroupBand* gb = dynamic_cast<IGroupBand*>(band); IGroupBand* gb = dynamic_cast<IGroupBand*>(band);
if (gb&&gb->isNeedToClose(m_datasources)){ if (gb&&gb->isNeedToClose(datasources())){
if (band->childBands().count()>0){ if (band->childBands().count()>0){
dataSource->prior(); dataSource->prior();
foreach (BandDesignIntf* subBand, band->childrenByType(BandDesignIntf::GroupHeader)) { foreach (BandDesignIntf* subBand, band->childrenByType(BandDesignIntf::GroupHeader)) {
foreach(BandDesignIntf* footer, subBand->childrenByType(BandDesignIntf::GroupFooter)){ foreach(BandDesignIntf* footer, subBand->childrenByType(BandDesignIntf::GroupFooter)){
renderBand(footer, 0); renderBand(footer, 0);
@ -724,10 +773,6 @@ void ReportRender::renderGroupHeader(BandDesignIntf *parentBand, IDataSource* da
dataSource->next(); dataSource->next();
} }
closeDataGroup(band); closeDataGroup(band);
// if (gb->isNeedToStartNewPage()){
// savePage();
// startNewPage();
// }
} }
if (!gb->isStarted()){ if (!gb->isStarted()){
@ -735,12 +780,15 @@ void ReportRender::renderGroupHeader(BandDesignIntf *parentBand, IDataSource* da
m_reprintableBands.append(band); m_reprintableBands.append(band);
gb->startGroup(m_datasources); gb->startGroup(m_datasources);
openDataGroup(band); openDataGroup(band);
BandDesignIntf* renderedHeader = 0;
if (!firstTime && gb->startNewPage()){ if (!firstTime && gb->startNewPage()){
if (gb->resetPageNumber()) resetPageNumber(BandReset); if (gb->resetPageNumber()) resetPageNumber(BandReset);
renderBand(band, 0, ForcedStartPage); renderedHeader = renderBand(band, 0, ForcedStartPage);
} else { } else {
renderBand(band, 0, StartNewPageAsNeeded); renderedHeader = renderBand(band, 0, StartNewPageAsNeeded);
} }
if (containsGroupsFunction(band))
m_recalcBands.append(renderedHeader);
} }
renderGroupHeader(band, dataSource, firstTime); renderGroupHeader(band, dataSource, firstTime);
@ -754,6 +802,7 @@ void ReportRender::renderGroupFooterByHeader(BandDesignIntf* groupHeader){
foreach (BandDesignIntf* footer, groupHeader->childrenByType(BandDesignIntf::GroupFooter)){ foreach (BandDesignIntf* footer, groupHeader->childrenByType(BandDesignIntf::GroupFooter)){
renderBand(footer, 0, StartNewPageAsNeeded); renderBand(footer, 0, StartNewPageAsNeeded);
} }
recalcIfNeeded(groupHeader);
} }
void ReportRender::renderGroupFooter(BandDesignIntf *parentBand) void ReportRender::renderGroupFooter(BandDesignIntf *parentBand)
@ -781,6 +830,7 @@ void ReportRender::initGroups()
if (band->isHeader()){ if (band->isHeader()){
IGroupBand* gb = dynamic_cast<IGroupBand*>(band); IGroupBand* gb = dynamic_cast<IGroupBand*>(band);
if (gb) gb->closeGroup(); if (gb) gb->closeGroup();
extractGroupsFunction(band);
} }
} }
} }
@ -853,6 +903,7 @@ void ReportRender::closeDataGroup(BandDesignIntf *band)
groupBand->closeGroup(); groupBand->closeGroup();
if (band->reprintOnEachPage()) m_reprintableBands.removeOne(band); if (band->reprintOnEachPage()) m_reprintableBands.removeOne(band);
} }
recalcIfNeeded(band);
closeGroup(band); closeGroup(band);
} }
@ -1057,6 +1108,11 @@ BandDesignIntf *ReportRender::renderData(BandDesignIntf *patternBand)
if (patternBand->isFooter()){ if (patternBand->isFooter()){
replaceGroupsFunction(bandClone); replaceGroupsFunction(bandClone);
} }
if (patternBand->isHeader()){
replaceGroupsFunction(bandClone);
}
bandClone->updateItemSize(m_datasources); bandClone->updateItemSize(m_datasources);
baseDesignIntfToScript(bandClone); baseDesignIntfToScript(bandClone);

View File

@ -90,6 +90,7 @@ private:
void baseDesignIntfToScript(BaseDesignIntf* item); void baseDesignIntfToScript(BaseDesignIntf* item);
void renderPage(PageDesignIntf *patternPage); void renderPage(PageDesignIntf *patternPage);
void initDatasources(); void initDatasources();
void initDatasource(const QString &name); void initDatasource(const QString &name);
@ -112,13 +113,18 @@ private:
void renderChildHeader(BandDesignIntf* parent, BandPrintMode printMode); void renderChildHeader(BandDesignIntf* parent, BandPrintMode printMode);
void renderChildFooter(BandDesignIntf* parent, BandPrintMode printMode); void renderChildFooter(BandDesignIntf* parent, BandPrintMode printMode);
void renderChildBands(BandDesignIntf* parentBand); void renderChildBands(BandDesignIntf* parentBand);
void recalcIfNeeded(BandDesignIntf *band);
void renderDataHeader(BandDesignIntf* header);
void renderGroupHeader(BandDesignIntf* parentBand, IDataSource* dataSource, bool firstTime); void renderGroupHeader(BandDesignIntf* parentBand, IDataSource* dataSource, bool firstTime);
void renderGroupFooter(BandDesignIntf* parentBand); void renderGroupFooter(BandDesignIntf* parentBand);
void initGroups(); void initGroups();
bool containsGroupsFunction(BandDesignIntf* band);
void extractGroupsFunction(BandDesignIntf* band); void extractGroupsFunction(BandDesignIntf* band);
void replaceGroupsFunction(BandDesignIntf* band); void replaceGroupsFunction(BandDesignIntf* band);
BandDesignIntf *findRecalcableBand(BandDesignIntf *patternBand);
void popPageFooterGroupValues(BandDesignIntf* dataBand); void popPageFooterGroupValues(BandDesignIntf* dataBand);
void pushPageFooterGroupValues(BandDesignIntf* dataBand); void pushPageFooterGroupValues(BandDesignIntf* dataBand);
@ -162,6 +168,7 @@ private:
QList<PageItemDesignIntf::Ptr> m_renderedPages; QList<PageItemDesignIntf::Ptr> m_renderedPages;
QMultiMap< BandDesignIntf*, GroupBandsHolder* > m_childBands; QMultiMap< BandDesignIntf*, GroupBandsHolder* > m_childBands;
QList<BandDesignIntf*> m_reprintableBands; QList<BandDesignIntf*> m_reprintableBands;
QList<BandDesignIntf*> m_recalcBands;
// QList<BandDesignIntf*> m_lastRenderedHeaders; // QList<BandDesignIntf*> m_lastRenderedHeaders;
//int m_maxHeightByColumn[0]; //int m_maxHeightByColumn[0];