Finish 1.5.14

This commit is contained in:
Arin Alexander 2019-10-12 23:11:38 +03:00
commit 1c7a06a410
16 changed files with 211 additions and 130 deletions

View File

@ -127,7 +127,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 = 13 LIMEREPORT_VERSION_RELEASE = 14
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

@ -52,6 +52,7 @@ namespace LimeReport {
namespace Const{ namespace Const{
int const DEFAULT_GRID_STEP = 1;
int const RESIZE_HANDLE_SIZE = 5; int const RESIZE_HANDLE_SIZE = 5;
int const SELECTION_PEN_SIZE = 1; int const SELECTION_PEN_SIZE = 1;
int const MINIMUM_ITEM_WIDTH = 2*RESIZE_HANDLE_SIZE; int const MINIMUM_ITEM_WIDTH = 2*RESIZE_HANDLE_SIZE;

View File

@ -212,6 +212,11 @@ signals:
void renderStarted(); void renderStarted();
void renderFinished(); void renderFinished();
void renderPageFinished(int renderedPageCount); void renderPageFinished(int renderedPageCount);
void printingStarted(int pageCount);
void printingFinished();
void pagePrintingFinished(int index);
void onSave(bool& saved); void onSave(bool& saved);
void onSaveAs(bool& saved); void onSaveAs(bool& saved);
void onLoad(bool& loaded); void onLoad(bool& loaded);

View File

@ -27,7 +27,7 @@ bool PDFExporter::exportPages(ReportPages pages, const QString &fileName, const
printer.setOutputFileName(fileName); printer.setOutputFileName(fileName);
printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFormat(QPrinter::PdfFormat);
if (!pages.isEmpty()){ if (!pages.isEmpty()){
m_reportEngine->printReport(pages, printer); m_reportEngine->printPages(pages, &printer);
} }
m_reportEngine->emitPrintedToPDF(fileName); m_reportEngine->emitPrintedToPDF(fileName);
return true; return true;

View File

@ -166,7 +166,8 @@ BandDesignIntf::BandDesignIntf(BandsType bandType, const QString &xmlTypeName, Q
m_printAlways(false), m_printAlways(false),
m_repeatOnEachRow(false), m_repeatOnEachRow(false),
m_useAlternateBackgroundColor(false), m_useAlternateBackgroundColor(false),
m_bottomSpace(0) m_bottomSpace(0),
m_shiftItems(0)
{ {
setPossibleResizeDirectionFlags(ResizeBottom); setPossibleResizeDirectionFlags(ResizeBottom);
setPossibleMoveFlags(TopBotom); setPossibleMoveFlags(TopBotom);
@ -277,6 +278,11 @@ void BandDesignIntf::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
BaseDesignIntf::paint(painter,option,widget); BaseDesignIntf::paint(painter,option,widget);
} }
QRectF BandDesignIntf::boundingRect() const
{
return ItemsContainerDesignInft::boundingRect().adjusted(0,-4,0,4);
}
void BandDesignIntf::translateBandsName() void BandDesignIntf::translateBandsName()
{ {
tr("DataBand"); tr("DataBand");
@ -582,14 +588,14 @@ void BandDesignIntf::preparePopUpMenu(QMenu &menu)
currAction->setCheckable(true); currAction->setCheckable(true);
currAction->setChecked(isSplittable()); currAction->setChecked(isSplittable());
currAction = menu.addAction(tr("Keep bottom space"));
currAction->setCheckable(true);
currAction->setChecked(keepBottomSpace());
currAction = menu.addAction(tr("Keep top space")); currAction = menu.addAction(tr("Keep top space"));
currAction->setCheckable(true); currAction->setCheckable(true);
currAction->setChecked(keepTopSpace()); currAction->setChecked(keepTopSpace());
currAction = menu.addAction(tr("Keep bottom space"));
currAction->setCheckable(true);
currAction->setChecked(keepBottomSpace());
currAction = menu.addAction(tr("Print if empty")); currAction = menu.addAction(tr("Print if empty"));
currAction->setCheckable(true); currAction->setCheckable(true);
currAction->setChecked(printIfEmpty()); currAction->setChecked(printIfEmpty());
@ -599,20 +605,26 @@ void BandDesignIntf::preparePopUpMenu(QMenu &menu)
void BandDesignIntf::processPopUpAction(QAction *action) void BandDesignIntf::processPopUpAction(QAction *action)
{ {
if (action->text().compare(tr("Auto height")) == 0){ if (action->text().compare(tr("Auto height")) == 0){
setProperty("autoHeight",action->isChecked()); setProperty("autoHeight", action->isChecked());
} }
if (action->text().compare(tr("Splittable")) == 0){ if (action->text().compare(tr("Splittable")) == 0){
setProperty("splittable",action->isChecked()); setProperty("splittable", action->isChecked());
} }
if (action->text().compare(tr("Keep top space")) == 0){
setProperty("keepTopSpace", action->isChecked());
}
if (action->text().compare(tr("Keep bottom space")) == 0){ if (action->text().compare(tr("Keep bottom space")) == 0){
setProperty("keepBottomSpace",action->isChecked()); setProperty("keepBottomSpace", action->isChecked());
} }
if (action->text().compare(tr("Keep top space")) == 0){ if (action->text().compare(tr("Keep top space")) == 0){
setProperty("keepTopSpace",action->isChecked()); setProperty("keepTopSpace",action->isChecked());
} }
if (action->text().compare(tr("Print if empty")) == 0){ if (action->text().compare(tr("Print if empty")) == 0){
setProperty("printIfEmpty",action->isChecked()); setProperty("printIfEmpty", action->isChecked());
} }
ItemsContainerDesignInft::processPopUpAction(action); ItemsContainerDesignInft::processPopUpAction(action);
} }
@ -910,6 +922,16 @@ void BandDesignIntf::slotPropertyObjectNameChanged(const QString &, const QStrin
m_bandNameLabel->updateLabel(newName); m_bandNameLabel->updateLabel(newName);
} }
int BandDesignIntf::shiftItems() const
{
return m_shiftItems;
}
void BandDesignIntf::setShiftItems(int shiftItems)
{
m_shiftItems = shiftItems;
}
bool BandDesignIntf::keepTopSpace() const bool BandDesignIntf::keepTopSpace() const
{ {
return m_keepTopSpace; return m_keepTopSpace;
@ -1112,7 +1134,7 @@ void BandDesignIntf::updateItemSize(DataSourceManager* dataManager, RenderPass p
arrangeSubItems(pass, dataManager); arrangeSubItems(pass, dataManager);
if (autoHeight()){ if (autoHeight()){
if (!keepTopSpace()) { if (!keepTopSpace()) {
qreal minTop = findMinTop() - spaceBorder; qreal minTop = findMinTop() + m_shiftItems;
foreach (BaseDesignIntf* item, childBaseItems()) { foreach (BaseDesignIntf* item, childBaseItems()) {
item->setY(item->y() - minTop); item->setY(item->y() - minTop);
} }

View File

@ -113,6 +113,7 @@ class BandDesignIntf : public ItemsContainerDesignInft
Q_PROPERTY(bool printIfEmpty READ printIfEmpty WRITE setPrintIfEmpty) Q_PROPERTY(bool printIfEmpty READ printIfEmpty WRITE setPrintIfEmpty)
Q_PROPERTY(BGMode backgroundMode READ backgroundMode WRITE setBackgroundModeProperty) Q_PROPERTY(BGMode backgroundMode READ backgroundMode WRITE setBackgroundModeProperty)
Q_PROPERTY(int backgroundOpacity READ opacity WRITE setBackgroundOpacity) Q_PROPERTY(int backgroundOpacity READ opacity WRITE setBackgroundOpacity)
Q_PROPERTY(int shiftItems READ shiftItems WRITE setShiftItems)
Q_ENUMS(BandColumnsLayoutType) Q_ENUMS(BandColumnsLayoutType)
friend class BandMarker; friend class BandMarker;
friend class BandNameLabel; friend class BandNameLabel;
@ -142,6 +143,7 @@ public:
~BandDesignIntf(); ~BandDesignIntf();
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
QRectF boundingRect() const;
void translateBandsName(); void translateBandsName();
virtual BandsType bandType() const; virtual BandsType bandType() const;
virtual QString bandTitle() const; virtual QString bandTitle() const;
@ -260,6 +262,8 @@ public:
int bootomSpace() const; int bootomSpace() const;
void setBootomSpace(int bootomSpace); void setBootomSpace(int bootomSpace);
void updateBandMarkerGeometry(); void updateBandMarkerGeometry();
int shiftItems() const;
void setShiftItems(int shiftItems);
signals: signals:
void bandRendered(BandDesignIntf* band); void bandRendered(BandDesignIntf* band);
@ -323,6 +327,7 @@ private:
bool m_useAlternateBackgroundColor; bool m_useAlternateBackgroundColor;
int m_bottomSpace; int m_bottomSpace;
QMap<QString,QVariant> m_bookmarks; QMap<QString,QVariant> m_bookmarks;
int m_shiftItems;
}; };
class DataBandDesignIntf : public BandDesignIntf{ class DataBandDesignIntf : public BandDesignIntf{

View File

@ -52,6 +52,7 @@ namespace LimeReport {
namespace Const{ namespace Const{
int const DEFAULT_GRID_STEP = 1;
int const RESIZE_HANDLE_SIZE = 5; int const RESIZE_HANDLE_SIZE = 5;
int const SELECTION_PEN_SIZE = 1; int const SELECTION_PEN_SIZE = 1;
int const MINIMUM_ITEM_WIDTH = 2*RESIZE_HANDLE_SIZE; int const MINIMUM_ITEM_WIDTH = 2*RESIZE_HANDLE_SIZE;

View File

@ -83,8 +83,8 @@ PageDesignIntf::PageDesignIntf(QObject *parent):
m_executingGroupCommand(false), m_executingGroupCommand(false),
m_settings(0), m_settings(0),
m_selectionRect(0), m_selectionRect(0),
m_verticalGridStep(2), m_verticalGridStep(Const::DEFAULT_GRID_STEP),
m_horizontalGridStep(2), m_horizontalGridStep(Const::DEFAULT_GRID_STEP),
m_updating(false), m_updating(false),
m_currentObjectIndex(1), m_currentObjectIndex(1),
m_multiSelectStarted(false), m_multiSelectStarted(false),

View File

@ -1011,7 +1011,7 @@ void PageItemDesignIntf::setGridStep(int value)
int PageItemDesignIntf::gridStep() int PageItemDesignIntf::gridStep()
{ {
if (page()) return page()->horizontalGridStep(); if (page()) return page()->horizontalGridStep();
else return 2; else return Const::DEFAULT_GRID_STEP;
} }
void PageItemDesignIntf::objectLoadFinished() void PageItemDesignIntf::objectLoadFinished()

View File

@ -222,9 +222,9 @@ void PreviewReportWidget::lastPage()
void PreviewReportWidget::printPages(QPrinter* printer) void PreviewReportWidget::printPages(QPrinter* printer)
{ {
if (!d_ptr->m_reportPages.isEmpty()) if (!d_ptr->m_reportPages.isEmpty())
ReportEnginePrivate::printReport( d_ptr->m_report->printPages(
d_ptr->m_reportPages, d_ptr->m_reportPages,
*printer printer
); );
foreach(PageItemDesignIntf::Ptr pageItem, d_ptr->m_reportPages){ foreach(PageItemDesignIntf::Ptr pageItem, d_ptr->m_reportPages){
d_ptr->m_previewPage->reactivatePageItem(pageItem); d_ptr->m_previewPage->reactivatePageItem(pageItem);

View File

@ -820,8 +820,8 @@ void ReportDesignWidget::editSetting()
void ReportDesignWidget::applyUseGrid() void ReportDesignWidget::applyUseGrid()
{ {
int hGridStep = m_useGrid ? m_horizontalGridStep : 2; int hGridStep = m_useGrid ? m_horizontalGridStep : Const::DEFAULT_GRID_STEP;
int vGridStep = m_useGrid ? m_verticalGridStep : 2; int vGridStep = m_useGrid ? m_verticalGridStep : Const::DEFAULT_GRID_STEP;
for(int i = 0; i < m_report->pageCount(); ++i){ for(int i = 0; i < m_report->pageCount(); ++i){
m_report->pageAt(i)->setVerticalGridStep(hGridStep); m_report->pageAt(i)->setVerticalGridStep(hGridStep);
m_report->pageAt(i)->setHorizontalGridStep(vGridStep); m_report->pageAt(i)->setHorizontalGridStep(vGridStep);

View File

@ -264,63 +264,75 @@ void ReportEnginePrivate::clearReport()
emit cleared(); emit cleared();
} }
void ReportEnginePrivate::printReport(ItemsReaderIntf::Ptr reader, QPrinter& printer) bool ReportEnginePrivate::printPages(ReportPages pages, QPrinter *printer)
{ {
LimeReport::PageDesignIntf renderPage; if (!printer&&!m_printerSelected){
renderPage.setItemMode(PrintMode); QPrinterInfo pi;
if (reader->first()){ if (!pi.defaultPrinter().isNull())
reader->readItem(renderPage.pageItem()); #ifdef HAVE_QT4
printer.setFullPage(renderPage.pageItem()->fullPage()); m_printer.data()->setPrinterName(pi.defaultPrinter().printerName());
printer.setOrientation((QPrinter::Orientation)renderPage.pageItem()->pageOrientation()); #endif
renderPage.setSceneRect(renderPage.pageItem()->mapToScene(renderPage.pageItem()->rect()).boundingRect()); #ifdef HAVE_QT5
#if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0))
if (renderPage.pageItem()->pageSize()==PageItemDesignIntf::Custom){ m_printer.data()->setPrinterName(pi.defaultPrinterName());
QSizeF pageSize = (renderPage.pageItem()->pageOrientation()==PageItemDesignIntf::Landscape)? #else
QSizeF(renderPage.pageItem()->sizeMM().height(),renderPage.pageItem()->sizeMM().width()): m_printer.data()->setPrinterName(pi.defaultPrinter().printerName());
renderPage.pageItem()->sizeMM(); #endif
printer.setPaperSize(pageSize,QPrinter::Millimeter); #endif
} else { QPrintDialog dialog(m_printer.data(),QApplication::activeWindow());
printer.setPaperSize((QPrinter::PageSize)renderPage.pageItem()->pageSize()); m_printerSelected = dialog.exec()!=QDialog::Rejected;
}
QPainter painter(&printer);
renderPage.render(&painter);
while (reader->next()){
printer.newPage();
renderPage.removeAllItems();
reader->readItem(renderPage.pageItem());
renderPage.setSceneRect(renderPage.pageItem()->mapToScene(renderPage.pageItem()->rect()).boundingRect());
renderPage.render(&painter);
}
} }
if (!printer&&!m_printerSelected) return false;
printer =(printer)?printer:m_printer.data();
if (printer&&printer->isValid()){
try{
if (pages.count()>0){
internalPrintPages(
pages,
*printer
);
}
} catch(ReportError &exception){
saveError(exception.what());
}
return true;
} else return false;
} }
void ReportEnginePrivate::printReport(ReportPages pages, QPrinter &printer) void ReportEnginePrivate::internalPrintPages(ReportPages pages, QPrinter &printer)
{ {
m_cancelPrinting = false;
int currenPage = 1; int currenPage = 1;
QMap<QString, QSharedPointer<PrintProcessor> > printProcessors; QMap<QString, QSharedPointer<PrintProcessor> > printProcessors;
printProcessors.insert("default",QSharedPointer<PrintProcessor>(new PrintProcessor(&printer))); printProcessors.insert("default",QSharedPointer<PrintProcessor>(new PrintProcessor(&printer)));
emit printingStarted(printer.toPage() - printer.fromPage());
foreach(PageItemDesignIntf::Ptr page, pages){ foreach(PageItemDesignIntf::Ptr page, pages){
if ( if ( !m_cancelPrinting &&
(printer.printRange() == QPrinter::AllPages) || ((printer.printRange() == QPrinter::AllPages) ||
( (printer.printRange()==QPrinter::PageRange) && ( (printer.printRange()==QPrinter::PageRange) &&
(currenPage>=printer.fromPage()) && (currenPage>=printer.fromPage()) &&
(currenPage<=printer.toPage()) (currenPage<=printer.toPage())
) ))
) )
{ {
printProcessors["default"]->printPage(page); printProcessors["default"]->printPage(page);
currenPage++;
emit pagePrintingFinished(currenPage);
QApplication::processEvents();
} }
currenPage++;
} }
emit printingFinished();
} }
void ReportEnginePrivate::printReport(ReportPages pages, QMap<QString, QPrinter*> printers, bool printToAllPrinters) void ReportEnginePrivate::printPages(ReportPages pages, QMap<QString, QPrinter*> printers, bool printToAllPrinters)
{ {
if (printers.values().isEmpty()) return; if (printers.values().isEmpty()) return;
int currenPage = 1; m_cancelPrinting = false;
QMap<QString, QSharedPointer<PrintProcessor> > printProcessors;
QMap<QString, QSharedPointer<PrintProcessor>> printProcessors;
for (int i = 0; i < printers.keys().count(); ++i) { for (int i = 0; i < printers.keys().count(); ++i) {
printProcessors.insert(printers.keys()[i],QSharedPointer<PrintProcessor>(new PrintProcessor(printers[printers.keys()[i]]))); printProcessors.insert(printers.keys()[i],QSharedPointer<PrintProcessor>(new PrintProcessor(printers[printers.keys()[i]])));
} }
@ -329,7 +341,12 @@ void ReportEnginePrivate::printReport(ReportPages pages, QMap<QString, QPrinter*
int currentPrinter = 0; int currentPrinter = 0;
if (printProcessors.contains("default")) defaultProcessor = printProcessors["default"].data(); if (printProcessors.contains("default")) defaultProcessor = printProcessors["default"].data();
else defaultProcessor = printProcessors.values().at(0).data(); else defaultProcessor = printProcessors.values().at(0).data();
foreach(PageItemDesignIntf::Ptr page, pages){
emit printingStarted(pages.size());
for(int i = 0; i < pages.size(); ++i){
if (m_cancelPrinting) break;
PageItemDesignIntf::Ptr page = pages.at(i);
if (!printToAllPrinters){ if (!printToAllPrinters){
if (printProcessors.contains(page->printerName())) if (printProcessors.contains(page->printerName()))
printProcessors[page->printerName()]->printPage(page); printProcessors[page->printerName()]->printPage(page);
@ -340,9 +357,11 @@ void ReportEnginePrivate::printReport(ReportPages pages, QMap<QString, QPrinter*
currentPrinter++; currentPrinter++;
else currentPrinter = 0; else currentPrinter = 0;
} }
emit pagePrintingFinished(i+1);
currenPage++; QApplication::processEvents();
} }
emit printingFinished();
} }
QStringList ReportEnginePrivate::aviableReportTranslations() QStringList ReportEnginePrivate::aviableReportTranslations()
@ -391,7 +410,7 @@ bool ReportEnginePrivate::printReport(QPrinter* printer)
ReportPages pages = renderToPages(); ReportPages pages = renderToPages();
dataManager()->setDesignTime(designTime); dataManager()->setDesignTime(designTime);
if (pages.count()>0){ if (pages.count()>0){
printReport(pages,*printer); internalPrintPages(pages, *printer);
} }
} catch(ReportError &exception){ } catch(ReportError &exception){
saveError(exception.what()); saveError(exception.what());
@ -408,7 +427,7 @@ bool ReportEnginePrivate::printReport(QMap<QString, QPrinter*> printers, bool pr
ReportPages pages = renderToPages(); ReportPages pages = renderToPages();
dataManager()->setDesignTime(designTime); dataManager()->setDesignTime(designTime);
if (pages.count()>0){ if (pages.count()>0){
printReport(pages, printers, printToAllPrinters); printPages(pages, printers, printToAllPrinters);
} }
} catch(ReportError &exception){ } catch(ReportError &exception){
saveError(exception.what()); saveError(exception.what());
@ -417,42 +436,6 @@ bool ReportEnginePrivate::printReport(QMap<QString, QPrinter*> printers, bool pr
return true; return true;
} }
bool ReportEnginePrivate::printPages(ReportPages pages, QPrinter *printer)
{
if (!printer&&!m_printerSelected){
QPrinterInfo pi;
if (!pi.defaultPrinter().isNull())
#ifdef HAVE_QT4
m_printer.data()->setPrinterName(pi.defaultPrinter().printerName());
#endif
#ifdef HAVE_QT5
#if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0))
m_printer.data()->setPrinterName(pi.defaultPrinterName());
#else
m_printer.data()->setPrinterName(pi.defaultPrinter().printerName());
#endif
#endif
QPrintDialog dialog(m_printer.data(),QApplication::activeWindow());
m_printerSelected = dialog.exec()!=QDialog::Rejected;
}
if (!printer&&!m_printerSelected) return false;
printer =(printer)?printer:m_printer.data();
if (printer&&printer->isValid()){
try{
if (pages.count()>0){
printReport(
pages,
*printer
);
}
} catch(ReportError &exception){
saveError(exception.what());
}
return true;
} else return false;
}
void ReportEnginePrivate::printToFile(const QString &fileName) void ReportEnginePrivate::printToFile(const QString &fileName)
{ {
if (!fileName.isEmpty()){ if (!fileName.isEmpty()){
@ -739,6 +722,11 @@ void ReportEnginePrivate::cancelRender()
m_reportRendering = false; m_reportRendering = false;
} }
void ReportEnginePrivate::cancelPrinting()
{
m_cancelPrinting = true;
}
QGraphicsScene* ReportEngine::createPreviewScene(QObject* parent){ QGraphicsScene* ReportEngine::createPreviewScene(QObject* parent){
Q_D(ReportEngine); Q_D(ReportEngine);
return d->createPreviewScene(parent); return d->createPreviewScene(parent);
@ -1387,6 +1375,12 @@ ReportEngine::ReportEngine(QObject *parent)
connect(d, SIGNAL(renderPageFinished(int)), connect(d, SIGNAL(renderPageFinished(int)),
this, SIGNAL(renderPageFinished(int))); this, SIGNAL(renderPageFinished(int)));
connect(d, SIGNAL(renderFinished()), this, SIGNAL(renderFinished())); connect(d, SIGNAL(renderFinished()), this, SIGNAL(renderFinished()));
connect(d, SIGNAL(printingStarted(int)), this, SIGNAL(printingStarted(int)));
connect(d, SIGNAL(pagePrintingFinished(int)),
this, SIGNAL(pagePrintingFinished(int)));
connect(d, SIGNAL(printingFinished()), this, SIGNAL(printingFinished()));
connect(d, SIGNAL(onSave(bool&)), this, SIGNAL(onSave(bool&))); connect(d, SIGNAL(onSave(bool&)), this, SIGNAL(onSave(bool&)));
connect(d, SIGNAL(onSaveAs(bool&)), this, SIGNAL(onSaveAs(bool&))); connect(d, SIGNAL(onSaveAs(bool&)), this, SIGNAL(onSaveAs(bool&)));
connect(d, SIGNAL(onLoad(bool&)), this, SIGNAL(onLoad(bool&))); connect(d, SIGNAL(onLoad(bool&)), this, SIGNAL(onLoad(bool&)));
@ -1766,21 +1760,21 @@ ScriptEngineManager*LimeReport::ReportEnginePrivate::scriptManager(){
PrintProcessor::PrintProcessor(QPrinter* printer) PrintProcessor::PrintProcessor(QPrinter* printer)
: m_printer(printer), m_painter(0), m_firstPage(true) : m_printer(printer), m_painter(0), m_firstPage(true)
{} {m_renderPage.setItemMode(PrintMode);}
bool PrintProcessor::printPage(PageItemDesignIntf::Ptr page) bool PrintProcessor::printPage(PageItemDesignIntf::Ptr page)
{ {
if (!m_firstPage && !m_painter->isActive()) return false; if (!m_firstPage && !m_painter->isActive()) return false;
LimeReport::PageDesignIntf renderPage; //LimeReport::PageDesignIntf m_renderPage;
renderPage.setItemMode(PrintMode); //m_renderPage.setItemMode(PrintMode);
QPointF backupPagePos = page->pos(); QPointF backupPagePos = page->pos();
page->setPos(0,0); page->setPos(0,0);
renderPage.setPageItem(page); m_renderPage.setPageItem(page);
renderPage.setSceneRect(renderPage.pageItem()->mapToScene(renderPage.pageItem()->rect()).boundingRect()); m_renderPage.setSceneRect(m_renderPage.pageItem()->mapToScene(m_renderPage.pageItem()->rect()).boundingRect());
initPrinter(renderPage.pageItem()); initPrinter(m_renderPage.pageItem());
if (!m_firstPage){ if (!m_firstPage){
m_printer->newPage(); m_printer->newPage();
@ -1809,7 +1803,7 @@ bool PrintProcessor::printPage(PageItemDesignIntf::Ptr page)
while (pageHeight > 0){ while (pageHeight > 0){
while (curWidth < pageWidth){ while (curWidth < pageWidth){
if (!first) m_printer->newPage(); else first = false; if (!first) m_printer->newPage(); else first = false;
renderPage.render(m_painter, m_printer->pageRect(), currentPrintingRect); m_renderPage.render(m_painter, m_printer->pageRect(), currentPrintingRect);
currentPrintingRect.adjust(printerPageRect.size().width(), 0, printerPageRect.size().width(), 0); currentPrintingRect.adjust(printerPageRect.size().width(), 0, printerPageRect.size().width(), 0);
curWidth += printerPageRect.size().width(); curWidth += printerPageRect.size().width();
@ -1822,7 +1816,7 @@ bool PrintProcessor::printPage(PageItemDesignIntf::Ptr page)
} }
} else { } else {
renderPage.render(m_painter); m_renderPage.render(m_painter);
} }
page->setPos(backupPagePos); page->setPos(backupPagePos);
return true; return true;

View File

@ -212,6 +212,11 @@ signals:
void renderStarted(); void renderStarted();
void renderFinished(); void renderFinished();
void renderPageFinished(int renderedPageCount); void renderPageFinished(int renderedPageCount);
void printingStarted(int pageCount);
void printingFinished();
void pagePrintingFinished(int index);
void onSave(bool& saved); void onSave(bool& saved);
void onSaveAs(bool& saved); void onSaveAs(bool& saved);
void onLoad(bool& loaded); void onLoad(bool& loaded);

View File

@ -122,6 +122,7 @@ private:
private: private:
QPrinter* m_printer; QPrinter* m_printer;
QPainter* m_painter; QPainter* m_painter;
LimeReport::PageDesignIntf m_renderPage;
bool m_firstPage; bool m_firstPage;
}; };
@ -141,9 +142,8 @@ class ReportEnginePrivate : public QObject,
friend class PreviewReportWidget; friend class PreviewReportWidget;
public: public:
static void printReport(ItemsReaderIntf::Ptr reader, QPrinter &printer); bool printPages(ReportPages pages, QPrinter *printer);
static void printReport(ReportPages pages, QPrinter &printer); void printPages(ReportPages pages, QMap<QString,QPrinter*>printers, bool printToAllPrinters = false);
static void printReport(ReportPages pages, QMap<QString,QPrinter*>printers, bool printToAllPrinters = false);
Q_INVOKABLE QStringList aviableReportTranslations(); Q_INVOKABLE QStringList aviableReportTranslations();
Q_INVOKABLE void setReportTranslation(const QString& languageName); Q_INVOKABLE void setReportTranslation(const QString& languageName);
public: public:
@ -168,7 +168,7 @@ public:
void clearReport(); void clearReport();
bool printReport(QPrinter* printer=0); bool printReport(QPrinter* printer=0);
bool printReport(QMap<QString, QPrinter*>printers, bool printToAllPrinters); bool printReport(QMap<QString, QPrinter*>printers, bool printToAllPrinters);
bool printPages(ReportPages pages, QPrinter *printer);
void printToFile(const QString& fileName); void printToFile(const QString& fileName);
bool printToPDF(const QString& fileName); bool printToPDF(const QString& fileName);
bool exportReport(QString exporterName, const QString &fileName = "", const QMap<QString, QVariant>& params = QMap<QString, QVariant>()); bool exportReport(QString exporterName, const QString &fileName = "", const QMap<QString, QVariant>& params = QMap<QString, QVariant>());
@ -268,13 +268,18 @@ signals:
void currentDefaultDesignerLanguageChanged(QLocale::Language); void currentDefaultDesignerLanguageChanged(QLocale::Language);
QLocale::Language getCurrentDefaultDesignerLanguage(); QLocale::Language getCurrentDefaultDesignerLanguage();
void externalPaint(const QString& objectName, QPainter* painter, const QStyleOptionGraphicsItem*); void externalPaint(const QString& objectName, QPainter* painter, const QStyleOptionGraphicsItem*);
void printingStarted(int pageCount);
void printingFinished();
void pagePrintingFinished(int index);
public slots: public slots:
bool slotLoadFromFile(const QString& fileName); bool slotLoadFromFile(const QString& fileName);
void cancelRender(); void cancelRender();
void cancelPrinting();
protected: protected:
PageDesignIntf* createPage(const QString& pageName="", bool preview = false); PageDesignIntf* createPage(const QString& pageName="", bool preview = false);
bool showPreviewWindow(ReportPages pages, PreviewHints hints, QPrinter *printer); bool showPreviewWindow(ReportPages pages, PreviewHints hints, QPrinter *printer);
void internalPrintPages(ReportPages pages, QPrinter &printer);
protected slots: protected slots:
void slotDataSourceCollectionLoaded(const QString& collectionName); void slotDataSourceCollectionLoaded(const QString& collectionName);
private slots: private slots:
@ -344,6 +349,7 @@ private:
bool m_saveToFileVisible; bool m_saveToFileVisible;
bool m_printToPdfVisible; bool m_printToPdfVisible;
bool m_printVisible; bool m_printVisible;
bool m_cancelPrinting;
}; };
} }

View File

@ -189,11 +189,46 @@ void ReportRender::initDatasource(const QString& name){
} }
} }
void ReportRender::analizeItem(ContentItemDesignIntf* contentItem, BandDesignIntf* band){
if (contentItem){
QString content = contentItem->content();
QVector<QString> functions;
foreach(const QString &functionName, m_datasources->groupFunctionNames()){
QRegExp rx(QString(Const::GROUP_FUNCTION_RX).arg(functionName));
rx.setMinimal(true);
if (rx.indexIn(content)>=0){
functions.append(functionName);
}
}
if (functions.size()>0)
m_groupfunctionItems.insert(contentItem->patternName(), functions);
}
}
void ReportRender::analizeContainer(BaseDesignIntf* item, BandDesignIntf* band){
foreach(BaseDesignIntf* child, item->childBaseItems()){
ContentItemDesignIntf* contentItem = dynamic_cast<ContentItemDesignIntf*>(child);
if (contentItem) analizeItem(contentItem, band);
else analizeContainer(child, band);
}
}
void ReportRender::analizePage(PageItemDesignIntf* patternPage){
m_groupfunctionItems.clear();
foreach(BandDesignIntf* band, patternPage->bands()){
if (band->isFooter() || band->isHeader()){
analizeContainer(band,band);
}
}
}
void ReportRender::renderPage(PageItemDesignIntf* patternPage, bool isTOC, bool /*isFirst*/, bool /*resetPageNumbers*/) void ReportRender::renderPage(PageItemDesignIntf* patternPage, bool isTOC, bool /*isFirst*/, bool /*resetPageNumbers*/)
{ {
m_currentNameIndex = 0; m_currentNameIndex = 0;
m_patternPageItem = patternPage; m_patternPageItem = patternPage;
analizePage(patternPage);
if (m_patternPageItem->resetPageNumber() && m_pageCount>0 && !isTOC) { if (m_patternPageItem->resetPageNumber() && m_pageCount>0 && !isTOC) {
resetPageNumber(PageReset); resetPageNumber(PageReset);
} }
@ -380,33 +415,34 @@ void ReportRender::extractGroupFunctions(BandDesignIntf *band)
extractGroupFunctionsFromContainer(band, band); extractGroupFunctionsFromContainer(band, band);
} }
void ReportRender::replaceGroupFunctionsInItem(ContentItemDesignIntf* contentItem, BandDesignIntf* band){ void ReportRender::replaceGroupFunctionsInItem(ContentItemDesignIntf* contentItem, BandDesignIntf* band){
if (contentItem){ if (contentItem){
QString content = contentItem->content(); if (m_groupfunctionItems.contains(contentItem->patternName())){
foreach(const QString &functionName, m_datasources->groupFunctionNames()){ QString content = contentItem->content();
QRegExp rx(QString(Const::GROUP_FUNCTION_RX).arg(functionName)); foreach(QString functionName, m_groupfunctionItems.value(contentItem->patternName())){
rx.setMinimal(true); QRegExp rx(QString(Const::GROUP_FUNCTION_RX).arg(functionName));
if (rx.indexIn(content)>=0){ rx.setMinimal(true);
int pos = 0; if (rx.indexIn(content)>=0){
while ( (pos = rx.indexIn(content,pos))!= -1 ){ int pos = 0;
QVector<QString> captures = normalizeCaptures(rx); while ( (pos = rx.indexIn(content,pos))!= -1 ){
if (captures.size() >= 3){ QVector<QString> captures = normalizeCaptures(rx);
QString expressionIndex = datasources()->putGroupFunctionsExpressions(captures.at(Const::VALUE_INDEX)); if (captures.size() >= 3){
if (captures.size()<5){ QString expressionIndex = datasources()->putGroupFunctionsExpressions(captures.at(Const::VALUE_INDEX));
content.replace(captures.at(0),QString("%1(%2,%3)").arg(functionName).arg('"'+expressionIndex+'"').arg('"'+band->objectName()+'"')); if (captures.size()<5){
} else { 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,%4)") } else {
.arg(functionName) content.replace(captures.at(0),QString("%1(%2,%3,%4)")
.arg('"'+expressionIndex+'"') .arg(functionName)
.arg('"'+band->objectName()+'"') .arg('"'+expressionIndex+'"')
.arg(captures.at(4))); .arg('"'+band->objectName()+'"')
.arg(captures.at(4)));
}
} }
pos += rx.matchedLength();
} }
pos += rx.matchedLength();
} }
contentItem->setContent(content);
} }
contentItem->setContent(content);
} }
} }
} }

View File

@ -82,6 +82,7 @@ private:
int m_TOCRangeIndex; int m_TOCRangeIndex;
}; };
class ReportRender: public QObject class ReportRender: public QObject
{ {
Q_OBJECT Q_OBJECT
@ -109,6 +110,10 @@ signals:
public slots: public slots:
void cancelRender(); void cancelRender();
private: private:
void analizeContainer(BaseDesignIntf *item, BandDesignIntf *band);
void analizeItem(ContentItemDesignIntf *item, BandDesignIntf *band);
void analizePage(PageItemDesignIntf *patternPage);
void initDatasources(); void initDatasources();
void initDatasource(const QString &name); void initDatasource(const QString &name);
void initRenderPage(); void initRenderPage();
@ -193,7 +198,7 @@ private:
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_recalcBands;
QMap<QString, QVector<QString>> m_groupfunctionItems;
int m_currentIndex; int m_currentIndex;
int m_pageCount; int m_pageCount;
@ -217,6 +222,7 @@ private:
bool m_newPageStarted; bool m_newPageStarted;
bool m_lostHeadersMoved; bool m_lostHeadersMoved;
}; };
} // namespace LimeReport } // namespace LimeReport
#endif // LRREPORTRENDER_H #endif // LRREPORTRENDER_H