From 5a6ee275a75969abbbba34fdfb7a1664d4c73e8b Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Sat, 12 Oct 2019 22:31:35 +0300 Subject: [PATCH] Some band improvements have been added. Printing signals have been added. Render & printing speed little bit has been increased --- include/lrglobal.h | 1 + include/lrreportengine.h | 5 + limereport/exporters/lrpdfexporter.cpp | 2 +- limereport/lrbanddesignintf.cpp | 38 +++++- limereport/lrbanddesignintf.h | 5 + limereport/lrglobal.h | 1 + limereport/lrpagedesignintf.cpp | 4 +- limereport/lrpageitemdesignintf.cpp | 2 +- limereport/lrpreviewreportwidget.cpp | 4 +- limereport/lrreportdesignwidget.cpp | 4 +- limereport/lrreportengine.cpp | 162 ++++++++++++------------- limereport/lrreportengine.h | 5 + limereport/lrreportengine_p.h | 14 ++- 13 files changed, 145 insertions(+), 102 deletions(-) diff --git a/include/lrglobal.h b/include/lrglobal.h index da6ab47..b0b462f 100644 --- a/include/lrglobal.h +++ b/include/lrglobal.h @@ -52,6 +52,7 @@ namespace LimeReport { namespace Const{ + int const DEFAULT_GRID_STEP = 1; int const RESIZE_HANDLE_SIZE = 5; int const SELECTION_PEN_SIZE = 1; int const MINIMUM_ITEM_WIDTH = 2*RESIZE_HANDLE_SIZE; diff --git a/include/lrreportengine.h b/include/lrreportengine.h index a4c314f..305ce72 100644 --- a/include/lrreportengine.h +++ b/include/lrreportengine.h @@ -212,6 +212,11 @@ signals: void renderStarted(); void renderFinished(); void renderPageFinished(int renderedPageCount); + + void printingStarted(int pageCount); + void printingFinished(); + void pagePrintingFinished(int index); + void onSave(bool& saved); void onSaveAs(bool& saved); void onLoad(bool& loaded); diff --git a/limereport/exporters/lrpdfexporter.cpp b/limereport/exporters/lrpdfexporter.cpp index d97bf7b..08f6f60 100644 --- a/limereport/exporters/lrpdfexporter.cpp +++ b/limereport/exporters/lrpdfexporter.cpp @@ -27,7 +27,7 @@ bool PDFExporter::exportPages(ReportPages pages, const QString &fileName, const printer.setOutputFileName(fileName); printer.setOutputFormat(QPrinter::PdfFormat); if (!pages.isEmpty()){ - m_reportEngine->printReport(pages, printer); + m_reportEngine->printPages(pages, &printer); } m_reportEngine->emitPrintedToPDF(fileName); return true; diff --git a/limereport/lrbanddesignintf.cpp b/limereport/lrbanddesignintf.cpp index caac574..f4db01d 100644 --- a/limereport/lrbanddesignintf.cpp +++ b/limereport/lrbanddesignintf.cpp @@ -166,7 +166,8 @@ BandDesignIntf::BandDesignIntf(BandsType bandType, const QString &xmlTypeName, Q m_printAlways(false), m_repeatOnEachRow(false), m_useAlternateBackgroundColor(false), - m_bottomSpace(0) + m_bottomSpace(0), + m_shiftItems(0) { setPossibleResizeDirectionFlags(ResizeBottom); setPossibleMoveFlags(TopBotom); @@ -277,6 +278,11 @@ void BandDesignIntf::paint(QPainter *painter, const QStyleOptionGraphicsItem *op BaseDesignIntf::paint(painter,option,widget); } +QRectF BandDesignIntf::boundingRect() const +{ + return ItemsContainerDesignInft::boundingRect().adjusted(0,-4,0,4); +} + void BandDesignIntf::translateBandsName() { tr("DataBand"); @@ -582,6 +588,10 @@ void BandDesignIntf::preparePopUpMenu(QMenu &menu) currAction->setCheckable(true); currAction->setChecked(isSplittable()); + currAction = menu.addAction(tr("Keep top space")); + currAction->setCheckable(true); + currAction->setChecked(keepBottomSpaceOption()); + currAction = menu.addAction(tr("Keep bottom space")); currAction->setCheckable(true); currAction->setChecked(keepBottomSpaceOption()); @@ -595,17 +605,23 @@ void BandDesignIntf::preparePopUpMenu(QMenu &menu) void BandDesignIntf::processPopUpAction(QAction *action) { if (action->text().compare(tr("Auto height")) == 0){ - setProperty("autoHeight",action->isChecked()); + setProperty("autoHeight", action->isChecked()); } + 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){ - setProperty("keepBottomSpace",action->isChecked()); + setProperty("keepBottomSpace", action->isChecked()); } if (action->text().compare(tr("Print if empty")) == 0){ - setProperty("printIfEmpty",action->isChecked()); + setProperty("printIfEmpty", action->isChecked()); } ItemsContainerDesignInft::processPopUpAction(action); } @@ -903,6 +919,16 @@ void BandDesignIntf::slotPropertyObjectNameChanged(const QString &, const QStrin m_bandNameLabel->updateLabel(newName); } +int BandDesignIntf::shiftItems() const +{ + return m_shiftItems; +} + +void BandDesignIntf::setShiftItems(int shiftItems) +{ + m_shiftItems = shiftItems; +} + bool BandDesignIntf::keepTopSpace() const { return m_keepTopSpace; @@ -1105,7 +1131,7 @@ void BandDesignIntf::updateItemSize(DataSourceManager* dataManager, RenderPass p arrangeSubItems(pass, dataManager); if (autoHeight()){ if (!keepTopSpace()) { - qreal minTop = findMinTop(); + qreal minTop = findMinTop() + m_shiftItems; foreach (BaseDesignIntf* item, childBaseItems()) { item->setY(item->y() - minTop); } diff --git a/limereport/lrbanddesignintf.h b/limereport/lrbanddesignintf.h index a6e09be..8da77ed 100644 --- a/limereport/lrbanddesignintf.h +++ b/limereport/lrbanddesignintf.h @@ -113,6 +113,7 @@ class BandDesignIntf : public ItemsContainerDesignInft Q_PROPERTY(bool printIfEmpty READ printIfEmpty WRITE setPrintIfEmpty) Q_PROPERTY(BGMode backgroundMode READ backgroundMode WRITE setBackgroundModeProperty) Q_PROPERTY(int backgroundOpacity READ opacity WRITE setBackgroundOpacity) + Q_PROPERTY(int shiftItems READ shiftItems WRITE setShiftItems) Q_ENUMS(BandColumnsLayoutType) friend class BandMarker; friend class BandNameLabel; @@ -142,6 +143,7 @@ public: ~BandDesignIntf(); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + QRectF boundingRect() const; void translateBandsName(); virtual BandsType bandType() const; virtual QString bandTitle() const; @@ -260,6 +262,8 @@ public: int bootomSpace() const; void setBootomSpace(int bootomSpace); void updateBandMarkerGeometry(); + int shiftItems() const; + void setShiftItems(int shiftItems); signals: void bandRendered(BandDesignIntf* band); @@ -323,6 +327,7 @@ private: bool m_useAlternateBackgroundColor; int m_bottomSpace; QMap m_bookmarks; + int m_shiftItems; }; class DataBandDesignIntf : public BandDesignIntf{ diff --git a/limereport/lrglobal.h b/limereport/lrglobal.h index da6ab47..b0b462f 100644 --- a/limereport/lrglobal.h +++ b/limereport/lrglobal.h @@ -52,6 +52,7 @@ namespace LimeReport { namespace Const{ + int const DEFAULT_GRID_STEP = 1; int const RESIZE_HANDLE_SIZE = 5; int const SELECTION_PEN_SIZE = 1; int const MINIMUM_ITEM_WIDTH = 2*RESIZE_HANDLE_SIZE; diff --git a/limereport/lrpagedesignintf.cpp b/limereport/lrpagedesignintf.cpp index bc81b94..c28bdcf 100644 --- a/limereport/lrpagedesignintf.cpp +++ b/limereport/lrpagedesignintf.cpp @@ -83,8 +83,8 @@ PageDesignIntf::PageDesignIntf(QObject *parent): m_executingGroupCommand(false), m_settings(0), m_selectionRect(0), - m_verticalGridStep(2), - m_horizontalGridStep(2), + m_verticalGridStep(Const::DEFAULT_GRID_STEP), + m_horizontalGridStep(Const::DEFAULT_GRID_STEP), m_updating(false), m_currentObjectIndex(1), m_multiSelectStarted(false), diff --git a/limereport/lrpageitemdesignintf.cpp b/limereport/lrpageitemdesignintf.cpp index 47715c8..15b200f 100644 --- a/limereport/lrpageitemdesignintf.cpp +++ b/limereport/lrpageitemdesignintf.cpp @@ -1011,7 +1011,7 @@ void PageItemDesignIntf::setGridStep(int value) int PageItemDesignIntf::gridStep() { if (page()) return page()->horizontalGridStep(); - else return 2; + else return Const::DEFAULT_GRID_STEP; } void PageItemDesignIntf::objectLoadFinished() diff --git a/limereport/lrpreviewreportwidget.cpp b/limereport/lrpreviewreportwidget.cpp index 01cc68e..87a3bab 100644 --- a/limereport/lrpreviewreportwidget.cpp +++ b/limereport/lrpreviewreportwidget.cpp @@ -222,9 +222,9 @@ void PreviewReportWidget::lastPage() void PreviewReportWidget::printPages(QPrinter* printer) { if (!d_ptr->m_reportPages.isEmpty()) - ReportEnginePrivate::printReport( + d_ptr->m_report->printPages( d_ptr->m_reportPages, - *printer + printer ); foreach(PageItemDesignIntf::Ptr pageItem, d_ptr->m_reportPages){ d_ptr->m_previewPage->reactivatePageItem(pageItem); diff --git a/limereport/lrreportdesignwidget.cpp b/limereport/lrreportdesignwidget.cpp index c7f965e..cd09abc 100644 --- a/limereport/lrreportdesignwidget.cpp +++ b/limereport/lrreportdesignwidget.cpp @@ -820,8 +820,8 @@ void ReportDesignWidget::editSetting() void ReportDesignWidget::applyUseGrid() { - int hGridStep = m_useGrid ? m_horizontalGridStep : 2; - int vGridStep = m_useGrid ? m_verticalGridStep : 2; + int hGridStep = m_useGrid ? m_horizontalGridStep : Const::DEFAULT_GRID_STEP; + int vGridStep = m_useGrid ? m_verticalGridStep : Const::DEFAULT_GRID_STEP; for(int i = 0; i < m_report->pageCount(); ++i){ m_report->pageAt(i)->setVerticalGridStep(hGridStep); m_report->pageAt(i)->setHorizontalGridStep(vGridStep); diff --git a/limereport/lrreportengine.cpp b/limereport/lrreportengine.cpp index c07cff4..fc1b4c2 100644 --- a/limereport/lrreportengine.cpp +++ b/limereport/lrreportengine.cpp @@ -264,62 +264,74 @@ void ReportEnginePrivate::clearReport() emit cleared(); } -void ReportEnginePrivate::printReport(ItemsReaderIntf::Ptr reader, QPrinter& printer) +bool ReportEnginePrivate::printPages(ReportPages pages, QPrinter *printer) { - LimeReport::PageDesignIntf renderPage; - renderPage.setItemMode(PrintMode); - if (reader->first()){ - reader->readItem(renderPage.pageItem()); - printer.setFullPage(renderPage.pageItem()->fullPage()); - printer.setOrientation((QPrinter::Orientation)renderPage.pageItem()->pageOrientation()); - renderPage.setSceneRect(renderPage.pageItem()->mapToScene(renderPage.pageItem()->rect()).boundingRect()); - - if (renderPage.pageItem()->pageSize()==PageItemDesignIntf::Custom){ - QSizeF pageSize = (renderPage.pageItem()->pageOrientation()==PageItemDesignIntf::Landscape)? - QSizeF(renderPage.pageItem()->sizeMM().height(),renderPage.pageItem()->sizeMM().width()): - renderPage.pageItem()->sizeMM(); - printer.setPaperSize(pageSize,QPrinter::Millimeter); - } else { - printer.setPaperSize((QPrinter::PageSize)renderPage.pageItem()->pageSize()); - } - - 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){ + 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){ + 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; QMap> printProcessors; printProcessors.insert("default",QSharedPointer(new PrintProcessor(&printer))); + emit printingStarted(printer.toPage() - printer.fromPage()); foreach(PageItemDesignIntf::Ptr page, pages){ - if ( - (printer.printRange() == QPrinter::AllPages) || + if ( !m_cancelPrinting && + ((printer.printRange() == QPrinter::AllPages) || ( (printer.printRange()==QPrinter::PageRange) && (currenPage>=printer.fromPage()) && (currenPage<=printer.toPage()) - ) + )) ) { printProcessors["default"]->printPage(page); + currenPage++; + emit pagePrintingFinished(currenPage); + QApplication::processEvents(); } - currenPage++; + + } + emit printingFinished(); } -void ReportEnginePrivate::printReport(ReportPages pages, QMap printers, bool printToAllPrinters) +void ReportEnginePrivate::printPages(ReportPages pages, QMap printers, bool printToAllPrinters) { if (printers.values().isEmpty()) return; - int currenPage = 1; + m_cancelPrinting = false; + QMap> printProcessors; for (int i = 0; i < printers.keys().count(); ++i) { printProcessors.insert(printers.keys()[i],QSharedPointer(new PrintProcessor(printers[printers.keys()[i]]))); @@ -329,7 +341,12 @@ void ReportEnginePrivate::printReport(ReportPages pages, QMapprinterName())) printProcessors[page->printerName()]->printPage(page); @@ -340,9 +357,11 @@ void ReportEnginePrivate::printReport(ReportPages pages, QMapsetDesignTime(designTime); if (pages.count()>0){ - printReport(pages,*printer); + internalPrintPages(pages, *printer); } } catch(ReportError &exception){ saveError(exception.what()); @@ -408,7 +427,7 @@ bool ReportEnginePrivate::printReport(QMap printers, bool pr ReportPages pages = renderToPages(); dataManager()->setDesignTime(designTime); if (pages.count()>0){ - printReport(pages, printers, printToAllPrinters); + printPages(pages, printers, printToAllPrinters); } } catch(ReportError &exception){ saveError(exception.what()); @@ -417,42 +436,6 @@ bool ReportEnginePrivate::printReport(QMap printers, bool pr 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) { if (!fileName.isEmpty()){ @@ -739,6 +722,11 @@ void ReportEnginePrivate::cancelRender() m_reportRendering = false; } +void ReportEnginePrivate::cancelPrinting() +{ + m_cancelPrinting = true; +} + QGraphicsScene* ReportEngine::createPreviewScene(QObject* parent){ Q_D(ReportEngine); return d->createPreviewScene(parent); @@ -1387,6 +1375,12 @@ ReportEngine::ReportEngine(QObject *parent) connect(d, SIGNAL(renderPageFinished(int)), this, SIGNAL(renderPageFinished(int))); 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(onSaveAs(bool&)), this, SIGNAL(onSaveAs(bool&))); connect(d, SIGNAL(onLoad(bool&)), this, SIGNAL(onLoad(bool&))); @@ -1766,21 +1760,21 @@ ScriptEngineManager*LimeReport::ReportEnginePrivate::scriptManager(){ PrintProcessor::PrintProcessor(QPrinter* printer) : m_printer(printer), m_painter(0), m_firstPage(true) -{} +{m_renderPage.setItemMode(PrintMode);} bool PrintProcessor::printPage(PageItemDesignIntf::Ptr page) { if (!m_firstPage && !m_painter->isActive()) return false; - LimeReport::PageDesignIntf renderPage; - renderPage.setItemMode(PrintMode); + //LimeReport::PageDesignIntf m_renderPage; + //m_renderPage.setItemMode(PrintMode); QPointF backupPagePos = page->pos(); page->setPos(0,0); - renderPage.setPageItem(page); - renderPage.setSceneRect(renderPage.pageItem()->mapToScene(renderPage.pageItem()->rect()).boundingRect()); - initPrinter(renderPage.pageItem()); + m_renderPage.setPageItem(page); + m_renderPage.setSceneRect(m_renderPage.pageItem()->mapToScene(m_renderPage.pageItem()->rect()).boundingRect()); + initPrinter(m_renderPage.pageItem()); if (!m_firstPage){ m_printer->newPage(); @@ -1809,7 +1803,7 @@ bool PrintProcessor::printPage(PageItemDesignIntf::Ptr page) while (pageHeight > 0){ while (curWidth < pageWidth){ 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); curWidth += printerPageRect.size().width(); @@ -1822,7 +1816,7 @@ bool PrintProcessor::printPage(PageItemDesignIntf::Ptr page) } } else { - renderPage.render(m_painter); + m_renderPage.render(m_painter); } page->setPos(backupPagePos); return true; diff --git a/limereport/lrreportengine.h b/limereport/lrreportengine.h index a4c314f..305ce72 100644 --- a/limereport/lrreportengine.h +++ b/limereport/lrreportengine.h @@ -212,6 +212,11 @@ signals: void renderStarted(); void renderFinished(); void renderPageFinished(int renderedPageCount); + + void printingStarted(int pageCount); + void printingFinished(); + void pagePrintingFinished(int index); + void onSave(bool& saved); void onSaveAs(bool& saved); void onLoad(bool& loaded); diff --git a/limereport/lrreportengine_p.h b/limereport/lrreportengine_p.h index 6bdefe6..17cacd7 100644 --- a/limereport/lrreportengine_p.h +++ b/limereport/lrreportengine_p.h @@ -122,6 +122,7 @@ private: private: QPrinter* m_printer; QPainter* m_painter; + LimeReport::PageDesignIntf m_renderPage; bool m_firstPage; }; @@ -141,9 +142,8 @@ class ReportEnginePrivate : public QObject, friend class PreviewReportWidget; public: - static void printReport(ItemsReaderIntf::Ptr reader, QPrinter &printer); - static void printReport(ReportPages pages, QPrinter &printer); - static void printReport(ReportPages pages, QMapprinters, bool printToAllPrinters = false); + bool printPages(ReportPages pages, QPrinter *printer); + void printPages(ReportPages pages, QMapprinters, bool printToAllPrinters = false); Q_INVOKABLE QStringList aviableReportTranslations(); Q_INVOKABLE void setReportTranslation(const QString& languageName); public: @@ -168,7 +168,7 @@ public: void clearReport(); bool printReport(QPrinter* printer=0); bool printReport(QMapprinters, bool printToAllPrinters); - bool printPages(ReportPages pages, QPrinter *printer); + void printToFile(const QString& fileName); bool printToPDF(const QString& fileName); bool exportReport(QString exporterName, const QString &fileName = "", const QMap& params = QMap()); @@ -268,13 +268,18 @@ signals: void currentDefaultDesignerLanguageChanged(QLocale::Language); QLocale::Language getCurrentDefaultDesignerLanguage(); void externalPaint(const QString& objectName, QPainter* painter, const QStyleOptionGraphicsItem*); + void printingStarted(int pageCount); + void printingFinished(); + void pagePrintingFinished(int index); public slots: bool slotLoadFromFile(const QString& fileName); void cancelRender(); + void cancelPrinting(); protected: PageDesignIntf* createPage(const QString& pageName="", bool preview = false); bool showPreviewWindow(ReportPages pages, PreviewHints hints, QPrinter *printer); + void internalPrintPages(ReportPages pages, QPrinter &printer); protected slots: void slotDataSourceCollectionLoaded(const QString& collectionName); private slots: @@ -344,6 +349,7 @@ private: bool m_saveToFileVisible; bool m_printToPdfVisible; bool m_printVisible; + bool m_cancelPrinting; }; }