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
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
(cherry picked from commit 8d77ee0f2b042af7aec43e1e83eb26d92c2f8234)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Ahmad Samir 2023-05-29 01:04:54 +03:00 committed by Qt Cherry-pick Bot
parent e71dfbb7db
commit f22bedf5af
4 changed files with 13 additions and 12 deletions

View File

@ -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));
}

View File

@ -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);

View File

@ -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();

View File

@ -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;