Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-131686

qmlformat: Provide a way to preserve line breaks in multi-line expressions

    XMLWordPrintable

Details

    Description

      Sometimes, we want to maintain our line breaks for readability, but qmlformat squeezes them into single lines.

      It would be great to have a mechanism to prevent this. (Using comments to disable formatting for specific blocks, perhaps? QTBUG-97796 )

       

      qmlformat inputs (already good)

      // From https://github.com/qt/qtdeclarative/blob/v6.8.0/src/quickcontrols/basic/TreeViewDelegate.qml#L22-L25
      import QtQuick
      import QtQuick.Controls.impl
      import QtQuick.Templates as T
      
      T.TreeViewDelegate {
          id: control
          highlighted: control.selected || control.current
                     || ((control.treeView.selectionBehavior === TableView.SelectRows
                     || control.treeView.selectionBehavior === TableView.SelectionDisabled)
                     && control.row === control.treeView.currentRow)
      }
      
      import QtQml
      
      QtObject {
          function getBatteryAdvice(batteryLevel_pct : int) : string {
              return batteryLevel_pct > 40
                      ? `Battery OK. ${batteryLevel_pct}% remaining.`
                      : `Only ${batteryLevel_pct}% remaining. Please recharge.`
      
          }
      }
      

       

      qmlformat outputs (made worse)

      // From https://github.com/qt/qtdeclarative/blob/v6.8.0/src/quickcontrols/basic/TreeViewDelegate.qml#L22-L25
      import QtQuick
      import QtQuick.Controls.impl
      import QtQuick.Templates as T
      
      T.TreeViewDelegate {
          id: control
          highlighted: control.selected || control.current || ((control.treeView.selectionBehavior === TableView.SelectRows || control.treeView.selectionBehavior === TableView.SelectionDisabled) && control.row === control.treeView.currentRow)
      }
      
      import QtQml
      
      QtObject {
          function getBatteryAdvice(batteryLevel_pct : int) : string {
              return batteryLevel_pct > 40 ? `Battery OK. ${batteryLevel_pct}% remaining.` : `Only ${batteryLevel_pct}% remaining. Please recharge.`;
      
          }
      }
      

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              qtqmlteam Qt Qml Team User
              skoh-qt Sze Howe Koh
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes