mirror of
https://github.com/python-LimeReport/LimeReport.git
synced 2025-10-09 05:57:15 +03:00
Console demo has been refactored and added to the limereport.pro
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QCommandLineParser>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <io.h>
|
||||
@@ -14,49 +15,64 @@
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
QApplication::setApplicationVersion(LIMEREPORT_VERSION_STR);
|
||||
QStringList vars;
|
||||
|
||||
QCommandLineParser parser;
|
||||
parser.addHelpOption();
|
||||
parser.addVersionOption();
|
||||
QCommandLineOption sourceOption(QStringList() << "s" << "source",
|
||||
QCoreApplication::translate("main", "Limereport pattern file name"),
|
||||
QCoreApplication::translate("main", "source"));
|
||||
parser.addOption(sourceOption);
|
||||
QCommandLineOption destinationOption(QStringList() << "d" << "destination",
|
||||
QCoreApplication::translate("main", "Output file name"),
|
||||
QCoreApplication::translate("main", "destination"));
|
||||
parser.addOption(destinationOption);
|
||||
QCommandLineOption variablesOption(QStringList() << "p" << "param",
|
||||
QCoreApplication::translate("main", "Report parameter (can be more than one)"),
|
||||
QCoreApplication::translate("main", "param_name=param_value"));
|
||||
parser.addOption(variablesOption);
|
||||
parser.process(a);
|
||||
|
||||
LimeReport::ReportEngine report;
|
||||
if (a.arguments().count() < 2 ){
|
||||
std::cerr<<"Error! Report file is not specified !!";
|
||||
|
||||
if (parser.value(sourceOption).isEmpty()){
|
||||
std::cerr<<"Error! Report file is not specified !! \n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (a.arguments().count()>2){
|
||||
vars = a.arguments().at(2).split(";");
|
||||
qDebug()<<vars;
|
||||
foreach(QString var, vars){
|
||||
if (!report.loadFromFile(parser.value(sourceOption))){
|
||||
std::cerr<<"Error! Report file \""+parser.value(sourceOption).toStdString()+"\" not found \n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!parser.values(variablesOption).isEmpty()){
|
||||
foreach(QString var, parser.values(variablesOption)){
|
||||
QStringList varItem = var.split("=");
|
||||
report.dataManager()->setReportVariable(varItem.at(0),varItem.at(1));
|
||||
if (varItem.size() == 2)
|
||||
report.dataManager()->setReportVariable(varItem.at(0),varItem.at(1));
|
||||
}
|
||||
}
|
||||
|
||||
QString reportFile = a.arguments().at(1);
|
||||
|
||||
if (!report.loadFromFile(reportFile)){
|
||||
qDebug()<<QDir::currentPath();
|
||||
QFile::exists(reportFile);
|
||||
std::cerr<<"Error! Report file \""+reportFile.toStdString()+"\" not found";
|
||||
return 1;
|
||||
if (parser.value(destinationOption).isEmpty()){
|
||||
report.printToPDF(QFileInfo(parser.value(sourceOption)).baseName());
|
||||
} else {
|
||||
report.printToPDF(parser.value(destinationOption));
|
||||
}
|
||||
|
||||
QUuid uid = QUuid::createUuid();
|
||||
QString uidStr = uid.toString()+".pdf";
|
||||
report.printToPDF(uidStr);
|
||||
QFile in(uidStr);
|
||||
QFile out;
|
||||
out.open(stdout, QFile::WriteOnly);
|
||||
in.open(QIODevice::ReadOnly);
|
||||
#ifdef _WIN32
|
||||
_setmode(fileno(stdout),O_BINARY);
|
||||
//qDebug()<<result;
|
||||
#endif
|
||||
QByteArray buffer = in.readAll();
|
||||
fwrite(buffer,1,buffer.size(),stdout);
|
||||
// out.write(in.readAll());
|
||||
in.close();
|
||||
in.remove();
|
||||
// std::cout << uidStr.toStdString();
|
||||
// std::cout << in.readAll().data();
|
||||
// QUuid uid = QUuid::createUuid();
|
||||
// QString uidStr = uid.toString()+".pdf";
|
||||
// report.printToPDF(uidStr);
|
||||
// QFile in(uidStr);
|
||||
// QFile out;
|
||||
// out.open(stdout, QFile::WriteOnly);
|
||||
// in.open(QIODevice::ReadOnly);
|
||||
//#ifdef _WIN32
|
||||
// _setmode(fileno(stdout),O_BINARY);
|
||||
//#endif
|
||||
// QByteArray buffer = in.readAll();
|
||||
// fwrite(buffer,1,buffer.size(),stdout);
|
||||
// in.close();
|
||||
// in.remove();
|
||||
|
||||
|
Reference in New Issue
Block a user