Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Feature Request] Automatic Class generator
Forum Updated to NodeBB v4.3 + New Features

[Feature Request] Automatic Class generator

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 2.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tloz
    wrote on 25 Jan 2013, 19:51 last edited by
    #1

    Hello. Few days ago, I went back to C for an old project and I used Code::Block which has an interesting feature that creates the main part of your classes, just by asking you the members, writing them into the code, and adding getters and setters.

    Here is a snapshot of the window that does it:

    !http://i15.servimg.com/u/f15/16/17/33/57/captur11.png(class generator)!

    This would be really time saving in qtCreator.

    Thank you!

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on 25 Jan 2013, 19:58 last edited by
      #2

      Please file feature requests in the "bug tracker":https://bugreports.qt-project.org/ .

      The bug tracker makes sure that the relevant developers will see your suggestion. That is far from guaranteed here in the forum:)

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Tloz
        wrote on 25 Jan 2013, 23:31 last edited by
        #3

        Well, thank you for the advice.
        If an admin goes here, maybe he can lock the topic...

        1 Reply Last reply
        0
        • U Offline
          U Offline
          utcenter
          wrote on 26 Jan 2013, 05:49 last edited by
          #4

          Doesn't seem like that good of an idea - a lot of features are redundant and unnecessary, others are missing. All in all, such a tool might end up making a developer forget how to write classes, or never really learn in the case of a newbie, which will be the kind of person most tempted to use it in the first place.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tobias.hunger
            wrote on 26 Jan 2013, 09:04 last edited by
            #5

            I do not really like the UI either, but this dialog offers some things that are not available in Qt Creators new class dialog.

            I do not think that setter/getter thing is a good UI... having some QuickFix to add getters/setters for a member variable makes more sense to me. That way the same mechanism is available when initially creating a class as well as when adding members to existing classes.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DerManu
              wrote on 26 Jan 2013, 12:23 last edited by
              #6

              QtCreator has a different approach to such things, in my opinion. Right-Click->Refactor, or faster, Alt+Return. So It would be really great to have that refactoring option on a member variable Create Getter and Setter which adds the needed getters/setters in .h and .cpp at the appropriate locations. Further, it may also create an appropriate Q_PROPERTY line.

              The tricky part becomes positioning. QtCreator should try to understand the way the person writes his classes, i.e. look through the specific class header and find a bunch of "set[A-Z][A-Za-z]+\s*(" lines. This is the location of the setters, and the refactoring mechanism should add its setters there, probably in the order in which it finds the member variables (so it will need to parse them into an ordered list, too, and correlate that order with the order of the found setter functions in a fuzzy, robust manner). Then it needs to extract the position of the getters by looking for a bunch of functions that are named like the parts after "set" in the setter functions, with first letter lower case. That's the position of the getters and the mechanism shall add its getter there, again respecting the order of member variables.
              The getter/setters in the .cpp file should be placed in the correct positions, too, and not just at the end of the file (this is already done relatively well via the current refactoring option when writing a new method declaration).
              Further, there are many options, so It will probably also need an extra options page. For example, I only use const& parameters in the setters when it's a complex type, i.e. QRect and QString but not with int and double. Of course, the refactoring mechanism would only be of use to me, if it respects that, too. Else I'd have to correct all the output which will be as annoying as writing setters/getters myself. And options like having the default getter to just add the definition in the header, returning the member variable in one line: someType someValue() const { return mSomeValue; }.

              I've done a quick search whether there's an easy plugin interface for adding own refactoring actions, but haven't found one yet...

              1 Reply Last reply
              0
              • U Offline
                U Offline
                utcenter
                wrote on 26 Jan 2013, 14:58 last edited by
                #7

                [quote author="Tobias Hunger" date="1359191066"]I do not think that setter/getter thing is a good UI…
                .[/quote]

                A while back I posted an idea about "integrating property support tighter in Creator, with a degree of boilerplate code generation":http://qt-project.org/forums/viewthread/23684/, but it didn't seem to catch any attention.

                About that UI - doesn't the compiler like... always generate the big three defaults, even if you don't specify them? Also, I don't see how this dialog would help in the case of something like multiple inheritance.

                Overall, I don't think CodeBlocks is that good of a role model, it is a dead and heavily dated IDE, whose feature set is hardly exemplary.

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  tobias.hunger
                  wrote on 26 Jan 2013, 17:05 last edited by
                  #8

                  utcenter: Of course not, it is not in the bug tracker:-) I did read it, but I don't have any additional comments to make and then I promptly forgot all about it...

                  1 Reply Last reply
                  0
                  • U Offline
                    U Offline
                    utcenter
                    wrote on 26 Jan 2013, 17:17 last edited by
                    #9

                    Well, unlike some other people, I would not rush into suggesting something just for my sake - had the idea attacked more interest here, then I'd consider it worthy to forward as an official feature request. But something as significant as enforcing a naming convention, albeit the most useful and used one, is most certainly not a trivial matter that can go without discussing.

                    1 Reply Last reply
                    0

                    1/9

                    25 Jan 2013, 19:51

                    • Login

                    • Login or register to search.
                    1 out of 9
                    • First post
                      1/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved