Commit 7808266f authored by Eike Ziller's avatar Eike Ziller

TextEditors: Remove useless duplicated (set)textCodec methods

They are duplicated from TextDocument::(set)codec. The default
implementation of the duplicated methods was just delegating to the text
document. The override of setTextCodec in QmlJsEditor was useless, since
it was only called from EditorConfiguration::configureEditor with the
ITextEditor::TextCodecFromProjectSetting flag anyhow, which made the
overridden method in QmlJsEditor be the same as the fallback.
Aside from that, the duplicated methods wouldn't have belonged to the
*editor* anyhow, but to the document.

Change-Id: Ib43c28210b6bf88726159d751a4905a1d062f80e
Reviewed-by: default avatarFriedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
parent fade19a9
......@@ -237,7 +237,7 @@ void EditorConfiguration::configureEditor(ITextEditor *textEditor) const
if (baseTextEditor)
baseTextEditor->setCodeStyle(codeStyle(baseTextEditor->languageSettingsId()));
if (!d->m_useGlobal) {
textEditor->setTextCodec(d->m_textCodec, ITextEditor::TextCodecFromProjectSetting);
textEditor->textDocument()->setCodec(d->m_textCodec);
if (baseTextEditor)
switchSettings(baseTextEditor);
}
......
......@@ -60,13 +60,6 @@ bool QmlJSEditor::isDesignModePreferred() const
return false;
}
void QmlJSEditor::setTextCodec(QTextCodec *codec, TextCodecReason reason)
{
if (reason != TextCodecOtherReason) // qml is defined to be utf8
return;
editorWidget()->setTextCodec(codec);
}
const Utils::CommentDefinition *QmlJSEditor::commentDefinition() const
{
return &m_commentDefinition;
......
......@@ -49,7 +49,6 @@ public:
Core::Id id() const;
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
bool isDesignModePreferred() const;
void setTextCodec(QTextCodec *codec, TextCodecReason = TextCodecOtherReason);
const Utils::CommentDefinition *commentDefinition() const;
private:
......
......@@ -5837,17 +5837,6 @@ void BaseTextEditorWidget::unfoldAll()
centerCursor();
}
void BaseTextEditorWidget::setTextCodec(QTextCodec *codec)
{
baseTextDocument()->setCodec(codec);
}
QTextCodec *BaseTextEditorWidget::textCodec() const
{
// TODO: Fix all QTextCodec usages to be const *.
return const_cast<QTextCodec *>(baseTextDocument()->codec());
}
void BaseTextEditorWidget::setReadOnly(bool b)
{
QPlainTextEdit::setReadOnly(b);
......
......@@ -211,9 +211,6 @@ public:
void setActionHack(QObject *hack);
QObject *actionHack() const;
void setTextCodec(QTextCodec *codec);
QTextCodec *textCodec() const;
void setReadOnly(bool b);
void setTextCursor(const QTextCursor &cursor);
......@@ -640,9 +637,6 @@ public:
QString contextHelpId() const; // from IContext
void setTextCodec(QTextCodec *codec, TextCodecReason = TextCodecOtherReason) { m_editorWidget->setTextCodec(codec); }
QTextCodec *textCodec() const { return m_editorWidget->textCodec(); }
// ITextEditor
void remove(int length);
void insert(const QString &string);
......
......@@ -59,7 +59,7 @@ QMap<QString, QTextCodec *> TextEditor::ITextEditor::openedTextEditorsEncodings(
if (!textEditor)
continue;
QString fileName = textEditor->document()->filePath();
workingCopy[fileName] = textEditor->textCodec();
workingCopy[fileName] = const_cast<QTextCodec *>(textEditor->textDocument()->codec());
}
return workingCopy;
}
......
......@@ -109,15 +109,6 @@ public:
virtual ITextMarkable *markableInterface() = 0;
enum TextCodecReason {
TextCodecOtherReason,
TextCodecFromSystemSetting,
TextCodecFromProjectSetting
};
virtual void setTextCodec(QTextCodec *, TextCodecReason reason = TextCodecOtherReason) = 0;
virtual QTextCodec *textCodec() const = 0;
virtual const Utils::CommentDefinition* commentDefinition() const = 0;
static QMap<QString, QString> openedTextEditorsContents();
......
......@@ -1164,7 +1164,7 @@ DiffChunk VcsBaseEditorWidget::diffChunk(QTextCursor cursor) const
unicode += QLatin1Char('\n');
}
}
const QTextCodec *cd = textCodec();
const QTextCodec *cd = baseTextDocument()->codec();
rc.chunk = cd ? cd->fromUnicode(unicode) : unicode.toLocal8Bit();
return rc;
}
......@@ -1232,8 +1232,8 @@ static QTextCodec *findFileCodec(const QString &source)
if (!editors.empty()) {
const EditorList::const_iterator ecend = editors.constEnd();
for (EditorList::const_iterator it = editors.constBegin(); it != ecend; ++it)
if (const TextEditor::BaseTextEditor *be = qobject_cast<const TextEditor::BaseTextEditor *>(*it)) {
QTextCodec *codec = be->editorWidget()->textCodec();
if (TextEditor::BaseTextEditor *be = qobject_cast<TextEditor::BaseTextEditor *>(*it)) {
QTextCodec *codec = const_cast<QTextCodec *>(be->textDocument()->codec());
return codec;
}
}
......
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