Tear-off band has been added

Tear-off band has been added

Tear-off band has been added
This commit is contained in:
Arin Alexander 2016-10-04 04:21:22 +04:00
parent 46e89b8e9d
commit dc41959d52
17 changed files with 228 additions and 26 deletions

View File

@ -95,7 +95,7 @@ void GroupBandHeader::startGroup(DataSourceManager* dataManager)
QString datasourceName = findDataSourceName(parentBand());
if (dataManager->containsDatasource(datasourceName)){
IDataSource* ds = dataManager->dataSource(datasourceName);
if (ds->columnIndexByName(m_groupFiledName)!=-1)
if (ds && ds->columnIndexByName(m_groupFiledName)!=-1)
m_groupFieldValue=ds->data(m_groupFiledName);
}
}
@ -122,8 +122,10 @@ bool GroupBandHeader::isNeedToClose(DataSourceManager* dataManager)
QString datasourceName = findDataSourceName(parentBand());
if (dataManager->containsDatasource(datasourceName)){
IDataSource* ds = dataManager->dataSource(datasourceName);
if (ds){
if (ds->data(m_groupFiledName).isNull() && m_groupFieldValue.isNull()) return false;
return ds->data(m_groupFiledName)!=m_groupFieldValue;
}
} else {
dataManager->putError(tr("Datasource \"%1\" not found !!!").arg(datasourceName));
}

View File

@ -48,7 +48,9 @@ bool registred = LimeReport::DesignElementsFactory::instance().registerCreator(
namespace LimeReport{
PageFooter::PageFooter(QObject *owner, QGraphicsItem *parent)
: BandDesignIntf(LimeReport::BandDesignIntf::PageFooter,xmlTag,owner,parent) {
: BandDesignIntf(LimeReport::BandDesignIntf::PageFooter,xmlTag,owner,parent),
m_printOnFirstPage(true), m_printOnLastPage(true)
{
setBandTypeText( tr("Page Footer") );
setMarkerColor(bandColor());
}
@ -63,4 +65,24 @@ QColor PageFooter::bandColor() const
return QColor(246,120,12);
}
bool PageFooter::printOnFirstPage() const
{
return m_printOnFirstPage;
}
void PageFooter::setPrintOnFirstPage(bool printOnFirstPage)
{
m_printOnFirstPage = printOnFirstPage;
}
bool PageFooter::printOnLastPage() const
{
return m_printOnLastPage;
}
void PageFooter::setPrintOnLastPage(bool printOnLastPage)
{
m_printOnLastPage = printOnLastPage;
}
} // namespace LimeReport

View File

@ -38,12 +38,22 @@ namespace LimeReport{
class PageFooter : public LimeReport::BandDesignIntf
{
Q_OBJECT
Q_PROPERTY(bool printOnFirstPage READ printOnFirstPage WRITE setPrintOnFirstPage)
Q_PROPERTY(bool printOnLastPage READ printOnLastPage WRITE setPrintOnLastPage)
public:
PageFooter(QObject* owner = 0, QGraphicsItem* parent=0);
virtual BaseDesignIntf* createSameTypeItem(QObject* owner=0, QGraphicsItem* parent=0);
virtual bool isFooter() const {return true;}
bool printOnLastPage() const;
void setPrintOnLastPage(bool printOnLastPage);
bool printOnFirstPage() const;
void setPrintOnFirstPage(bool printOnFirstPage);
protected:
QColor bandColor() const;
private:
bool m_printOnLastPage;
bool m_printOnFirstPage;
};
}

View File

@ -52,7 +52,8 @@ bool registred = LimeReport::DesignElementsFactory::instance().registerCreator(
namespace LimeReport{
PageHeader::PageHeader(QObject* owner, QGraphicsItem *parent)
: BandDesignIntf(LimeReport::BandDesignIntf::PageHeader,xmlTag,owner,parent) {
: BandDesignIntf(LimeReport::BandDesignIntf::PageHeader,xmlTag,owner,parent),
m_printOnFirstPage(true), m_printOnLastPage(true) {
setBandTypeText(tr("Page Header"));
setMarkerColor(bandColor());
}
@ -67,4 +68,24 @@ QColor PageHeader::bandColor() const
return QColor(246,120,12);
}
bool PageHeader::printOnLastPage() const
{
return m_printOnLastPage;
}
void PageHeader::setPrintOnLastPage(bool printOnLastPage)
{
m_printOnLastPage = printOnLastPage;
}
bool PageHeader::printOnFirstPage() const
{
return m_printOnFirstPage;
}
void PageHeader::setPrintOnFirstPage(bool printOnFirstPage)
{
m_printOnFirstPage = printOnFirstPage;
}
}

View File

@ -38,11 +38,20 @@ namespace LimeReport {
class PageHeader : public LimeReport::BandDesignIntf
{
Q_OBJECT
Q_PROPERTY(bool printOnFirstPage READ printOnFirstPage WRITE setPrintOnFirstPage)
Q_PROPERTY(bool printOnLastPage READ printOnLastPage WRITE setPrintOnLastPage)
public:
PageHeader(QObject* owner = 0, QGraphicsItem* parent=0);
bool printOnFirstPage() const;
void setPrintOnFirstPage(bool printOnFirstPage);
bool printOnLastPage() const;
void setPrintOnLastPage(bool printOnLastPage);
protected:
virtual BaseDesignIntf* createSameTypeItem(QObject* owner=0, QGraphicsItem* parent=0);
QColor bandColor() const;
private:
bool m_printOnFirstPage;
bool m_printOnLastPage;
};
}
#endif // LRPAGEHEADER_H

View File

@ -41,6 +41,7 @@ class SubDetailBand : public DataBandDesignIntf
Q_PROPERTY(bool splittable READ isSplittable WRITE setSplittable)
Q_PROPERTY(int columnsCount READ columnsCount WRITE setColumnsCount)
Q_PROPERTY(BandColumnsLayoutType columnsFillDirection READ columnsFillDirection WRITE setColumnsFillDirection)
Q_PROPERTY(bool keepFooterTogether READ keepFooterTogether WRITE setKeepFooterTogether)
public:
SubDetailBand(QObject* owner = 0, QGraphicsItem* parent=0);
bool isUnique() const {return false;}
@ -55,7 +56,7 @@ protected:
class SubDetailHeaderBand : public BandDesignIntf
{
Q_OBJECT
Q_PROPERTY(bool printAlways READ printAlways() WRITE setPrintAlways())
Q_PROPERTY(bool printAlways READ printAlways WRITE setPrintAlways)
public:
SubDetailHeaderBand(QObject* owner = 0, QGraphicsItem* parent=0);
bool isUnique() const;

View File

@ -0,0 +1,37 @@
#include "lrtearoffband.h"
#include "lrdesignelementsfactory.h"
#include "lrglobal.h"
const QString xmlTag ="TearOffBand";
namespace{
LimeReport::BaseDesignIntf * createBand(QObject* owner, LimeReport::BaseDesignIntf* parent){
return new LimeReport::TearOffBand(owner,parent);
}
bool registred = LimeReport::DesignElementsFactory::instance().registerCreator(
xmlTag,
LimeReport::ItemAttribs(QObject::tr("Tear-off Band"),LimeReport::Const::bandTAG),
createBand
);
}
namespace LimeReport{
TearOffBand::TearOffBand(QObject *owner, QGraphicsItem *parent)
:BandDesignIntf(LimeReport::BandDesignIntf::TearOffBand,xmlTag,owner,parent)
{
setBandTypeText(tr("Tear-off Band"));
setMarkerColor(bandColor());
}
BaseDesignIntf *TearOffBand::createSameTypeItem(QObject *owner, QGraphicsItem *parent)
{
return new TearOffBand(owner,parent);
}
QColor TearOffBand::bandColor() const
{
return QColor(200,200,200);
}
} // namedpace LimeReport

View File

@ -0,0 +1,20 @@
#ifndef TEAROFFBAND_H
#define TEAROFFBAND_H
#include "lrbanddesignintf.h"
namespace LimeReport {
class TearOffBand : public BandDesignIntf
{
Q_OBJECT
public:
TearOffBand(QObject* owner = 0, QGraphicsItem *parent=0);
virtual BaseDesignIntf* createSameTypeItem(QObject* owner=0, QGraphicsItem* parent=0);
protected:
QColor bandColor() const;
bool isUnique(){ return true;}
};
} // namespace LimeReport
#endif // TEAROFFBAND_H

View File

@ -19,6 +19,7 @@ SOURCES += \
$$REPORT_PATH/bands/lrdataband.cpp \
$$REPORT_PATH/bands/lrgroupbands.cpp \
$$REPORT_PATH/bands/lrsubdetailband.cpp \
$$REPORT_PATH/bands/lrtearoffband.cpp \
$$REPORT_PATH/objectinspector/lrobjectinspectorwidget.cpp \
$$REPORT_PATH/objectinspector/lrobjectitemmodel.cpp \
$$REPORT_PATH/objectinspector/lrobjectpropitem.cpp \
@ -89,6 +90,7 @@ SOURCES += \
$$REPORT_PATH/lraboutdialog.cpp \
$$REPORT_PATH/lrsettingdialog.cpp
contains(CONFIG, zint){
SOURCES += $$REPORT_PATH/items/lrbarcodeitem.cpp
}
@ -100,6 +102,7 @@ HEADERS += \
$$REPORT_PATH/bands/lrreportheader.h \
$$REPORT_PATH/bands/lrreportfooter.h \
$$REPORT_PATH/bands/lrdataband.h \
$$REPORT_PATH/bands/lrtearoffband.h \
$$REPORT_PATH/objectinspector/lrobjectinspectorwidget.h \
$$REPORT_PATH/objectinspector/lrobjectitemmodel.h \
$$REPORT_PATH/objectinspector/lrobjectpropitem.h \
@ -160,6 +163,7 @@ HEADERS += \
$$REPORT_PATH/lrreportrender.h \
$$REPORT_PATH/lrpreviewreportwindow.h \
$$REPORT_PATH/lrpreviewreportwidget.h \
$$REPORT_PATH/lrpreviewreportwidget_p.h \
$$REPORT_PATH/lrgraphicsviewzoom.h \
$$REPORT_PATH/objectinspector/propertyItems/lrfontpropitem.h \
$$REPORT_PATH/objectinspector/editors/lrfonteditor.h \
@ -182,8 +186,7 @@ HEADERS += \
$$REPORT_PATH/lrsimplecrypt.h \
$$REPORT_PATH/lraboutdialog.h \
$$REPORT_PATH/lrcallbackdatasourceintf.h \
$$REPORT_PATH/lrsettingdialog.h \
$$PWD/lrpreviewreportwidget_p.h
$$REPORT_PATH/lrsettingdialog.h
contains(CONFIG,zint){
HEADERS += $$REPORT_PATH/items/lrbarcodeitem.h

View File

@ -110,7 +110,8 @@ public:
GroupFooter=8,
DataFooter=9,
ReportFooter=10,
PageFooter=11
TearOffBand=11,
PageFooter=12
};
enum BandColumnsLayoutType{

View File

@ -37,6 +37,7 @@
#include "lrdataband.h"
#include "lrsubdetailband.h"
#include "lrgroupbands.h"
#include "lrtearoffband.h"
namespace LimeReport{
@ -90,6 +91,8 @@ BandDesignIntf *BandsManager::createBand(BandDesignIntf::BandsType bandType, QOb
return new DataHeaderBand(owner, parent);
case BandDesignIntf::DataFooter:
return new DataFooterBand(owner, parent);
case BandDesignIntf::TearOffBand:
return new TearOffBand(owner, parent);
}
return 0;

View File

@ -336,14 +336,26 @@ void PageItemDesignIntf::relocateBands()
qSort(m_bands.begin(),m_bands.end(),bandSortBandLessThenByIndex);
if (m_bands.count()>0) {
initColumnsPos(posByColumn,pageRect().y(),m_bands[0]->columnsCount());
m_bands[0]->setPos(pageRect().x(),pageRect().y());
posByColumn[0]+=m_bands[0]->height()+bandSpace;
int bandIndex = 0;
if (!(itemMode() & DesignMode)){
while ( (bandIndex < m_bands.count()) &&
((m_bands[bandIndex]->bandType() == BandDesignIntf::TearOffBand) ||
(m_bands[bandIndex]->bandType() == BandDesignIntf::PageFooter))
){
bandIndex++;
}
}
if ( (m_bands.count()>0) && (bandIndex<m_bands.count()) ) {
initColumnsPos(posByColumn,pageRect().y(),m_bands[bandIndex]->columnsCount());
m_bands[bandIndex]->setPos(pageRect().x(),pageRect().y());
posByColumn[0]+=m_bands[bandIndex]->height()+bandSpace;
}
if(m_bands.count()>1){
for(int i=0;i<(m_bands.count()-1);i++){
if ((m_bands[i+1]->bandType()!=BandDesignIntf::PageFooter) || (itemMode() & DesignMode)){
if (((m_bands[i+1]->bandType()!=BandDesignIntf::PageFooter) &&
(m_bands[i+1]->bandType()!=BandDesignIntf::TearOffBand)) || (itemMode() & DesignMode)){
if (m_bands[i+1]->columnsCount()>1 &&
m_bands[i]->columnsCount() != m_bands[i+1]->columnsCount())
{

View File

@ -164,7 +164,7 @@ QSettings*PreviewReportWindow::settings()
}
}
void PreviewReportWindow::setReportReader(ItemsReaderIntf::Ptr reader)
void PreviewReportWindow::setReportReader(ItemsReaderIntf::Ptr /*reader*/)
{
// m_reader=reader;
// if (!reader.isNull()){

View File

@ -390,6 +390,11 @@ void ReportDesignWindow::createBandsButton()
m_bandsAddSignalsMap->setMapping(m_newGroupFooter,BandDesignIntf::GroupFooter);
m_newBandButton->addAction(m_newGroupFooter);
m_newTearOffBand=new QAction(QIcon(),tr("Tear-off Band"),this);
connect(m_newTearOffBand,SIGNAL(triggered()),m_bandsAddSignalsMap,SLOT(map()));
m_bandsAddSignalsMap->setMapping(m_newTearOffBand,BandDesignIntf::TearOffBand);
m_newBandButton->addAction(m_newTearOffBand);
connect(m_bandsAddSignalsMap,SIGNAL(mapped(int)),this,SLOT(slotNewBand(int)));
}
@ -983,6 +988,8 @@ void ReportDesignWindow::slotBandAdded(PageDesignIntf *, BandDesignIntf * band)
break;
case BandDesignIntf::ReportFooter:
m_newReportFooter->setDisabled(true);
case BandDesignIntf::TearOffBand:
m_newTearOffBand->setDisabled(true);
default:
break;
}
@ -1004,6 +1011,8 @@ void ReportDesignWindow::slotBandDeleted(PageDesignIntf *, BandDesignIntf *band)
break;
case BandDesignIntf::ReportFooter:
m_newReportFooter->setEnabled(true);
case BandDesignIntf::TearOffBand:
m_newTearOffBand->setEnabled(true);
default:
break;
}

View File

@ -187,6 +187,7 @@ private:
QAction* m_newSubDetailFooter;
QAction* m_newGroupHeader;
QAction* m_newGroupFooter;
QAction* m_newTearOffBand;
QAction* m_aboutAction;
QAction* m_editLayoutMode;
QAction* m_addHLayout;

View File

@ -170,8 +170,11 @@ void ReportRender::initDatasources(){
void ReportRender::initDatasource(const QString& name){
try{
if (datasources()->containsDatasource(name))
datasources()->dataSource(name)->first();
if (datasources()->containsDatasource(name)){
IDataSource* ds = datasources()->dataSource(name);
if (ds)
ds->first();
}
} catch(ReportError &exception){
QMessageBox::critical(0,tr("Error"),exception.what());
return;
@ -211,7 +214,11 @@ void ReportRender::renderPage(PageDesignIntf* patternPage)
if (lastRenderedBand && lastRenderedBand->keepFooterTogether())
closeFooterGroup(lastRenderedBand);
savePage();
BandDesignIntf* tearOffBand = m_patternPageItem->bandByType(BandDesignIntf::TearOffBand);
if (tearOffBand)
renderBand(tearOffBand,StartNewPageAsNeeded);
savePage(true);
if (!m_renderCanceled)
secondRenderPass();
}
@ -461,7 +468,12 @@ void ReportRender::renderDataBand(BandDesignIntf *dataBand)
void ReportRender::renderPageHeader(PageItemDesignIntf *patternPage)
{
BandDesignIntf* band = patternPage->bandByType(BandDesignIntf::PageHeader);
if (band) renderBand(band);
if (band){
if (m_datasources->variable("#PAGE").toInt()!=1 ||
band->property("printOnFirstPage").toBool()
)
renderBand(band);
}
}
void ReportRender::renderPageFooter(PageItemDesignIntf *patternPage)
@ -497,6 +509,9 @@ qreal ReportRender::calcPageFooterHeight(PageItemDesignIntf *patternPage)
{
BandDesignIntf* band = patternPage->bandByType(BandDesignIntf::PageFooter);
if (band){
if (m_datasources->variable("#PAGE")!=1)
return band->height();
else if (band->property("printOnFirstPage").toBool())
return band->height();
}
return 0;
@ -988,10 +1003,12 @@ void ReportRender::checkLostHeadersOnPrevPage()
QMutableListIterator<BandDesignIntf*>it(page->bands());
it.toBack();
if (it.hasPrevious())
if (it.previous()->isFooter())
if (it.hasPrevious()){
if (it.previous()->isFooter()){
if (it.hasPrevious()) it.previous();
else return;
}
}
while (it.hasPrevious()){
if (it.value()->isHeader()){
@ -1022,13 +1039,36 @@ BandDesignIntf* ReportRender::findEnclosingGroup()
return result;
}
void ReportRender::savePage()
void ReportRender::moveTearOffBand(){
BandDesignIntf* tearOffBand = m_renderPageItem->bandByType(BandDesignIntf::TearOffBand);
if (tearOffBand){
BandDesignIntf* pageFooter = m_renderPageItem->bandByType(BandDesignIntf::PageFooter);
if (pageFooter){
tearOffBand->setItemPos(m_patternPageItem->pageRect().x(),
m_patternPageItem->pageRect().bottom()-(tearOffBand->height()+pageFooter->height()));
} else {
tearOffBand->setItemPos(m_patternPageItem->pageRect().x(),m_patternPageItem->pageRect().bottom()-tearOffBand->height());
}
}
}
void ReportRender::savePage(bool isLast)
{
checkFooterGroup(m_lastDataBand);
cutGroups();
rearrangeColumnsItems();
m_columnedBandItems.clear();
BandDesignIntf* pf = m_patternPageItem->bandByType(BandDesignIntf::PageFooter);
if (pf && m_datasources->variable("#PAGE").toInt()!=1 && !isLast){
renderPageFooter(m_patternPageItem);
} else {
if (pf && pf->property("printOnFirstPage").toBool() && m_datasources->variable("#PAGE").toInt()==1){
renderPageFooter(m_patternPageItem);
} else if(pf && pf->property("printOnLastPage").toBool() && isLast){
renderPageFooter(m_patternPageItem);
}
}
if (m_ranges.last().lastPage==0 && m_ranges.count()>1) {
m_datasources->setReportVariable("#PAGE",1);
@ -1043,6 +1083,15 @@ void ReportRender::savePage()
m_renderedPages.append(PageItemDesignIntf::Ptr(m_renderPageItem));
emit pageRendered(m_pageCount);
m_pageCount++;
if (isLast){
BandDesignIntf* ph = m_renderPageItem->bandByType(BandDesignIntf::PageHeader);
if (ph && !ph->property("printOnLastPage").toBool()){
delete ph;
}
}
moveTearOffBand();
}
QString ReportRender::toString()

View File

@ -93,6 +93,7 @@ private:
void renderDataBand(BandDesignIntf* dataBand);
void renderPageHeader(PageItemDesignIntf* patternPage);
void renderPageFooter(PageItemDesignIntf* patternPage);
void moveTearOffBand();
void renderPageItems(PageItemDesignIntf* patternPage);
qreal calcPageFooterHeight(PageItemDesignIntf* patternPage);
qreal calcSlicePercent(qreal height);
@ -130,7 +131,7 @@ private:
void startNewPage();
void resetPageNumber();
int findLastPageNumber(int currentPage);
void savePage();
void savePage(bool isLast = false);
QString toString();
void initColumns();
bool isNeedToRearrangeColumnsItems();
@ -171,6 +172,7 @@ private:
QVector<BandDesignIntf*> m_columnedBandItems;
unsigned long long m_curentNameIndex;
};
} // namespace LimeReport
#endif // LRREPORTRENDER_H