Commit 2c07175b authored by hjk's avatar hjk

TextEditor: Avoid using Core::Id::uniqueIdentifier

... by using Core::Ids instead of ExtraSelectionKind enum.

Change-Id: I664ff2a4a03eddd8fe1150929203a1727c12dc84
Reviewed-by: default avatarDavid Schulz <david.schulz@theqtcompany.com>
parent 1a0a7312
......@@ -229,7 +229,7 @@ void CppEditorWidget::finalizeInitializationAfterDuplication(TextEditorWidget *o
if (cppEditorWidget->isSemanticInfoValidExceptLocalUses())
updateSemanticInfo(cppEditorWidget->semanticInfo());
d->m_cppEditorOutline->update();
const ExtraSelectionKind selectionKind = CodeWarningsSelection;
const Id selectionKind = CodeWarningsSelection;
setExtraSelections(selectionKind, cppEditorWidget->extraSelections(selectionKind));
}
......
......@@ -150,6 +150,8 @@ using namespace Utils;
namespace TextEditor {
namespace Internal {
enum { NExtraSelectionKinds = 12 };
typedef QString (TransformationMethod)(const QString &);
static QString QString_toUpper(const QString &str)
......@@ -414,8 +416,8 @@ public:
void highlightSearchResults(const QTextBlock &block, TextEditorOverlay *overlay);
QTimer m_delayedUpdateTimer;
void setExtraSelections(int kind, const QList<QTextEdit::ExtraSelection> &selections);
QHash<int, QList<QTextEdit::ExtraSelection>> m_extraSelections;
void setExtraSelections(Core::Id kind, const QList<QTextEdit::ExtraSelection> &selections);
QHash<Core::Id, QList<QTextEdit::ExtraSelection>> m_extraSelections;
// block selection mode
bool m_inBlockSelectionMode;
......@@ -555,8 +557,7 @@ TextEditorWidgetPrivate::TextEditorWidgetPrivate(TextEditorWidget *parent)
m_cursorPositionLabelAction = m_toolBar->addWidget(m_cursorPositionLabel);
m_fileEncodingLabelAction = m_toolBar->addWidget(m_fileEncodingLabel);
m_extraSelections.reserve(TextEditorWidget::NExtraSelectionKinds);
m_extraSelections.reserve(NExtraSelectionKinds);
}
} // namespace Internal
......@@ -619,6 +620,18 @@ QString TextEditorWidget::convertToPlainText(const QString &txt)
static const char kTextBlockMimeType[] = "application/vnd.qtcreator.blocktext";
Id TextEditorWidget::SnippetPlaceholderSelection("TextEdit.SnippetPlaceHolderSelection");
Id TextEditorWidget::CurrentLineSelection("TextEdit.CurrentLineSelection");
Id TextEditorWidget::ParenthesesMatchingSelection("TextEdit.ParenthesesMatchingSelection");
Id TextEditorWidget::CodeWarningsSelection("TextEdit.CodeWarningsSelection");
Id TextEditorWidget::CodeSemanticsSelection("TextEdit.CodeSemanticsSelection");
Id TextEditorWidget::UndefinedSymbolSelection("TextEdit.UndefinedSymbolSelection");
Id TextEditorWidget::UnusedSymbolSelection("TextEdit.UnusedSymbolSelection");
Id TextEditorWidget::OtherSelection("TextEdit.OtherSelection");
Id TextEditorWidget::ObjCSelection("TextEdit.ObjCSelection");
Id TextEditorWidget::DebuggerExceptionSelection("TextEdit.DebuggerExceptionSelection");
Id TextEditorWidget::FakeVimSelection("TextEdit.FakeVimSelection");
TextEditorWidget::TextEditorWidget(QWidget *parent)
: QPlainTextEdit(parent)
{
......@@ -2615,7 +2628,7 @@ void TextEditorWidgetPrivate::documentAboutToBeReloaded()
// remove extra selections (loads of QTextCursor objects)
m_extraSelections.clear();
m_extraSelections.reserve(TextEditorWidget::NExtraSelectionKinds);
m_extraSelections.reserve(NExtraSelectionKinds);
q->QPlainTextEdit::setExtraSelections(QList<QTextEdit::ExtraSelection>());
// clear all overlays
......@@ -6085,8 +6098,7 @@ void TextEditorWidget::deleteStartOfWordCamelCase()
setTextCursor(c);
}
// kind can be either a value from the ExtraSelectionKind enum, or an unique Core::Id identifier.
void TextEditorWidgetPrivate::setExtraSelections(int kind, const QList<QTextEdit::ExtraSelection> &selections)
void TextEditorWidgetPrivate::setExtraSelections(Id kind, const QList<QTextEdit::ExtraSelection> &selections)
{
if (selections.isEmpty() && m_extraSelections[kind].isEmpty())
return;
......@@ -6124,28 +6136,14 @@ void TextEditorWidgetPrivate::setExtraSelections(int kind, const QList<QTextEdit
}
}
void TextEditorWidget::setExtraSelections(ExtraSelectionKind kind, const QList<QTextEdit::ExtraSelection> &selections)
{
d->setExtraSelections(kind, selections);
}
QList<QTextEdit::ExtraSelection> TextEditorWidget::extraSelections(ExtraSelectionKind kind) const
{
return d->m_extraSelections[kind];
}
void TextEditorWidget::setExtraSelections(Id kind, const QList<QTextEdit::ExtraSelection> &selections)
{
// Private Core:Id identifiers from the 0-1000 range cannot be used here, they conflict with ExtraSelectionKind
QTC_ASSERT(kind.uniqueIdentifier() >= NExtraSelectionKinds, return);
d->setExtraSelections(kind.uniqueIdentifier(), selections);
d->setExtraSelections(kind, selections);
}
QList<QTextEdit::ExtraSelection> TextEditorWidget::extraSelections(Id kind) const
{
// Private Core:Id identifiers from the 0-1000 range cannot be used here, they conflict with ExtraSelectionKind
QTC_ASSERT(kind.uniqueIdentifier() >= NExtraSelectionKinds, return QList<QTextEdit::ExtraSelection>());
return d->m_extraSelections[kind.uniqueIdentifier()];
return d->m_extraSelections.value(kind);
}
QString TextEditorWidget::extraSelectionTooltip(int pos) const
......
......@@ -328,22 +328,18 @@ public:
void ensureCursorVisible();
enum ExtraSelectionKind {
CurrentLineSelection,
ParenthesesMatchingSelection,
CodeWarningsSelection,
CodeSemanticsSelection,
UndefinedSymbolSelection,
UnusedSymbolSelection,
FakeVimSelection,
OtherSelection,
SnippetPlaceholderSelection,
ObjCSelection,
DebuggerExceptionSelection,
NExtraSelectionKinds
};
void setExtraSelections(ExtraSelectionKind kind, const QList<QTextEdit::ExtraSelection> &selections);
QList<QTextEdit::ExtraSelection> extraSelections(ExtraSelectionKind kind) const;
static Core::Id FakeVimSelection;
static Core::Id SnippetPlaceholderSelection;
static Core::Id CurrentLineSelection;
static Core::Id ParenthesesMatchingSelection;
static Core::Id CodeWarningsSelection;
static Core::Id CodeSemanticsSelection;
static Core::Id UndefinedSymbolSelection;
static Core::Id UnusedSymbolSelection;
static Core::Id OtherSelection;
static Core::Id ObjCSelection;
static Core::Id DebuggerExceptionSelection;
void setExtraSelections(Core::Id kind, const QList<QTextEdit::ExtraSelection> &selections);
QList<QTextEdit::ExtraSelection> extraSelections(Core::Id kind) const;
QString extraSelectionTooltip(int pos) const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment