aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-11-09 10:46:07 +0100
committerUlf Hermann <ulf.hermann@qt.io>2020-11-09 18:09:30 +0100
commitd7008c79d4ec023527ebfc118ad47f40075f244d (patch)
treece4e1b3e4148820fd5682ee1877a7626274cdb59 /src/qml
parent5824283a7804e7975140c17731329786045ef432 (diff)
QQmlListProperty: Use qsizetype rather than int for sizes
[ChangeLog][QtQml] The QQmlListProperty callback functions use qsizetype now as type for the size of a list. This is in line with the containers that you might use to back the list. Fixes: QTBUG-88269 Change-Id: Ia38403cb32f241e6c70e1a580dbeff1d6d694331 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml')
-rw-r--r--src/qml/qml/qqmlcontext.cpp4
-rw-r--r--src/qml/qml/qqmlcontext_p.h4
-rw-r--r--src/qml/qml/qqmllist.cpp12
-rw-r--r--src/qml/qml/qqmllist.h32
-rw-r--r--src/qml/qml/qqmlproperty.cpp4
-rw-r--r--src/qml/qml/qqmlvmemetaobject.cpp6
6 files changed, 31 insertions, 31 deletions
diff --git a/src/qml/qml/qqmlcontext.cpp b/src/qml/qml/qqmlcontext.cpp
index 65cf6b3686..c6aab78a63 100644
--- a/src/qml/qml/qqmlcontext.cpp
+++ b/src/qml/qml/qqmlcontext.cpp
@@ -441,7 +441,7 @@ QUrl QQmlContext::baseUrl() const
return d->m_data->baseUrl();
}
-int QQmlContextPrivate::context_count(QQmlListProperty<QObject> *prop)
+qsizetype QQmlContextPrivate::context_count(QQmlListProperty<QObject> *prop)
{
QQmlContext *context = static_cast<QQmlContext*>(prop->object);
QQmlContextPrivate *d = QQmlContextPrivate::get(context);
@@ -453,7 +453,7 @@ int QQmlContextPrivate::context_count(QQmlListProperty<QObject> *prop)
return ((const QList<QObject> *)d->propertyValue(contextProperty).constData())->count();
}
-QObject *QQmlContextPrivate::context_at(QQmlListProperty<QObject> *prop, int index)
+QObject *QQmlContextPrivate::context_at(QQmlListProperty<QObject> *prop, qsizetype index)
{
QQmlContext *context = static_cast<QQmlContext*>(prop->object);
QQmlContextPrivate *d = QQmlContextPrivate::get(context);
diff --git a/src/qml/qml/qqmlcontext_p.h b/src/qml/qml/qqmlcontext_p.h
index e1b2e9d41d..1c2cb7ff67 100644
--- a/src/qml/qml/qqmlcontext_p.h
+++ b/src/qml/qml/qqmlcontext_p.h
@@ -78,8 +78,8 @@ public:
return static_cast<QQmlContext *>(context->q_func());
}
- static int context_count(QQmlListProperty<QObject> *);
- static QObject *context_at(QQmlListProperty<QObject> *, int);
+ static qsizetype context_count(QQmlListProperty<QObject> *);
+ static QObject *context_at(QQmlListProperty<QObject> *, qsizetype);
void dropDestroyedQObject(const QString &name, QObject *destroyed);
diff --git a/src/qml/qml/qqmllist.cpp b/src/qml/qml/qqmllist.cpp
index 887fe66bc1..51499f816d 100644
--- a/src/qml/qml/qqmllist.cpp
+++ b/src/qml/qml/qqmllist.cpp
@@ -324,7 +324,7 @@ Returns the list element at \a index, or 0 if the operation failed.
\sa canAt()
*/
-QObject *QQmlListReference::at(int index) const
+QObject *QQmlListReference::at(qsizetype index) const
{
if (!canAt()) return nullptr;
@@ -348,7 +348,7 @@ bool QQmlListReference::clear() const
/*!
Returns the number of objects in the list, or 0 if the operation failed.
*/
-int QQmlListReference::count() const
+qsizetype QQmlListReference::count() const
{
if (!canCount()) return 0;
@@ -361,7 +361,7 @@ Returns true if the operation succeeded, otherwise false.
\sa canReplace()
*/
-bool QQmlListReference::replace(int index, QObject *object) const
+bool QQmlListReference::replace(qsizetype index, QObject *object) const
{
if (!canReplace())
return false;
@@ -602,7 +602,7 @@ Append the \a value to the list \a property.
/*!
\typedef QQmlListProperty::CountFunction
-Synonym for \c {int (*)(QQmlListProperty<T> *property)}.
+Synonym for \c {qsizetype (*)(QQmlListProperty<T> *property)}.
Return the number of elements in the list \a property.
*/
@@ -616,7 +616,7 @@ Returns true if this QQmlListProperty is equal to \a other, otherwise false.
/*!
\typedef QQmlListProperty::AtFunction
-Synonym for \c {T *(*)(QQmlListProperty<T> *property, int index)}.
+Synonym for \c {T *(*)(QQmlListProperty<T> *property, qsizetype index)}.
Return the element at position \a index in the list \a property.
*/
@@ -632,7 +632,7 @@ Clear the list \a property.
/*!
\typedef QQmlListProperty::ReplaceFunction
-Synonym for \c {void (*)(QQmlListProperty<T> *property, int index, T *value)}.
+Synonym for \c {void (*)(QQmlListProperty<T> *property, qsizetype index, T *value)}.
Replace the element at position \a index in the list \a property with \a value.
*/
diff --git a/src/qml/qml/qqmllist.h b/src/qml/qml/qqmllist.h
index c51a9c7636..7eb6d71670 100644
--- a/src/qml/qml/qqmllist.h
+++ b/src/qml/qml/qqmllist.h
@@ -60,10 +60,10 @@ template<typename T>
class QQmlListProperty {
public:
using AppendFunction = void (*)(QQmlListProperty<T> *, T *);
- using CountFunction = int (*)(QQmlListProperty<T> *);
- using AtFunction = T *(*)(QQmlListProperty<T> *, int);
+ using CountFunction = qsizetype (*)(QQmlListProperty<T> *);
+ using AtFunction = T *(*)(QQmlListProperty<T> *, qsizetype);
using ClearFunction = void (*)(QQmlListProperty<T> *);
- using ReplaceFunction = void (*)(QQmlListProperty<T> *, int, T *);
+ using ReplaceFunction = void (*)(QQmlListProperty<T> *, qsizetype, T *);
using RemoveLastFunction = void (*)(QQmlListProperty<T> *);
QQmlListProperty() = default;
@@ -126,39 +126,39 @@ private:
static void qlist_append(QQmlListProperty *p, T *v) {
reinterpret_cast<QList<T *> *>(p->data)->append(v);
}
- static int qlist_count(QQmlListProperty *p) {
+ static qsizetype qlist_count(QQmlListProperty *p) {
return reinterpret_cast<QList<T *> *>(p->data)->count();
}
- static T *qlist_at(QQmlListProperty *p, int idx) {
+ static T *qlist_at(QQmlListProperty *p, qsizetype idx) {
return reinterpret_cast<QList<T *> *>(p->data)->at(idx);
}
static void qlist_clear(QQmlListProperty *p) {
return reinterpret_cast<QList<T *> *>(p->data)->clear();
}
- static void qlist_replace(QQmlListProperty *p, int idx, T *v) {
+ static void qlist_replace(QQmlListProperty *p, qsizetype idx, T *v) {
return reinterpret_cast<QList<T *> *>(p->data)->replace(idx, v);
}
static void qlist_removeLast(QQmlListProperty *p) {
return reinterpret_cast<QList<T *> *>(p->data)->removeLast();
}
- static void qslow_replace(QQmlListProperty<T> *list, int idx, T *v)
+ static void qslow_replace(QQmlListProperty<T> *list, qsizetype idx, T *v)
{
- const int length = list->count(list);
+ const qsizetype length = list->count(list);
if (idx < 0 || idx >= length)
return;
QVector<T *> stash;
if (list->clear != qslow_clear) {
stash.reserve(length);
- for (int i = 0; i < length; ++i)
+ for (qsizetype i = 0; i < length; ++i)
stash.append(i == idx ? v : list->at(list, i));
list->clear(list);
for (T *item : qAsConst(stash))
list->append(list, item);
} else {
stash.reserve(length - idx - 1);
- for (int i = length - 1; i > idx; --i) {
+ for (qsizetype i = length - 1; i > idx; --i) {
stash.append(list->at(list, i));
list->removeLast(list);
}
@@ -171,18 +171,18 @@ private:
static void qslow_clear(QQmlListProperty<T> *list)
{
- for (int i = 0, end = list->count(list); i < end; ++i)
+ for (qsizetype i = 0, end = list->count(list); i < end; ++i)
list->removeLast(list);
}
static void qslow_removeLast(QQmlListProperty<T> *list)
{
- const int length = list->count(list) - 1;
+ const qsizetype length = list->count(list) - 1;
if (length < 0)
return;
QVector<T *> stash;
stash.reserve(length);
- for (int i = 0; i < length; ++i)
+ for (qsizetype i = 0; i < length; ++i)
stash.append(list->at(list, i));
list->clear(list);
for (T *item : qAsConst(stash))
@@ -218,10 +218,10 @@ public:
bool isReadable() const;
bool append(QObject *) const;
- QObject *at(int) const;
+ QObject *at(qsizetype) const;
bool clear() const;
- int count() const;
- bool replace(int, QObject *) const;
+ qsizetype count() const;
+ bool replace(qsizetype, QObject *) const;
bool removeLast() const;
bool operator==(const QQmlListReference &other) const {return d == other.d;}
diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp
index a30314635a..d53e751cb6 100644
--- a/src/qml/qml/qqmlproperty.cpp
+++ b/src/qml/qml/qqmlproperty.cpp
@@ -1339,7 +1339,7 @@ bool QQmlPropertyPrivate::write(
if (variantType == qMetaTypeId<QQmlListReference>()) {
QQmlListReference qdlr = value.value<QQmlListReference>();
- for (int ii = 0; ii < qdlr.count(); ++ii) {
+ for (qsizetype ii = 0; ii < qdlr.count(); ++ii) {
QObject *o = qdlr.at(ii);
if (o && !QQmlMetaObject::canConvert(o, listType))
o = nullptr;
@@ -1348,7 +1348,7 @@ bool QQmlPropertyPrivate::write(
} else if (variantType == qMetaTypeId<QList<QObject *> >()) {
const QList<QObject *> &list = qvariant_cast<QList<QObject *> >(value);
- for (int ii = 0; ii < list.count(); ++ii) {
+ for (qsizetype ii = 0; ii < list.count(); ++ii) {
QObject *o = list.at(ii);
if (o && !QQmlMetaObject::canConvert(o, listType))
o = nullptr;
diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp
index 6919c6dba3..2379f393aa 100644
--- a/src/qml/qml/qqmlvmemetaobject.cpp
+++ b/src/qml/qml/qqmlvmemetaobject.cpp
@@ -131,12 +131,12 @@ static void list_append(QQmlListProperty<QObject> *prop, QObject *o)
resolved.activateSignal();
}
-static int list_count(QQmlListProperty<QObject> *prop)
+static qsizetype list_count(QQmlListProperty<QObject> *prop)
{
return ResolvedList(prop).list()->count();
}
-static QObject *list_at(QQmlListProperty<QObject> *prop, int index)
+static QObject *list_at(QQmlListProperty<QObject> *prop, qsizetype index)
{
return ResolvedList(prop).list()->at(index);
}
@@ -148,7 +148,7 @@ static void list_clear(QQmlListProperty<QObject> *prop)
resolved.activateSignal();
}
-static void list_replace(QQmlListProperty<QObject> *prop, int index, QObject *o)
+static void list_replace(QQmlListProperty<QObject> *prop, qsizetype index, QObject *o)
{
const ResolvedList resolved(prop);
resolved.list()->replace(index, o);