summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-09-21 06:55:09 +0000
committerThe Qt Project <gerrit-noreply@qt-project.org>2017-09-21 06:55:09 +0000
commite5114e10dcb1fc535b4a33a3008448baf4ec7cbf (patch)
tree7ec9eaac618a4de514f452b0e7aff58510ce7c62 /src/corelib
parent34aa7a18af5d355380c662bb1a10b3f0d7b7ed3e (diff)
parent01bc69f99f189b03d0b9cad77cc300798937cad1 (diff)
Merge "Merge remote-tracking branch 'origin/5.9' into 5.10" into refs/staging/5.10
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/io/qfilesystemengine_unix.cpp1
-rw-r--r--src/corelib/kernel/qvariant.cpp92
-rw-r--r--src/corelib/tools/qsharedpointer_impl.h9
3 files changed, 59 insertions, 43 deletions
diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp
index 2828c85048..9fb3855472 100644
--- a/src/corelib/io/qfilesystemengine_unix.cpp
+++ b/src/corelib/io/qfilesystemengine_unix.cpp
@@ -47,6 +47,7 @@
#include <QtCore/private/qcore_unix_p.h>
#include <QtCore/qvarlengtharray.h>
+#include <pwd.h>
#include <stdlib.h> // for realpath()
#include <sys/types.h>
#include <sys/stat.h>
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp
index b79716ff4c..29429b5e55 100644
--- a/src/corelib/kernel/qvariant.cpp
+++ b/src/corelib/kernel/qvariant.cpp
@@ -3173,6 +3173,9 @@ static bool canConvertMetaObject(int fromId, int toId, QObject *fromObject)
*/
bool QVariant::canConvert(int targetTypeId) const
{
+ if (d.type == targetTypeId)
+ return true;
+
if ((targetTypeId == QMetaType::QModelIndex && d.type == QMetaType::QPersistentModelIndex)
|| (targetTypeId == QMetaType::QPersistentModelIndex && d.type == QMetaType::QModelIndex))
return true;
@@ -3639,29 +3642,36 @@ static int numericCompare(const QVariant::Private *d1, const QVariant::Private *
*/
bool QVariant::cmp(const QVariant &v) const
{
+ auto cmp_helper = [] (const QVariant::Private &d1, const QVariant::Private &d2)
+ {
+ Q_ASSERT(d1.type == d2.type);
+ if (d1.type >= QMetaType::User) {
+ int result;
+ if (QMetaType::equals(QT_PREPEND_NAMESPACE(constData(d1)), QT_PREPEND_NAMESPACE(constData(d2)), d1.type, &result))
+ return result == 0;
+ }
+ return handlerManager[d1.type]->compare(&d1, &d2);
+ };
+
// try numerics first, with C++ type promotion rules (no conversion)
if (qIsNumericType(d.type) && qIsNumericType(v.d.type))
return numericCompare(&d, &v.d) == 0;
+ if (d.type == v.d.type)
+ return cmp_helper(d, v.d);
+
QVariant v1 = *this;
QVariant v2 = v;
- if (d.type != v2.d.type) {
- if (v2.canConvert(v1.d.type)) {
- if (!v2.convert(v1.d.type))
- return false;
- } else {
- // try the opposite conversion, it might work
- qSwap(v1, v2);
- if (!v2.convert(v1.d.type))
- return false;
- }
- }
- if (v1.d.type >= QMetaType::User) {
- int result;
- if (QMetaType::equals(QT_PREPEND_NAMESPACE(constData(v1.d)), QT_PREPEND_NAMESPACE(constData(v2.d)), v1.d.type, &result))
- return result == 0;
+ if (v2.canConvert(v1.d.type)) {
+ if (!v2.convert(v1.d.type))
+ return false;
+ } else {
+ // try the opposite conversion, it might work
+ qSwap(v1, v2);
+ if (!v2.convert(v1.d.type))
+ return false;
}
- return handlerManager[v1.d.type]->compare(&v1.d, &v2.d);
+ return cmp_helper(v1.d, v2.d);
}
/*!
@@ -3677,51 +3687,53 @@ int QVariant::compare(const QVariant &v) const
if (cmp(v))
return 0;
- QVariant v1 = *this;
- QVariant v2 = v;
+ const QVariant *v1 = this;
+ const QVariant *v2 = &v;
+ QVariant converted1;
+ QVariant converted2;
- if (v1.d.type != v2.d.type) {
+ if (d.type != v.d.type) {
// if both types differ, try to convert
- if (v2.canConvert(v1.d.type)) {
- QVariant temp = v2;
- if (temp.convert(v1.d.type))
- v2 = temp;
+ if (v2->canConvert(v1->d.type)) {
+ converted2 = *v2;
+ if (converted2.convert(v1->d.type))
+ v2 = &converted2;
}
- if (v1.d.type != v2.d.type && v1.canConvert(v2.d.type)) {
- QVariant temp = v1;
- if (temp.convert(v2.d.type))
- v1 = temp;
+ if (v1->d.type != v2->d.type && v1->canConvert(v2->d.type)) {
+ converted1 = *v1;
+ if (converted1.convert(v2->d.type))
+ v1 = &converted1;
}
- if (v1.d.type != v2.d.type) {
+ if (v1->d.type != v2->d.type) {
// if conversion fails, default to toString
- int r = v1.toString().compare(v2.toString(), Qt::CaseInsensitive);
+ int r = v1->toString().compare(v2->toString(), Qt::CaseInsensitive);
if (r == 0) {
// cmp(v) returned false, so we should try to agree with it.
- return (v1.d.type < v2.d.type) ? -1 : 1;
+ return (v1->d.type < v2->d.type) ? -1 : 1;
}
return r;
}
// did we end up with two numerics? If so, restart
- if (qIsNumericType(v1.d.type) && qIsNumericType(v2.d.type))
- return v1.compare(v2);
+ if (qIsNumericType(v1->d.type) && qIsNumericType(v2->d.type))
+ return v1->compare(*v2);
}
- if (v1.d.type >= QMetaType::User) {
+ if (v1->d.type >= QMetaType::User) {
int result;
- if (QMetaType::compare(QT_PREPEND_NAMESPACE(constData(d)), QT_PREPEND_NAMESPACE(constData(v2.d)), d.type, &result))
+ if (QMetaType::compare(QT_PREPEND_NAMESPACE(constData(d)), QT_PREPEND_NAMESPACE(constData(v2->d)), d.type, &result))
return result;
}
- switch (v1.d.type) {
+ switch (v1->d.type) {
case QVariant::Date:
- return v1.toDate() < v2.toDate() ? -1 : 1;
+ return v1->toDate() < v2->toDate() ? -1 : 1;
case QVariant::Time:
- return v1.toTime() < v2.toTime() ? -1 : 1;
+ return v1->toTime() < v2->toTime() ? -1 : 1;
case QVariant::DateTime:
- return v1.toDateTime() < v2.toDateTime() ? -1 : 1;
+ return v1->toDateTime() < v2->toDateTime() ? -1 : 1;
case QVariant::StringList:
- return v1.toStringList() < v2.toStringList() ? -1 : 1;
+ return v1->toStringList() < v2->toStringList() ? -1 : 1;
}
- int r = v1.toString().compare(v2.toString(), Qt::CaseInsensitive);
+ int r = v1->toString().compare(v2->toString(), Qt::CaseInsensitive);
if (r == 0) {
// cmp(v) returned false, so we should try to agree with it.
return (d.type < v.d.type) ? -1 : 1;
diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h
index 15573c5588..ede54c155d 100644
--- a/src/corelib/tools/qsharedpointer_impl.h
+++ b/src/corelib/tools/qsharedpointer_impl.h
@@ -850,17 +850,20 @@ Q_INLINE_TEMPLATE typename QSharedPointer<X>::difference_type operator-(T *ptr1,
template <class T, class X>
Q_INLINE_TEMPLATE bool operator<(const QSharedPointer<T> &ptr1, const QSharedPointer<X> &ptr2)
{
- return ptr1.data() < ptr2.data();
+ using CT = typename std::common_type<T *, X *>::type;
+ return std::less<CT>()(ptr1.data(), ptr2.data());
}
template <class T, class X>
Q_INLINE_TEMPLATE bool operator<(const QSharedPointer<T> &ptr1, X *ptr2)
{
- return ptr1.data() < ptr2;
+ using CT = typename std::common_type<T *, X *>::type;
+ return std::less<CT>()(ptr1.data(), ptr2);
}
template <class T, class X>
Q_INLINE_TEMPLATE bool operator<(T *ptr1, const QSharedPointer<X> &ptr2)
{
- return ptr1 < ptr2.data();
+ using CT = typename std::common_type<T *, X *>::type;
+ return std::less<CT>()(ptr1, ptr2.data());
}
//