From 674528b09556e2c9b7885592bd97114406a65afa Mon Sep 17 00:00:00 2001 From: Alexander Arin Date: Fri, 8 Nov 2019 19:12:03 +0300 Subject: [PATCH] "Type" parameter has been added to console --- console/main.cpp | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/console/main.cpp b/console/main.cpp index 764fc36..17e250b 100644 --- a/console/main.cpp +++ b/console/main.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #ifdef _WIN32 #include @@ -34,6 +35,10 @@ int main(int argc, char *argv[]) QCoreApplication::translate("main", "Report parameter (can be more than one)"), QCoreApplication::translate("main", "param_name=param_value")); parser.addOption(variablesOption); + QCommandLineOption typeOption(QStringList() << "t" << "type", + QCoreApplication::translate("main", "Output type (Printer | PDF)"), + QCoreApplication::translate("main", "type")); + parser.addOption(typeOption); parser.process(a); LimeReport::ReportEngine report; @@ -56,10 +61,31 @@ int main(int argc, char *argv[]) } } - if (parser.value(destinationOption).isEmpty()){ - report.printToPDF(QFileInfo(parser.value(sourceOption)).baseName()); + bool printToPDF = true; + if (!parser.value(typeOption).isEmpty()){ + printToPDF = !(parser.value(typeOption).compare("Printer",Qt::CaseInsensitive) == 0); + } + + if (printToPDF){ + if (parser.value(destinationOption).isEmpty()){ + report.printToPDF(QFileInfo(parser.value(sourceOption)).baseName()); + } else { + report.printToPDF(parser.value(destinationOption)); + } } else { - report.printToPDF(parser.value(destinationOption)); + QPrinterInfo pi; + QPrinter printer; + if (parser.value(destinationOption).isEmpty()){ + if (!pi.defaultPrinterName().isEmpty()){ + printer.setPrinterName(pi.defaultPrinterName()); + report.printReport(&printer); + } else { + std::cerr<<"Error! Default printer not found on system"; + } + } else { + printer.setPrinterName(parser.value(destinationOption)); + report.printReport(&printer); + } } #else std::cerr<<"This demo intended for Qt 5.2 and higher\n";