Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-21804

improve the Q_PROPERTY refactor code generation (needs some options)

    XMLWordPrintable

Details

    • 5b5ae971045adebe40209150cf9e1cac6cc62191 (qt-creator/qt-creator/master)

    Description

      I’ve been wishing for more flexibility in the feature that implements properties. (Right-click on a Q_PROPERTY declaration, and choose Refactor | Generate Missing Q_PROPERTY Members.) I have noticed a few use cases where it doesn’t help as much as it could.

      1) It always writes the accessors as inline functions, so I then have to refactor again to move at least the setters to the .cpp file. (Sometimes I keep the getters inline.)

      2) It always writes them in widget-programming style: the setter is a slot, and the signal has a parameter with the changed value. In Qt Quick we don’t use slots much, and signals don’t have parameters (but I’m not sure of the exact explanation why widgets need signal parameters and QtQuick doesn’t).

      3) If my public class has a private class, there are no refactoring tools that have any clue about that. It’s so tedious to move and rename the new variables (remove the m_ prefix) and remove signal parameters and move the inline functions to the private class all at the same time, that I’m typically better off to duplicate an existing pair of setters.

      4) Maybe it could write qdoc comments too?

      So I think maybe it should first pop up a dialog with a few checkboxes. And perhaps the use case can be detected heuristically to pre-set the checkboxes: if the #includes bring in QtQuick or QML stuff, the signals won't need parameters; if a private class is declared, probably we want to put the variables and accessors there; otherwise, by default, the setters should be in the .cpp and the getters should be in the header. But have checkboxes for all these things.

      Attachments

        Issue Links

          For Gerrit Dashboard: QTCREATORBUG-21804
          # Subject Branch Project Status CR V

          Activity

            People

              bubke Marco Bubke
              srutledg Shawn Rutledge
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes