diff options
author | Ahmad Samir <a.samirh78@gmail.com> | 2023-05-29 01:04:54 +0300 |
---|---|---|
committer | Ahmad Samir <a.samirh78@gmail.com> | 2023-06-05 23:35:20 +0300 |
commit | 8d77ee0f2b042af7aec43e1e83eb26d92c2f8234 (patch) | |
tree | 2ebd90e7675c494b0cd9420cb2eb2ccc3feb1724 | |
parent | 3ee289e40d1a7d3582cb1a3a304e681d2085bb82 (diff) |
Misc.: fix narrowing conversion warnings with explicit cast to int
And using qsizetype in some places.
::pathconf() returns long.
Found by using -Wshorten-64-to-32 clang compiler flag, or adding that
flag to the flags clangd uses.
Change-Id: I9f9abd3d4d6fe73f525eec869ceabc799317f3d6
Pick-to: 6.6 6.5
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
-rw-r--r-- | src/gui/kernel/qplatformdialoghelper.cpp | 2 | ||||
-rw-r--r-- | src/gui/kernel/qplatformgraphicsbufferhelper.cpp | 4 | ||||
-rw-r--r-- | src/widgets/dialogs/qfiledialog.cpp | 15 | ||||
-rw-r--r-- | src/widgets/dialogs/qfiledialog_p.h | 4 |
4 files changed, 13 insertions, 12 deletions
diff --git a/src/gui/kernel/qplatformdialoghelper.cpp b/src/gui/kernel/qplatformdialoghelper.cpp index c14c0f0142..7153c90f50 100644 --- a/src/gui/kernel/qplatformdialoghelper.cpp +++ b/src/gui/kernel/qplatformdialoghelper.cpp @@ -905,7 +905,7 @@ const QList<QMessageDialogOptions::CustomButton> &QMessageDialogOptions::customB const QMessageDialogOptions::CustomButton *QMessageDialogOptions::customButton(int id) { - int i = d->customButtons.indexOf(CustomButton(id)); + const int i = int(d->customButtons.indexOf(CustomButton(id))); return (i < 0 ? nullptr : &d->customButtons.at(i)); } diff --git a/src/gui/kernel/qplatformgraphicsbufferhelper.cpp b/src/gui/kernel/qplatformgraphicsbufferhelper.cpp index 4c2b9e5b39..0ec2308453 100644 --- a/src/gui/kernel/qplatformgraphicsbufferhelper.cpp +++ b/src/gui/kernel/qplatformgraphicsbufferhelper.cpp @@ -179,14 +179,14 @@ bool QPlatformGraphicsBufferHelper::bindSWToTexture(const QPlatformGraphicsBuffe QRect rect = subRect; if (rect.isNull() || rect == QRect(QPoint(0,0),size)) { if (needsRowLength) - funcs->glPixelStorei(GL_UNPACK_ROW_LENGTH, image.bytesPerLine() / 4); + funcs->glPixelStorei(GL_UNPACK_ROW_LENGTH, GLint(image.bytesPerLine() / 4)); funcs->glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, size.width(), size.height(), 0, GL_RGBA, pixelType, image.constBits()); if (needsRowLength) funcs->glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); } else { if (!ctx->isOpenGLES() || ctx->format().majorVersion() >= 3) { // OpenGL 2.1+ or OpenGL ES/3+ - funcs->glPixelStorei(GL_UNPACK_ROW_LENGTH, image.bytesPerLine() / 4); + funcs->glPixelStorei(GL_UNPACK_ROW_LENGTH, GLint(image.bytesPerLine() / 4)); funcs->glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x(), rect.y(), rect.width(), rect.height(), GL_RGBA, pixelType, image.constScanLine(rect.y()) + rect.x() * 4); funcs->glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp index 18395e928a..1f88608fe9 100644 --- a/src/widgets/dialogs/qfiledialog.cpp +++ b/src/widgets/dialogs/qfiledialog.cpp @@ -651,7 +651,7 @@ void QFileDialogPrivate::retranslateStrings() if (proxyModel) abstractModel = proxyModel; #endif - int total = qMin(abstractModel->columnCount(QModelIndex()), actions.size() + 1); + const int total = qMin(abstractModel->columnCount(QModelIndex()), int(actions.size() + 1)); for (int i = 1; i < total; ++i) { actions.at(i - 1)->setText(QFileDialog::tr("Show ") + abstractModel->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); } @@ -1770,7 +1770,7 @@ QLineEdit *QFileDialogPrivate::lineEdit() const { return (QLineEdit*)qFileDialogUi->fileNameEdit; } -int QFileDialogPrivate::maxNameLength(const QString &path) +long QFileDialogPrivate::maxNameLength(const QString &path) { #if defined(Q_OS_UNIX) return ::pathconf(QFile::encodeName(path).data(), _PC_NAME_MAX); @@ -2730,7 +2730,7 @@ void QFileDialog::accept() } if (!info.exists()) { - int maxNameLength = d->maxNameLength(info.path()); + const long maxNameLength = d->maxNameLength(info.path()); if (maxNameLength >= 0 && info.fileName().size() > maxNameLength) return; } @@ -2866,7 +2866,7 @@ bool QFileDialogPrivate::restoreWidgetState(QStringList &history, int splitterPo if (proxyModel) abstractModel = proxyModel; #endif - int total = qMin(abstractModel->columnCount(QModelIndex()), actions.size() + 1); + const int total = qMin(abstractModel->columnCount(QModelIndex()), int(actions.size() + 1)); for (int i = 1; i < total; ++i) actions.at(i - 1)->setChecked(!headerView->isSectionHidden(i)); @@ -3109,7 +3109,8 @@ void QFileDialogPrivate::_q_showHeader(QAction *action) { Q_Q(QFileDialog); QActionGroup *actionGroup = qobject_cast<QActionGroup*>(q->sender()); - qFileDialogUi->treeView->header()->setSectionHidden(actionGroup->actions().indexOf(action) + 1, !action->isChecked()); + qFileDialogUi->treeView->header()->setSectionHidden(int(actionGroup->actions().indexOf(action) + 1), + !action->isChecked()); } #if QT_CONFIG(proxymodel) @@ -3671,7 +3672,7 @@ void QFileDialogPrivate::_q_updateOkButton() break; } if (!idx.isValid()) { - int maxLength = maxNameLength(fileDir); + const long maxLength = maxNameLength(fileDir); enableButton = maxLength < 0 || fileName.size() <= maxLength; } break; @@ -3803,7 +3804,7 @@ void QFileDialogPrivate::_q_useNameFilter(int index) QString fileName = lineEdit()->text(); const QString fileNameExtension = QFileInfo(fileName).suffix(); if (!fileNameExtension.isEmpty() && !newNameFilterExtension.isEmpty()) { - const int fileNameExtensionLength = fileNameExtension.size(); + const qsizetype fileNameExtensionLength = fileNameExtension.size(); fileName.replace(fileName.size() - fileNameExtensionLength, fileNameExtensionLength, newNameFilterExtension); qFileDialogUi->listView->clearSelection(); diff --git a/src/widgets/dialogs/qfiledialog_p.h b/src/widgets/dialogs/qfiledialog_p.h index c2111415f5..dc5e33d7e4 100644 --- a/src/widgets/dialogs/qfiledialog_p.h +++ b/src/widgets/dialogs/qfiledialog_p.h @@ -120,11 +120,11 @@ public: QLineEdit *lineEdit() const; - static int maxNameLength(const QString &path); + static long maxNameLength(const QString &path); QString basename(const QString &path) const { - int separator = QDir::toNativeSeparators(path).lastIndexOf(QDir::separator()); + const qsizetype separator = QDir::toNativeSeparators(path).lastIndexOf(QDir::separator()); if (separator != -1) return path.mid(separator + 1); return path; |