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

Merge branch 'master' into 1.4

# Conflicts:
#	limereport/lrreportrender.cpp
This commit is contained in:
Arin Alexander 2016-09-28 02:27:45 +04:00
commit 1e7aa027d7
5 changed files with 44 additions and 21 deletions

View File

@ -92,8 +92,9 @@ void GroupBandHeader::startGroup(DataSourceManager* dataManager)
QString lineVar = QLatin1String("line_")+objectName().toLower(); QString lineVar = QLatin1String("line_")+objectName().toLower();
dataManager->setReportVariable(lineVar,1); dataManager->setReportVariable(lineVar,1);
if ((dataManager->dataSource(parentBand()->datasourceName()))){ QString datasourceName = findDataSourceName(parentBand());
IDataSource* ds = dataManager->dataSource(parentBand()->datasourceName()); if (dataManager->containsDatasource(datasourceName)){
IDataSource* ds = dataManager->dataSource(datasourceName);
if (ds->columnIndexByName(m_groupFiledName)!=-1) if (ds->columnIndexByName(m_groupFiledName)!=-1)
m_groupFieldValue=ds->data(m_groupFiledName); m_groupFieldValue=ds->data(m_groupFiledName);
} }
@ -104,17 +105,27 @@ QColor GroupBandHeader::bandColor() const
return QColor(Qt::darkBlue); return QColor(Qt::darkBlue);
} }
QString GroupBandHeader::findDataSourceName(BandDesignIntf* parentBand){
if (!parentBand) return "";
if (!parentBand->datasourceName().isEmpty())
return parentBand->datasourceName();
else
return findDataSourceName(parentBand->parentBand());
}
bool GroupBandHeader::isNeedToClose(DataSourceManager* dataManager) bool GroupBandHeader::isNeedToClose(DataSourceManager* dataManager)
{ {
//if (m_groupFieldValue.isNull()) return false;
if (!m_groupStarted) return false; if (!m_groupStarted) return false;
if (m_groupFiledName.isNull() || m_groupFiledName.isEmpty()) if (m_groupFiledName.isNull() || m_groupFiledName.isEmpty())
dataManager->putError("Group Field Not found"); dataManager->putError(tr("Group field not found"));
if ((dataManager->dataSource(parentBand()->datasourceName()))){ QString datasourceName = findDataSourceName(parentBand());
IDataSource* ds = dataManager->dataSource(parentBand()->datasourceName()); if (dataManager->containsDatasource(datasourceName)){
IDataSource* ds = dataManager->dataSource(datasourceName);
if (ds->data(m_groupFiledName).isNull() && m_groupFieldValue.isNull()) return false; if (ds->data(m_groupFiledName).isNull() && m_groupFieldValue.isNull()) return false;
return ds->data(m_groupFiledName)!=m_groupFieldValue; return ds->data(m_groupFiledName)!=m_groupFieldValue;
} else {
dataManager->putError(tr("Datasource \"%1\" not found !!!").arg(datasourceName));
} }
return false; return false;

View File

@ -64,6 +64,7 @@ private:
bool isStarted(); bool isStarted();
void closeGroup(); void closeGroup();
int index(); int index();
QString findDataSourceName(BandDesignIntf *parentBand);
private: private:
QVariant m_groupFieldValue; QVariant m_groupFieldValue;
QString m_groupFiledName; QString m_groupFiledName;

View File

@ -207,7 +207,7 @@ void ReportRender::renderPage(PageDesignIntf* patternPage)
m_reportFooterHeight = 0; m_reportFooterHeight = 0;
if (reportFooter) if (reportFooter)
m_reportFooterHeight = reportFooter->height(); m_reportFooterHeight = reportFooter->height();
initGroupFunctions(); initGroups();
#ifdef HAVE_UI_LOADER #ifdef HAVE_UI_LOADER
initDialogs(); initDialogs();
#endif #endif
@ -588,16 +588,17 @@ void ReportRender::renderGroupHeader(BandDesignIntf *parentBand, IDataSource* da
if (gb&&gb->isNeedToClose(m_datasources)){ if (gb&&gb->isNeedToClose(m_datasources)){
if (band->childBands().count()>0){ if (band->childBands().count()>0){
dataSource->prior(); dataSource->prior();
foreach (BandDesignIntf* subBand, parentBand->childrenByType(BandDesignIntf::GroupHeader)) { foreach (BandDesignIntf* subBand, band->childrenByType(BandDesignIntf::GroupHeader)) {
if ( (subBand->bandIndex() > band->bandIndex()) && foreach(BandDesignIntf* footer, subBand->childrenByType(BandDesignIntf::GroupFooter)){
(subBand->childBands().count()>0) renderBand(footer);
){
renderBand(subBand->childBands().at(0));
closeDataGroup(subBand); closeDataGroup(subBand);
} }
} }
renderBand(band->childBands().at(0),StartNewPageAsNeeded); foreach (BandDesignIntf* footer, band->childrenByType(BandDesignIntf::GroupFooter)) {
renderBand(footer,StartNewPageAsNeeded);
}
dataSource->next(); dataSource->next();
} }
closeDataGroup(band); closeDataGroup(band);
@ -606,6 +607,7 @@ void ReportRender::renderGroupHeader(BandDesignIntf *parentBand, IDataSource* da
// startNewPage(); // startNewPage();
// } // }
} }
if (!gb->isStarted()){ if (!gb->isStarted()){
if (band->reprintOnEachPage()) if (band->reprintOnEachPage())
m_reprintableBands.append(band); m_reprintableBands.append(band);
@ -618,6 +620,8 @@ void ReportRender::renderGroupHeader(BandDesignIntf *parentBand, IDataSource* da
renderBand(band,StartNewPageAsNeeded); renderBand(band,StartNewPageAsNeeded);
} }
} }
renderGroupHeader(band, dataSource, firstTime);
} }
} }
@ -635,11 +639,12 @@ void ReportRender::renderGroupFooter(BandDesignIntf *parentBand)
} }
} }
void ReportRender::initGroupFunctions() void ReportRender::initGroups()
{ {
m_datasources->clearGroupFunction(); m_datasources->clearGroupFunction();
foreach(BandDesignIntf* band, m_patternPageItem->childBands()){ foreach(BandDesignIntf* band, m_patternPageItem->childBands()){
if (band->isFooter()) extractGroupsFunction(band); if (band->isFooter()) extractGroupsFunction(band);
if (band->isHeader()) dynamic_cast<IGroupBand*>(band)->closeGroup();
} }
} }

View File

@ -109,7 +109,7 @@ private:
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 initGroupFunctions(); void initGroups();
void extractGroupsFunction(BandDesignIntf* band); void extractGroupsFunction(BandDesignIntf* band);
void replaceGroupsFunction(BandDesignIntf* band); void replaceGroupsFunction(BandDesignIntf* band);

View File

@ -42,18 +42,24 @@ namespace {
} }
namespace LimeReport { namespace LimeReport {
QString findDatasourceName(BandDesignIntf* band){
if (!band) return "";
if (!band->datasourceName().isEmpty()) return band->datasourceName();
else return findDatasourceName(band->parentBand());
}
QWidget *GroupFieldPropItem::createProperyEditor(QWidget *parent) const QWidget *GroupFieldPropItem::createProperyEditor(QWidget *parent) const
{ {
ComboBoxEditor *editor = new ComboBoxEditor(parent,true); ComboBoxEditor *editor = new ComboBoxEditor(parent,true);
editor->setEditable(true); editor->setEditable(true);
GroupBandHeader *item=dynamic_cast<GroupBandHeader*>(object()); GroupBandHeader *item=dynamic_cast<GroupBandHeader*>(object());
if (item){ if (item){
DataBandDesignIntf* dataBand = dynamic_cast<DataBandDesignIntf*>(item->parentBand()); BandDesignIntf* dataBand = dynamic_cast<BandDesignIntf*>(item->parentBand());
if (dataBand){ if (dataBand){
int propertyIndex = dataBand->metaObject()->indexOfProperty("datasource"); QString datasourceName = findDatasourceName(dataBand);
if (!datasourceName.isEmpty()){
if (item && propertyIndex>0){ editor->addItems(item->reportEditor()->dataManager()->fieldNames(datasourceName));
editor->addItems(item->reportEditor()->dataManager()->fieldNames(dataBand->property("datasource").toString()));
} }
} }
} }