diff options
author | Frederik Gladhorn <frederik.gladhorn@theqtcompany.com> | 2015-03-09 10:22:45 +0100 |
---|---|---|
committer | Frederik Gladhorn <frederik.gladhorn@theqtcompany.com> | 2015-03-09 10:23:15 +0100 |
commit | 6cef72d0b4f6cd676203688a2562f0a9a620c7fb (patch) | |
tree | d45d59493e942e4489c6428e40ea979eb373eec5 /src/corelib | |
parent | f7118e7f1b495fc0a0b8d83dff1a207dfddb09aa (diff) | |
parent | 1cd8d67d5f9bb0cd17147481544db8fb9342354d (diff) |
Merge remote-tracking branch 'origin/5.5' into dev
Change-Id: I9d10911c51700965f2cf0e3173b88fd9116bd3ee
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/arch/qatomic_cxx11.h | 96 | ||||
-rw-r--r-- | src/corelib/global/qglobal.h | 6 | ||||
-rw-r--r-- | src/corelib/global/qnamespace.h | 1 | ||||
-rw-r--r-- | src/corelib/io/qlockfile_unix.cpp | 12 | ||||
-rw-r--r-- | src/corelib/itemmodels/qabstractitemmodel.h | 27 | ||||
-rw-r--r-- | src/corelib/itemmodels/qitemselectionmodel.h | 3 | ||||
-rw-r--r-- | src/corelib/kernel/qcoreapplication.cpp | 22 | ||||
-rw-r--r-- | src/corelib/kernel/qmetatype.cpp | 3 | ||||
-rw-r--r-- | src/corelib/kernel/qmetatype.h | 5 | ||||
-rw-r--r-- | src/corelib/kernel/qmetatype_p.h | 1 | ||||
-rw-r--r-- | src/corelib/kernel/qvariant.cpp | 52 | ||||
-rw-r--r-- | src/corelib/kernel/qvariant.h | 3 | ||||
-rw-r--r-- | src/corelib/thread/qbasicatomic.h | 8 | ||||
-rw-r--r-- | src/corelib/tools/qdatetime.cpp | 55 | ||||
-rw-r--r-- | src/corelib/tools/qdatetime.h | 2 | ||||
-rw-r--r-- | src/corelib/tools/qdatetime_p.h | 14 | ||||
-rw-r--r-- | src/corelib/tools/qsharedpointer_impl.h | 1 | ||||
-rw-r--r-- | src/corelib/tools/qstringalgorithms_p.h | 2 |
18 files changed, 244 insertions, 69 deletions
diff --git a/src/corelib/arch/qatomic_cxx11.h b/src/corelib/arch/qatomic_cxx11.h index a58c8ab72e..09e900f4ea 100644 --- a/src/corelib/arch/qatomic_cxx11.h +++ b/src/corelib/arch/qatomic_cxx11.h @@ -230,6 +230,102 @@ template <typename X> struct QAtomicOps { return _q_value.fetch_add(valueToAdd, std::memory_order_acq_rel); } + + template <typename T> static inline + T fetchAndSubRelaxed(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + { + return _q_value.fetch_sub(valueToAdd, std::memory_order_relaxed); + } + + template <typename T> static inline + T fetchAndSubAcquire(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + { + return _q_value.fetch_sub(valueToAdd, std::memory_order_acquire); + } + + template <typename T> static inline + T fetchAndSubRelease(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + { + return _q_value.fetch_sub(valueToAdd, std::memory_order_release); + } + + template <typename T> static inline + T fetchAndSubOrdered(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + { + return _q_value.fetch_sub(valueToAdd, std::memory_order_acq_rel); + } + + template <typename T> static inline + T fetchAndAndRelaxed(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + { + return _q_value.fetch_and(valueToAdd, std::memory_order_relaxed); + } + + template <typename T> static inline + T fetchAndAndAcquire(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + { + return _q_value.fetch_and(valueToAdd, std::memory_order_acquire); + } + + template <typename T> static inline + T fetchAndAndRelease(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + { + return _q_value.fetch_and(valueToAdd, std::memory_order_release); + } + + template <typename T> static inline + T fetchAndAndOrdered(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + { + return _q_value.fetch_and(valueToAdd, std::memory_order_acq_rel); + } + + template <typename T> static inline + T fetchAndOrRelaxed(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + { + return _q_value.fetch_or(valueToAdd, std::memory_order_relaxed); + } + + template <typename T> static inline + T fetchAndOrAcquire(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + { + return _q_value.fetch_or(valueToAdd, std::memory_order_acquire); + } + + template <typename T> static inline + T fetchAndOrRelease(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + { + return _q_value.fetch_or(valueToAdd, std::memory_order_release); + } + + template <typename T> static inline + T fetchAndOrOrdered(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + { + return _q_value.fetch_or(valueToAdd, std::memory_order_acq_rel); + } + + template <typename T> static inline + T fetchAndXorRelaxed(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + { + return _q_value.fetch_xor(valueToAdd, std::memory_order_relaxed); + } + + template <typename T> static inline + T fetchAndXorAcquire(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + { + return _q_value.fetch_xor(valueToAdd, std::memory_order_acquire); + } + + template <typename T> static inline + T fetchAndXorRelease(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + { + return _q_value.fetch_xor(valueToAdd, std::memory_order_release); + } + + template <typename T> static inline + T fetchAndXorOrdered(std::atomic<T> &_q_value, typename QAtomicAdditiveType<T>::AdditiveT valueToAdd) Q_DECL_NOTHROW + { + return _q_value.fetch_xor(valueToAdd, std::memory_order_acq_rel); + } }; #ifdef ATOMIC_VAR_INIT diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 2d3a78db01..6aa3eb305b 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -585,6 +585,10 @@ class QDataStream; # define QT_NO_SOCKS5 #endif +#if defined(Q_OS_IOS) +# define QT_NO_PROCESS +#endif + inline void qt_noop(void) {} /* These wrap try/catch so we can switch off exceptions later. @@ -660,7 +664,7 @@ Q_CORE_EXPORT void qt_assert(const char *assertion, const char *file, int line) #if !defined(Q_ASSERT) # if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) -# define Q_ASSERT(cond) do { } while (false && (cond)) +# define Q_ASSERT(cond) do { } while ((false) && (cond)) # else # define Q_ASSERT(cond) ((!(cond)) ? qt_assert(#cond,__FILE__,__LINE__) : qt_noop()) # endif diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h index e115cedc51..420b8b0430 100644 --- a/src/corelib/global/qnamespace.h +++ b/src/corelib/global/qnamespace.h @@ -1663,6 +1663,7 @@ public: QT_Q_ENUM(ItemSelectionOperation) QT_Q_FLAG(ItemFlags) QT_Q_ENUM(CheckState) + QT_Q_ENUM(ItemDataRole) QT_Q_ENUM(SortOrder) QT_Q_ENUM(CaseSensitivity) QT_Q_FLAG(MatchFlags) diff --git a/src/corelib/io/qlockfile_unix.cpp b/src/corelib/io/qlockfile_unix.cpp index 5719d899a0..1c8da607a7 100644 --- a/src/corelib/io/qlockfile_unix.cpp +++ b/src/corelib/io/qlockfile_unix.cpp @@ -157,13 +157,17 @@ QLockFile::LockError QLockFilePrivate::tryLock_sys() if (!setNativeLocks(fd)) qWarning() << "setNativeLocks failed:" << strerror(errno); + if (qt_write_loop(fd, fileData.constData(), fileData.size()) < fileData.size()) { + close(fd); + if (!QFile::remove(fileName)) + qWarning("QLockFile: Could not remove our own lock file %s.", qPrintable(fileName)); + return QLockFile::UnknownError; // partition full + } + // We hold the lock, continue. fileHandle = fd; - QLockFile::LockError error = QLockFile::NoError; - if (qt_write_loop(fd, fileData.constData(), fileData.size()) < fileData.size()) - error = QLockFile::UnknownError; // partition full - return error; + return QLockFile::NoError; } bool QLockFilePrivate::removeStaleLock() diff --git a/src/corelib/itemmodels/qabstractitemmodel.h b/src/corelib/itemmodels/qabstractitemmodel.h index 7789c0d483..1c2ff9f190 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.h +++ b/src/corelib/itemmodels/qabstractitemmodel.h @@ -164,20 +164,20 @@ public: explicit QAbstractItemModel(QObject *parent = 0); virtual ~QAbstractItemModel(); - bool hasIndex(int row, int column, const QModelIndex &parent = QModelIndex()) const; - virtual QModelIndex index(int row, int column, + Q_INVOKABLE bool hasIndex(int row, int column, const QModelIndex &parent = QModelIndex()) const; + Q_INVOKABLE virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const = 0; - virtual QModelIndex parent(const QModelIndex &child) const = 0; + Q_INVOKABLE virtual QModelIndex parent(const QModelIndex &child) const = 0; - virtual QModelIndex sibling(int row, int column, const QModelIndex &idx) const; - virtual int rowCount(const QModelIndex &parent = QModelIndex()) const = 0; - virtual int columnCount(const QModelIndex &parent = QModelIndex()) const = 0; - virtual bool hasChildren(const QModelIndex &parent = QModelIndex()) const; + Q_INVOKABLE virtual QModelIndex sibling(int row, int column, const QModelIndex &idx) const; + Q_INVOKABLE virtual int rowCount(const QModelIndex &parent = QModelIndex()) const = 0; + Q_INVOKABLE virtual int columnCount(const QModelIndex &parent = QModelIndex()) const = 0; + Q_INVOKABLE virtual bool hasChildren(const QModelIndex &parent = QModelIndex()) const; - virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const = 0; - virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); + Q_INVOKABLE virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const = 0; + Q_INVOKABLE virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); - virtual QVariant headerData(int section, Qt::Orientation orientation, + Q_INVOKABLE virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; virtual bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole); @@ -217,9 +217,9 @@ public: inline bool moveColumn(const QModelIndex &sourceParent, int sourceColumn, const QModelIndex &destinationParent, int destinationChild); - virtual void fetchMore(const QModelIndex &parent); - virtual bool canFetchMore(const QModelIndex &parent) const; - virtual Qt::ItemFlags flags(const QModelIndex &index) const; + Q_INVOKABLE virtual void fetchMore(const QModelIndex &parent); + Q_INVOKABLE virtual bool canFetchMore(const QModelIndex &parent) const; + Q_INVOKABLE virtual Qt::ItemFlags flags(const QModelIndex &index) const; virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder); virtual QModelIndex buddy(const QModelIndex &index) const; virtual QModelIndexList match(const QModelIndex &start, int role, @@ -484,6 +484,5 @@ inline uint qHash(const QModelIndex &index) Q_DECL_NOTHROW QT_END_NAMESPACE Q_DECLARE_METATYPE(QModelIndexList) -Q_DECLARE_METATYPE(QPersistentModelIndex) #endif // QABSTRACTITEMMODEL_H diff --git a/src/corelib/itemmodels/qitemselectionmodel.h b/src/corelib/itemmodels/qitemselectionmodel.h index fe0bd459cd..09fab78214 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.h +++ b/src/corelib/itemmodels/qitemselectionmodel.h @@ -146,6 +146,7 @@ class Q_CORE_EXPORT QItemSelectionModel : public QObject Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelChanged) Q_PROPERTY(bool hasSelection READ hasSelection NOTIFY selectionChanged STORED false DESIGNABLE false) Q_PROPERTY(QModelIndex currentIndex READ currentIndex NOTIFY currentChanged STORED false DESIGNABLE false) + Q_PROPERTY(QItemSelection selection READ selection NOTIFY selectionChanged STORED false DESIGNABLE false) Q_DECLARE_PRIVATE(QItemSelectionModel) @@ -186,7 +187,7 @@ public: Q_INVOKABLE QModelIndexList selectedIndexes() const; Q_INVOKABLE QModelIndexList selectedRows(int column = 0) const; Q_INVOKABLE QModelIndexList selectedColumns(int row = 0) const; - Q_INVOKABLE const QItemSelection selection() const; + const QItemSelection selection() const; // ### Qt 6: Merge these two as "QAbstractItemModel *model() const" const QAbstractItemModel *model() const; diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index 18a379f8b9..0bde57c8b3 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -368,7 +368,9 @@ struct QCoreApplicationData { } #endif - QString orgName, orgDomain, application; + QString orgName, orgDomain; + QString application; // application name, initially from argv[0], can then be modified. + QString applicationNameCompat; // for QDesktopServices. Only set explicitly. QString applicationVersion; #ifndef QT_NO_LIBRARY @@ -750,6 +752,9 @@ void QCoreApplication::init() Q_ASSERT_X(!self, "QCoreApplication", "there should be only one application object"); QCoreApplication::self = this; + // Store app name (so it's still available after QCoreApplication is destroyed) + coreappdata()->application = d_func()->appName(); + QLoggingRegistry::instance()->init(); #ifndef QT_NO_QOBJECT @@ -2345,9 +2350,13 @@ QString QCoreApplication::organizationDomain() */ void QCoreApplication::setApplicationName(const QString &application) { - if (coreappdata()->application == application) + QString newAppName = application; + if (newAppName.isEmpty() && QCoreApplication::self) + newAppName = QCoreApplication::self->d_func()->appName(); + if (coreappdata()->application == newAppName) return; - coreappdata()->application = application; + coreappdata()->application = newAppName; + coreappdata()->applicationNameCompat = newAppName; #ifndef QT_NO_QOBJECT if (QCoreApplication::self) emit QCoreApplication::self->applicationNameChanged(); @@ -2359,16 +2368,13 @@ QString QCoreApplication::applicationName() #ifdef Q_OS_BLACKBERRY coreappdata()->loadManifest(); #endif - QString appname = coreappdata() ? coreappdata()->application : QString(); - if (appname.isEmpty() && QCoreApplication::self) - appname = QCoreApplication::self->d_func()->appName(); - return appname; + return coreappdata() ? coreappdata()->application : QString(); } // Exported for QDesktopServices (Qt4 behavior compatibility) Q_CORE_EXPORT QString qt_applicationName_noFallback() { - return coreappdata()->application; + return coreappdata()->applicationNameCompat; } /*! diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index 305e998818..d4a69ee4b9 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -277,6 +277,7 @@ struct DefinedTypesFilter { \value QJsonArray QJsonArray \value QJsonDocument QJsonDocument \value QModelIndex QModelIndex + \value QPersistentModelIndex QPersistentModelIndex (since 5.5) \value QUuid QUuid \value QByteArrayList QByteArrayList @@ -1209,6 +1210,7 @@ bool QMetaType::save(QDataStream &stream, int type, const void *data) case QMetaType::VoidStar: case QMetaType::QObjectStar: case QMetaType::QModelIndex: + case QMetaType::QPersistentModelIndex: case QMetaType::QJsonValue: case QMetaType::QJsonObject: case QMetaType::QJsonArray: @@ -1429,6 +1431,7 @@ bool QMetaType::load(QDataStream &stream, int type, void *data) case QMetaType::VoidStar: case QMetaType::QObjectStar: case QMetaType::QModelIndex: + case QMetaType::QPersistentModelIndex: case QMetaType::QJsonValue: case QMetaType::QJsonObject: case QMetaType::QJsonArray: diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index 9659c015ff..2c2dbeef9d 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -113,6 +113,7 @@ inline Q_DECL_CONSTEXPR int qMetaTypeId(); F(QJsonObject, 46, QJsonObject) \ F(QJsonArray, 47, QJsonArray) \ F(QJsonDocument, 48, QJsonDocument) \ + F(QPersistentModelIndex, 50, QPersistentModelIndex) \ #define QT_FOR_EACH_STATIC_CORE_POINTER(F)\ F(QObjectStar, 39, QObject*) @@ -407,7 +408,7 @@ public: QT_FOR_EACH_STATIC_TYPE(QT_DEFINE_METATYPE_ID) FirstCoreType = Bool, - LastCoreType = QByteArrayList, + LastCoreType = QPersistentModelIndex, FirstGuiType = QFont, LastGuiType = QPolygonF, FirstWidgetsType = QSizePolicy, @@ -431,7 +432,7 @@ public: QLocale = 18, QRect = 19, QRectF = 20, QSize = 21, QSizeF = 22, QLine = 23, QLineF = 24, QPoint = 25, QPointF = 26, QRegExp = 27, QEasingCurve = 29, QUuid = 30, QVariant = 41, QModelIndex = 42, - QRegularExpression = 44, + QPersistentModelIndex = 50, QRegularExpression = 44, QJsonValue = 45, QJsonObject = 46, QJsonArray = 47, QJsonDocument = 48, QByteArrayList = 49, QObjectStar = 39, SChar = 40, Void = 43, diff --git a/src/corelib/kernel/qmetatype_p.h b/src/corelib/kernel/qmetatype_p.h index 7880baf0f1..7c0c984c9c 100644 --- a/src/corelib/kernel/qmetatype_p.h +++ b/src/corelib/kernel/qmetatype_p.h @@ -192,6 +192,7 @@ template<> struct TypeDefinition<QJsonDocument> { static const bool IsAvailable template<> struct TypeDefinition<QJsonObject> { static const bool IsAvailable = false; }; template<> struct TypeDefinition<QJsonValue> { static const bool IsAvailable = false; }; template<> struct TypeDefinition<QModelIndex> { static const bool IsAvailable = false; }; +template<> struct TypeDefinition<QPersistentModelIndex> { static const bool IsAvailable = false; }; template<> struct TypeDefinition<QUrl> { static const bool IsAvailable = false; }; template<> struct TypeDefinition<QByteArrayList> { static const bool IsAvailable = false; }; #endif diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index b14c9ed167..9ae6c779c0 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -390,7 +390,25 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) return false; } break; -#endif + case QVariant::ModelIndex: + switch (d->type) { + case QVariant::PersistentModelIndex: + *static_cast<QModelIndex *>(result) = QModelIndex(*v_cast<QPersistentModelIndex>(d)); + break; + default: + return false; + } + break; + case QVariant::PersistentModelIndex: + switch (d->type) { + case QVariant::ModelIndex: + *static_cast<QPersistentModelIndex *>(result) = QPersistentModelIndex(*v_cast<QModelIndex>(d)); + break; + default: + return false; + } + break; +#endif // QT_BOOTSTRAPPED case QVariant::String: { QString *str = static_cast<QString *>(result); switch (d->type) { @@ -1208,6 +1226,7 @@ Q_CORE_EXPORT void QVariantPrivate::registerHandler(const int /* Modules::Names \value EasingCurve a QEasingCurve \value Uuid a QUuid \value ModelIndex a QModelIndex + \value PersistentModelIndex a QPersistentModelIndex (since 5.5) \value Font a QFont \value Hash a QVariantHash \value Icon a QIcon @@ -1455,7 +1474,14 @@ QVariant::QVariant(const char *val) \since 5.0 \fn QVariant::QVariant(const QModelIndex &val) - Constructs a new variant with an modelIndex value, \a val. + Constructs a new variant with a QModelIndex value, \a val. +*/ + +/*! + \since 5.5 + \fn QVariant::QVariant(const QPersistentModelIndex &val) + + Constructs a new variant with a QPersistentModelIndex value, \a val. */ /*! @@ -1763,6 +1789,9 @@ QVariant::QVariant(const QUuid &uuid) QVariant::QVariant(const QModelIndex &modelIndex) : d(ModelIndex) { v_construct<QModelIndex>(&d, modelIndex); } +QVariant::QVariant(const QPersistentModelIndex &modelIndex) + : d(PersistentModelIndex) +{ v_construct<QPersistentModelIndex>(&d, modelIndex); } QVariant::QVariant(const QJsonValue &jsonValue) : d(QMetaType::QJsonValue) { v_construct<QJsonValue>(&d, jsonValue); } @@ -2492,7 +2521,7 @@ QUuid QVariant::toUuid() const Returns the variant as a QModelIndex if the variant has userType() \l QModelIndex; otherwise returns a default constructed QModelIndex. - \sa canConvert(), convert() + \sa canConvert(), convert(), toPersistentModelIndex() */ QModelIndex QVariant::toModelIndex() const { @@ -2500,6 +2529,19 @@ QModelIndex QVariant::toModelIndex() const } /*! + \since 5.5 + + Returns the variant as a QPersistentModelIndex if the variant has userType() \l + QPersistentModelIndex; otherwise returns a default constructed QPersistentModelIndex. + + \sa canConvert(), convert(), toModelIndex() +*/ +QModelIndex QVariant::toPersistentModelIndex() const +{ + return qVariantToHelper<QPersistentModelIndex>(d, handlerManager); +} + +/*! \since 5.0 Returns the variant as a QJsonValue if the variant has userType() \l @@ -2966,6 +3008,10 @@ static bool canConvertMetaObject(int fromId, int toId, QObject *fromObject) */ bool QVariant::canConvert(int targetTypeId) const { + if ((targetTypeId == QMetaType::QModelIndex && d.type == QMetaType::QPersistentModelIndex) + || (targetTypeId == QMetaType::QPersistentModelIndex && d.type == QMetaType::QModelIndex)) + return true; + if (targetTypeId == QMetaType::QVariantList && (d.type == QMetaType::QVariantList || d.type == QMetaType::QStringList diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index b6a4133582..d9eca94391 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -156,6 +156,7 @@ class Q_CORE_EXPORT QVariant EasingCurve = QMetaType::QEasingCurve, Uuid = QMetaType::QUuid, ModelIndex = QMetaType::QModelIndex, + PersistentModelIndex = QMetaType::QPersistentModelIndex, LastCoreType = QMetaType::LastCoreType, Font = QMetaType::QFont, @@ -245,6 +246,7 @@ class Q_CORE_EXPORT QVariant QVariant(const QEasingCurve &easing); QVariant(const QUuid &uuid); QVariant(const QModelIndex &modelIndex); + QVariant(const QPersistentModelIndex &modelIndex); QVariant(const QJsonValue &jsonValue); QVariant(const QJsonObject &jsonObject); QVariant(const QJsonArray &jsonArray); @@ -318,6 +320,7 @@ class Q_CORE_EXPORT QVariant QEasingCurve toEasingCurve() const; QUuid toUuid() const; QModelIndex toModelIndex() const; + QModelIndex toPersistentModelIndex() const; QJsonValue toJsonValue() const; QJsonObject toJsonObject() const; QJsonArray toJsonArray() const; diff --git a/src/corelib/thread/qbasicatomic.h b/src/corelib/thread/qbasicatomic.h index 16a27862c2..ecf39d699f 100644 --- a/src/corelib/thread/qbasicatomic.h +++ b/src/corelib/thread/qbasicatomic.h @@ -39,6 +39,14 @@ #if defined(QT_BOOTSTRAPPED) # include <QtCore/qatomic_bootstrap.h> +// The following two are used for testing only. +// Note that we don't check the compiler support -- you had better +// know what you're doing if you set them +#elif defined(QT_ATOMIC_FORCE_CXX11) +# include <QtCore/qatomic_cxx11.h> +#elif defined(QT_ATOMIC_FORCE_GCC) +# include <QtCore/qatomic_gcc.h> + // Compiler dependent implementation #elif defined(Q_CC_MSVC) # include <QtCore/qatomic_msvc.h> diff --git a/src/corelib/tools/qdatetime.cpp b/src/corelib/tools/qdatetime.cpp index eeefea8137..e5fbf5af5e 100644 --- a/src/corelib/tools/qdatetime.cpp +++ b/src/corelib/tools/qdatetime.cpp @@ -2607,7 +2607,6 @@ QDateTimePrivate::QDateTimePrivate(const QDate &toDate, const QTime &toTime, void QDateTimePrivate::setTimeSpec(Qt::TimeSpec spec, int offsetSeconds) { clearValidDateTime(); - clearTimeZoneCached(); clearSetToDaylightStatus(); #ifndef QT_BOOTSTRAPPED @@ -2707,27 +2706,44 @@ QDateTimePrivate::DaylightStatus QDateTimePrivate::daylightStatus() const return UnknownDaylightTime; } +qint64 QDateTimePrivate::toMSecsSinceEpoch() const +{ + switch (m_spec) { + case Qt::OffsetFromUTC: + case Qt::UTC: + return (m_msecs - (m_offsetFromUtc * 1000)); + + case Qt::LocalTime: + // recalculate the local timezone + return localMSecsToEpochMSecs(m_msecs); + + case Qt::TimeZone: +#ifndef QT_BOOTSTRAPPED + return zoneMSecsToEpochMSecs(m_msecs, m_timeZone); +#endif + break; + } + Q_UNREACHABLE(); + return 0; +} + // Check the UTC / offsetFromUTC validity void QDateTimePrivate::checkValidDateTime() { switch (m_spec) { case Qt::OffsetFromUTC: case Qt::UTC: + // for these, a valid date and a valid time imply a valid QDateTime if (isValidDate() && isValidTime()) setValidDateTime(); else clearValidDateTime(); break; case Qt::TimeZone: - // Defer checking until required as can be expensive - clearValidDateTime(); - clearTimeZoneCached(); - m_offsetFromUtc = 0; - break; case Qt::LocalTime: - // Defer checking until required as can be expensive - clearValidDateTime(); - m_offsetFromUtc = 0; + // for these, we need to check whether the timezone is valid and whether + // the time is valid in that timezone. Expensive, but no other option. + refreshDateTime(); break; } } @@ -2741,12 +2757,6 @@ void QDateTimePrivate::refreshDateTime() // Always set by setDateTime so just return return; case Qt::TimeZone: - // If already cached then don't need to refresh as tz won't change - if (isTimeZoneCached()) - return; - // Flag that will have a cached result after calculations - setTimeZoneCached(); - break; case Qt::LocalTime: break; } @@ -3082,7 +3092,6 @@ bool QDateTime::isNull() const bool QDateTime::isValid() const { - d->refreshDateTime(); return (d->isValidDateTime()); } @@ -3143,13 +3152,11 @@ Qt::TimeSpec QDateTime::timeSpec() const QTimeZone QDateTime::timeZone() const { switch (d->m_spec) { - case Qt::OffsetFromUTC: - if (!d->m_timeZone.isValid()) - d->m_timeZone = QTimeZone(d->m_offsetFromUtc); - return d->m_timeZone; case Qt::UTC: return QTimeZone::utc(); + case Qt::OffsetFromUTC: case Qt::TimeZone: + Q_ASSERT(d->m_timeZone.isValid()); return d->m_timeZone; case Qt::LocalTime: return QTimeZone::systemTimeZone(); @@ -3178,7 +3185,6 @@ QTimeZone QDateTime::timeZone() const int QDateTime::offsetFromUtc() const { - d->refreshDateTime(); return d->m_offsetFromUtc; } @@ -3350,7 +3356,7 @@ void QDateTime::setTimeZone(const QTimeZone &toZone) d->m_spec = Qt::TimeZone; d->m_offsetFromUtc = 0; d->m_timeZone = toZone; - d->m_status = d->m_status & ~QDateTimePrivate::ValidDateTime & ~QDateTimePrivate::TimeZoneCached; + d->refreshDateTime(); } #endif // QT_BOOTSTRAPPED @@ -3371,7 +3377,6 @@ void QDateTime::setTimeZone(const QTimeZone &toZone) */ qint64 QDateTime::toMSecsSinceEpoch() const { - d->refreshDateTime(); return d->toMSecsSinceEpoch(); } @@ -3453,8 +3458,8 @@ void QDateTime::setMSecsSinceEpoch(qint64 msecs) d->m_status = d->m_status | QDateTimePrivate::ValidDate | QDateTimePrivate::ValidTime - | QDateTimePrivate::ValidDateTime - | QDateTimePrivate::TimeZoneCached; + | QDateTimePrivate::ValidDateTime; + d->refreshDateTime(); #endif // QT_BOOTSTRAPPED break; case Qt::LocalTime: { diff --git a/src/corelib/tools/qdatetime.h b/src/corelib/tools/qdatetime.h index 784aced71a..88288872df 100644 --- a/src/corelib/tools/qdatetime.h +++ b/src/corelib/tools/qdatetime.h @@ -326,7 +326,7 @@ private: // ### Qt6: Using a private here has high impact on runtime // on users such as QFileInfo. In Qt 6, the data members // should be inlined. - QExplicitlySharedDataPointer<QDateTimePrivate> d; + QSharedDataPointer<QDateTimePrivate> d; #ifndef QT_NO_DATASTREAM friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QDateTime &); diff --git a/src/corelib/tools/qdatetime_p.h b/src/corelib/tools/qdatetime_p.h index a139390a9d..b8934f7f70 100644 --- a/src/corelib/tools/qdatetime_p.h +++ b/src/corelib/tools/qdatetime_p.h @@ -79,10 +79,9 @@ public: enum StatusFlag { NullDate = 0x01, NullTime = 0x02, - ValidDate = 0x04, - ValidTime = 0x08, - ValidDateTime = 0x10, - TimeZoneCached = 0x20, + ValidDate = 0x04, // just the date field + ValidTime = 0x08, // just the time field + ValidDateTime = 0x10, // the whole object (including timezone) SetToStandardTime = 0x40, SetToDaylightTime = 0x80 }; @@ -120,7 +119,7 @@ public: DaylightStatus daylightStatus() const; // Returns msecs since epoch, assumes offset value is current - inline qint64 toMSecsSinceEpoch() const { return (m_msecs - (m_offsetFromUtc * 1000)); } + inline qint64 toMSecsSinceEpoch() const; void checkValidDateTime(); void refreshDateTime(); @@ -133,14 +132,11 @@ public: inline bool isValidDateTime() const { return m_status & ValidDateTime; } inline void setValidDateTime() { m_status |= ValidDateTime; } inline void clearValidDateTime() { m_status &= ~ValidDateTime; } - inline bool isTimeZoneCached() const { return m_status & TimeZoneCached; } - inline void setTimeZoneCached() { m_status |= TimeZoneCached; } - inline void clearTimeZoneCached() { m_status &= ~TimeZoneCached; } inline void clearSetToDaylightStatus() { m_status &= ~(SetToStandardTime | SetToDaylightTime); } #ifndef QT_BOOTSTRAPPED static qint64 zoneMSecsToEpochMSecs(qint64 msecs, const QTimeZone &zone, - QDate *localDate, QTime *localTime); + QDate *localDate = 0, QTime *localTime = 0); #endif // QT_BOOTSTRAPPED static inline qint64 minJd() { return QDate::minJd(); } diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index 8cccc83e9d..9e6b48a97d 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -247,6 +247,7 @@ namespace QtSharedPointer { ExternalRefCountWithContiguousData *that = static_cast<ExternalRefCountWithContiguousData *>(self); that->data.~T(); + Q_UNUSED(that); // MSVC warns if T has a trivial destructor } static void safetyCheckDeleter(ExternalRefCountData *self) { diff --git a/src/corelib/tools/qstringalgorithms_p.h b/src/corelib/tools/qstringalgorithms_p.h index 1481b194eb..b4be5c7ec7 100644 --- a/src/corelib/tools/qstringalgorithms_p.h +++ b/src/corelib/tools/qstringalgorithms_p.h @@ -114,7 +114,7 @@ template <typename StringType> struct QStringAlgorithms return str; const Char *src = str.cbegin(); const Char *end = str.cend(); - NakedStringType result = isConst ? + NakedStringType result = isConst || !str.isDetached() ? StringType(str.size(), Qt::Uninitialized) : qMove(str); |