diff --git a/limereport/bands/lrgroupbands.cpp b/limereport/bands/lrgroupbands.cpp index 57624eb..316e03e 100644 --- a/limereport/bands/lrgroupbands.cpp +++ b/limereport/bands/lrgroupbands.cpp @@ -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->data(m_groupFiledName).isNull() && m_groupFieldValue.isNull()) return false; - return ds->data(m_groupFiledName)!=m_groupFieldValue; + 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)); } diff --git a/limereport/bands/lrpagefooter.cpp b/limereport/bands/lrpagefooter.cpp index 5974abf..8df5c37 100644 --- a/limereport/bands/lrpagefooter.cpp +++ b/limereport/bands/lrpagefooter.cpp @@ -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 diff --git a/limereport/bands/lrpagefooter.h b/limereport/bands/lrpagefooter.h index 8987317..c8d4b81 100644 --- a/limereport/bands/lrpagefooter.h +++ b/limereport/bands/lrpagefooter.h @@ -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; }; } diff --git a/limereport/bands/lrpageheader.cpp b/limereport/bands/lrpageheader.cpp index df3fa22..895c53d 100644 --- a/limereport/bands/lrpageheader.cpp +++ b/limereport/bands/lrpageheader.cpp @@ -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; +} + } diff --git a/limereport/bands/lrpageheader.h b/limereport/bands/lrpageheader.h index dbbb6f5..b078ae1 100644 --- a/limereport/bands/lrpageheader.h +++ b/limereport/bands/lrpageheader.h @@ -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 diff --git a/limereport/bands/lrsubdetailband.h b/limereport/bands/lrsubdetailband.h index ab0340f..499e5e3 100644 --- a/limereport/bands/lrsubdetailband.h +++ b/limereport/bands/lrsubdetailband.h @@ -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; diff --git a/limereport/bands/lrtearoffband.cpp b/limereport/bands/lrtearoffband.cpp new file mode 100644 index 0000000..61b7e79 --- /dev/null +++ b/limereport/bands/lrtearoffband.cpp @@ -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 diff --git a/limereport/bands/lrtearoffband.h b/limereport/bands/lrtearoffband.h new file mode 100644 index 0000000..d1ee19b --- /dev/null +++ b/limereport/bands/lrtearoffband.h @@ -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 diff --git a/limereport/limereport.pri b/limereport/limereport.pri index 8b82707..ae11f9e 100644 --- a/limereport/limereport.pri +++ b/limereport/limereport.pri @@ -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 \ @@ -88,6 +89,7 @@ SOURCES += \ $$REPORT_PATH/lrsimplecrypt.cpp \ $$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,9 +186,8 @@ 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 } diff --git a/limereport/lrbanddesignintf.h b/limereport/lrbanddesignintf.h index 2ae0d8f..5e1b7d4 100644 --- a/limereport/lrbanddesignintf.h +++ b/limereport/lrbanddesignintf.h @@ -110,7 +110,8 @@ public: GroupFooter=8, DataFooter=9, ReportFooter=10, - PageFooter=11 + TearOffBand=11, + PageFooter=12 }; enum BandColumnsLayoutType{ diff --git a/limereport/lrbandsmanager.cpp b/limereport/lrbandsmanager.cpp index 9e009de..25ba344 100644 --- a/limereport/lrbandsmanager.cpp +++ b/limereport/lrbandsmanager.cpp @@ -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; diff --git a/limereport/lrpageitemdesignintf.cpp b/limereport/lrpageitemdesignintf.cpp index 50c4241..17afe41 100644 --- a/limereport/lrpageitemdesignintf.cpp +++ b/limereport/lrpageitemdesignintf.cpp @@ -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) && (bandIndexcolumnsCount()); + 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()) { diff --git a/limereport/lrpreviewreportwindow.cpp b/limereport/lrpreviewreportwindow.cpp index 788ab5b..3b7a930 100644 --- a/limereport/lrpreviewreportwindow.cpp +++ b/limereport/lrpreviewreportwindow.cpp @@ -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()){ diff --git a/limereport/lrreportdesignwindow.cpp b/limereport/lrreportdesignwindow.cpp index b0ebae7..8dd3815 100644 --- a/limereport/lrreportdesignwindow.cpp +++ b/limereport/lrreportdesignwindow.cpp @@ -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; } diff --git a/limereport/lrreportdesignwindow.h b/limereport/lrreportdesignwindow.h index d70f4a9..b732c25 100644 --- a/limereport/lrreportdesignwindow.h +++ b/limereport/lrreportdesignwindow.h @@ -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; diff --git a/limereport/lrreportrender.cpp b/limereport/lrreportrender.cpp index 89c03d1..7cf8b98 100644 --- a/limereport/lrreportrender.cpp +++ b/limereport/lrreportrender.cpp @@ -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,7 +509,10 @@ qreal ReportRender::calcPageFooterHeight(PageItemDesignIntf *patternPage) { BandDesignIntf* band = patternPage->bandByType(BandDesignIntf::PageFooter); if (band){ - return band->height(); + 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() QMutableListIteratorit(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(); - renderPageFooter(m_patternPageItem); + + 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() diff --git a/limereport/lrreportrender.h b/limereport/lrreportrender.h index 74bc011..25aa6ab 100644 --- a/limereport/lrreportrender.h +++ b/limereport/lrreportrender.h @@ -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 m_columnedBandItems; unsigned long long m_curentNameIndex; + }; } // namespace LimeReport #endif // LRREPORTRENDER_H