Added report variable filler.
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user