From 0bca412d27462fe317e185d72ac88856c7b0ee06 Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Wed, 23 May 2018 14:50:55 +0200 Subject: [PATCH] Adding reports without recompilation now possible. --- core/imetadataplugin.cpp | 43 ++++++++++++++++++++++++++++++---------- core/imetadataplugin.h | 2 ++ 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/core/imetadataplugin.cpp b/core/imetadataplugin.cpp index 50e57e2..88e5ab1 100644 --- a/core/imetadataplugin.cpp +++ b/core/imetadataplugin.cpp @@ -2,9 +2,11 @@ #include #include +#include #include #include #include +#include #include "igridform.h" @@ -112,17 +114,8 @@ void IMetaDataPlugin::parseMetaData(const QJsonObject &metaData) } QJsonValue repArray = data.toObject()["reports"]; - foreach (QJsonValue repVal, repArray.toArray()) { - QJsonObject repObj = repVal.toObject(); - - ReportPtr report = ReportPtr(new Report()); - report->setName(repObj["name"].toString()); - report->setDescription(repObj["description"].toString()); - report->setListReport(repObj["listReport"].toBool()); - report->setFile(repObj["file"].toString()); - - m_reports.append(report); - } + addReportsFromJson(repArray); + addCustomReports(); } QString IMetaDataPlugin::parseLocaleText(const QJsonObject &object) @@ -144,3 +137,31 @@ QString IMetaDataPlugin::parseLocaleText(const QJsonObject &object) return ret; } +void IMetaDataPlugin::addCustomReports() +{ + QString jsonPath = qApp->applicationDirPath() + REPORT_ROOT + "/" + pluginId().toLower() + ".json"; + + QFile f (jsonPath); + if (f.open(QIODevice::ReadOnly | QIODevice::Text)) + { + QJsonDocument d = QJsonDocument::fromJson(f.readAll()); + QJsonObject obj = d.object(); + addReportsFromJson(obj.value("reports")); + } +} + +void IMetaDataPlugin::addReportsFromJson(const QJsonValue &repArray) +{ + foreach (QJsonValue repVal, repArray.toArray()) { + QJsonObject repObj = repVal.toObject(); + + ReportPtr report = ReportPtr(new Report()); + report->setName(repObj["name"].toString()); + report->setDescription(repObj["description"].toString()); + report->setListReport(repObj["listReport"].toBool()); + report->setFile(repObj["file"].toString()); + + m_reports.append(report); + } +} + diff --git a/core/imetadataplugin.h b/core/imetadataplugin.h index 1eb7fa1..258b01d 100644 --- a/core/imetadataplugin.h +++ b/core/imetadataplugin.h @@ -38,6 +38,8 @@ private: ReportList m_reports; QString parseLocaleText(const QJsonObject &object); + void addCustomReports(); + void addReportsFromJson(const QJsonValue &repArray); }; #endif // IMETADATAPLUGIN_H