summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJarek Kobus <jkobus@trolltech.com>2011-08-04 11:19:25 +0200
committerJarek Kobus <jaroslaw.kobus@nokia.com>2011-08-05 10:29:41 +0200
commit0c8df0597fd84068d535bc459e0694b1ccf87189 (patch)
tree0773109beeaf7edeb579be53c6426efcdbc74136
parent55f0f64a5dbba40442efc34a1868d428a66298ff (diff)
downloadqt-creator-0c8df0597fd84068d535bc459e0694b1ccf87189.tar.gz
Refactor: Get rid of BaseTextEditorWidget from Indenter
Provide directly TabSettings instead. This will be used for indenting a text for which there is no editor instance. Change-Id: Ia5f11a481f42464cf4820efdf2c7c4c32166f55e Reviewed-on: http://codereview.qt.nokia.com/2622 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Leandro T. C. Melo <leandro.melo@nokia.com>
-rw-r--r--src/plugins/cpptools/cppqtstyleindenter.cpp21
-rw-r--r--src/plugins/cpptools/cppqtstyleindenter.h4
-rw-r--r--src/plugins/fakevim/fakevimplugin.cpp5
-rw-r--r--src/plugins/glsleditor/glslindenter.cpp21
-rw-r--r--src/plugins/glsleditor/glslindenter.h4
-rw-r--r--src/plugins/qmljstools/qmljsindenter.cpp11
-rw-r--r--src/plugins/qmljstools/qmljsindenter.h2
-rw-r--r--src/plugins/texteditor/basetexteditor.cpp4
-rw-r--r--src/plugins/texteditor/indenter.cpp32
-rw-r--r--src/plugins/texteditor/indenter.h8
-rw-r--r--src/plugins/texteditor/normalindenter.cpp6
-rw-r--r--src/plugins/texteditor/normalindenter.h2
12 files changed, 53 insertions, 67 deletions
diff --git a/src/plugins/cpptools/cppqtstyleindenter.cpp b/src/plugins/cpptools/cppqtstyleindenter.cpp
index 3bcbe813c2..64ac333e96 100644
--- a/src/plugins/cpptools/cppqtstyleindenter.cpp
+++ b/src/plugins/cpptools/cppqtstyleindenter.cpp
@@ -36,7 +36,6 @@
#include "cpptoolssettings.h"
#include "cppcodestylepreferences.h"
#include "cpptoolsconstants.h"
-#include <texteditor/basetexteditor.h>
#include <texteditor/tabsettings.h>
#include <texteditor/texteditorsettings.h>
@@ -93,12 +92,11 @@ static bool colonIsElectric(const QString &text)
void CppQtStyleIndenter::indentBlock(QTextDocument *doc,
const QTextBlock &block,
const QChar &typedChar,
- TextEditor::BaseTextEditorWidget *editor)
+ const TextEditor::TabSettings &tabSettings)
{
Q_UNUSED(doc)
- const TextEditor::TabSettings &ts = editor->tabSettings();
- CppTools::QtStyleCodeFormatter codeFormatter(ts, codeStyleSettings());
+ CppTools::QtStyleCodeFormatter codeFormatter(tabSettings, codeStyleSettings());
codeFormatter.updateStateUntil(block);
int indent;
@@ -115,39 +113,38 @@ void CppQtStyleIndenter::indentBlock(QTextDocument *doc,
int newlineIndent;
int newlinePadding;
codeFormatter.indentForNewLineAfter(block.previous(), &newlineIndent, &newlinePadding);
- if (ts.indentationColumn(block.text()) != newlineIndent + newlinePadding)
+ if (tabSettings.indentationColumn(block.text()) != newlineIndent + newlinePadding)
return;
}
- ts.indentLine(block, indent + padding, padding);
+ tabSettings.indentLine(block, indent + padding, padding);
}
void CppQtStyleIndenter::indent(QTextDocument *doc,
const QTextCursor &cursor,
const QChar &typedChar,
- TextEditor::BaseTextEditorWidget *editor)
+ const TextEditor::TabSettings &tabSettings)
{
if (cursor.hasSelection()) {
QTextBlock block = doc->findBlock(cursor.selectionStart());
const QTextBlock end = doc->findBlock(cursor.selectionEnd()).next();
- const TextEditor::TabSettings &ts = editor->tabSettings();
- CppTools::QtStyleCodeFormatter codeFormatter(ts, codeStyleSettings());
+ CppTools::QtStyleCodeFormatter codeFormatter(tabSettings, codeStyleSettings());
codeFormatter.updateStateUntil(block);
- QTextCursor tc = editor->textCursor();
+ QTextCursor tc = cursor;
tc.beginEditBlock();
do {
int indent;
int padding;
codeFormatter.indentFor(block, &indent, &padding);
- ts.indentLine(block, indent + padding, padding);
+ tabSettings.indentLine(block, indent + padding, padding);
codeFormatter.updateLineStateChange(block);
block = block.next();
} while (block.isValid() && block != end);
tc.endEditBlock();
} else {
- indentBlock(doc, cursor.block(), typedChar, editor);
+ indentBlock(doc, cursor.block(), typedChar, tabSettings);
}
}
diff --git a/src/plugins/cpptools/cppqtstyleindenter.h b/src/plugins/cpptools/cppqtstyleindenter.h
index a544e8b304..deeb5a11c5 100644
--- a/src/plugins/cpptools/cppqtstyleindenter.h
+++ b/src/plugins/cpptools/cppqtstyleindenter.h
@@ -54,12 +54,12 @@ public:
virtual void indentBlock(QTextDocument *doc,
const QTextBlock &block,
const QChar &typedChar,
- TextEditor::BaseTextEditorWidget *editor);
+ const TextEditor::TabSettings &tabSettings);
virtual void indent(QTextDocument *doc,
const QTextCursor &cursor,
const QChar &typedChar,
- TextEditor::BaseTextEditorWidget *editor);
+ const TextEditor::TabSettings &tabSettings);
virtual void setCodeStylePreferences(TextEditor::IFallbackPreferences *preferences);
private:
diff --git a/src/plugins/fakevim/fakevimplugin.cpp b/src/plugins/fakevim/fakevimplugin.cpp
index 1d6c7e56ef..87babf502a 100644
--- a/src/plugins/fakevim/fakevimplugin.cpp
+++ b/src/plugins/fakevim/fakevimplugin.cpp
@@ -1673,7 +1673,6 @@ void FakeVimPluginPrivate::indentRegion(int beginLine, int endLine,
tabSettings.m_indentSize = theFakeVimSetting(ConfigShiftWidth)->value().toInt();
tabSettings.m_tabSize = theFakeVimSetting(ConfigTabStop)->value().toInt();
tabSettings.m_spacesForTabs = theFakeVimSetting(ConfigExpandTab)->value().toBool();
- bt->setTabSettings(tabSettings);
QTextDocument *doc = bt->document();
QTextBlock startBlock = doc->findBlockByNumber(beginLine);
@@ -1690,12 +1689,10 @@ void FakeVimPluginPrivate::indentRegion(int beginLine, int endLine,
while (!cursor.atBlockEnd())
cursor.deleteChar();
} else {
- bt->indenter()->indentBlock(doc, block, typedChar, bt);
+ bt->indenter()->indentBlock(doc, block, typedChar, tabSettings);
}
block = block.next();
}
-
- bt->setTabSettings(oldTabSettings);
}
void FakeVimPluginPrivate::quitFakeVim()
diff --git a/src/plugins/glsleditor/glslindenter.cpp b/src/plugins/glsleditor/glslindenter.cpp
index 1180764c17..ea39a47eb9 100644
--- a/src/plugins/glsleditor/glslindenter.cpp
+++ b/src/plugins/glsleditor/glslindenter.cpp
@@ -35,7 +35,6 @@
#include <cpptools/cppcodeformatter.h>
#include <cpptools/cpptoolssettings.h>
#include <cpptools/cppcodestylepreferences.h>
-#include <texteditor/basetexteditor.h>
#include <texteditor/tabsettings.h>
#include <QtCore/QChar>
@@ -66,13 +65,12 @@ bool GLSLIndenter::isElectricCharacter(const QChar &ch) const
void GLSLIndenter::indentBlock(QTextDocument *doc,
const QTextBlock &block,
const QChar &typedChar,
- TextEditor::BaseTextEditorWidget *editor)
+ const TextEditor::TabSettings &tabSettings)
{
Q_UNUSED(doc)
- const TextEditor::TabSettings &ts = editor->tabSettings();
// TODO: do something with it
- CppTools::QtStyleCodeFormatter codeFormatter(ts,
+ CppTools::QtStyleCodeFormatter codeFormatter(tabSettings,
CppTools::CppToolsSettings::instance()->cppCodeStylePreferences()->settings());
codeFormatter.updateStateUntil(block);
@@ -86,40 +84,39 @@ void GLSLIndenter::indentBlock(QTextDocument *doc,
int newlineIndent;
int newlinePadding;
codeFormatter.indentForNewLineAfter(block.previous(), &newlineIndent, &newlinePadding);
- if (ts.indentationColumn(block.text()) != newlineIndent + newlinePadding)
+ if (tabSettings.indentationColumn(block.text()) != newlineIndent + newlinePadding)
return;
}
- ts.indentLine(block, indent + padding, padding);
+ tabSettings.indentLine(block, indent + padding, padding);
}
void GLSLIndenter::indent(QTextDocument *doc,
const QTextCursor &cursor,
const QChar &typedChar,
- TextEditor::BaseTextEditorWidget *editor)
+ const TextEditor::TabSettings &tabSettings)
{
if (cursor.hasSelection()) {
QTextBlock block = doc->findBlock(cursor.selectionStart());
const QTextBlock end = doc->findBlock(cursor.selectionEnd()).next();
- const TextEditor::TabSettings &ts = editor->tabSettings();
// TODO: do something with it
- CppTools::QtStyleCodeFormatter codeFormatter(ts,
+ CppTools::QtStyleCodeFormatter codeFormatter(tabSettings,
CppTools::CppToolsSettings::instance()->cppCodeStylePreferences()->settings());
codeFormatter.updateStateUntil(block);
- QTextCursor tc = editor->textCursor();
+ QTextCursor tc = cursor;
tc.beginEditBlock();
do {
int indent;
int padding;
codeFormatter.indentFor(block, &indent, &padding);
- ts.indentLine(block, indent + padding, padding);
+ tabSettings.indentLine(block, indent + padding, padding);
codeFormatter.updateLineStateChange(block);
block = block.next();
} while (block.isValid() && block != end);
tc.endEditBlock();
} else {
- indentBlock(doc, cursor.block(), typedChar, editor);
+ indentBlock(doc, cursor.block(), typedChar, tabSettings);
}
}
diff --git a/src/plugins/glsleditor/glslindenter.h b/src/plugins/glsleditor/glslindenter.h
index bf28a5781f..a1d89c59a9 100644
--- a/src/plugins/glsleditor/glslindenter.h
+++ b/src/plugins/glsleditor/glslindenter.h
@@ -48,12 +48,12 @@ public:
virtual void indentBlock(QTextDocument *doc,
const QTextBlock &block,
const QChar &typedChar,
- TextEditor::BaseTextEditorWidget *editor);
+ const TextEditor::TabSettings &tabSettings);
virtual void indent(QTextDocument *doc,
const QTextCursor &cursor,
const QChar &typedChar,
- TextEditor::BaseTextEditorWidget *editor);
+ const TextEditor::TabSettings &tabSettings);
};
} // Internal
diff --git a/src/plugins/qmljstools/qmljsindenter.cpp b/src/plugins/qmljstools/qmljsindenter.cpp
index 97f641a734..1691eb40ff 100644
--- a/src/plugins/qmljstools/qmljsindenter.cpp
+++ b/src/plugins/qmljstools/qmljsindenter.cpp
@@ -33,7 +33,6 @@
#include "qmljsindenter.h"
#include <qmljstools/qmljsqtstylecodeformatter.h>
-#include <texteditor/basetexteditor.h>
#include <texteditor/tabsettings.h>
#include <QtCore/QChar>
@@ -63,13 +62,11 @@ bool Indenter::isElectricCharacter(const QChar &ch) const
void Indenter::indentBlock(QTextDocument *doc,
const QTextBlock &block,
const QChar &typedChar,
- TextEditor::BaseTextEditorWidget *editor)
+ const TextEditor::TabSettings &tabSettings)
{
Q_UNUSED(doc)
- Q_UNUSED(editor)
- const TextEditor::TabSettings &ts = editor->tabSettings();
- QmlJSTools::QtStyleCodeFormatter codeFormatter(ts);
+ QmlJSTools::QtStyleCodeFormatter codeFormatter(tabSettings);
codeFormatter.updateStateUntil(block);
const int depth = codeFormatter.indentFor(block);
@@ -78,9 +75,9 @@ void Indenter::indentBlock(QTextDocument *doc,
// only reindent the current line when typing electric characters if the
// indent is the same it would be if the line were empty
const int newlineIndent = codeFormatter.indentForNewLineAfter(block.previous());
- if (ts.indentationColumn(block.text()) != newlineIndent)
+ if (tabSettings.indentationColumn(block.text()) != newlineIndent)
return;
}
- ts.indentLine(block, depth);
+ tabSettings.indentLine(block, depth);
}
diff --git a/src/plugins/qmljstools/qmljsindenter.h b/src/plugins/qmljstools/qmljsindenter.h
index da29d56ece..f61617b3c2 100644
--- a/src/plugins/qmljstools/qmljsindenter.h
+++ b/src/plugins/qmljstools/qmljsindenter.h
@@ -50,7 +50,7 @@ public:
virtual void indentBlock(QTextDocument *doc,
const QTextBlock &block,
const QChar &typedChar,
- TextEditor::BaseTextEditorWidget *editor);
+ const TextEditor::TabSettings &tabSettings);
};
} // Internal
diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp
index 4eb148e3fd..3c84096a5c 100644
--- a/src/plugins/texteditor/basetexteditor.cpp
+++ b/src/plugins/texteditor/basetexteditor.cpp
@@ -4611,13 +4611,13 @@ void BaseTextEditorWidget::indentInsertedText(const QTextCursor &tc)
void BaseTextEditorWidget::indent(QTextDocument *doc, const QTextCursor &cursor, QChar typedChar)
{
maybeClearSomeExtraSelections(cursor);
- d->m_indenter->indent(doc, cursor, typedChar, this);
+ d->m_indenter->indent(doc, cursor, typedChar, tabSettings());
}
void BaseTextEditorWidget::reindent(QTextDocument *doc, const QTextCursor &cursor)
{
maybeClearSomeExtraSelections(cursor);
- d->m_indenter->reindent(doc, cursor, this);
+ d->m_indenter->reindent(doc, cursor, tabSettings());
}
BaseTextEditorWidget::Link BaseTextEditorWidget::findLinkAt(const QTextCursor &, bool)
diff --git a/src/plugins/texteditor/indenter.cpp b/src/plugins/texteditor/indenter.cpp
index 02e24e390e..cb85c6a4d5 100644
--- a/src/plugins/texteditor/indenter.cpp
+++ b/src/plugins/texteditor/indenter.cpp
@@ -31,9 +31,11 @@
**************************************************************************/
#include "indenter.h"
-#include "basetexteditor.h"
#include "tabsettings.h"
+#include <QtGui/QTextDocument>
+#include <QtGui/QTextCursor>
+
using namespace TextEditor;
Indenter::Indenter()
@@ -50,60 +52,58 @@ bool Indenter::isElectricCharacter(const QChar &) const
void Indenter::indentBlock(QTextDocument *doc,
const QTextBlock &block,
const QChar &typedChar,
- BaseTextEditorWidget *editor)
+ const TextEditor::TabSettings &tabSettings)
{
Q_UNUSED(doc);
Q_UNUSED(block);
Q_UNUSED(typedChar);
- Q_UNUSED(editor);
+ Q_UNUSED(tabSettings);
}
void Indenter::indent(QTextDocument *doc,
const QTextCursor &cursor,
const QChar &typedChar,
- BaseTextEditorWidget *editor)
+ const TextEditor::TabSettings &tabSettings)
{
if (cursor.hasSelection()) {
QTextBlock block = doc->findBlock(cursor.selectionStart());
const QTextBlock end = doc->findBlock(cursor.selectionEnd()).next();
do {
- indentBlock(doc, block, typedChar, editor);
+ indentBlock(doc, block, typedChar, tabSettings);
block = block.next();
} while (block.isValid() && block != end);
} else {
- indentBlock(doc, cursor.block(), typedChar, editor);
+ indentBlock(doc, cursor.block(), typedChar, tabSettings);
}
}
-void Indenter::reindent(QTextDocument *doc, const QTextCursor &cursor, BaseTextEditorWidget *editor)
+void Indenter::reindent(QTextDocument *doc, const QTextCursor &cursor, const TextEditor::TabSettings &tabSettings)
{
if (cursor.hasSelection()) {
QTextBlock block = doc->findBlock(cursor.selectionStart());
const QTextBlock end = doc->findBlock(cursor.selectionEnd()).next();
- const TabSettings &ts = editor->tabSettings();
-
// skip empty blocks
while (block.isValid() && block != end) {
QString bt = block.text();
- if (ts.firstNonSpace(bt) < bt.size())
+ if (tabSettings.firstNonSpace(bt) < bt.size())
break;
- indentBlock(doc, block, QChar::Null, editor);
+ indentBlock(doc, block, QChar::Null, tabSettings);
block = block.next();
}
- int previousIndentation = ts.indentationColumn(block.text());
- indentBlock(doc, block, QChar::Null, editor);
- int currentIndentation = ts.indentationColumn(block.text());
+ int previousIndentation = tabSettings.indentationColumn(block.text());
+ indentBlock(doc, block, QChar::Null, tabSettings);
+ int currentIndentation = tabSettings.indentationColumn(block.text());
int delta = currentIndentation - previousIndentation;
block = block.next();
while (block.isValid() && block != end) {
- ts.reindentLine(block, delta);
+ tabSettings.reindentLine(block, delta);
block = block.next();
}
} else {
- indentBlock(doc, cursor.block(), QChar::Null, editor);
+ indentBlock(doc, cursor.block(), QChar::Null, tabSettings);
}
}
diff --git a/src/plugins/texteditor/indenter.h b/src/plugins/texteditor/indenter.h
index 2f32c78e77..7d571a3f36 100644
--- a/src/plugins/texteditor/indenter.h
+++ b/src/plugins/texteditor/indenter.h
@@ -46,8 +46,8 @@ QT_END_NAMESPACE
namespace TextEditor {
-class BaseTextEditorWidget;
class IFallbackPreferences;
+class TabSettings;
class TEXTEDITOR_EXPORT Indenter
{
@@ -62,17 +62,17 @@ public:
virtual void indentBlock(QTextDocument *doc,
const QTextBlock &block,
const QChar &typedChar,
- BaseTextEditorWidget *editor);
+ const TabSettings &tabSettings);
// Indent at cursor. Calls indentBlock for selection or current line.
virtual void indent(QTextDocument *doc,
const QTextCursor &cursor,
const QChar &typedChar,
- BaseTextEditorWidget *editor);
+ const TabSettings &tabSettings);
// Reindent at cursor. Selection will be adjusted according to the indentation
// change of the first block.
- virtual void reindent(QTextDocument *doc, const QTextCursor &cursor, BaseTextEditorWidget *editor);
+ virtual void reindent(QTextDocument *doc, const QTextCursor &cursor, const TabSettings &tabSettings);
virtual void setCodeStylePreferences(IFallbackPreferences *preferences);
};
diff --git a/src/plugins/texteditor/normalindenter.cpp b/src/plugins/texteditor/normalindenter.cpp
index b0ebb3e4a7..a625e95e5d 100644
--- a/src/plugins/texteditor/normalindenter.cpp
+++ b/src/plugins/texteditor/normalindenter.cpp
@@ -32,7 +32,6 @@
#include "normalindenter.h"
#include "tabsettings.h"
-#include "basetexteditor.h"
#include <QtGui/QTextDocument>
@@ -66,7 +65,7 @@ NormalIndenter::~NormalIndenter()
void NormalIndenter::indentBlock(QTextDocument *doc,
const QTextBlock &block,
const QChar &typedChar,
- BaseTextEditorWidget *editor)
+ const TextEditor::TabSettings &tabSettings)
{
Q_UNUSED(typedChar)
@@ -82,11 +81,10 @@ void NormalIndenter::indentBlock(QTextDocument *doc,
// Just use previous line.
// Skip blank characters when determining the indentation
- const TabSettings &ts = editor->tabSettings();
int i = 0;
while (i < previousText.size()) {
if (!previousText.at(i).isSpace()) {
- ts.indentLine(block, ts.columnAt(previousText, i));
+ tabSettings.indentLine(block, tabSettings.columnAt(previousText, i));
break;
}
++i;
diff --git a/src/plugins/texteditor/normalindenter.h b/src/plugins/texteditor/normalindenter.h
index 413f8e72e9..07cee38730 100644
--- a/src/plugins/texteditor/normalindenter.h
+++ b/src/plugins/texteditor/normalindenter.h
@@ -46,7 +46,7 @@ public:
virtual void indentBlock(QTextDocument *doc,
const QTextBlock &block,
const QChar &typedChar,
- BaseTextEditorWidget *editor);
+ const TextEditor::TabSettings &tabSettings);
};
} // namespace TextEditor