Skip to content

Commit

Permalink
Apply suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Nov 8, 2023
1 parent cb8c062 commit 5b1d8ec
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 17 deletions.
16 changes: 13 additions & 3 deletions src/gui/editorwidgets/qgshtmlwidgetwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ QWidget *QgsHtmlWidgetWrapper::createWidget( QWidget *parent )
{
if ( attributeChanged )
{
const thread_local QRegularExpression expRe { QStringLiteral( R"re(expression.evaluate\s*\(\s*"(.*)"\))re" ), QRegularExpression::PatternOption::MultilineOption | QRegularExpression::PatternOption::DotMatchesEverythingOption };
const QRegularExpressionMatch match { expRe.match( mHtmlCode ) };
if ( match.hasMatch() && QgsValueRelationFieldFormatter::expressionRequiresFormScope( match.captured( 1 ) ) )
if ( mRequiresFormScope )
{
mFormFeature.setAttribute( attribute, newValue );
setHtmlContext();
Expand Down Expand Up @@ -121,6 +119,18 @@ void QgsHtmlWidgetWrapper::checkGeometryNeeds()
void QgsHtmlWidgetWrapper::setHtmlCode( const QString &htmlCode )
{
mHtmlCode = htmlCode;

bool ok = false;
const thread_local QRegularExpression expRe( QStringLiteral( R"re(expression.evaluate\s*\(\s*"(.*)"\))re" ), QRegularExpression::PatternOption::MultilineOption | QRegularExpression::PatternOption::DotMatchesEverythingOption );
QRegularExpressionMatchIterator matchIt = expRe.globalMatch( mHtmlCode );
while ( !ok && matchIt.hasNext() )
{
const QRegularExpressionMatch match = matchIt.next();
const QgsExpression exp = match.captured( 1 );
ok = QgsValueRelationFieldFormatter::expressionRequiresFormScope( exp );
}
mRequiresFormScope = ok;

checkGeometryNeeds();
}

Expand Down
1 change: 1 addition & 0 deletions src/gui/editorwidgets/qgshtmlwidgetwrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class GUI_EXPORT QgsHtmlWidgetWrapper : public QgsWidgetWrapper
QgsFeature mFeature;
bool mNeedsGeometry = false;
QgsFeature mFormFeature;
bool mRequiresFormScope = false;

friend class TestQgsHtmlWidgetWrapper;
};
Expand Down
15 changes: 12 additions & 3 deletions src/gui/editorwidgets/qgsqmlwidgetwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ QWidget *QgsQmlWidgetWrapper::createWidget( QWidget *parent )
{
if ( attributeChanged )
{
const thread_local QRegularExpression expRe { QStringLiteral( R"re(expression.evaluate\s*\(\s*"(.*)"\))re" ), QRegularExpression::PatternOption::MultilineOption | QRegularExpression::PatternOption::DotMatchesEverythingOption };
const QRegularExpressionMatch match { expRe.match( mQmlCode ) };
if ( match.hasMatch() && QgsValueRelationFieldFormatter::expressionRequiresFormScope( match.captured( 1 ) ) )
if ( mRequiresFormScope )
{
mFormFeature.setAttribute( attribute, newValue );
setQmlContext();
Expand Down Expand Up @@ -99,6 +97,17 @@ void QgsQmlWidgetWrapper::setQmlCode( const QString &qmlCode )

mQmlCode = qmlCode;

bool ok = false;
const thread_local QRegularExpression expRe( QStringLiteral( R"re(expression.evaluate\s*\(\s*"(.*)"\))re" ), QRegularExpression::PatternOption::MultilineOption | QRegularExpression::PatternOption::DotMatchesEverythingOption );
QRegularExpressionMatchIterator matchIt = expRe.globalMatch( mQmlCode );
while ( !ok && matchIt.hasNext() )
{
const QRegularExpressionMatch match = matchIt.next();
const QgsExpression exp = match.captured( 1 );
ok = QgsValueRelationFieldFormatter::expressionRequiresFormScope( exp );
}
mRequiresFormScope = ok;

if ( !mQmlFile.open() )
{
QgsMessageLog::logMessage( tr( "Failed to open temporary QML file" ) );
Expand Down
1 change: 1 addition & 0 deletions src/gui/editorwidgets/qgsqmlwidgetwrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class GUI_EXPORT QgsQmlWidgetWrapper : public QgsWidgetWrapper
QQuickWidget *mWidget = nullptr;
QgsFeature mFeature;
QgsFeature mFormFeature;
bool mRequiresFormScope = false;
};


Expand Down
24 changes: 13 additions & 11 deletions src/gui/editorwidgets/qgstextwidgetwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,7 @@ QWidget *QgsTextWidgetWrapper::createWidget( QWidget *parent )
{
if ( attributeChanged )
{
bool ok { false };
const thread_local QRegularExpression sRegEx{ QStringLiteral( "\\[%(.*?)%\\]" ), QRegularExpression::MultilineOption | QRegularExpression::DotMatchesEverythingOption };
QRegularExpressionMatchIterator matchIt { sRegEx.globalMatch( mText ) };
while ( !ok && matchIt.hasNext() )
{
const QRegularExpressionMatch match { matchIt.next() };
const QgsExpression exp { match.captured( 1 ) };
ok = QgsValueRelationFieldFormatter::expressionRequiresFormScope( exp );
}

if ( ok )
if ( mRequiresFormScope )
{
mFormFeature.setAttribute( attribute, newValue );
updateTextContext();
Expand Down Expand Up @@ -99,6 +89,18 @@ void QgsTextWidgetWrapper::reinitWidget( )
void QgsTextWidgetWrapper::setText( const QString &text )
{
mText = text;

bool ok = false;
const thread_local QRegularExpression sRegEx( QStringLiteral( "\\[%(.*?)%\\]" ), QRegularExpression::MultilineOption | QRegularExpression::DotMatchesEverythingOption );
QRegularExpressionMatchIterator matchIt = sRegEx.globalMatch( mText );
while ( !ok && matchIt.hasNext() )
{
const QRegularExpressionMatch match = matchIt.next();
const QgsExpression exp = match.captured( 1 );
ok = QgsValueRelationFieldFormatter::expressionRequiresFormScope( exp );
}
mRequiresFormScope = ok;

reinitWidget();
}

Expand Down
1 change: 1 addition & 0 deletions src/gui/editorwidgets/qgstextwidgetwrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class GUI_EXPORT QgsTextWidgetWrapper : public QgsWidgetWrapper
QLabel *mWidget = nullptr;
QgsFeature mFeature;
QgsFeature mFormFeature;
bool mRequiresFormScope = false;
QgsExpressionContext mTextContext;
bool mNeedsGeometry = false;

Expand Down

0 comments on commit 5b1d8ec

Please sign in to comment.