0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 16:44:39 +03:00

Console demo has been refactored and added to the limereport.pro

This commit is contained in:
Arin Alexander 2019-02-20 21:06:18 +03:00
parent c30bfc9a06
commit 0ca4366ad8
3 changed files with 68 additions and 49 deletions

View File

@ -1,33 +1,35 @@
QT += core widgets include(../common.pri)
QT += core
QT -= gui QT -= gui
CONFIG += c++11 TARGET = limereport
TARGET = console
CONFIG += console CONFIG += console
CONFIG -= app_bundle CONFIG -= app_bundle
TEMPLATE = app TEMPLATE = app
SOURCES += main.cpp SOURCES += main.cpp
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS DEFINES += QT_DEPRECATED_WARNINGS
include(../common.pri) DESTDIR = $${DEST_BINS}
INCLUDEPATH += $$PWD/../include INCLUDEPATH += $$PWD/../include
DEPENDPATH += $$PWD/../include DEPENDPATH += $$PWD/../include
LIBS += -L$${DEST_LIBS} -llimereport
LIBS += -L$${DEST_LIBS}
CONFIG(debug, debug|release) {
LIBS += -llimereportd
} else {
LIBS += -llimereport
}
!contains(CONFIG, static_build){ !contains(CONFIG, static_build){
contains(CONFIG,zint){ contains(CONFIG,zint){
LIBS += -L$${DEST_LIBS} -lQtZint LIBS += -L$${DEST_LIBS}
CONFIG(debug, debug|release) {
LIBS += -lQtZintd
} else {
LIBS += -lQtZint
}
} }
} }
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

View File

@ -5,6 +5,7 @@
#include <QDebug> #include <QDebug>
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
#include <QCommandLineParser>
#ifdef _WIN32 #ifdef _WIN32
#include <io.h> #include <io.h>
@ -14,49 +15,64 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
QApplication::setApplicationVersion(LIMEREPORT_VERSION_STR);
QStringList vars; 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; 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; return 1;
} }
if (a.arguments().count()>2){ if (!report.loadFromFile(parser.value(sourceOption))){
vars = a.arguments().at(2).split(";"); std::cerr<<"Error! Report file \""+parser.value(sourceOption).toStdString()+"\" not found \n";
qDebug()<<vars; return 1;
foreach(QString var, vars){ }
if (!parser.values(variablesOption).isEmpty()){
foreach(QString var, parser.values(variablesOption)){
QStringList varItem = var.split("="); QStringList varItem = var.split("=");
if (varItem.size() == 2)
report.dataManager()->setReportVariable(varItem.at(0),varItem.at(1)); report.dataManager()->setReportVariable(varItem.at(0),varItem.at(1));
} }
} }
QString reportFile = a.arguments().at(1); if (parser.value(destinationOption).isEmpty()){
report.printToPDF(QFileInfo(parser.value(sourceOption)).baseName());
if (!report.loadFromFile(reportFile)){ } else {
qDebug()<<QDir::currentPath(); report.printToPDF(parser.value(destinationOption));
QFile::exists(reportFile);
std::cerr<<"Error! Report file \""+reportFile.toStdString()+"\" not found";
return 1;
} }
QUuid uid = QUuid::createUuid(); // QUuid uid = QUuid::createUuid();
QString uidStr = uid.toString()+".pdf"; // QString uidStr = uid.toString()+".pdf";
report.printToPDF(uidStr); // report.printToPDF(uidStr);
QFile in(uidStr); // QFile in(uidStr);
QFile out; // QFile out;
out.open(stdout, QFile::WriteOnly); // out.open(stdout, QFile::WriteOnly);
in.open(QIODevice::ReadOnly); // in.open(QIODevice::ReadOnly);
#ifdef _WIN32 //#ifdef _WIN32
_setmode(fileno(stdout),O_BINARY); // _setmode(fileno(stdout),O_BINARY);
//qDebug()<<result; //#endif
#endif // QByteArray buffer = in.readAll();
QByteArray buffer = in.readAll(); // fwrite(buffer,1,buffer.size(),stdout);
fwrite(buffer,1,buffer.size(),stdout);
// out.write(in.readAll());
in.close();
in.remove();
// std::cout << uidStr.toStdString();
// std::cout << in.readAll().data();
// in.close(); // in.close();
// in.remove(); // in.remove();

View File

@ -16,6 +16,7 @@ SUBDIRS += \
limereport \ limereport \
demo_r1 \ demo_r1 \
demo_r2 \ demo_r2 \
console \
designer designer
!contains(CONFIG, embedded_designer){ !contains(CONFIG, embedded_designer){