Getters/setters added twice
-
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 -
@angela2016 Could be a regression, worth reporting on Qt Bug Tracker.
-
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. :)
-
@angela2016 Nice catch !
Since you found the bug and the fix, please submit a patch :-)