Misc.: Fix some narrowing integral conversion warnings
Drive-by change: use QByteArrayView instead of allocating a QByteArray. Change-Id: Iaf7acbbdb4efbb101b73b30061ce38dd1fa99ca3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
d8a688adf0
commit
4538bbf4a6
@ -341,13 +341,7 @@ QList<QUrl> QMimeData::urls() const
|
||||
void QMimeData::setUrls(const QList<QUrl> &urls)
|
||||
{
|
||||
Q_D(QMimeData);
|
||||
QList<QVariant> list;
|
||||
const int numUrls = urls.size();
|
||||
list.reserve(numUrls);
|
||||
for (int i = 0; i < numUrls; ++i)
|
||||
list.append(urls.at(i));
|
||||
|
||||
d->setData(textUriListLiteral(), list);
|
||||
d->setData(textUriListLiteral(), QList<QVariant>(urls.cbegin(), urls.cend()));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -199,7 +199,7 @@ bool QLibraryPrivate::load_sys()
|
||||
continue;
|
||||
if (loadHints & QLibrary::LoadArchiveMemberHint) {
|
||||
attempt = name;
|
||||
int lparen = attempt.indexOf(u'(');
|
||||
qsizetype lparen = attempt.indexOf(u'(');
|
||||
if (lparen == -1)
|
||||
lparen = attempt.size();
|
||||
attempt = path + prefixes.at(prefix) + attempt.insert(lparen, suffixes.at(suffix));
|
||||
|
@ -235,7 +235,7 @@ static QString locatePlugin(const QString& fileName)
|
||||
suffixes.prepend(QString());
|
||||
|
||||
// Split up "subdir/filename"
|
||||
const int slash = fileName.lastIndexOf(u'/');
|
||||
const qsizetype slash = fileName.lastIndexOf(u'/');
|
||||
const auto baseName = QStringView{fileName}.mid(slash + 1);
|
||||
const auto basePath = isAbsolute ? QStringView() : QStringView{fileName}.left(slash + 1); // keep the '/'
|
||||
|
||||
|
@ -973,7 +973,7 @@ QCborContainerPrivate *QCborContainerPrivate::grow(QCborContainerPrivate *d, qsi
|
||||
Q_ASSERT(index >= 0);
|
||||
d = detach(d, index + 1);
|
||||
Q_ASSERT(d);
|
||||
int j = d->elements.size();
|
||||
qsizetype j = d->elements.size();
|
||||
while (j++ < index)
|
||||
d->append(Undefined());
|
||||
return d;
|
||||
|
@ -839,7 +839,7 @@ static inline bool scanUtf8Char(const char *&json, const char *end, char32_t *re
|
||||
const auto *usrc = reinterpret_cast<const uchar *>(json);
|
||||
const auto *uend = reinterpret_cast<const uchar *>(end);
|
||||
const uchar b = *usrc++;
|
||||
int res = QUtf8Functions::fromUtf8<QUtf8BaseTraits>(b, result, usrc, uend);
|
||||
qsizetype res = QUtf8Functions::fromUtf8<QUtf8BaseTraits>(b, result, usrc, uend);
|
||||
if (res < 0)
|
||||
return false;
|
||||
|
||||
|
@ -35,7 +35,7 @@ static QByteArray escapedString(const QString &s)
|
||||
while (src != end) {
|
||||
if (cursor >= ba_end - 6) {
|
||||
// ensure we have enough space
|
||||
int pos = cursor - (const uchar *)ba.constData();
|
||||
qptrdiff pos = cursor - (const uchar *)ba.constData();
|
||||
ba.resize(ba.size()*2);
|
||||
cursor = (uchar *)ba.data() + pos;
|
||||
ba_end = (const uchar *)ba.constData() + ba.size();
|
||||
|
@ -3384,7 +3384,9 @@ QString QCalendarBackend::dateTimeToString(QStringView format, const QDateTime &
|
||||
}
|
||||
|
||||
const QChar c = format.at(i);
|
||||
qsizetype repeat = qt_repeatCount(format.mid(i));
|
||||
qsizetype rep = qt_repeatCount(format.mid(i));
|
||||
Q_ASSERT(rep < std::numeric_limits<int>::max());
|
||||
int repeat = int(rep);
|
||||
bool used = false;
|
||||
if (formatDate) {
|
||||
switch (c.unicode()) {
|
||||
|
@ -800,7 +800,7 @@ void QFutureInterfaceBasePrivate::connectOutputInterface(QFutureCallOutInterface
|
||||
void QFutureInterfaceBasePrivate::disconnectOutputInterface(QFutureCallOutInterface *interface)
|
||||
{
|
||||
QMutexLocker lock(&m_mutex);
|
||||
const int index = outputConnections.indexOf(interface);
|
||||
const qsizetype index = outputConnections.indexOf(interface);
|
||||
if (index == -1)
|
||||
return;
|
||||
outputConnections.removeAt(index);
|
||||
|
@ -259,7 +259,7 @@ struct QWindowGeometrySpecification
|
||||
static inline int nextGeometryToken(const QByteArray &a, int &pos, char *op)
|
||||
{
|
||||
*op = 0;
|
||||
const int size = a.size();
|
||||
const qsizetype size = a.size();
|
||||
if (pos >= size)
|
||||
return -1;
|
||||
|
||||
@ -1311,7 +1311,7 @@ static void init_platform(const QString &pluginNamesWithArguments, const QString
|
||||
if (!platformArguments.isEmpty()) {
|
||||
if (QObject *nativeInterface = QGuiApplicationPrivate::platform_integration->nativeInterface()) {
|
||||
for (const QString &argument : std::as_const(platformArguments)) {
|
||||
const int equalsPos = argument.indexOf(u'=');
|
||||
const qsizetype equalsPos = argument.indexOf(u'=');
|
||||
const QByteArray name =
|
||||
equalsPos != -1 ? argument.left(equalsPos).toUtf8() : argument.toUtf8();
|
||||
const QVariant value =
|
||||
@ -1331,7 +1331,7 @@ static void init_plugins(const QList<QByteArray> &pluginList)
|
||||
{
|
||||
for (int i = 0; i < pluginList.size(); ++i) {
|
||||
QByteArray pluginSpec = pluginList.at(i);
|
||||
int colonPos = pluginSpec.indexOf(':');
|
||||
qsizetype colonPos = pluginSpec.indexOf(':');
|
||||
QObject *plugin;
|
||||
if (colonPos < 0)
|
||||
plugin = QGenericPluginFactory::create(QLatin1StringView(pluginSpec), QString());
|
||||
@ -1598,7 +1598,7 @@ void Q_TRACE_INSTRUMENT(qtgui) QGuiApplicationPrivate::init()
|
||||
++i;
|
||||
if (argv[i] && *argv[i]) {
|
||||
session_id = QString::fromLatin1(argv[i]);
|
||||
int p = session_id.indexOf(u'_');
|
||||
qsizetype p = session_id.indexOf(u'_');
|
||||
if (p >= 0) {
|
||||
session_key = session_id.mid(p +1);
|
||||
session_id = session_id.left(p);
|
||||
|
@ -699,7 +699,7 @@ QVector<QHighDpiScaling::ScreenFactor> QHighDpiScaling::parseScreenScaleFactorsS
|
||||
// - a semicolon-separated name=factor list: "foo=1.5;bar=2;baz=3"
|
||||
const auto specs = screenScaleFactors.split(u';');
|
||||
for (const auto &spec : specs) {
|
||||
const int equalsPos = spec.lastIndexOf(u'=');
|
||||
const qsizetype equalsPos = spec.lastIndexOf(u'=');
|
||||
if (equalsPos == -1) {
|
||||
// screens in order
|
||||
bool ok;
|
||||
|
@ -20,7 +20,7 @@ static QStringList imageMimeFormats(const QList<QByteArray> &imageFormats)
|
||||
formats.append("image/"_L1 + QLatin1StringView(format.toLower()));
|
||||
|
||||
//put png at the front because it is best
|
||||
int pngIndex = formats.indexOf("image/png"_L1);
|
||||
const qsizetype pngIndex = formats.indexOf("image/png"_L1);
|
||||
if (pngIndex != -1 && pngIndex != 0)
|
||||
formats.move(pngIndex, 0);
|
||||
|
||||
|
@ -940,7 +940,7 @@ QKeySequence QKeySequence::mnemonic(const QString &text)
|
||||
return ret;
|
||||
|
||||
bool found = false;
|
||||
int p = 0;
|
||||
qsizetype p = 0;
|
||||
while (p >= 0) {
|
||||
p = text.indexOf(u'&', p) + 1;
|
||||
if (p <= 0 || p >= (int)text.size())
|
||||
@ -993,7 +993,7 @@ int QKeySequence::assign(const QString &ks, QKeySequence::SequenceFormat format)
|
||||
{
|
||||
QString keyseq = ks;
|
||||
int n = 0;
|
||||
int p = 0, diff = 0;
|
||||
qsizetype p = 0, diff = 0;
|
||||
|
||||
// Run through the whole string, but stop
|
||||
// if we have MaxKeyCount keys before the end.
|
||||
@ -1111,8 +1111,8 @@ int QKeySequencePrivate::decodeString(QString accel, QKeySequence::SequenceForma
|
||||
return Qt::Key_unknown;
|
||||
#endif
|
||||
|
||||
int i = 0;
|
||||
int lastI = 0;
|
||||
qsizetype i = 0;
|
||||
qsizetype lastI = 0;
|
||||
while ((i = sl.indexOf(u'+', i + 1)) != -1) {
|
||||
const QStringView sub = QStringView{sl}.mid(lastI, i - lastI + 1);
|
||||
// If we get here the shortcuts contains at least one '+'. We break up
|
||||
@ -1146,7 +1146,7 @@ int QKeySequencePrivate::decodeString(QString accel, QKeySequence::SequenceForma
|
||||
lastI = i + 1;
|
||||
}
|
||||
|
||||
int p = accel.lastIndexOf(u'+', accel.size() - 2); // -2 so that Ctrl++ works
|
||||
qsizetype p = accel.lastIndexOf(u'+', accel.size() - 2); // -2 so that Ctrl++ works
|
||||
QStringView accelRef(accel);
|
||||
if (p > 0)
|
||||
accelRef = accelRef.mid(p + 1);
|
||||
|
@ -564,7 +564,7 @@ bool QPointingDevicePrivate::addPassiveGrabber(const QPointerEvent *event, const
|
||||
|
||||
bool QPointingDevicePrivate::setPassiveGrabberContext(QPointingDevicePrivate::EventPointData *epd, QObject *grabber, QObject *context)
|
||||
{
|
||||
int i = epd->passiveGrabbers.indexOf(grabber);
|
||||
qsizetype i = epd->passiveGrabbers.indexOf(grabber);
|
||||
if (i < 0)
|
||||
return false;
|
||||
if (epd->passiveGrabbersContext.size() <= i)
|
||||
@ -581,7 +581,7 @@ bool QPointingDevicePrivate::removePassiveGrabber(const QPointerEvent *event, co
|
||||
qWarning() << "point is not in activePoints" << point;
|
||||
return false;
|
||||
}
|
||||
int i = persistentPoint->passiveGrabbers.indexOf(grabber);
|
||||
qsizetype i = persistentPoint->passiveGrabbers.indexOf(grabber);
|
||||
if (i >= 0) {
|
||||
if (Q_UNLIKELY(lcPointerGrab().isDebugEnabled())) {
|
||||
qCDebug(lcPointerGrab) << name << "point" << point.id() << point.state()
|
||||
@ -644,7 +644,7 @@ void QPointingDevicePrivate::removeGrabber(QObject *grabber, bool cancel)
|
||||
cancel ? QPointingDevice::CancelGrabExclusive : QPointingDevice::UngrabExclusive,
|
||||
nullptr, epd.eventPoint);
|
||||
}
|
||||
int pi = epd.passiveGrabbers.indexOf(grabber);
|
||||
qsizetype pi = epd.passiveGrabbers.indexOf(grabber);
|
||||
if (pi >= 0) {
|
||||
qCDebug(lcPointerGrab) << name << "point" << epd.eventPoint.id() << epd.eventPoint.state()
|
||||
<< ": removing passive grabber" << grabber;
|
||||
|
@ -431,14 +431,14 @@ void QWindowPrivate::updateSiblingPosition(SiblingPosition position)
|
||||
|
||||
QObjectList &siblings = q->parent()->d_ptr->children;
|
||||
|
||||
const int siblingCount = siblings.size() - 1;
|
||||
const qsizetype siblingCount = siblings.size() - 1;
|
||||
if (siblingCount == 0)
|
||||
return;
|
||||
|
||||
const int currentPosition = siblings.indexOf(q);
|
||||
const qsizetype currentPosition = siblings.indexOf(q);
|
||||
Q_ASSERT(currentPosition >= 0);
|
||||
|
||||
const int targetPosition = position == PositionTop ? siblingCount : 0;
|
||||
const qsizetype targetPosition = position == PositionTop ? siblingCount : 0;
|
||||
|
||||
if (currentPosition == targetPosition)
|
||||
return;
|
||||
|
@ -138,7 +138,7 @@ static bool handleWindowSystemEvent(Args ...args)
|
||||
return QWindowSystemHelper<Delivery>::template handleEvent<EventType>(args...);
|
||||
}
|
||||
|
||||
int QWindowSystemInterfacePrivate::windowSystemEventsQueued()
|
||||
qsizetype QWindowSystemInterfacePrivate::windowSystemEventsQueued()
|
||||
{
|
||||
return windowSystemEventQueue.count();
|
||||
}
|
||||
@ -791,7 +791,7 @@ void QWindowSystemInterface::handleScreenRemoved(QPlatformScreen *platformScreen
|
||||
void QWindowSystemInterface::handlePrimaryScreenChanged(QPlatformScreen *newPrimary)
|
||||
{
|
||||
QScreen *newPrimaryScreen = newPrimary->screen();
|
||||
int indexOfScreen = QGuiApplicationPrivate::screen_list.indexOf(newPrimaryScreen);
|
||||
qsizetype indexOfScreen = QGuiApplicationPrivate::screen_list.indexOf(newPrimaryScreen);
|
||||
Q_ASSERT(indexOfScreen >= 0);
|
||||
if (indexOfScreen == 0)
|
||||
return;
|
||||
@ -1058,7 +1058,7 @@ Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QWindowSystemInterface::TouchPo
|
||||
*/
|
||||
bool QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ProcessEventsFlags flags)
|
||||
{
|
||||
const int count = QWindowSystemInterfacePrivate::windowSystemEventQueue.count();
|
||||
const qsizetype count = QWindowSystemInterfacePrivate::windowSystemEventQueue.count();
|
||||
if (!count)
|
||||
return false;
|
||||
if (!QGuiApplication::instance()) {
|
||||
|
@ -473,7 +473,7 @@ public:
|
||||
}
|
||||
void append(WindowSystemEvent *e)
|
||||
{ const QMutexLocker locker(&mutex); impl.append(e); }
|
||||
int count() const
|
||||
qsizetype count() const
|
||||
{ const QMutexLocker locker(&mutex); return impl.size(); }
|
||||
WindowSystemEvent *peekAtFirstOfType(EventType t) const
|
||||
{
|
||||
@ -500,7 +500,7 @@ public:
|
||||
|
||||
static WindowSystemEventList windowSystemEventQueue;
|
||||
|
||||
static int windowSystemEventsQueued();
|
||||
static qsizetype windowSystemEventsQueued();
|
||||
static bool nonUserInputEventsQueued();
|
||||
static WindowSystemEvent *getWindowSystemEvent();
|
||||
static WindowSystemEvent *getNonUserInputWindowSystemEvent();
|
||||
|
@ -88,13 +88,12 @@ QList<EGLint> q_createConfigAttributesFromFormat(const QSurfaceFormat &format)
|
||||
|
||||
bool q_reduceConfigAttributes(QList<EGLint> *configAttributes)
|
||||
{
|
||||
int i = -1;
|
||||
// Reduce the complexity of a configuration request to ask for less
|
||||
// because the previous request did not result in success. Returns
|
||||
// true if the complexity was reduced, or false if no further
|
||||
// reductions in complexity are possible.
|
||||
|
||||
i = configAttributes->indexOf(EGL_SWAP_BEHAVIOR);
|
||||
qsizetype i = configAttributes->indexOf(EGL_SWAP_BEHAVIOR);
|
||||
if (i >= 0) {
|
||||
configAttributes->remove(i,2);
|
||||
}
|
||||
@ -258,7 +257,7 @@ EGLConfig QEglConfigChooser::chooseConfig()
|
||||
|
||||
// Fetch all of the matching configurations and find the
|
||||
// first that matches the pixel format we wanted.
|
||||
int i = configureAttributes.indexOf(EGL_RED_SIZE);
|
||||
qsizetype i = configureAttributes.indexOf(EGL_RED_SIZE);
|
||||
m_confAttrRed = configureAttributes.at(i+1);
|
||||
i = configureAttributes.indexOf(EGL_GREEN_SIZE);
|
||||
m_confAttrGreen = configureAttributes.at(i+1);
|
||||
@ -268,7 +267,8 @@ EGLConfig QEglConfigChooser::chooseConfig()
|
||||
m_confAttrAlpha = i == -1 ? 0 : configureAttributes.at(i+1);
|
||||
|
||||
QList<EGLConfig> configs(matching);
|
||||
eglChooseConfig(display(), configureAttributes.constData(), configs.data(), configs.size(), &matching);
|
||||
eglChooseConfig(display(), configureAttributes.constData(), configs.data(),
|
||||
EGLint(configs.size()), &matching);
|
||||
if (!cfg && matching > 0)
|
||||
cfg = configs.first();
|
||||
|
||||
|
@ -385,7 +385,8 @@ static bool readGpuFeatures(const QOpenGLConfig::Gpu &gpu,
|
||||
QJsonParseError error;
|
||||
const QJsonDocument document = QJsonDocument::fromJson(jsonAsciiData, &error);
|
||||
if (document.isNull()) {
|
||||
const int lineNumber = 1 + jsonAsciiData.left(error.offset).count('\n');
|
||||
const qsizetype lineNumber =
|
||||
QByteArrayView(jsonAsciiData).left(error.offset).count('\n') + 1;
|
||||
QTextStream str(errorMessage);
|
||||
str << "Failed to parse data: \"" << error.errorString()
|
||||
<< "\" at line " << lineNumber << " (offset: "
|
||||
|
Loading…
Reference in New Issue
Block a user