diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-08-27 10:56:34 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-08-27 11:39:50 +0000 |
commit | 37edb4464e5f05d239cff4e53c5552fc851960a1 (patch) | |
tree | 79f47e0145586c1d25bf1b5fac4a0c19936b162e | |
parent | aedc6d42ed31333ad84d505e0792ba0b1f8679cc (diff) |
Fix remaining Clang warnings
- Remove else after return/break
- Avoid copies of variables which are used as const-ref
- Simplify boolean return values
- Remove redundant declarations
- Use range-based for where applicable
Change-Id: I5a3e4ba86845ac4d1c6f166c3f808eb06469c28f
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
-rw-r--r-- | src/activeqt/container/qaxbase.cpp | 42 | ||||
-rw-r--r-- | src/activeqt/container/qaxdump.cpp | 47 | ||||
-rw-r--r-- | src/activeqt/container/qaxscript.cpp | 10 | ||||
-rw-r--r-- | src/activeqt/control/qaxfactory.cpp | 6 | ||||
-rw-r--r-- | src/activeqt/control/qaxfactory.h | 8 | ||||
-rw-r--r-- | src/activeqt/control/qaxserverbase.cpp | 13 | ||||
-rw-r--r-- | src/activeqt/shared/qaxutils.cpp | 2 | ||||
-rw-r--r-- | src/activeqt/shared/qaxutils_p.h | 2 | ||||
-rw-r--r-- | src/tools/idc/main.cpp | 10 | ||||
-rw-r--r-- | tools/testcon/changeproperties.cpp | 6 | ||||
-rw-r--r-- | tools/testcon/docuwindow.cpp | 2 | ||||
-rw-r--r-- | tools/testcon/mainwindow.cpp | 7 |
12 files changed, 66 insertions, 89 deletions
diff --git a/src/activeqt/container/qaxbase.cpp b/src/activeqt/container/qaxbase.cpp index d1ea09c..9c0e0d9 100644 --- a/src/activeqt/container/qaxbase.cpp +++ b/src/activeqt/container/qaxbase.cpp @@ -415,7 +415,7 @@ public: const int argcount = int(pDispParams->cArgs); if (pcount > argcount) return DISP_E_PARAMNOTOPTIONAL; - else if (pcount < argcount) + if (pcount < argcount) return DISP_E_BADPARAMCOUNT; // setup parameters (no return values in signals) @@ -1555,9 +1555,8 @@ private: Bindable = 0x02000000 }; - static inline QList<QByteArray> paramList(const QByteArray &proto) + static inline QList<QByteArray> paramList(const QByteArray &prototype) { - QByteArray prototype(proto); QByteArray parameters = prototype.mid(prototype.indexOf('(') + 1); parameters.truncate(parameters.length() - 1); if (parameters.isEmpty() || parameters == "void") @@ -1567,20 +1566,18 @@ private: inline QByteArray replaceType(const QByteArray &type) { - int i = 0; - if (type.isEmpty()) { + if (type.isEmpty()) return QByteArray("void"); - } else { - while (type_conversion[i][0]) { - int len = int(strlen(type_conversion[i][0])); - int ti; - if ((ti = type.indexOf(type_conversion[i][0])) != -1) { - QByteArray rtype(type); - rtype.replace(ti, len, type_conversion[i][1]); - return rtype; - } - ++i; + int i = 0; + while (type_conversion[i][0]) { + int len = int(strlen(type_conversion[i][0])); + int ti; + if ((ti = type.indexOf(type_conversion[i][0])) != -1) { + QByteArray rtype(type); + rtype.replace(ti, len, type_conversion[i][1]); + return rtype; } + ++i; } return type; } @@ -1591,7 +1588,7 @@ private: QList<QByteArray> plist = paramList(prototype); for (int p = 0; p < plist.count(); ++p) { - QByteArray param(plist.at(p)); + const QByteArray ¶m = plist.at(p); if (param != replaceType(param)) { int type = 0; while (type_conversion[type][0]) { @@ -4358,13 +4355,12 @@ QAxBase::PropertyBag QAxBase::propertyBag() const pbag->Release(); persist->Release(); return result; - } else { - const QMetaObject *mo = metaObject(); - for (int p = mo->propertyOffset(); p < mo->propertyCount(); ++p) { - const QMetaProperty property = mo->property(p); - QVariant var = qObject()->property(property.name()); - result.insert(QLatin1String(property.name()), var); - } + } + const QMetaObject *mo = metaObject(); + for (int p = mo->propertyOffset(); p < mo->propertyCount(); ++p) { + const QMetaProperty property = mo->property(p); + QVariant var = qObject()->property(property.name()); + result.insert(QLatin1String(property.name()), var); } return result; } diff --git a/src/activeqt/container/qaxdump.cpp b/src/activeqt/container/qaxdump.cpp index ebe96d7..80133d7 100644 --- a/src/activeqt/container/qaxdump.cpp +++ b/src/activeqt/container/qaxdump.cpp @@ -100,8 +100,7 @@ static QByteArray namedPrototype(const QList<QByteArray> ¶meterTypes, const { QByteArray prototype("("); for (int p = 0; p < parameterTypes.count(); ++p) { - QByteArray type(parameterTypes.at(p)); - prototype += type; + prototype += parameterTypes.at(p); if (p < parameterNames.count()) prototype += ' ' + parameterNames.at(p); @@ -217,31 +216,27 @@ QString qax_generateDocumentation(QAxBase *that) QString::fromLatin1(prototype.constData()) + QLatin1String("));"); detail += QLatin1String("</pre>\n"); - if (1) { - detail += QLatin1String("<p>Or call the function directly:<pre>\n"); - - bool hasParams = slot.parameterTypes().count() != 0; - if (hasParams) - detail += QLatin1String("\tQVariantList params = ...\n"); - detail += QLatin1String("\t"); - QByteArray functionToCall = "dynamicCall"; - if (returntype == "IDispatch*" || returntype == "IUnknown*") { - functionToCall = "querySubObject"; - returntype = "QAxObject *"; - } - if (returntype != "void") - detail += QLatin1String(returntype.constData()) + QLatin1String(" result = "); - detail += QLatin1String("object->") + QLatin1String(functionToCall.constData()) + - QLatin1String("(\"" + name + prototype + '\"'); - if (hasParams) - detail += QLatin1String(", params"); - detail += QLatin1Char(')'); - if (returntype != "void" && returntype != "QAxObject *" && returntype != "QVariant") - detail += QLatin1Char('.') + QLatin1String(toType(returntype)); - detail += QLatin1String(";</pre>\n"); - } else { - detail += QLatin1String("<p>This function has parameters of unsupported types and cannot be called directly."); + detail += QLatin1String("<p>Or call the function directly:<pre>\n"); + + bool hasParams = slot.parameterTypes().count() != 0; + if (hasParams) + detail += QLatin1String("\tQVariantList params = ...\n"); + detail += QLatin1String("\t"); + QByteArray functionToCall = "dynamicCall"; + if (returntype == "IDispatch*" || returntype == "IUnknown*") { + functionToCall = "querySubObject"; + returntype = "QAxObject *"; } + if (returntype != "void") + detail += QLatin1String(returntype.constData()) + QLatin1String(" result = "); + detail += QLatin1String("object->") + QLatin1String(functionToCall.constData()) + + QLatin1String("(\"" + name + prototype + '\"'); + if (hasParams) + detail += QLatin1String(", params"); + detail += QLatin1Char(')'); + if (returntype != "void" && returntype != "QAxObject *" && returntype != "QVariant") + detail += QLatin1Char('.') + QLatin1String(toType(returntype)); + detail += QLatin1String(";</pre>\n"); methodDetails << detail; defArgCount = 0; diff --git a/src/activeqt/container/qaxscript.cpp b/src/activeqt/container/qaxscript.cpp index a209df5..0f0aa08 100644 --- a/src/activeqt/container/qaxscript.cpp +++ b/src/activeqt/container/qaxscript.cpp @@ -1291,13 +1291,9 @@ QAxScript *QAxScriptManager::scriptForFunction(const QString &function) const */ void QAxScriptManager::updateScript(QAxScript *script) { - QHash<QString, QAxBase*>::ConstIterator objectIt; - for (objectIt = d->objectDict.constBegin(); objectIt != d->objectDict.constEnd(); ++objectIt) { - QString name = objectIt.key(); - - QAxScriptEngine *engine = script->scriptEngine(); - if (engine) - engine->addItem(name); + if (QAxScriptEngine *engine = script->scriptEngine()) { + for (auto it = d->objectDict.constBegin(), end = d->objectDict.constEnd(); it != end; ++it) + engine->addItem(it.key()); } } diff --git a/src/activeqt/control/qaxfactory.cpp b/src/activeqt/control/qaxfactory.cpp index 1a999aa..2a0ed4f 100644 --- a/src/activeqt/control/qaxfactory.cpp +++ b/src/activeqt/control/qaxfactory.cpp @@ -288,9 +288,7 @@ bool QAxFactory::validateLicenseKey(const QString &key, const QString &licenseKe int lastDot = licFile.lastIndexOf(QLatin1Char('.')); licFile.truncate(lastDot); licFile += QLatin1String(".lic"); - if (QFile::exists(licFile)) - return true; - return false; + return QFile::exists(licFile); } return licenseKey == classKey; } @@ -369,8 +367,6 @@ bool QAxFactory::isServer() return qAxIsServer; } -extern wchar_t qAxModuleFilename[MAX_PATH]; - /*! Returns the directory that contains the server binary. diff --git a/src/activeqt/control/qaxfactory.h b/src/activeqt/control/qaxfactory.h index 342017e..05df3c9 100644 --- a/src/activeqt/control/qaxfactory.h +++ b/src/activeqt/control/qaxfactory.h @@ -220,9 +220,9 @@ public: { const QStringList categories = getImplementedCategories(); - for (QStringList::const_iterator it = categories.begin(), end = categories.end(); it != end; ++it) { + for (const auto &cat : categories) { settings->setValue(QLatin1String("/CLSID/") + classID(key).toString() - + QLatin1String("/Implemented Categories/") + *it + QLatin1String("/."), + + QLatin1String("/Implemented Categories/") + cat + QLatin1String("/."), QString()); } } @@ -231,9 +231,9 @@ public: { const QStringList categories = getImplementedCategories(); - for (QStringList::const_iterator it = categories.begin(), end = categories.end(); it != end; ++it) { + for (const auto &cat : categories) { settings->remove(QLatin1String("/CLSID/") + classID(key).toString() - + QLatin1String("/Implemented Categories/") + *it + QLatin1String("/.")); + + QLatin1String("/Implemented Categories/") + cat + QLatin1String("/.")); } } diff --git a/src/activeqt/control/qaxserverbase.cpp b/src/activeqt/control/qaxserverbase.cpp index 30ea1dc..d11fbeb 100644 --- a/src/activeqt/control/qaxserverbase.cpp +++ b/src/activeqt/control/qaxserverbase.cpp @@ -229,8 +229,7 @@ public: void reportError(int code, const QString &src, const QString &desc, const QString &context) override { - if (exception) - delete exception; + delete exception; exception = new QAxExceptInfo(code, src, desc, context); } @@ -2380,9 +2379,9 @@ HRESULT WINAPI QAxServerBase::Invoke(DISPID dispidMember, REFIID riid, else res = S_OK; break; - } else if (wFlags == DISPATCH_PROPERTYGET) { - break; } + if (wFlags == DISPATCH_PROPERTYGET) + break; } Q_FALLTHROUGH(); // Fall through if wFlags == DISPATCH_PROPERTYGET|DISPATCH_METHOD AND not a property. case DISPATCH_METHOD: @@ -3078,7 +3077,7 @@ HRESULT WINAPI QAxServerBase::Load(LPCOLESTR fileName, DWORD /* mode */) QString mimeType = QLatin1String(mo->classInfo(mimeIndex).value()); QStringList mimeTypes = mimeType.split(QLatin1Char(';')); for (int m = 0; m < mimeTypes.count(); ++m) { - QString mime = mimeTypes.at(m); + const QString &mime = mimeTypes.at(m); if (mime.count(QLatin1Char(':')) != 2) { qWarning() << class_name << ": Invalid syntax in Q_CLASSINFO for MIME"; continue; @@ -3123,7 +3122,7 @@ HRESULT WINAPI QAxServerBase::Save(LPCOLESTR fileName, BOOL fRemember) QString mimeType = QLatin1String(mo->classInfo(mimeIndex).value()); QStringList mimeTypes = mimeType.split(QLatin1Char(';')); for (int m = 0; m < mimeTypes.count(); ++m) { - QString mime = mimeTypes.at(m); + const QString &mime = mimeTypes.at(m); if (mime.count(QLatin1Char(':')) != 2) { qWarning() << class_name << ": Invalid syntax in Q_CLASSINFO for MIME"; continue; @@ -3576,7 +3575,7 @@ HRESULT WINAPI QAxServerBase::TranslateAcceleratorW(MSG *pMsg) } } else { QWidget *nextFocus = curFocus; - while (1) { + while (true) { nextFocus = nextFocus->nextInFocusChain(); if (nextFocus->isWindow()) break; diff --git a/src/activeqt/shared/qaxutils.cpp b/src/activeqt/shared/qaxutils.cpp index fb610f5..c1f1e74 100644 --- a/src/activeqt/shared/qaxutils.cpp +++ b/src/activeqt/shared/qaxutils.cpp @@ -97,7 +97,7 @@ static void addRectToHrgn(HRGN &winRegion, const QRect &r) } } -HRGN qaxHrgnFromQRegion(QRegion region, const QWindow *window) +HRGN qaxHrgnFromQRegion(const QRegion ®ion, const QWindow *window) { HRGN hRegion = CreateRectRgn(0, 0, 0, 0); for (const QRect &rect : QHighDpi::toNativeLocalRegion(region, window)) diff --git a/src/activeqt/shared/qaxutils_p.h b/src/activeqt/shared/qaxutils_p.h index 21dcfeb..8c86980 100644 --- a/src/activeqt/shared/qaxutils_p.h +++ b/src/activeqt/shared/qaxutils_p.h @@ -76,7 +76,7 @@ class QRegion; class QWindow; HWND hwndForWidget(QWidget *widget); -HRGN qaxHrgnFromQRegion(QRegion region, const QWindow *window); +HRGN qaxHrgnFromQRegion(const QRegion ®ion, const QWindow *window); typedef QPair<qreal, qreal> QDpi; diff --git a/src/tools/idc/main.cpp b/src/tools/idc/main.cpp index 19bd874..dddfeda 100644 --- a/src/tools/idc/main.cpp +++ b/src/tools/idc/main.cpp @@ -69,11 +69,8 @@ static bool prependPath() return false; *ptr++ = L';'; const wchar_t pathVariable[] = L"PATH"; - if (!GetEnvironmentVariable(pathVariable, ptr, DWORD(maxEnvironmentSize - (ptr - buffer))) - || !SetEnvironmentVariable(pathVariable, buffer)) { - return false; - } - return true; + return GetEnvironmentVariable(pathVariable, ptr, DWORD(maxEnvironmentSize - (ptr - buffer))) != 0 + && SetEnvironmentVariable(pathVariable, buffer) == TRUE; } static QString errorString(DWORD errorCode) @@ -381,7 +378,8 @@ int runIdc(int argc, char **argv) const bool ok = attachTypeLibrary(input, 1, file.readAll(), &error); fprintf(stderr, "%s\n", qPrintable(error)); return ok ? 0 : 4; - } else if (!idlfile.isEmpty()) { + } + if (!idlfile.isEmpty()) { idlfile = QDir::toNativeSeparators(idlfile); fprintf(stderr, "\n\n%s\n\n", qPrintable(idlfile)); const HRESULT res = dumpIdl(input, idlfile, version); diff --git a/tools/testcon/changeproperties.cpp b/tools/testcon/changeproperties.cpp index 395acc7..cae1f84 100644 --- a/tools/testcon/changeproperties.cpp +++ b/tools/testcon/changeproperties.cpp @@ -234,12 +234,10 @@ void ChangeProperties::updateProperties() break; case QVariant::List: { - QList<QVariant> varList = var.toList(); + const QList<QVariant> varList = var.toList(); QStringList strList; - for (int i = 0; i < varList.count(); ++i) { - QVariant var = varList.at(i); + for (const auto &var : varList) strList << var.toString(); - } item->setText(2, strList.join(QLatin1String(", "))); } break; diff --git a/tools/testcon/docuwindow.cpp b/tools/testcon/docuwindow.cpp index e1c27fe..c5f60e9 100644 --- a/tools/testcon/docuwindow.cpp +++ b/tools/testcon/docuwindow.cpp @@ -137,7 +137,7 @@ void DocuWindow::print() } QPrintDialog printDialog(&printer, this); - if (!printDialog.exec()) { + if (printDialog.exec() == QDialog::Rejected) { statusBar()->showMessage(tr("Printing aborted"), 2000); return; } diff --git a/tools/testcon/mainwindow.cpp b/tools/testcon/mainwindow.cpp index 3ff0016..06ce0a0 100644 --- a/tools/testcon/mainwindow.cpp +++ b/tools/testcon/mainwindow.cpp @@ -79,10 +79,9 @@ MainWindow::MainWindow(QWidget *parent) setObjectName(QLatin1String("MainWindow")); - const int scriptCount = int(sizeof(scriptLanguages) / sizeof(scriptLanguages[0])); - for (int s = 0; s < scriptCount; ++s) { - const QString name = QLatin1String(scriptLanguages[s].name); - const QString suffix = QLatin1String(scriptLanguages[s].suffix); + for (auto scriptLanguage : scriptLanguages) { + const QString name = QLatin1String(scriptLanguage.name); + const QString suffix = QLatin1String(scriptLanguage.suffix); if (!QAxScriptManager::registerEngine(name, suffix)) qWarning().noquote().nospace() << "Failed to register \"" << name << "\" (*" << suffix << ") with QAxScriptManager."; |