1

If we right click on any Data member and goto Refractor -> and click on Create Getter Setter. It creates Getter ByDefault as get+DataMemberName. But i want to make Getter as Qt's convention, Example : for DataMember carName ByDefault QtCretor will create -> getCarName() but i want -> CarName().

Can it be possible by changing some Creator Setting or some thing else..

DesignIsLife
  • 510
  • 5
  • 11

2 Answers2

1

After looking at /plugins/cppeditor/cppquickfixes.cpp mentioned in Dominik's answer, there is simple way:

Name you private data member in any of these ways

QString m_carName;
QString _carName; // note: using _ to start identifier is questionable (*)
QString carName_;

Then Qt Creator should generate getter carName. Note that CarName is not Qt convention, but if you do want that anyway, then use m_CarName as variable name.

(*) See What are the rules about using an underscore in a C++ identifier?

Community
  • 1
  • 1
hyde
  • 60,639
  • 21
  • 115
  • 176
0

A very easy option would be to compile QtCreator from source and change the naming rule in file /plugins/cppeditor/cppquickfixes.cpp. Search for class GenerateGetterSetterOperation. In the constructor the variable name m_getterName and m_setterName are defined here.

The piece of code you are looking for is:

m_getterName = m_baseName != m_variableString
        ? QString::fromLatin1("%1").arg(m_baseName)
        : QString::fromLatin1("get%1%2")
            .arg(m_baseName.left(1).toUpper()).arg(m_baseName.mid(1));
m_setterName = QString::fromLatin1("set%1%2")
        .arg(m_baseName.left(1).toUpper()).arg(m_baseName.mid(1));

You have to change the first part to something like:

 m_getterName = m_baseName != m_variableString
        ? QString::fromLatin1("%1").arg(m_baseName)
        : QString::fromLatin1("%1%2")
            .arg(m_baseName.left(1).toLower()).arg(m_baseName.mid(1).toUpper());

Honestly, i did not check for correctness.

EDIT: Hyde is absolutely right. I did not check the mechanism that i cited in-depth due to time limitations but tried it a few minutes ago and checked the source.

OnWhenReady
  • 939
  • 6
  • 15