0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-23 16:22:58 +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
CONFIG += c++11
TARGET = console
TARGET = limereport
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
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
include(../common.pri)
DESTDIR = $${DEST_BINS}
INCLUDEPATH += $$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,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 <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();

View File

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