Windows QPA: Fix some clang-tidy-warnings

- Replace index-based loops by range-based for
- Change else if to if after return/break/continue or simplify
- Fix indentation
- Do not check for non-null before invoking delete on pointer
- Use isEmpty() instead size() to check for empty containers
- Remove C-style casts
- Use raw string literal
- Do not repeat type in return, use {} instead
- Reference local variables by const ref where applicable

Change-Id: I5cc4b4026a10bddb561ba1ba8ec137e0d4119f94
Reviewed-by: Miguel Costa <miguel.costa@qt.io>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
This commit is contained in:
Friedemann Kleint 2018-08-03 14:34:17 +02:00
parent 67b296e249
commit 43af54c228
15 changed files with 59 additions and 69 deletions

View File

@ -524,10 +524,11 @@ HCURSOR QWindowsCursor::createCursorFromShape(Qt::CursorShape cursorShape, const
}
// Load available standard cursors from resources
const QWindowsStandardCursorMapping *sEnd = standardCursors + sizeof(standardCursors) / sizeof(standardCursors[0]);
for (const QWindowsStandardCursorMapping *s = standardCursors; s < sEnd; ++s) {
if (s->shape == cursorShape)
return static_cast<HCURSOR>(LoadImage(0, s->resource, IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE | LR_SHARED));
for (const QWindowsStandardCursorMapping &s : standardCursors) {
if (s.shape == cursorShape) {
return static_cast<HCURSOR>(LoadImage(nullptr, s.resource, IMAGE_CURSOR,
0, 0, LR_DEFAULTSIZE | LR_SHARED));
}
}
qWarning("%s: Invalid cursor shape %d", __FUNCTION__, cursorShape);

View File

@ -364,7 +364,7 @@ static BOOL QT_WIN_CALLBACK findDialogEnumWindowsProc(HWND hwnd, LPARAM lParam)
wchar_t buf[256];
if (!RealGetWindowClass(hwnd, buf, sizeof(buf)/sizeof(wchar_t)) || buf[0] != L'#')
return TRUE;
if (!GetWindowTextW(hwnd, buf, sizeof(buf)/sizeof(wchar_t)) || wcscmp(buf, context->title.data()))
if (!GetWindowTextW(hwnd, buf, sizeof(buf)/sizeof(wchar_t)) || wcscmp(buf, context->title.data()) != 0)
return TRUE;
context->hwnd = hwnd;
return FALSE;
@ -1545,8 +1545,8 @@ QWindowsNativeDialogBase *QWindowsFileDialogHelper::createNativeDialog()
result->updateDirectory();
result->updateSelectedNameFilter();
const QList<QUrl> initialSelection = opts->initiallySelectedFiles();
if (initialSelection.size() > 0) {
const QUrl url = initialSelection.front();
if (!initialSelection.empty()) {
const QUrl &url = initialSelection.constFirst();
if (url.isLocalFile()) {
QFileInfo info(url.toLocalFile());
if (!info.isDir())
@ -1698,7 +1698,7 @@ void QWindowsXpNativeFileDialog::doExec(HWND owner)
const QStringList nameFilters = m_options->nameFilters();
if (selectedFilterIndex >= 0 && selectedFilterIndex < nameFilters.size())
m_data.setSelectedNameFilter(nameFilters.at(selectedFilterIndex));
QUrl firstFile = selectedFiles.front();
const QUrl &firstFile = selectedFiles.constFirst();
m_data.setDirectory(firstFile.adjusted(QUrl::RemoveFilename));
m_result = QPlatformDialogHelper::Accepted;
emit accepted();
@ -1727,7 +1727,7 @@ int QWindowsXpNativeFileDialog::existingDirCallback(HWND hwnd, UINT uMsg, LPARAM
switch (uMsg) {
case BFFM_INITIALIZED: {
if (!m_title.isEmpty())
SetWindowText(hwnd, (wchar_t *)m_title.utf16());
SetWindowText(hwnd, reinterpret_cast<const wchar_t *>(m_title.utf16()));
const QString initialFile = QDir::toNativeSeparators(m_data.directory().toLocalFile());
if (!initialFile.isEmpty())
SendMessage(hwnd, BFFM_SETSELECTION, TRUE, LPARAM(initialFile.utf16()));

View File

@ -889,19 +889,19 @@ EGLConfig QWindowsEGLContext::chooseConfig(const QSurfaceFormat &format)
EGLint green = 0;
EGLint blue = 0;
EGLint alpha = 0;
for (int i = 0; i < configs.size(); ++i) {
for (const EGLConfig &config : configs) {
if (confAttrRed)
QWindowsEGLStaticContext::libEGL.eglGetConfigAttrib(display, configs[i], EGL_RED_SIZE, &red);
QWindowsEGLStaticContext::libEGL.eglGetConfigAttrib(display, config, EGL_RED_SIZE, &red);
if (confAttrGreen)
QWindowsEGLStaticContext::libEGL.eglGetConfigAttrib(display, configs[i], EGL_GREEN_SIZE, &green);
QWindowsEGLStaticContext::libEGL.eglGetConfigAttrib(display, config, EGL_GREEN_SIZE, &green);
if (confAttrBlue)
QWindowsEGLStaticContext::libEGL.eglGetConfigAttrib(display, configs[i], EGL_BLUE_SIZE, &blue);
QWindowsEGLStaticContext::libEGL.eglGetConfigAttrib(display, config, EGL_BLUE_SIZE, &blue);
if (confAttrAlpha)
QWindowsEGLStaticContext::libEGL.eglGetConfigAttrib(display, configs[i], EGL_ALPHA_SIZE, &alpha);
QWindowsEGLStaticContext::libEGL.eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE, &alpha);
if (red == confAttrRed && green == confAttrGreen
&& blue == confAttrBlue && alpha == confAttrAlpha)
return configs[i];
return config;
}
} while (reduceConfigAttributes(&configureAttributes));

View File

@ -206,18 +206,12 @@ bool QWindowsOpengl32DLL::init(bool softwareRendering)
BOOL QWindowsOpengl32DLL::swapBuffers(HDC dc)
{
if (moduleIsNotOpengl32())
return wglSwapBuffers(dc);
else
return SwapBuffers(dc);
return moduleIsNotOpengl32() ? wglSwapBuffers(dc) : SwapBuffers(dc);
}
BOOL QWindowsOpengl32DLL::setPixelFormat(HDC dc, int pf, const PIXELFORMATDESCRIPTOR *pfd)
{
if (moduleIsNotOpengl32())
return wglSetPixelFormat(dc, pf, pfd);
else
return SetPixelFormat(dc, pf, pfd);
return moduleIsNotOpengl32() ? wglSetPixelFormat(dc, pf, pfd) : SetPixelFormat(dc, pf, pfd);
}
QWindowsOpenGLContext *QOpenGLStaticContext::createContext(QOpenGLContext *context)

View File

@ -255,8 +255,7 @@ QWindowsIntegrationPrivate::QWindowsIntegrationPrivate(const QStringList &paramL
QWindowsIntegrationPrivate::~QWindowsIntegrationPrivate()
{
if (m_fontDatabase)
delete m_fontDatabase;
delete m_fontDatabase;
}
QWindowsIntegration *QWindowsIntegration::m_instance = nullptr;

View File

@ -653,8 +653,8 @@ static inline int asciiToKeycode(char a, int state)
void QWindowsKeyMapper::deleteLayouts()
{
for (size_t i = 0; i < NumKeyboardLayoutItems; ++i)
keyLayout[i].exists = false;
for (KeyboardLayoutItem &k : keyLayout)
k.exists = false;
}
void QWindowsKeyMapper::changeKeyboard()
@ -1111,7 +1111,8 @@ bool QWindowsKeyMapper::translateKeyEventInternal(QWindow *window, const MSG &ms
if (uch.isHighSurrogate()) {
m_lastHighSurrogate = uch;
return true;
} else if (uch.isLowSurrogate() && !m_lastHighSurrogate.isNull()) {
}
if (uch.isLowSurrogate() && !m_lastHighSurrogate.isNull()) {
if (QObject *focusObject = QGuiApplication::focusObject()) {
const QChar chars[2] = {m_lastHighSurrogate, uch};
QInputMethodEvent event;

View File

@ -628,7 +628,8 @@ bool QWindowsMimeText::convertFromMime(const FORMATETC &formatetc, const QMimeDa
}
o[j]=0;
return setData(r, pmedium);
} else if (cf == CF_UNICODETEXT) {
}
if (cf == CF_UNICODETEXT) {
QString str = mimeData->text();
const QChar *u = str.unicode();
QString res;
@ -750,9 +751,9 @@ QWindowsMimeURI::QWindowsMimeURI()
bool QWindowsMimeURI::canConvertFromMime(const FORMATETC &formatetc, const QMimeData *mimeData) const
{
if (mimeData->hasUrls() && getCf(formatetc) == CF_HDROP) {
QList<QUrl> urls = mimeData->urls();
for (int i=0; i<urls.size(); i++) {
if (!urls.at(i).toLocalFile().isEmpty())
const QList<QUrl> urls = mimeData->urls();
for (const QUrl &url : urls) {
if (url.isLocalFile())
return true;
}
}
@ -763,11 +764,11 @@ bool QWindowsMimeURI::convertFromMime(const FORMATETC &formatetc, const QMimeDat
{
if (canConvertFromMime(formatetc, mimeData)) {
if (getCf(formatetc) == CF_HDROP) {
QList<QUrl> urls = mimeData->urls();
const QList<QUrl> &urls = mimeData->urls();
QStringList fileNames;
int size = sizeof(DROPFILES)+2;
for (int i=0; i<urls.size(); i++) {
QString fn = QDir::toNativeSeparators(urls.at(i).toLocalFile());
for (const QUrl &url : urls) {
const QString fn = QDir::toNativeSeparators(url.toLocalFile());
if (!fn.isEmpty()) {
size += sizeof(ushort) * size_t(fn.length() + 1);
fileNames.append(fn);
@ -792,7 +793,8 @@ bool QWindowsMimeURI::convertFromMime(const FORMATETC &formatetc, const QMimeDat
*f = 0;
return setData(result, pmedium);
} else if (getCf(formatetc) == CF_INETURL_W) {
}
if (getCf(formatetc) == CF_INETURL_W) {
QList<QUrl> urls = mimeData->urls();
QByteArray result;
if (!urls.isEmpty()) {
@ -803,7 +805,8 @@ bool QWindowsMimeURI::convertFromMime(const FORMATETC &formatetc, const QMimeDat
result.append('\0');
result.append('\0');
return setData(result, pmedium);
} else if (getCf(formatetc) == CF_INETURL) {
}
if (getCf(formatetc) == CF_INETURL) {
QList<QUrl> urls = mimeData->urls();
QByteArray result;
if (!urls.isEmpty())
@ -873,7 +876,7 @@ QVariant QWindowsMimeURI::convertToMime(const QString &mimeType, LPDATAOBJECT pD
if (preferredType == QVariant::Url && urls.size() == 1)
return urls.at(0);
else if (!urls.isEmpty())
if (!urls.isEmpty())
return urls;
} else if (canGetData(CF_INETURL_W, pDataObj)) {
QByteArray data = getData(CF_INETURL_W, pDataObj);
@ -1076,10 +1079,8 @@ QString QWindowsMimeImage::mimeForFormat(const FORMATETC &formatetc) const
bool QWindowsMimeImage::canConvertToMime(const QString &mimeType, IDataObject *pDataObj) const
{
if (mimeType == QLatin1String("application/x-qt-image") &&
(canGetData(CF_DIB, pDataObj) || canGetData(CF_PNG, pDataObj)))
return true;
return false;
return mimeType == QLatin1String("application/x-qt-image")
&& (canGetData(CF_DIB, pDataObj) || canGetData(CF_PNG, pDataObj));
}
bool QWindowsMimeImage::canConvertFromMime(const FORMATETC &formatetc, const QMimeData *mimeData) const
@ -1135,7 +1136,7 @@ bool QWindowsMimeImage::hasOriginalDIBV5(IDataObject *pDataObj) const
CoTaskMemFree(fc.ptd);
if (fc.cfFormat == CF_DIB)
break;
else if (fc.cfFormat == CF_DIBV5) {
if (fc.cfFormat == CF_DIBV5) {
isSynthesized = false;
break;
}
@ -1329,7 +1330,7 @@ QStringList QLastResortMimes::excludeList;
QLastResortMimes::QLastResortMimes()
{
//MIME Media-Types
if (!ianaTypes.size()) {
if (ianaTypes.isEmpty()) {
ianaTypes.append(QStringLiteral("application/"));
ianaTypes.append(QStringLiteral("audio/"));
ianaTypes.append(QStringLiteral("example/"));
@ -1341,7 +1342,7 @@ QLastResortMimes::QLastResortMimes()
ianaTypes.append(QStringLiteral("video/"));
}
//Types handled by other classes
if (!excludeList.size()) {
if (excludeList.isEmpty()) {
excludeList.append(QStringLiteral("HTML Format"));
excludeList.append(QStringLiteral("UniformResourceLocator"));
excludeList.append(QStringLiteral("text/html"));

View File

@ -363,9 +363,9 @@ bool QWindowsMouseHandler::translateMouseEvent(QWindow *window, HWND hwnd,
}
m_previousCaptureWindow = window;
return true;
} else if (m_leftButtonDown && !actualLeftDown) {
m_leftButtonDown = false;
}
if (m_leftButtonDown && !actualLeftDown)
m_leftButtonDown = false;
}
// In this context, neither an invisible nor a transparent window (transparent regarding mouse

View File

@ -275,11 +275,11 @@ QFunctionPointer QWindowsNativeInterface::platformFunction(const QByteArray &fun
{
if (function == QWindowsWindowFunctions::setTouchWindowTouchTypeIdentifier())
return QFunctionPointer(QWindowsWindow::setTouchWindowTouchTypeStatic);
else if (function == QWindowsWindowFunctions::setHasBorderInFullScreenIdentifier())
if (function == QWindowsWindowFunctions::setHasBorderInFullScreenIdentifier())
return QFunctionPointer(QWindowsWindow::setHasBorderInFullScreenStatic);
else if (function == QWindowsWindowFunctions::setWindowActivationBehaviorIdentifier())
if (function == QWindowsWindowFunctions::setWindowActivationBehaviorIdentifier())
return QFunctionPointer(QWindowsNativeInterface::setWindowActivationBehavior);
else if (function == QWindowsWindowFunctions::isTabletModeIdentifier())
if (function == QWindowsWindowFunctions::isTabletModeIdentifier())
return QFunctionPointer(QWindowsNativeInterface::isTabletMode);
return nullptr;
}

View File

@ -365,10 +365,9 @@ QWindowsOleEnumFmtEtc::Clone(LPENUMFORMATETC FAR* newEnum)
if (result->isNull()) {
delete result;
return ResultFromScode(E_OUTOFMEMORY);
} else {
*newEnum = result;
}
*newEnum = result;
return NOERROR;
}

View File

@ -69,7 +69,7 @@ static inline QDpi monitorDPI(HMONITOR hMonitor)
if (SUCCEEDED(QWindowsContext::shcoredll.getDpiForMonitor(hMonitor, 0, &dpiX, &dpiY)))
return QDpi(dpiX, dpiY);
}
return QDpi(0, 0);
return {0, 0};
}
typedef QList<QWindowsScreenData> WindowsScreenDataList;
@ -401,7 +401,8 @@ QPlatformScreen::SubpixelAntialiasingType QWindowsScreen::subpixelAntialiasingTy
{
QPlatformScreen::SubpixelAntialiasingType type = QPlatformScreen::subpixelAntialiasingTypeHint();
if (type == QPlatformScreen::Subpixel_None) {
QSettings settings(QLatin1String("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Avalon.Graphics\\DISPLAY1"), QSettings::NativeFormat);
QSettings settings(QLatin1String(R"(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Avalon.Graphics\DISPLAY1)"),
QSettings::NativeFormat);
int registryValue = settings.value(QLatin1String("PixelStructure"), -1).toInt();
switch (registryValue) {
case 0:

View File

@ -108,7 +108,7 @@ inline QPointF QWindowsTabletDeviceData::scaleCoordinates(int coordX, int coordY
((coordY - minY) * qAbs(targetHeight) / qAbs(qreal(maxY - minY))) + targetY :
((qAbs(maxY) - (coordY - minY)) * qAbs(targetHeight) / qAbs(qreal(maxY - minY))) + targetY;
return QPointF(x, y);
return {x, y};
}
template <class Stream>

View File

@ -107,7 +107,7 @@ static inline bool booleanSystemParametersInfo(UINT what, bool defaultValue)
{
BOOL result;
if (SystemParametersInfo(what, 0, &result, 0))
return result ? true : false;
return result != FALSE;
return defaultValue;
}
@ -121,9 +121,9 @@ static inline DWORD dWordSystemParametersInfo(UINT what, DWORD defaultValue)
static inline QColor mixColors(const QColor &c1, const QColor &c2)
{
return QColor ((c1.red() + c2.red()) / 2,
(c1.green() + c2.green()) / 2,
(c1.blue() + c2.blue()) / 2);
return {(c1.red() + c2.red()) / 2,
(c1.green() + c2.green()) / 2,
(c1.blue() + c2.blue()) / 2};
}
static inline QColor getSysColor(int index)

View File

@ -660,7 +660,7 @@ QWindowsWindowData
WindowData result;
result.flags = flags;
const HINSTANCE appinst = (HINSTANCE)GetModuleHandle(0);
const auto appinst = reinterpret_cast<HINSTANCE>(GetModuleHandle(nullptr));
const QString windowClassName = QWindowsContext::instance()->registerWindowClass(w);
@ -1374,18 +1374,12 @@ bool QWindowsWindow::isEmbedded() const
QPoint QWindowsWindow::mapToGlobal(const QPoint &pos) const
{
if (m_data.hwnd)
return QWindowsGeometryHint::mapToGlobal(m_data.hwnd, pos);
else
return pos;
return m_data.hwnd ? QWindowsGeometryHint::mapToGlobal(m_data.hwnd, pos) : pos;
}
QPoint QWindowsWindow::mapFromGlobal(const QPoint &pos) const
{
if (m_data.hwnd)
return QWindowsGeometryHint::mapFromGlobal(m_data.hwnd, pos);
else
return pos;
return m_data.hwnd ? QWindowsGeometryHint::mapFromGlobal(m_data.hwnd, pos) : pos;
}
static inline HWND transientParentHwnd(HWND hwnd)

View File

@ -430,7 +430,7 @@ inline QWindowsWindow *QWindowsWindow::windowsWindowOf(const QWindow *w)
void *QWindowsWindow::userDataOf(HWND hwnd)
{
return (void *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
return reinterpret_cast<void *>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
}
void QWindowsWindow::setUserDataOf(HWND hwnd, void *ud)