0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 00:33:02 +03:00

QRegularExpression usage has been fixed

Qt6 drag&drop has been fixed
This commit is contained in:
Arin Alex 2022-07-16 02:33:39 +03:00
parent 3a0a77a2e2
commit 64193a18d0
15 changed files with 121 additions and 80 deletions

View File

@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.14)
set(LIMEREPORT_VERSION_MAJOR 1)
set(LIMEREPORT_VERSION_MINOR 6)
set(LIMEREPORT_VERSION_RELEASE 6)
set(LIMEREPORT_VERSION_RELEASE 7)
option(ENABLE_ZINT "Enable libzint build for barcode support" OFF)
option(LIMEREPORT_STATIC "Build LimeReport as static library" OFF)

View File

@ -141,7 +141,7 @@ RCC_DIR = $${ARCH_DIR}/$${BUILD_TYPE}/rcc
LIMEREPORT_VERSION_MAJOR = 1
LIMEREPORT_VERSION_MINOR = 6
LIMEREPORT_VERSION_RELEASE = 0
LIMEREPORT_VERSION_RELEASE = 7
LIMEREPORT_VERSION = '$${LIMEREPORT_VERSION_MAJOR}.$${LIMEREPORT_VERSION_MINOR}.$${LIMEREPORT_VERSION_RELEASE}'
DEFINES *= LIMEREPORT_VERSION_STR=\\\"$${LIMEREPORT_VERSION}\\\"

View File

@ -157,6 +157,16 @@ namespace Const{
#else
typedef QStyleOptionViewItem StyleOptionViewItem;
#endif
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 1)
QRegularExpression getRegEx(QString expression);
QRegularExpression getVariableRegEx();
QRegularExpression getFieldRegEx();
QRegularExpression getScriptRegEx();
QRegularExpression getGroupFunctionRegEx(QString functionName);
QRegularExpression getGroupFunctionNameRegEx(QString functionName);
QRegularExpression getNamedVariableRegEx(QString variableName);
#endif
class Enums
{

View File

@ -36,7 +36,11 @@ namespace LimeReport {
DataBrowserTree::DataBrowserTree(QWidget *parent) :
QTreeWidget(parent){}
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
QMimeData *DataBrowserTree::mimeData(const QList<QTreeWidgetItem *> &items) const
#else
QMimeData *DataBrowserTree::mimeData(const QList<QTreeWidgetItem *> items) const
#endif
{
QMimeData* result = QTreeWidget::mimeData(items);
if (items.at(0)->type()==Row){

View File

@ -42,7 +42,11 @@ public:
enum NodeType{Connection, Table, Row, Category, Variable, ExternalVariable};
explicit DataBrowserTree(QWidget *parent = 0);
protected:
QMimeData* mimeData(const QList<QTreeWidgetItem *> items) const;
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
virtual QMimeData *mimeData(const QList<QTreeWidgetItem *> &items) const;
#else
virtual QMimeData *mimeData(const QList<QTreeWidgetItem*> items) const;
#endif
public slots:

View File

@ -827,7 +827,7 @@ void TextItem::expandContent(DataSourceManager* dataManager, RenderPass pass)
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 1))
QRegExp rx(QString(Const::NAMED_VARIABLE_RX).arg(variableName));
#else
QRegularExpression rx(QString(Const::NAMED_VARIABLE_RX).arg(variableName));
QRegularExpression rx = getNamedVariableRegEx(variableName);
#endif
if (context.contains(rx) && pass == FirstPass){
backupContent();

View File

@ -261,7 +261,6 @@ public:
void setAlternateBackgroundColor(const QColor &alternateBackgroundColor);
bool useAlternateBackgroundColor() const;
void setUseAlternateBackgroundColor(bool useAlternateBackgroundColor);
void replaceGroupsFunction(BandDesignIntf *band);
qreal bottomSpace() const;
void setBackgroundModeProperty(BGMode value);
void setBackgroundOpacity(int value);

View File

@ -423,8 +423,8 @@ QString DataSourceManager::extractField(QString source)
}
QString DataSourceManager::replaceVariables(QString value){
#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 3)
QRegularExpression rx(Const::VARIABLE_RX);
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 1)
QRegularExpression rx = getVariableRegEx();
QRegularExpressionMatchIterator iter = rx.globalMatch(value);
qsizetype pos = 0;
QString result;
@ -468,8 +468,8 @@ QString DataSourceManager::replaceVariables(QString value){
QString DataSourceManager::replaceVariables(QString query, QMap<QString,QString> &aliasesToParam)
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 3)
QRegularExpression rx(Const::VARIABLE_RX);
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 1)
QRegularExpression rx = getVariableRegEx();
int curentAliasIndex = 0;
if (query.contains(rx)){
int pos = -1;
@ -553,9 +553,8 @@ QString DataSourceManager::replaceVariables(QString query, QMap<QString,QString>
QString DataSourceManager::replaceFields(QString query, QMap<QString,QString> &aliasesToParam, QString masterDatasource)
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 3)
QRegularExpression rx(Const::FIELD_RX);
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 1)
QRegularExpression rx = getFieldRegEx();
int curentAliasIndex = 0;
if (query.contains(rx)){
int pos = -1;
@ -1498,7 +1497,7 @@ void DataSourceManager::invalidateQueriesContainsVariable(const QString& variabl
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 1))
QRegExp rx(QString(Const::NAMED_VARIABLE_RX).arg(variableName));
#else
QRegularExpression rx(QString(Const::NAMED_VARIABLE_RX).arg(variableName));
QRegularExpression rx = getNamedVariableRegEx(variableName);
#endif
if (holder->queryText().contains(rx)){
holder->invalidate(designTime() ? IDataSource::DESIGN_MODE : IDataSource::RENDER_MODE);

View File

@ -67,7 +67,7 @@ QString replaceHTMLSymbols(const QString &value)
return result;
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 3)
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 1)
QVector<QString> normalizeCaptures(const QRegularExpressionMatch& reg){
#else
QVector<QString> normalizeCaptures(const QRegExp& reg){
@ -93,4 +93,53 @@ ReportError::ReportError(const QString& message):std::runtime_error(message.toSt
IExternalPainter::~IExternalPainter(){}
IPainterProxy::~IPainterProxy(){}
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 1)
QRegularExpression getRegEx(QString expression){
return QRegularExpression(expression, QRegularExpression::DotMatchesEverythingOption);
}
QRegularExpression getVariableRegEx(){
return QRegularExpression(
Const::VARIABLE_RX,
QRegularExpression::DotMatchesEverythingOption |
QRegularExpression::CaseInsensitiveOption
);
}
QRegularExpression getFieldRegEx(){
return QRegularExpression(
Const::FIELD_RX,
QRegularExpression::DotMatchesEverythingOption |
QRegularExpression::CaseInsensitiveOption
);
}
QRegularExpression getScriptRegEx(){
return QRegularExpression(
Const::SCRIPT_RX,
QRegularExpression::DotMatchesEverythingOption |
QRegularExpression::CaseInsensitiveOption
);
}
QRegularExpression getGroupFunctionRegEx(QString functionName){
return QRegularExpression(
QString(Const::GROUP_FUNCTION_RX).arg(functionName),
QRegularExpression::DotMatchesEverythingOption |
QRegularExpression::InvertedGreedinessOption
);
}
QRegularExpression getGroupFunctionNameRegEx(QString functionName){
return QRegularExpression(
QString(Const::GROUP_FUNCTION_NAME_RX).arg(functionName),
QRegularExpression::DotMatchesEverythingOption |
QRegularExpression::InvertedGreedinessOption
);
}
QRegularExpression getNamedVariableRegEx(QString variableName){
return QRegularExpression(
QString(Const::NAMED_VARIABLE_RX).arg(variableName),
QRegularExpression::DotMatchesEverythingOption
);
}
#endif
} //namespace LimeReport

View File

@ -157,6 +157,16 @@ namespace Const{
#else
typedef QStyleOptionViewItem StyleOptionViewItem;
#endif
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 1)
QRegularExpression getRegEx(QString expression);
QRegularExpression getVariableRegEx();
QRegularExpression getFieldRegEx();
QRegularExpression getScriptRegEx();
QRegularExpression getGroupFunctionRegEx(QString functionName);
QRegularExpression getGroupFunctionNameRegEx(QString functionName);
QRegularExpression getNamedVariableRegEx(QString variableName);
#endif
class Enums
{

View File

@ -48,8 +48,8 @@ void GroupFunction::slotBandRendered(BandDesignIntf *band)
QRegExp rxField(Const::FIELD_RX);
QRegExp rxVar(Const::VARIABLE_RX);
#else
QRegularExpression rxField(Const::FIELD_RX);
QRegularExpression rxVar(Const::VARIABLE_RX);
QRegularExpression rxField = getFieldRegEx();
QRegularExpression rxVar = getVariableRegEx();
#endif
switch (m_dataType){
@ -154,9 +154,9 @@ GroupFunction::GroupFunction(const QString &expression, const QString &dataBandN
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);
QRegularExpression rxField = getFieldRegEx();
QRegularExpression rxVariable = getVariableRegEx();
QRegularExpression rxScript = getScriptRegEx();
#endif
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 1))
if (rxScript.indexIn(expression) != -1){

View File

@ -726,7 +726,6 @@ ReportEnginePrivate *PageDesignIntf::reportEditor()
void PageDesignIntf::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
{
if (!event->mimeData()->text().isEmpty()){
event->setDropAction(Qt::CopyAction);
event->accept();
@ -755,7 +754,7 @@ void PageDesignIntf::dropEvent(QGraphicsSceneDragDropEvent* event)
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 1))
if (isVar) data = data.remove(QRegExp(" \\[.*\\]"));
#else
if (isVar) data = data.remove(QRegularExpression(" \\[.*\\]"));
if (isVar) data = data.remove(QRegularExpression(" \\[.*\\]", QRegularExpression::DotMatchesEverythingOption));
#endif
ti->setContent(data);
if (!isVar){
@ -767,7 +766,7 @@ void PageDesignIntf::dropEvent(QGraphicsSceneDragDropEvent* event)
parentBand->setProperty("datasource",dataSource.cap(1));
}
#else
QRegularExpression dataSource("(?:\\$D\\{\\s*(.*)\\..*\\})");
QRegularExpression dataSource("(?:\\$D\\{\\s*(.*)\\..*\\})", QRegularExpression::DotMatchesEverythingOption);
QRegularExpressionMatch match = dataSource.match(data);
if(match.hasMatch()){
parentBand->setProperty("datasource", match.captured(1));

View File

@ -196,13 +196,11 @@ void ReportRender::analizeItem(ContentItemDesignIntf* contentItem, BandDesignInt
QString content = contentItem->content();
QVector<QString> functions;
foreach(const QString &functionName, m_datasources->groupFunctionNames()){
#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 3)
QRegularExpression rx(QString(Const::GROUP_FUNCTION_RX).arg(functionName));
rx.setPatternOptions(rx.InvertedGreedinessOption);
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 1)
QRegularExpression rx = getGroupFunctionRegEx(functionName);
if(content.indexOf(rx)>=0){
functions.append(functionName);
}
// TODO: Qt6 port - done
#else
QRegExp rx(QString(Const::GROUP_FUNCTION_RX).arg(functionName));
rx.setMinimal(true);
@ -368,13 +366,11 @@ void ReportRender::clearPageMap()
bool checkContentItem(ContentItemDesignIntf* item, DataSourceManager* datasources){
QString content = item->content();
foreach(QString functionName, datasources->groupFunctionNames()){
#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 3)
QRegularExpression rx(QString(Const::GROUP_FUNCTION_RX).arg(functionName));
rx.setPatternOptions(rx.InvertedGreedinessOption);
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 1)
QRegularExpression rx = getGroupFunctionRegEx(functionName);
if(content.indexOf(rx)>=0){
return true;
}
// TODO: Qt6 port - done
#else
QRegExp rx(QString(Const::GROUP_FUNCTION_RX).arg(functionName));
if (rx.indexIn(content)>=0){
@ -400,16 +396,14 @@ bool ReportRender::containsGroupFunctions(BaseDesignIntf *container){
}
void ReportRender::extractGroupFuntionsFromItem(ContentItemDesignIntf* contentItem, BandDesignIntf* band){
#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 3)
if ( contentItem && contentItem->content().contains(QRegularExpression("\\$S\\s*\\{.*\\}"))){
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 1)
if ( contentItem && contentItem->content().contains(getScriptRegEx())){
foreach(const QString &functionName, m_datasources->groupFunctionNames()){
QRegularExpression rx(QString(Const::GROUP_FUNCTION_RX).arg(functionName));
rx.setPatternOptions(rx.InvertedGreedinessOption);
QRegularExpression rxName(QString(Const::GROUP_FUNCTION_NAME_RX).arg(functionName));
rxName.setPatternOptions(rx.InvertedGreedinessOption);
QRegularExpression rx = getGroupFunctionRegEx(functionName);
QRegularExpression rxName = getGroupFunctionNameRegEx(functionName);
QRegularExpressionMatch match = rx.match(contentItem->content());
if (match.hasMatch()){
QRegularExpressionMatchIterator iter = rx.globalMatch(contentItem->content());
@ -437,31 +431,7 @@ void ReportRender::extractGroupFuntionsFromItem(ContentItemDesignIntf* contentIt
}
}
}
// int pos = 0;
// while ( (pos = match.capturedStart()) != -1){
// QVector<QString> captures = normalizeCaptures(match);
// if (captures.size() >= 3){
// int dsIndex = captures.size() == 3 ? Const::DATASOURCE_INDEX - 1 : Const::DATASOURCE_INDEX;
// BandDesignIntf* dataBand = m_patternPageItem->bandByName(captures.at(dsIndex));
// if (dataBand){
// GroupFunction* gf = datasources()->addGroupFunction(
// functionName, captures.at(Const::VALUE_INDEX), band->objectName(), dataBand->objectName()
// );
// if (gf){
// connect(dataBand, SIGNAL(bandRendered(BandDesignIntf*)),
// gf, SLOT(slotBandRendered(BandDesignIntf*)));
// connect(dataBand, SIGNAL(bandReRendered(BandDesignIntf*, BandDesignIntf*)),
// gf, SLOT(slotBandReRendered(BandDesignIntf*, BandDesignIntf*)));
// }
// } else {
// GroupFunction* gf = datasources()->addGroupFunction(
// functionName, captures.at(Const::VALUE_INDEX), band->objectName(), captures.at(dsIndex)
// );
// gf->setInvalid(tr("Databand \"%1\" not found").arg(captures.at(dsIndex)));
// }
// }
// match = rx.match(contentItem->content(), pos + match.capturedLength());
// }
} else if (contentItem->content().indexOf(rxName)>=0){
match = rxName.match(contentItem->content());
GroupFunction* gf = datasources()->addGroupFunction(functionName, match.captured(1), band->objectName(), "");
@ -470,7 +440,6 @@ void ReportRender::extractGroupFuntionsFromItem(ContentItemDesignIntf* contentIt
}
}
// TODO: Qt6 port - done
#else
if ( contentItem && contentItem->content().contains(QRegExp("\\$S\\s*\\{.*\\}"))){
foreach(const QString &functionName, m_datasources->groupFunctionNames()){
@ -529,10 +498,8 @@ 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 >= QT_VERSION_CHECK(5, 12, 3)
QRegularExpression rx(QString(Const::GROUP_FUNCTION_RX).arg(functionName));
rx.setPatternOptions(rx.InvertedGreedinessOption);
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 1)
QRegularExpression rx = getGroupFunctionRegEx(functionName);
QRegularExpressionMatch match = rx.match(content);
if (match.capturedStart() != -1){
@ -556,7 +523,6 @@ void ReportRender::replaceGroupFunctionsInItem(ContentItemDesignIntf* contentIte
match = rx.match(content, pos + match.capturedLength());
}
}
// TODO: Qt6 port - done
#else
QRegExp rx(QString(Const::GROUP_FUNCTION_RX).arg(functionName));
rx.setMinimal(true);

View File

@ -398,7 +398,7 @@ QString ScriptEngineManager::expandUserVariables(QString context, RenderPass /*
}
return context;
#else
QRegularExpression rx(Const::VARIABLE_RX);
QRegularExpression rx = getVariableRegEx();
if (context.contains(rx)){
int pos = 0;
QRegularExpressionMatch match = rx.match(context, pos);
@ -504,8 +504,7 @@ QString ScriptEngineManager::expandDataFields(QString context, ExpandType expand
return context;
#else
QRegularExpression rx(Const::FIELD_RX);
QRegularExpression rx = getFieldRegEx();
if (context.contains(rx)){
QRegularExpressionMatch match = rx.match(context);
while (match.hasMatch()){
@ -567,8 +566,7 @@ QString ScriptEngineManager::expandScripts(QString context, QVariant& varValue,
if (context.contains(rx)){
#else
QRegularExpression rx(Const::SCRIPT_RX, QRegularExpression::DotMatchesEverythingOption);
QRegularExpression rx = getScriptRegEx();
if(context.contains(rx)){
#endif
@ -636,8 +634,8 @@ QVariant ScriptEngineManager::evaluateScript(const QString& script){
QVariant varValue;
if (script.contains(rx)){
#else
QRegularExpression rx(Const::SCRIPT_RX);
#else
QRegularExpression rx = getScriptRegEx();
QVariant varValue;
if (script.contains(rx)){
@ -1110,7 +1108,7 @@ bool ScriptExtractor::parse()
bool ScriptExtractor::parse(int &curPos, const State& state, ScriptNode::Ptr scriptNode)
{
while (curPos<m_context.length()){
while (curPos < m_context.length()){
switch (state) {
case OpenBracketFound:
if (m_context[curPos]=='}'){
@ -1680,11 +1678,10 @@ QVariant ScriptFunctionsManager::calcGroupFunction(const QString &name, const QS
if (gf){
if (gf->isValid()){
return gf->calculate(pageItem);
}else{
} else{
return gf->error();
}
}
else {
} else {
return QString(QObject::tr("Function %1 not found or have wrong arguments").arg(name));
}
} else {

View File

@ -401,7 +401,11 @@ private:
class ScriptNode{
public:
typedef QSharedPointer<ScriptNode> Ptr;
QString body(){return m_body;}
QString body(){
if (m_body.isEmpty() && m_children.count() > 0)
return m_children.at(0)->body();
return m_body;
}
void setBody(const QString& body){ m_body = body;}
void setStartLex(const QString startLex){ m_startLex = startLex;}
QString script(){return m_startLex + m_body + '}';}