summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2022-09-06 12:54:40 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-09-09 06:04:26 +0000
commit34cfcf852975f310ec1cfa27282c60686a0d2269 (patch)
tree8837d050791b53d29713f05ba19ba87531f199e2
parent04437ed3041f5608ab6f68eca837c349a547c701 (diff)
PdfSelection: check m_document before accessing
The document is a property that the user needs to bind. If initializing it has been neglected or delayed somehow, we shouldn't crash. Fixes: QTBUG-106355 Change-Id: I8e99b4bb84d868b694886058d56166fb3c4eabff Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> (cherry picked from commit c1dc52321cda894771bbbc38be92ae852281e26a) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/pdfquick/qquickpdfselection.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/pdfquick/qquickpdfselection.cpp b/src/pdfquick/qquickpdfselection.cpp
index c414e7ecf..11cee1542 100644
--- a/src/pdfquick/qquickpdfselection.cpp
+++ b/src/pdfquick/qquickpdfselection.cpp
@@ -151,6 +151,8 @@ void QQuickPdfSelection::clear()
*/
void QQuickPdfSelection::selectAll()
{
+ if (!m_document)
+ return;
QPdfSelection sel = m_document->document()->getAllText(m_page);
if (sel.text() != m_text) {
m_text = sel.text();
@@ -184,6 +186,8 @@ void QQuickPdfSelection::keyReleaseEvent(QKeyEvent *ev)
qCDebug(qLcIm) << "release" << ev;
const auto &allText = pageText();
if (ev == QKeySequence::MoveToPreviousWord) {
+ if (!m_document)
+ return;
// iOS sends MoveToPreviousWord first to get to the beginning of the word,
// and then SelectNextWord to select the whole word.
int i = allText.lastIndexOf(WordDelimiter, m_fromCharIndex - allText.length());
@@ -195,6 +199,8 @@ void QQuickPdfSelection::keyReleaseEvent(QKeyEvent *ev)
update(sel);
QGuiApplication::inputMethod()->update(Qt::ImAnchorRectangle);
} else if (ev == QKeySequence::SelectNextWord) {
+ if (!m_document)
+ return;
int i = allText.indexOf(WordDelimiter, m_toCharIndex);
if (i < 0)
i = allText.length(); // go to the end of m_textAfter
@@ -214,6 +220,8 @@ void QQuickPdfSelection::inputMethodEvent(QInputMethodEvent *event)
qCDebug(qLcIm) << "QInputMethodEvent::Cursor: moved to" << attr.start << "len" << attr.length;
break;
case QInputMethodEvent::Selection: {
+ if (!m_document)
+ return;
auto sel = m_document->document()->getSelectionAtIndex(m_page, attr.start, attr.length);
update(sel);
qCDebug(qLcIm) << "QInputMethodEvent::Selection: from" << attr.start << "len" << attr.length
@@ -235,6 +243,8 @@ QVariant QQuickPdfSelection::inputMethodQuery(Qt::InputMethodQuery query, const
if (!argument.isNull()) {
qCDebug(qLcIm) << "IM query" << query << "with arg" << argument;
if (query == Qt::ImCursorPosition) {
+ if (!m_document)
+ return {};
// If it didn't move since last time, return the same result.
if (m_hitPoint == argument.toPointF())
return inputMethodQuery(query);
@@ -323,6 +333,8 @@ QVariant QQuickPdfSelection::inputMethodQuery(Qt::InputMethodQuery query) const
const QString &QQuickPdfSelection::pageText() const
{
if (m_pageTextDirty) {
+ if (!m_document)
+ return m_pageText;
m_pageText = m_document->document()->getAllText(m_page).text();
m_pageTextDirty = false;
}