Newer
Older
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "cppcodeformatter.h"
#include <Token.h>
#include <Lexer.h>
#include <texteditor/basetextdocumentlayout.h>
#include <texteditor/tabsettings.h>
#include <QtCore/QDebug>
#include <QtGui/QTextDocument>
#include <QtGui/QTextCursor>
#include <QtGui/QTextBlock>
using namespace CPlusPlus;
using namespace CppTools;
using namespace TextEditor;
using namespace CppTools::Internal;
CodeFormatter::BlockData::BlockData()
: m_blockRevision(-1)
{
}
: m_indentDepth(0)
, m_tabSize(4)
{
}
CodeFormatter::~CodeFormatter()
{
}
void CodeFormatter::setTabSize(int tabSize)
{
m_tabSize = tabSize;
}
void CodeFormatter::recalculateStateAfter(const QTextBlock &block)
{
restoreCurrentState(block.previous());
bool endedJoined = false;
const int lexerState = tokenizeBlock(block, &endedJoined);
m_tokenIndex = 0;
m_newStates.clear();
if (tokenAt(0).kind() == T_POUND) {
enter(cpp_macro_start);
m_tokenIndex = 1;
}
for (; m_tokenIndex < m_tokens.size(); ) {
m_currentToken = tokenAt(m_tokenIndex);
const int kind = m_currentToken.kind();
switch (m_currentState.top().type) {
case topmost_intro:
tryDeclaration();
break;
case namespace_start:
switch (kind) {
case T_LBRACE: enter(namespace_open); break;
case T_RBRACE: leave(); break;
} break;
case namespace_open:
if (tryDeclaration())
break;
switch (kind) {
case T_RBRACE: leave(); continue; // always nested in namespace_start
} break;
case class_start:
switch (kind) {
case T_SEMICOLON: leave(); break;
case T_LBRACE: enter(class_open); break;
} break;
case class_open:
if (tryDeclaration())
break;
switch (kind) {
case T_RBRACE: leave(); continue; // always nested in class_start
} break;
case enum_start:
switch (kind) {
case T_SEMICOLON: leave(); break;
case T_LBRACE: enter(enum_open); break;
} break;
case enum_open:
switch (kind) {
case T_RBRACE: leave(); continue; // always nested in enum_start
case T_LBRACE: enter(brace_list_open); break;
} break;
case brace_list_open:
switch (kind) {
case T_RBRACE: leave(); break;
case T_LBRACE: enter(brace_list_open); break;
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
} break;
case using_start:
switch (kind) {
case T_SEMICOLON: leave(); break;
} break;
case template_start:
switch (kind) {
case T_LESS: turnInto(template_param); break;
} break;
case template_param:
switch (kind) {
case T_LESS: enter(template_param); break;
case T_GREATER: leave(); break;
} break;
case operator_declaration:
switch (kind) {
case T_LPAREN: break;
default: leave(); break;
} break;
case declaration_start:
if (tryExpression(true))
break;
switch (kind) {
case T_RBRACE:
case T_SEMICOLON: leave(true); break;
case T_EQUAL: enter(initializer); break;
case T_LBRACE: enter(defun_open); break;
case T_COLON: enter(member_init_open); enter(member_init); break;
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
case T_OPERATOR: enter(operator_declaration); break;
} break;
case initializer:
switch (kind) {
case T_LBRACE: enter(brace_list_open); break;
default: turnInto(expression); continue;
} break;
case expression:
if (tryExpression())
break;
switch (kind) {
case T_SEMICOLON: leave(); continue;
case T_LBRACE:
case T_COLON:
if (m_currentState.at(m_currentState.size() - 2).type == declaration_start) {
// oops, the expression was a function declaration argument list, hand lbrace/colon to declaration_start
leave();
continue;
}
break;
} break;
case arglist_open:
if (tryExpression())
break;
switch (kind) {
case T_RPAREN: leave(); break;
} break;
case ternary_op:
if (tryExpression())
break;
switch (kind) {
case T_RPAREN:
case T_COMMA:
case T_SEMICOLON: leave(); continue; // always nested, propagate
} break;
case stream_op:
case stream_op_cont:
if (kind != T_LESS_LESS && kind != T_GREATER_GREATER && tryExpression())
case T_LESS_LESS:
case T_GREATER_GREATER:
if (m_currentState.top().type == stream_op)
enter(stream_op_cont);
else // stream_op_cont already
turnInto(stream_op_cont);
break;
case T_COMMA:
case T_SEMICOLON: leave(); continue; // always nested, propagate semicolon
} break;
case member_init_open:
switch (kind) {
case T_LBRACE: turnInto(defun_open); break;
case T_COMMA: enter(member_init); break;
case T_SEMICOLON: leave(); continue; // try to recover
} break;
case member_init:
switch (kind) {
case T_LPAREN: enter(member_init_paren_open); break;
case T_RPAREN: leave(); break;
case T_LBRACE:
case T_SEMICOLON: leave(); continue; // try to recover
} break;
case member_init_paren_open:
if (tryExpression())
break;
switch (kind) {
case T_RPAREN: leave(); continue;
case T_SEMICOLON: leave(); continue; // try to recover
} break;
case defun_open:
if (tryStatement())
break;
switch (kind) {
case T_RBRACE: leave(); continue; // always nested in declaration_start
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
} break;
case switch_statement:
case statement_with_condition:
case if_statement:
switch (kind) {
case T_LPAREN: enter(condition_open); break;
} break;
case maybe_else:
if (m_currentToken.isComment()) {
break;
} else if (kind == T_ELSE) {
turnInto(else_clause);
enter(substatement);
break;
} else {
leave(true);
continue;
}
case else_clause:
// ### shouldn't happen
dump();
Q_ASSERT(false);
leave(true);
break;
case do_statement:
// ### shouldn't happen
dump();
Q_ASSERT(false);
leave(true);
break;
case return_statement:
switch (kind) {
case T_SEMICOLON: leave(true); break;
} break;
case substatement:
// prefer substatement_open over block_open
if (kind != T_LBRACE && tryStatement())
break;
switch (kind) {
case T_LBRACE: turnInto(substatement_open); break;
case T_SEMICOLON: leave(true); break;
} break;
case for_statement:
switch (kind) {
case T_LPAREN: enter(for_statement_paren_open); break;
} break;
case for_statement_paren_open:
enter(for_statement_init); continue;
case for_statement_init:
switch (kind) {
case T_SEMICOLON: turnInto(for_statement_condition); break;
case T_LPAREN: enter(condition_paren_open); break;
} break;
case for_statement_condition:
switch (kind) {
case T_SEMICOLON: turnInto(for_statement_expression); break;
case T_LPAREN: enter(condition_paren_open); break;
} break;
case for_statement_expression:
switch (kind) {
case T_RPAREN: leave(); turnInto(substatement); break;
case T_LPAREN: enter(condition_paren_open); break;
} break;
case case_start:
switch (kind) {
case T_COLON: turnInto(case_cont); break;
} break;
case case_cont:
if (kind != T_CASE && kind != T_DEFAULT && tryStatement())
break;
switch (kind) {
case T_RBRACE: leave(); continue;
case T_DEFAULT:
case T_CASE: leave(); continue;
} break;
case substatement_open:
if (tryStatement())
break;
switch (kind) {
case T_RBRACE: leave(true); break;
} break;
case condition_open:
switch (kind) {
case T_RPAREN: turnInto(substatement); break;
case T_LPAREN: enter(condition_paren_open); break;
} break;
case block_open:
if (tryStatement())
break;
switch(kind) {
case T_RBRACE: leave(true); break;
} break;
// paren nesting
case condition_paren_open:
switch (kind) {
case T_RPAREN: leave(); break;
case T_LPAREN: enter(condition_paren_open); break;
} break;
case qt_like_macro:
switch (kind) {
case T_LPAREN: enter(arglist_open); break;
case T_SEMICOLON: leave(true); break;
default: leave(); continue;
} break;
case multiline_comment_start:
case multiline_comment_cont:
if (kind != T_COMMENT && kind != T_DOXY_COMMENT) {
leave();
continue;
} else if (m_tokenIndex == m_tokens.size() - 1
&& lexerState == Lexer::State_Default) {
leave();
} else if (m_tokenIndex == 0 && m_currentToken.isComment()) {
// to allow enter/leave to update the indentDepth
turnInto(multiline_comment_cont);
}
break;
case cpp_macro_start: {
const int size = m_currentState.size();
int previousMarker = -1;
int previousPreviousMarker = -1;
for (int i = size - 1; i >= 0; --i) {
if (m_currentState.at(i).type == cpp_macro_conditional) {
if (previousMarker == -1)
previousMarker = i;
else {
previousPreviousMarker = i;
break;
}
}
}
QStringRef tokenText = currentTokenText();
if (tokenText == QLatin1String("ifdef")
|| tokenText == QLatin1String("if")
|| tokenText == QLatin1String("ifndef")) {
enter(cpp_macro_conditional);
// copy everything right of previousMarker, excluding cpp_macro_conditional
for (int i = previousMarker + 1; i < size; ++i)
m_currentState += m_currentState.at(i);
}
if (previousMarker != -1) {
if (tokenText == QLatin1String("endif")) {
QStack<State>::iterator begin = m_currentState.begin() + previousPreviousMarker + 1;
QStack<State>::iterator end = m_currentState.begin() + previousMarker + 1;
m_currentState.erase(begin, end);
} else if (tokenText == QLatin1String("else")
|| tokenText == QLatin1String("elif")) {
m_currentState.resize(previousMarker + 1);
for (int i = previousPreviousMarker + 1; i < previousMarker; ++i)
m_currentState += m_currentState.at(i);
}
}
turnInto(cpp_macro);
break;
}
case cpp_macro:
case cpp_macro_cont:
break;
default:
qWarning() << "Unhandled state" << m_currentState.top().type;
break;
} // end of state switch
++m_tokenIndex;
}
int topState = m_currentState.top().type;
if (topState != multiline_comment_start
&& topState != multiline_comment_cont
&& (lexerState == Lexer::State_MultiLineComment
|| lexerState == Lexer::State_MultiLineDoxyComment)) {
enter(multiline_comment_start);
}
if (topState == qt_like_macro)
leave(true);
if ((topState == cpp_macro_cont
|| topState == cpp_macro) && !endedJoined)
leave();
if (topState == cpp_macro && endedJoined)
turnInto(cpp_macro_cont);
saveCurrentState(block);
}
int CodeFormatter::indentFor(const QTextBlock &block)
{
// qDebug() << "indenting for" << block.blockNumber() + 1;
restoreCurrentState(block.previous());
correctIndentation(block);
return m_indentDepth;
}
void CodeFormatter::updateStateUntil(const QTextBlock &endBlock)
{
QStack<State> previousState = initialState();
QTextBlock it = endBlock.document()->firstBlock();
// find the first block that needs recalculation
for (; it.isValid() && it != endBlock; it = it.next()) {
BlockData blockData;
if (!loadBlockData(it, &blockData))
if (blockData.m_blockRevision != it.revision())
if (previousState.isEmpty() || blockData.m_beginState.isEmpty()
|| previousState != blockData.m_beginState)
if (loadLexerState(it) == -1)
previousState = blockData.m_endState;
if (it == endBlock)
return;
// update everthing until endBlock
for (; it.isValid() && it != endBlock; it = it.next()) {
recalculateStateAfter(it);
}
// invalidate everything below by marking the state in endBlock as invalid
if (it.isValid()) {
BlockData invalidBlockData;
saveBlockData(&it, invalidBlockData);
}
}
void CodeFormatter::updateLineStateChange(const QTextBlock &block)
{
if (!block.isValid())
return;
BlockData blockData;
if (loadBlockData(block, &blockData) && blockData.m_blockRevision == block.revision())
return;
recalculateStateAfter(block);
// invalidate everything below by marking the next block's state as invalid
QTextBlock next = block.next();
if (!next.isValid())
return;
saveBlockData(&next, BlockData());
}
CodeFormatter::State CodeFormatter::state(int belowTop) const
{
if (belowTop < m_currentState.size())
return m_currentState.at(m_currentState.size() - 1 - belowTop);
else
return State();
}
const QVector<CodeFormatter::State> &CodeFormatter::newStatesThisLine() const
{
return m_newStates;
}
int CodeFormatter::tokenIndex() const
{
return m_tokenIndex;
}
int CodeFormatter::tokenCount() const
return m_tokens.size();
}
const CPlusPlus::Token &CodeFormatter::currentToken() const
{
return m_currentToken;
}
void CodeFormatter::invalidateCache(QTextDocument *document)
if (!document)
return;
BlockData invalidBlockData;
QTextBlock it = document->firstBlock();
for (; it.isValid(); it = it.next()) {
saveBlockData(&it, invalidBlockData);
}
}
void CodeFormatter::enter(int newState)
{
int savedIndentDepth = m_indentDepth;
onEnter(newState, &m_indentDepth, &savedIndentDepth);
State s(newState, savedIndentDepth);
m_currentState.push(s);
m_newStates.push(s);
}
void CodeFormatter::leave(bool statementDone)
{
Q_ASSERT(m_currentState.size() > 1);
if (m_currentState.top().type == topmost_intro)
return;
if (m_newStates.size() > 0)
m_newStates.pop();
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
// restore indent depth
State poppedState = m_currentState.pop();
m_indentDepth = poppedState.savedIndentDepth;
int topState = m_currentState.top().type;
// does it suffice to check if token is T_SEMICOLON or T_RBRACE?
// maybe distinction between leave and turnInto?
if (statementDone) {
if (topState == substatement
|| topState == statement_with_condition
|| topState == for_statement
|| topState == switch_statement
|| topState == do_statement) {
leave(true);
} else if (topState == if_statement) {
if (poppedState.type != maybe_else)
enter(maybe_else);
else
leave(true);
} else if (topState == else_clause) {
// leave the else *and* the surrounding if, to prevent another else
leave();
leave(true);
}
}
}
void CodeFormatter::correctIndentation(const QTextBlock &block)
{
const int lexerState = tokenizeBlock(block);
Q_ASSERT(m_currentState.size() >= 1);
adjustIndent(m_tokens, lexerState, &m_indentDepth);
}
bool CodeFormatter::tryExpression(bool alsoExpression)
{
int newState = -1;
const int kind = m_currentToken.kind();
switch (kind) {
case T_LPAREN: newState = arglist_open; break;
case T_QUESTION: newState = ternary_op; break;
case T_LESS_LESS:
case T_GREATER_GREATER:
newState = stream_op;
for (int i = m_currentState.size() - 1; i >= 0; --i) {
const int type = m_currentState.at(i).type;
if (type == arglist_open) { // likely a left-shift instead
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
newState = -1;
break;
}
if (type == topmost_intro
|| type == substatement_open
|| type == defun_open
|| type == namespace_open
|| type == class_open
|| type == brace_list_open) {
break;
}
}
break;
}
if (newState != -1) {
if (alsoExpression)
enter(expression);
enter(newState);
return true;
}
return false;
}
bool CodeFormatter::tryDeclaration()
{
const int kind = m_currentToken.kind();
switch (kind) {
case T_Q_ENUMS:
case T_Q_PROPERTY:
case T_Q_FLAGS:
case T_Q_GADGET:
case T_Q_OBJECT:
case T_Q_INTERFACES:
case T_Q_DECLARE_INTERFACE:
case T_Q_PRIVATE_SLOT:
enter(qt_like_macro);
return true;
case T_IDENTIFIER:
if (m_tokenIndex == 0) {
QString tokenText = currentTokenText().toString();
if (tokenText.startsWith(QLatin1String("Q_"))
|| tokenText.startsWith(QLatin1String("QT_"))
|| tokenText.startsWith(QLatin1String("QDOC_"))) {
enter(qt_like_macro);
return true;
}
}
// fallthrough
case T_CHAR:
case T_WCHAR_T:
case T_BOOL:
case T_SHORT:
case T_INT:
case T_LONG:
case T_SIGNED:
case T_UNSIGNED:
case T_FLOAT:
case T_DOUBLE:
case T_VOID:
case T_AUTO:
case T___TYPEOF__:
case T___ATTRIBUTE__:
case T_STATIC:
case T_FRIEND:
case T_CONST:
case T_VOLATILE:
case T_INLINE:
enter(declaration_start);
return true;
case T_TEMPLATE:
enter(template_start);
return true;
case T_NAMESPACE:
enter(namespace_start);
return true;
case T_STRUCT:
case T_UNION:
case T_CLASS:
enter(class_start);
return true;
case T_ENUM:
enter(enum_start);
return true;
case T_USING:
enter(using_start);
return true;
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
default:
return false;
}
}
bool CodeFormatter::tryStatement()
{
const int kind = m_currentToken.kind();
if (tryDeclaration())
return true;
switch (kind) {
case T_RETURN:
enter(return_statement);
enter(expression);
return true;
case T_FOR:
enter(for_statement);
return true;
case T_SWITCH:
enter(switch_statement);
return true;
case T_IF:
enter(if_statement);
return true;
case T_WHILE:
case T_Q_FOREACH:
enter(statement_with_condition);
return true;
case T_DO:
enter(do_statement);
enter(substatement);
return true;
case T_CASE:
case T_DEFAULT:
enter(case_start);
return true;
case T_LBRACE:
enter(block_open);
return true;
default:
return false;
}
}
bool CodeFormatter::isBracelessState(int type) const
{
return type == substatement
|| type == if_statement
|| type == else_clause
|| type == statement_with_condition
|| type == for_statement
|| type == do_statement;
}
const Token &CodeFormatter::tokenAt(int idx) const
{
static const Token empty;
if (idx < 0 || idx >= m_tokens.size())
return empty;
else
return m_tokens.at(idx);
}
int CodeFormatter::column(int index) const
{
int col = 0;
if (index > m_currentLine.length())
index = m_currentLine.length();
const QChar tab = QLatin1Char('\t');
for (int i = 0; i < index; i++) {
if (m_currentLine[i] == tab) {
col = ((col / m_tabSize) + 1) * m_tabSize;
} else {
col++;
}
}
return col;
}
QStringRef CodeFormatter::currentTokenText() const
{
return m_currentLine.midRef(m_currentToken.begin(), m_currentToken.length());
}
void CodeFormatter::turnInto(int newState)
{
leave(false);
enter(newState);
}
void CodeFormatter::saveCurrentState(const QTextBlock &block)
{
if (!block.isValid())
return;
BlockData blockData;
blockData.m_blockRevision = block.revision();
blockData.m_beginState = m_beginState;
blockData.m_endState = m_currentState;
blockData.m_indentDepth = m_indentDepth;
QTextBlock saveableBlock(block);
saveBlockData(&saveableBlock, blockData);
void CodeFormatter::restoreCurrentState(const QTextBlock &block)
BlockData blockData;
if (loadBlockData(block, &blockData)) {
m_indentDepth = blockData.m_indentDepth;
m_currentState = blockData.m_endState;
m_beginState = m_currentState;
return;
}
}
m_currentState = initialState();
m_beginState = m_currentState;
m_indentDepth = 0;
}
QStack<CodeFormatter::State> CodeFormatter::initialState()
{
static QStack<CodeFormatter::State> initialState;
if (initialState.isEmpty())
initialState.push(State(topmost_intro, 0));
return initialState;
}
int CodeFormatter::tokenizeBlock(const QTextBlock &block, bool *endedJoined)
{
int startState = loadLexerState(block.previous());
if (block.blockNumber() == 0)
startState = 0;
Q_ASSERT(startState != -1);
SimpleLexer tokenize;
tokenize.setQtMocRunEnabled(true);
tokenize.setObjCEnabled(true);
m_currentLine = block.text();
// to determine whether a line was joined, Tokenizer needs a
// newline character at the end
m_currentLine.append(QLatin1Char('\n'));
m_tokens = tokenize(m_currentLine, startState);
if (endedJoined)
*endedJoined = tokenize.endedJoined();
const int lexerState = tokenize.state();
return lexerState;
}
void CodeFormatter::dump()
{
qDebug() << "Current token index" << m_tokenIndex;
qDebug() << "Current state:";
foreach (State s, m_currentState) {
qDebug() << s.type << s.savedIndentDepth;
}
qDebug() << "Current indent depth:" << m_indentDepth;
}
namespace CppTools {
namespace Internal {
class CppCodeFormatterData: public TextEditor::CodeFormatterData
{
public:
CodeFormatter::BlockData m_data;
};
}
}
QtStyleCodeFormatter::QtStyleCodeFormatter()
: m_indentSize(4)
, m_indentSubstatementBraces(false)
, m_indentSubstatementStatements(true)
, m_indentDeclarationBraces(false)
, m_indentDeclarationMembers(true)
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
QtStyleCodeFormatter::QtStyleCodeFormatter(const TextEditor::TabSettings &tabSettings)
: m_indentSize(tabSettings.m_indentSize)
, m_indentSubstatementBraces(false)
, m_indentSubstatementStatements(true)
, m_indentDeclarationBraces(false)
, m_indentDeclarationMembers(true)
{
setTabSize(tabSettings.m_tabSize);
if (tabSettings.m_indentBraces && tabSettings.m_doubleIndentBlocks) { // gnu style
setIndentSubstatementBraces(true);
setIndentSubstatementStatements(true);
setIndentDeclarationBraces(false);
setIndentDeclarationMembers(true);
} else if (tabSettings.m_indentBraces) { // whitesmiths style
setIndentSubstatementBraces(true);
setIndentSubstatementStatements(false);
setIndentDeclarationBraces(true);
setIndentDeclarationMembers(false);
} else { // default Qt style
setIndentSubstatementBraces(false);
setIndentSubstatementStatements(true);
setIndentDeclarationBraces(false);
setIndentDeclarationMembers(true);
}
}
void QtStyleCodeFormatter::setIndentSize(int size)
{
m_indentSize = size;
void QtStyleCodeFormatter::setIndentSubstatementBraces(bool onOff)
m_indentSubstatementBraces = onOff;
}
void QtStyleCodeFormatter::setIndentSubstatementStatements(bool onOff)
{
m_indentSubstatementStatements = onOff;
}
void QtStyleCodeFormatter::setIndentDeclarationBraces(bool onOff)
{
m_indentDeclarationBraces = onOff;
}
void QtStyleCodeFormatter::setIndentDeclarationMembers(bool onOff)
{
m_indentDeclarationMembers = onOff;
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
void QtStyleCodeFormatter::saveBlockData(QTextBlock *block, const BlockData &data) const
{
TextBlockUserData *userData = BaseTextDocumentLayout::userData(*block);
CppCodeFormatterData *cppData = static_cast<CppCodeFormatterData *>(userData->codeFormatterData());
if (!cppData) {
cppData = new CppCodeFormatterData;
userData->setCodeFormatterData(cppData);
}
cppData->m_data = data;
}
bool QtStyleCodeFormatter::loadBlockData(const QTextBlock &block, BlockData *data) const
{
TextBlockUserData *userData = BaseTextDocumentLayout::testUserData(block);
if (!userData)
return false;
CppCodeFormatterData *cppData = static_cast<CppCodeFormatterData *>(userData->codeFormatterData());
if (!cppData)
return false;
*data = cppData->m_data;
return true;
}
void QtStyleCodeFormatter::saveLexerState(QTextBlock *block, int state) const
{
}
int QtStyleCodeFormatter::loadLexerState(const QTextBlock &block) const
{