From 3a97bf192e25a788d4906002a51aca1715adda45 Mon Sep 17 00:00:00 2001 From: Alexander Arin Date: Thu, 19 Dec 2019 23:42:05 +0300 Subject: [PATCH] Display type has been added to console application --- console/main.cpp | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/console/main.cpp b/console/main.cpp index 17e250b..6bbd395 100644 --- a/console/main.cpp +++ b/console/main.cpp @@ -13,6 +13,8 @@ #include #endif +enum PrintType{ Printer, PDF, Display}; + int main(int argc, char *argv[]) { QApplication a(argc, argv); @@ -61,20 +63,29 @@ int main(int argc, char *argv[]) } } - bool printToPDF = true; + + PrintType printType = PDF; + if (!parser.value(typeOption).isEmpty()){ - printToPDF = !(parser.value(typeOption).compare("Printer",Qt::CaseInsensitive) == 0); + if (parser.value(typeOption).compare("Printer",Qt::CaseInsensitive) == 0) + printType = Printer; + if (parser.value(typeOption).compare("Display",Qt::CaseInsensitive) == 0) + printType = Display; } - if (printToPDF){ + + QPrinterInfo pi; + QPrinter printer; + + switch(printType){ + case PDF: if (parser.value(destinationOption).isEmpty()){ report.printToPDF(QFileInfo(parser.value(sourceOption)).baseName()); } else { report.printToPDF(parser.value(destinationOption)); } - } else { - QPrinterInfo pi; - QPrinter printer; + break; + case Printer: if (parser.value(destinationOption).isEmpty()){ if (!pi.defaultPrinterName().isEmpty()){ printer.setPrinterName(pi.defaultPrinterName()); @@ -86,7 +97,12 @@ int main(int argc, char *argv[]) printer.setPrinterName(parser.value(destinationOption)); report.printReport(&printer); } + break; + case Display: + report.previewReport(); + break; } + #else std::cerr<<"This demo intended for Qt 5.2 and higher\n"; #endif