0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-25 09:04:39 +03:00

"Type" parameter has been added to console

This commit is contained in:
Alexander Arin 2019-11-08 19:12:03 +03:00
parent 15671cf6f4
commit 674528b095

View File

@ -6,6 +6,7 @@
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
#include <QCommandLineParser> #include <QCommandLineParser>
#include <QPrinterInfo>
#ifdef _WIN32 #ifdef _WIN32
#include <io.h> #include <io.h>
@ -34,6 +35,10 @@ int main(int argc, char *argv[])
QCoreApplication::translate("main", "Report parameter (can be more than one)"), QCoreApplication::translate("main", "Report parameter (can be more than one)"),
QCoreApplication::translate("main", "param_name=param_value")); QCoreApplication::translate("main", "param_name=param_value"));
parser.addOption(variablesOption); 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); parser.process(a);
LimeReport::ReportEngine report; LimeReport::ReportEngine report;
@ -56,10 +61,31 @@ int main(int argc, char *argv[])
} }
} }
if (parser.value(destinationOption).isEmpty()){ bool printToPDF = true;
report.printToPDF(QFileInfo(parser.value(sourceOption)).baseName()); 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 { } 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 #else
std::cerr<<"This demo intended for Qt 5.2 and higher\n"; std::cerr<<"This demo intended for Qt 5.2 and higher\n";