- 
    Suggestion 
- 
    Resolution: Unresolved
- 
    P3: Somewhat important 
- 
    6.8
- 
    None
The ternary operator can be formatted like this:
Key: a ? b : c
Also we need to make sure the indent for nested ternary is correct:
Key: a ? b ? 1 : 2 ? 4 ? 555 : 6666 : 77777 : 33333
For this we can modify the function indentForLineStartingWithToken from qqmldomcodeformatter.cpp, for the T_COLON case:
case QQmlJSGrammar::T_COLON: { // find the most recent '?' that was not yet closed by a colon // and return its indent QStack <int> indentStack; for (int i = 0; i < oldStatus.states.length(); ++i) { const auto state = oldStatus.states[i]; const StateType type = state.type; if (type == StateType::TernaryOp) { indentStack.push(state.savedIndentDepth); } else if (type == StateType::TernaryOpAfterColon){ indentStack.pop(); } } return indentStack.length() > 0 ? indentStack.top() : indentDepth; }
Also in the function handleTokens from the same file:
case StateType::TernaryOpAfterColon: if(kind == QQmlJSGrammar::T_COLON){ //leave both, TernaryOp and TernaryOpAfterColon leave(false); leave(false); continue; }
| For Gerrit Dashboard: QTBUG-132095 | ||||||
|---|---|---|---|---|---|---|
| # | Subject | Branch | Project | Status | CR | V | 
| 625737,12 | qmlformat: Ternary operators on separate lines | dev | qt/qtdeclarative | Status: NEW | -1 | +1 |