aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@qt.io>2021-04-22 10:59:32 +0200
committerDavid Schulz <david.schulz@qt.io>2021-05-03 04:11:07 +0000
commitec2449cae43aef0a81f7eeab25ba995515d9bd2f (patch)
tree981ff5bfc56886a3d0df653d7e7d3ffb580d0768 /src/plugins
parent7880950eca95d84b302c36fa2f4a72e6f19ea7d4 (diff)
TextEditor: move snippet overlay into own cpp file
Change-Id: I3343d9abf19e4edc7bd88077bf8fe6666a901e1b Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/texteditor/CMakeLists.txt1
-rw-r--r--src/plugins/texteditor/snippets/snippetoverlay.cpp112
-rw-r--r--src/plugins/texteditor/snippets/snippetoverlay.h54
-rw-r--r--src/plugins/texteditor/texteditor.cpp1
-rw-r--r--src/plugins/texteditor/texteditor.pro6
-rw-r--r--src/plugins/texteditor/texteditor.qbs6
-rw-r--r--src/plugins/texteditor/texteditoroverlay.cpp78
-rw-r--r--src/plugins/texteditor/texteditoroverlay.h18
8 files changed, 176 insertions, 100 deletions
diff --git a/src/plugins/texteditor/CMakeLists.txt b/src/plugins/texteditor/CMakeLists.txt
index 93d773ddb5e..8d5f9236cb4 100644
--- a/src/plugins/texteditor/CMakeLists.txt
+++ b/src/plugins/texteditor/CMakeLists.txt
@@ -81,6 +81,7 @@ add_qtc_plugin(TextEditor
snippets/snippet.cpp snippets/snippet.h
snippets/snippetassistcollector.cpp snippets/snippetassistcollector.h
snippets/snippeteditor.cpp snippets/snippeteditor.h
+ snippets/snippetoverlay.cpp snippets/snippetoverlay.h
snippets/snippetprovider.cpp snippets/snippetprovider.h
snippets/snippetscollection.cpp snippets/snippetscollection.h
snippets/snippetssettings.cpp snippets/snippetssettings.h
diff --git a/src/plugins/texteditor/snippets/snippetoverlay.cpp b/src/plugins/texteditor/snippets/snippetoverlay.cpp
new file mode 100644
index 00000000000..e80cf8cb948
--- /dev/null
+++ b/src/plugins/texteditor/snippets/snippetoverlay.cpp
@@ -0,0 +1,112 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#include "snippetoverlay.h"
+
+#include "snippet.h"
+
+namespace TextEditor {
+namespace Internal {
+
+
+void SnippetOverlay::clear()
+{
+ TextEditorOverlay::clear();
+ m_equivalentSelections.clear();
+ m_manglers.clear();
+}
+
+void SnippetOverlay::mapEquivalentSelections()
+{
+ m_equivalentSelections.clear();
+ m_equivalentSelections.resize(selections().size());
+
+ QMultiMap<QString, int> all;
+ for (int i = 0; i < selections().size(); ++i)
+ all.insert(selectionText(i).toLower(), i);
+
+ const QList<QString> &uniqueKeys = all.uniqueKeys();
+ foreach (const QString &key, uniqueKeys) {
+ QList<int> indexes;
+ const auto cAll = all;
+ QMultiMap<QString, int>::const_iterator lbit = cAll.lowerBound(key);
+ QMultiMap<QString, int>::const_iterator ubit = cAll.upperBound(key);
+ while (lbit != ubit) {
+ indexes.append(lbit.value());
+ ++lbit;
+ }
+
+ foreach (int index, indexes)
+ m_equivalentSelections[index] = indexes;
+ }
+}
+
+void SnippetOverlay::updateEquivalentSelections(const QTextCursor &cursor)
+{
+ int selectionIndex = selectionIndexForCursor(cursor);
+ if (selectionIndex == -1)
+ return;
+
+ const QString &currentText = selectionText(selectionIndex);
+ const QList<int> &equivalents = m_equivalentSelections.at(selectionIndex);
+ foreach (int i, equivalents) {
+ if (i == selectionIndex)
+ continue;
+ const QString &equivalentText = selectionText(i);
+ if (currentText != equivalentText) {
+ QTextCursor selectionCursor = assembleCursorForSelection(i);
+ selectionCursor.joinPreviousEditBlock();
+ selectionCursor.removeSelectedText();
+ selectionCursor.insertText(currentText);
+ selectionCursor.endEditBlock();
+ }
+ }
+}
+
+void SnippetOverlay::setNameMangler(const QList<NameMangler *> &manglers)
+{
+ m_manglers = manglers;
+}
+
+void SnippetOverlay::mangle()
+{
+ for (int i = 0; i < m_manglers.count(); ++i) {
+ if (!m_manglers.at(i))
+ continue;
+
+ const QString current = selectionText(i);
+ const QString result = m_manglers.at(i)->mangle(current);
+ if (result != current) {
+ QTextCursor selectionCursor = assembleCursorForSelection(i);
+ selectionCursor.joinPreviousEditBlock();
+ selectionCursor.removeSelectedText();
+ selectionCursor.insertText(result);
+ selectionCursor.endEditBlock();
+ }
+ }
+}
+
+} // namespace Internal
+} // namespace TextEditor
diff --git a/src/plugins/texteditor/snippets/snippetoverlay.h b/src/plugins/texteditor/snippets/snippetoverlay.h
new file mode 100644
index 00000000000..0edf0a8e0d9
--- /dev/null
+++ b/src/plugins/texteditor/snippets/snippetoverlay.h
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+****************************************************************************/
+
+#pragma once
+
+#include "texteditor/texteditoroverlay.h"
+
+namespace TextEditor {
+class NameMangler;
+
+namespace Internal {
+
+class SnippetOverlay : public TextEditorOverlay
+{
+public:
+ using TextEditorOverlay::TextEditorOverlay;
+
+ void clear() override;
+
+ void mapEquivalentSelections();
+ void updateEquivalentSelections(const QTextCursor &cursor);
+ void setNameMangler(const QList<NameMangler *> &manglers);
+ void mangle();
+
+private:
+ QVector<QList<int> > m_equivalentSelections;
+ QList<NameMangler *> m_manglers;
+};
+
+} // namespace Internal
+} // namespace TextEditor
+
diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp
index 81459f90cd2..921b3610105 100644
--- a/src/plugins/texteditor/texteditor.cpp
+++ b/src/plugins/texteditor/texteditor.cpp
@@ -42,6 +42,7 @@
#include "icodestylepreferences.h"
#include "refactoroverlay.h"
#include "snippets/snippet.h"
+#include "snippets/snippetoverlay.h"
#include "storagesettings.h"
#include "syntaxhighlighter.h"
#include "tabsettings.h"
diff --git a/src/plugins/texteditor/texteditor.pro b/src/plugins/texteditor/texteditor.pro
index bbf536459ed..6e00135a166 100644
--- a/src/plugins/texteditor/texteditor.pro
+++ b/src/plugins/texteditor/texteditor.pro
@@ -97,7 +97,8 @@ SOURCES += texteditorplugin.cpp \
commentssettings.cpp \
marginsettings.cpp \
formattexteditor.cpp \
- command.cpp
+ command.cpp \
+ snippets/snippetoverlay.cpp
HEADERS += texteditorplugin.h \
plaintexteditorfactory.h \
@@ -192,7 +193,8 @@ HEADERS += texteditorplugin.h \
formattexteditor.h \
command.h \
indenter.h \
- formatter.h
+ formatter.h \
+ snippets/snippetoverlay.h
FORMS += \
displaysettingspage.ui \
diff --git a/src/plugins/texteditor/texteditor.qbs b/src/plugins/texteditor/texteditor.qbs
index 5b36e0c76c4..a7046a42418 100644
--- a/src/plugins/texteditor/texteditor.qbs
+++ b/src/plugins/texteditor/texteditor.qbs
@@ -205,8 +205,6 @@ Project {
name: "Snippets"
prefix: "snippets/"
files: [
- "snippetprovider.cpp",
- "snippetprovider.h",
"reuse.h",
"snippet.cpp",
"snippet.h",
@@ -214,6 +212,10 @@ Project {
"snippetassistcollector.h",
"snippeteditor.cpp",
"snippeteditor.h",
+ "snippetoverlay.cpp",
+ "snippetoverlay.h",
+ "snippetprovider.cpp",
+ "snippetprovider.h",
"snippetscollection.cpp",
"snippetscollection.h",
"snippetssettings.cpp",
diff --git a/src/plugins/texteditor/texteditoroverlay.cpp b/src/plugins/texteditor/texteditoroverlay.cpp
index 5522a7ef333..41107e39d92 100644
--- a/src/plugins/texteditor/texteditoroverlay.cpp
+++ b/src/plugins/texteditor/texteditoroverlay.cpp
@@ -25,7 +25,6 @@
#include "texteditoroverlay.h"
#include "texteditor.h"
-#include "snippets/snippet.h"
#include <QDebug>
#include <QMap>
@@ -485,80 +484,3 @@ bool TextEditorOverlay::hasFirstSelectionBeginMoved() const
return false;
return m_selections.at(0).m_cursor_begin.position() != m_firstSelectionOriginalBegin;
}
-
-void SnippetOverlay::clear()
-{
- TextEditorOverlay::clear();
- m_equivalentSelections.clear();
- m_manglers.clear();
-}
-
-void SnippetOverlay::mapEquivalentSelections()
-{
- m_equivalentSelections.clear();
- m_equivalentSelections.resize(selections().size());
-
- QMultiMap<QString, int> all;
- for (int i = 0; i < selections().size(); ++i)
- all.insert(selectionText(i).toLower(), i);
-
- const QList<QString> &uniqueKeys = all.uniqueKeys();
- foreach (const QString &key, uniqueKeys) {
- QList<int> indexes;
- const auto cAll = all;
- QMultiMap<QString, int>::const_iterator lbit = cAll.lowerBound(key);
- QMultiMap<QString, int>::const_iterator ubit = cAll.upperBound(key);
- while (lbit != ubit) {
- indexes.append(lbit.value());
- ++lbit;
- }
-
- foreach (int index, indexes)
- m_equivalentSelections[index] = indexes;
- }
-}
-
-void SnippetOverlay::updateEquivalentSelections(const QTextCursor &cursor)
-{
- int selectionIndex = selectionIndexForCursor(cursor);
- if (selectionIndex == -1)
- return;
-
- const QString &currentText = selectionText(selectionIndex);
- const QList<int> &equivalents = m_equivalentSelections.at(selectionIndex);
- foreach (int i, equivalents) {
- if (i == selectionIndex)
- continue;
- const QString &equivalentText = selectionText(i);
- if (currentText != equivalentText) {
- QTextCursor selectionCursor = assembleCursorForSelection(i);
- selectionCursor.joinPreviousEditBlock();
- selectionCursor.removeSelectedText();
- selectionCursor.insertText(currentText);
- selectionCursor.endEditBlock();
- }
- }
-}
-
-void SnippetOverlay::setNameMangler(const QList<NameMangler *> &manglers)
-{
- m_manglers = manglers;
-}
-
-void SnippetOverlay::mangle()
-{
- for (int i = 0; i < m_manglers.count(); ++i) {
- if (!m_manglers.at(i))
- continue;
-
- const QString current = selectionText(i);
- const QString result = m_manglers.at(i)->mangle(current);
- if (result != current) {
- QTextCursor selectionCursor = assembleCursorForSelection(i);
- selectionCursor.joinPreviousEditBlock();
- selectionCursor.removeSelectedText();
- selectionCursor.insertText(result);
- selectionCursor.endEditBlock();
- }
- }
-}
diff --git a/src/plugins/texteditor/texteditoroverlay.h b/src/plugins/texteditor/texteditoroverlay.h
index a07252c0b22..e995f007c5d 100644
--- a/src/plugins/texteditor/texteditoroverlay.h
+++ b/src/plugins/texteditor/texteditoroverlay.h
@@ -35,7 +35,6 @@ QT_FORWARD_DECLARE_CLASS(QWidget)
QT_FORWARD_DECLARE_CLASS(QPainterPath)
namespace TextEditor {
-class NameMangler;
class TextEditorWidget;
namespace Internal {
@@ -117,22 +116,5 @@ private:
QList<OverlaySelection> m_selections;
};
-class SnippetOverlay : public TextEditorOverlay
-{
-public:
- using TextEditorOverlay::TextEditorOverlay;
-
- void clear() override;
-
- void mapEquivalentSelections();
- void updateEquivalentSelections(const QTextCursor &cursor);
- void setNameMangler(const QList<NameMangler *> &manglers);
- void mangle();
-
-private:
- QVector<QList<int> > m_equivalentSelections;
- QList<NameMangler *> m_manglers;
-};
-
} // namespace Internal
} // namespace TextEditor