Commit 4eff289e authored by Eike Ziller's avatar Eike Ziller

TextEditors: Remove widget's setTabSettings method

Change-Id: If212b45e2d526534b7853f3fa23b170f61e1976e
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent f506104f
......@@ -41,7 +41,7 @@ using namespace Android::Internal;
AndroidManifestDocument::AndroidManifestDocument(AndroidManifestEditorWidget *editorWidget)
: TextEditor::BaseTextDocument(),
: TextEditor::PlainTextDocument(),
m_editorWidget(editorWidget)
{
setMimeType(QLatin1String(Constants::ANDROID_MANIFEST_MIME_TYPE));
......
......@@ -31,13 +31,13 @@
#define ANDROIDMANIFESTDOCUMENT_H
#include <coreplugin/textdocument.h>
#include <texteditor/basetextdocument.h>
#include <texteditor/plaintexteditor.h>
namespace Android {
namespace Internal {
class AndroidManifestEditorWidget;
class AndroidManifestDocument : public TextEditor::BaseTextDocument
class AndroidManifestDocument : public TextEditor::PlainTextDocument
{
public:
explicit AndroidManifestDocument(AndroidManifestEditorWidget *editorWidget);
......
......@@ -512,7 +512,7 @@ CPPEditor::CPPEditor(CPPEditorWidget *editor)
Q_GLOBAL_STATIC(CppTools::SymbolFinder, symbolFinder)
CPPEditorWidget::CPPEditorWidget(QWidget *parent)
: TextEditor::BaseTextEditorWidget(parent)
: TextEditor::BaseTextEditorWidget(new CPPEditorDocument(), parent)
{
baseTextDocument()->setIndenter(new CppTools::CppQtStyleIndenter);
ctor();
......@@ -1583,14 +1583,6 @@ void CPPEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
highlighter->rehighlight();
}
void CPPEditorWidget::setTabSettings(const TextEditor::TabSettings &ts)
{
CppTools::QtStyleCodeFormatter formatter;
formatter.invalidateCache(document());
TextEditor::BaseTextEditorWidget::setTabSettings(ts);
}
void CPPEditorWidget::unCommentSelection()
{
Utils::unCommentSelection(this);
......@@ -2027,4 +2019,16 @@ void CPPEditorWidget::showPreProcessorWidget()
}
}
CPPEditorDocument::CPPEditorDocument()
{
connect(this, SIGNAL(tabSettingsChanged()),
this, SLOT(invalidateFormatterCache()));
}
void CPPEditorDocument::invalidateFormatterCache()
{
CppTools::QtStyleCodeFormatter formatter;
formatter.invalidateCache(document());
}
#include <cppeditor.moc>
......@@ -71,6 +71,16 @@ namespace Internal {
class CPPEditorWidget;
class CPPEditorDocument : public TextEditor::BaseTextDocument
{
Q_OBJECT
public:
CPPEditorDocument();
private slots:
void invalidateFormatterCache();
};
class CPPEditor : public TextEditor::BaseTextEditor
{
Q_OBJECT
......@@ -136,7 +146,6 @@ Q_SIGNALS:
public Q_SLOTS:
virtual void setFontSettings(const TextEditor::FontSettings &);
virtual void setTabSettings(const TextEditor::TabSettings &);
void setSortedOutline(bool sort);
void switchDeclarationDefinition(bool inNextSplit);
void renameSymbolUnderCursor();
......
......@@ -465,7 +465,7 @@ void CppCodeStylePreferencesWidget::updatePreview()
const TextEditor::TabSettings ts = cppCodeStylePreferences->currentTabSettings();
QtStyleCodeFormatter formatter(ts, ccss);
foreach (TextEditor::SnippetEditorWidget *preview, m_previews) {
preview->setTabSettings(ts);
preview->baseTextDocument()->setTabSettings(ts);
preview->setCodeStyle(cppCodeStylePreferences);
QTextDocument *doc = preview->document();
......
......@@ -30,7 +30,7 @@
#ifndef FORMWINDOWFILE_H
#define FORMWINDOWFILE_H
#include <texteditor/basetextdocument.h>
#include <texteditor/plaintexteditor.h>
#include <QPointer>
......@@ -42,7 +42,7 @@ QT_END_NAMESPACE
namespace Designer {
namespace Internal {
class FormWindowFile : public TextEditor::BaseTextDocument
class FormWindowFile : public TextEditor::PlainTextDocument
{
Q_OBJECT
......
......@@ -761,6 +761,18 @@ void QmlJSTextEditorWidget::updateOutlineIndexNow()
}
}
QmlJSEditorDocument::QmlJSEditorDocument()
{
connect(this, SIGNAL(tabSettingsChanged()),
this, SLOT(invalidateFormatterCache()));
}
void QmlJSEditorDocument::invalidateFormatterCache()
{
QmlJSTools::CreatorCodeFormatter formatter(tabSettings());
formatter.invalidateCache(document());
}
} // namespace QmlJSEditor
class QtQuickToolbarMarker {};
......@@ -1286,14 +1298,6 @@ void QmlJSTextEditorWidget::unCommentSelection()
Utils::unCommentSelection(this);
}
void QmlJSTextEditorWidget::setTabSettings(const TextEditor::TabSettings &ts)
{
QmlJSTools::CreatorCodeFormatter formatter(ts);
formatter.invalidateCache(document());
TextEditor::BaseTextEditorWidget::setTabSettings(ts);
}
void QmlJSTextEditorWidget::updateSemanticInfo()
{
// If the editor is newer than the future semantic info, new semantic infos
......
......@@ -73,6 +73,16 @@ class QmlOutlineModel;
class SemanticInfoUpdater;
struct SemanticInfoUpdaterSource;
class SemanticHighlighter;
class QmlJSEditorDocument : public TextEditor::BaseTextDocument
{
Q_OBJECT
public:
QmlJSEditorDocument();
private slots:
void invalidateFormatterCache();
};
} // namespace Internal
struct QMLJSEDITOR_EXPORT Declaration
......@@ -118,7 +128,6 @@ public:
TextEditor::IAssistInterface *createAssistInterface(TextEditor::AssistKind assistKind,
TextEditor::AssistReason reason) const;
public slots:
virtual void setTabSettings(const TextEditor::TabSettings &ts);
void reparseDocument();
void reparseDocumentNow();
void updateSemanticInfo();
......
......@@ -131,7 +131,7 @@ void QmlJSCodeStylePreferencesWidget::updatePreview()
const TextEditor::TabSettings &ts = m_preferences
? m_preferences->currentTabSettings()
: TextEditorSettings::codeStyle()->tabSettings();
m_ui->previewTextEdit->setTabSettings(ts);
m_ui->previewTextEdit->baseTextDocument()->setTabSettings(ts);
CreatorCodeFormatter formatter(ts);
formatter.invalidateCache(doc);
......
......@@ -209,9 +209,12 @@ const StorageSettings &BaseTextDocument::storageSettings() const
return d->m_storageSettings;
}
void BaseTextDocument::setTabSettings(const TabSettings &tabSettings)
void BaseTextDocument::setTabSettings(const TextEditor::TabSettings &tabSettings)
{
if (tabSettings == d->m_tabSettings)
return;
d->m_tabSettings = tabSettings;
emit tabSettingsChanged();
}
const TabSettings &BaseTextDocument::tabSettings() const
......
......@@ -65,7 +65,6 @@ public:
void setTypingSettings(const TypingSettings &typingSettings);
void setStorageSettings(const StorageSettings &storageSettings);
void setTabSettings(const TabSettings &tabSettings);
void setExtraEncodingSettings(const ExtraEncodingSettings &extraEncodingSettings);
const TypingSettings &typingSettings() const;
......@@ -111,8 +110,12 @@ public:
bool reload(QString *errorString, QTextCodec *codec);
void cleanWhitespace(const QTextCursor &cursor);
public slots:
void setTabSettings(const TextEditor::TabSettings &tabSettings);
signals:
void mimeTypeChanged();
void tabSettingsChanged();
private:
void cleanWhitespace(QTextCursor &cursor, bool cleanIndentation, bool inEntireDocument);
......
......@@ -2395,6 +2395,7 @@ void BaseTextEditorWidgetPrivate::setupDocumentSignals()
SLOT(editorContentsChange(int,int,int)), Qt::DirectConnection);
QObject::connect(m_document.data(), SIGNAL(aboutToReload()), q, SLOT(documentAboutToBeReloaded()));
QObject::connect(m_document.data(), SIGNAL(reloadFinished(bool)), q, SLOT(documentReloadFinished(bool)));
QObject::connect(m_document.data(), SIGNAL(tabSettingsChanged()), q, SLOT(updateTabStops()));
q->slotUpdateExtraAreaWidth();
}
......@@ -4430,17 +4431,17 @@ void BaseTextEditorWidget::setCodeStyle(ICodeStylePreferences *preferences)
baseTextDocument()->indenter()->setCodeStylePreferences(preferences);
if (d->m_codeStylePreferences) {
disconnect(d->m_codeStylePreferences, SIGNAL(currentTabSettingsChanged(TextEditor::TabSettings)),
this, SLOT(setTabSettings(TextEditor::TabSettings)));
d->m_document.data(), SLOT(setTabSettings(TextEditor::TabSettings)));
disconnect(d->m_codeStylePreferences, SIGNAL(currentValueChanged(QVariant)),
this, SLOT(slotCodeStyleSettingsChanged(QVariant)));
}
d->m_codeStylePreferences = preferences;
if (d->m_codeStylePreferences) {
connect(d->m_codeStylePreferences, SIGNAL(currentTabSettingsChanged(TextEditor::TabSettings)),
this, SLOT(setTabSettings(TextEditor::TabSettings)));
d->m_document.data(), SLOT(setTabSettings(TextEditor::TabSettings)));
connect(d->m_codeStylePreferences, SIGNAL(currentValueChanged(QVariant)),
this, SLOT(slotCodeStyleSettingsChanged(QVariant)));
setTabSettings(d->m_codeStylePreferences->currentTabSettings());
d->m_document->setTabSettings(d->m_codeStylePreferences->currentTabSettings());
slotCodeStyleSettingsChanged(d->m_codeStylePreferences->currentValue());
}
}
......@@ -5401,7 +5402,7 @@ void BaseTextEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
p.setBrush(QPalette::Inactive, QPalette::HighlightedText, p.highlightedText());
setPalette(p);
setFont(font);
setTabSettings(d->m_document->tabSettings()); // update tabs, they depend on the font
updateTabStops(); // update tab stops, they depend on the font
// Line numbers
QPalette ep = d->m_extraArea->palette();
......@@ -5432,18 +5433,6 @@ void BaseTextEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
}
}
void BaseTextEditorWidget::setTabSettings(const TabSettings &ts)
{
d->m_document->setTabSettings(ts);
// Although the tab stop is stored as qreal the API from QPlainTextEdit only allows it
// to be set as an int. A work around is to access directly the QTextOption.
qreal charWidth = QFontMetricsF(font()).width(QLatin1Char(' '));
QTextOption option = document()->defaultTextOption();
option.setTabStop(charWidth * ts.m_tabSize);
document()->setDefaultTextOption(option);
}
void BaseTextEditorWidget::setDisplaySettings(const DisplaySettings &ds)
{
setLineWrapMode(ds.m_textWrapping ? QPlainTextEdit::WidgetWidth : QPlainTextEdit::NoWrap);
......@@ -6306,6 +6295,16 @@ void BaseTextEditorWidget::handleBlockSelection(int diff_row, int diff_col)
}
void BaseTextEditorWidget::updateTabStops()
{
// Although the tab stop is stored as qreal the API from QPlainTextEdit only allows it
// to be set as an int. A work around is to access directly the QTextOption.
qreal charWidth = QFontMetricsF(font()).width(QLatin1Char(' '));
QTextOption option = document()->defaultTextOption();
option.setTabStop(charWidth * d->m_document->tabSettings().m_tabSize);
document()->setDefaultTextOption(option);
}
int BaseTextEditorWidget::columnCount() const
{
QFontMetricsF fm(font());
......
......@@ -414,7 +414,6 @@ public slots:
virtual void unCommentSelection();
virtual void setFontSettings(const TextEditor::FontSettings &);
void setFontSettingsIfVisible(const TextEditor::FontSettings &);
virtual void setTabSettings(const TextEditor::TabSettings &);
virtual void setDisplaySettings(const TextEditor::DisplaySettings &);
virtual void setMarginSettings(const TextEditor::MarginSettings &);
virtual void setBehaviorSettings(const TextEditor::BehaviorSettings &);
......@@ -547,6 +546,7 @@ private:
private slots:
void handleBlockSelection(int diff_row, int diff_col);
void updateTabStops();
// parentheses matcher
void _q_matchParentheses();
......
......@@ -58,14 +58,14 @@ PlainTextEditor::PlainTextEditor(PlainTextEditorWidget *editor)
}
PlainTextEditorWidget::PlainTextEditorWidget(QWidget *parent)
: BaseTextEditorWidget(parent)
: BaseTextEditorWidget(new PlainTextDocument(), parent)
{
// Currently only "normal" indentation is supported.
baseTextDocument()->setIndenter(new NormalIndenter);
ctor();
}
PlainTextEditorWidget::PlainTextEditorWidget(BaseTextDocument *doc, QWidget *parent)
PlainTextEditorWidget::PlainTextEditorWidget(PlainTextDocument *doc, QWidget *parent)
: BaseTextEditorWidget(doc, parent)
{
ctor();
......@@ -111,17 +111,6 @@ void PlainTextEditorWidget::unCommentSelection()
Utils::unCommentSelection(this, m_commentDefinition);
}
void PlainTextEditorWidget::setTabSettings(const TextEditor::TabSettings &ts)
{
BaseTextEditorWidget::setTabSettings(ts);
if (baseTextDocument()->syntaxHighlighter()) {
Highlighter *highlighter =
static_cast<Highlighter *>(baseTextDocument()->syntaxHighlighter());
highlighter->setTabSettings(ts);
}
}
void PlainTextEditorWidget::configure()
{
MimeType mimeType;
......@@ -188,4 +177,15 @@ void PlainTextEditorWidget::acceptMissingSyntaxDefinitionInfo()
Constants::TEXT_EDITOR_HIGHLIGHTER_SETTINGS);
}
PlainTextDocument::PlainTextDocument()
{
connect(this, SIGNAL(tabSettingsChanged()), this, SLOT(updateTabSettings()));
}
void PlainTextDocument::updateTabSettings()
{
if (Highlighter *highlighter = qobject_cast<Highlighter *>(syntaxHighlighter()))
highlighter->setTabSettings(tabSettings());
}
} // namespace TextEditor
......@@ -54,13 +54,22 @@ public:
Core::Id id() const;
};
class TEXTEDITOR_EXPORT PlainTextDocument : public BaseTextDocument
{
Q_OBJECT
public:
PlainTextDocument();
private slots:
void updateTabSettings();
};
class TEXTEDITOR_EXPORT PlainTextEditorWidget : public BaseTextEditorWidget
{
Q_OBJECT
public:
PlainTextEditorWidget(QWidget *parent = 0);
PlainTextEditorWidget(BaseTextDocument *doc, QWidget *parent = 0);
PlainTextEditorWidget(PlainTextDocument *doc, QWidget *parent = 0);
PlainTextEditorWidget(PlainTextEditorWidget *other);
void configure(const QString& mimeType);
......@@ -69,7 +78,6 @@ public:
public slots:
virtual void unCommentSelection();
virtual void setTabSettings(const TextEditor::TabSettings &);
private slots:
void configure();
......@@ -83,6 +91,7 @@ protected:
private:
PlainTextEditorWidget(TextEditor::BaseTextEditorWidget *); // avoid stupidity
PlainTextEditorWidget(BaseTextDocument *, QWidget *); //avoid stupidity
void ctor();
bool m_isMissingSyntaxDefinition;
......
......@@ -356,9 +356,9 @@ void TextEditorSettings::initializeEditor(BaseTextEditorWidget *editor)
connect(editor, SIGNAL(requestZoomReset()),
m_instance, SLOT(zoomResetRequested()));
// Apply current settings (tab settings depend on font settings)
// Apply current settings
editor->setFontSettings(fontSettings());
editor->setTabSettings(codeStyle()->tabSettings());
editor->baseTextDocument()->setTabSettings(codeStyle()->tabSettings()); // also set through code style ???
editor->setTypingSettings(typingSettings());
editor->setStorageSettings(storageSettings());
editor->setBehaviorSettings(behaviorSettings());
......
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