Designer: Modernize

* Remove QLatin1{Char|String}
* Use member initialization
* Use range-for
* Use nullptr

Change-Id: I51c24c0a2066861f59731585f19d61b28c76c0a3
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
Andre Hartmann
2017-10-16 20:47:05 +02:00
committed by André Hartmann
parent 72c283afc8
commit 1d53110402
28 changed files with 161 additions and 184 deletions

View File

@@ -43,6 +43,7 @@
#include <texteditor/textdocument.h>
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/session.h>
#include <utils/asconst.h>
#include <utils/mimetypes/mimedatabase.h>
#include <utils/qtcassert.h>
@@ -66,8 +67,8 @@ using namespace ProjectExplorer;
static QString msgClassNotFound(const QString &uiClassName, const QList<Document::Ptr> &docList)
{
QString files;
foreach (const Document::Ptr &doc, docList) {
files += QLatin1Char('\n');
for (const Document::Ptr &doc : docList) {
files += '\n';
files += QDir::toNativeSeparators(doc->fileName());
}
return QtCreatorIntegration::tr(
@@ -121,10 +122,10 @@ static QList<Document::Ptr> findDocumentsIncluding(const Snapshot &docTable,
const QString &fileName, bool checkFileNameOnly)
{
QList<Document::Ptr> docList;
foreach (const Document::Ptr &doc, docTable) { // we go through all documents
for (const Document::Ptr &doc : docTable) { // we go through all documents
const QList<Document::Include> includes = doc->resolvedIncludes()
+ doc->unresolvedIncludes();
foreach (const Document::Include &include, includes) {
for (const Document::Include &include : includes) {
if (checkFileNameOnly) {
const QFileInfo fi(include.unresolvedFileName());
if (fi.fileName() == fileName) { // we are only interested in docs which includes fileName only
@@ -204,7 +205,7 @@ static const Class *findClass(const Namespace *parentNameSpace, const LookupCont
if (const Namespace *ns = sym->asNamespace()) {
QString tempNS = *namespaceName;
tempNS += o.prettyName(ns->name());
tempNS += QLatin1String("::");
tempNS += "::";
if (const Class *cl = findClass(ns, context, className, &tempNS)) {
*namespaceName = tempNS;
return cl;
@@ -227,15 +228,15 @@ static Function *findDeclaration(const Class *cl, const QString &functionName)
if (Function *fun = decl->type()->asFunctionType()) {
// Format signature
QString memberFunction = overview.prettyName(fun->name());
memberFunction += QLatin1Char('(');
memberFunction += '(';
const uint aCount = fun->argumentCount();
for (uint i = 0; i < aCount; i++) { // we build argument types string
const Argument *arg = fun->argumentAt(i)->asArgument();
if (i > 0)
memberFunction += QLatin1Char(',');
memberFunction += ',';
memberFunction += overview.prettyType(arg->type());
}
memberFunction += QLatin1Char(')');
memberFunction += ')';
// we compare normalized signatures
memberFunction = QString::fromUtf8(QMetaObject::normalizedSignature(memberFunction.toUtf8()));
if (memberFunction == funName) // we match function names and argument lists
@@ -273,9 +274,7 @@ static void addDeclaration(const Snapshot &snapshot,
const Class *cl,
const QString &functionName)
{
QString declaration = QLatin1String("void ");
declaration += functionName;
declaration += QLatin1String(";\n");
const QString declaration = "void " + functionName + ";\n";
CppTools::CppRefactoringChanges refactoring(snapshot);
CppTools::InsertionPointLocator find(refactoring);
@@ -303,13 +302,8 @@ static Document::Ptr addDefinition(const Snapshot &docTable,
const QString &functionName,
int *line)
{
QString definition = QLatin1String("\nvoid ");
definition += className;
definition += QLatin1String("::");
definition += functionName;
definition += QLatin1String("\n{\n");
definition += QString(indentation, QLatin1Char(' '));
definition += QLatin1String("\n}\n");
const QString definition = "\nvoid " + className + "::" + functionName
+ "\n{\n" + QString(indentation, ' ') + "\n}\n";
// we find all documents which include headerFileName
const QList<Document::Ptr> docList = findDocumentsIncluding(docTable, headerFileName, false);
@@ -318,7 +312,7 @@ static Document::Ptr addDefinition(const Snapshot &docTable,
QFileInfo headerFI(headerFileName);
const QString headerBaseName = headerFI.completeBaseName();
foreach (const Document::Ptr &doc, docList) {
for (const Document::Ptr &doc : docList) {
const QFileInfo sourceFI(doc->fileName());
// we take only those documents which have the same filename
if (headerBaseName == sourceFI.baseName()) {
@@ -347,9 +341,7 @@ static Document::Ptr addDefinition(const Snapshot &docTable,
static QString addConstRefIfNeeded(const QString &argument)
{
if (argument.startsWith(QLatin1String("const "))
|| argument.endsWith(QLatin1Char('&'))
|| argument.endsWith(QLatin1Char('*')))
if (argument.startsWith("const ") || argument.endsWith('&') || argument.endsWith('*'))
return argument;
// for those types we don't want to add "const &"
@@ -359,10 +351,10 @@ static QString addConstRefIfNeeded(const QString &argument)
for (int i = 0; i < nonConstRefs.count(); i++) {
const QString nonConstRef = nonConstRefs.at(i);
if (argument == nonConstRef || argument.startsWith(nonConstRef + QLatin1Char(' ')))
if (argument == nonConstRef || argument.startsWith(nonConstRef + ' '))
return argument;
}
return QLatin1String("const ") + argument + QLatin1Char('&');
return "const " + argument + '&';
}
static QString formatArgument(const QString &argument)
@@ -372,8 +364,8 @@ static QString formatArgument(const QString &argument)
while (i > 0) { // from the end of the "argument" string
i--;
const QChar c = argument.at(i); // take the char
if (c != QLatin1Char('*') && c != QLatin1Char('&')) { // if it's not the * or &
formattedArgument.insert(i + 1, QLatin1Char(' ')); // insert space after that char or just append space (to separate it from the parameter name)
if (c != '*' && c != '&') { // if it's not the * or &
formattedArgument.insert(i + 1, ' '); // insert space after that char or just append space (to separate it from the parameter name)
break;
}
}
@@ -384,25 +376,25 @@ static QString formatArgument(const QString &argument)
// "void foo(bool checked)"
static QString addParameterNames(const QString &functionSignature, const QStringList &parameterNames)
{
const int firstParen = functionSignature.indexOf(QLatin1Char('('));
const int firstParen = functionSignature.indexOf('(');
QString functionName = functionSignature.left(firstParen + 1);
QString argumentsString = functionSignature.mid(firstParen + 1);
const int lastParen = argumentsString.lastIndexOf(QLatin1Char(')'));
const int lastParen = argumentsString.lastIndexOf(')');
if (lastParen != -1)
argumentsString.truncate(lastParen);
const QStringList arguments = argumentsString.split(QLatin1Char(','), QString::SkipEmptyParts);
const QStringList arguments = argumentsString.split(',', QString::SkipEmptyParts);
const int pCount = parameterNames.count();
const int aCount = arguments.count();
for (int i = 0; i < aCount; ++i) {
if (i > 0)
functionName += QLatin1String(", ");
functionName += ", ";
const QString argument = addConstRefIfNeeded(arguments.at(i));
functionName += formatArgument(argument);
if (i < pCount) {
// prepare parameterName
QString parameterName = parameterNames.at(i);
if (parameterName.isEmpty()) {
const QString generatedName = QLatin1String("arg") + QString::number(i + 1);
const QString generatedName = "arg" + QString::number(i + 1);
if (!parameterNames.contains(generatedName))
parameterName = generatedName;
}
@@ -411,7 +403,7 @@ static QString addParameterNames(const QString &functionSignature, const QString
functionName += parameterName;
}
}
functionName += QLatin1Char(')');
functionName += ')';
return functionName;
}
@@ -435,7 +427,8 @@ static ClassDocumentPtrPair
if (maxIncludeDepth) {
// Check the includes
const unsigned recursionMaxIncludeDepth = maxIncludeDepth - 1u;
foreach (const QString &include, doc->includedFiles()) {
const auto includedFiles = doc->includedFiles();
for (const QString &include : includedFiles) {
const Snapshot::const_iterator it = docTable.find(include);
if (it != docTable.end()) {
const Document::Ptr includeDoc = it.value();
@@ -463,9 +456,9 @@ void QtCreatorIntegration::slotNavigateToSlot(const QString &objectName, const Q
static inline QString uiClassName(QString formObjectName)
{
const int indexOfScope = formObjectName.lastIndexOf(QLatin1String("::"));
const int indexOfScope = formObjectName.lastIndexOf("::");
const int uiNameSpaceInsertionPos = indexOfScope >= 0 ? indexOfScope + 2 : 0;
formObjectName.insert(uiNameSpaceInsertionPos, QLatin1String("Ui::"));
formObjectName.insert(uiNameSpaceInsertionPos, "Ui::");
return formObjectName;
}
@@ -510,7 +503,7 @@ bool QtCreatorIntegration::navigateToSlot(const QString &objectName,
// So we should somehow get that info from project manager (?)
const QFileInfo fi = currentUiFile.toFileInfo();
const QString uiFolder = fi.absolutePath();
const QString uicedName = QLatin1String("ui_") + fi.completeBaseName() + QLatin1String(".h");
const QString uicedName = "ui_" + fi.completeBaseName() + ".h";
// Retrieve code model snapshot restricted to project of ui file or the working copy.
Snapshot docTable = CppTools::CppModelManager::instance()->snapshot();
@@ -542,7 +535,7 @@ bool QtCreatorIntegration::navigateToSlot(const QString &objectName,
// first in case there are project subdirectories that contain identical file names.
const QList<Document::Ptr> docList = findDocumentsIncluding(docTable, uicedName, true); // change to false when we know the absolute path to generated ui_<>.h file
DocumentMap docMap;
foreach (const Document::Ptr &d, docList) {
for (const Document::Ptr &d : docList) {
const QFileInfo docFi(d->fileName());
docMap.insert(qAbs(docFi.absolutePath().compare(uiFolder, Qt::CaseInsensitive)), d);
}
@@ -567,7 +560,7 @@ bool QtCreatorIntegration::navigateToSlot(const QString &objectName,
const Class *cl = 0;
Document::Ptr doc;
foreach (const Document::Ptr &d, docMap) {
for (const Document::Ptr &d : Utils::asConst(docMap)) {
LookupContext context(d, docTable);
const ClassDocumentPtrPair cd = findClassRecursively(context, uiClass, 1u , &namespaceName);
if (cd.first) {
@@ -586,7 +579,7 @@ bool QtCreatorIntegration::navigateToSlot(const QString &objectName,
if (Designer::Constants::Internal::debug)
qDebug() << "Found class " << className << doc->fileName();
const QString functionName = QLatin1String("on_") + objectName + QLatin1Char('_') + signalSignature;
const QString functionName = "on_" + objectName + '_' + signalSignature;
const QString functionNameWithParameterNames = addParameterNames(functionName, parameterNames);
if (Designer::Constants::Internal::debug)