TextEditors: Remove widget's setTabSettings method

Change-Id: If212b45e2d526534b7853f3fa23b170f61e1976e
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
Eike Ziller
2014-01-17 17:09:15 +01:00
parent f506104f29
commit 4eff289e03
16 changed files with 102 additions and 62 deletions

View File

@@ -41,7 +41,7 @@ using namespace Android::Internal;
AndroidManifestDocument::AndroidManifestDocument(AndroidManifestEditorWidget *editorWidget) AndroidManifestDocument::AndroidManifestDocument(AndroidManifestEditorWidget *editorWidget)
: TextEditor::BaseTextDocument(), : TextEditor::PlainTextDocument(),
m_editorWidget(editorWidget) m_editorWidget(editorWidget)
{ {
setMimeType(QLatin1String(Constants::ANDROID_MANIFEST_MIME_TYPE)); setMimeType(QLatin1String(Constants::ANDROID_MANIFEST_MIME_TYPE));

View File

@@ -31,13 +31,13 @@
#define ANDROIDMANIFESTDOCUMENT_H #define ANDROIDMANIFESTDOCUMENT_H
#include <coreplugin/textdocument.h> #include <coreplugin/textdocument.h>
#include <texteditor/basetextdocument.h> #include <texteditor/plaintexteditor.h>
namespace Android { namespace Android {
namespace Internal { namespace Internal {
class AndroidManifestEditorWidget; class AndroidManifestEditorWidget;
class AndroidManifestDocument : public TextEditor::BaseTextDocument class AndroidManifestDocument : public TextEditor::PlainTextDocument
{ {
public: public:
explicit AndroidManifestDocument(AndroidManifestEditorWidget *editorWidget); explicit AndroidManifestDocument(AndroidManifestEditorWidget *editorWidget);

View File

@@ -512,7 +512,7 @@ CPPEditor::CPPEditor(CPPEditorWidget *editor)
Q_GLOBAL_STATIC(CppTools::SymbolFinder, symbolFinder) Q_GLOBAL_STATIC(CppTools::SymbolFinder, symbolFinder)
CPPEditorWidget::CPPEditorWidget(QWidget *parent) CPPEditorWidget::CPPEditorWidget(QWidget *parent)
: TextEditor::BaseTextEditorWidget(parent) : TextEditor::BaseTextEditorWidget(new CPPEditorDocument(), parent)
{ {
baseTextDocument()->setIndenter(new CppTools::CppQtStyleIndenter); baseTextDocument()->setIndenter(new CppTools::CppQtStyleIndenter);
ctor(); ctor();
@@ -1583,14 +1583,6 @@ void CPPEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
highlighter->rehighlight(); highlighter->rehighlight();
} }
void CPPEditorWidget::setTabSettings(const TextEditor::TabSettings &ts)
{
CppTools::QtStyleCodeFormatter formatter;
formatter.invalidateCache(document());
TextEditor::BaseTextEditorWidget::setTabSettings(ts);
}
void CPPEditorWidget::unCommentSelection() void CPPEditorWidget::unCommentSelection()
{ {
Utils::unCommentSelection(this); 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> #include <cppeditor.moc>

View File

@@ -71,6 +71,16 @@ namespace Internal {
class CPPEditorWidget; class CPPEditorWidget;
class CPPEditorDocument : public TextEditor::BaseTextDocument
{
Q_OBJECT
public:
CPPEditorDocument();
private slots:
void invalidateFormatterCache();
};
class CPPEditor : public TextEditor::BaseTextEditor class CPPEditor : public TextEditor::BaseTextEditor
{ {
Q_OBJECT Q_OBJECT
@@ -136,7 +146,6 @@ Q_SIGNALS:
public Q_SLOTS: public Q_SLOTS:
virtual void setFontSettings(const TextEditor::FontSettings &); virtual void setFontSettings(const TextEditor::FontSettings &);
virtual void setTabSettings(const TextEditor::TabSettings &);
void setSortedOutline(bool sort); void setSortedOutline(bool sort);
void switchDeclarationDefinition(bool inNextSplit); void switchDeclarationDefinition(bool inNextSplit);
void renameSymbolUnderCursor(); void renameSymbolUnderCursor();

View File

@@ -465,7 +465,7 @@ void CppCodeStylePreferencesWidget::updatePreview()
const TextEditor::TabSettings ts = cppCodeStylePreferences->currentTabSettings(); const TextEditor::TabSettings ts = cppCodeStylePreferences->currentTabSettings();
QtStyleCodeFormatter formatter(ts, ccss); QtStyleCodeFormatter formatter(ts, ccss);
foreach (TextEditor::SnippetEditorWidget *preview, m_previews) { foreach (TextEditor::SnippetEditorWidget *preview, m_previews) {
preview->setTabSettings(ts); preview->baseTextDocument()->setTabSettings(ts);
preview->setCodeStyle(cppCodeStylePreferences); preview->setCodeStyle(cppCodeStylePreferences);
QTextDocument *doc = preview->document(); QTextDocument *doc = preview->document();

View File

@@ -30,7 +30,7 @@
#ifndef FORMWINDOWFILE_H #ifndef FORMWINDOWFILE_H
#define FORMWINDOWFILE_H #define FORMWINDOWFILE_H
#include <texteditor/basetextdocument.h> #include <texteditor/plaintexteditor.h>
#include <QPointer> #include <QPointer>
@@ -42,7 +42,7 @@ QT_END_NAMESPACE
namespace Designer { namespace Designer {
namespace Internal { namespace Internal {
class FormWindowFile : public TextEditor::BaseTextDocument class FormWindowFile : public TextEditor::PlainTextDocument
{ {
Q_OBJECT Q_OBJECT

View File

@@ -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 } // namespace QmlJSEditor
class QtQuickToolbarMarker {}; class QtQuickToolbarMarker {};
@@ -1286,14 +1298,6 @@ void QmlJSTextEditorWidget::unCommentSelection()
Utils::unCommentSelection(this); Utils::unCommentSelection(this);
} }
void QmlJSTextEditorWidget::setTabSettings(const TextEditor::TabSettings &ts)
{
QmlJSTools::CreatorCodeFormatter formatter(ts);
formatter.invalidateCache(document());
TextEditor::BaseTextEditorWidget::setTabSettings(ts);
}
void QmlJSTextEditorWidget::updateSemanticInfo() void QmlJSTextEditorWidget::updateSemanticInfo()
{ {
// If the editor is newer than the future semantic info, new semantic infos // If the editor is newer than the future semantic info, new semantic infos

View File

@@ -73,6 +73,16 @@ class QmlOutlineModel;
class SemanticInfoUpdater; class SemanticInfoUpdater;
struct SemanticInfoUpdaterSource; struct SemanticInfoUpdaterSource;
class SemanticHighlighter; class SemanticHighlighter;
class QmlJSEditorDocument : public TextEditor::BaseTextDocument
{
Q_OBJECT
public:
QmlJSEditorDocument();
private slots:
void invalidateFormatterCache();
};
} // namespace Internal } // namespace Internal
struct QMLJSEDITOR_EXPORT Declaration struct QMLJSEDITOR_EXPORT Declaration
@@ -118,7 +128,6 @@ public:
TextEditor::IAssistInterface *createAssistInterface(TextEditor::AssistKind assistKind, TextEditor::IAssistInterface *createAssistInterface(TextEditor::AssistKind assistKind,
TextEditor::AssistReason reason) const; TextEditor::AssistReason reason) const;
public slots: public slots:
virtual void setTabSettings(const TextEditor::TabSettings &ts);
void reparseDocument(); void reparseDocument();
void reparseDocumentNow(); void reparseDocumentNow();
void updateSemanticInfo(); void updateSemanticInfo();

View File

@@ -131,7 +131,7 @@ void QmlJSCodeStylePreferencesWidget::updatePreview()
const TextEditor::TabSettings &ts = m_preferences const TextEditor::TabSettings &ts = m_preferences
? m_preferences->currentTabSettings() ? m_preferences->currentTabSettings()
: TextEditorSettings::codeStyle()->tabSettings(); : TextEditorSettings::codeStyle()->tabSettings();
m_ui->previewTextEdit->setTabSettings(ts); m_ui->previewTextEdit->baseTextDocument()->setTabSettings(ts);
CreatorCodeFormatter formatter(ts); CreatorCodeFormatter formatter(ts);
formatter.invalidateCache(doc); formatter.invalidateCache(doc);

View File

@@ -209,9 +209,12 @@ const StorageSettings &BaseTextDocument::storageSettings() const
return d->m_storageSettings; 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; d->m_tabSettings = tabSettings;
emit tabSettingsChanged();
} }
const TabSettings &BaseTextDocument::tabSettings() const const TabSettings &BaseTextDocument::tabSettings() const

View File

@@ -65,7 +65,6 @@ public:
void setTypingSettings(const TypingSettings &typingSettings); void setTypingSettings(const TypingSettings &typingSettings);
void setStorageSettings(const StorageSettings &storageSettings); void setStorageSettings(const StorageSettings &storageSettings);
void setTabSettings(const TabSettings &tabSettings);
void setExtraEncodingSettings(const ExtraEncodingSettings &extraEncodingSettings); void setExtraEncodingSettings(const ExtraEncodingSettings &extraEncodingSettings);
const TypingSettings &typingSettings() const; const TypingSettings &typingSettings() const;
@@ -111,8 +110,12 @@ public:
bool reload(QString *errorString, QTextCodec *codec); bool reload(QString *errorString, QTextCodec *codec);
void cleanWhitespace(const QTextCursor &cursor); void cleanWhitespace(const QTextCursor &cursor);
public slots:
void setTabSettings(const TextEditor::TabSettings &tabSettings);
signals: signals:
void mimeTypeChanged(); void mimeTypeChanged();
void tabSettingsChanged();
private: private:
void cleanWhitespace(QTextCursor &cursor, bool cleanIndentation, bool inEntireDocument); void cleanWhitespace(QTextCursor &cursor, bool cleanIndentation, bool inEntireDocument);

View File

@@ -2395,6 +2395,7 @@ void BaseTextEditorWidgetPrivate::setupDocumentSignals()
SLOT(editorContentsChange(int,int,int)), Qt::DirectConnection); SLOT(editorContentsChange(int,int,int)), Qt::DirectConnection);
QObject::connect(m_document.data(), SIGNAL(aboutToReload()), q, SLOT(documentAboutToBeReloaded())); 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(reloadFinished(bool)), q, SLOT(documentReloadFinished(bool)));
QObject::connect(m_document.data(), SIGNAL(tabSettingsChanged()), q, SLOT(updateTabStops()));
q->slotUpdateExtraAreaWidth(); q->slotUpdateExtraAreaWidth();
} }
@@ -4430,17 +4431,17 @@ void BaseTextEditorWidget::setCodeStyle(ICodeStylePreferences *preferences)
baseTextDocument()->indenter()->setCodeStylePreferences(preferences); baseTextDocument()->indenter()->setCodeStylePreferences(preferences);
if (d->m_codeStylePreferences) { if (d->m_codeStylePreferences) {
disconnect(d->m_codeStylePreferences, SIGNAL(currentTabSettingsChanged(TextEditor::TabSettings)), 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)), disconnect(d->m_codeStylePreferences, SIGNAL(currentValueChanged(QVariant)),
this, SLOT(slotCodeStyleSettingsChanged(QVariant))); this, SLOT(slotCodeStyleSettingsChanged(QVariant)));
} }
d->m_codeStylePreferences = preferences; d->m_codeStylePreferences = preferences;
if (d->m_codeStylePreferences) { if (d->m_codeStylePreferences) {
connect(d->m_codeStylePreferences, SIGNAL(currentTabSettingsChanged(TextEditor::TabSettings)), 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)), connect(d->m_codeStylePreferences, SIGNAL(currentValueChanged(QVariant)),
this, SLOT(slotCodeStyleSettingsChanged(QVariant))); this, SLOT(slotCodeStyleSettingsChanged(QVariant)));
setTabSettings(d->m_codeStylePreferences->currentTabSettings()); d->m_document->setTabSettings(d->m_codeStylePreferences->currentTabSettings());
slotCodeStyleSettingsChanged(d->m_codeStylePreferences->currentValue()); slotCodeStyleSettingsChanged(d->m_codeStylePreferences->currentValue());
} }
} }
@@ -5401,7 +5402,7 @@ void BaseTextEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
p.setBrush(QPalette::Inactive, QPalette::HighlightedText, p.highlightedText()); p.setBrush(QPalette::Inactive, QPalette::HighlightedText, p.highlightedText());
setPalette(p); setPalette(p);
setFont(font); 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 // Line numbers
QPalette ep = d->m_extraArea->palette(); 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) void BaseTextEditorWidget::setDisplaySettings(const DisplaySettings &ds)
{ {
setLineWrapMode(ds.m_textWrapping ? QPlainTextEdit::WidgetWidth : QPlainTextEdit::NoWrap); 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 int BaseTextEditorWidget::columnCount() const
{ {
QFontMetricsF fm(font()); QFontMetricsF fm(font());

View File

@@ -414,7 +414,6 @@ public slots:
virtual void unCommentSelection(); virtual void unCommentSelection();
virtual void setFontSettings(const TextEditor::FontSettings &); virtual void setFontSettings(const TextEditor::FontSettings &);
void setFontSettingsIfVisible(const TextEditor::FontSettings &); void setFontSettingsIfVisible(const TextEditor::FontSettings &);
virtual void setTabSettings(const TextEditor::TabSettings &);
virtual void setDisplaySettings(const TextEditor::DisplaySettings &); virtual void setDisplaySettings(const TextEditor::DisplaySettings &);
virtual void setMarginSettings(const TextEditor::MarginSettings &); virtual void setMarginSettings(const TextEditor::MarginSettings &);
virtual void setBehaviorSettings(const TextEditor::BehaviorSettings &); virtual void setBehaviorSettings(const TextEditor::BehaviorSettings &);
@@ -547,6 +546,7 @@ private:
private slots: private slots:
void handleBlockSelection(int diff_row, int diff_col); void handleBlockSelection(int diff_row, int diff_col);
void updateTabStops();
// parentheses matcher // parentheses matcher
void _q_matchParentheses(); void _q_matchParentheses();

View File

@@ -58,14 +58,14 @@ PlainTextEditor::PlainTextEditor(PlainTextEditorWidget *editor)
} }
PlainTextEditorWidget::PlainTextEditorWidget(QWidget *parent) PlainTextEditorWidget::PlainTextEditorWidget(QWidget *parent)
: BaseTextEditorWidget(parent) : BaseTextEditorWidget(new PlainTextDocument(), parent)
{ {
// Currently only "normal" indentation is supported. // Currently only "normal" indentation is supported.
baseTextDocument()->setIndenter(new NormalIndenter); baseTextDocument()->setIndenter(new NormalIndenter);
ctor(); ctor();
} }
PlainTextEditorWidget::PlainTextEditorWidget(BaseTextDocument *doc, QWidget *parent) PlainTextEditorWidget::PlainTextEditorWidget(PlainTextDocument *doc, QWidget *parent)
: BaseTextEditorWidget(doc, parent) : BaseTextEditorWidget(doc, parent)
{ {
ctor(); ctor();
@@ -111,17 +111,6 @@ void PlainTextEditorWidget::unCommentSelection()
Utils::unCommentSelection(this, m_commentDefinition); 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() void PlainTextEditorWidget::configure()
{ {
MimeType mimeType; MimeType mimeType;
@@ -188,4 +177,15 @@ void PlainTextEditorWidget::acceptMissingSyntaxDefinitionInfo()
Constants::TEXT_EDITOR_HIGHLIGHTER_SETTINGS); 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 } // namespace TextEditor

View File

@@ -54,13 +54,22 @@ public:
Core::Id id() const; Core::Id id() const;
}; };
class TEXTEDITOR_EXPORT PlainTextDocument : public BaseTextDocument
{
Q_OBJECT
public:
PlainTextDocument();
private slots:
void updateTabSettings();
};
class TEXTEDITOR_EXPORT PlainTextEditorWidget : public BaseTextEditorWidget class TEXTEDITOR_EXPORT PlainTextEditorWidget : public BaseTextEditorWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
PlainTextEditorWidget(QWidget *parent = 0); PlainTextEditorWidget(QWidget *parent = 0);
PlainTextEditorWidget(BaseTextDocument *doc, QWidget *parent = 0); PlainTextEditorWidget(PlainTextDocument *doc, QWidget *parent = 0);
PlainTextEditorWidget(PlainTextEditorWidget *other); PlainTextEditorWidget(PlainTextEditorWidget *other);
void configure(const QString& mimeType); void configure(const QString& mimeType);
@@ -69,7 +78,6 @@ public:
public slots: public slots:
virtual void unCommentSelection(); virtual void unCommentSelection();
virtual void setTabSettings(const TextEditor::TabSettings &);
private slots: private slots:
void configure(); void configure();
@@ -83,6 +91,7 @@ protected:
private: private:
PlainTextEditorWidget(TextEditor::BaseTextEditorWidget *); // avoid stupidity PlainTextEditorWidget(TextEditor::BaseTextEditorWidget *); // avoid stupidity
PlainTextEditorWidget(BaseTextDocument *, QWidget *); //avoid stupidity
void ctor(); void ctor();
bool m_isMissingSyntaxDefinition; bool m_isMissingSyntaxDefinition;

View File

@@ -356,9 +356,9 @@ void TextEditorSettings::initializeEditor(BaseTextEditorWidget *editor)
connect(editor, SIGNAL(requestZoomReset()), connect(editor, SIGNAL(requestZoomReset()),
m_instance, SLOT(zoomResetRequested())); m_instance, SLOT(zoomResetRequested()));
// Apply current settings (tab settings depend on font settings) // Apply current settings
editor->setFontSettings(fontSettings()); editor->setFontSettings(fontSettings());
editor->setTabSettings(codeStyle()->tabSettings()); editor->baseTextDocument()->setTabSettings(codeStyle()->tabSettings()); // also set through code style ???
editor->setTypingSettings(typingSettings()); editor->setTypingSettings(typingSettings());
editor->setStorageSettings(storageSettings()); editor->setStorageSettings(storageSettings());
editor->setBehaviorSettings(behaviorSettings()); editor->setBehaviorSettings(behaviorSettings());