Some band improvements have been added. Printing signals have been added. Render & printing speed little bit has been increased

This commit is contained in:
Arin Alexander 2019-10-12 22:31:35 +03:00
parent 9756ddde9c
commit 5a6ee275a7
13 changed files with 145 additions and 102 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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);
}

View File

@ -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<QString,QVariant> m_bookmarks;
int m_shiftItems;
};
class DataBandDesignIntf : public BandDesignIntf{

View File

@ -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;

View File

@ -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),

View File

@ -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()

View File

@ -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);

View File

@ -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);

View File

@ -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<QString, QSharedPointer<PrintProcessor>> printProcessors;
printProcessors.insert("default",QSharedPointer<PrintProcessor>(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<QString, QPrinter*> printers, bool printToAllPrinters)
void ReportEnginePrivate::printPages(ReportPages pages, QMap<QString, QPrinter*> printers, bool printToAllPrinters)
{
if (printers.values().isEmpty()) return;
int currenPage = 1;
m_cancelPrinting = false;
QMap<QString, QSharedPointer<PrintProcessor>> printProcessors;
for (int i = 0; i < printers.keys().count(); ++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;
if (printProcessors.contains("default")) defaultProcessor = printProcessors["default"].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 (printProcessors.contains(page->printerName()))
printProcessors[page->printerName()]->printPage(page);
@ -340,9 +357,11 @@ void ReportEnginePrivate::printReport(ReportPages pages, QMap<QString, QPrinter*
currentPrinter++;
else currentPrinter = 0;
}
currenPage++;
emit pagePrintingFinished(i+1);
QApplication::processEvents();
}
emit printingFinished();
}
QStringList ReportEnginePrivate::aviableReportTranslations()
@ -391,7 +410,7 @@ bool ReportEnginePrivate::printReport(QPrinter* printer)
ReportPages pages = renderToPages();
dataManager()->setDesignTime(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<QString, QPrinter*> 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<QString, QPrinter*> 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;

View File

@ -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);

View File

@ -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, QMap<QString,QPrinter*>printers, bool printToAllPrinters = false);
bool printPages(ReportPages pages, QPrinter *printer);
void printPages(ReportPages pages, QMap<QString,QPrinter*>printers, 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(QMap<QString, QPrinter*>printers, 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<QString, QVariant>& params = QMap<QString, QVariant>());
@ -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;
};
}