printToAllPrinters flag has been added to printReport method

This commit is contained in:
Arin Alexander 2019-02-09 23:57:19 +03:00
parent 362c7217f3
commit a43368751c
4 changed files with 20 additions and 13 deletions

View File

@ -80,7 +80,7 @@ public:
explicit ReportEngine(QObject *parent = 0); explicit ReportEngine(QObject *parent = 0);
~ReportEngine(); ~ReportEngine();
bool printReport(QPrinter *printer=0); bool printReport(QPrinter *printer=0);
bool printReport(QMap<QString, QPrinter*> printers); bool printReport(QMap<QString, QPrinter*> printers, bool printToAllPrinters = false);
bool printPages(ReportPages pages, QPrinter *printer); bool printPages(ReportPages pages, QPrinter *printer);
void printToFile(const QString& fileName); void printToFile(const QString& fileName);
PageDesignIntf *createPreviewScene(QObject *parent = 0); PageDesignIntf *createPreviewScene(QObject *parent = 0);

View File

@ -307,7 +307,7 @@ void ReportEnginePrivate::printReport(ReportPages pages, QPrinter &printer)
} }
} }
void ReportEnginePrivate::printReport(ReportPages pages, QMap<QString, QPrinter*> printers) void ReportEnginePrivate::printReport(ReportPages pages, QMap<QString, QPrinter*> printers, bool printToAllPrinters)
{ {
if (printers.values().isEmpty()) return; if (printers.values().isEmpty()) return;
int currenPage = 1; int currenPage = 1;
@ -317,13 +317,20 @@ void ReportEnginePrivate::printReport(ReportPages pages, QMap<QString, QPrinter*
} }
PrintProcessor* defaultProcessor = 0; PrintProcessor* defaultProcessor = 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){ foreach(PageItemDesignIntf::Ptr page, pages){
if (!printToAllPrinters){
if (printProcessors.contains(page->printerName())) if (printProcessors.contains(page->printerName()))
printProcessors[page->printerName()]->printPage(page); printProcessors[page->printerName()]->printPage(page);
else defaultProcessor->printPage(page); else defaultProcessor->printPage(page);
} else {
printProcessors.values().at(currentPrinter)->printPage(page);
if (currentPrinter < printers.values().count()-1)
currentPrinter++;
else currentPrinter = 0;
}
currenPage++; currenPage++;
} }
@ -384,7 +391,7 @@ bool ReportEnginePrivate::printReport(QPrinter* printer)
} else return false; } else return false;
} }
bool ReportEnginePrivate::printReport(QMap<QString, QPrinter*> printers) bool ReportEnginePrivate::printReport(QMap<QString, QPrinter*> printers, bool printToAllPrinters)
{ {
try{ try{
bool designTime = dataManager()->designTime(); bool designTime = dataManager()->designTime();
@ -392,7 +399,7 @@ bool ReportEnginePrivate::printReport(QMap<QString, QPrinter*> printers)
ReportPages pages = renderToPages(); ReportPages pages = renderToPages();
dataManager()->setDesignTime(designTime); dataManager()->setDesignTime(designTime);
if (pages.count()>0){ if (pages.count()>0){
printReport(pages,printers); printReport(pages, printers, printToAllPrinters);
} }
} catch(ReportError &exception){ } catch(ReportError &exception){
saveError(exception.what()); saveError(exception.what());
@ -1263,10 +1270,10 @@ bool ReportEngine::printReport(QPrinter *printer)
return d->printReport(printer); return d->printReport(printer);
} }
bool ReportEngine::printReport(QMap<QString, QPrinter*> printers) bool ReportEngine::printReport(QMap<QString, QPrinter*> printers, bool printToAllPrinters)
{ {
Q_D(ReportEngine); Q_D(ReportEngine);
return d->printReport(printers); return d->printReport(printers, printToAllPrinters);
} }
bool ReportEngine::printPages(ReportPages pages, QPrinter *printer){ bool ReportEngine::printPages(ReportPages pages, QPrinter *printer){

View File

@ -80,7 +80,7 @@ public:
explicit ReportEngine(QObject *parent = 0); explicit ReportEngine(QObject *parent = 0);
~ReportEngine(); ~ReportEngine();
bool printReport(QPrinter *printer=0); bool printReport(QPrinter *printer=0);
bool printReport(QMap<QString, QPrinter*> printers); bool printReport(QMap<QString, QPrinter*> printers, bool printToAllPrinters = false);
bool printPages(ReportPages pages, QPrinter *printer); bool printPages(ReportPages pages, QPrinter *printer);
void printToFile(const QString& fileName); void printToFile(const QString& fileName);
PageDesignIntf *createPreviewScene(QObject *parent = 0); PageDesignIntf *createPreviewScene(QObject *parent = 0);

View File

@ -124,7 +124,7 @@ class ReportEnginePrivate : public QObject,
public: public:
static void printReport(ItemsReaderIntf::Ptr reader, QPrinter &printer); static void printReport(ItemsReaderIntf::Ptr reader, QPrinter &printer);
static void printReport(ReportPages pages, QPrinter &printer); static void printReport(ReportPages pages, QPrinter &printer);
static void printReport(ReportPages pages, QMap<QString,QPrinter*>printers); 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:
@ -148,7 +148,7 @@ public:
void clearReport(); void clearReport();
bool printReport(QPrinter *printer=0); bool printReport(QPrinter *printer=0);
bool printReport(QMap<QString, QPrinter*>printers); bool printReport(QMap<QString, QPrinter*>printers, bool printToAllPrinters);
bool printPages(ReportPages pages, QPrinter *printer); 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);