2024-09-04 17:31:16 +03:00
|
|
|
#include "../limereport/version.h"
|
|
|
|
|
2018-06-07 21:03:55 +03:00
|
|
|
#include <QApplication>
|
2024-09-04 17:31:16 +03:00
|
|
|
#include <QCommandLineParser>
|
2018-06-07 21:03:55 +03:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QFile>
|
2024-09-04 17:31:16 +03:00
|
|
|
#include <QUuid>
|
|
|
|
|
|
|
|
#include <LimeReport>
|
|
|
|
#include <iostream>
|
2018-06-07 21:03:55 +03:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2024-09-04 17:31:16 +03:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <io.h>
|
2018-06-07 21:03:55 +03:00
|
|
|
#endif
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
int main(int argc, char* argv[])
|
2018-06-07 21:03:55 +03:00
|
|
|
{
|
|
|
|
QApplication a(argc, argv);
|
2019-02-20 21:06:18 +03:00
|
|
|
QApplication::setApplicationVersion(LIMEREPORT_VERSION_STR);
|
2018-06-07 21:03:55 +03:00
|
|
|
QStringList vars;
|
2019-02-20 21:06:18 +03:00
|
|
|
|
2021-08-24 10:22:30 +03:00
|
|
|
#if QT_VERSION > 0x050200
|
2019-02-20 21:06:18 +03:00
|
|
|
QCommandLineParser parser;
|
|
|
|
parser.addHelpOption();
|
|
|
|
parser.addVersionOption();
|
2024-09-04 17:31:16 +03:00
|
|
|
QCommandLineOption sourceOption(
|
|
|
|
QStringList() << "s"
|
|
|
|
<< "source",
|
|
|
|
QCoreApplication::translate("main", "Limereport pattern file name"),
|
|
|
|
QCoreApplication::translate("main", "source"));
|
2019-02-20 21:06:18 +03:00
|
|
|
parser.addOption(sourceOption);
|
2024-09-04 17:31:16 +03:00
|
|
|
QCommandLineOption destinationOption(QStringList() << "d"
|
|
|
|
<< "destination",
|
|
|
|
QCoreApplication::translate("main", "Output file name"),
|
|
|
|
QCoreApplication::translate("main", "destination"));
|
2019-02-20 21:06:18 +03:00
|
|
|
parser.addOption(destinationOption);
|
2024-09-04 17:31:16 +03:00
|
|
|
QCommandLineOption variablesOption(
|
|
|
|
QStringList() << "p"
|
|
|
|
<< "param",
|
|
|
|
QCoreApplication::translate("main", "Report parameter (can be more than one)"),
|
|
|
|
QCoreApplication::translate("main", "param_name=param_value"));
|
2019-02-20 21:06:18 +03:00
|
|
|
parser.addOption(variablesOption);
|
|
|
|
parser.process(a);
|
|
|
|
|
2018-06-07 21:03:55 +03:00
|
|
|
LimeReport::ReportEngine report;
|
2019-02-20 21:06:18 +03:00
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (parser.value(sourceOption).isEmpty()) {
|
|
|
|
std::cerr << "Error! Report file is not specified !! \n";
|
2019-02-20 21:06:18 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!report.loadFromFile(parser.value(sourceOption))) {
|
|
|
|
std::cerr << "Error! Report file \"" + parser.value(sourceOption).toStdString()
|
|
|
|
+ "\" not found \n";
|
2018-06-07 21:03:55 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (!parser.values(variablesOption).isEmpty()) {
|
|
|
|
foreach (QString var, parser.values(variablesOption)) {
|
2018-06-07 21:03:55 +03:00
|
|
|
QStringList varItem = var.split("=");
|
2019-02-20 21:06:18 +03:00
|
|
|
if (varItem.size() == 2)
|
2024-09-04 17:31:16 +03:00
|
|
|
report.dataManager()->setReportVariable(varItem.at(0), varItem.at(1));
|
2018-06-07 21:03:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 17:31:16 +03:00
|
|
|
if (parser.value(destinationOption).isEmpty()) {
|
2019-02-20 21:06:18 +03:00
|
|
|
report.printToPDF(QFileInfo(parser.value(sourceOption)).baseName());
|
|
|
|
} else {
|
|
|
|
report.printToPDF(parser.value(destinationOption));
|
2018-06-07 21:03:55 +03:00
|
|
|
}
|
2019-02-20 21:37:32 +03:00
|
|
|
#else
|
2024-09-04 17:31:16 +03:00
|
|
|
std::cerr << "This demo intended for Qt 5.2 and higher\n";
|
2019-02-20 21:37:32 +03:00
|
|
|
#endif
|
2024-09-04 17:31:16 +03:00
|
|
|
// 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();
|
2018-06-07 21:03:55 +03:00
|
|
|
|
|
|
|
return 0;
|
2024-09-04 17:31:16 +03:00
|
|
|
// return a.exec();
|
2018-06-07 21:03:55 +03:00
|
|
|
}
|