Added report variable filler.

master
Josef Rokos 8 years ago
parent 37b2dd7246
commit 1e785fd488

@ -65,7 +65,8 @@ SOURCES += \
reporting/reportdialog.cpp \
csvimporter.cpp \
importdialog.cpp \
importprogress.cpp
importprogress.cpp \
reporting/variablefiller.cpp
HEADERS += core.h\
core_global.h \
@ -130,7 +131,8 @@ HEADERS += core.h\
csvimporter.h \
iimportprogress.h \
importdialog.h \
importprogress.h
importprogress.h \
reporting/variablefiller.h
unix {
target.path = /usr/lib

@ -244,6 +244,16 @@ protected:
}
}
virtual int currentRecordId()
{
if (tableView()->currentIndex().isValid())
{
return m_tableModel->itemFromIndex(tableView()->currentIndex())->id();
}
return 0;
}
void addRow(QSharedPointer<T> entity)
{
m_tableModel->addRow(entity);

@ -22,10 +22,17 @@ IGridForm::IGridForm(QWidget *parent) :
m_columnDialog = new ColumnDialog(this);
connect(m_columnDialog, SIGNAL(accepted()), this, SLOT(columnsAccepted()));
m_varFiller = new VariableFiller();
}
IGridForm::~IGridForm()
{
if (m_varFiller != NULL)
{
delete m_varFiller;
}
delete ui;
}
@ -59,6 +66,16 @@ QWidget *IGridForm::toolbar()
return ui->widget;
}
void IGridForm::setReportVarFiller(VariableFiller *filler)
{
if (m_varFiller != NULL)
{
delete m_varFiller;
}
m_varFiller = filler;
}
void IGridForm::hideColumns(const QList<int> &cols)
{
foreach (int col, cols) {
@ -157,6 +174,12 @@ void IGridForm::on_btnPrint_clicked()
{
ReportDialog *dialog = new ReportDialog(this);
dialog->setAttribute(Qt::WA_DeleteOnClose);
if (m_varFiller != NULL)
{
m_varFiller->fillList(Context::instance().plugin(pluginId())->reports(), currentRecordId());
}
dialog->setReports(Context::instance().plugin(pluginId())->reports());
dialog->show();
}

@ -12,6 +12,7 @@
#include "filterui.h"
#include "defaultformhandler.h"
#include "core_global.h"
#include "reporting/variablefiller.h"
namespace Ui {
class GridForm;
@ -30,6 +31,7 @@ public:
QTableView *tableView();
QWidget *toolbar();
virtual void setTranslations(const QMap<QString, QString> &translations) = 0;
void setReportVarFiller(VariableFiller *filler);
signals:
void dataChanged();
@ -44,6 +46,7 @@ protected:
virtual bool canAddRecord() { return true; }
virtual bool canEditRecord() { return true; }
virtual bool canDeleteRecord() { return true; }
virtual int currentRecordId() = 0;
void hideColumns(const QList<int> &cols);
QWidget *filterWidget();
void enableButtons();
@ -69,6 +72,7 @@ private:
Ui::GridForm *ui;
QMenu *m_contextMenu;
ColumnDialog *m_columnDialog;
VariableFiller *m_varFiller;
protected:
FilterUi *m_filterUi;

@ -55,7 +55,7 @@ void Report::setVariables(const QMap<QString, QString> &variables)
m_variables = variables;
}
void Report::addVariable(const QString &varName, const QString &value)
void Report::setVariable(const QString &varName, const QString &value)
{
m_variables[varName] = value;
}

@ -27,7 +27,7 @@ public:
QMap<QString, QString> variables() const;
void setVariables(const QMap<QString, QString> &variables);
void addVariable(const QString &varName, const QString &value);
void setVariable(const QString &varName, const QString &value);
private:
QString m_name;

@ -32,6 +32,10 @@ void ReportViewer::setReport(ReportPtr report)
m_report->loadFromByteArray(&data);
m_report->setReportFileName(reportPath);
m_report->dataManager()->setReportVariable("dbPath", Context::instance().settings()->value("db/path", "").toString());
foreach (QString key, report->variables().keys()) {
m_report->dataManager()->setReportVariable(key, report->variables()[key]);
}
}
void ReportViewer::openPreview()

@ -0,0 +1,52 @@
#include "variablefiller.h"
#include "../settingsservice.h"
VariableFiller::VariableFiller()
{
}
VariableFiller::~VariableFiller()
{
}
void VariableFiller::fill(ReportPtr report, int recordId)
{
if (m_settings.isNull())
{
loadSettings();
}
QMap<QString, QString> vars;
vars[COMPANY] = m_settings->firmName();
vars[STREET] = m_settings->street();
vars[HOUSE_NUMBER] = m_settings->houseNumber();
vars[CITY] = m_settings->city();
vars[ZIP_CODE] = m_settings->zipCode();
vars[IC] = QString::number(m_settings->ic());
vars[DIC] = m_settings->dic();
vars[LOGO_PATH] = m_settings->logoPath();
if (recordId > 0)
{
vars[RECORD_ID] = QString::number(recordId);
}
else
{
vars[RECORD_ID] = "";
}
report->setVariables(vars);
}
void VariableFiller::fillList(QList<ReportPtr> reports, int recordId)
{
foreach (ReportPtr report, reports) {
fill(report, recordId);
}
}
void VariableFiller::loadSettings()
{
SettingsService srv("CORE");
m_settings = srv.loadSettings<GlobalSettings>();
}

@ -0,0 +1,32 @@
#ifndef VARIABLEFILLER_H
#define VARIABLEFILLER_H
#include "report.h"
#include "../settings/globalsettings.h"
#include "../core_global.h"
#define COMPANY "COMPANY"
#define STREET "STREET"
#define HOUSE_NUMBER "HOUSE_NUMBER"
#define CITY "CITY"
#define ZIP_CODE "ZIP_CODE"
#define IC "IC"
#define DIC "DIC"
#define LOGO_PATH "LOGO_PATH"
#define RECORD_ID "RECORD_ID"
class CORESHARED_EXPORT VariableFiller
{
public:
VariableFiller();
virtual ~VariableFiller();
virtual void fill(ReportPtr report, int recordId = 0);
void fillList(QList<ReportPtr> reports, int recordId = 0);
void loadSettings();
private:
GlobalSettingsPtr m_settings;
};
#endif // VARIABLEFILLER_H
Loading…
Cancel
Save