Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Getters/setters added twice
Forum Updated to NodeBB v4.3 + New Features

Getters/setters added twice

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
4 Posts 3 Posters 294 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.
  • A Offline
    A Offline
    angela2016
    wrote on last edited by
    #1

    Hi,

    I used to use a rather old version of Qt Creator for a long time and when you right clicked on a member variable - "Refactor" the "Generate getter/setter" button would only be available if there wasn't a getter/setter for that variable, which made sense.

    Now with version 15.0.0 this is no longer the case, so that if there already is a getter, it will just be added twice, and then I have to delete it again, which is very annoying.

    Is there any way to recreate the way it worked before? Thanks.

    Best wishes,
    Angela

    jsulmJ 1 Reply Last reply
    0
    • A angela2016

      Hi,

      I used to use a rather old version of Qt Creator for a long time and when you right clicked on a member variable - "Refactor" the "Generate getter/setter" button would only be available if there wasn't a getter/setter for that variable, which made sense.

      Now with version 15.0.0 this is no longer the case, so that if there already is a getter, it will just be added twice, and then I have to delete it again, which is very annoying.

      Is there any way to recreate the way it worked before? Thanks.

      Best wishes,
      Angela

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @angela2016 Could be a regression, worth reporting on Qt Bug Tracker.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      0
      • jsulmJ jsulm

        @angela2016 Could be a regression, worth reporting on Qt Bug Tracker.

        A Offline
        A Offline
        angela2016
        wrote on last edited by
        #3

        I looked at the source code and found the problem. In "cppcodegenerationquickfixes.cpp", "findExistingFunctions": apparently the idea is to get all possible getter/setter names including the custom ones and then compare the lowercase version of it with the lowercase version of the member functions. But "settings->getSetterName(lowerBaseName)" doesn't actually return a lowercase version of the name, so the comparison doesn't work.

        I changed the code to this and it seems to work now. Guess I'll work with my own compiled Qt Creator then.

        static void findExistingFunctions(ExistingGetterSetterData &existing, QStringList memberFunctionNames)
        {
            const CppQuickFixSettings *settings = CppQuickFixProjectsSettings::getQuickFixSettings(
                ProjectExplorer::ProjectTree::currentProject());
            const QString lowerBaseName = memberBaseName(existing.memberVariableName).toLower();
            const QStringList getterNames{lowerBaseName,
                                          "get_" + lowerBaseName,
                                          "get" + lowerBaseName,
                                          "is_" + lowerBaseName,
                                          "is" + lowerBaseName,
                                          settings->getGetterName(lowerBaseName).toLower()}; //changed from settings->getGetterName(lowerBaseName)};
            const QStringList setterNames{"set_" + lowerBaseName,
                                          "set" + lowerBaseName,
                                          settings->getSetterName(lowerBaseName).toLower()}; //changed;
            const QStringList resetNames{"reset_" + lowerBaseName,
                                         "reset" + lowerBaseName,
                                         settings->getResetName(lowerBaseName).toLower()};//changed;
            const QStringList signalNames{lowerBaseName + "_changed",
                                          lowerBaseName + "changed",
                                          settings->getSignalName(lowerBaseName).toLower()};//changed;
            for (const auto &memberFunctionName : memberFunctionNames) {
                const QString lowerName = memberFunctionName.toLower();
                if (getterNames.contains(lowerName))
                    existing.getterName = memberFunctionName;
                else if (setterNames.contains(lowerName))
                    existing.setterName = memberFunctionName;
                else if (resetNames.contains(lowerName))
                    existing.resetName = memberFunctionName;
                else if (signalNames.contains(lowerName))
                    existing.signalName = memberFunctionName;
            }
        }
        

        Can't believe none of us camel case people ever complained about this. :)

        SGaistS 1 Reply Last reply
        1
        • A angela2016

          I looked at the source code and found the problem. In "cppcodegenerationquickfixes.cpp", "findExistingFunctions": apparently the idea is to get all possible getter/setter names including the custom ones and then compare the lowercase version of it with the lowercase version of the member functions. But "settings->getSetterName(lowerBaseName)" doesn't actually return a lowercase version of the name, so the comparison doesn't work.

          I changed the code to this and it seems to work now. Guess I'll work with my own compiled Qt Creator then.

          static void findExistingFunctions(ExistingGetterSetterData &existing, QStringList memberFunctionNames)
          {
              const CppQuickFixSettings *settings = CppQuickFixProjectsSettings::getQuickFixSettings(
                  ProjectExplorer::ProjectTree::currentProject());
              const QString lowerBaseName = memberBaseName(existing.memberVariableName).toLower();
              const QStringList getterNames{lowerBaseName,
                                            "get_" + lowerBaseName,
                                            "get" + lowerBaseName,
                                            "is_" + lowerBaseName,
                                            "is" + lowerBaseName,
                                            settings->getGetterName(lowerBaseName).toLower()}; //changed from settings->getGetterName(lowerBaseName)};
              const QStringList setterNames{"set_" + lowerBaseName,
                                            "set" + lowerBaseName,
                                            settings->getSetterName(lowerBaseName).toLower()}; //changed;
              const QStringList resetNames{"reset_" + lowerBaseName,
                                           "reset" + lowerBaseName,
                                           settings->getResetName(lowerBaseName).toLower()};//changed;
              const QStringList signalNames{lowerBaseName + "_changed",
                                            lowerBaseName + "changed",
                                            settings->getSignalName(lowerBaseName).toLower()};//changed;
              for (const auto &memberFunctionName : memberFunctionNames) {
                  const QString lowerName = memberFunctionName.toLower();
                  if (getterNames.contains(lowerName))
                      existing.getterName = memberFunctionName;
                  else if (setterNames.contains(lowerName))
                      existing.setterName = memberFunctionName;
                  else if (resetNames.contains(lowerName))
                      existing.resetName = memberFunctionName;
                  else if (signalNames.contains(lowerName))
                      existing.signalName = memberFunctionName;
              }
          }
          

          Can't believe none of us camel case people ever complained about this. :)

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @angela2016 Nice catch !

          Since you found the bug and the fix, please submit a patch :-)

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

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