From 004ad8eb4e19c6157221e16dc17f3980eb9b8482 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Wed, 29 Jan 2025 14:19:15 +1000 Subject: [PATCH 1/2] Fix incorrect annotation HTML shown when clicking between annotations and HTML source view is enabled --- src/gui/qgsrichtexteditor.cpp | 10 +++++++--- src/gui/qgsrichtexteditor.h | 2 -- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/gui/qgsrichtexteditor.cpp b/src/gui/qgsrichtexteditor.cpp index d8775783886f..172132aa0005 100644 --- a/src/gui/qgsrichtexteditor.cpp +++ b/src/gui/qgsrichtexteditor.cpp @@ -752,16 +752,20 @@ void QgsRichTextEditor::setText( const QString &text ) { if ( text.isEmpty() ) { - setPlainText( text ); + mTextEdit->setPlainText( text ); + mSourceEdit->clear(); return; } + if ( text[0] == '<' ) { - setHtml( text ); + mTextEdit->setHtml( text ); + mSourceEdit->setText( text ); } else { - setPlainText( text ); + mTextEdit->setPlainText( text ); + mSourceEdit->setText( text ); } } diff --git a/src/gui/qgsrichtexteditor.h b/src/gui/qgsrichtexteditor.h index c83551ddeda1..37968593d737 100644 --- a/src/gui/qgsrichtexteditor.h +++ b/src/gui/qgsrichtexteditor.h @@ -162,8 +162,6 @@ class GUI_EXPORT QgsRichTextEditor : public QWidget, protected Ui::QgsRichTextEd void focusInEvent( QFocusEvent *event ) override; private slots: - void setPlainText( const QString &text ) { mTextEdit->setPlainText( text ); } - void setHtml( const QString &text ) { mTextEdit->setHtml( text ); } void textRemoveFormat(); void textRemoveAllFormat(); void textBold(); From 1aa1e5525a079216679d654ef47c011b95970785 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Thu, 30 Jan 2025 13:59:35 +1000 Subject: [PATCH 2/2] Improve HTML text detection --- src/gui/qgsrichtexteditor.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gui/qgsrichtexteditor.cpp b/src/gui/qgsrichtexteditor.cpp index 172132aa0005..a2b7115d3ad0 100644 --- a/src/gui/qgsrichtexteditor.cpp +++ b/src/gui/qgsrichtexteditor.cpp @@ -757,7 +757,8 @@ void QgsRichTextEditor::setText( const QString &text ) return; } - if ( text[0] == '<' ) + const thread_local QRegularExpression sIsHtmlRx( QStringLiteral( "^\\s*<" ) ); + if ( sIsHtmlRx.match( text ).hasMatch() ) { mTextEdit->setHtml( text ); mSourceEdit->setText( text );