[libraries/ktextaddons] textcustomeditor: Const'ify variables

Laurent Montel <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit bd86ea915d1f78d83bade3d6244bd1d9ed35477b by Laurent Montel.
Committed on 07/08/2026 at 17:58.
Pushed by mlaurent into branch 'master'.

Const'ify variables

M  +2    -2    textcustomeditor/core/texteditorcompleter.cpp
M  +8    -8    textcustomeditor/plaintexteditor/plaintexteditor.cpp
M  +1    -3    textcustomeditor/plaintexteditor/plaintextsyntaxspellcheckinghighlighter.cpp
M  +7    -7    textcustomeditor/richtextbrowser/richtextbrowser.cpp
M  +1    -1    textcustomeditor/widgets/textfindreplacewidget.cpp

https://invent.kde.org/libraries/ktextaddons/-/commit/bd86ea915d1f78d83bade3d6244bd1d9ed35477b

diff --git a/textcustomeditor/core/texteditorcompleter.cpp b/textcustomeditor/core/texteditorcompleter.cpp
index 2e722ed22..1d3a640cb 100644
--- a/textcustomeditor/core/texteditorcompleter.cpp
+++ b/textcustomeditor/core/texteditorcompleter.cpp
@@ -62,7 +62,7 @@ void TextEditorCompleter::TextEditorCompleterPrivate::createCompleter()
 
 QString TextEditorCompleter::TextEditorCompleterPrivate::wordUnderCursor() const
 {
-    static QString eow = u"~!@#$%^&*()+{}|\"<>,./;'[]\\-= "_s; // everything without ':', '?' and '_'
+    static const QString eow = u"~!@#$%^&*()+{}|\"<>,./;'[]\\-= "_s; // everything without ':', '?' and '_'
     QTextCursor tc;
     QTextDocument *document = nullptr;
     if (plainTextEdit) {
@@ -78,7 +78,7 @@ QString TextEditorCompleter::TextEditorCompleterPrivate::wordUnderCursor() const
     while (true) {
         // vHanda: I don't understand why the cursor seems to give a pos 1 past the last char instead
         // of just the last char.
-        int pos = tc.position() - 1;
+        const int pos = tc.position() - 1;
         if (pos < 0 || eowStr.contains(document->characterAt(pos)) || document->characterAt(pos) == QChar(QChar::LineSeparator)
             || document->characterAt(pos) == QChar(QChar::ParagraphSeparator)) {
             break;
diff --git a/textcustomeditor/plaintexteditor/plaintexteditor.cpp b/textcustomeditor/plaintexteditor/plaintexteditor.cpp
index aaf1a5efd..a316042bb 100644
--- a/textcustomeditor/plaintexteditor/plaintexteditor.cpp
+++ b/textcustomeditor/plaintexteditor/plaintexteditor.cpp
@@ -587,7 +587,7 @@ bool PlainTextEditor::handleShortcut(QKeyEvent *event)
         qreal lastY = cursorRect(cursor).bottom();
         qreal distance = 0;
         do {
-            qreal y = cursorRect(cursor).bottom();
+            const qreal y = cursorRect(cursor).bottom();
             distance += qAbs(y - lastY);
             lastY = y;
             moved = cursor.movePosition(QTextCursor::Down);
@@ -605,7 +605,7 @@ bool PlainTextEditor::handleShortcut(QKeyEvent *event)
         qreal lastY = cursorRect(cursor).bottom();
         qreal distance = 0;
         do {
-            qreal y = cursorRect(cursor).bottom();
+            const qreal y = cursorRect(cursor).bottom();
             distance += qAbs(y - lastY);
             lastY = y;
             moved = cursor.movePosition(QTextCursor::Up);
@@ -646,7 +646,7 @@ bool PlainTextEditor::handleShortcut(QKeyEvent *event)
         }
         return true;
     } else if (KStandardShortcut::pasteSelection().contains(key)) {
-        QString text = QApplication::clipboard()->text(QClipboard::Selection);
+        const QString text = QApplication::clipboard()->text(QClipboard::Selection);
         if (!text.isEmpty()) {
             insertPlainText(text); // TODO: check if this is html? (MiB)
         }
@@ -661,7 +661,7 @@ bool PlainTextEditor::handleShortcut(QKeyEvent *event)
 void PlainTextEditor::deleteEndOfLine()
 {
     QTextCursor cursor = textCursor();
-    QTextBlock block = cursor.block();
+    const QTextBlock block = cursor.block();
     if (cursor.position() == block.position() + block.length() - 2) {
         cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
     } else {
@@ -685,7 +685,7 @@ void PlainTextEditor::moveCursorBeginUpDown(bool moveUp)
 
 void PlainTextEditor::moveLineUpDown(bool moveUp)
 {
-    QTextCursor cursor = textCursor();
+    const QTextCursor cursor = textCursor();
     QTextCursor move = cursor;
     move.beginEditBlock();
 
@@ -881,7 +881,7 @@ void PlainTextEditor::setSpellCheckingConfigFileName(const QString &_fileName)
     d->spellCheckingConfigFileName = _fileName;
     KSharedConfig::Ptr config = KSharedConfig::openConfig(d->spellCheckingConfigFileName);
     if (config->hasGroup("Spelling"_L1)) {
-        KConfigGroup group(config, "Spelling"_L1);
+        const KConfigGroup group(config, "Spelling"_L1);
         d->checkSpellingEnabled = group.readEntry("checkerEnabledByDefault", false);
         d->spellCheckingLanguage = group.readEntry("Language", QString());
     }
@@ -918,7 +918,7 @@ void PlainTextEditor::setSpellCheckingLanguage(const QString &_language)
 
     if (_language != d->spellCheckingLanguage) {
         d->spellCheckingLanguage = _language;
-        KSharedConfig::Ptr config = KSharedConfig::openConfig(d->spellCheckingConfigFileName);
+        const KSharedConfig::Ptr config = KSharedConfig::openConfig(d->spellCheckingConfigFileName);
         KConfigGroup group(config, "Spelling"_L1);
         group.writeEntry("Language", d->spellCheckingLanguage);
         setCheckSpellingEnabled(checkSpellingEnabled());
@@ -930,7 +930,7 @@ void PlainTextEditor::setSpellCheckingLanguage(const QString &_language)
 void PlainTextEditor::slotToggleAutoSpellCheck()
 {
     setCheckSpellingEnabled(!checkSpellingEnabled());
-    KSharedConfig::Ptr config = KSharedConfig::openConfig(d->spellCheckingConfigFileName);
+    const KSharedConfig::Ptr config = KSharedConfig::openConfig(d->spellCheckingConfigFileName);
     KConfigGroup group(config, "Spelling"_L1);
     group.writeEntry("checkerEnabledByDefault", d->checkSpellingEnabled);
 }
diff --git a/textcustomeditor/plaintexteditor/plaintextsyntaxspellcheckinghighlighter.cpp b/textcustomeditor/plaintexteditor/plaintextsyntaxspellcheckinghighlighter.cpp
index 7461c8ef8..26788234f 100644
--- a/textcustomeditor/plaintexteditor/plaintextsyntaxspellcheckinghighlighter.cpp
+++ b/textcustomeditor/plaintexteditor/plaintextsyntaxspellcheckinghighlighter.cpp
@@ -157,9 +157,7 @@ void PlainTextSyntaxSpellCheckingHighlighter::setMisspelled(int start, int count
 void PlainTextSyntaxSpellCheckingHighlighter::applyFormat(int offset, int length, const KSyntaxHighlighting::Format &format)
 {
     if (format.spellCheck() && length > 0) {
-        if (d->spellCheckRanges.empty()) {
-            d->spellCheckRanges.emplace_back(offset, length);
-        } else if (d->spellCheckRanges.back().end() + 1 == offset) {
+        if (d->spellCheckRanges.back().end() + 1 == offset) {
             d->spellCheckRanges.back().length += length;
         } else {
             d->spellCheckRanges.emplace_back(offset, length);
diff --git a/textcustomeditor/richtextbrowser/richtextbrowser.cpp b/textcustomeditor/richtextbrowser/richtextbrowser.cpp
index 10ef4db85..69a374469 100644
--- a/textcustomeditor/richtextbrowser/richtextbrowser.cpp
+++ b/textcustomeditor/richtextbrowser/richtextbrowser.cpp
@@ -368,7 +368,7 @@ bool RichTextBrowser::handleShortcut(QKeyEvent *event)
         qreal lastY = cursorRect(cursor).bottom();
         qreal distance = 0;
         do {
-            qreal y = cursorRect(cursor).bottom();
+            const qreal y = cursorRect(cursor).bottom();
             distance += qAbs(y - lastY);
             lastY = y;
             moved = cursor.movePosition(QTextCursor::Down);
@@ -386,7 +386,7 @@ bool RichTextBrowser::handleShortcut(QKeyEvent *event)
         qreal lastY = cursorRect(cursor).bottom();
         qreal distance = 0;
         do {
-            qreal y = cursorRect(cursor).bottom();
+            const qreal y = cursorRect(cursor).bottom();
             distance += qAbs(y - lastY);
             lastY = y;
             moved = cursor.movePosition(QTextCursor::Up);
@@ -422,14 +422,14 @@ bool RichTextBrowser::handleShortcut(QKeyEvent *event)
         Q_EMIT findText();
         return true;
     } else if (KStandardShortcut::pasteSelection().contains(key)) {
-        QString text = QApplication::clipboard()->text(QClipboard::Selection);
+        const QString text = QApplication::clipboard()->text(QClipboard::Selection);
         if (!text.isEmpty()) {
             insertPlainText(text); // TODO: check if this is html? (MiB)
         }
         return true;
     } else if (event == QKeySequence::DeleteEndOfLine) {
         QTextCursor cursor = textCursor();
-        QTextBlock block = cursor.block();
+        const QTextBlock block = cursor.block();
         if (cursor.position() == block.position() + block.length() - 2) {
             cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
         } else {
@@ -547,7 +547,7 @@ void RichTextBrowser::moveCursorBeginUpDown(bool moveUp)
 
 void RichTextBrowser::moveLineUpDown(bool moveUp)
 {
-    QTextCursor cursor = textCursor();
+    const QTextCursor cursor = textCursor();
     QTextCursor move = cursor;
     move.beginEditBlock();
 
@@ -582,10 +582,10 @@ void RichTextBrowser::moveLineUpDown(bool moveUp)
         }
     }
 
-    int start = move.position();
+    const int start = move.position();
     move.clearSelection();
     move.insertText(text);
-    int end = move.position();
+    const int end = move.position();
 
     if (hasSelection) {
         move.setPosition(end);
diff --git a/textcustomeditor/widgets/textfindreplacewidget.cpp b/textcustomeditor/widgets/textfindreplacewidget.cpp
index dbef451f0..24c1e651c 100644
--- a/textcustomeditor/widgets/textfindreplacewidget.cpp
+++ b/textcustomeditor/widgets/textfindreplacewidget.cpp
@@ -144,7 +144,7 @@ void TextFindWidget::setFoundMatch(bool match)
             bgColorScheme = KColorScheme::NegativeBackground;
         }
 
-        KStatefulBrush bgBrush(KColorScheme::View, bgColorScheme);
+        const KStatefulBrush bgBrush(KColorScheme::View, bgColorScheme);
 
         styleSheet = u"QLineEdit{ background-color:%1 }"_s.arg(bgBrush.brush(mSearch->palette()).color().name());
     }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.