From 67d8146b9c70fdda30df4ed0e514ff9018925423 Mon Sep 17 00:00:00 2001 From: Rodrigo Torres Date: Tue, 24 Aug 2021 04:22:30 -0300 Subject: [PATCH] WIP --- console/main.cpp | 2 +- include/lrglobal.cpp | 4 + include/lrglobal.h | 8 +- include/lrscriptenginemanagerintf.h | 2 +- limereport/items/lrabstractlayout.h | 2 +- limereport/items/lrbarcodeitem.h | 2 +- limereport/items/lrchartitem.h | 4 +- limereport/items/lrimageitem.h | 2 +- limereport/items/lrshapeitem.h | 2 +- limereport/items/lrsimpletagparser.cpp | 28 +++++- limereport/items/lrtextitem.h | 2 +- limereport/lrbanddesignintf.h | 2 +- limereport/lrbasedesignintf.h | 2 +- limereport/lrdatasourcemanager.cpp | 20 ++++ limereport/lrglobal.cpp | 4 + limereport/lrglobal.h | 8 +- limereport/lrgroupfunctions.cpp | 47 +++++++++- limereport/lritemdesignintf.h | 2 +- limereport/lrpagedesignintf.cpp | 8 ++ limereport/lrpageitemdesignintf.h | 2 +- limereport/lrpreviewreportwidget.cpp | 6 +- limereport/lrreportengine.cpp | 106 +++++++++++++++++++--- limereport/lrreportrender.cpp | 16 ++++ limereport/lrscriptenginemanager.cpp | 121 +++++++++++++++++++++++++ limereport/lrscriptenginemanagerintf.h | 2 +- 25 files changed, 360 insertions(+), 44 deletions(-) diff --git a/console/main.cpp b/console/main.cpp index 764fc36..7493e67 100644 --- a/console/main.cpp +++ b/console/main.cpp @@ -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(); diff --git a/include/lrglobal.cpp b/include/lrglobal.cpp index 5d68a1d..e8a31bb 100644 --- a/include/lrglobal.cpp +++ b/include/lrglobal.cpp @@ -67,7 +67,11 @@ QString replaceHTMLSymbols(const QString &value) return result; } +#if QT_VERSION < 0x060000 QVector normalizeCaptures(const QRegExp& reg){ +#else +QVector normalizeCaptures(const QRegularExpressionMatch ®){ +#endif QVector result; foreach (QString cap, reg.capturedTexts()) { if (!cap.isEmpty()) diff --git a/include/lrglobal.h b/include/lrglobal.h index d1a2b38..f1da95f 100644 --- a/include/lrglobal.h +++ b/include/lrglobal.h @@ -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 normalizeCaptures(const QRegExp ®); #else - QVector normalizeCaptures(const QRegularExpression ®); + QVector normalizeCaptures(const QRegularExpressionMatch ®); #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) diff --git a/include/lrscriptenginemanagerintf.h b/include/lrscriptenginemanagerintf.h index eaad8fd..573f748 100644 --- a/include/lrscriptenginemanagerintf.h +++ b/include/lrscriptenginemanagerintf.h @@ -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 diff --git a/limereport/items/lrabstractlayout.h b/limereport/items/lrabstractlayout.h index 7e38275..fcda489 100644 --- a/limereport/items/lrabstractlayout.h +++ b/limereport/items/lrabstractlayout.h @@ -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) diff --git a/limereport/items/lrbarcodeitem.h b/limereport/items/lrbarcodeitem.h index e3e9c1a..b156c14 100644 --- a/limereport/items/lrbarcodeitem.h +++ b/limereport/items/lrbarcodeitem.h @@ -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) diff --git a/limereport/items/lrchartitem.h b/limereport/items/lrchartitem.h index 5208bcd..cfc283e 100644 --- a/limereport/items/lrchartitem.h +++ b/limereport/items/lrchartitem.h @@ -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) diff --git a/limereport/items/lrimageitem.h b/limereport/items/lrimageitem.h index 274a183..5640e8a 100644 --- a/limereport/items/lrimageitem.h +++ b/limereport/items/lrimageitem.h @@ -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) diff --git a/limereport/items/lrshapeitem.h b/limereport/items/lrshapeitem.h index 69a4a31..b9ba727 100644 --- a/limereport/items/lrshapeitem.h +++ b/limereport/items/lrshapeitem.h @@ -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) diff --git a/limereport/items/lrsimpletagparser.cpp b/limereport/items/lrsimpletagparser.cpp index c608e7f..2ee4e6a 100644 --- a/limereport/items/lrsimpletagparser.cpp +++ b/limereport/items/lrsimpletagparser.cpp @@ -28,14 +28,18 @@ * GNU General Public License for more details. * ****************************************************************************/ #include "lrsimpletagparser.h" -#include #include #include - +#if QT_VERSION < 0x060000 +#include +#else +#include +#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 &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 &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() diff --git a/limereport/items/lrtextitem.h b/limereport/items/lrtextitem.h index 2009917..0d63415 100644 --- a/limereport/items/lrtextitem.h +++ b/limereport/items/lrtextitem.h @@ -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) diff --git a/limereport/lrbanddesignintf.h b/limereport/lrbanddesignintf.h index 343f20e..0def742 100644 --- a/limereport/lrbanddesignintf.h +++ b/limereport/lrbanddesignintf.h @@ -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) diff --git a/limereport/lrbasedesignintf.h b/limereport/lrbasedesignintf.h index a61e127..6a2b3ea 100644 --- a/limereport/lrbasedesignintf.h +++ b/limereport/lrbasedesignintf.h @@ -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) diff --git a/limereport/lrdatasourcemanager.cpp b/limereport/lrdatasourcemanager.cpp index 1fc9dd5..03135ff 100644 --- a/limereport/lrdatasourcemanager.cpp +++ b/limereport/lrdatasourcemanager.cpp @@ -31,7 +31,9 @@ #include "lrdatadesignintf.h" #include #include +#if QT_VERSION < 0x060000 #include +#endif #include #include #include @@ -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 &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 } } return query; +#else + QRegularExpression rx(Const::VARIABLE_RX); + // TODO: Qt6 port +#endif + return QString(); } QString DataSourceManager::replaceFields(QString query, QMap &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 &a } } return query; +#else + QRegularExpression rx(Const::FIELD_RX); + // TODO: Qt6 port +#endif + return QString(); } void DataSourceManager::setReportVariable(const QString &name, const QVariant &value) diff --git a/limereport/lrglobal.cpp b/limereport/lrglobal.cpp index 59e90fc..8df6e22 100644 --- a/limereport/lrglobal.cpp +++ b/limereport/lrglobal.cpp @@ -67,7 +67,11 @@ QString replaceHTMLSymbols(const QString &value) return result; } +#if QT_VERSION < 0x060000 QVector normalizeCaptures(const QRegExp& reg){ +#else +QVector normalizeCaptures(const QRegularExpressionMatch& reg){ +#endif QVector result; foreach (QString cap, reg.capturedTexts()) { if (!cap.isEmpty()) diff --git a/limereport/lrglobal.h b/limereport/lrglobal.h index d1a2b38..f1da95f 100644 --- a/limereport/lrglobal.h +++ b/limereport/lrglobal.h @@ -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 normalizeCaptures(const QRegExp ®); #else - QVector normalizeCaptures(const QRegularExpression ®); + QVector normalizeCaptures(const QRegularExpressionMatch ®); #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) diff --git a/limereport/lrgroupfunctions.cpp b/limereport/lrgroupfunctions.cpp index 15da1ea..30db2d2 100644 --- a/limereport/lrgroupfunctions.cpp +++ b/limereport/lrgroupfunctions.cpp @@ -34,7 +34,9 @@ #include "lrscriptenginemanager.h" #include "lrpageitemdesignintf.h" +#if QT_VERSION < 0x060000 #include +#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; } diff --git a/limereport/lritemdesignintf.h b/limereport/lritemdesignintf.h index 482d441..0687651 100644 --- a/limereport/lritemdesignintf.h +++ b/limereport/lritemdesignintf.h @@ -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) diff --git a/limereport/lrpagedesignintf.cpp b/limereport/lrpagedesignintf.cpp index c0ff952..bf10519 100644 --- a/limereport/lrpagedesignintf.cpp +++ b/limereport/lrpagedesignintf.cpp @@ -762,10 +762,18 @@ void PageDesignIntf::dropEvent(QGraphicsSceneDragDropEvent* event) if (!isVar){ BandDesignIntf* parentBand = dynamic_cast(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 } } } diff --git a/limereport/lrpageitemdesignintf.h b/limereport/lrpageitemdesignintf.h index 1b097fd..97d5118 100644 --- a/limereport/lrpageitemdesignintf.h +++ b/limereport/lrpageitemdesignintf.h @@ -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) diff --git a/limereport/lrpreviewreportwidget.cpp b/limereport/lrpreviewreportwidget.cpp index 4e0f1b1..43ea2cc 100644 --- a/limereport/lrpreviewreportwidget.cpp +++ b/limereport/lrpreviewreportwidget.cpp @@ -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 } diff --git a/limereport/lrreportengine.cpp b/limereport/lrreportengine.cpp index ffb8e06..2b808c4 100644 --- a/limereport/lrreportengine.cpp +++ b/limereport/lrreportengine.cpp @@ -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 + m_printer.data()->setPrinterName(pi.defaultPrinter().printerName()); #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(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(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(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 diff --git a/limereport/lrreportrender.cpp b/limereport/lrreportrender.cpp index f5f0867..32a9062 100644 --- a/limereport/lrreportrender.cpp +++ b/limereport/lrreportrender.cpp @@ -196,11 +196,15 @@ void ReportRender::analizeItem(ContentItemDesignIntf* contentItem, BandDesignInt QString content = contentItem->content(); QVector 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); } diff --git a/limereport/lrscriptenginemanager.cpp b/limereport/lrscriptenginemanager.cpp index f90da59..b027c2c 100644 --- a/limereport/lrscriptenginemanager.cpp +++ b/limereport/lrscriptenginemanager.cpp @@ -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()); diff --git a/limereport/lrscriptenginemanagerintf.h b/limereport/lrscriptenginemanagerintf.h index eaad8fd..573f748 100644 --- a/limereport/lrscriptenginemanagerintf.h +++ b/limereport/lrscriptenginemanagerintf.h @@ -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