Added reporting support- depends on LimeReport.

This commit is contained in:
2017-03-24 14:49:46 +01:00
parent d7952b987d
commit 37c9ee15af
27 changed files with 895 additions and 6 deletions
+61
View File
@@ -0,0 +1,61 @@
#include "report.h"
Report::Report()
{
}
QString Report::name() const
{
return m_name;
}
void Report::setName(const QString &name)
{
m_name = name;
}
QString Report::description() const
{
return m_description;
}
void Report::setDescription(const QString &description)
{
m_description = description;
}
QString Report::file() const
{
return m_file;
}
void Report::setFile(const QString &file)
{
m_file = file;
}
bool Report::listReport() const
{
return m_listReport;
}
void Report::setListReport(bool listReport)
{
m_listReport = listReport;
}
QMap<QString, QString> Report::variables() const
{
return m_variables;
}
void Report::setVariables(const QMap<QString, QString> &variables)
{
m_variables = variables;
}
void Report::addVariable(const QString &varName, const QString &value)
{
m_variables[varName] = value;
}
+43
View File
@@ -0,0 +1,43 @@
#ifndef REPORT_H
#define REPORT_H
#include <QString>
#include <QMap>
#include <QList>
#include <QSharedPointer>
#include "../core_global.h"
class CORESHARED_EXPORT Report
{
public:
Report();
QString name() const;
void setName(const QString &name);
QString description() const;
void setDescription(const QString &description);
QString file() const;
void setFile(const QString &file);
bool listReport() const;
void setListReport(bool listReport);
QMap<QString, QString> variables() const;
void setVariables(const QMap<QString, QString> &variables);
void addVariable(const QString &varName, const QString &value);
private:
QString m_name;
QString m_description;
QString m_file;
bool m_listReport;
QMap<QString, QString> m_variables;
};
typedef QSharedPointer<Report> ReportPtr;
typedef QList<ReportPtr> ReportList;
#endif // REPORT_H
+50
View File
@@ -0,0 +1,50 @@
#include "reportdialog.h"
#include "ui_reportdialog.h"
#include <QStandardItemModel>
#include <QIcon>
#include "reportviewer.h"
ReportDialog::ReportDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ReportDialog)
{
ui->setupUi(this);
}
ReportDialog::~ReportDialog()
{
delete ui;
}
void ReportDialog::setReports(ReportList reports)
{
QStandardItemModel *model = qobject_cast<QStandardItemModel*>(ui->listReports->model());
if (model == NULL)
{
model = new QStandardItemModel(0, 1);
}
else
{
model->clear();
}
foreach (ReportPtr report, reports) {
QStandardItem *item = new QStandardItem((report->listReport() ? QIcon(":/icons/list.svg") : QIcon(":/icons/report.svg")), report->name());
model->appendRow(item);
}
ui->listReports->setModel(model);
m_reports = reports;
}
void ReportDialog::on_btnPreview_clicked()
{
ReportViewer *viewer = new ReportViewer(this);
viewer->setAttribute(Qt::WA_DeleteOnClose);
viewer->setReport(m_reports[ui->listReports->currentIndex().row()]);
viewer->openPreview();
}
+29
View File
@@ -0,0 +1,29 @@
#ifndef REPORTDIALOG_H
#define REPORTDIALOG_H
#include <QDialog>
#include "report.h"
namespace Ui {
class ReportDialog;
}
class ReportDialog : public QDialog
{
Q_OBJECT
public:
explicit ReportDialog(QWidget *parent = 0);
~ReportDialog();
void setReports(ReportList reports);
private slots:
void on_btnPreview_clicked();
private:
Ui::ReportDialog *ui;
ReportList m_reports;
};
#endif // REPORTDIALOG_H
+184
View File
@@ -0,0 +1,184 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ReportDialog</class>
<widget class="QDialog" name="ReportDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>569</width>
<height>442</height>
</rect>
</property>
<property name="windowTitle">
<string>Reports</string>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<item>
<widget class="QFrame" name="frame">
<property name="styleSheet">
<string notr="true">background-color: rgb(255, 255, 255);</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="minimumSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>36</width>
<height>36</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap resource="../rc.qrc">:/icons/print.svg</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="font">
<font>
<pointsize>10</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="styleSheet">
<string notr="true">color: rgb(0, 0, 0);</string>
</property>
<property name="text">
<string>Print reports</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="widgetReports" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QListView" name="listReports"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="widget_2" native="true">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>90</height>
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QTextBrowser" name="textDescription">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnPreview">
<property name="text">
<string>Preview</string>
</property>
<property name="icon">
<iconset resource="../rc.qrc">
<normaloff>:/icons/report.svg</normaloff>:/icons/report.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnPrint">
<property name="text">
<string>Print</string>
</property>
<property name="icon">
<iconset resource="../rc.qrc">
<normaloff>:/icons/print.svg</normaloff>:/icons/print.svg</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnClose">
<property name="text">
<string>Close</string>
</property>
<property name="icon">
<iconset resource="../rc.qrc">
<normaloff>:/icons/close.svg</normaloff>:/icons/close.svg</iconset>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../rc.qrc"/>
</resources>
<connections/>
</ui>
+70
View File
@@ -0,0 +1,70 @@
#include "reportviewer.h"
#include "ui_reportviewer.h"
#include "../context.h"
#include <QFile>
#include <LimeReport>
ReportViewer::ReportViewer(QWidget *parent) :
QDialog(parent),
ui(new Ui::ReportViewer)
{
ui->setupUi(this);
}
ReportViewer::~ReportViewer()
{
delete ui;
}
void ReportViewer::setReport(ReportPtr report)
{
m_report = new LimeReport::ReportEngine(this);
QString reportPath = qApp->applicationDirPath() + REPORT_ROOT + "/" + report->file();
QFile file(reportPath);
file.open(QFile::ReadOnly);
m_report->loadFromByteArray(&file.readAll());
m_report->setReportFileName(reportPath);
m_report->dataManager()->setReportVariable("dbPath", Context::instance().settings()->value("db/path", "").toString());
}
void ReportViewer::openPreview()
{
showMaximized();
m_prevWidget = m_report->createPreviewWidget(this);
connect(m_prevWidget, SIGNAL(pagesSet(int)), this, SLOT(slotPageSet(int)));
connect(ui->pageNavigator, SIGNAL(valueChanged(int)), m_prevWidget, SLOT(pageNavigatorChanged(int)));
connect(ui->btnPrint, SIGNAL(clicked(bool)), m_prevWidget, SLOT(print()));
connect(ui->btnPdf, SIGNAL(clicked(bool)), m_prevWidget, SLOT(printToPDF()));
connect(ui->btnPageUp, SIGNAL(clicked(bool)), m_prevWidget, SLOT(priorPage()));
connect(ui->btnPageDown, SIGNAL(clicked(bool)), m_prevWidget, SLOT(nextPage()));
connect(ui->btnZoomIn, SIGNAL(clicked(bool)), m_prevWidget, SLOT(zoomIn()));
connect(ui->btnZoomOut, SIGNAL(clicked(bool)), m_prevWidget, SLOT(zoomOut()));
connect(ui->btnFitHoriz, SIGNAL(clicked(bool)), m_prevWidget, SLOT(fitWidth()));
connect(ui->btnFitVert, SIGNAL(clicked(bool)), m_prevWidget, SLOT(fitPage()));
ui->reportLayout->addWidget(m_prevWidget);
m_prevWidget->refreshPages();
}
void ReportViewer::on_btnClose_clicked()
{
close();
}
void ReportViewer::on_btnEdit_clicked()
{
m_report->designReport();
}
void ReportViewer::slotPageSet(int page)
{
ui->pageNavigator->setSuffix(ui->pageNavigator->suffix() + QString::number(page));
ui->pageNavigator->setMinimum(1);
ui->pageNavigator->setMaximum(page);
}
+40
View File
@@ -0,0 +1,40 @@
#ifndef REPORTVIEWER_H
#define REPORTVIEWER_H
#include <QDialog>
#include "report.h"
namespace Ui {
class ReportViewer;
}
namespace LimeReport {
class PreviewReportWidget;
class ReportEngine;
}
class ReportViewer : public QDialog
{
Q_OBJECT
public:
explicit ReportViewer(QWidget *parent = 0);
~ReportViewer();
void setReport(ReportPtr report);
void openPreview();
private slots:
void on_btnClose_clicked();
void on_btnEdit_clicked();
void slotPageSet(int page);
private:
Ui::ReportViewer *ui;
LimeReport::PreviewReportWidget *m_prevWidget;
LimeReport::ReportEngine *m_report;
};
#endif // REPORTVIEWER_H
+312
View File
@@ -0,0 +1,312 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ReportViewer</class>
<widget class="QDialog" name="ReportViewer">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>914</width>
<height>675</height>
</rect>
</property>
<property name="windowTitle">
<string>Report</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QToolButton" name="btnClose">
<property name="toolTip">
<string>Close</string>
</property>
<property name="text">
<string>Close</string>
</property>
<property name="icon">
<iconset resource="../rc.qrc">
<normaloff>:/icons/close.svg</normaloff>:/icons/close.svg</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnPrint">
<property name="toolTip">
<string>Print</string>
</property>
<property name="text">
<string>Print</string>
</property>
<property name="icon">
<iconset resource="../rc.qrc">
<normaloff>:/icons/print.svg</normaloff>:/icons/print.svg</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnPdf">
<property name="toolTip">
<string>Export to PDF</string>
</property>
<property name="text">
<string>Export to PDF</string>
</property>
<property name="icon">
<iconset resource="../rc.qrc">
<normaloff>:/icons/pdf.svg</normaloff>:/icons/pdf.svg</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnEdit">
<property name="toolTip">
<string>Edit</string>
</property>
<property name="text">
<string>Edit</string>
</property>
<property name="icon">
<iconset resource="../rc.qrc">
<normaloff>:/icons/edit.svg</normaloff>:/icons/edit.svg</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnPageUp">
<property name="toolTip">
<string>Page up</string>
</property>
<property name="text">
<string>Page up</string>
</property>
<property name="icon">
<iconset resource="../rc.qrc">
<normaloff>:/icons/pageUp.svg</normaloff>:/icons/pageUp.svg</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="pageNavigator">
<property name="suffix">
<string> of </string>
</property>
<property name="prefix">
<string>Page: </string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnPageDown">
<property name="toolTip">
<string>Page down</string>
</property>
<property name="text">
<string>Page down</string>
</property>
<property name="icon">
<iconset resource="../rc.qrc">
<normaloff>:/icons/pageDown.svg</normaloff>:/icons/pageDown.svg</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnZoomOut">
<property name="toolTip">
<string>Zoom out</string>
</property>
<property name="text">
<string>Zoom out</string>
</property>
<property name="icon">
<iconset resource="../rc.qrc">
<normaloff>:/icons/zoomOut.svg</normaloff>:/icons/zoomOut.svg</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnZoomIn">
<property name="toolTip">
<string>Zoom in</string>
</property>
<property name="text">
<string>Zoom in</string>
</property>
<property name="icon">
<iconset resource="../rc.qrc">
<normaloff>:/icons/zoomIn.svg</normaloff>:/icons/zoomIn.svg</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnFitHoriz">
<property name="toolTip">
<string>Fit horizontal</string>
</property>
<property name="text">
<string>Fit horizontal</string>
</property>
<property name="icon">
<iconset resource="../rc.qrc">
<normaloff>:/icons/fitHorizontal.svg</normaloff>:/icons/fitHorizontal.svg</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnFitVert">
<property name="toolTip">
<string>Fit vertical</string>
</property>
<property name="text">
<string>Fit vertical</string>
</property>
<property name="icon">
<iconset resource="../rc.qrc">
<normaloff>:/icons/fitVertical.svg</normaloff>:/icons/fitVertical.svg</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="widget_2" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QVBoxLayout" name="reportLayout"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../rc.qrc"/>
</resources>
<connections/>
</ui>