mirror of
https://github.com/fralx/LimeReport.git
synced 2025-09-23 16:39:07 +03:00
Define code style and format all source file using clang-format-14
except those placed in 3rdparty directories.
This commit is contained in:
@@ -28,10 +28,10 @@
|
||||
* GNU General Public License for more details. *
|
||||
****************************************************************************/
|
||||
#include "mainwindow.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
MainWindow w;
|
||||
|
@@ -29,85 +29,94 @@
|
||||
****************************************************************************/
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QPrinter>
|
||||
#include <QStringListModel>
|
||||
#include <QtSql/QSqlQuery>
|
||||
#include <QtSql/QSqlRecord>
|
||||
#include <LimeReport>
|
||||
|
||||
#include <LRCallbackDS>
|
||||
#include <QDebug>
|
||||
#include <QStringListModel>
|
||||
#include <QPrinter>
|
||||
#include <LimeReport>
|
||||
|
||||
#ifdef BUILD_WITH_EASY_PROFILER
|
||||
#include "easy/profiler.h"
|
||||
#else
|
||||
# define EASY_BLOCK(...)
|
||||
# define EASY_END_BLOCK
|
||||
# define EASY_PROFILER_ENABLE
|
||||
#define EASY_BLOCK(...)
|
||||
#define EASY_END_BLOCK
|
||||
#define EASY_PROFILER_ENABLE
|
||||
#endif
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
MainWindow::MainWindow(QWidget* parent):
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::MainWindow), m_progressDialog(0), m_customers(0), m_orders(0)
|
||||
ui(new Ui::MainWindow),
|
||||
m_progressDialog(0),
|
||||
m_customers(0),
|
||||
m_orders(0)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
report = new LimeReport::ReportEngine(this);
|
||||
|
||||
connect(report, SIGNAL(renderStarted()), this, SLOT(renderStarted()));
|
||||
connect(report, SIGNAL(renderPageFinished(int)),
|
||||
this, SLOT(renderPageFinished(int)));
|
||||
connect(report, SIGNAL(renderPageFinished(int)), this, SLOT(renderPageFinished(int)));
|
||||
connect(report, SIGNAL(renderFinished()), this, SLOT(renderFinished()));
|
||||
|
||||
QFile dbFile(QApplication::applicationDirPath()+"/demo_reports/northwind.db");
|
||||
if (dbFile.exists()){
|
||||
QFile dbFile(QApplication::applicationDirPath() + "/demo_reports/northwind.db");
|
||||
if (dbFile.exists()) {
|
||||
m_db = QSqlDatabase::addDatabase("QSQLITE");
|
||||
m_db.setDatabaseName(dbFile.fileName());
|
||||
if (m_db.open()){
|
||||
if (m_db.open()) {
|
||||
QSqlQueryModel* customersModel = new QSqlQueryModel();
|
||||
customersModel->setQuery("select * from customers", m_db);
|
||||
report->dataManager()->addModel("external_customers_data",customersModel,true);
|
||||
report->dataManager()->addModel("external_customers_data", customersModel, true);
|
||||
QSqlQueryModel* ordersModel = new QSqlQueryModel();
|
||||
ordersModel->setQuery("Select * from orders",m_db);
|
||||
report->dataManager()->addModel("external_orders_data",ordersModel,true);
|
||||
m_customers = new QSqlQuery("Select * from customers limit 10",m_db);
|
||||
ordersModel->setQuery("Select * from orders", m_db);
|
||||
report->dataManager()->addModel("external_orders_data", ordersModel, true);
|
||||
m_customers = new QSqlQuery("Select * from customers limit 10", m_db);
|
||||
m_customers->first();
|
||||
m_orders = new QSqlQuery(m_db);
|
||||
m_orders->prepare("Select * from orders where CustomerID = :id");
|
||||
int index = m_customers->record().indexOf("CustomerID");
|
||||
m_orders->bindValue(":id",m_customers->value(index));
|
||||
m_orders->bindValue(":id", m_customers->value(index));
|
||||
m_orders->exec();
|
||||
}
|
||||
}
|
||||
|
||||
LimeReport::ICallbackDatasource * callbackDatasource = report->dataManager()->createCallbackDatasource("master");
|
||||
connect(callbackDatasource, SIGNAL(getCallbackData(LimeReport::CallbackInfo,QVariant&)),
|
||||
this, SLOT(slotGetCallbackData(LimeReport::CallbackInfo,QVariant&)));
|
||||
connect(callbackDatasource, SIGNAL(changePos(const LimeReport::CallbackInfo::ChangePosType&,bool&)),
|
||||
this, SLOT(slotChangePos(const LimeReport::CallbackInfo::ChangePosType&,bool&)));
|
||||
LimeReport::ICallbackDatasource* callbackDatasource
|
||||
= report->dataManager()->createCallbackDatasource("master");
|
||||
connect(callbackDatasource, SIGNAL(getCallbackData(LimeReport::CallbackInfo, QVariant&)), this,
|
||||
SLOT(slotGetCallbackData(LimeReport::CallbackInfo, QVariant&)));
|
||||
connect(callbackDatasource,
|
||||
SIGNAL(changePos(const LimeReport::CallbackInfo::ChangePosType&, bool&)), this,
|
||||
SLOT(slotChangePos(const LimeReport::CallbackInfo::ChangePosType&, bool&)));
|
||||
|
||||
callbackDatasource = report->dataManager()->createCallbackDatasource("detail");
|
||||
connect(callbackDatasource, SIGNAL(getCallbackData(LimeReport::CallbackInfo,QVariant&)),
|
||||
this, SLOT(slotGetCallbackChildData(LimeReport::CallbackInfo,QVariant&)));
|
||||
connect(callbackDatasource, SIGNAL(changePos(const LimeReport::CallbackInfo::ChangePosType&,bool&)),
|
||||
this, SLOT(slotChangeChildPos(const LimeReport::CallbackInfo::ChangePosType&,bool&)));
|
||||
connect(callbackDatasource, SIGNAL(getCallbackData(LimeReport::CallbackInfo, QVariant&)), this,
|
||||
SLOT(slotGetCallbackChildData(LimeReport::CallbackInfo, QVariant&)));
|
||||
connect(callbackDatasource,
|
||||
SIGNAL(changePos(const LimeReport::CallbackInfo::ChangePosType&, bool&)), this,
|
||||
SLOT(slotChangeChildPos(const LimeReport::CallbackInfo::ChangePosType&, bool&)));
|
||||
|
||||
callbackDatasource = report->dataManager()->createCallbackDatasource("oneSlotDS");
|
||||
connect(callbackDatasource, SIGNAL(getCallbackData(LimeReport::CallbackInfo,QVariant&)),
|
||||
this, SLOT(slotOneSlotDS(LimeReport::CallbackInfo,QVariant&)));
|
||||
connect(callbackDatasource, SIGNAL(getCallbackData(LimeReport::CallbackInfo, QVariant&)), this,
|
||||
SLOT(slotOneSlotDS(LimeReport::CallbackInfo, QVariant&)));
|
||||
|
||||
QStringList simpleData;
|
||||
simpleData << "value1" << "value2" << "value3";
|
||||
simpleData << "value1"
|
||||
<< "value2"
|
||||
<< "value3";
|
||||
QStringListModel* stringListModel = new QStringListModel();
|
||||
stringListModel->setStringList(simpleData);
|
||||
|
||||
report->dataManager()->addModel("string_list",stringListModel,true);
|
||||
report->dataManager()->addModel("string_list", stringListModel, true);
|
||||
QStringList strList;
|
||||
strList<<"value1"<<"value2";
|
||||
//QScriptValue value = qScriptValueFromSequence(report->scriptManager()->scriptEngine(),strList);
|
||||
//report->scriptManager()->scriptEngine()->globalObject().setProperty("test_list",value);
|
||||
|
||||
|
||||
strList << "value1"
|
||||
<< "value2";
|
||||
// QScriptValue value =
|
||||
// qScriptValueFromSequence(report->scriptManager()->scriptEngine(),strList);
|
||||
// report->scriptManager()->scriptEngine()->globalObject().setProperty("test_list",value);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@@ -122,8 +131,9 @@ void MainWindow::on_pushButton_clicked()
|
||||
EASY_PROFILER_ENABLE;
|
||||
EASY_BLOCK("design report");
|
||||
report->dataManager()->clearUserVariables();
|
||||
if (!ui->leVariableName->text().isEmpty() && !ui->leVariableValue->text().isEmpty()){
|
||||
report->dataManager()->setReportVariable(ui->leVariableName->text(), ui->leVariableValue->text());
|
||||
if (!ui->leVariableName->text().isEmpty() && !ui->leVariableValue->text().isEmpty()) {
|
||||
report->dataManager()->setReportVariable(ui->leVariableName->text(),
|
||||
ui->leVariableValue->text());
|
||||
}
|
||||
report->setShowProgressDialog(false);
|
||||
report->designReport();
|
||||
@@ -135,27 +145,30 @@ void MainWindow::on_pushButton_clicked()
|
||||
|
||||
void MainWindow::on_pushButton_2_clicked()
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(this,"Select report file",QApplication::applicationDirPath()+"/demo_reports/","*.lrxml");
|
||||
QString fileName = QFileDialog::getOpenFileName(
|
||||
this, "Select report file", QApplication::applicationDirPath() + "/demo_reports/",
|
||||
"*.lrxml");
|
||||
if (!fileName.isEmpty()) {
|
||||
EASY_PROFILER_ENABLE;
|
||||
EASY_BLOCK("Load file");
|
||||
report->loadFromFile(fileName);
|
||||
EASY_END_BLOCK;
|
||||
EASY_BLOCK("Set report variable");
|
||||
if (!ui->leVariableName->text().isEmpty() && !ui->leVariableValue->text().isEmpty()){
|
||||
report->dataManager()->setReportVariable(ui->leVariableName->text(), ui->leVariableValue->text());
|
||||
if (!ui->leVariableName->text().isEmpty() && !ui->leVariableValue->text().isEmpty()) {
|
||||
report->dataManager()->setReportVariable(ui->leVariableName->text(),
|
||||
ui->leVariableValue->text());
|
||||
}
|
||||
EASY_END_BLOCK;
|
||||
#ifdef BUILD_WITH_EASY_PROFILER
|
||||
profiler::dumpBlocksToFile("test.prof");
|
||||
#endif
|
||||
// QPrinter* printer = new QPrinter;
|
||||
// QPrintDialog dialog(printer);
|
||||
// if (dialog.exec()){
|
||||
// QMap<QString, QPrinter*> printers;
|
||||
// printers.insert("default",printer);
|
||||
// report->printReport(printers);
|
||||
// }
|
||||
// QPrinter* printer = new QPrinter;
|
||||
// QPrintDialog dialog(printer);
|
||||
// if (dialog.exec()){
|
||||
// QMap<QString, QPrinter*> printers;
|
||||
// printers.insert("default",printer);
|
||||
// report->printReport(printers);
|
||||
// }
|
||||
report->setShowProgressDialog(true);
|
||||
report->previewReport();
|
||||
}
|
||||
@@ -163,10 +176,10 @@ void MainWindow::on_pushButton_2_clicked()
|
||||
|
||||
void MainWindow::renderStarted()
|
||||
{
|
||||
if (report->isShowProgressDialog()){
|
||||
if (report->isShowProgressDialog()) {
|
||||
m_currentPage = 0;
|
||||
m_progressDialog = new QProgressDialog(tr("Start render"),tr("Cancel"),0,0,this);
|
||||
//m_progressDialog->setWindowModality(Qt::WindowModal);
|
||||
m_progressDialog = new QProgressDialog(tr("Start render"), tr("Cancel"), 0, 0, this);
|
||||
// m_progressDialog->setWindowModality(Qt::WindowModal);
|
||||
connect(m_progressDialog, SIGNAL(canceled()), report, SLOT(cancelRender()));
|
||||
QApplication::processEvents();
|
||||
m_progressDialog->show();
|
||||
@@ -175,22 +188,22 @@ void MainWindow::renderStarted()
|
||||
|
||||
void MainWindow::renderPageFinished(int renderedPageCount)
|
||||
{
|
||||
if (m_progressDialog){
|
||||
m_progressDialog->setLabelText(QString::number(renderedPageCount)+tr(" page rendered"));
|
||||
if (m_progressDialog) {
|
||||
m_progressDialog->setLabelText(QString::number(renderedPageCount) + tr(" page rendered"));
|
||||
m_progressDialog->setValue(renderedPageCount);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::renderFinished()
|
||||
{
|
||||
if (m_progressDialog){
|
||||
if (m_progressDialog) {
|
||||
m_progressDialog->close();
|
||||
delete m_progressDialog;
|
||||
}
|
||||
m_progressDialog = 0;
|
||||
}
|
||||
|
||||
void MainWindow::prepareData(QSqlQuery* ds, LimeReport::CallbackInfo info, QVariant &data)
|
||||
void MainWindow::prepareData(QSqlQuery* ds, LimeReport::CallbackInfo info, QVariant& data)
|
||||
{
|
||||
switch (info.dataType) {
|
||||
case LimeReport::CallbackInfo::ColumnCount:
|
||||
@@ -210,67 +223,81 @@ void MainWindow::prepareData(QSqlQuery* ds, LimeReport::CallbackInfo info, QVari
|
||||
case LimeReport::CallbackInfo::ColumnData:
|
||||
data = ds->value(ds->record().indexOf(info.columnName));
|
||||
break;
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::slotGetCallbackData(LimeReport::CallbackInfo info, QVariant &data)
|
||||
void MainWindow::slotGetCallbackData(LimeReport::CallbackInfo info, QVariant& data)
|
||||
{
|
||||
if (!m_customers) return;
|
||||
if (!m_customers)
|
||||
return;
|
||||
prepareData(m_customers, info, data);
|
||||
}
|
||||
|
||||
void MainWindow::slotChangePos(const LimeReport::CallbackInfo::ChangePosType &type, bool &result)
|
||||
void MainWindow::slotChangePos(const LimeReport::CallbackInfo::ChangePosType& type, bool& result)
|
||||
{
|
||||
QSqlQuery* ds = m_customers;
|
||||
if (!ds) return;
|
||||
if (type == LimeReport::CallbackInfo::First) {result = ds->first();}
|
||||
else {result = ds->next();}
|
||||
if (result){
|
||||
m_orders->bindValue(":id",m_customers->value(m_customers->record().indexOf("CustomerID")));
|
||||
if (!ds)
|
||||
return;
|
||||
if (type == LimeReport::CallbackInfo::First) {
|
||||
result = ds->first();
|
||||
} else {
|
||||
result = ds->next();
|
||||
}
|
||||
if (result) {
|
||||
m_orders->bindValue(":id", m_customers->value(m_customers->record().indexOf("CustomerID")));
|
||||
m_orders->exec();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::slotGetCallbackChildData(LimeReport::CallbackInfo info, QVariant &data)
|
||||
void MainWindow::slotGetCallbackChildData(LimeReport::CallbackInfo info, QVariant& data)
|
||||
{
|
||||
if (!m_orders) return ;
|
||||
if (!m_orders)
|
||||
return;
|
||||
prepareData(m_orders, info, data);
|
||||
}
|
||||
|
||||
void MainWindow::slotChangeChildPos(const LimeReport::CallbackInfo::ChangePosType &type, bool &result)
|
||||
void MainWindow::slotChangeChildPos(const LimeReport::CallbackInfo::ChangePosType& type,
|
||||
bool& result)
|
||||
{
|
||||
QSqlQuery* ds = m_orders;
|
||||
if (!ds) return;
|
||||
if (type == LimeReport::CallbackInfo::First) result = ds->first();
|
||||
else result = ds->next();
|
||||
if (!ds)
|
||||
return;
|
||||
if (type == LimeReport::CallbackInfo::First)
|
||||
result = ds->first();
|
||||
else
|
||||
result = ds->next();
|
||||
}
|
||||
|
||||
void MainWindow::slotOneSlotDS(LimeReport::CallbackInfo info, QVariant &data)
|
||||
void MainWindow::slotOneSlotDS(LimeReport::CallbackInfo info, QVariant& data)
|
||||
{
|
||||
QStringList columns;
|
||||
columns << "Name" << "Value" << "Image";
|
||||
columns << "Name"
|
||||
<< "Value"
|
||||
<< "Image";
|
||||
switch (info.dataType) {
|
||||
case LimeReport::CallbackInfo::RowCount:
|
||||
data = 4;
|
||||
break;
|
||||
case LimeReport::CallbackInfo::ColumnCount:
|
||||
data = columns.size();
|
||||
break;
|
||||
// case LimeReport::CallbackInfo::IsEmpty:
|
||||
// data = false;
|
||||
// break;
|
||||
case LimeReport::CallbackInfo::ColumnHeaderData: {
|
||||
data = columns.at(info.index);
|
||||
break;
|
||||
}
|
||||
case LimeReport::CallbackInfo::ColumnData:
|
||||
if (info.columnName == "Image")
|
||||
data = QImage(":/report//images/logo32");
|
||||
else {
|
||||
data = info.columnName+" "+QString::number(info.index);
|
||||
}
|
||||
break;
|
||||
default: break;
|
||||
case LimeReport::CallbackInfo::RowCount:
|
||||
data = 4;
|
||||
break;
|
||||
case LimeReport::CallbackInfo::ColumnCount:
|
||||
data = columns.size();
|
||||
break;
|
||||
// case LimeReport::CallbackInfo::IsEmpty:
|
||||
// data = false;
|
||||
// break;
|
||||
case LimeReport::CallbackInfo::ColumnHeaderData: {
|
||||
data = columns.at(info.index);
|
||||
break;
|
||||
}
|
||||
case LimeReport::CallbackInfo::ColumnData:
|
||||
if (info.columnName == "Image")
|
||||
data = QImage(":/report//images/logo32");
|
||||
else {
|
||||
data = info.columnName + " " + QString::number(info.index);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -30,22 +30,22 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include "lrreportengine.h"
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QProgressDialog>
|
||||
#include <QtSql/QSqlDatabase>
|
||||
#include <QtSql/QSqlQueryModel>
|
||||
#include "lrreportengine.h"
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
class MainWindow: public QMainWindow {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
explicit MainWindow(QWidget* parent = 0);
|
||||
~MainWindow();
|
||||
private slots:
|
||||
void on_pushButton_clicked();
|
||||
@@ -58,11 +58,13 @@ private slots:
|
||||
void slotGetCallbackChildData(LimeReport::CallbackInfo info, QVariant& data);
|
||||
void slotChangeChildPos(const LimeReport::CallbackInfo::ChangePosType& type, bool& result);
|
||||
void slotOneSlotDS(LimeReport::CallbackInfo info, QVariant& data);
|
||||
|
||||
private:
|
||||
void prepareData(QSqlQuery* ds, LimeReport::CallbackInfo info, QVariant &data);
|
||||
void prepareData(QSqlQuery* ds, LimeReport::CallbackInfo info, QVariant& data);
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
LimeReport::ReportEngine *report;
|
||||
Ui::MainWindow* ui;
|
||||
LimeReport::ReportEngine* report;
|
||||
QProgressDialog* m_progressDialog;
|
||||
int m_currentPage;
|
||||
QSqlDatabase m_db;
|
||||
@@ -73,9 +75,6 @@ private:
|
||||
int m_currentOrderRecord;
|
||||
QSqlQuery* m_customers;
|
||||
QSqlQuery* m_orders;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
Reference in New Issue
Block a user