0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 00:33:02 +03:00
This commit is contained in:
Rodrigo Torres 2021-08-24 04:22:30 -03:00
parent fa6cbef6a7
commit 67d8146b9c
25 changed files with 360 additions and 44 deletions

View File

@ -18,7 +18,7 @@ int main(int argc, char *argv[])
QApplication::setApplicationVersion(LIMEREPORT_VERSION_STR);
QStringList vars;
#if QT_VERSION > QT_VERSION_CHECK(5, 2, 0)
#if QT_VERSION > 0x050200
QCommandLineParser parser;
parser.addHelpOption();
parser.addVersionOption();

View File

@ -67,7 +67,11 @@ QString replaceHTMLSymbols(const QString &value)
return result;
}
#if QT_VERSION < 0x060000
QVector<QString> normalizeCaptures(const QRegExp& reg){
#else
QVector<QString> normalizeCaptures(const QRegularExpressionMatch &reg){
#endif
QVector<QString> result;
foreach (QString cap, reg.capturedTexts()) {
if (!cap.isEmpty())

View File

@ -51,7 +51,7 @@ namespace LimeReport {
#define VARIABLE_IS_NOT_USED
#endif
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
#if QT_VERSION >= 0x050800
Q_NAMESPACE
#endif
@ -104,10 +104,10 @@ namespace Const{
QString extractClassName(QString className);
QString escapeSimbols(const QString& value);
QString replaceHTMLSymbols(const QString &value);
#if QT_VERSION < 0x060000
#if QT_VERSION < 0x060000
QVector<QString> normalizeCaptures(const QRegExp &reg);
#else
QVector<QString> normalizeCaptures(const QRegularExpression &reg);
QVector<QString> normalizeCaptures(const QRegularExpressionMatch &reg);
#endif
bool isColorDark(QColor color);
@ -162,7 +162,7 @@ namespace Const{
{
public:
enum VariableDataType {Undefined, String, Bool, Int, Real, Date, Time, DateTime};
#if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0))
#if QT_VERSION >= 0x050500
Q_ENUM(VariableDataType)
#else
Q_ENUMS(VariableDataType)

View File

@ -31,7 +31,7 @@
#define LRSCRIPTENGINEMANAGERINTF_H
#include "qglobal.h"
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
#if QT_VERSION >= 0x050600
#ifndef USE_QTSCRIPTENGINE
#ifndef USE_QJSENGINE
#define USE_QJSENGINE

View File

@ -13,7 +13,7 @@ class AbstractLayout: public LayoutDesignIntf
Q_PROPERTY(int layoutSpacing READ layoutSpacing WRITE setLayoutSpacing)
public:
enum LayoutType{Layout,Table};
#if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0))
#if QT_VERSION >= 0x050500
Q_ENUM(LayoutType)
#else
Q_ENUMS(LayoutType)

View File

@ -152,7 +152,7 @@ public:
KANJI_INPUT_MODE = 3,
SJIS_INPUT_MODE = 4
};
#if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0))
#if QT_VERSION >= 0x050500
Q_ENUM(BarcodeType)
Q_ENUM(AngleType)
Q_ENUM(InputMode)

View File

@ -33,7 +33,7 @@ class SeriesItem : public QObject{
Q_PROPERTY(SeriesItemPreferredType preferredType READ preferredType WRITE setPreferredType)
public:
enum SeriesItemPreferredType {Bar, Line};
#if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0))
#if QT_VERSION >= 0x050500
Q_ENUM(SeriesItemPreferredType)
#else
Q_ENUMS(SeriesItemPreferredType)
@ -135,7 +135,7 @@ public:
enum LegendAlign{LegendAlignTop,LegendAlignCenter,LegendAlignBottom};
enum TitleAlign{TitleAlignLeft, TitleAlignCenter, TitleAlignRight};
enum ChartType{Pie, VerticalBar, HorizontalBar, Lines};
#if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0))
#if QT_VERSION >= 0x050500
Q_ENUM(LegendAlign)
Q_ENUM(TitleAlign)
Q_ENUM(ChartType)

View File

@ -58,7 +58,7 @@ public:
Hex = 1,
Base64 = 2
};
#if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0))
#if QT_VERSION >= 0x050500
Q_ENUM(Format)
#else
Q_ENUMS(Format)

View File

@ -47,7 +47,7 @@ class ShapeItem: public LimeReport::ItemDesignIntf
Q_PROPERTY(int cornerRadius READ cornerRadius WRITE setCornerRadius)
public:
enum ShapeType{HorizontalLine,VerticalLine,Ellipse,Rectangle};
#if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0))
#if QT_VERSION >= 0x050500
Q_ENUM(ShapeType)
#else
Q_ENUMS(ShapeType)

View File

@ -28,14 +28,18 @@
* GNU General Public License for more details. *
****************************************************************************/
#include "lrsimpletagparser.h"
#include <QRegExp>
#include <QDebug>
#include <QStringList>
#if QT_VERSION < 0x060000
#include <QRegExp>
#else
#include <QRegularExpression>
#endif
namespace LimeReport{
void HtmlContext::fillTagVector(QString html)
{
#if QT_VERSION < 0x060000
QRegExp rx("<[^<]*>");
QString buff=html;
int curPos=0;
@ -49,10 +53,20 @@ void HtmlContext::fillTagVector(QString html)
}
buff=buff.right(buff.length()-rx.matchedLength());
}
#else
QRegularExpression rx("<[^<]*>");
QString buff=html;
while(buff.contains(rx)){
QRegularExpressionMatch match = rx.match(buff);
// TODO: Qt6 port
}
#endif
}
QString HtmlContext::parseTag(QVector<Tag *> &storage, QString text, int &curPos, bool createTag)
{
#if QT_VERSION < 0x060000
QRegExp rx("<[^<]*>");
int pos=rx.indexIn(text);
int begPos=pos+curPos;
@ -78,12 +92,16 @@ QString HtmlContext::parseTag(QVector<Tag *> &storage, QString text, int &curPos
buff=buff.right(buff.length()-rx.matchedLength());
}
}
#else
QRegularExpression rx("<[^<]*>");
// TODO: Qt6 port
#endif
return "";
}
void HtmlContext::parseSymbs(QString text)
{
#if QT_VERSION < 0x060000
QRegExp rx("<[^<]*[^/]>");
while (text.contains(rx)){
int pos=rx.indexIn(text);
@ -100,6 +118,10 @@ void HtmlContext::parseSymbs(QString text)
text.replace(rx.cap(0)," ");
}
}
#else
QRegularExpression rx("<[^<]*>");
// TODO: Qt6 port
#endif
}
void HtmlContext::initSymbPatterns()

View File

@ -79,7 +79,7 @@ public:
enum AutoWidth{NoneAutoWidth, MaxWordLength, MaxStringLength};
enum AngleType{Angle0, Angle90, Angle180, Angle270, Angle45, Angle315};
enum ValueType{Default, DateTime, Double};
#if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0))
#if QT_VERSION >= 0x050500
Q_ENUM(AutoWidth)
Q_ENUM(AngleType)
Q_ENUM(ValueType)

View File

@ -138,7 +138,7 @@ public:
enum BandColumnsLayoutType{
Horizontal, Vertical, VerticalUniform
};
#if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0))
#if QT_VERSION >= 0x050500
Q_ENUM(BandColumnsLayoutType)
#else
Q_ENUMS(BandColumnsLayoutType)

View File

@ -144,7 +144,7 @@ public:
enum ItemAlign {LeftItemAlign,RightItemAlign,CenterItemAlign,ParentWidthItemAlign,DesignedItemAlign};
enum UnitType {Millimeters, Inches};
#if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0))
#if QT_VERSION >= 0x050500
Q_ENUM(BGMode)
Q_ENUM(BrushStyle)
Q_ENUM(ResizeFlags)

View File

@ -31,7 +31,9 @@
#include "lrdatadesignintf.h"
#include <QStringList>
#include <QSqlQuery>
#if QT_VERSION < 0x060000
#include <QRegExp>
#endif
#include <QSqlError>
#include <QSqlQueryModel>
#include <QFileInfo>
@ -421,6 +423,7 @@ QString DataSourceManager::extractField(QString source)
}
QString DataSourceManager::replaceVariables(QString value){
#if QT_VERSION < 0x060000
QRegExp rx(Const::VARIABLE_RX);
if (value.contains(rx)){
@ -438,10 +441,16 @@ QString DataSourceManager::replaceVariables(QString value){
}
}
return value;
#else
QRegularExpression rx(Const::VARIABLE_RX);
// TODO: Qt6 port
#endif
return QString();
}
QString DataSourceManager::replaceVariables(QString query, QMap<QString,QString> &aliasesToParam)
{
#if QT_VERSION < 0x060000
QRegExp rx(Const::VARIABLE_RX);
int curentAliasIndex = 0;
if (query.contains(rx)){
@ -480,10 +489,16 @@ QString DataSourceManager::replaceVariables(QString query, QMap<QString,QString>
}
}
return query;
#else
QRegularExpression rx(Const::VARIABLE_RX);
// TODO: Qt6 port
#endif
return QString();
}
QString DataSourceManager::replaceFields(QString query, QMap<QString,QString> &aliasesToParam, QString masterDatasource)
{
#if QT_VERSION < 0x060000
QRegExp rx(Const::FIELD_RX);
if (query.contains(rx)){
int curentAliasIndex=0;
@ -510,6 +525,11 @@ QString DataSourceManager::replaceFields(QString query, QMap<QString,QString> &a
}
}
return query;
#else
QRegularExpression rx(Const::FIELD_RX);
// TODO: Qt6 port
#endif
return QString();
}
void DataSourceManager::setReportVariable(const QString &name, const QVariant &value)

View File

@ -67,7 +67,11 @@ QString replaceHTMLSymbols(const QString &value)
return result;
}
#if QT_VERSION < 0x060000
QVector<QString> normalizeCaptures(const QRegExp& reg){
#else
QVector<QString> normalizeCaptures(const QRegularExpressionMatch& reg){
#endif
QVector<QString> result;
foreach (QString cap, reg.capturedTexts()) {
if (!cap.isEmpty())

View File

@ -51,7 +51,7 @@ namespace LimeReport {
#define VARIABLE_IS_NOT_USED
#endif
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
#if QT_VERSION >= 0x050800
Q_NAMESPACE
#endif
@ -104,10 +104,10 @@ namespace Const{
QString extractClassName(QString className);
QString escapeSimbols(const QString& value);
QString replaceHTMLSymbols(const QString &value);
#if QT_VERSION < 0x060000
#if QT_VERSION < 0x060000
QVector<QString> normalizeCaptures(const QRegExp &reg);
#else
QVector<QString> normalizeCaptures(const QRegularExpression &reg);
QVector<QString> normalizeCaptures(const QRegularExpressionMatch &reg);
#endif
bool isColorDark(QColor color);
@ -162,7 +162,7 @@ namespace Const{
{
public:
enum VariableDataType {Undefined, String, Bool, Int, Real, Date, Time, DateTime};
#if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0))
#if QT_VERSION >= 0x050500
Q_ENUM(VariableDataType)
#else
Q_ENUMS(VariableDataType)

View File

@ -34,7 +34,9 @@
#include "lrscriptenginemanager.h"
#include "lrpageitemdesignintf.h"
#if QT_VERSION < 0x060000
#include <QRegExp>
#endif
namespace LimeReport {
@ -42,13 +44,24 @@ void GroupFunction::slotBandRendered(BandDesignIntf *band)
{
ScriptEngineManager& sm = ScriptEngineManager::instance();
#if QT_VERSION < 0x060000
QRegExp rxField(Const::FIELD_RX);
QRegExp rxVar(Const::VARIABLE_RX);
#else
QRegularExpression rxField(Const::FIELD_RX);
QRegularExpression rxVar(Const::VARIABLE_RX);
#endif
switch (m_dataType){
case Field:
case Field:{
#if QT_VERSION < 0x060000
if (rxField.indexIn(m_data) != -1){
QString field = rxField.cap(1);
#else
QRegularExpressionMatch matchField = rxField.match(m_data);
if(matchField.hasMatch()){
QString field = matchField.captured(1);
#endif
if (m_dataManager->containsField(field)){
m_values.push_back(m_dataManager->fieldData(field));
m_valuesByBand.insert(band, m_dataManager->fieldData(field));
@ -57,9 +70,16 @@ void GroupFunction::slotBandRendered(BandDesignIntf *band)
}
}
break;
case Variable:
}
case Variable:{
#if QT_VERSION < 0x060000
if (rxVar.indexIn(m_data) != -1){
QString var = rxVar.cap(1);
#else
QRegularExpressionMatch matchVar = rxVar.match(m_data);
if(matchVar.hasMatch()){
QString var = matchVar.captured(1);
#endif
if (m_dataManager->containsVariable(var)){
m_values.push_back(m_dataManager->variable(var));
m_valuesByBand.insert(band, m_dataManager->variable(var));
@ -68,6 +88,7 @@ void GroupFunction::slotBandRendered(BandDesignIntf *band)
}
}
break;
}
case Script:
{
QVariant value = sm.evaluateScript(m_data);
@ -128,21 +149,41 @@ QVariant GroupFunction::multiplication(QVariant value1, QVariant value2)
GroupFunction::GroupFunction(const QString &expression, const QString &dataBandName, DataSourceManager* dataManager)
:m_data(expression), m_dataBandName(dataBandName), m_dataManager(dataManager), m_isValid(true), m_errorMessage("")
{
#if QT_VERSION < 0x060000
QRegExp rxField(Const::FIELD_RX,Qt::CaseInsensitive);
QRegExp rxVariable(Const::VARIABLE_RX,Qt::CaseInsensitive);
QRegExp rxScript(Const::SCRIPT_RX,Qt::CaseInsensitive);
#else
QRegularExpression rxField(Const::FIELD_RX, QRegularExpression::CaseInsensitiveOption);
QRegularExpression rxVariable(Const::VARIABLE_RX, QRegularExpression::CaseInsensitiveOption);
QRegularExpression rxScript(Const::SCRIPT_RX, QRegularExpression::CaseInsensitiveOption);
#endif
#if QT_VERSION < 0x060000
if (rxScript.indexIn(expression) != -1){
#else
QRegularExpressionMatch matchScript = rxScript.match(expression);
if(matchScript.hasMatch()){
#endif
m_dataType = Script;
return;
}
#if QT_VERSION < 0x060000
if (rxField.indexIn(expression) != -1){
#else
QRegularExpressionMatch matchField = rxField.match(expression);
if(matchField.hasMatch()){
#endif
m_dataType=Field;
return;
}
#if QT_VERSION < 0x060000
if (rxVariable.indexIn(expression) != -1){
#else
QRegularExpressionMatch matchVariable = rxVariable.match(expression);
if(matchVariable.hasMatch()){
#endif
m_dataType = Variable;
return;
}

View File

@ -43,7 +43,7 @@ class ItemDesignIntf : public BaseDesignIntf
Q_PROPERTY(ItemAlign itemAlign READ itemAlign WRITE setItemAlign)
public:
enum LocationType{Band,Page};
#if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0))
#if QT_VERSION >= 0x050500
Q_ENUM(LocationType)
#else
Q_ENUMS(LocationType)

View File

@ -762,10 +762,18 @@ void PageDesignIntf::dropEvent(QGraphicsSceneDragDropEvent* event)
if (!isVar){
BandDesignIntf* parentBand = dynamic_cast<BandDesignIntf*>(ti->parentItem());
if (parentBand && parentBand->datasourceName().isEmpty()){
#if QT_VERSION < 0x060000
QRegExp dataSource("(?:\\$D\\{\\s*(.*)\\..*\\})");
if (dataSource.indexIn(data) != -1){
parentBand->setProperty("datasource",dataSource.cap(1));
}
#else
QRegularExpression dataSource("(?:\\$D\\{\\s*(.*)\\..*\\})");
QRegularExpressionMatch match = dataSource.match(data);
if(match.hasMatch()){
parentBand->setProperty("datasource", match.captured(1));
}
#endif
}
}
}

View File

@ -102,7 +102,7 @@ public:
};
#endif
#if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0))
#if QT_VERSION >= 0x050500
Q_ENUM(Orientation)
Q_ENUM(PrintBehavior)
Q_ENUM(PageSize)

View File

@ -241,14 +241,10 @@ void PreviewReportWidget::print()
QPrinter lp(QPrinter::HighResolution);
if (!pi.defaultPrinter().isNull()){
#if QT_VERSION < 0x050000
lp.setPrinterName(pi.defaultPrinter().printerName());
#else
#if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0))
#if QT_VERSION >= 0x050300
lp.setPrinterName(pi.defaultPrinterName());
#else
lp.setPrinterName(pi.defaultPrinter().printerName());
#endif
#endif
}

View File

@ -276,14 +276,10 @@ bool ReportEnginePrivate::printPages(ReportPages pages, QPrinter *printer)
if (!printer&&!m_printerSelected){
QPrinterInfo pi;
if (!pi.defaultPrinter().isNull())
#if QT_VERSION < 0x050000
m_printer.data()->setPrinterName(pi.defaultPrinter().printerName());
#else
#if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0))
#if QT_VERSION >= 0x050300
m_printer.data()->setPrinterName(pi.defaultPrinterName());
#else
m_printer.data()->setPrinterName(pi.defaultPrinter().printerName());
#endif
#endif
QPrintDialog dialog(m_printer.data(),QApplication::activeWindow());
m_printerSelected = dialog.exec()!=QDialog::Rejected;
@ -397,14 +393,10 @@ bool ReportEnginePrivate::printReport(QPrinter* printer)
if (!printer&&!m_printerSelected){
QPrinterInfo pi;
if (!pi.defaultPrinter().isNull())
#if QT_VERSION < 0x050000
m_printer.data()->setPrinterName(pi.defaultPrinter().printerName());
#else
#if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0))
#if QT_VERSION >= 0x050300
m_printer.data()->setPrinterName(pi.defaultPrinterName());
#else
m_printer.data()->setPrinterName(pi.defaultPrinter().printerName());
#endif
#endif
QPrintDialog dialog(m_printer.data(),QApplication::activeWindow());
m_printerSelected = dialog.exec()!=QDialog::Rejected;
@ -1826,6 +1818,7 @@ PrintProcessor::PrintProcessor(QPrinter* printer)
bool PrintProcessor::printPage(PageItemDesignIntf::Ptr page)
{
#if QT_VERSION < 0x060000
if (!m_firstPage && !m_painter->isActive()) return false;
PageDesignIntf* backupPage = dynamic_cast<PageDesignIntf*>(page->scene());
@ -1887,11 +1880,77 @@ bool PrintProcessor::printPage(PageItemDesignIntf::Ptr page)
page->setPos(backupPagePos);
m_renderPage.removePageItem(page);
if (backupPage) backupPage->reactivatePageItem(page);
#else
if (!m_firstPage && !m_painter->isActive()) return false;
PageDesignIntf* backupPage = dynamic_cast<PageDesignIntf*>(page->scene());
QPointF backupPagePos = page->pos();
page->setPos(0,0);
m_renderPage.setPageItem(page);
m_renderPage.setSceneRect(m_renderPage.pageItem()->mapToScene(m_renderPage.pageItem()->rect()).boundingRect());
initPrinter(m_renderPage.pageItem());
if (!m_firstPage){
m_printer->newPage();
} else {
m_painter = new QPainter(m_printer);
if (!m_painter->isActive()) return false;
m_firstPage = false;
}
qreal leftMargin = m_printer->pageLayout().margins().left();
qreal topMargin = m_printer->pageLayout().margins().top();
qreal rightMargin = m_printer->pageLayout().margins().right();
qreal bottomMargin = m_printer->pageLayout().margins().bottom();
QRectF printerPageRect = m_printer->pageRect(QPrinter::Millimeter);
printerPageRect = QRectF(0,0,(printerPageRect.size().width() + rightMargin + leftMargin) * page->unitFactor(),
(printerPageRect.size().height() + bottomMargin + topMargin) * page->unitFactor());
if (page->printBehavior() == PageItemDesignIntf::Split && m_printer->pageLayout().pageSize() != (QPageSize::PageSizeId)page->pageSize() &&
printerPageRect.width() < page->geometry().width())
{
qreal pageWidth = page->geometry().width();
qreal pageHeight = page->geometry().height();
QRectF currentPrintingRect = printerPageRect;
qreal curHeight = 0;
qreal curWidth = 0;
bool first = true;
while (pageHeight > 0){
while (curWidth < pageWidth){
if (!first) m_printer->newPage(); else first = false;
m_renderPage.render(m_painter, m_printer->pageRect(QPrinter::Millimeter), currentPrintingRect);
currentPrintingRect.adjust(printerPageRect.size().width(), 0, printerPageRect.size().width(), 0);
curWidth += printerPageRect.size().width();
}
pageHeight -= printerPageRect.size().height();
curHeight += printerPageRect.size().height();
currentPrintingRect = printerPageRect;
currentPrintingRect.adjust(0, curHeight, 0, curHeight);
curWidth = 0;
}
} else {
if (page->getSetPageSizeToPrinter()){
QRectF source = page->geometry();
QSizeF inchSize = source.size() / (100 * 2.54);
QRectF target = QRectF(QPoint(0,0), inchSize * m_printer->resolution());
m_renderPage.render(m_painter, target, source);
} else {
m_renderPage.render(m_painter);
}
}
page->setPos(backupPagePos);
m_renderPage.removePageItem(page);
if (backupPage) backupPage->reactivatePageItem(page);
#endif
return true;
}
void PrintProcessor::initPrinter(PageItemDesignIntf* page)
{
#if QT_VERSION < 0x060000
if (page->oldPrintMode()){
m_printer->setPageMargins(page->leftMargin(),
page->topMargin(),
@ -1919,6 +1978,31 @@ void PrintProcessor::initPrinter(PageItemDesignIntf* page)
m_printer->setPaperSize(static_cast<QPrinter::PageSize>(page->pageSize()));
}
}
#else
if (page->oldPrintMode()){
m_printer->setPageMargins(QMarginsF(page->leftMargin(), page->topMargin(), page->rightMargin(), page->bottomMargin()),QPageLayout::Millimeter);
m_printer->setPageOrientation((QPageLayout::Orientation)page->pageOrientation());
QSizeF pageSize = (page->pageOrientation()==PageItemDesignIntf::Landscape)?
QSizeF(page->sizeMM().height(),page->sizeMM().width()):
page->sizeMM();
m_printer->setPageSize(QPageSize(pageSize, QPageSize::Millimeter));
} else {
m_printer->setFullPage(page->fullPage());
if (page->dropPrinterMargins())
m_printer->setPageMargins(QMarginsF(0, 0, 0, 0), QPageLayout::Point);
m_printer->setPageOrientation((QPageLayout::Orientation)page->pageOrientation());
if (page->pageSize()==PageItemDesignIntf::Custom){
QSizeF pageSize = (page->pageOrientation()==PageItemDesignIntf::Landscape)?
QSizeF(page->sizeMM().height(),page->sizeMM().width()):
page->sizeMM();
if (page->getSetPageSizeToPrinter() || m_printer->outputFormat() == QPrinter::PdfFormat)
m_printer->setPageSize(QPageSize(pageSize, QPageSize::Millimeter));
} else {
if (page->getSetPageSizeToPrinter() || m_printer->outputFormat() == QPrinter::PdfFormat)
m_printer->setPageSize(QPageSize((QPageSize::PageSizeId)page->pageSize()));
}
}
#endif
}
qreal ItemGeometry::x() const

View File

@ -196,11 +196,15 @@ void ReportRender::analizeItem(ContentItemDesignIntf* contentItem, BandDesignInt
QString content = contentItem->content();
QVector<QString> functions;
foreach(const QString &functionName, m_datasources->groupFunctionNames()){
#if QT_VERSION < 0x060000
QRegExp rx(QString(Const::GROUP_FUNCTION_RX).arg(functionName));
rx.setMinimal(true);
if (rx.indexIn(content)>=0){
functions.append(functionName);
}
#else
// TODO: Qt6 port
#endif
}
if (functions.size()>0)
m_groupfunctionItems.insert(contentItem->patternName(), functions);
@ -361,10 +365,14 @@ bool ReportRender::containsGroupFunctions(BandDesignIntf *band){
if (contentItem){
QString content = contentItem->content();
foreach(QString functionName, m_datasources->groupFunctionNames()){
#if QT_VERSION < 0x060000
QRegExp rx(QString(Const::GROUP_FUNCTION_RX).arg(functionName));
if (rx.indexIn(content)>=0){
return true;
}
#else
// TODO: Qt6 port
#endif
}
}
}
@ -372,6 +380,7 @@ bool ReportRender::containsGroupFunctions(BandDesignIntf *band){
}
void ReportRender::extractGroupFuntionsFromItem(ContentItemDesignIntf* contentItem, BandDesignIntf* band){
#if QT_VERSION < 0x060000
if ( contentItem && contentItem->content().contains(QRegExp("\\$S\\s*\\{.*\\}"))){
foreach(const QString &functionName, m_datasources->groupFunctionNames()){
QRegExp rx(QString(Const::GROUP_FUNCTION_RX).arg(functionName));
@ -406,6 +415,9 @@ void ReportRender::extractGroupFuntionsFromItem(ContentItemDesignIntf* contentIt
}
}
}
#else
// TODO: Qt6 port
#endif
}
void ReportRender::extractGroupFunctionsFromContainer(BaseDesignIntf* baseItem, BandDesignIntf* band){
@ -428,6 +440,7 @@ void ReportRender::replaceGroupFunctionsInItem(ContentItemDesignIntf* contentIte
if (m_groupfunctionItems.contains(contentItem->patternName())){
QString content = contentItem->content();
foreach(QString functionName, m_groupfunctionItems.value(contentItem->patternName())){
#if QT_VERSION < 0x060000
QRegExp rx(QString(Const::GROUP_FUNCTION_RX).arg(functionName));
rx.setMinimal(true);
if (rx.indexIn(content)>=0){
@ -450,6 +463,9 @@ void ReportRender::replaceGroupFunctionsInItem(ContentItemDesignIntf* contentIte
pos += rx.matchedLength();
}
}
#else
// TODO: Qt6 port
#endif
}
contentItem->setContent(content);
}

View File

@ -354,6 +354,7 @@ void ScriptEngineManager::setDataManager(DataSourceManager *dataManager){
QString ScriptEngineManager::expandUserVariables(QString context, RenderPass /* pass */, ExpandType expandType, QVariant &varValue)
{
#if QT_VERSION < 0x060000
QRegExp rx(Const::VARIABLE_RX);
if (context.contains(rx)){
int pos = 0;
@ -396,10 +397,62 @@ QString ScriptEngineManager::expandUserVariables(QString context, RenderPass /*
}
}
return context;
#else
QRegularExpression rx(Const::VARIABLE_RX);
if (context.contains(rx)){
int pos = 0;
QRegularExpressionMatch match = rx.match(context, pos);
while (match.hasMatch()){
QString variable=match.captured(1);
pos = match.capturedEnd();
if (dataManager()->containsVariable(variable) ){
try {
varValue = dataManager()->variable(variable);
switch (expandType){
case EscapeSymbols:
context.replace(match.captured(0), escapeSimbols(varValue.toString()));
break;
case NoEscapeSymbols:
context.replace(match.captured(0), varValue.toString());
break;
case ReplaceHTMLSymbols:
context.replace(match.captured(0), replaceHTMLSymbols(varValue.toString()));
break;
}
pos = 0;
} catch (ReportError &e){
dataManager()->putError(e.what());
if (!dataManager()->reportSettings() || dataManager()->reportSettings()->suppressAbsentFieldsAndVarsWarnings())
context.replace(match.captured(0), e.what());
else
context.replace(match.captured(0), "");
}
} else {
QString error;
error = tr("Variable %1 not found").arg(variable);
dataManager()->putError(error);
if (!dataManager()->reportSettings() || dataManager()->reportSettings()->suppressAbsentFieldsAndVarsWarnings())
context.replace(match.captured(0), error);
else
context.replace(match.captured(0), "");
}
match = rx.match(context, pos);
}
}
return context;
#endif
}
QString ScriptEngineManager::expandDataFields(QString context, ExpandType expandType, QVariant &varValue, QObject *reportItem)
{
#if QT_VERSION < 0x060000
QRegExp rx(Const::FIELD_RX);
if (context.contains(rx)){
@ -450,13 +503,74 @@ QString ScriptEngineManager::expandDataFields(QString context, ExpandType expand
}
return context;
#else
QRegularExpression rx(Const::FIELD_RX);
if (context.contains(rx)){
QRegularExpressionMatch match = rx.match(context);
while (match.hasMatch()){
QString field=match.captured(1);
if (dataManager()->containsField(field)) {
QString fieldValue;
varValue = dataManager()->fieldData(field);
if (expandType == EscapeSymbols) {
if (varValue.isNull()) {
fieldValue="\"\"";
} else {
fieldValue = escapeSimbols(varValue.toString());
switch (dataManager()->fieldData(field).type()) {
case QVariant::Char:
case QVariant::String:
case QVariant::StringList:
case QVariant::Date:
case QVariant::DateTime:
fieldValue = "\""+fieldValue+"\"";
break;
default:
break;
}
}
} else {
if (expandType == ReplaceHTMLSymbols)
fieldValue = replaceHTMLSymbols(varValue.toString());
else fieldValue = varValue.toString();
}
context.replace(match.captured(0),fieldValue);
} else {
QString error;
if (reportItem){
error = tr("Field %1 not found in %2!").arg(field).arg(reportItem->objectName());
dataManager()->putError(error);
}
varValue = QVariant();
if (!dataManager()->reportSettings() || !dataManager()->reportSettings()->suppressAbsentFieldsAndVarsWarnings())
context.replace(match.captured(0), error);
else
context.replace(match.captured(0), "");
}
match = rx.match(context);
}
}
return context;
#endif
}
QString ScriptEngineManager::expandScripts(QString context, QVariant& varValue, QObject *reportItem)
{
#if QT_VERSION < 0x060000
QRegExp rx(Const::SCRIPT_RX);
if (context.contains(rx)){
#else
QRegularExpression rx(Const::SCRIPT_RX, QRegularExpression::DotMatchesEverythingOption);
if(context.contains(rx)){
#endif
if (ScriptEngineManager::instance().dataManager() != dataManager())
ScriptEngineManager::instance().setDataManager(dataManager());
@ -517,10 +631,17 @@ QString ScriptEngineManager::replaceScripts(QString context, QVariant &varValue,
QVariant ScriptEngineManager::evaluateScript(const QString& script){
#if QT_VERSION < 0x060000
QRegExp rx(Const::SCRIPT_RX);
QVariant varValue;
if (script.contains(rx)){
#else
QRegularExpression rx(Const::SCRIPT_RX);
QVariant varValue;
if (script.contains(rx)){
#endif
if (ScriptEngineManager::instance().dataManager()!=dataManager())
ScriptEngineManager::instance().setDataManager(dataManager());

View File

@ -31,7 +31,7 @@
#define LRSCRIPTENGINEMANAGERINTF_H
#include "qglobal.h"
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
#if QT_VERSION >= 0x050600
#ifndef USE_QTSCRIPTENGINE
#ifndef USE_QJSENGINE
#define USE_QJSENGINE