Editor: Collect indentation for a list of text blocks

Allows the indenter to reuse code formatter structures.

Task-number: QTCREATORBUG-16420
Change-Id: Ie906d7fdcb50798da02ef5b750fb03ae752aadc1
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
David Schulz
2016-08-25 13:25:45 +02:00
parent b97bc4016f
commit 89ff2c1db5
9 changed files with 100 additions and 18 deletions

View File

@@ -186,3 +186,21 @@ CppCodeStyleSettings CppQtStyleIndenter::codeStyleSettings() const
return m_cppCodeStylePreferences->currentCodeStyleSettings();
return CppCodeStyleSettings();
}
TextEditor::IndentationForBlock
CppQtStyleIndenter::indentationForBlocks(const QVector<QTextBlock> &blocks,
const TextEditor::TabSettings &tabSettings)
{
QtStyleCodeFormatter codeFormatter(tabSettings, codeStyleSettings());
codeFormatter.updateStateUntil(blocks.last());
TextEditor::IndentationForBlock ret;
foreach (QTextBlock block, blocks) {
int indent;
int padding;
codeFormatter.indentFor(block, &indent, &padding);
ret.insert(block.blockNumber(), indent);
}
return ret;
}

View File

@@ -58,6 +58,8 @@ public:
void setCodeStylePreferences(TextEditor::ICodeStylePreferences *preferences) override;
void invalidateCache(QTextDocument *doc) override;
int indentFor(const QTextBlock &block, const TextEditor::TabSettings &tabSettings) override;
TextEditor::IndentationForBlock indentationForBlocks(const QVector<QTextBlock> &blocks,
const TextEditor::TabSettings &tabSettings) override;
private:
CppCodeStyleSettings codeStyleSettings() const;
CppCodeStylePreferences *m_cppCodeStylePreferences;